private void btnDeleteItem_Click(object sender, EventArgs e) { if (DgvSale.Rows.Count >= 1) { int index = DgvSale.SelectedRows[0].Index; DgvSale.Rows.RemoveAt(index); if (DgvSale.Rows.Count <= 0) { txtTotal.Text = "0"; } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvSale.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvSale.Rows[i].Cells[6].Value); DgvSale.ClearSelection(); DgvSale.FirstDisplayedScrollingRowIndex = DgvSale.Rows.Count - 1; DgvSale.Rows[DgvSale.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvSale.Rows.Count).ToString(); } catch (Exception) { } } }
private void txtbarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { DataTable tblItems = new DataTable(); tblItems.Clear(); DataTable tblUnit = new DataTable(); tblUnit.Clear(); tblItems = db.readData("select * from Products where Barcode=N'" + txtbarcode.Text + "'", ""); if (tblItems.Rows.Count >= 1) { try { cbxItems.SelectedValue = Convert.ToInt32(tblItems.Rows[0][0]); string Product_ID = tblItems.Rows[0][0].ToString(); string Product_Name = tblItems.Rows[0][1].ToString(); string Product_Qty = "1"; string Product_Price = "0"; decimal Discount = 0; string Product_Unit = tblItems.Rows[0][14].ToString();; DgvSale.Rows.Add(1); int rowindex = DgvSale.Rows.Count - 1; DgvSale.Rows[rowindex].Cells[0].Value = Product_ID; DgvSale.Rows[rowindex].Cells[1].Value = Product_Name; DgvSale.Rows[rowindex].Cells[3].Value = Product_Qty; DgvSale.Rows[rowindex].Cells[2].Value = Product_Unit; tblUnit = db.readData("select * from Products_Unit where Pro_ID=" + DgvSale.CurrentRow.Cells[0].Value + " and Unit_Name=N'" + DgvSale.CurrentRow.Cells[2].Value + "'", ""); decimal realPrice = 0; try { realPrice = Convert.ToDecimal(tblUnit.Rows[0][5]) / Convert.ToDecimal(tblUnit.Rows[0][3]); } catch (Exception) { } DgvSale.Rows[rowindex].Cells[4].Value = realPrice; decimal total = Convert.ToDecimal(Product_Qty) * Convert.ToDecimal(realPrice); DgvSale.Rows[rowindex].Cells[5].Value = Discount; DgvSale.Rows[rowindex].Cells[6].Value = total; } catch (Exception) { } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvSale.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvSale.Rows[i].Cells[6].Value); DgvSale.ClearSelection(); DgvSale.FirstDisplayedScrollingRowIndex = DgvSale.Rows.Count - 1; DgvSale.Rows[DgvSale.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvSale.Rows.Count).ToString(); } catch (Exception) { } } } }
private void btnItems_Click(object sender, EventArgs e) { if (cbxItems.Text == "اختر منتج") { MessageBox.Show("من فضلك اختر منتج", "تاكيد", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cbxItems.Items.Count <= 0) { MessageBox.Show("من فضلك ادخل المنتجات اولا", "تاكيد", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DataTable tblItems = new DataTable(); tblItems.Clear(); DataTable tblUnit = new DataTable(); tblUnit.Clear(); tblItems = db.readData("select * from Products where Pro_ID=" + cbxItems.SelectedValue + "", ""); if (tblItems.Rows.Count >= 1) { try { string Product_ID = tblItems.Rows[0][0].ToString(); string Product_Name = tblItems.Rows[0][1].ToString(); string Product_Qty = "1"; string Product_Price = "0"; decimal Discount = 0; string Product_Unit = tblItems.Rows[0][14].ToString();; DgvSale.Rows.Add(1); int rowindex = DgvSale.Rows.Count - 1; DgvSale.Rows[rowindex].Cells[0].Value = Product_ID; DgvSale.Rows[rowindex].Cells[1].Value = Product_Name; DgvSale.Rows[rowindex].Cells[3].Value = Product_Qty; DgvSale.Rows[rowindex].Cells[2].Value = Product_Unit; tblUnit = db.readData("select * from Products_Unit where Pro_ID=" + DgvSale.CurrentRow.Cells[0].Value + " and Unit_Name=N'" + DgvSale.CurrentRow.Cells[2].Value + "'", ""); decimal realPrice = 0; try { realPrice = Convert.ToDecimal(tblUnit.Rows[0][5]) / Convert.ToDecimal(tblUnit.Rows[0][3]); } catch (Exception) { } DgvSale.Rows[rowindex].Cells[4].Value = realPrice; decimal total = Convert.ToDecimal(Product_Qty) * Convert.ToDecimal(realPrice); DgvSale.Rows[rowindex].Cells[5].Value = Discount; DgvSale.Rows[rowindex].Cells[6].Value = total; } catch (Exception) { } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvSale.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvSale.Rows[i].Cells[6].Value); DgvSale.ClearSelection(); DgvSale.FirstDisplayedScrollingRowIndex = DgvSale.Rows.Count - 1; DgvSale.Rows[DgvSale.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvSale.Rows.Count).ToString(); } catch (Exception) { } } }