private void button15_Click(object sender, EventArgs e) { dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); if (dataGridView1.RowCount == 0) { ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } else { dataGridView1.Rows[0].Selected = true; dataGridView1.CurrentCell = dataGridView1[0, 0]; ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } BillGeneration bg = new BillGeneration(); bg.total(this); }
private void button5_Click(object sender, EventArgs e) { decimal total; decimal quantity; Decimal.TryParse(textBox10.Text, out quantity); Billingform bf = (Billingform)frm; try { if (txtBoxDiscount.Text != "") { decimal discount_Price; Decimal.TryParse(txtBoxDiscount.Text + ".00", out discount_Price); total = (quantity * discount_Price); //calculate total when discount price is entered bf.dataGridView1.Rows[bf.dataGridView1.CurrentCell.RowIndex].Cells[6].Value = total; //total //...........................update total,qty & discount decimal sum = 0; int qty = 0; decimal discount = 0; for (int i = 0; i < bf.dataGridView1.Rows.Count; i++) { sum += Convert.ToDecimal(bf.dataGridView1.Rows[i].Cells[6].Value); qty += Convert.ToInt32(bf.dataGridView1.Rows[i].Cells[3].Value); discount += Convert.ToDecimal(bf.dataGridView1.Rows[i].Cells[4].Value); } bf.label7.Text = sum.ToString(); bf.label2.Text = qty.ToString(); bf.label4.Text = discount.ToString(); this.Close(); } else if (textBox1.Text != " ") { decimal presentage; Decimal.TryParse(textBox1.Text, out presentage); if ((presentage > 0 && presentage <= 100)) { decimal price; Decimal.TryParse(textBox8.Text, out price); decimal discount; discount = (price * (presentage / 100)); //calculate discount when presentage is entered total = (quantity * (price - discount)); //calculate total bf.dataGridView1.Rows[bf.dataGridView1.CurrentCell.RowIndex].Cells[4].Value = discount; //discount bf.dataGridView1.Rows[bf.dataGridView1.CurrentCell.RowIndex].Cells[6].Value = total; //total // ..............................................................update labels decimal sum = 0; int qty = 0; decimal discount1 = 0; for (int i = 0; i < bf.dataGridView1.Rows.Count; i++) { sum += Convert.ToDecimal(bf.dataGridView1.Rows[i].Cells[6].Value); qty += Convert.ToInt32(bf.dataGridView1.Rows[i].Cells[3].Value); discount1 += Convert.ToDecimal(bf.dataGridView1.Rows[i].Cells[4].Value); } bf.label7.Text = sum.ToString(); bf.label2.Text = qty.ToString(); bf.label4.Text = discount1.ToString(); this.Close(); } else { MessageBox.Show("Precentage is out of Range"); } } else if (textBox1.Text != " " && txtBoxDiscount.Text != "") { MessageBox.Show("Both Discount Presentage and Discount Price can't be filled"); } else { MessageBox.Show("Discount Presentage or Discount Price Must be Enter"); } } catch (Exception ex) { MessageBox.Show("Please Try Again" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { BillGeneration bill = new BillGeneration(); bill.total(frm); } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------ public void dataGridView1_KeyDown(object sender, KeyEventArgs e) { try { string keyVal; keyVal = e.KeyValue.ToString(); if (int.Parse(keyVal) == 40) { if (dataGridView1.RowCount != 0 || dataGridView1.RowCount != 1) { KeyPressEvent kpe = new KeyPressEvent(); kpe.downArrow("bf", "dgv", this); //mb=ManualBilling, dgv=DataGridView } } else if (int.Parse(keyVal) == 38) { KeyPressEvent kpe = new KeyPressEvent(); kpe.upArrow("bf", "dgv", this); } else if (int.Parse(keyVal) == 13) { KeyPressEvent kpe = new KeyPressEvent(); kpe.enterButton("bf", "dgv", this); } else if (int.Parse(keyVal) == 27) { dataGridView1.Rows[0].Selected = true; dataGridView1.CurrentCell = dataGridView1[0, 0]; ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } else if (int.Parse(keyVal) == 46) { dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex); if (dataGridView1.RowCount == 0) { ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } else { dataGridView1.Rows[0].Selected = true; dataGridView1.CurrentCell = dataGridView1[0, 0]; ActiveControl = txtBoxDescription; // focus on Description textbox dataGridView1.BorderStyle = BorderStyle.Fixed3D; //change borderStyle to identify active control txtBoxDescription.BorderStyle = BorderStyle.FixedSingle; //change borderStyle to identify active control txtBoxDescription.Select(txtBoxDescription.Text.Length, 0); //move cursor into the end of text in the textbox } BillGeneration bg = new BillGeneration(); bg.total(this); } else { if (int.Parse(keyVal) < 65 && int.Parse(keyVal) > 105 && int.Parse(keyVal) != 32) { SystemSounds.Hand.Play(); } } } catch (Exception exc) { MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }