كود :
Imports System.Data.OleDb
Public Class MaterialsAdd
Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DB.mdb;Jet OLEDB:Database Password=343282"
Dim Conn As New OleDbConnection(ConStr)
Dim DatasatMORD As New DataSet
Dim SQLMORD As String = "Select * from MORD"
Dim DataSetMaterials As New DataSet
Dim SQLMaterials As String = "Select * from Materials"
Dim DataSNF As New DataSet
Dim SQLSNF As String = "Select * from TaCategory"
Sub fill_comb()
DatasatMORD.Clear()
Conn.Open()
Dim DataAdapterLevels As New OleDbDataAdapter(SQLMORD, Conn)
DataAdapterLevels.Fill(DatasatMORD, "MORD")
Conn.Close()
Mwrd.DataSource = DatasatMORD.Tables("MORD")
Mwrd.ValueMember = "IDMO"
Mwrd.DisplayMember = "NEM"
Mwrd.Text = ""
CSNF.DataBindings.Clear()
DataSNF.Clear()
Conn.Open()
Dim dataadapter1 As New OleDbDataAdapter(SQLSNF, Conn)
dataadapter1.Fill(DataSNF, "TaCategory")
Conn.Close()
CSNF.DataSource = DataSNF.Tables("TaCategory")
CSNF.DisplayMember = "CatName"
CSNF.ValueMember = "CatID"
CSNF.Text = ""
End Sub
' Sub fill_CWH()
' CWH.DataBindings.Clear()
' DataSetMaterials.Clear()
' Conn.Open()
' Dim dataadapter1 As New OleDbDataAdapter(SQLMaterials, Conn)
' dataadapter1.Fill(DataSetMaterials, "Materials")
' Conn.Close()
' CWH.DataSource = DataSetMaterials.Tables("Materials")
' CWH.DisplayMember = "WAHDA"
' CWH.ValueMember = "MID"
' CWH.Text = ""
' End Sub
Private Sub TxTQuantityAvailable_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxTQuantityAvailable.KeyPress
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub TxTWholesalePrice_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub TxTSellingPrice_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Dispose()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TxTMaterialBarCode.Text = "" Then
MsgBox("إدخل رقم البار كود")
Exit Sub
End If
If TxTMaterialName.Text = "" Then
MsgBox("إدخل اسم المادة")
Exit Sub
End If
If TxTQuantityAvailable.Text = "" Then
MsgBox("إدخل الكمية المتوفرة لديك من المادة")
Exit Sub
End If
If TxTWholesalePrice.Text = "" Or TxTSellingPrice.Text = "" Then
MsgBox("إدخل سعر البيع او سعر الجملة")
Exit Sub
End If
Try
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = Conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO Materials (MaterialBarCode, SANF, MaterialName, WAHDA, QuantityAvailable, WholesalePrice, SellingPrice, DataMa, Rabh, Ml, MORD, DownPrice) VALUES (@MaterialBarCode, @SANF, @MaterialName ,@WAHDA, @QuantityAvailable, @WholesalePrice, @SellingPrice, @DataMa, @Rabh, @Ml, @MORD, @DownPrice)"
cmd.Parameters.AddWithValue("@MaterialBarCode", TxTMaterialBarCode.Text.Trim)
cmd.Parameters.AddWithValue("@SANF", CSNF.Text.Trim)
cmd.Parameters.AddWithValue("@MaterialName", TxTMaterialName.Text.Trim)
cmd.Parameters.AddWithValue("@WAHDA", CWH.Text.Trim)
cmd.Parameters.AddWithValue("@QuantityAvailable", TxTQuantityAvailable.Text.Trim)
cmd.Parameters.AddWithValue("@WholesalePrice", TxTWholesalePrice.Text.Trim)
cmd.Parameters.AddWithValue("@SellingPrice", TxTSellingPrice.Text.Trim)
cmd.Parameters.AddWithValue("@DataMa", DataM.Text.Trim)
cmd.Parameters.AddWithValue("@Rabh", Rabh.Text.Trim)
cmd.Parameters.AddWithValue("@Ml", Note.Text.Trim)
cmd.Parameters.AddWithValue("@MORD", Mwrd.Text.Trim)
cmd.Parameters.AddWithValue("@DownPrice", TextBox1.Text.Trim)
cmd.ExecuteScalar()
Conn.Close()
TxTMaterialBarCode.Text = ""
TxTMaterialName.Text = ""
TxTQuantityAvailable.Text = ""
TxTWholesalePrice.Text = ""
TxTSellingPrice.Text = ""
CSNF.Text = ""
Note.Text = ""
CWH.Text = ""
Mwrd.Text = ""
TextBox1.Text = ""
TxTMaterialBarCode.Focus()
MsgBox("تم إضافة المادة بنجاح")
Materials.LoadMaterials()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
End Sub
Private Sub TxTSellingPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TxTQuantityAvailable_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxTQuantityAvailable.TextChanged
End Sub
Private Sub TxTMaterialBarCode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxTMaterialBarCode.KeyPress
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SANF.ShowDialog()
End Sub
Private Sub FormMaterialsAdd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fill_comb()
' fill_CWH()
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub GroupBox2_Enter(sender As Object, e As EventArgs)
End Sub
Private Sub CSNF_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CSNF.SelectedIndexChanged
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
DataM.Text = ""
DataMp.Enabled = False
Else
DataM.Text = DataMp.Text
DataMp.Enabled = True
End If
End Sub
Private Sub DataMp_ValueChanged(sender As Object, e As EventArgs) Handles DataMp.ValueChanged
DataM.Text = DataMp.Text
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TxTWholesalePrice.TextChanged
If TxTSellingPrice.Text = "" Then
Rabh.Text = "00.00"
Else
Rabh.Text = Val(TxTSellingPrice.Text) - Val(TxTWholesalePrice.Text)
End If
End Sub
Private Sub TextBox1_TextChanged_1(sender As Object, e As EventArgs) Handles TxTSellingPrice.TextChanged
Rabh.Text = Val(TxTSellingPrice.Text) - Val(TxTWholesalePrice.Text)
End Sub
End Class