Friend Sub Add(ByVal ParamArray Values() As Object)
conn = New OleDbConnection(Globals.CONN_STR)
conn.Open()
Try
cmd = conn.CreateCommand
trans = conn.BeginTransaction(IsolationLevel.ReadCommitted)
cmd.Connection = conn
cmd.Transaction = trans
Select Case _getdata
Case ReceviedDataType.Ware
cmd.CommandText = "INSERT INTO Ware (wname,amount,wunit,wprice,wcost,wcategory, wnote,wcode) VALUES (?,?,?,?,?,?,?,?)"
cmd.Parameters.Add("wname", OleDbType.VarChar).Value = Values(0)
cmd.Parameters.Add("amount", OleDbType.Double).Value = Values(1)
cmd.Parameters.Add("wunit", OleDbType.VarChar).Value = Values(2)
cmd.Parameters.Add("wprice", OleDbType.Double).Value = Values(3)
cmd.Parameters.Add("wcost", OleDbType.Double).Value = Values(4)
cmd.Parameters.Add("wcategory", OleDbType.VarChar).Value = Values(5)
cmd.Parameters.Add("wnote", OleDbType.LongVarChar).Value = Values(6)
cmd.Parameters.Add("wcode", OleDbType.LongVarChar).Value = Values(7)
cmd.ExecuteNonQuery()
Case ReceviedDataType.Categories
cmd.CommandText = "INSERT INTO Categories (cname,cnote,ccode) VALUES (?,?,?)"
cmd.Parameters.Add("cname", OleDbType.VarChar).Value = Values(0)
cmd.Parameters.Add("cnote", OleDbType.LongVarChar).Value = Values(1)
cmd.Parameters.Add("ccode", OleDbType.VarChar).Value = Values(2)
cmd.ExecuteNonQuery()
Case ReceviedDataType.Dishes
cmd.CommandText = "INSERT INTO Dishes (dname,dprice,dcost,dcreated,dimage,dcategory,dcode) VALUES (?,?,?,?,?,?,?)"
cmd.Parameters.Add("dname", OleDbType.VarChar).Value = Values(0)
cmd.Parameters.Add("dprice", OleDbType.Double).Value = Values(1)
cmd.Parameters.Add("dcost", OleDbType.Double).Value = Values(2)
cmd.Parameters.Add("dcreated", OleDbType.DBTimeStamp).Value = Values(3)
If Values(4) Is Nothing Then
cmd.Parameters.Add("dimage", OleDbType.Binary).Value = DBNull.Value
Else
cmd.Parameters.Add("dimage", OleDbType.Binary).Value = Values(4)
End If
cmd.Parameters.Add("dcategory", OleDbType.VarChar).Value = Values(5)
cmd.Parameters.Add("dcode", OleDbType.VarChar).Value = Values(6)
cmd.ExecuteNonQuery()
Case ReceviedDataType.Components
cmd.CommandText = String.Format("INSERT INTO {0} (mname,mamount,munit,mprice,mwcode) VALUES (?,?,?,?,?)", Values(0))
cmd.Parameters.Add("mname", OleDbType.VarChar).Value = Values(1)
cmd.Parameters.Add("mamount", OleDbType.Double).Value = Values(2)
cmd.Parameters.Add("munit", OleDbType.VarChar).Value = Values(3)
cmd.Parameters.Add("mprice", OleDbType.Double).Value = Values(4)
cmd.Parameters.Add("mwcode", OleDbType.VarChar).Value = Values(5)
cmd.ExecuteNonQuery()
Case ReceviedDataType.Charge
cmd.CommandText = String.Format("INSERT INTO Charge (hname,hamount,hunit,hprice,hcost,hcategory,hnote,hcharge,hdate) SELECT Ware.wname,{0},Ware.wunit,Ware.wprice,Ware.wcost,Ware.wcategory,Ware.wnote,'{1}',DATEVALUE('{2}') FROM Ware WHERE Ware.id={3}", Values(0), Values(1), Values(2), Values(3))
cmd.ExecuteNonQuery()
End Select
trans.Commit()
Catch ex As Exception
trans.Rollback()
If ex.GetType Is GetType(OleDbException) Then
Dim dex As OleDbException = CType(ex, OleDbException)
If dex.ErrorCode = -2147467259 Then
MessageBox.Show("Такой код уще существует.", "Добавление", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Else
MessageBox.Show(ex.Message, "Добавление", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
_exception = True
Finally
conn.Close()
End Try
End Sub
Вот код добавления, взял из одного своих проектов
Удаление по аналогии
Ответить
|