private void btnDeleteItem_Click(object sender, EventArgs e) { if (DgvBuy.Rows.Count >= 1) { int index = DgvBuy.SelectedRows[0].Index; DgvBuy.Rows.RemoveAt(index); if (DgvBuy.Rows.Count <= 0) { txtTotal.Text = "0"; } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvBuy.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvBuy.Rows[i].Cells[6].Value); DgvBuy.ClearSelection(); DgvBuy.FirstDisplayedScrollingRowIndex = DgvBuy.Rows.Count - 1; DgvBuy.Rows[DgvBuy.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvBuy.Rows.Count).ToString(); } catch (Exception) { } } }
private void txtbarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { DataTable tblItems = new DataTable(); tblItems.Clear(); DataTable tblPrice = new DataTable(); tblPrice.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.ToDecimal(tblItems.Rows[0][0]); } catch (Exception) { } try { int countQty = 0; try { countQty = Convert.ToInt32(db.readData("select sum (Pro_ID) from Products_Qty where Pro_ID=" + cbxItems.SelectedValue + "", "").Rows[0][0]); } catch (Exception) { } tblPrice = db.readData("select * from Products_Qty where Pro_ID=" + cbxItems.SelectedValue + "", ""); string Product_ID = tblItems.Rows[0][0].ToString(); string Product_Name = tblItems.Rows[0][1].ToString(); string Product_Qty = "1"; string Product_Price = tblPrice.Rows[countQty - 1][4].ToString(); string Product_Unit = tblItems.Rows[0][16].ToString(); decimal Discount = 0; DgvBuy.Rows.Add(1); int rowindex = DgvBuy.Rows.Count - 1; DgvBuy.Rows[rowindex].Cells[0].Value = Product_ID; DgvBuy.Rows[rowindex].Cells[1].Value = Product_Name; DgvBuy.Rows[rowindex].Cells[2].Value = Product_Unit; DgvBuy.Rows[rowindex].Cells[3].Value = Product_Qty; tblunit = db.readData("select * from Products_Unit where Pro_ID=" + DgvBuy.CurrentRow.Cells[0].Value + " and Unit_Name=N'" + DgvBuy.CurrentRow.Cells[2].Value + "'", ""); decimal realPrice = 0; try { realPrice = Convert.ToDecimal(Product_Price) / Convert.ToDecimal(tblunit.Rows[0][3]); } catch (Exception) { } decimal total = Convert.ToDecimal(Product_Qty) * Convert.ToDecimal(realPrice); DgvBuy.Rows[rowindex].Cells[4].Value = Math.Round(realPrice, 2); DgvBuy.Rows[rowindex].Cells[5].Value = Discount; DgvBuy.Rows[rowindex].Cells[6].Value = Math.Round(total, 2); } catch (Exception) { } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvBuy.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvBuy.Rows[i].Cells[6].Value); DgvBuy.ClearSelection(); DgvBuy.FirstDisplayedScrollingRowIndex = DgvBuy.Rows.Count - 1; DgvBuy.Rows[DgvBuy.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvBuy.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 tblPrice = new DataTable(); tblPrice.Clear(); DataTable tblunit = new DataTable(); tblunit.Clear(); tblItems = db.readData("select * from Products where Pro_ID=" + cbxItems.SelectedValue + "", ""); if (tblItems.Rows.Count >= 1) { try { int countQty = 0; try { countQty = Convert.ToInt32(db.readData("select sum (Pro_ID) from Products_Qty where Pro_ID=" + cbxItems.SelectedValue + "", "").Rows[0][0]); } catch (Exception) { } tblPrice = db.readData("select * from Products_Qty where Pro_ID=" + cbxItems.SelectedValue + "", ""); string Product_ID = tblItems.Rows[0][0].ToString(); string Product_Name = tblItems.Rows[0][1].ToString(); string Product_Qty = "1"; string Product_Price = tblPrice.Rows[countQty - 1][4].ToString(); string Product_Unit = tblItems.Rows[0][16].ToString(); decimal Discount = 0; DgvBuy.Rows.Add(1); int rowindex = DgvBuy.Rows.Count - 1; DgvBuy.Rows[rowindex].Cells[0].Value = Product_ID; DgvBuy.Rows[rowindex].Cells[1].Value = Product_Name; DgvBuy.Rows[rowindex].Cells[2].Value = Product_Unit; DgvBuy.Rows[rowindex].Cells[3].Value = Product_Qty; tblunit = db.readData("select * from Products_Unit where Pro_ID=" + DgvBuy.CurrentRow.Cells[0].Value + " and Unit_Name=N'" + DgvBuy.CurrentRow.Cells[2].Value + "'", ""); decimal realPrice = 0; try { realPrice = Convert.ToDecimal(Product_Price) / Convert.ToDecimal(tblunit.Rows[0][3]); } catch (Exception) { } decimal total = Convert.ToDecimal(Product_Qty) * Convert.ToDecimal(realPrice); DgvBuy.Rows[rowindex].Cells[4].Value = Math.Round(realPrice, 2); DgvBuy.Rows[rowindex].Cells[5].Value = Discount; DgvBuy.Rows[rowindex].Cells[6].Value = Math.Round(total, 2); } catch (Exception) { } try { decimal TotalOrder = 0; for (int i = 0; i <= DgvBuy.Rows.Count - 1; i++) { TotalOrder += Convert.ToDecimal(DgvBuy.Rows[i].Cells[6].Value); DgvBuy.ClearSelection(); DgvBuy.FirstDisplayedScrollingRowIndex = DgvBuy.Rows.Count - 1; DgvBuy.Rows[DgvBuy.Rows.Count - 1].Selected = true; } txtTotal.Text = Math.Round(TotalOrder, 2).ToString(); lblItemsCount.Text = (DgvBuy.Rows.Count).ToString(); } catch (Exception) { } } }