Public Class Purchases
Implements IControlEvent
Public PurchaseOrderID As Long = 0
Public dt As DataTable
Public ds As New DataSet
Private mView As DataView
Dim _theme As Theme
Event Changed()
Private EnteredBy As Long
Dim cmbProductCode As ComboBox
Private pCode As String
Public dv As DataRowView
Public ProductID As Integer = 0
Public ProductIDs As New List(Of Long)
Dim combocolum As New DataGridViewComboBoxColumn
Dim namecombocolum As New DataGridViewComboBoxColumn
Dim PurchaseItemID As Integer = 0
Enum CBO_MODE
NORMAL = 0
EDITABLE = 1
EDITABLE_WITH_NOTIFYCURRENTCELLDIRTY = 2
End Enum
Const ALLOW_ADDS As Boolean = True
Private MODE As CBO_MODE = CBO_MODE.EDITABLE_WITH_NOTIFYCURRENTCELLDIRTY
Public Function Notify(ByVal obj As Object) As Boolean Implements IControlEvent.Notify
Try
PurchaseOrderID = CInt(obj)
FillDetails(PurchaseOrderID)
FillGrid(PurchaseOrderID)
btnDelete.Enabled = True
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
Return False
End Try
Return True
End Function
Private Sub FillDetails(ByVal PurchaseOrderID As Long)
Dim c As New POSCLayer.Purchaseorders
c = POSBLayer.Purchaseorders.GetValue(PurchaseOrderID)
If c IsNot Nothing Then
dtpPurchaseDate.Value = c.PurchaseDate
txtInvoiceNumber.Text = c.InvoiceNumber
txtOrderDetail.Text = c.OrderDetail
txtRemarks.Text = c.Remarks
txtTotalAmount.Text = c.TotalAmount.ToString()
EnteredBy = c.EnteredBy
btnDelete.Enabled = True
End If
End Sub
Public Sub FillGrid(ByVal PurchaseOrderID As Long)
Dim dtgrid As DataTable = POSBLayer.Purchaseitems.GetDataAll(PurchaseOrderID)
Dim j As Integer = 0
dgvPurchaseItems.Rows.Clear()
If dtgrid.Rows.Count > 0 Then
For j = 0 To dtgrid.Rows.Count - 1
dgvPurchaseItems.Rows.Add()
'dgvPurchaseItems("Name", j).Value = dtgrid.Rows(j)("Name").ToString()
dgvPurchaseItems("Quantity", j).Value = dtgrid.Rows(j)("Quantity").ToString()
dgvPurchaseItems("Damaged", j).Value = dtgrid.Rows(j)("Damaged").ToString()
dgvPurchaseItems("Expired", j).Value = dtgrid.Rows(j)("Expired").ToString()
dgvPurchaseItems("PurchaseRate", j).Value = dtgrid.Rows(j)("PurchaseRate").ToString()
dgvPurchaseItems("SellingRate", j).Value = dtgrid.Rows(j)("SellingRate").ToString()
dgvPurchaseItems("Current", j).Value = dtgrid.Rows(j)("Current").ToString()
dgvPurchaseItems("Loose", j).Value = dtgrid.Rows(j)("Loose").ToString()
dgvPurchaseItems("PurchaseItemID", j).Value = dtgrid.Rows(j)("PurchaseItemID").ToString()
dgvPurchaseItems("ProductID", j).Value = dtgrid.Rows(j)("ProductID").ToString()
'Dim combo As DataGridViewComboBoxCell = TryCast(dgvPurchaseItems(0, j), DataGridViewComboBoxCell)
'Dim dt As DataTable = POSBLayer.Products.GetDataAll()
'combo.DataSource = dt
dgvPurchaseItems.Rows(j).Cells(combocolum.Name).Value = dtgrid.Rows(j)("pcode").ToString()
dgvPurchaseItems.Rows(j).Cells(namecombocolum.Name).Value = dtgrid.Rows(j)("Name").ToString()
ProductIDs.Add(CLng(dtgrid.Rows(j)("ProductID").ToString()))
Next
Else
dgvPurchaseItems.Rows.Clear()
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
If txtInvoiceNumber.Text <> "" And
txtOrderDetail.Text <> "" And
txtTotalAmount.Text <> "" Then
Dim data As New POSCLayer.Purchaseorders
data.PurchaseOrderID = PurchaseOrderID
data.PurchaseDate = dtpPurchaseDate.Value
data.OrderDetail = txtOrderDetail.Text
data.Remarks = txtRemarks.Text
data.InvoiceNumber = txtInvoiceNumber.Text
data.TotalAmount = CDec(txtTotalAmount.Text)
If PurchaseOrderID = 0 Then
data.EnteredBy = Config.User.UserID
EnteredBy = Config.User.UserID
Else
data.EnteredBy = EnteredBy
End If
data.ModifiedBy = Config.User.UserID
Dim result As Long = POSBLayer.Purchaseorders.Save(data)
PurchaseOrderID = result
btnNew.Enabled = True
btnDelete.Enabled = False
Dim data1 As New POSCLayer.Purchaseitems
Dim i As Integer = 0
For Each row As DataGridViewRow In dgvPurchaseItems.Rows
If row.Cells("PurchaseItemID").Value IsNot Nothing And
row.Cells("ProductID").Value IsNot Nothing And
row.Cells("Quantity").Value IsNot Nothing And
row.Cells("Damaged").Value IsNot Nothing And
row.Cells("Expired").Value IsNot Nothing And
row.Cells("PurchaseRate").Value IsNot Nothing And
row.Cells("SellingRate").Value IsNot Nothing And
row.Cells("Current").Value IsNot Nothing Then
If row.Cells("PurchaseItemID").Value IsNot Nothing Then
Integer.TryParse(row.Cells("PurchaseItemID").Value.ToString(), PurchaseItemID)
End If
If row.Cells("ProductID").Value IsNot Nothing Then
Integer.TryParse(row.Cells("ProductID").Value.ToString(), ProductID)
End If
data1.PurchaseOrderID = PurchaseOrderID
data1.ProductID = ProductID
Dim dtItems As DataTable = POSBLayer.Purchaseitems.Get_PurchaseItems_ProductID(PurchaseOrderID, ProductID)
If dtItems.Rows.Count > 0 Then
If PurchaseItemID = 0 Then
data1.PurchaseItemID = POSBLayer.Purchaseitems.Get_PurchaseItemsID(PurchaseOrderID, ProductID)
data1.Quantity = Decimal.Parse(row.Cells("Quantity").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("Quantity").ToString())
data1.DamagedQuantity = Decimal.Parse(row.Cells("Damaged").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("DamagedQuantity").ToString())
data1.ExpiredQuantity = Decimal.Parse(row.Cells("Expired").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("ExpiredQuantity").ToString())
data1.PurchasePrice = Decimal.Parse(row.Cells("PurchaseRate").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("PurchasePrice").ToString())
data1.SellingPrice = Decimal.Parse(row.Cells("SellingRate").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("SellingPrice").ToString())
data1.CurrentQuantity = Decimal.Parse(row.Cells("Current").Value.ToString()) + Decimal.Parse(dtItems.Rows(0)("CurrentQuantity").ToString())
data1.CurrentLooseVolume = 0
data1.LooseQuantity = 0
Else
data1.PurchaseItemID = PurchaseItemID
data1.Quantity = Decimal.Parse(row.Cells("Quantity").Value.ToString())
data1.DamagedQuantity = Decimal.Parse(row.Cells("Damaged").Value.ToString())
data1.ExpiredQuantity = Decimal.Parse(row.Cells("Expired").Value.ToString())
data1.PurchasePrice = Decimal.Parse(row.Cells("PurchaseRate").Value.ToString())
data1.SellingPrice = Decimal.Parse(row.Cells("SellingRate").Value.ToString())
data1.CurrentQuantity = Decimal.Parse(row.Cells("Current").Value.ToString())
data1.CurrentLooseVolume = 0
data1.LooseQuantity = 0
End If
Else
data1.PurchaseItemID = PurchaseItemID
data1.Quantity = Decimal.Parse(row.Cells("Quantity").Value.ToString())
data1.DamagedQuantity = Decimal.Parse(row.Cells("Damaged").Value.ToString())
data1.ExpiredQuantity = Decimal.Parse(row.Cells("Expired").Value.ToString())
data1.PurchasePrice = Decimal.Parse(row.Cells("PurchaseRate").Value.ToString())
data1.SellingPrice = Decimal.Parse(row.Cells("SellingRate").Value.ToString())
data1.CurrentQuantity = Decimal.Parse(row.Cells("Current").Value.ToString())
data1.CurrentLooseVolume = 0
data1.LooseQuantity = 0
End If
result = POSBLayer.Purchaseitems.Save(data1)
i = i + 1
End If
Next
RaiseEvent Changed()
MessageBox.Show("Saved successfully.",
"POS",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("Please enter required fields",
"POS",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub Clear()
PurchaseOrderID = 0
dtpPurchaseDate.Value = CDate(Now.ToString("dd-MM-yyyy"))
txtOrderDetail.Text = ""
txtRemarks.Text = ""
txtInvoiceNumber.Text = ""
txtTotalAmount.Text = ""
btnDelete.Enabled = False
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Try
Clear()
dgvPurchaseItems.Rows.Clear()
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Try
Dim checkPurchaseOrderID As Integer = 0
checkPurchaseOrderID = POSBLayer.Purchaseorders.checkPurchaseOrderID(CInt(PurchaseOrderID))
If checkPurchaseOrderID = 0 Then
Dim msgResult As DialogResult = DialogResult.No
msgResult = MessageBox.Show("Are you sure you want to remove the record ?",
Config.MsgTitle,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If msgResult = DialogResult.Yes Then
If txtInvoiceNumber.Text <> "" And
txtOrderDetail.Text <> "" And
txtTotalAmount.Text <> "" Then
Dim result As Integer = CInt(POSBLayer.Purchaseorders.Delete(PurchaseOrderID))
Clear()
RaiseEvent Changed()
Else
MessageBox.Show("Please enter required fields",
Config.MsgTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Else
dtpPurchaseDate.Focus()
End If
Else
MessageBox.Show("Cannot delete, this Purchase Order is already assigned to a Purchase Items.",
Config.MsgTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub Purchases_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim dt As DataTable = POSBLayer.Products.GetDataAll()
combocolum.DefaultCellStyle.Tag = "editable" ' this is the enhance to control if editable or not
combocolum.HeaderText = "Code"
combocolum.DataPropertyName = "ProductID"
combocolum.DataSource = dt
combocolum.DisplayMember = "pcode"
combocolum.ValueMember = "ProductID"
combocolum.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
combocolum.Name = "Product"
combocolum.ValueType = GetType(System.String)
combocolum.Width = 200
dgvPurchaseItems.Columns.Add(combocolum)
'Dim Namecolum As New DataGridViewTextBoxColumn
'Namecolum.HeaderText = "Name"
'Namecolum.Name = "Name"
'Namecolum.ValueType = GetType(System.String)
'Namecolum.Width = 170
'Namecolum.ReadOnly = True
'dgvPurchaseItems.Columns.Add(Namecolum)
namecombocolum.DefaultCellStyle.Tag = "editable" ' this is the enhance to control if editable or not
namecombocolum.HeaderText = "Name"
namecombocolum.DataPropertyName = "ProductID"
namecombocolum.DataSource = dt
namecombocolum.DisplayMember = "NAME"
namecombocolum.ValueMember = "ProductID"
namecombocolum.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
namecombocolum.Name = "Name"
namecombocolum.ValueType = GetType(System.String)
namecombocolum.Width = 170
dgvPurchaseItems.Columns.Add(namecombocolum)
Dim Quantitycolum As New DataGridViewTextBoxColumn
Quantitycolum.HeaderText = "Quantity"
Quantitycolum.Name = "Quantity"
Quantitycolum.ValueType = GetType(System.Decimal)
Quantitycolum.Width = 70
dgvPurchaseItems.Columns.Add(Quantitycolum)
Dim Damagedcolum As New DataGridViewTextBoxColumn
Damagedcolum.HeaderText = "Damaged"
Damagedcolum.Name = "Damaged"
Damagedcolum.ValueType = GetType(System.Decimal)
Damagedcolum.Width = 70
dgvPurchaseItems.Columns.Add(Damagedcolum)
Dim Expiredcolum As New DataGridViewTextBoxColumn
Expiredcolum.HeaderText = "Expired"
Expiredcolum.Name = "Expired"
Expiredcolum.ValueType = GetType(System.Decimal)
Expiredcolum.Width = 70
dgvPurchaseItems.Columns.Add(Expiredcolum)
Dim PurchaseRatecolum As New DataGridViewTextBoxColumn
PurchaseRatecolum.HeaderText = "Purchase Rate"
PurchaseRatecolum.Name = "PurchaseRate"
PurchaseRatecolum.ValueType = GetType(System.Decimal)
PurchaseRatecolum.Width = 110
dgvPurchaseItems.Columns.Add(PurchaseRatecolum)
Dim SellingRatecolum As New DataGridViewTextBoxColumn
SellingRatecolum.HeaderText = "Selling Rate"
SellingRatecolum.Name = "SellingRate"
SellingRatecolum.ValueType = GetType(System.Decimal)
SellingRatecolum.Width = 100
dgvPurchaseItems.Columns.Add(SellingRatecolum)
Dim Currentcolum As New DataGridViewTextBoxColumn
Currentcolum.HeaderText = "Current"
Currentcolum.Name = "Current"
Currentcolum.ValueType = GetType(System.Decimal)
Currentcolum.ReadOnly = True
Currentcolum.Width = 70
dgvPurchaseItems.Columns.Add(Currentcolum)
Dim Loosecolum As New DataGridViewTextBoxColumn
Loosecolum.HeaderText = "Loose"
Loosecolum.Name = "Loose"
Loosecolum.ValueType = GetType(System.Decimal)
Loosecolum.ReadOnly = True
Loosecolum.Width = 70
dgvPurchaseItems.Columns.Add(Loosecolum)
Dim PurchaseItemIDcolum As New DataGridViewTextBoxColumn
PurchaseItemIDcolum.HeaderText = "PurchaseItemID"
PurchaseItemIDcolum.Name = "PurchaseItemID"
PurchaseItemIDcolum.ValueType = GetType(System.Decimal)
PurchaseItemIDcolum.Width = 70
dgvPurchaseItems.Columns.Add(PurchaseItemIDcolum)
Dim ProductIDcolum As New DataGridViewTextBoxColumn
ProductIDcolum.HeaderText = "ProductID"
ProductIDcolum.Name = "ProductID"
ProductIDcolum.ValueType = GetType(System.Decimal)
ProductIDcolum.Width = 70
dgvPurchaseItems.Columns.Add(ProductIDcolum)
Dim Deletecolum As New DataGridViewLinkColumn
Deletecolum.HeaderText = "Delete"
Deletecolum.Name = "Delete"
Deletecolum.Width = 70
Deletecolum.Text = "Delete"
Deletecolum.UseColumnTextForLinkValue = True
dgvPurchaseItems.Columns.Add(Deletecolum)
'Dim Savecolum As New DataGridViewLinkColumn
'Savecolum.HeaderText = "Save"
'Savecolum.Name = "Save"
'Savecolum.Width = 70
'Savecolum.Text = "Save"
'Savecolum.UseColumnTextForLinkValue = True
'dgvPurchaseItems.Columns.Add(Savecolum)
dgvPurchaseItems.RowHeadersVisible = False
dgvPurchaseItems.BackgroundColor = Color.White
dgvPurchaseItems.Columns("PurchaseItemID").Visible = False
dgvPurchaseItems.Columns("ProductID").Visible = False
'Theme.SetGridViewStyle(dgvPurchaseItems)
Theme.SetControlTheme(Me)
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub dgvPurchaseItems_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvPurchaseItems.EditingControlShowing
Try
' Here you control if combobox will be editable or not
If e.CellStyle.Tag Is "editable" Then
Dim dgvPurchaseItems As DataGridView = CType(sender, DataGridView)
If (TypeOf (e.Control) Is ComboBox) Then
Dim cb As ComboBox = CType(e.Control, ComboBox)
If (Not cb Is Nothing) Then
cb.DropDownStyle = ComboBoxStyle.DropDown
cb.AutoCompleteMode = AutoCompleteMode.SuggestAppend
cb.AutoCompleteSource = AutoCompleteSource.ListItems
AddHandler cb.SelectionChangeCommitted, AddressOf cmbProductCodeOnSelectionChangeCommitted
AddHandler cb.LostFocus, AddressOf cmbProductCode_LostFocus
AddHandler cb.Leave, AddressOf cmbProductCode_Leave
If (MODE = CBO_MODE.EDITABLE_WITH_NOTIFYCURRENTCELLDIRTY) Then
' Added thanks to Ying Liu, Microsoft Support
dgvPurchaseItems.NotifyCurrentCellDirty(True)
End If
End If
End If
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub cmbProductCodeOnSelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)
Dim comboBox As DataGridViewComboBoxEditingControl = TryCast(sender, DataGridViewComboBoxEditingControl)
If sender Is Nothing Then
Return
End If
If comboBox.SelectedItem Is Nothing Then
Return
End If
If Me.dgvPurchaseItems.CurrentCell.Value Is comboBox.SelectedItem Then
Return
End If
Me.dgvPurchaseItems.CurrentCell.Value = comboBox.SelectedItem
dv = CType(comboBox.SelectedItem, DataRowView)
pCode = CStr(dv.Item("pcode"))
ProductIDs.Add(CLng(dv.Item("ProductID")))
ProductID = CInt(dv.Item("ProductID"))
End Sub
Private Sub cmbProductCode_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
Dim comboBox As DataGridViewComboBoxEditingControl = TryCast(sender, DataGridViewComboBoxEditingControl)
If sender Is Nothing Then
Return
End If
If comboBox.SelectedItem Is Nothing Then
Return
End If
If Me.dgvPurchaseItems.CurrentCell.Value Is comboBox.SelectedItem Then
Return
End If
Me.dgvPurchaseItems.CurrentCell.Value = comboBox.SelectedItem
dv = CType(comboBox.SelectedItem, DataRowView)
pCode = CStr(dv.Item("pcode"))
ProductIDs.Add(CLng(dv.Item("ProductID")))
ProductID = CInt(dv.Item("ProductID"))
End Sub
Private Sub cmbProductCode_Leave(ByVal sender As Object, ByVal e As EventArgs)
Dim comboBox As DataGridViewComboBoxEditingControl = TryCast(sender, DataGridViewComboBoxEditingControl)
If sender Is Nothing Then
Return
End If
If comboBox.SelectedItem Is Nothing Then
Return
End If
If Me.dgvPurchaseItems.CurrentCell.Value Is comboBox.SelectedItem Then
Return
End If
Me.dgvPurchaseItems.CurrentCell.Value = comboBox.SelectedItem
dv = CType(comboBox.SelectedItem, DataRowView)
pCode = CStr(dv.Item("pcode"))
ProductIDs.Add(CLng(dv.Item("ProductID")))
ProductID = CInt(dv.Item("ProductID"))
End Sub
Private Sub dgvPurchaseItems_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvPurchaseItems.CellEndEdit
Try
Dim j As Integer = e.RowIndex
Dim q As Decimal
Dim d As Decimal
Dim r As Decimal
Dim c As Decimal
Decimal.TryParse(CStr(dgvPurchaseItems.Rows(j).Cells("Quantity").Value), q)
Decimal.TryParse(CStr(dgvPurchaseItems.Rows(j).Cells("Damaged").Value), d)
Decimal.TryParse(CStr(dgvPurchaseItems.Rows(j).Cells("Expired").Value), r)
If q < d + r Then
MessageBox.Show("Enter Quantity greater than Damaged and Expired.",
"POS",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
c = q - (d + r)
End If
dgvPurchaseItems.Rows(j).Cells("Current").Value = c.ToString()
dgvPurchaseItems.Rows(j).Cells("Loose").Value = 0
If ProductID <> 0 Then
dgvPurchaseItems.Rows(j).Cells("ProductID").Value = ProductID
dgvPurchaseItems.Rows(j).Cells("Name").Value = POSBLayer.Purchaseitems.GetProductName(ProductID)
dgvPurchaseItems.Rows(j).Cells("Product").Value = POSBLayer.Purchaseitems.GetProductCode(ProductID)
Else
Name = CStr(dgvPurchaseItems.Rows(j).Cells("Name").Value)
pCode = CStr(dgvPurchaseItems.Rows(j).Cells("Product").Value)
dgvPurchaseItems.Rows(j).Cells("Name").Value = Name
dgvPurchaseItems.Rows(j).Cells("Product").Value = pCode
End If
If dgvPurchaseItems.Rows(j).Cells("PurchaseItemID").Value Is Nothing Then
dgvPurchaseItems.Rows(j).Cells("PurchaseItemID").Value = PurchaseItemID
End If
'Dim data1 As New POSCLayer.Purchaseitems
'data1.PurchaseItemID = CLng(dgvPurchaseItems.Rows(j).Cells(8).Value.ToString())
'data1.PurchaseOrderID = PurchaseOrderID
'data1.ProductID = CLng(dgvPurchaseItems.Rows(j).Cells(9).Value.ToString())
'data1.Quantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Quantity").Value.ToString())
'data1.DamagedQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Damaged").Value.ToString())
'data1.ExpiredQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Expired").Value.ToString())
'data1.PurchasePrice = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("PurchaseRate").Value.ToString())
'data1.SellingPrice = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("SellingRate").Value.ToString())
'data1.CurrentQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Current").Value.ToString())
'data1.CurrentLooseVolume = 0
'data1.LooseQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Loose").Value.ToString())
'Dim result = POSBLayer.Purchaseitems.Save(data1)
'MessageBox.Show("Saved successfully.",
' "POS",
' MessageBoxButtons.OK,
' MessageBoxIcon.Information)
'FillGrid(PurchaseOrderID)
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub dgvPurchaseItems_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvPurchaseItems.CellLeave
Try
'If Not cmbProductCode Is Nothing Then
' pCode = cmbProductCode.Text
' Dim dt As DataTable = POSBLayer.Products.GetDataAll()
' cmbProductCode.DataSource = dt
' cmbProductCode.DisplayMember = "Code"
' cmbProductCode.ValueMember = "ProductID"
' cmbProductCode.SelectedIndex = cmbProductCode.FindStringExact(pCode)
' cmbProductCode.Text = pCode
' cmbProductCode.DroppedDown = False
'End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub dgvPurchaseItems_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvPurchaseItems.CellValidating
Try
Dim dgvPurchaseItems As DataGridView = CType(sender, DataGridView)
If (TypeOf dgvPurchaseItems.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn) Then
Dim comboBoxColumn As DataGridViewComboBoxColumn = CType(dgvPurchaseItems.Columns(e.ColumnIndex), DataGridViewComboBoxColumn)
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
If (ALLOW_ADDS) Then
'Beep() ' Audio confirmation that the item has been added (optional)
'comboBoxColumn.Items.Add(e.FormattedValue)
Else
' How do we cancel?
e.Cancel = True
End If
End If
Else
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub dgvPurchaseItems_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles dgvPurchaseItems.DataError
Try
If e.Exception IsNot Nothing Then
' checking Integer numbers
If dgvPurchaseItems.Columns(e.ColumnIndex).ValueType.ToString() = "System.Int32" Then
MessageBox.Show("Enter only Integer values ")
' checking decimal values
ElseIf dgvPurchaseItems.Columns(e.ColumnIndex).ValueType.ToString() = "System.Decimal" Then
MessageBox.Show("Enter only numbers")
ElseIf dgvPurchaseItems.Columns(e.ColumnIndex).ValueType.ToString() = "System.String" Then
'MessageBox.Show("Enter only numbers")
Else
MessageBox.Show("Enter correct format data. Different format data will not accept")
End If
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
Private Sub dgvPurchaseItems_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvPurchaseItems.CellContentClick
Try
If e.ColumnIndex = 11 Then
Dim j As Integer = e.RowIndex
Dim data1 As New POSCLayer.Purchaseitems
data1.PurchaseItemID = CLng(dgvPurchaseItems.Rows(j).Cells("PurchaseItemID").Value.ToString())
Dim pid = POSBLayer.Purchaseitems.GetPurchaseItemID(data1.PurchaseItemID)
If pid > 0 Then
MessageBox.Show("Cannot delete.",
"POS",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
Dim result = POSBLayer.Purchaseitems.Delete(data1.PurchaseItemID)
MessageBox.Show("Deleted successfully.",
"POS",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
FillGrid(PurchaseOrderID)
End If
Else
'If e.ColumnIndex = 11 Then
' If PurchaseOrderID <> 0 Then
' Dim j As Integer = e.RowIndex
' Dim data1 As New POSCLayer.Purchaseitems
' data1.PurchaseItemID = CLng(dgvPurchaseItems.Rows(j).Cells(8).Value.ToString())
' data1.PurchaseOrderID = PurchaseOrderID
' data1.ProductID = CLng(dgvPurchaseItems.Rows(j).Cells(9).Value.ToString())
' data1.Quantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Quantity").Value.ToString())
' data1.DamagedQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Damaged").Value.ToString())
' data1.ExpiredQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Expired").Value.ToString())
' data1.PurchasePrice = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("PurchaseRate").Value.ToString())
' data1.SellingPrice = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("SellingRate").Value.ToString())
' data1.CurrentQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Current").Value.ToString())
' data1.CurrentLooseVolume = 0
' data1.LooseQuantity = Decimal.Parse(dgvPurchaseItems.Rows(j).Cells("Loose").Value.ToString())
' Dim result = POSBLayer.Purchaseitems.Save(data1)
' MessageBox.Show("Saved successfully.",
' "POS",
' MessageBoxButtons.OK,
' MessageBoxIcon.Information)
' FillGrid(PurchaseOrderID)
' End If
End If
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
End Class
No comments:
Post a Comment