Exemplo n.º 1
0
 private void txtCustomer_TextChanged(object sender, EventArgs e)
 {
     if (Class.Function.GetTextId(txtCustomer.Text) != "")
     {
         frmEarnestMain frm = new frmEarnestMain();
         txtPledge.Text = frm.EarnestGet(Class.Function.GetTextId(txtCustomer.Text)).ToString("N2");
     }
 }
Exemplo n.º 2
0
        /*บันทึกหน้าขายทั้งหมดในฐานข้อมูล*/
        private void insertDateSale()
        {
            frmEarnestMain frm = new frmEarnestMain();
            List<String> listq;
            String sql = "";
            List<String> ListSql = new List<String>();
            List<String> ListSqlQtyX = new List<String>();
            String arraydetailid = "";
            if (dataGridView1.Rows.Count > 0)
            {
                arraydetailid += dataGridView1.Rows[0].Cells[0].Value.ToString();
                for (int i = 1; i < dataGridView1.Rows.Count; i++) { arraydetailid += "," + dataGridView1.Rows[i].Cells[0].Value.ToString(); }
            }
            if (arraydetailid == "") { arraydetailid = "0"; }
            if (head != null)
            {

                sql = "SELECT COUNT(SaleHeadId) AS CountId FROM SALE_STORE_HEAD WHERE SaleHeadId = '" + head + "' ";
                DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
                if (Count > 0)
                {
                    sql = "DELETE SALE_STORE_WEIGHT WHERE SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                    sql = "DELETE SALE_STORE_DETAIL WHERE SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                    sql = "DELETE SALE_STORE_HEAD WHERE SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                    sql = "DELETE RECEIVE_SHIP WHERE ReceiveHeadId = '" + head + "' and shipType = '" + shipType + "' ";
                    ListSql.Add(sql);
                }
                //Delete payment
                sql = "select count(PaymentId) from PAYMENT where SaleHeadId = '" + head + "'";
                dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
                if (Count > 0)
                {
                    sql = "DELETE PAYMENT WHERE SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                }
                //End delete payment
                //Delete paycheck
                sql = "select count(PayCheckId) from PAYCHECK where SaleHeadId = '" + head + "'";
                dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
                if (Count > 0)
                {
                    sql = "DELETE PAYCHECK WHERE SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                }
                //End delete paycheck
                //Delete Deposit
                //sql = "select count(EarnestDetailId) from EarnestDetail where SaleHeadId = '" + head + "'";
                //dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                //Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
                //if (Count > 0)
                //{
                //    sql = "DELETE EarnestDetail WHERE SaleHeadId = '" + head + "' ";
                //    ListSql.Add(sql);
                //}
                //End delete Deposit
                //Delete Deposit2
                sql = "select EarnestId,EarnestDetailAmnt,SaleHeadId from EarnestDetail where SaleHeadId = '" + head + "'";
                dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                foreach (DataRow row in dtc.Rows)
                {
                    String strEarnestId = row[0].ToString();
                    String valueCut = row[1].ToString();
                    //String strSaleHeadId = row[2].ToString();
                    sql = "UPDATE EarnestHead set EarnestAmntCut = EarnestAmntCut-" + valueCut + " WHERE EarnestId = '" + strEarnestId + "' ";
                    ListSql.Add(sql);

                    sql = "DELETE EarnestDetail WHERE EarnestId = '" + strEarnestId + "' " +
                        "and SaleHeadId = '" + head + "' ";
                    ListSql.Add(sql);
                }
                //End delete Deposit2
            }

            String strCustomer = Class.Function.GetTextId(textBox13.Text);
            String strShippId = Class.Function.GetTextId(textBox3.Text);
            String strTime = DateTime.Now.ToString("hh:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo);
            String strDay = dateTimePicker1.Value.Day.ToString();
            String strMonth = dateTimePicker1.Value.Month.ToString();
            String strYear = dateTimePicker1.Value.Year.ToString();
            String rdate = strYear + "-" + strMonth + "-" + strDay + " " + strTime;

            String strDaySh = dateTimePicker3.Value.Day.ToString();
            String strMonthSh = dateTimePicker3.Value.Month.ToString();
            String strYearSh = dateTimePicker3.Value.Year.ToString();
            String rdateSh = strYearSh + "-" + strMonthSh + "-" + strDaySh + " " + strTime;

            Double SaleVat = Convert.ToDouble(textBox20.Text);
            Double SaleShipping = Convert.ToDouble(textBox18.Text);
            Double Discount = Convert.ToDouble(textBox5.Text);
            Double Cash = Convert.ToDouble(textBox8.Text);
            String UserName = clsCash.sUserIdLogin;
            Double Credit = Convert.ToDouble(textBox23.Text);
            Double TotalPrice = Convert.ToDouble(textBox4.Text);
            Double Vatbase = Convert.ToDouble(textBox6.Text);
            Double DisBath = Convert.ToDouble(textBox19.Text);
            Double Mcash = Convert.ToDouble(textBox22.Text);
            Double TranfMny = Convert.ToDouble(textBox37.Text);
            Double Cheque = Convert.ToDouble(textBox38.Text);
            Double DisCash = Convert.ToDouble(textBox25.Text);
            Double Pay = Convert.ToDouble(label34.Text);
            Double Deposit_Pay = Convert.ToDouble(textBox24.Text);

            getNewDetailId();

            //Insert Payment
            if (Convert.ToDouble(textBox37.Text) > 0)
            {
                foreach (DataGridViewRow row in dataGridView7.Rows)
                {
                    try
                    {
                        String strBankBookCode = row.Cells[0].Value.ToString();
                        String strPay = row.Cells[5].Value.ToString();
                        sql = "INSERT INTO PAYMENT(SaleHeadId,BankBookCode,Pay)VALUES('" + textBox1.Text + "','" + strBankBookCode + "','" + strPay + "')";
                        ListSql.Add(sql);
                    }
                    catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
                }
            }
            //End insert payment
            //Insert PayCheck
            if (Convert.ToDouble(textBox38.Text) > 0)
            {
                foreach (DataGridViewRow row in dataGridView8.Rows)
                {
                    try
                    {
                        String strPayCheckDate = row.Cells[3].Value.ToString();
                        DateTime date1 = DateTime.Parse(strPayCheckDate);
                        strDay = date1.Day.ToString();
                        strMonth = date1.Month.ToString();
                        strYear = (Convert.ToInt16(date1.Year.ToString())).ToString();
                        String strDate = strYear + "-" + strMonth + "-" + strDay;
                        String strBankAccountId = row.Cells[0].Value.ToString();
                        String strBankBranch = row.Cells[2].Value.ToString();
                        String strCheckId = row.Cells[4].Value.ToString();
                        String strPay = row.Cells[5].Value.ToString();
                        sql = "INSERT INTO PAYCHECK(PayCheckDate,SaleHeadId,BankAccountId,BankBranch,CheckId,Pay)VALUES(" +
                            "'" + strDate + "','" + textBox1.Text + "','" + strBankAccountId + "','" + strBankBranch + "'," +
                            "'" + strCheckId + "','" + strPay + "')";
                        ListSql.Add(sql);
                    }
                    catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
                }
            }
            //End insert PayCheck
            //Insert Deposit
            if (Convert.ToDouble(textBox24.Text) > 0)
            {
                foreach (DataGridViewRow row in dataGridView9.Rows)
                {
                    getNewDepositId();
                    try
                    {
                        String strEarnestId = row.Cells[0].Value.ToString();
                        String strAmountCut = Convert.ToDouble(row.Cells[3].Value.ToString()).ToString();
                        sql = "UPDATE EarnestHead set EarnestAmntCut = EarnestAmntCut+" + strAmountCut + " WHERE EarnestId = '" + strEarnestId + "' ";
                        ListSql.Add(sql);

                        sql = "INSERT INTO EarnestDetail(EarnestId,EarnestDetailAmnt,SaleHeadId,EarnestDetailRemark)VALUES(" +
                            "'" + strEarnestId + "','" + strAmountCut + "','" + textBox1.Text + "',''" +
                            ")";
                        ListSql.Add(sql);
                    }
                    catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
                }
            }
            //End insert Deposit

            //Set status RO
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[16].Value.ToString() != "")
                {
                    String strROId = row.Cells[16].Value.ToString();
                    sql = "UPDATE SALE_APP_HEAD set statusId='3',SaleHeadId='" + textBox1.Text + "' where SdateId='" + strROId + "' ";
                    ListSql.Add(sql);
                }
            }//End set status RO
            //Insert ship
            if (dgvship.Rows.Count > 0)
            {
                foreach (DataGridViewRow row in dgvship.Rows)
                {
                    String shipnum = Convert.ToDouble(row.Cells[0].Value.ToString()).ToString();
                    String shipproduct = row.Cells[1].Value.ToString();
                    String shipunit = Convert.ToDouble(row.Cells[3].Value.ToString()).ToString();
                    String shipsum = Convert.ToDouble(row.Cells[4].Value.ToString()).ToString();
                    String strunit = row.Cells[2].Value.ToString();

                    sql = "INSERT INTO RECEIVE_SHIP(Shipnum,ShipProduct,ShipUnit,ShipSum,ReceiveHeadId,unit,shipType)" +
                      "VALUES (" + shipnum + ",'" + shipproduct + "'," + shipunit + "," + shipsum + ",'" + textBox1.Text + "','" + strunit + "','" + shipType + "')";
                    ListSql.Add(sql);
                }
            }
            //End insert ship
            List<string> iProductId = new List<string>();

            string sql_app_validate = "";

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {

                try
                {
                    String ProductId = row.Cells[1].Value.ToString();

                    iProductId.Add(ProductId);

                    Double SaleDetailQuantityPack = Convert.ToDouble(row.Cells[3].Value.ToString());
                    Double SaleDetailQuantity = Convert.ToDouble(row.Cells[5].Value.ToString());
                    Double SaleDetailWeight = Convert.ToDouble(row.Cells[7].Value.ToString());
                    Double SaleDetailPriceUnit = Convert.ToDouble(row.Cells[8].Value.ToString());
                    Double PriceQuantity = Convert.ToDouble(row.Cells[9].Value.ToString());
                    String Distext = row.Cells[10].Value.ToString();
                    Double Disperunit = Convert.ToDouble(row.Cells[11].Value.ToString());
                    Double Distotal = Convert.ToDouble(row.Cells[12].Value.ToString());
                    Double SaleDetailTotal = Convert.ToDouble(row.Cells[15].Value.ToString());
                    String SdateId = row.Cells[16].Value.ToString();
                    String data = row.Cells[17].Value.ToString();
                    String type = row.Cells[18].Value.ToString();

                    sql_app_validate += "'" + SdateId + "',";

                    sql = "INSERT INTO SALE_STORE_DETAIL(" +
                        "SaleDetailId,SaleHeadId,ProductId,SaleDetailQuantityPack,SaleDetailQuantity," +
                        "SaleDetailWeight,SaleDetailPriceUnit,PriceQuantity,Distext,DisperUnit," +
                        "Distotal,SaleDetailTotal,SdateId,detailType)VALUES(" +
                        "" + NewDetailId + ",'" + textBox1.Text + "','" + ProductId + "'," + SaleDetailQuantityPack + "," + SaleDetailQuantity + "," +
                        "" + SaleDetailWeight + "," + SaleDetailPriceUnit + "," + PriceQuantity + ",'" + Distext + "'," + Disperunit + "," +
                        "" + Distotal + "," + SaleDetailTotal + ",'" + SdateId + "','" + type + "')";
                    ListSql.Add(sql);

                    if (type != "3")
                    {
                        String[] weight = data.Split('#');
                        for (int i = 0; i < weight.Length - 1; i++)//1 2 3,4 5 6,7 8 9
                        {
                            if (i % ((type == "1") ? 3 : 2) == 0)
                            {
                                String Pack = weight[i];
                                String Quantity = weight[i + 1];
                                String Weight = "0";
                                if (((type == "1") ? 3 : 2) == 3)
                                {
                                    Weight = weight[i + 2];
                                }
                                sql = "INSERT INTO SALE_STORE_WEIGHT(SaleDetailId,PackId,SalePack,SaleWeight,SaleHeadId)VALUES(" +
                                    "" + NewDetailId + "," + Pack + "," + Quantity + "," + Weight + ",'" + textBox1.Text + "')";
                                ListSql.Add(sql);
                            }
                        }
                    }
                    NewDetailId = NewDetailId + 1;
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (head == null)
            {
                sql_app_validate = "SELECT * FROM sale_app_head WHERE statusid = 3 AND sdateid IN (" + sql_app_validate.Substring(0, sql_app_validate.Length - 1) + ")";
                DataTable dt_app = Class.DBConnString.clsDB.QueryDataTable(sql_app_validate);
                if (dt_app.Rows.Count > 0)
                {
                    string msg = "ใบเบิกเลขที่ ";
                    foreach (DataRow ddr in dt_app.Rows)
                        msg += ddr["SdateId"].ToString() + ",";
                    msg += " ขายแล้ว";
                    MessageBox.Show(msg);
                    return;
                }
            }

            sql = "INSERT INTO SALE_STORE_HEAD(" +
                "SaleHeadId,SaleHeadDate,SaleHeadDatetime,SaleHeadDrowId,CustomerId," +
                "SaleHeadStatus,SaleVat,SaleShipping,Discount,Cash," +
                "AbountId,DrowId,Noinv,SaleHeadSaleTypeId,Remark," +
                "UserName,ConfirmId,Credit,SaleCurrencyId1,SaleCurrencyId2," +
                "Exrate1,Exrate2,TotalPrice,VatBase,tax_auto_id," +
                "Disper,DisBath,Mcash,TranfMny,Cheque," +
                "Discash,Pay,Deposit_Pay,ShipperId,ShipperBill," +
                "ShipperDate)VALUES(" +
                "'" + textBox1.Text + "','" + rdate + "',GETDATE(),'" + textBox2.Text + "','" + strCustomer + "'," +
                "'1'," + SaleVat + "," + SaleShipping + "," + Discount + "," + Cash + "," +
                "'','3','','','" + textBox15.Text + "'," +
                "'" + UserName + "','1'," + Credit + ",'',''," +
                "'1','1'," + TotalPrice + "," + Vatbase + ",'" + comboBox3.SelectedValue + "'," +
                "'" + textBox17.Text + "'," + DisBath + "," + Mcash + "," + TranfMny + "," + Cheque + "," +
                "" + DisCash + "," + Pay + "," + Deposit_Pay + ",'" + strShippId + "','" + textBox9.Text + "'," +
                "'" + rdateSh + "')";
                ListSql.Add(sql);

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + textBox1.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (DBConnString.clsDB.ExecuteTransaction(ListSql.ToArray())) { }

                if (Class.DBConnString.sDb == "KTC" || Class.DBConnString.sDb == "KTC_TEST")
                {
                    SalePos7CSK.frmSaleOrderMatch frmcut = new SalePos7CSK.frmSaleOrderMatch(strCustomer, textBox1.Text, SalePos7CSK.CaseSrc.SaleNew);
                    frmcut.showMsg = false;
                    DataTable saleMath = frmcut.CustBalance(strCustomer, iProductId);
                    if (saleMath.Rows.Count > 0 || head != null)
                    {
                        if (MessageBox.Show("พบสินค้าในใบสั่งขายสำหรับลูกค้านี้ ต้องการตัดใบสั่งขายหรือไม่", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                        {
                            if (head != null)
                            {
                                frmcut.CancelMatching(textBox1.Text);
                                frmcut.Reload();
                                frmcut.Match();
                            }
                            else
                            {
                                frmcut.Reload();
                                frmcut.Match();
                            }
                        }
                    }
                }

                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + textBox1.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    SalePosNew.DialogSelectSlip rpt = new SalePosNew.DialogSelectSlip(textBox1.Text,1);
                    rpt.StartPosition = FormStartPosition.CenterParent;
                    rpt.ShowDialog();
                }
                setFirstLoad();
                setNewForm();
            }
        }
Exemplo n.º 3
0
        /*บันทึกข้อมูลการขายสินค้าฝากลงในฐานข้อมูล*/
        private void saveDataSale()
        {
            frmEarnestMain frm = new frmEarnestMain();
            List<String> listq;
            String sql = "";
            List<String> ListSql = new List<String>();
            List<String> ListSqlQtyX = new List<String>();
            String arraydetailid = "";
            if (dgvDetail.Rows.Count > 0)
            {
                arraydetailid += dgvDetail.Rows[0].Cells[0].Value.ToString();
                for (int i = 1; i < dgvDetail.Rows.Count; i++) { arraydetailid += "," + dgvDetail.Rows[i].Cells[0].Value.ToString(); }
            }
            if (arraydetailid == "") { arraydetailid = "0"; }
            if (DBConnString.clsDB.ExecuteTransaction(ListSqlQtyX.ToArray()))
            {
                List<String> ListSqlstsX = new List<String>();
                DBConnString.clsDB.ExecuteTransaction(ListSqlstsX.ToArray());
            }
            sql = "select count(COSaleHeadId) from CO_SALE_HEAD where COSaleHeadId = '" + txtCSHeadId.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE FROM CO_SALE_WEIGHT WHERE COSaleHeadId = '" + txtCSHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_SALE_DETAIL WHERE COSaleHeadId = '" + txtCSHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_SALE_HEAD WHERE COSaleHeadId = '" + txtCSHeadId.Text + "' ";
                ListSql.Add(sql);

                if (Convert.ToDecimal(txtPledge.Text) > 0)
                {
                    listq = frm.EarnestRemove(txtCSHeadId.Text);
                    ListSql.AddRange(listq);
                }
            }
            //Delete payment
            sql = "select count(PaymentId) from PAYMENT where SaleHeadId = '" + txtCSHeadId.Text + "'";
            dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count > 0)
            {
                sql = "DELETE PAYMENT WHERE SaleHeadId = '" + txtCSHeadId.Text + "' ";
                ListSql.Add(sql);
            }
            //End delete payment
            //Delete paycheck
            sql = "select count(PayCheckId) from PAYCHECK where SaleHeadId = '" + txtCSHeadId.Text + "'";
            dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count > 0)
            {
                sql = "DELETE PAYCHECK WHERE SaleHeadId = '" + txtCSHeadId.Text + "' ";
                ListSql.Add(sql);
            }
            //End delete paycheck
            String CQNew = "";
            String strCreditStatus, strCashStatus, strPaymentStatus, strCheckStatus, strPledgeStatus;
            if (txtCredit.Text == "0.00") { strCreditStatus = "0"; }
            else { strCreditStatus = "1"; }
            if (txtCash.Text == "0.00") { strCashStatus = "0"; }
            else { strCashStatus = "1"; }
            if (txtSumPayment.Text == "0.00") { strPaymentStatus = "0"; }
            else { strPaymentStatus = "1"; }
            if (txtSumCheck.Text == "0.00") { strCheckStatus = "0"; }
            else { strCheckStatus = "1"; }
            if (txtPledge.Text == "0.00") { strPledgeStatus = "0"; }
            else { strPledgeStatus = "1"; }

            String strBookCode;
            if (txtBookCode.Text != "") { strBookCode = Class.Function.GetTextId(txtBookCode.Text); }
            else { strBookCode = ""; }
            Double Discount = Convert.ToDouble(TxtDiscount.Text);
            String cust = Class.Function.GetTextId(txtCustomer.Text);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String strCheckDate  = Class .Function .GetDate (dateTimePicker2 .Value );
            String UserName = clsCash.sUserIdLogin;

            Double Credit = Convert.ToDouble(txtCredit.Text);
            Double Cash = Convert.ToDouble(txtCash.Text);
            Double Payment = Convert.ToDouble(txtSumPayment.Text);
            Double PayCehck = Convert.ToDouble(txtSumCheck.Text);
            Double PayDis = Convert.ToDouble(txtPayDis.Text);
            Double Pledge = Convert.ToDouble(txtPledge.Text);
            String pricetotal = TxtPriceTotal.Text.Replace(",","");

            if (Convert.ToDecimal(txtPledge.Text) > 0)
            {
                listq = frm.EarnestSet(cust, txtCSHeadId.Text, Convert.ToDecimal(txtPledge.Text));
                ListSql.AddRange(listq);
            }

            if (CmboxVat.SelectedIndex == 0) { strVat = "1"; }
            else if (CmboxVat.SelectedIndex == 1) { strVat = "7"; }
            else if (CmboxVat.SelectedIndex == 2) { strVat = "8"; }
            sql = "INSERT INTO CO_SALE_HEAD([COSaleHeadId],[COSaleHeadDate],[COSaleHeadDateTime],[CustomerId],[COSaleHeadStatusId]," +
                "[COSaleHeadConfirmStatus],[CreditStatus],[CashStatus],[PaymentStatus],[CheckStatus]," +
                "[COTotalPrice],[CODiscount],[COBaseVat],[Tax_auto_id],[CORateVat]," +
                "[COSaleVat],[COSaleShipping],[COSumPrice],[CODescription],[UserName]," +
                "[CODiscountText],[Shipper],[GrStockDetailId],[Credit],[Cash]," +
                "[Payment],[PayCehck],[PayDis],[PledgeStatus],[Pledge]," +
                "[PayTotal])" +
                "VALUES('" + txtCSHeadId.Text + "','" + rdate + "',GETDATE(),'" + cust + "','1'," +
                "'1','" + strCreditStatus + "','" + strCashStatus + "','" + strPaymentStatus + "','" + strCheckStatus + "'," +
                "" + pricetotal.ToDecimal().ToString() + "," + Discount + "," + TxtBaseVat.Text.ToDecimal().ToString() + "," + strVat + "," + TxtPercentVat.Text + "," +
                "" + TxtVat.Text + ",'" + textBox1.Text + "','" + TxtAmountTotal.Text.ToDecimal().ToString() + "','" + TxtDescription.Text + "','" + UserName + "'," +
                "'" + TxtDiscountText.Text + "','','" + stock + "','" + Credit.ToDecimal().ToString() + "','" + Cash.ToDecimal().ToString() + "'," +
                "'" + Payment + "','" + PayCehck + "','" + PayDis + "','" + strPledgeStatus + "','" + Pledge + "'," +
                "'" + txtPayTotal.Text.ToDecimal().ToString() + "'" +
                ")";
            ListSql.Add(sql);
            //Insert Payment
            if (Convert.ToDouble(txtSumPayment.Text) > 0)
            {
                foreach (DataGridViewRow row in dgvPayment.Rows)
                {
                    try
                    {
                        String strBankBookCode = row.Cells[0].Value.ToString();
                        String strPay = row.Cells[6].Value.ToString();
                        sql = "INSERT INTO PAYMENT(SaleHeadId,BankBookCode,Pay)VALUES('" + txtCSHeadId.Text + "','" + strBankBookCode + "','" + strPay + "')";
                        ListSql.Add(sql);
                    }
                    catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
                }
            }
            //End insert payment
            //Insert PayCheck
            if (Convert.ToDouble(txtSumCheck.Text) > 0)
            {
                foreach (DataGridViewRow row in dgvPayCheck.Rows)
                {
                    try
                    {
                        String strPayCheckDate = row.Cells[3].Value.ToString();
                        DateTime date1 = DateTime.Parse(strPayCheckDate);
                        String strDay = date1.Day.ToString();
                        String strMonth = date1.Month.ToString();
                        String strYear = (Convert.ToInt16(date1.Year.ToString())).ToString();
                        String strDate = strYear + "-" + strMonth + "-" + strDay;
                        String strBankAccountId = row.Cells[0].Value.ToString();
                        String strBankBranch = row.Cells[2].Value.ToString();
                        String strCheckId = row.Cells[4].Value.ToString();
                        String strPay = row.Cells[5].Value.ToString();
                        sql = "INSERT INTO PAYCHECK(PayCheckDate,SaleHeadId,BankAccountId,BankBranch,CheckId,Pay)VALUES(" +
                            "'" + strDate + "','" + txtCSHeadId.Text + "','" + strBankAccountId + "','" + strBankBranch + "'," +
                            "'" + strCheckId + "','" + strPay + "')";
                        ListSql.Add(sql);
                    }
                    catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
                }
            }
            //End insert PayCheck

            List<string> iProductId = new List<string>();

            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                try
                {
                    String ProductId = row.Cells[0].Value.ToString();

                    iProductId.Add(ProductId);

                    Double QuantityPack = Convert .ToDouble ( row.Cells[2].Value.ToString());
                    Double QuantitySale = Convert .ToDouble ( row.Cells[4].Value.ToString());
                    String QuantityWeight = row.Cells[6].Value.ToString();
                    Double PricePerUnit = Convert.ToDouble ( row.Cells[8].Value.ToString());
                    String strDisText = row.Cells[9].Value.ToString();
                    String strDisPerUnit = row.Cells[10].Value.ToString();
                    String strDiscountBth = row.Cells[11].Value.ToString();
                    String data = row.Cells[12].Value.ToString();
                    String type = row.Cells[13].Value.ToString();
                    Double  PriceQuantity = Convert .ToDouble ( row.Cells[14].Value.ToString());
                    //String strCQHeadId = row.Cells[15].Value.ToString();

                    sql = "INSERT INTO CO_SALE_DETAIL(COSaleHeadId,ProductId,COSaleDetailQuantityPack,COSaleDetailQuantity,COSaleDetailWeight,COSaleDetailPriceUnit," +
                        "PriceQuantity,DisText,DisPerUnit,DiscountBth,DetailType,CQHeadId) " +
                        "VALUES ('" + txtCSHeadId.Text + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale.ToDecimal().ToString() + "','" + QuantityWeight + "','" + PricePerUnit.ToDecimal().ToString() + "'," +
                        "'" + PriceQuantity.ToDecimal().ToString() + "','" + strDisText + "','" + strDisPerUnit + "','" + strDiscountBth + "','" + type + "','')";
                    ListSql.Add(sql);

                    if (type != "3")
                    {
                        String[] weight = data.Split('#');
                        for (int i = 0; i < weight.Length - 1; i++)//1 2 3,4 5 6,7 8 9
                        {
                            if (i % ((type == "1") ? 3 : 2) == 0)
                            {
                                String Pack = weight[i];
                                String Quantity = weight[i + 1];
                                String Weight = "0";
                                if (((type == "1") ? 3 : 2) == 3)
                                {
                                    Weight = weight[i + 2];
                                }
                                sql = "INSERT INTO CO_SALE_WEIGHT(COSaleHeadId,ProductId,COSalePackId,COSalePack,COSaleWeight,CQHeadId) " +
                                  "VALUES ('" + txtCSHeadId.Text + "','" + ProductId + "','" + Pack + "','" + Quantity.ToDecimal().ToString() + "','" + Weight + "','')";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtCSHeadId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {

                if (DBConnString.clsDB.ExecuteTransaction(ListSql.ToArray()))
                {
                    List<String> ListSqlQty = new List<String>();
                    if (DBConnString.clsDB.ExecuteTransaction(ListSqlQty.ToArray()))
                    {
                        List<String> ListSqlsts = new List<String>();
                        if (DBConnString.clsDB.ExecuteTransaction(ListSqlsts.ToArray()))
                        {
                        }
                    }
                }

                SalePos7CSK.frmSaleOrderMatch frmcut = new SalePos7CSK.frmSaleOrderMatch(cust, txtCSHeadId.Text.Trim(), SalePos7CSK.CaseSrc.SaleDeposit);
                frmcut.showMsg = false;
                DataTable saleMath = frmcut.CustBalance(cust, iProductId);
                if (saleMath.Rows.Count > 0 || head != null)
                {
                    if (MessageBox.Show("พบสินค้าในใบสั่งขายสำหรับลูกค้านี้ ต้องการตัดใบสั่งขายหรือไหม", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                    {
                        if (head != null)
                        {
                            frmcut.CancelMatching(txtCSHeadId.Text.Trim());
                            frmcut.Reload();
                            frmcut.Match();
                        }
                        else
                        {
                            frmcut.Reload();
                            frmcut.Match();
                        }
                    }
                }

                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCSHeadId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 8, 0);
                    rpt.ShowDialog();
                }
                if (CheckFrom == 0) { setNewForm(); }
                else if (CheckFrom == 1) { this.Close(); }
            }
        }
Exemplo n.º 4
0
 private void จดการมดจำToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Cashier.frmEarnestMain frm = new Cashier.frmEarnestMain();
     frm.MdiParent = this;
     frm.Show();
 }