Please i needs codes to calculate 5% Vat and 1% stamp duty on every transaction in my sales invoice.
your kind gesture will be appreciated.
Thank you
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace NSPM_Sales_Invoice
- {
- public partial class frmNewBill: Form
- {
- SqlConnection con = new SqlConnection(Properties.Settings.Default.NSPM_Sales_InvoiceCon);
- SqlCommand cmd;
- public frmNewBill()
- {
- InitializeComponent();
- txtDeleteUpdate.Visible = false;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void frmNewBill_Load(object sender, EventArgs e)
- {
- cmbDescription.Items.Clear();
- con.Open();
- cmd = con.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "Select ProName from tbl_Products order by ProName asc";
- cmd.ExecuteNonQuery();
- DataTable dt = new DataTable();
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(dt);
- foreach(DataRow dr in dt.Rows)
- {
- cmbDescription.Items.Add(dr["ProName"].ToString());
- }
- con.Close();
- dataGridView1.Columns[5].Visible = false;
- dataGridView1.Columns[6].Visible = false;
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- if (cmbDescription.Text == "")
- {
- MessageBox.Show("Description is Empty");
- } else if (txtQuantity.Text == "")
- {
- MessageBox.Show("Quantity is Empty");
- } else if (txtUnitPrice.Text == "")
- {
- MessageBox.Show("Unit Price is Empty");
- } else if (txtJobNo.Text == "")
- {
- MessageBox.Show("JobNo is Empty");
- if (txtDeleteUpdate.Text == "")
- {
- int row = 0;
- dataGridView1.Rows.Add();
- row = dataGridView1.Rows.Count - 1;
- dataGridView1["Description", row].Value = cmbDescription.Text;
- dataGridView1["Quantity", row].Value = txtQuantity.Text;
- dataGridView1["UnitPrice", row].Value = txtUnitPrice.Text;
- dataGridView1["GoodValue", row].Value = txtGoodValue.Text;
- dataGridView1["JobNo", row].Value = txtJobNo.Text;
- dataGridView1["Date", row].Value = dateTimePicker1.Value.ToString("dd-MM-yyyy");
- dataGridView1.Refresh();
- cmbDescription.Focus();
- if (dataGridView1.Rows.Count > 0)
- {
- dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1];
- }
- } else
- {
- btnAdd.Text = "UPDATE";
- int i = 0;
- DataGridViewRow row = dataGridView1.Rows[i];
- row.Cells[1].Value = cmbDescription.Text;
- row.Cells[2].Value = txtQuantity.Text;
- row.Cells[3].Value = txtUnitPrice.Text;
- row.Cells[4].Value = txtGoodValue.Text;
- row.Cells[5].Value = txtJobNo.Text;
- btnAdd.Text = "ADD";
- }
- cleartextbox();
- gridGoodValue();
- }
- }
- private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = (e.RowIndex + 1).ToString();
- }
- int i;
- private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- i = e.RowIndex;
- DataGridViewRow row = dataGridView1.Rows[i];
- cmbDescription.Text = row.Cells[1].Value.ToString();
- txtQuantity.Text = row.Cells[2].Value.ToString();
- txtUnitPrice.Text = row.Cells[3].Value.ToString();
- txtGoodValue.Text = row.Cells[4].Value.ToString();
- txtDeleteUpdate.Text = row.Cells[0].Value.ToString();
- btnAdd.Text = "UPDATE";
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- if (txtDeleteUpdate.Text == "")
- {
- MessageBox.Show("Select Product to Delete");
- } else
- {
- foreach(DataGridViewRow row in dataGridView1.SelectedRows)
- {
- if (!row.IsNewRow) dataGridView1.Rows.Remove(row);
- }
- }
- btnAdd.Text = "ADD";
- gridGoodValue();
- cleartextbox();
- }
- public void cleartextbox()
- {
- cmbDescription.Text = "";
- txtQuantity.Text = "";
- txtUnitPrice.Text = "";
- txtGoodValue.Text = "";
- txtJobNo.Text = "";
- txtDeleteUpdate.Text = "";
- }
- public void CalGoodValue()
- {
- double a1, b1, i;
- double.TryParse(txtUnitPrice.Text, out a1);
- double.TryParse(txtQuantity.Text, out b1);
- i = a1 * b1;
- if (1 > 0)
- {
- txtGoodValue.Text = i.ToString("C").Remove(0, 1);
- }
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void txtQuantity_Leave(object sender, EventArgs e)
- {
- CalGoodValue();
- }
- private void txtQuantity_TextChanged(object sender, EventArgs e)
- {
- }
- private void txtUnitPrice_Leave(object sender, EventArgs e)
- {
- CalGoodValue();
- }
- public void gridGoodValue()
- {
- double sum = 0;
- for (int i = 0; i < dataGridView1.Rows.Count; ++i)
- {
- sum += Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value);
- }
- txtTotalGoodValue.Text = sum.ToString();
- }
- {
- }
- {
- }
- }
- }