المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
السلام عليكم ورحمة الله
يسعد الله اوقاتكم
استفساري عن طريقه تغيير اسم ول Button وفي نفس الوقت تغيير المهام
مثلا
اسم ال Button
add
وعند الضغط يعمل المهام
INSERT INTO
وبعد تنزيل المعلومات يقوم بتغيير اسم Button
الى UPDATE
وعند الضغط يعمل مهام
SQL UPDATE
الفكرة باني عندي Button بعد الضغط عليه يقوم بعمليه ال INSERT INTO
وبعدها محتاج اني اعمل تحديث للمعلومات ان لزم الامر
ان شاءالله قدر اوصل الفكرة
وشكرا لكم
المشاركات : 189
المواضيع 19
الإنتساب : Sep 2012
السمعة :
13
الشكر: 114
تم شكره 144 مرات في 81 مشاركات
صباح الخير
من وجهة نظرى ... يستحسن يكون هناك
زر للاضافة (يقوم بتهيئة الفورم للاضافة )
زر للتعديل والحفظ
تحياتى للجميع
المشاركات : 50
المواضيع 0
الإنتساب : Sep 2018
السمعة :
12
الشكر: 121
تم شكره 181 مرات في 75 مشاركات
كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If sender.Text = "Add" Then
Add()
sender.Text = "Update"
Else
Update()
sender.Text = "Add"
End If
End Sub
Private Sub Add()
MsgBox("Add")
End Sub
Private Sub Update()
MsgBox("Update")
End Sub
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
(16-09-18, 11:23 AM)mmali127 كتب : صباح الخير
من وجهة نظرى ... يستحسن يكون هناك
زر للاضافة (يقوم بتهيئة الفورم للاضافة )
زر للتعديل والحفظ
تحياتى للجميع
اهلا بك شكرا على المشاركه
انا فكرة اعمل زر للاضافه وزر للتعديل
بس قلت اذا في طريقه اخرى افضل
لان هم مجموعة ازرار للاضافه
المشاركات : 189
المواضيع 19
الإنتساب : Sep 2012
السمعة :
13
الشكر: 114
تم شكره 144 مرات في 81 مشاركات
فهمت عليك
تمام كده يكون مشاركة استاذنا 911 تفيذك فى هذه الحالة
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
16-09-18, 11:58 AM
(آخر تعديل لهذه المشاركة : 16-09-18, 11:59 AM {2} بواسطة dubai.eig.)
(16-09-18, 11:42 AM)911 كتب :
كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If sender.Text = "Add" Then
Add()
sender.Text = "Update"
Else
Update()
sender.Text = "Add"
End If
End Sub
Private Sub Add()
MsgBox("Add")
End Sub
Private Sub Update()
MsgBox("Update")
End Sub
تسلم على مشاركتك الكريمه
نعمل عمل الكود معاي بشكل ممتاز
بس انا عندي مع كل زر ثلاث textbox
مثلا الزر الاولي
في
textbox1 textbox2 textbox3
ووقت الاضافه بيكون
كود :
cmdx.Parameters.AddWithValue("@add1", TextBox1.Text)
cmdx.Parameters.AddWithValue("@add2", TextBox2.Text)
cmdx.Parameters.AddWithValue("@add3", TextBox3.Text)
وفي الزر الثاني
textbox4 textbox5 textbox6
ووقت الاضافه بيكون
كود :
cmdx.Parameters.AddWithValue("@add1", TextBox4.Text)
cmdx.Parameters.AddWithValue("@add2", TextBox5.Text)
cmdx.Parameters.AddWithValue("@add3", TextBox6.Text)
يعني في هذه الحاله يجب ان اعمل
كود :
Private Sub Add1()
MsgBox("Add")
End Sub
Private Sub Add2()
MsgBox("Add")
End Sub
Private Sub Add3()
MsgBox("Add")
End Sub
هل هناك طريقه مختصره والا اتوكل على الله واعمل Add1 Add2 Add3
بارك الله فيك وشكرا من جديد
(16-09-18, 11:49 AM)mmali127 كتب : فهمت عليك
تمام كده يكون مشاركة استاذنا 911 تفيذك فى هذه الحالة
كلامك صحيح بارك الله فيك
المشاركات : 50
المواضيع 0
الإنتساب : Sep 2018
السمعة :
12
الشكر: 121
تم شكره 181 مرات في 75 مشاركات
إذا كانت الأسطر كثيرة استخدم DataGridView بثلاث أعمدة TextBox وعمود رابع Button
وهذه كود الاستخدام إن شاء الله تكون واضحة
كود :
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
sender.EndEdit()
If e.ColumnIndex = 3 Then
Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
If btn.FormattedValue = "Add" Then
Add(sender.CurrentRow)
'btn.Style.NullValue = "Update"
Else
Update(sender.CurrentRow)
'btn.Style.NullValue = "Add"
End If
End If
End Sub
Private Sub Add(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Update"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Add Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub
Private Sub Update(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Add"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Update Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
16-09-18, 06:46 PM
(آخر تعديل لهذه المشاركة : 16-09-18, 07:16 PM {2} بواسطة dubai.eig.)
(16-09-18, 01:32 PM)911 كتب :
إذا كانت الأسطر كثيرة استخدم DataGridView بثلاث أعمدة TextBox وعمود رابع Button
وهذه كود الاستخدام إن شاء الله تكون واضحة
كود :
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
sender.EndEdit()
If e.ColumnIndex = 3 Then
Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
If btn.FormattedValue = "Add" Then
Add(sender.CurrentRow)
'btn.Style.NullValue = "Update"
Else
Update(sender.CurrentRow)
'btn.Style.NullValue = "Add"
End If
End If
End Sub
Private Sub Add(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Update"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Add Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub
Private Sub Update(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Add"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Update Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub
احسنت استاذي طريقتك فعلا بتسهل عليه وبتختصر لي الطريق
بس طلع لي مشكله ما عرفت اضبطها كيف اكتب اسم البوت
هو بعد الضغط يتغير الاسم
وشكرا لك
عرفت كيف اكتب الاسم على ال Button
المشاركات : 536
المواضيع 182
الإنتساب : Mar 2016
السمعة :
19
الشكر: 652
تم شكره 264 مرات في 171 مشاركات
الحمدالله كل ضبط تمام
بس واجهتني مشكله
عندما اضغط Add
لاول مربع يضيف المعلومات ويطلع لي رقم ال id --- رقم الاي دي احتاج له في عمليه التحديث
اما في المربع الثاني او الثالث ما يضيف لي المعلومات في القاعده
هذا الكود كامل
يمكن في خلل في الكود ما عرفت اضبطه
كود :
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strca, Opencon))
cmdx = New SQLiteCommand("INSERT INTO DBQTC (d1, d2, d3) Values (@d1,@d2,@d3)") With {
.Connection = conx
}
End Sub
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
sender.EndEdit()
If e.ColumnIndex = 3 Then
Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
If btn.FormattedValue = "Add" Then
Add(sender.CurrentRow)
'btn.Style.NullValue = "Update"
Else
UpdateX1(sender.CurrentRow)
'btn.Style.NullValue = "Add"
End If
End If
End Sub
Private Sub Add(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Update"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
conx.Open()
cmdx.Parameters.AddWithValue("@d1", txt1)
cmdx.Parameters.AddWithValue("@d2", txt2)
cmdx.Parameters.AddWithValue("@d3", txt3)
'------------------------------------
cmdx.CommandText = "SELECT last_insert_rowid()"
NewID = cmdx.ExecuteScalar()
MsgBox(NewID)
MsgBox("Add Row: " & row.Index & vbNewLine &
"txt1: " & txt1 & vbNewLine &
"txt2: " & txt2 & vbNewLine &
"txt3: " & txt3)
conx.Close()
End Sub
Private Sub UpdateX1(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Add"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
Dim UPDATPONT As New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strca, Opencon))
Dim cmdlidXX As New SQLiteCommand("UPDATE DBQTC SET d1=@d1,d2=@d2, d3=@d3 WHERE id=@id ", UPDATPONT)
UPDATPONT.Open()
cmdx.Parameters.AddWithValue("@d1",txt1)
cmdx.Parameters.AddWithValue("@d2", txt1)
cmdx.Parameters.AddWithValue("@d3", txt1)
cmdlidXX.Parameters.AddWithValue("@id", NewID)
cmdlidXX.ExecuteNonQuery()
MsgBox("Update Row: " & row.Index & vbNewLine &
"txt1: " & txt1 & vbNewLine &
"txt2: " & txt2 & vbNewLine &
"txt3: " & txt3)
MsgBox(NewID)
End Sub
بارك الله فيكم
المشاركات : 50
المواضيع 0
الإنتساب : Sep 2018
السمعة :
12
الشكر: 121
تم شكره 181 مرات في 75 مشاركات
كود :
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conx = New SQLiteConnection(String.Format("Data Source= C:\LOG\{0}\DB{1}.s3db", strca, Opencon))
cmdx.Connection = conx
End Sub
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
sender.EndEdit()
If e.ColumnIndex = 3 Then
Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
If btn.FormattedValue = "Add" Then
Add(sender.CurrentRow)
'btn.Style.NullValue = "Update"
Else
UpdateX1(sender.CurrentRow)
'btn.Style.NullValue = "Add"
End If
End If
End Sub
Private Sub Add(row As DataGridViewRow)
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
cmdx.CommandText = "INSERT INTO DBQTC (d1, d2, d3) Values (@d1,@d2,@d3)"
cmdx.Parameters.Clear()
cmdx.Parameters.AddWithValue("@d1", txt1)
cmdx.Parameters.AddWithValue("@d2", txt2)
cmdx.Parameters.AddWithValue("@d3", txt3)
If conx.State <> ConnectionState.Open Then conx.Open()
'------------------------------------
Dim ret As Integer = cmdx.ExecuteNonQuery()
If ret > 0 Then
cmdx.CommandText = "SELECT last_insert_rowid()"
Dim id As Integer = cmdx.ExecuteScalar()
row.Tag = id
MsgBox("تمت الإضافة بنجاح")
row.Cells(3).Style.NullValue = "Update"
End If
'------------------------------------
conx.Close()
End Sub
Private Sub UpdateX1(row As DataGridViewRow)
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
Dim id As String = Val(row.Tag)
cmdx.CommandText = "UPDATE DBQTC SET d1=@d1,d2=@d2, d3=@d3 WHERE id=@id "
cmdx.Parameters.Clear()
cmdx.Parameters.AddWithValue("@d1", txt1)
cmdx.Parameters.AddWithValue("@d2", txt2)
cmdx.Parameters.AddWithValue("@d3", txt3)
cmdx.Parameters.AddWithValue("@id", id)
If conx.State <> ConnectionState.Open Then conx.Open()
Dim ret As Integer = cmdx.ExecuteNonQuery()
conx.Close()
If ret > 0 Then
MsgBox("تم التحديث بنجاح")
row.Cells(3).Style.NullValue = "Add"
End If
End Sub
|