14-03-14, 03:29 PM
المثال بعد التعديل مرفق
اضطريت لعدة حيل لانجاح الفكرة قد توجد طرق افضل لعل احدا يدلنا بها
الكلاس بعد التعديل
اضطريت لعدة حيل لانجاح الفكرة قد توجد طرق افضل لعل احدا يدلنا بها
الكلاس بعد التعديل
كود :
Imports System.Data.OleDb
Public Class Form1
Dim str As String = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\db.accdb"
Dim con As New OleDbConnection(str)
Sub gd()
Dim ds As New DataSet
Dim da As New OleDbDataAdapter("select tn from tb", con)
ds.Clear()
d.DataSource = Nothing
da.Fill(ds, "tb")
d.DataSource = ds
d.DataMember = "tb"
If con.State = ConnectionState.Open Then
con.Close()
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.m = Me.Location
My.Settings.Save()
End
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Location = My.Settings.m
gd()
End Sub
Function isfound(ByVal t As String) As Boolean
Dim sql As New OleDbCommand("select count(tn) from tb where tn=@tn", con)
sql.Parameters.AddWithValue("@tn", t)
If con.State = ConnectionState.Closed Then
con.Open()
End If
If sql.ExecuteScalar > 0 Then
' MsgBox("الاسم موجود", MsgBoxStyle.Critical, "")
Return True
Else
Return False
End If
gd()
If con.State = ConnectionState.Open Then
con.Close()
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each tt In Me.Controls
If TypeOf tt Is TextBox Then
If tt.text.Trim.Replace(" ", "") = "" Then
tt.backcolor = Color.Red
Exit Sub
End If
End If
Next
If TextBox1.Text.Trim.Replace(" ", "").Length < 2 Then Exit Sub
If insert(TextBox1.Text, Val(TextBox2.Text)) Then
MsgBox("الاسم موجود", MsgBoxStyle.Critical, "")
Else
gd()
MsgBox("تم الحفظ", MsgBoxStyle.Information, "")
End If
End Sub
Function insert(ByVal t As String, ByVal m As Integer) As Boolean
If isfound(t) Then
Return True
Else
Dim se As New OleDbCommand("insert into tb(tn,mo) values(@tn,@mo)", con)
se.Parameters.AddWithValue("@tn", t)
se.Parameters.AddWithValue("@mo", Val(m))
If con.State = ConnectionState.Closed Then
con.Open()
End If
Try
se.ExecuteNonQuery()
Return False
Catch ex As Exception
Return True
End Try
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
End Function
Dim t_allow As Boolean = False
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text.Trim.Replace(" ", "") = "" Then
MsgBox("يجب كتابة اسم في مربع النص الخاص بالاسم ", MsgBoxStyle.Critical, "")
TextBox1.Focus()
Exit Sub
End If
If isfound(TextBox1.Text) Then
t_allow = False
TextBox1.BackColor = Color.Red
MsgBox("الاسم محجوز , فضلا جرب اسما آخر ", MsgBoxStyle.Critical, "")
TextBox1.Focus()
Exit Sub
Else
TextBox1.BackColor = Color.White
t_allow = True
TextBox2.Focus()
End If
End Sub
Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.LostFocus
If TextBox1.Text.Trim.Replace(" ", "") = "" Then Exit Sub
If t_allow = False Then Exit Sub
If TextBox2.Text.Trim.Replace(" ", "") = "" Then
MsgBox("يجب كتابة رقم في مربع النص الخاص بالرقم ", MsgBoxStyle.Critical, "")
TextBox2.Focus()
Exit Sub
End If
End Sub
End Classاللهم إني أعوذ بك من غلبة الدين وغلبة العدو، اللهم إني أعوذ بك من جهد البلاء ومن درك الشقاء ومن سوء القضاء ومن شماتة الأعداء
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير

