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()); } } } }
// private void col_dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { // Delete (order) selected in datagridview if (e.ColumnIndex == 0) { string Message = "do you really want to delete this Order ?"; if (MessageBox.Show(Message, "Confirmation Messag", MessageBoxButtons.YesNo) == DialogResult.Yes) { new CustomerOrderLineBLO(db).Delete(Convert.ToInt32(col_dgv.CurrentRow.Cells[2].Value.ToString())); MessageBox.Show("Deleted !!"); col_dgv.DataSource = null; col_dgv.DataSource = new CustomerOrderLineBLO(db).GetCOlByOpType("Order"); if (new CustomerOrderLineBLO(db).GetCOlByOpType("Order").Count() > 0) { // Hide 2 values : ProviderOrderLine_id , ProviderOrder_id col_dgv.Columns[2].Visible = false; col_dgv.Columns[3].Visible = false; } } } //Update (order) selected in datagridview and save changes in the stock if (e.ColumnIndex == 1) { string Message = "Are u want To change it from Order To Sell ?"; if (MessageBox.Show(Message, "Confirmation Messag", MessageBoxButtons.YesNo) == DialogResult.Yes) { // CustomerOrderLine col = new CustomerOrderLine(); // col = new CustomerOrderLineBLO(db).GetByID(Convert.ToInt32(col_dgv.CurrentRow.Cells[2].Value.ToString())); MessageBox.Show(col_dgv.CurrentRow.Cells[5].Value.ToString()); CustomerOrder co = new CustomerOrder(); co = new CustomerOrdersBLO(db).GetByID(Convert.ToInt32(col_dgv.CurrentRow.Cells[3].Value.ToString())); co.OrderState = "Sell"; co.OrderDate = DateTime.Now; new CustomerOrdersBLO(db).Save(co); Article article = new Article(); article = new ArticlesBLO(db).SearchByReference(col_dgv.CurrentRow.Cells[4].Value.ToString())[0]; MessageBox.Show("Quantity Article Before : " + article.Quantity); article.Quantity = article.Quantity - float.Parse(col_dgv.CurrentRow.Cells[5].Value.ToString()); MessageBox.Show("Quantity Article After : " + article.Quantity); col_dgv.DataSource = null; col_dgv.DataSource = new CustomerOrderLineBLO(db).GetCOlByOpType(optype_combo.SelectedItem.ToString()); } } }
// define the datagridview 's article selected // private void articles_dgv_CellContentClick(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 the required quantity is empty we inform the //user to Fill this information before check any item if (articles_dgv.CurrentRow.Cells[1].Value == null) { MessageBox.Show("You Must Fill the Required Quantity Before selecting Any Article ! "); articles_dgv.DataSource = null; articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); } else { // // Get the required quantity value string Rqte = articles_dgv.CurrentRow.Cells[1].Value.ToString(); float RequieredQuantity = float.Parse(Rqte); // Get the Article selected s quantity string qtestock = articles_dgv.CurrentRow.Cells[4].Value.ToString(); float QuantityInStock = float.Parse(qtestock); // compare between the quantity in stock and the quantity filled by the user // in case of the Rrequired quantity > quantity in stock // we inform the user to check the article and fill again the required quantity // with a quantity less then the quantity ins stock if (RequieredQuantity > QuantityInStock) { MessageBox.Show("The Required Quantity must be less than : " + QuantityInStock); articles_dgv.DataSource = null; articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); } // else { // test if the article is already in the virtual sell articles list or not // in case of the article selected is in the already selected // we inform the user to select another article ! if (SelectedArticles.Contains(new ArticlesBLO(db).GetByID(Convert.ToInt32(articles_dgv.CurrentRow.Cells[2].Value)))) { MessageBox.Show("This Article is already in the list !"); articles_dgv.DataSource = null; articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); } else { // define the customer order line and save the changes CustomerOrderLine col = new CustomerOrderLine(); col.Quantity = RequieredQuantity; col.customerOrder = co; col.article = new ArticlesBLO(db).GetByID(Convert.ToInt32(articles_dgv.CurrentRow.Cells[2].Value)); new CustomerOrderLineBLO(db).Save(col); if (co.OrderState == "Sell") { // rduce the article s quantity in stock in state of the article is in state of sell Article article = new ArticlesBLO(db).GetByID(Convert.ToInt32(articles_dgv.CurrentRow.Cells[2].Value)); MessageBox.Show("Quantity Before : " + article.Quantity); article.Quantity = article.Quantity - RequieredQuantity; MessageBox.Show("Quantity After : " + article.Quantity); new ArticlesBLO(db).Save(article); } SelectedArticles.Add(new ArticlesBLO(db).GetByID(Convert.ToInt32(articles_dgv.CurrentRow.Cells[2].Value))); MessageBox.Show("Article : " + col.article.Reference + "\nQuantity : " + col.Quantity); // filled again the datagridview articles_dgv.DataSource = null; articles_dgv.DataSource = new ArticlesBLO(db).GetAll(); // compute the selected articles count articles_count_tb.Text = SelectedArticles.Count().ToString(); //compute the articles selected total price TotalPrice = TotalPrice + (col.Quantity * col.article.SellingPrice); totalPrice_tb.Text = TotalPrice.ToString(); } } } } }