Chidiebere Mgbemena

Chidiebere Mgbemena

  • NA
  • 179
  • 12.9k

codes to calculate Vat snd Stamp duty

Apr 30 2020 2:26 PM
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
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.Data.SqlClient;  
  11. namespace NSPM_Sales_Invoice  
  12. {  
  13.  public partial class frmNewBill: Form  
  14.  {  
  15.   SqlConnection con = new SqlConnection(Properties.Settings.Default.NSPM_Sales_InvoiceCon);  
  16.   SqlCommand cmd;  
  17.   public frmNewBill()  
  18.   {  
  19.    InitializeComponent();  
  20.    txtDeleteUpdate.Visible = false;  
  21.   }  
  22.   private void textBox1_TextChanged(object sender, EventArgs e)  
  23.   {  
  24.   }  
  25.   private void panel1_Paint(object sender, PaintEventArgs e)  
  26.   {  
  27.   }  
  28.   private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)  
  29.   {  
  30.   }  
  31.   private void frmNewBill_Load(object sender, EventArgs e)  
  32.   {  
  33.    cmbDescription.Items.Clear();  
  34.    con.Open();  
  35.    cmd = con.CreateCommand();  
  36.    cmd.CommandType = CommandType.Text;  
  37.    cmd.CommandText = "Select ProName from tbl_Products order by ProName asc";  
  38.    cmd.ExecuteNonQuery();  
  39.    DataTable dt = new DataTable();  
  40.    SqlDataAdapter da = new SqlDataAdapter(cmd);  
  41.    da.Fill(dt);  
  42.    foreach(DataRow dr in dt.Rows)  
  43.    {  
  44.     cmbDescription.Items.Add(dr["ProName"].ToString());  
  45.    }  
  46.    con.Close();  
  47.    dataGridView1.Columns[5].Visible = false;  
  48.    dataGridView1.Columns[6].Visible = false;  
  49.   }  
  50.   private void btnAdd_Click(object sender, EventArgs e)  
  51.   {  
  52.    if (cmbDescription.Text == "")  
  53.    {  
  54.     MessageBox.Show("Description is Empty");  
  55.    } else if (txtQuantity.Text == "")  
  56.    {  
  57.     MessageBox.Show("Quantity is Empty");  
  58.    } else if (txtUnitPrice.Text == "")  
  59.    {  
  60.     MessageBox.Show("Unit Price is Empty");  
  61.    } else if (txtJobNo.Text == "")  
  62.    {  
  63.     MessageBox.Show("JobNo is Empty");  
  64.     if (txtDeleteUpdate.Text == "")  
  65.     {  
  66.      int row = 0;  
  67.      dataGridView1.Rows.Add();  
  68.      row = dataGridView1.Rows.Count - 1;  
  69.      dataGridView1["Description", row].Value = cmbDescription.Text;  
  70.      dataGridView1["Quantity", row].Value = txtQuantity.Text;  
  71.      dataGridView1["UnitPrice", row].Value = txtUnitPrice.Text;  
  72.      dataGridView1["GoodValue", row].Value = txtGoodValue.Text;  
  73.      dataGridView1["JobNo", row].Value = txtJobNo.Text;  
  74.      dataGridView1["Date", row].Value = dateTimePicker1.Value.ToString("dd-MM-yyyy");  
  75.      dataGridView1.Refresh();  
  76.      cmbDescription.Focus();  
  77.      if (dataGridView1.Rows.Count > 0)  
  78.      {  
  79.       dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1];  
  80.      }  
  81.     } else  
  82.     {  
  83.      btnAdd.Text = "UPDATE";  
  84.      int i = 0;  
  85.      DataGridViewRow row = dataGridView1.Rows[i];  
  86.      row.Cells[1].Value = cmbDescription.Text;  
  87.      row.Cells[2].Value = txtQuantity.Text;  
  88.      row.Cells[3].Value = txtUnitPrice.Text;  
  89.      row.Cells[4].Value = txtGoodValue.Text;  
  90.      row.Cells[5].Value = txtJobNo.Text;  
  91.      btnAdd.Text = "ADD";  
  92.     }  
  93.     cleartextbox();  
  94.     gridGoodValue();  
  95.    }  
  96.   }  
  97.   private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)  
  98.   {  
  99.    this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = (e.RowIndex + 1).ToString();  
  100.   }  
  101.   int i;  
  102.   private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)  
  103.   {  
  104.    i = e.RowIndex;  
  105.    DataGridViewRow row = dataGridView1.Rows[i];  
  106.    cmbDescription.Text = row.Cells[1].Value.ToString();  
  107.    txtQuantity.Text = row.Cells[2].Value.ToString();  
  108.    txtUnitPrice.Text = row.Cells[3].Value.ToString();  
  109.    txtGoodValue.Text = row.Cells[4].Value.ToString();  
  110.    txtDeleteUpdate.Text = row.Cells[0].Value.ToString();  
  111.    btnAdd.Text = "UPDATE";  
  112.   }  
  113.   private void btnDelete_Click(object sender, EventArgs e)  
  114.   {  
  115.    if (txtDeleteUpdate.Text == "")  
  116.    {  
  117.     MessageBox.Show("Select Product to Delete");  
  118.    } else  
  119.    {  
  120.     foreach(DataGridViewRow row in dataGridView1.SelectedRows)  
  121.     {  
  122.      if (!row.IsNewRow) dataGridView1.Rows.Remove(row);  
  123.     }  
  124.    }  
  125.    btnAdd.Text = "ADD";  
  126.    gridGoodValue();  
  127.    cleartextbox();  
  128.   }  
  129.   public void cleartextbox()  
  130.   {  
  131.    cmbDescription.Text = "";  
  132.    txtQuantity.Text = "";  
  133.    txtUnitPrice.Text = "";  
  134.    txtGoodValue.Text = "";  
  135.    txtJobNo.Text = "";  
  136.    txtDeleteUpdate.Text = "";  
  137.   }  
  138.   public void CalGoodValue()  
  139.   {  
  140.    double a1, b1, i;  
  141.    double.TryParse(txtUnitPrice.Text, out a1);  
  142.    double.TryParse(txtQuantity.Text, out b1);  
  143.    i = a1 * b1;  
  144.    if (1 > 0)  
  145.    {  
  146.     txtGoodValue.Text = i.ToString("C").Remove(0, 1);  
  147.    }  
  148.   }  
  149.   private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)  
  150.   {  
  151.   }  
  152.   private void txtQuantity_Leave(object sender, EventArgs e)  
  153.   {  
  154.    CalGoodValue();  
  155.   }  
  156.   private void txtQuantity_TextChanged(object sender, EventArgs e)  
  157.   {  
  158.   }  
  159.   private void txtUnitPrice_Leave(object sender, EventArgs e)  
  160.   {  
  161.    CalGoodValue();  
  162.   }  
  163.   public void gridGoodValue()  
  164.   {  
  165.    double sum = 0;  
  166.    for (int i = 0; i < dataGridView1.Rows.Count; ++i)  
  167.    {  
  168.     sum += Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value);  
  169.    }  
  170.    txtTotalGoodValue.Text = sum.ToString();  
  171.   }  
  172.   {  
  173.   }  
  174.   {  
  175.   }  
  176.  }  

 

Answers (2)