private void BTN_UPDATE_Click(object sender, EventArgs e) { if (textBox1.Text == string.Empty) { MessageBox.Show("Please Enter the Return Quantity"); } else { double _APT = 0; string _cash = ""; string _change = ""; string _date = ""; string _time = ""; // string _operator = ""; int _billno = 0; string _operators = ""; int _bit = 2; string cs = "Data Source=.;Initial Catalog=MY_DB;Integrated Security=true"; SqlConnection con; SqlDataAdapter adapt; DataTable dt; con = new SqlConnection(cs); con.Open(); adapt = new SqlDataAdapter("select productQty from Receiptss where productBillNo ='" + txtBillNo.Text + "' and productid ='" + txtBarcode.Text + "'", con); dt = new DataTable(); adapt.Fill(dt); string OrignalQty = dt.Rows[0]["productQty"].ToString(); if (Convert.ToInt16(OrignalQty) > 0) { using (SqlConnection conn = new SqlConnection(cs)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("UPDATE PRODUCT Set STOCK_QTE = STOCK_QTE + '" + (Convert.ToInt32(textBox1.Text)) + "' where PRODUCT_BARCODE ='" + txtBarcode.Text + "'", conn)) { cmd.ExecuteNonQuery(); //rows number of record got updated } using (SqlCommand cmd = new SqlCommand("UPDATE Receiptss Set productTotal ='" + txtSaleAmount.Text + "' ,productQty = '" + (Convert.ToInt32(txtQuanity.Text) - Convert.ToInt32(textBox1.Text)) + "' where productBillNo ='" + txtBillNo.Text + "' and productid ='" + txtBarcode.Text + "'", conn)) { cmd.ExecuteNonQuery(); MessageBox.Show("Sucessfully Update"); //rows number of record got updated adapt = new SqlDataAdapter("select productBillNo,productid,productName, productQty, UnitPrice, productTotal, [date],time,cash,change, optr from Receiptss where productBillNo ='" + txtBillNo.Text + "'", con); dt = new DataTable(); adapt.Fill(dt); con.Close(); conn.Close(); DGV_SALES_RETURN.DataSource = dt; this.DGV_SALES_RETURN.Columns[7].Visible = false; this.DGV_SALES_RETURN.Columns[8].Visible = false; this.DGV_SALES_RETURN.Columns[9].Visible = false; this.DGV_SALES_RETURN.Columns[10].Visible = false; foreach (DataRow row in dt.Rows) { // TextBox1.Text = row["ImagePath"].ToString(); Receipt obj = new Receipt() { BARCODE_ID = row["productid"].ToString(), PRODUCT_NAME = row["productName"].ToString(), UNIT_PRICE = Convert.ToDouble(row["UnitPrice"].ToString()), QTY = Convert.ToInt32(row["productQty"].ToString()), TOTAL = Convert.ToDouble(row["productTotal"].ToString()) }; _APT = _APT + Convert.ToDouble(row["productTotal"].ToString()); _cash = row["cash"].ToString(); _change = row["change"].ToString(); _date = row["date"].ToString(); _time = row["time"].ToString(); _billno = Convert.ToInt32(row["productBillNo"].ToString()); _operators = row["optr"].ToString(); SaleBindingSource.Add(obj); } } } } using (frmPrint frm = new frmPrint(SaleBindingSource.DataSource as List <Receipt>, string.Format("{0}", Convert.ToString(_APT)), string.Format("{0}", Convert.ToString(_cash)), string.Format("{0}", Convert.ToString(_change)), _date, _time, _operators, _billno, _bit)) { frm.ShowDialog(); SaleBindingSource.Clear(); // txtTotal.Text = string.Format("{0}.00"); txtQuanity.Text = ""; txtProductName.Text = ""; txtUnitPrice.Text = ""; txtBarcode.Text = ""; txtSaleAmount.Text = ""; textBox1.Text = ""; txtBillNo.Text = ""; txtsearchbyBillNo.Text = ""; DGV_SALES_RETURN.DataSource = getInvoicesData(); // for resetting fields after receipt }; } }
private void BTN_INSERT_ORDER_Click(object sender, EventArgs e) { //int InvoiceNo = 01; //string output; //SqlConnection cs = new SqlConnection("Data Source=.; Initial Catalog=MY_DB; Integrated Security=TRUE"); //cs.Open(); //SqlCommand cmd = new SqlCommand("select max(productBillNo) + 1 from Receiptss", cs); //SqlDataReader dr = cmd.ExecuteReader(); //if (dr.HasRows) //{ // while (dr.Read()) // { // // output = dr[03].ToString(); // output = dr["productBillNo"].ToString(); // InvoiceNo = Convert.ToInt32(output); // } //} ///////////////////////////////////////////// int InvoiceNo = 0; string css = "Data Source=.;Initial Catalog=MY_DB;Integrated Security=true"; SqlConnection con; SqlDataAdapter adapt; DataTable dt; con = new SqlConnection(css); con.Open(); /// adapt = new SqlDataAdapter("select max(productBillNo) + 1 as productBillNo from Receiptss", con); /// adapt = new SqlDataAdapter("select (max(productBillNo)) + 1 as productBillNo from Receiptss", con); dt = new DataTable(); adapt.Fill(dt); foreach (DataRow row in dt.Rows) { if (row.IsNull("productBillNo")) { InvoiceNo = 1000; } else { string output = dt.Rows[0]["productBillNo"].ToString(); InvoiceNo = Convert.ToInt32(output); } } /////////////////////////////////////////////////// if (string.IsNullOrEmpty(txtCash.Text)) { MessageBox.Show("Please Enter Cash to proceed with customer RECEIPT"); } else { int _bit = 1; // string Invoice_No = System.String.Format ( "E{0:000000}" , 42 ) ; using (frmPrint frm = new frmPrint(receiptBindingSource.DataSource as List <Receipt>, string.Format("{0}", total), string.Format("{0}", txtCash.Text), string.Format("{0:0}", Convert.ToDouble(txtCash.Text) - total), DateTime.Now.ToString("MM/dd/yyyy"), DateTime.Now.ToString("HH:mm:ss tt"), lbluser.Text, InvoiceNo, _bit)) { frm.ShowDialog(this); // for resetting fields after receipt txtBarcode.Text = ""; txtProductName.Text = ""; txtunit.Text = ""; txtBrand.Text = ""; txtPrice.Text = ""; txtQuantity.Text = ""; txtCash.Text = ""; txtChange.Text = ""; lblTime.Text = DateTime.Now.ToLongTimeString(); lbldate.Text = DateTime.Now.ToLongDateString(); txtTotal.Text = ""; receiptBindingSource.DataSource = new List <Receipt>(); // txtTotal.Text = string.Format("{0}.00", total); txtunit.Enabled = false; checkBox1.Checked = false; txtTotal.Visible = true; txtBrand.Enabled = false; ddlCalulationMode.SelectedIndex = 0; // for resetting fields after receipt }; } }