private void Billingform_Load(object sender, EventArgs e) { this.KeyPreview = true; this.textBox2.KeyDown += new KeyEventHandler(textBox2_KeyDown); this.textBox3.KeyDown += new KeyEventHandler(textBox3_KeyDown); this.txtBoxDescription.KeyDown += new KeyEventHandler(txtBoxDescription_KeyDown); this.txtBoxCode.KeyDown += new KeyEventHandler(txtBoxCode_KeyDown); this.dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown); this.ActiveControl = txtBoxCode; //this.ActiveControl = txtBoxDescription; //focus on Description textbox BillGeneration bf = new BillGeneration(); textBox1.Text = bf.BillNoGen(this).ToString(); //call to BillNoGen function timer1 = new Timer(); timer1.Interval = 1000; timer1.Tick += new EventHandler(timer1_Tick); timer1.Start(); //initialize timer label16.Text = user_name; }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- private void timer1_Tick(object sender, EventArgs e) { try { BillGeneration bf = new BillGeneration(); label9.Text = bf.Date(this).ToString() + " "; //call to Date function } catch (Exception exc) { MessageBox.Show("Error Occured, Please Try Again, " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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) { int qty = int.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value.ToString()); string code = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString(); 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.update_qty(this, qty, code); } 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); } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------ public void textBox3_KeyDown(object sender, KeyEventArgs e) { string keyVal = e.KeyValue.ToString(); if (int.Parse(keyVal) == 13 && textBox3.Text != "") { decimal tot; decimal cash; Decimal.TryParse(textBox3.Text, out cash); Decimal.TryParse(label7.Text, out tot); if (cash < tot) { MessageBox.Show("Cash value is lesser than Total Invoice amount", "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { label14.Text = (cash - tot).ToString(); } //call print function //if (PrintClass.printfunction()) //{ BillGeneration bg = new BillGeneration(); bg.billToDB(this); //} } else if (int.Parse(keyVal) == 110) //validate dot--------------------------------------------------------------- { string dot = "."; textBox3.Text = textBox3.Text + dot; textBox3.Select(textBox3.Text.Length, 0); } else if (int.Parse(keyVal) == 8) //validate BackSpace--------------------------------------------------------------- { if (textBox3.Text.Length > 0) //check is there any text in the textbox { string text = textBox3.Text; text = text.Substring(0, text.Length - 1); //remove last character from the text of the textbox textBox3.Text = text; textBox3.Select(textBox3.Text.Length, 0); //move cursor into the end of text in the textbox } else { SystemSounds.Hand.Play(); } } else if (int.Parse(keyVal) > 95 && int.Parse(keyVal) < 106) { string num = e.KeyCode.ToString(); num = num.Substring(6, num.Length - 6); textBox3.Text = textBox3.Text + num; textBox3.Select(textBox3.Text.Length, 0); } else if (int.Parse(keyVal) == 27) { this.ActiveControl = txtBoxDescription; textBox3.Text = ""; } else { SystemSounds.Hand.Play(); } }