private void Articles_dgv_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { //We make DataGridCheckBoxColumn commit changes with single click if (e.ColumnIndex == 0 && e.RowIndex >= 0) { this.Articles_dgv.CommitEdit(DataGridViewDataErrorContexts.Commit); } if ((bool)this.Articles_dgv.CurrentCell.Value == true) { // in case of Requierd quantity datagrid view textbox is null if (Articles_dgv.CurrentRow.Cells[2].Value == null) { MessageBox.Show("Vous avez oblige de remplire 'Required Quantity ' avant !"); Articles_dgv.DataSource = null; Articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); } else { // string qte = Articles_dgv.CurrentRow.Cells[2].Value.ToString(); float RequieredQuantity = float.Parse(qte); // ProviderOrderLine pol = new ProviderOrderLine(); pol.Quantity = RequieredQuantity; pol.providerOrder = po; pol.article = new ArticlesBLO(db).GetByID(Convert.ToInt32(Articles_dgv.CurrentRow.Cells[1].Value)); new ProviderOrderLineBLO(db).Save(pol); // if (po.OrderState == "Buy") { Article article = new ArticlesBLO(db).GetByID(Convert.ToInt32(Articles_dgv.CurrentRow.Cells[1].Value)); // MessageBox.Show("Quantity Before : " + article.Quantity); article.Quantity = article.Quantity + RequieredQuantity; MessageBox.Show("Quantity after : " + article.Quantity); new ArticlesBLO(db).Save(article); } // MessageBox.Show("Article : " + pol.article.Reference + "\nQuantity : " + pol.Quantity); // ArticlesList.Add((Article) new ArticlesBLO(db).GetByID(Convert.ToInt32(Articles_dgv.CurrentRow.Cells[1].Value))); // Articles_dgv.DataSource = null; Articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); // articlesCount_tb.Text = ArticlesList.Count.ToString(); // TotalPrice = TotalPrice + (pol.Quantity * pol.article.BuyingPrice); // totalp_tb.Text = TotalPrice.ToString(); } } }
// case delete || update in provider order state = Order private void Operations_dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (comboBox1.SelectedItem.ToString() == "Order") { // case of dalete if (e.ColumnIndex == 0) { // user confirm about the delete operation string messag = "Do You really sure about the delete operation ?"; if (MessageBox.Show(messag, "Confirmation Messag", MessageBoxButtons.YesNo) == DialogResult.Yes) { new ProviderOrderLineBLO(db).Delete(Convert.ToInt32(Operations_dgv.CurrentRow.Cells[2].Value.ToString())); MessageBox.Show("Deleted !!"); // referesh the datagridview after delliting the item selected Operations_dgv.DataSource = null; Operations_dgv.DataSource = new ProviderOrderLineBLO(db).GetPOlByOpType(comboBox1.SelectedItem.ToString()); //Operations_dgv.Columns[2].Visible = false; //Operations_dgv.Columns[3].Visible = false; } } // Update s case if (e.ColumnIndex == 1) { // user s confirm about the operation string messsage = "This Order is already here ?"; if (MessageBox.Show(messsage, "Confirmation Messag", MessageBoxButtons.YesNo) == DialogResult.Yes) { ProviderOrderLine pol = new ProviderOrderLine(); pol = new ProviderOrderLineBLO(db).GetByID(Convert.ToInt32(Operations_dgv.CurrentRow.Cells[2].Value.ToString())); //MessageBox.Show(pol.Id.ToString()); ProviderOrder po = new ProviderOrder(); // change the order state selected form order to buy po = new ProviderOrderBLO(db).GetByID(Convert.ToInt32(Operations_dgv.CurrentRow.Cells[3].Value.ToString())); po.OrderState = "Buy"; po.orderDate = DateTime.Now; new ProviderOrderBLO(db).Save(po); Article article = new Article(); article = new ArticlesBLO(db).SearchByReference(Operations_dgv.CurrentRow.Cells[4].Value.ToString())[0]; MessageBox.Show("Count Article Before " + article.Quantity); // add the quantity selected to the article in stock article.Quantity = article.Quantity + pol.Quantity; MessageBox.Show("Count Article After : " + article.Quantity); // refresh the articles datagridview after this operation Operations_dgv.DataSource = null; Operations_dgv.DataSource = new ProviderOrderLineBLO(db).GetPOlByOpType(comboBox1.SelectedItem.ToString()); } } } }