void ProductButton_Click(object sender, EventArgs e) { Button ProductButton = sender as Button; int ProduitID = Convert.ToInt32(ProductButton.Tag); ProduitDAO bd = new ProduitDAO(); Produit p = bd.Find(ProduitID); if (CheckProductAlreadyAdded(ProduitID)) { // MessageBox.Show("Product Alraedy Exists in Datagrid view at Index : " + RowIndex); int Quantity = Convert.ToInt32(dgvProd.Rows[RowIndex].Cells["qte"].Value); decimal Price = Convert.ToInt32(dgvProd.Rows[RowIndex].Cells["prix"].Value); Quantity++; /////////////<Do thisssss...... Important.. Have decimal part in the total price> double TotalPrice = Convert.ToDouble(Quantity * Price); dgvProd.Rows[RowIndex].Cells["qte"].Value = Quantity; dgvProd.Rows[RowIndex].Cells["totalProduit"].Value = TotalPrice; txtTotal.Text = CalculateTotalBill(dgvProd).ToString(); } else { dgvProd.Rows.Add(ProduitID, p.Nom, p.Prix, 1, p.Prix * 1); txtTotal.Text = CalculateTotalBill(dgvProd).ToString(); } }
private void btnConfirme_Click(object sender, EventArgs e) { EmployerDAO empd = new EmployerDAO(); Employer emp2 = empd.Find(user); DateTime auj = DateTime.Now.Date; string d = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime auj2 = DateTime.Parse(d); // Employer emp = new Employer(0,"","","","","","","","","", auj,auj,null); decimal total, don, ret; total = Convert.ToDecimal(txtTotal.Text); don = Convert.ToDecimal(txtmtdonne.Text); ret = Convert.ToDecimal(txtmtretourne.Text); metiers.Ticket m = new metiers.Ticket(idTick, emp2, total, don, ret, auj2); //metiers.Ticket m2 = new metiers.Ticket(emp2, total, don, ret, auj); TicketDAO bd = new TicketDAO(); bd.Add(m); // bd.Add2(m2); metiers.Ticket m2 = bd.Find(Convert.ToInt32(txtnumtick.Text)); foreach (DataGridViewRow Row in dgvProd.Rows) { try { LigneTicketDAO ltb = new LigneTicketDAO(); int ProductId = Convert.ToInt32(Row.Cells["id"].Value); string ProductName = Row.Cells["Nomproduit"].Value.ToString(); decimal ProductPrice = Convert.ToDecimal(Row.Cells["prix"].Value); int ProductQuantity = Convert.ToInt32(Row.Cells["qte"].Value); decimal ProductTotal = Convert.ToDecimal(Row.Cells["totalProduit"].Value); ProduitDAO pb = new ProduitDAO(); Produit p = pb.Find(ProductId); LigneTicket l = new LigneTicket(0, p, m2, ProductName, ProductQuantity, ProductPrice, ProductTotal); ltb.Add(l); } catch { //means Rows are ended } } new Ticket(txtTotal.Text, txtmtdonne.Text, txtmtretourne.Text).ShowDialog(); this.Hide(); UIEmployer f1 = new UIEmployer(user); f1.Show(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (dataGridView1.Columns[e.ColumnIndex].Name == "delete") { if (MessageBox.Show("Are You Sure You Want to Delete this Product\nfrom Database", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { int ProductID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); ProduitDAO pdo = new ProduitDAO(); if (pdo.RemoveProduitbyId(ProductID)) { dataGridView1.Rows.RemoveAt(e.RowIndex); } else if (pdo.RemoveProduitbyId(ProductID)) { MessageBox.Show("Product Not Deleted"); } } } else if (dataGridView1.Columns[e.ColumnIndex].Name == "edit") { int ProductID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); string ProductName = dataGridView1.Rows[e.RowIndex].Cells["nom"].Value.ToString(); decimal ProductPrice = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells["prix"].Value.ToString()); string ProductCategory = dataGridView1.Rows[e.RowIndex].Cells["categorie"].Value.ToString(); string ProductDescription = dataGridView1.Rows[e.RowIndex].Cells["description"].Value.ToString(); byte[] ProductPicture = (byte[])dataGridView1.Rows[e.RowIndex].Cells["image"].Value; UpdateProduit UpdateProductForm = new UpdateProduit(ProductID, ProductName, ProductPrice, ProductCategory, ProductDescription, ProductPicture); if (UpdateProductForm.ShowDialog() == DialogResult.OK) { ProduitDAO pdo = new ProduitDAO(); Produit UpdatedProductDetail = pdo.Find(ProductID); dataGridView1.Rows[e.RowIndex].Cells["nom"].Value = UpdatedProductDetail.Nom; dataGridView1.Rows[e.RowIndex].Cells["prix"].Value = UpdatedProductDetail.Prix; dataGridView1.Rows[e.RowIndex].Cells["categorie"].Value = UpdatedProductDetail.IdCat.Nom; dataGridView1.Rows[e.RowIndex].Cells["description"].Value = UpdatedProductDetail.Description; dataGridView1.Rows[e.RowIndex].Cells["image"].Value = UpdatedProductDetail.Img; } } } }