private void SearchInvoice_Click(object sender, EventArgs e) { try { int invoiceid = Convert.ToInt32(InvoiceNumber.Text); SqlConnection con = new SqlConnection(Helper.con); con.Open(); string query = "select * from DeletedBill where InvioceID = '" + invoiceid + "' "; SqlCommand cmd = new SqlCommand(query, con); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgv1.DataSource = dt; con.Close(); dgv1.Columns[0].HeaderText = "INVOICE ID"; dgv1.Columns[1].HeaderText = "CUST ID"; dgv1.Columns[2].HeaderText = "ORDER ID"; dgv1.Columns[3].HeaderText = "CUST NAME"; dgv1.Columns[4].HeaderText = "PRODUCT NAME"; dgv1.Columns[5].HeaderText = "PRODUCT QTY"; dgv1.Columns[6].HeaderText = "PRODUCT RATE"; dgv1.Columns[7].HeaderText = "PRODUCT AMOUNT"; dgv1.Columns[8].HeaderText = "GST AMOUNT"; dgv1.Columns[9].HeaderText = "ORDER TIME"; dgv1.Columns[10].HeaderText = "ORDER DATE"; dgv1.Columns[11].HeaderText = "TOTAL QTY"; dgv1.Columns[11].Visible = false; dgv1.Columns[12].HeaderText = "ACTUAL AMOUNT"; dgv1.Columns[12].Visible = false; dgv1.Columns[13].HeaderText = "TOTAL AMOUNT"; dgv1.Columns[13].Visible = false; dgv1.Columns[14].HeaderText = "TOTAL GST AMOUNT"; dgv1.Columns[14].Visible = false; dgv1.Columns[15].HeaderText = "DISCOUNT"; dgv1.Columns[15].Visible = false; totalquantity.Text = "0"; totalprice.Text = "0"; int totalQuantity = 0; double totalAmount = 0; for (int i = 0; i < dgv1.Rows.Count; ++i) { totalQuantity += Convert.ToInt32(dgv1.Rows[i].Cells[5].Value); totalAmount += Convert.ToDouble(dgv1.Rows[i].Cells[7].Value); } totalquantity.Text = totalQuantity.ToString(); totalprice.Text = totalAmount.ToString(); InvoiceNumber.Text = ""; InvoiceNumber.Focus(); } catch (Exception) { MessageBox.Show("InvoiceID cannot be blank"); } }
private void btnRefresh_Click(object sender, EventArgs e) { dgv1.Refresh(); LoadGridView(); totalQuantity = 0; actualAmount = 0; invoiceid2 = 0; ActualAmount.Text = "0"; TotalQty.Text = "0"; TotalAmount.Text = "0"; txtDiscount.Text = string.Empty; txtDiscount.Visible = false; InvoiceNumber.Text = string.Empty; InvoiceNumber.Focus(); }
private void SearchInvoice_Click(object sender, EventArgs e) { try { int invoiceid = Convert.ToInt32(InvoiceNumber.Text); SqlConnection con = new SqlConnection(Helper.con); con.Open(); string query = "select * from Bill where InvioceID = '" + invoiceid + "' "; SqlCommand cmd = new SqlCommand(query, con); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgv1.DataSource = dt; con.Close(); totalquantity.Text = "0"; totalprice.Text = "0"; int totalQuantity = 0; double totalAmount = 0; for (int i = 0; i < dgv1.Rows.Count; ++i) { totalQuantity += Convert.ToInt32(dgv1.Rows[i].Cells[5].Value); totalAmount += Convert.ToDouble(dgv1.Rows[i].Cells[7].Value); } totalquantity.Text = totalQuantity.ToString(); totalprice.Text = totalAmount.ToString(); InvoiceNumber.Text = ""; InvoiceNumber.Focus(); } catch (Exception) { MessageBox.Show("InvoiceID cannot be blank"); } }
public EditInvoice() { InitializeComponent(); InvoiceNumber.Focus(); }
private void SearchInvoice_Click(object sender, EventArgs e) { try { ActualAmount.Text = "0"; TotalQty.Text = "0"; TotalAmount.Text = "0"; int invoiceid = Convert.ToInt32(InvoiceNumber.Text); invoiceid2 = Convert.ToInt32(InvoiceNumber.Text); SqlConnection con = new SqlConnection(Helper.con); con.Open(); string query = "select * from Bill where InvioceID = '" + invoiceid + "' "; SqlCommand cmd = new SqlCommand(query, con); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgv1.DataSource = dt; dgv1.Columns[0].HeaderText = "INVOICE ID"; dgv1.Columns[1].HeaderText = "CUST ID"; dgv1.Columns[2].HeaderText = "ORDER ID"; dgv1.Columns[3].HeaderText = "CUST NAME"; dgv1.Columns[4].HeaderText = "PRODUCT NAME"; dgv1.Columns[5].HeaderText = "PRODUCT QTY"; dgv1.Columns[6].HeaderText = "PRODUCT RATE"; dgv1.Columns[7].HeaderText = "PRODUCT AMOUNT"; dgv1.Columns[8].HeaderText = "GST AMOUNT"; dgv1.Columns[9].HeaderText = "ORDER TIME"; dgv1.Columns[10].HeaderText = "ORDER DATE"; dgv1.Columns[11].HeaderText = "TOTAL QTY"; dgv1.Columns[11].Visible = false; dgv1.Columns[12].HeaderText = "ACTUAL AMOUNT"; dgv1.Columns[12].Visible = false; dgv1.Columns[13].HeaderText = "TOTAL AMOUNT"; dgv1.Columns[13].Visible = false; dgv1.Columns[14].HeaderText = "TOTAL GST AMOUNT"; dgv1.Columns[14].Visible = false; dgv1.Columns[15].HeaderText = "DISCOUNT"; dgv1.Columns[15].Visible = false; SqlTransaction tran = con.BeginTransaction(); SqlCommand cmd2 = new SqlCommand("select top 1 ActualAmount,TotalAmount,DiscountInPercent from Bill where InvioceID = '" + InvoiceNumber.Text + "' ", con, tran); cmd2.ExecuteNonQuery(); InvoiceNumber.Text = ""; InvoiceNumber.Focus(); totalQuantity = 0; using (SqlDataReader dr = cmd2.ExecuteReader()) { while (dr.Read()) { totalAmount = dr["TotalAmount"].ToString(); discount = dr["DiscountInPercent"].ToString(); DRactualAmount = dr["ActualAmount"].ToString(); } } TotalAmount.Text = totalAmount; txtDiscount.Text = discount; ActualAmount.Text = DRactualAmount.ToString(); for (int i = 0; i < dgv1.Rows.Count; ++i) { totalQuantity += Convert.ToInt32(dgv1.Rows[i].Cells[5].Value); } TotalQty.Text = totalQuantity.ToString(); con.Close(); } catch (Exception) { MessageBox.Show("InvoiceID cannot be blank"); } }
private void DeleteInvoice_Click(object sender, EventArgs e) { string Invoiceid, CustID, OrderID, CustName, ProductName, ProductQuantity, ProductRate, ProductAmount, ProductAmountWithGST, OrderTime, OrderDate, TotalQty, ActualAmount, TotalAmount, TotalAmountWithGST, DiscounInPercent; try { int txt_invoiceid = Convert.ToInt32(InvoiceNumber.Text); SqlConnection con = new SqlConnection(Helper.con); con.Open(); string query = "select * from Bill where InvioceID = '" + txt_invoiceid + "' "; SqlCommand cmd = new SqlCommand(query, con); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgv1.DataSource = dt; SqlTransaction tran = con.BeginTransaction(); for (int i = 0; i < dgv1.Rows.Count; i++) { Invoiceid = Convert.ToString(dgv1.Rows[i].Cells[0].Value); CustID = Convert.ToString(dgv1.Rows[i].Cells[1].Value); OrderID = Convert.ToString(dgv1.Rows[i].Cells[2].Value); CustName = Convert.ToString(dgv1.Rows[i].Cells[3].Value); ProductName = Convert.ToString(dgv1.Rows[i].Cells[4].Value); ProductQuantity = Convert.ToString(dgv1.Rows[i].Cells[5].Value); ProductRate = Convert.ToString(dgv1.Rows[i].Cells[6].Value); ProductAmount = Convert.ToString(dgv1.Rows[i].Cells[7].Value); ProductAmountWithGST = Convert.ToString(dgv1.Rows[i].Cells[8].Value); OrderTime = Convert.ToString(dgv1.Rows[i].Cells[9].Value); OrderDate = Convert.ToString(dgv1.Rows[i].Cells[10].Value); TotalQty = Convert.ToString(dgv1.Rows[i].Cells[11].Value); ActualAmount = Convert.ToString(dgv1.Rows[i].Cells[12].Value); TotalAmount = Convert.ToString(dgv1.Rows[i].Cells[13].Value); TotalAmountWithGST = Convert.ToString(dgv1.Rows[i].Cells[14].Value); DiscounInPercent = Convert.ToString(dgv1.Rows[i].Cells[15].Value); SqlCommand cmd1 = new SqlCommand ("insert into DeletedBill values ('" + Invoiceid + "' , '" + CustID + "' , '" + OrderID + "' , '" + CustName + "' , '" + ProductName + "' , '" + ProductQuantity + "' , '" + ProductRate + "' , '" + ProductAmount + "' , '" + ProductAmountWithGST + "' , '" + OrderTime + "' , '" + OrderDate + "' , '" + TotalQty + "' , '" + ActualAmount + "' , '" + TotalAmount + "' , '" + TotalAmountWithGST + "' , '" + DiscounInPercent + "') ", con, tran); cmd1.ExecuteNonQuery(); } SqlCommand cmd2 = new SqlCommand("Delete from Bill where InvioceID = '" + txt_invoiceid + "' ", con, tran); cmd2.ExecuteNonQuery(); tran.Commit(); con.Close(); InvoiceNumber.Text = ""; InvoiceNumber.Focus(); } catch (Exception) { MessageBox.Show("InvoiceID cannot be blank"); } LoadGridView(); }