PDA

View Full Version : قابلیت های فرم ها



mahdyari77
چهارشنبه 23 فروردین 1391, 21:16 عصر
سلام
من یک سری فرم دارم قابلیت این فرم هارو از فرم اول نمیتونم عوض کنم
مثلا وقتی مینویسم
form2.visibility = false
ارور میده جالب اینجاست که از توی خود فرم ها هم نمیتونم برخی خصوصیاتو تغییر بدم
تا الان این طوری نبود
error :
invalid operation exception
An error occurred creating the form. See Exception.InnerException for details. The error is: Format of the initialization string does not conform to specification starting at index 0.

Hybrid
چهارشنبه 23 فروردین 1391, 21:59 عصر
سلام ، اون خاصیت Visible هست نه Visibility به کد های زیر دقت کن :


Form2.Show()

برای مخفی کردن فرم Form2 :


Form2.Visible = False

mahdyari77
چهارشنبه 23 فروردین 1391, 22:05 عصر
نه اون visible یا visibility اشتباه لپی بود کلا هیچ خصوصیتی نمیشه حتی این form2.show هم کار نمیکنه

Hybrid
چهارشنبه 23 فروردین 1391, 22:17 عصر
خوب یکی شی از کلاس فرم بساز و از متدهاش استفاده کن به کد زیر دقت کن:


Public Class Form1

Dim frm2 As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm2.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm2.Hide()
End Sub
End Class

hakim22
پنج شنبه 24 فروردین 1391, 17:11 عصر
این خطا به فرم ربطی نداره ، به کدهای درون اون ربط داره.
این خطا معمولا در connectionString مربوط به اتصال به سرور مشاهده میشه.
لطفا اطلاعات بیشتری بدید !؟

mahdyari77
پنج شنبه 24 فروردین 1391, 17:12 عصر
نه اصلا از کد هایی که من میزنم نیست یه جای دیگه کار مشکل داره این کد مشکلش کجاست؟
فرم 1:Imports System.Drawing.Printing
Public Class Form1
Dim ocn As New System.Data.OleDb.OleDbConnection
Dim ocm As New System.Data.OleDb.OleDbCommand
Dim oda As New System.Data.OleDb.OleDbDataAdapter
Dim text1 As String
Dim text10 As String
Dim text11 As String
Dim text9 As String
Dim text8 As String
Dim text7 As String
Dim text6 As String
Dim text5 As String
Dim text4 As String
Dim text3 As String
Dim text2 As String
Dim if1 As String
Dim dt As New System.Data.DataTable
Dim startTime As DateTime
Dim number As Integer
Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
Dim my_con As New OleDb.OleDbConnection(cs)
Dim DA As New OleDb.OleDbDataAdapter
Dim endtime As DateTime
Dim endtimeh As String
Dim endtimem As String
Dim saati As String
Dim mini As String
Dim startctime As DateTime
Dim p15 As String
Dim p30 As String
Dim p45 As String
Dim p60 As String
Private Sub printText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
saati = p60
mini = 166
endtime = DateTime.Now
text1 = ":ساعت ورود"
text3 = ":ساعت خروج"
text2 = ":مبلغ"
text4 = startctime.Hour & ":" & startctime.Minute
text11 = startTime.Hour & ":" & startTime.Minute
text5 = ":" & "کد"
text6 = number
text7 = endtime.Hour & ":" & endtime.Minute
endtimeh = endtime.Hour - startctime.Hour
endtimem = endtime.Minute - startctime.Minute
text10 = "ساعتی" & saati & "تومان"
'text9 = endtimem * mini
If endtimem > 5 Then
If endtimem > 15 Then
If endtimem > 30 Then
If endtimem > 45 Then
mini = saati
Else : mini = p45
End If
Else
mini = p30
End If
Else
mini = p15
End If
Else : mini = 0
End If
If endtimem > 5 Then
If endtimem < 15 Then
mini = p15
End If
End If
text8 = endtimeh * saati + mini & " تومان "
If if1 = 0 Then

ev.Graphics.DrawString(text1, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 190)
ev.Graphics.DrawString(text5, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 215)
ev.Graphics.DrawString(text2, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 235)
ev.Graphics.DrawString(text11, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 190)
ev.Graphics.DrawString(text6, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 215)
ev.Graphics.DrawString(text10, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 280, 235)

ElseIf if1 = 1 Then
endtimeh = endtime.Hour - startTime.Hour
endtimem = endtime.Minute - startTime.Minute
ev.Graphics.DrawString(text1, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 190)
ev.Graphics.DrawString(text3, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 205)
ev.Graphics.DrawString(text2, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 235)
ev.Graphics.DrawString(text5, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 480, 260)
ev.Graphics.DrawString(text4, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 190)
ev.Graphics.DrawString(text6, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 260)
ev.Graphics.DrawString(text7, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 205)
ev.Graphics.DrawString(text8, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 380, 235)
Dim ocn As New System.Data.OleDb.OleDbConnection
Dim ocm As New System.Data.OleDb.OleDbCommand
ocn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
ocm.Connection = ocn
ocm.CommandText = "UPDATE t1 SET texh=@p2,texm=@p3,texd=@p4 WHERE tend=@p1"
ocm.Parameters.Clear()
ocm.Parameters.AddWithValue("@p1", startctime)
ocm.Parameters.AddWithValue("@p2", endtimeh)
ocm.Parameters.AddWithValue("@p3", endtimem)
ocm.Parameters.AddWithValue("@p4", endtime)
ocn.Open()
ocm.ExecuteNonQuery()
ocn.Close()
ocm.Dispose()
ocn.Dispose()

End If
ev.HasMorePages = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT saati From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
saati = dr.Item("saati").ToString()
End If

my_con.Close()

End With
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT p515 From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
p15 = dr.Item("p515").ToString()
End If

my_con.Close()

End With
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT p1530 From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
p30 = dr.Item("p1530").ToString()
End If

my_con.Close()

End With
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT p3045 From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
p45 = dr.Item("p3045").ToString()
End If

my_con.Close()

End With
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT saati From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
p60 = dr.Item("saati").ToString()
End If

my_con.Close()

End With

startTime = DateTime.Now
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
Dim prindoc As New PrintDocument
AddHandler prindoc.PrintPage, AddressOf Me.printText
prindoc.Print()
Catch ex As Exception
MessageBox.Show("Error", ex.ToString())
End Try
End Sub

Private Sub btnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnext.Click
End
End Sub



Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub btnvrd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvrd.Click
if1 = "0"
startTime = DateTime.Now
ocn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
ocm.Connection = ocn
ocm.CommandText = "INSERT INTO t1 (tenh,tenm,tend)VALUES(@p1,@p2,@p3)"
ocm.Parameters.Clear()
ocm.Parameters.AddWithValue("@p1", startTime.Hour)
ocm.Parameters.AddWithValue("@p2", startTime.Minute)
ocm.Parameters.AddWithValue("@p3", startTime)
ocn.Open()
ocm.ExecuteNonQuery()
ocn.Close()
ocm.Dispose()
ocn.Dispose()
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text

.CommandText = "SELECT id From t1 WHERE tend=@p1"
.Parameters.Clear()
.Parameters.AddWithValue("@p1", startTime)
.Parameters.AddWithValue("@p2", startTime.Minute)
.Parameters.AddWithValue("@p3", startTime.Date)
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then

number = dr.Item("id").ToString()
End If

my_con.Close()

End With
Try
Dim prindoc As New PrintDocument
AddHandler prindoc.PrintPage, AddressOf Me.printText
prindoc.Print()
Catch ex As Exception
MessageBox.Show("Error", ex.ToString())
End Try
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If txtext.Text = "" Then
MsgBox("لطفا کد وارد کنید", MsgBoxStyle.OkOnly, Nothing)
Else
if1 = 1
ocn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
ocm.Connection = ocn
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT tend From t1 WHERE id=@p1"
.Parameters.Clear()
.Parameters.AddWithValue("@p1", txtext.Text)
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
startctime = dr.Item("tend").ToString()
End If

my_con.Close()

End With

number = Me.txtext.Text
Try
Dim prindoc As New PrintDocument
AddHandler prindoc.PrintPage, AddressOf Me.printText
prindoc.Print()
Catch ex As Exception
MessageBox.Show("Error", ex.ToString())
End Try
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Me.Enabled = False
Form2.Visible = True
End Sub
End Class


فرم دو :
Public Class Form2
Dim pass As String
Dim ocn As New System.Data.OleDb.OleDbConnection
Dim ocm As New System.Data.OleDb.OleDbCommand
Dim oda As New System.Data.OleDb.OleDbDataAdapter
Dim cs As String = ocn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
Dim my_con As New OleDb.OleDbConnection(cs)
Dim DA As New OleDb.OleDbDataAdapter
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = pass Then
Me.Visible = False
Form3.Visible = True
TextBox1.Text = ""
Else
MsgBox("پسوردی که وارد کردید اشتباه است", MsgBoxStyle.OkOnly, "wrongpass")
TextBox1.Text = ""
End If
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ocn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
ocm.Connection = ocn
DA.SelectCommand = New OleDb.OleDbCommand()
With DA.SelectCommand
.Connection = my_con
.CommandType = CommandType.Text
.CommandText = "SELECT pass From setting WHERE id=1"
If .Connection.State <> ConnectionState.Open Then
.Connection.Open()
End If

Dim dr As OleDb.OleDbDataReader
dr = DA.SelectCommand.ExecuteReader()

If dr.Read() Then
pass = dr.Item("pass").ToString()
End If

my_con.Close()

End With
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Visible = False
Form1.Enabled = True
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class

hakim22
پنج شنبه 24 فروردین 1391, 17:31 عصر
این حجم زیاد کد که به کار من نمیاد، نه دیتابیس شما رو دارم نه پروژه شما
ولی با استفاده از debugging و مشخص کردن Break points محل دقیق خطا رو پیدا کنید.
یعنی مشخص کنید بعد از اجرای کدام خط از برنامه ی شما این خطا نمایش داده میشه.
پیشنهاد می کنم از اون خطی که مشکوک هستید نقطه ی شکست بسازید و گام به گام اجرا کنید تا خط خطا مشخص بشه.

mahdyari77
پنج شنبه 24 فروردین 1391, 19:29 عصر
ا یعنی چی خوب وقتی این ارور رو میده که نوشته
form2.visible = true

mahdyari77
پنج شنبه 24 فروردین 1391, 19:44 عصر
اینم برنامه
فایل دیتابیس هم توی فولدر دیباگ هست
http://uploadkon.ir/uploads/71161cf00e1bed5cdbd7add97e05ef3d.zip

Hybrid
پنج شنبه 24 فروردین 1391, 20:10 عصر
اشکال از اعلاناتت بود ، در اصل کانکشن استرینگ ،

به شکل زیر تغییر بده تا درست بشه :


Dim pass As String

Dim ocm As New System.Data.OleDb.OleDbCommand
Dim oda As New System.Data.OleDb.OleDbDataAdapter

Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\db1.mdb"
Dim ocn As New System.Data.OleDb.OleDbConnection(cs)
Dim my_con As New OleDb.OleDbConnection(cs)
Dim DA As New OleDb.OleDbDataAdapter

mahdyari77
پنج شنبه 24 فروردین 1391, 20:19 عصر
هنوزم اون ارور کزایی رو داره
ویرایش:
دستتتتتتتتتتتتتت درررررررررردددددددددددددد دد نکنه درست شد
ایول