Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
Using Conn As SqlConnection = New SqlConnection(ConnectionStr)
Conn.Open()
Dim transaction As SqlTransaction = Conn.BeginTransaction(IsolationLevel.ReadCommitted)
Dim command As SqlCommand = Conn.CreateCommand()
command.Transaction = transaction
If CboDepartment.Text = "" Then
MsgBox("Field Must Be Select - Department")
CboDepartment.Focus()
Exit Sub
End If
If CboRawmaterial.Text = "" Then
MsgBox("Field Must Be Select - Rawmaterial ")
CboRawmaterial.Focus()
Exit Sub
End If
If CboCategory.Text = "" Then
MsgBox("Field Must Be Select - Category ")
CboCategory.Focus()
Exit Sub
End If
If CboSubCategory.Text = "" Then
MsgBox("Field Must Be Select - SubCategory ")
CboSubCategory.Focus()
Exit Sub
End If
DeptId = CInt(Mid(CboDepartment.Text, (InStrRev(CboDepartment.Text, "|") + 1), Len(CboDepartment.Text)))
MatlId = CInt(Mid(CboRawmaterial.Text, (InStrRev(CboRawmaterial.Text, "|") + 1), Len(CboRawmaterial.Text)))
CatId = CInt(Mid(CboCategory.Text, (InStrRev(CboCategory.Text, "|") + 1), Len(CboCategory.Text)))
SubCatId = CInt(Mid(CboSubCategory.Text, (InStrRev(CboSubCategory.Text, "|") + 1), Len(CboSubCategory.Text)))
Try
command.CommandText = "Insert into RawmaterialMappingMaster (TranId,LocationId,DeptId,MatlId,CatId,SubCatId,CreatedBy,CreatedDate,CreatedSystem) " _
& " values ('" & DeptId & "','" & MatlId & "','" & CatId & "','" & SubCatId & "','" & UserId & "', '" & Now & "', '" & UserComp & "')"
command.ExecuteNonQuery()
DGRmMappingMaster.Rows.Add()
n = DGRmMappingMaster.RowCount - 1
DGRmMappingMaster.Rows.Item(n).Cells("Department").Value = CboDepartment.Text
DGRmMappingMaster.Rows.Item(n).Cells("Rawmaterial").Value = CboRawmaterial.Text
DGRmMappingMaster.Rows.Item(n).Cells("Category").Value = CboCategory.Text
DGRmMappingMaster.Rows.Item(n).Cells("SubCategory").Value = CboSubCategory.Text
MsgBox("Saved Successfuly")
transaction.Commit()
Catch ex As Exception
transaction.Rollback()
MsgBox(Err.Description)
MsgBox("Error while processing. Previous execution was rollback")
End Try
End Using
Exit Sub
End Sub
Using Conn As SqlConnection = New SqlConnection(ConnectionStr)
Conn.Open()
Dim transaction As SqlTransaction = Conn.BeginTransaction(IsolationLevel.ReadCommitted)
Dim command As SqlCommand = Conn.CreateCommand()
command.Transaction = transaction
If CboDepartment.Text = "" Then
MsgBox("Field Must Be Select - Department")
CboDepartment.Focus()
Exit Sub
End If
If CboRawmaterial.Text = "" Then
MsgBox("Field Must Be Select - Rawmaterial ")
CboRawmaterial.Focus()
Exit Sub
End If
If CboCategory.Text = "" Then
MsgBox("Field Must Be Select - Category ")
CboCategory.Focus()
Exit Sub
End If
If CboSubCategory.Text = "" Then
MsgBox("Field Must Be Select - SubCategory ")
CboSubCategory.Focus()
Exit Sub
End If
DeptId = CInt(Mid(CboDepartment.Text, (InStrRev(CboDepartment.Text, "|") + 1), Len(CboDepartment.Text)))
MatlId = CInt(Mid(CboRawmaterial.Text, (InStrRev(CboRawmaterial.Text, "|") + 1), Len(CboRawmaterial.Text)))
CatId = CInt(Mid(CboCategory.Text, (InStrRev(CboCategory.Text, "|") + 1), Len(CboCategory.Text)))
SubCatId = CInt(Mid(CboSubCategory.Text, (InStrRev(CboSubCategory.Text, "|") + 1), Len(CboSubCategory.Text)))
Try
command.CommandText = "Insert into RawmaterialMappingMaster (TranId,LocationId,DeptId,MatlId,CatId,SubCatId,CreatedBy,CreatedDate,CreatedSystem) " _
& " values ('" & DeptId & "','" & MatlId & "','" & CatId & "','" & SubCatId & "','" & UserId & "', '" & Now & "', '" & UserComp & "')"
command.ExecuteNonQuery()
DGRmMappingMaster.Rows.Add()
n = DGRmMappingMaster.RowCount - 1
DGRmMappingMaster.Rows.Item(n).Cells("Department").Value = CboDepartment.Text
DGRmMappingMaster.Rows.Item(n).Cells("Rawmaterial").Value = CboRawmaterial.Text
DGRmMappingMaster.Rows.Item(n).Cells("Category").Value = CboCategory.Text
DGRmMappingMaster.Rows.Item(n).Cells("SubCategory").Value = CboSubCategory.Text
MsgBox("Saved Successfuly")
transaction.Commit()
Catch ex As Exception
transaction.Rollback()
MsgBox(Err.Description)
MsgBox("Error while processing. Previous execution was rollback")
End Try
End Using
Exit Sub
End Sub
No comments:
Post a Comment