private void LoadGridView() { int id = Convert.ToInt32(lblId.Text); //row = Convert.ToInt32(foodGridView.CurrentRow.Index.ToString()); FIlterFoodDetails foodItem1 = blf.GetFilterFoodItems().Where(sc => sc.Id == id).FirstOrDefault(); int i = frm.dataGridView1.Rows.Count; ////dataGridView1.Rows.Clear(); frm.dataGridView1.Rows.Add(); frm.dataGridView1.Rows[i].Cells["ColSN"].Value = frm.dataGridView1.Rows.Count; frm.dataGridView1.Rows[i].Cells["ColItem"].Value = foodItem1.FoodName; frm.dataGridView1.Rows[i].Cells["ColQty"].Value = 1; ////dataGridView1.Rows[i].Cells["ColQty"].Value = (dataGridView1.Rows[i].Cells["ColQty"] as DataGridViewComboBoxCell).Items[0]; int Qty = Convert.ToInt32(frm.dataGridView1.Rows[i].Cells["ColQty"].Value); frm.dataGridView1.Rows[i].Cells["ColRate"].Value = foodItem1.Price; int Rate = Convert.ToInt32(frm.dataGridView1.Rows[i].Cells["ColRate"].Value); int Total = Qty * Rate; frm.dataGridView1.Rows[i].Cells["ColTotal"].Value = Total; //// foodGridView.Rows[e.RowIndex].Visible = false; //CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[foodGridView.DataSource]; //currencyManager1.SuspendBinding(); //foodGridView.Rows[row].Visible = false; //currencyManager1.ResumeBinding(); //// foodGridView.Rows[row].Visible = false; ////foodGridView.CurrentRow.Visible = false; frm.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = default; }
private void foodGridView_CellClick(object sender, DataGridViewCellEventArgs e) { id = Convert.ToInt32(foodGridView.CurrentRow.Cells[0].Value.ToString()); row = Convert.ToInt32(foodGridView.CurrentRow.Index.ToString()); FIlterFoodDetails foodItem1 = blf.GetFilterFoodItems().Where(sc => sc.Id == id).FirstOrDefault(); int i = dataGridView1.Rows.Count; if (i == 0) { //dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells["ColId"].Value = id; // dataGridView1.Columns["ColId"].Visible = false; dataGridView1.Rows[i].Cells["ColItem"].Value = foodItem1.FoodName; dataGridView1.Rows[i].Cells["ColQty"].Value = 1; //dataGridView1.Rows[i].Cells["ColQty"].Value = (dataGridView1.Rows[i].Cells["ColQty"] as DataGridViewComboBoxCell).Items[0]; int Qty = Convert.ToInt32(dataGridView1.Rows[i].Cells["ColQty"].Value); dataGridView1.Rows[i].Cells["ColRate"].Value = foodItem1.Price; double discountPercentage = Convert.ToDouble(foodItem1.Discount); double discountAmount = (discountPercentage / 100) * Convert.ToDouble(foodItem1.Price); dataGridView1.Rows[i].Cells["ColDiscount"].Value = discountAmount; double Rate = Convert.ToInt32(dataGridView1.Rows[i].Cells["ColRate"].Value); double Total = Qty * Rate; dataGridView1.Rows[i].Cells["ColTotal"].Value = Total; CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[foodGridView.DataSource]; currencyManager1.SuspendBinding(); foodGridView.Rows[row].Visible = false; currencyManager1.ResumeBinding(); this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = default; // code for Bill lblServiceCharge.Text = Properties.Settings.Default.ServiceCharge.ToString(); double sum = 0; double discount = 0; for (int k = 0; k < dataGridView1.Rows.Count; k++) { sum = Convert.ToDouble(dataGridView1.Rows[k].Cells["ColTotal"].Value) + sum; discount = Convert.ToDouble(dataGridView1.Rows[k].Cells["ColDiscount"].Value) + discount; } labelSubTotal.Text = sum.ToString(); lblDiscount.Text = discount.ToString(); double subTotalAfterGettingDiscount = sum - discount; double vatPercentage = Properties.Settings.Default.VAT; double vatAMt = (vatPercentage / 100); lblVat.Text = (vatAMt * subTotalAfterGettingDiscount).ToString(); double subTotal = subTotalAfterGettingDiscount; double vat = Convert.ToDouble(lblVat.Text); double serviceCharge = Properties.Settings.Default.ServiceCharge; //double discountAmt = discount; //double total1 = (subTotal - discount); double total = (subTotalAfterGettingDiscount + vat + serviceCharge); lblTotal.Text = total.ToString(); } else { for (int j = 0; j < dataGridView1.Rows.Count; j++) { if (Convert.ToInt32(dataGridView1.Rows[j].Cells["ColId"].Value) == id) { MessageBox.Show("FoodItem Already Ordered"); // break; return; } } //else //{ //dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells["ColId"].Value = id; // dataGridView1.Columns["ColId"].Visible = false; dataGridView1.Rows[i].Cells["ColItem"].Value = foodItem1.FoodName; dataGridView1.Rows[i].Cells["ColQty"].Value = 1; //dataGridView1.Rows[i].Cells["ColQty"].Value = (dataGridView1.Rows[i].Cells["ColQty"] as DataGridViewComboBoxCell).Items[0]; int Qty = Convert.ToInt32(dataGridView1.Rows[i].Cells["ColQty"].Value); dataGridView1.Rows[i].Cells["ColRate"].Value = foodItem1.Price; double discountPercentage = Convert.ToDouble(foodItem1.Discount); double discountAmount = (discountPercentage / 100) * Convert.ToDouble(foodItem1.Price); dataGridView1.Rows[i].Cells["ColDiscount"].Value = discountAmount; double Rate = Convert.ToInt32(dataGridView1.Rows[i].Cells["ColRate"].Value); double Total = Qty * Rate; dataGridView1.Rows[i].Cells["ColTotal"].Value = Total; CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[foodGridView.DataSource]; currencyManager1.SuspendBinding(); foodGridView.Rows[row].Visible = false; currencyManager1.ResumeBinding(); this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = default; // code for Bill lblServiceCharge.Text = Properties.Settings.Default.ServiceCharge.ToString(); double sum = 0; double discount = 0; for (int k = 0; k < dataGridView1.Rows.Count; k++) { sum = Convert.ToDouble(dataGridView1.Rows[k].Cells["ColTotal"].Value) + sum; discount = Convert.ToDouble(dataGridView1.Rows[k].Cells["ColDiscount"].Value) + discount; } labelSubTotal.Text = sum.ToString(); lblDiscount.Text = discount.ToString(); double subTotalAfterGettingDiscount = sum - discount; double vatPercentage = Properties.Settings.Default.VAT; double vatAMt = (vatPercentage / 100); lblVat.Text = (vatAMt * subTotalAfterGettingDiscount).ToString(); double subTotal = subTotalAfterGettingDiscount; double vat = Convert.ToDouble(lblVat.Text); double serviceCharge = Properties.Settings.Default.ServiceCharge; //double discountAmt = discount; //double total1 = (subTotal - discount); double total = (subTotalAfterGettingDiscount + vat + serviceCharge); lblTotal.Text = total.ToString(); //break; //} // } } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { id1 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()); FIlterFoodDetails foodItem1 = blf.GetFilterFoodItems().Where(sc => sc.Id == id1).FirstOrDefault(); sn = Convert.ToInt32(dataGridView1.CurrentRow.Index.ToString()); int i = dataGridView1.Rows.Count; int num = Convert.ToInt32(dataGridView1.Rows[sn].Cells["ColQty"].Value); if (dataGridView1.Columns[e.ColumnIndex].Name == "Add") { //int num= Convert.ToInt32(dataGridView1.Rows[sn].Cells["ColQty"].Value); //count++; num++; dataGridView1.Rows[sn].Cells["ColQty"].Value = num; int Qty = Convert.ToInt32(dataGridView1.Rows[sn].Cells["ColQty"].Value); double Rate = Convert.ToDouble(dataGridView1.Rows[sn].Cells["ColRate"].Value); double Total = Qty * Rate; double discountPercentage = Convert.ToDouble(foodItem1.Discount); double discountAmount = (discountPercentage / 100) * Total; dataGridView1.Rows[sn].Cells["ColDiscount"].Value = discountAmount; dataGridView1.Rows[sn].Cells["ColTotal"].Value = Total; } if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete") { if (num == 1) { num = 1; } else { num--; } dataGridView1.Rows[sn].Cells["ColQty"].Value = num; int Qty = Convert.ToInt32(dataGridView1.Rows[sn].Cells["ColQty"].Value); double Rate = Convert.ToDouble(dataGridView1.Rows[sn].Cells["ColRate"].Value); double Total = Qty * Rate; double discountPercentage = Convert.ToDouble(foodItem1.Discount); double discountAmount = (discountPercentage / 100) * Total; dataGridView1.Rows[sn].Cells["ColDiscount"].Value = discountAmount; dataGridView1.Rows[sn].Cells["ColTotal"].Value = Total; } if (dataGridView1.Columns[e.ColumnIndex].Name == "Action") { //if (i==1) //{ if (MessageBox.Show("Are You Sure Want to Remove ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { dataGridView1.Rows.RemoveAt(sn); // dataGridView1.Rows[sn].Cells["ColSN"].Value = dataGridView1.Rows.Count; } } double sum = 0; double discount = 0; for (int j = 0; j < dataGridView1.Rows.Count; j++) { sum = Convert.ToDouble(dataGridView1.Rows[j].Cells["ColTotal"].Value) + sum; discount = Convert.ToDouble(dataGridView1.Rows[j].Cells["ColDiscount"].Value) + discount; } labelSubTotal.Text = sum.ToString(); lblDiscount.Text = discount.ToString(); double subTotalAfterGettingDiscount = sum - discount; double vatPercentage = Properties.Settings.Default.VAT; double vatAMt = (vatPercentage / 100); lblVat.Text = (vatAMt * subTotalAfterGettingDiscount).ToString(); double subTotal = subTotalAfterGettingDiscount; double vat = Convert.ToDouble(lblVat.Text); double serviceCharge = Properties.Settings.Default.ServiceCharge; //double discountAmt = discount; //double total1 = (subTotal - discount); double total = (subTotalAfterGettingDiscount + vat + serviceCharge); lblTotal.Text = total.ToString(); }