private void btnConfirm_Click(object sender, EventArgs e) { if (table1.RowCount > 0) { string total = lblPrice.Text.Replace(",", ""); if (MessageBox.Show("คุณแน่ใจหรือไม่ ที่จะยืนยันการขายนี้ ?", "ยืนยันข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DataTable dt = Util.DBQuery(string.Format(@"SELECT IFNULL(SUBSTR(MAX(SellNo), 1, 5)||SUBSTR('0000'||(SUBSTR(MAX(SellNo), 6, 4)+1), -4, 4), SUBSTR(STRFTIME('%Y%m{0}'), 3)||'0001') SellNo FROM SellHeader WHERE SUBSTR(SellNo, 1, 4) = SUBSTR(STRFTIME('%Y%m'), 3, 4) AND SUBSTR(SellNo, 5, 1) = '{0}'", Param.DevicePrefix)); var SellNo = dt.Rows[0]["SellNo"].ToString(); //dt = Util.DBQuery(string.Format(@"SELECT b.Barcode, b.SellNo, p.Price{0} Price //FROM Barcode b // LEFT JOIN Product p // ON b.product = p.id //WHERE p.Shop = '{1}' AND b.sellBy = '{2}'", Param.SelectCustomerSellPrice == 0 ? "" : "" + Param.SelectCustomerSellPrice, Param.ShopId, Param.CpuId)); //for (int i = 0; i < dt.Rows.Count; i++) //{ // Util.DBExecute(string.Format(@"UPDATE Barcode // SET SellBy = '{0}', SellDate = STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW'), SellNo = '{1}', Sync = 1, SellPrice = {2}, Customer = '{3}', SellFinished = 1 // WHERE Barcode = '{4}' AND SellNo = '{5}'", // Param.UserId, SellNo, dt.Rows[i]["Price"].ToString(), Param.SelectCustomerId, // dt.Rows[i]["Barcode"].ToString(), dt.Rows[i]["SellNo"].ToString())); //} //DataTable dtP = Util.DBQuery(string.Format(@"SELECT IFNULL(SUM(SellPrice),0) SellPrice, IFNULL(SUM(Cost),0) Cost, IFNULL(SUM(OperationCost),0) OperationCost FROM Barcode WHERE SellNo = '{0}'", SellNo)); //DataTable dtS = Util.DBQuery(string.Format(@"SELECT IFNULL(SUM(Price),0) SellPrice, IFNULL(SUM(PriceCost),0) Cost FROM sellTemp")); //int val = ((Convert.ToInt32(dtP.Rows[0]["SellPrice"].ToString()) + Convert.ToInt32(dtS.Rows[0]["SellPrice"].ToString())) - (Convert.ToInt32(dtP.Rows[0]["Cost"].ToString()) + Convert.ToInt32(dtS.Rows[0]["Cost"].ToString()))) - Convert.ToInt32(dtP.Rows[0]["OperationCost"].ToString()); //Util.DBExecute(string.Format(@"INSERT INTO SellHeader (SellNo, Profit, TotalPrice, Customer, CustomerSex, CustomerAge, SellDate, SellBy) //SELECT '{0}', '{6}','{5}', '{1}', '{2}', {3}, STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW'), '{4}'", // SellNo, Param.SelectCustomerId, Param.SelectCustomerSex, Param.SelectCustomerAge, Param.UserId, total, val)); //Util.DBExecute(string.Format(@"INSERT INTO SellDetail (SellNo, Product, SellPrice, Cost, Quantity, Sync) //SELECT sellNo, Product, SUM(TotalPrice)TotalPrice, SUM(PriceCost) PriceCost, SUM(Amount) Amount,1 FROM( // SELECT '{0}' sellNo, Product, SUM(SellPrice) TotalPrice, SUM(Cost) PriceCost, COUNT(*) Amount, 1 FROM Barcode WHERE SellNo = '{0}' GROUP BY Product // Union ALL SELECT '{0}', Product, TotalPrice, PriceCost, Amount, 1 FROM SellTemp) GROUP BY sellNo, Product", SellNo)); //Util.DBExecute(string.Format(@"INSERT INTO SellDetail (SellNo, Product, SellPrice, Quantity, Cost, Sync) //SELECT '{0}', Product, TotalPrice, Amount, PriceCost, 1 FROM SellTemp", SellNo)); FmCashReceive dialog = new FmCashReceive(); dialog.lblPrice.Text = lblPrice.Text; dialog.lblChange.Text = "0"; dialog._TOTAL = int.Parse(lblPrice.Text.Replace(",", "")); dialog._SELL_NO = SellNo; var result = dialog.ShowDialog(this); if (result != DialogResult.OK) { Util.DBExecute(string.Format(@"UPDATE SellHeader SET Cash = 0, PayType = 0, Paid = 0, Sync = 1 WHERE SellNo = '{0}'", SellNo)); } //Param.SelectCustomerId = "000000"; //Param.SelectCustomerName = "ลูกค้าทั่วไป"; //Param.SelectCustomerSex = ""; //Param.SelectCustomerAge = 0; //Param.SelectCustomerSellPrice = 0; lblStatus.Text = ""; //if (Param.SystemConfig.Bill.PrintType == "Y") //{ // var cnt = int.Parse(Param.SystemConfig.Bill.PrintCount.ToString()); // for (int i = 1; i <= cnt; i++) // Util.PrintReceipt(SellNo); //} //else if (Param.SystemConfig.Bill.PrintType == "A") //{ // if (MessageBox.Show("คุณต้องการพิมพ์ใบเสร็จรับเงินหรือไม่ ?", "ยืนยันการพิมพ์", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // Util.PrintReceipt(SellNo); //} lblCustomerName.Text = "ลูกค้าทั่วไป"; Param.SelectCustomerSex = ""; Param.SelectCustomerAge = 0; Param.SelectCustomerSellPrice = 0; SelectCustomer(sender, (e)); LoadData(); } } else { MessageBox.Show("ไม่มีสินค้าในรายการขาย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnConfirm_Click(object sender, EventArgs e) { if (table1.RowCount > 0) { string total = lblPrice.Text.Replace(",", ""); if (MessageBox.Show("คุณแน่ใจหรือไม่ ที่จะยืนยันการขายนี้ ?", "ยืนยันข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DataTable dt = Util.DBQuery(string.Format(@"SELECT IFNULL(SUBSTR(MAX(SellNo), 1, 5)||SUBSTR('0000'||(SUBSTR(MAX(SellNo), 6, 4)+1), -4, 4), SUBSTR(STRFTIME('%Y%m{0}'), 3)||'0001') SellNo FROM SellHeader WHERE SUBSTR(SellNo, 1, 4) = SUBSTR(STRFTIME('%Y%m'), 3, 4) AND SUBSTR(SellNo, 5, 1) = '{0}'", Param.DevicePrefix)); var SellNo = dt.Rows[0]["SellNo"].ToString(); //dt = Util.DBQuery(string.Format(@"SELECT b.Barcode, b.SellNo, p.Price{0} Price //FROM Barcode b // LEFT JOIN Product p // ON b.product = p.id //WHERE p.Shop = '{1}' AND b.sellBy = '{2}'", Param.SelectCustomerSellPrice == 0 ? "" : "" + Param.SelectCustomerSellPrice, Param.ShopId, Param.CpuId)); //for (int i = 0; i < dt.Rows.Count; i++) //{ // Util.DBExecute(string.Format(@"UPDATE Barcode // SET SellBy = '{0}', SellDate = STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW'), SellNo = '{1}', Sync = 1, SellPrice = {2}, Customer = '{3}', SellFinished = 1 // WHERE Barcode = '{4}' AND SellNo = '{5}'", // Param.UserId, SellNo, dt.Rows[i]["Price"].ToString(), Param.SelectCustomerId, // dt.Rows[i]["Barcode"].ToString(), dt.Rows[i]["SellNo"].ToString())); //} //DataTable dtP = Util.DBQuery(string.Format(@"SELECT IFNULL(SUM(SellPrice),0) SellPrice, IFNULL(SUM(Cost),0) Cost, IFNULL(SUM(OperationCost),0) OperationCost FROM Barcode WHERE SellNo = '{0}'", SellNo)); //DataTable dtS = Util.DBQuery(string.Format(@"SELECT IFNULL(SUM(Price),0) SellPrice, IFNULL(SUM(PriceCost),0) Cost FROM sellTemp")); //int val = ((Convert.ToInt32(dtP.Rows[0]["SellPrice"].ToString()) + Convert.ToInt32(dtS.Rows[0]["SellPrice"].ToString())) - (Convert.ToInt32(dtP.Rows[0]["Cost"].ToString()) + Convert.ToInt32(dtS.Rows[0]["Cost"].ToString()))) - Convert.ToInt32(dtP.Rows[0]["OperationCost"].ToString()); //Util.DBExecute(string.Format(@"INSERT INTO SellHeader (SellNo, Profit, TotalPrice, Customer, CustomerSex, CustomerAge, SellDate, SellBy) //SELECT '{0}', '{6}','{5}', '{1}', '{2}', {3}, STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW'), '{4}'", // SellNo, Param.SelectCustomerId, Param.SelectCustomerSex, Param.SelectCustomerAge, Param.UserId, total, val)); //Util.DBExecute(string.Format(@"INSERT INTO SellDetail (SellNo, Product, SellPrice, Cost, Quantity, Sync) //SELECT sellNo, Product, SUM(TotalPrice)TotalPrice, SUM(PriceCost) PriceCost, SUM(Amount) Amount,1 FROM( // SELECT '{0}' sellNo, Product, SUM(SellPrice) TotalPrice, SUM(Cost) PriceCost, COUNT(*) Amount, 1 FROM Barcode WHERE SellNo = '{0}' GROUP BY Product // Union ALL SELECT '{0}', Product, TotalPrice, PriceCost, Amount, 1 FROM SellTemp) GROUP BY sellNo, Product", SellNo)); //Util.DBExecute(string.Format(@"INSERT INTO SellDetail (SellNo, Product, SellPrice, Quantity, Cost, Sync) //SELECT '{0}', Product, TotalPrice, Amount, PriceCost, 1 FROM SellTemp", SellNo)); FmCashReceive dialog = new FmCashReceive(); dialog.lblPrice.Text = lblPrice.Text; dialog.lblChange.Text = "0"; dialog._TOTAL = int.Parse(lblPrice.Text.Replace(",", "")); dialog._SELL_NO = SellNo; var result = dialog.ShowDialog(this); if (result != DialogResult.OK) { Util.DBExecute(string.Format(@"UPDATE SellHeader SET Cash = 0, PayType = 0, Paid = 0, Sync = 1 WHERE SellNo = '{0}'", SellNo)); } //Param.SelectCustomerId = "000000"; //Param.SelectCustomerName = "ลูกค้าทั่วไป"; //Param.SelectCustomerSex = ""; //Param.SelectCustomerAge = 0; //Param.SelectCustomerSellPrice = 0; lblStatus.Text = ""; //if (Param.SystemConfig.Bill.PrintType == "Y") //{ // var cnt = int.Parse(Param.SystemConfig.Bill.PrintCount.ToString()); // for (int i = 1; i <= cnt; i++) // Util.PrintReceipt(SellNo); //} //else if (Param.SystemConfig.Bill.PrintType == "A") //{ // if (MessageBox.Show("คุณต้องการพิมพ์ใบเสร็จรับเงินหรือไม่ ?", "ยืนยันการพิมพ์", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // Util.PrintReceipt(SellNo); //} lblCustomerName.Text = "ลูกค้าทั่วไป"; Param.SelectCustomerSex = ""; Param.SelectCustomerAge = 0; Param.SelectCustomerSellPrice = 0; SelectCustomer(sender, (e)); LoadData(); } } else { MessageBox.Show("ไม่มีสินค้าในรายการขาย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }