Ejemplo n.º 1
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(); }
            }
        }
Ejemplo n.º 2
0
 private void toolStripButton6_Click(object sender, EventArgs e)
 {
     StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataSale(), 8, 0);
     rpt.ShowDialog();
 }
Ejemplo n.º 3
0
        /*บันทึกข้อมูลของใบโอนสินค้าส่งไปฝากขายลงในฐานข้อมูล*/
        private void InsertValue()
        {
            String sql = "";
            List<String> ListSql = new List<String>();
            List<String> ListSqlQtyX = new List<String>();
            String arraydetailid = "";
            if (dgvHead.Rows.Count > 0)
            {
                arraydetailid += dgvHead.Rows[0].Cells[0].Value.ToString();
                for (int i = 1; i < dgvHead.Rows.Count; i++)
                {
                    arraydetailid += "," + dgvHead.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(COHeadId) from COSIGNMENT_STOCK_HEAD where COHeadId = '" + txtCOSentId.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE CO_STOCK_DETAIL WHERE COHeadId = '" + txtCOSentId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE COSIGNMENT_STOCK_HEAD WHERE COHeadId = '" + txtCOSentId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE RECEIVE_SHIP WHERE ReceiveHeadId = '" + txtCOSentId.Text + "' and shipType = '" + shipType + "' ";
                ListSql.Add(sql);
            }
            String CQNew = "";
            String CQ;
            for (int nbRow = 0; nbRow < dgvHead.Rows.Count; nbRow++)
            {
                CQ = dgvHead.Rows[nbRow].Cells[0].Value.ToString();
                if (CQNew != CQ)
                {
                    CQNew = CQ;
                    String sqldeleteR = "update CO_REQ_HEAD set COStatusId='1' where CQHeadId='" + CQNew + "'";
                    SqlDataReader readerUpdateHead1 = DBConnString.clsDB.QueryDataReader(sqldeleteR);
                }
            }
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String shipper = Class.Function.GetTextId(txtShipper.Text);
            String UserName = clsCash.sUserIdLogin;
            Double Summary = Convert.ToDouble(txtSummary.Text);
            sql = "INSERT INTO COSIGNMENT_STOCK_HEAD([COHeadId],[COHeadDate],[COHeadDateTime],[ShipperId],[UserName],[COTypeId],[COStatusId],[ConfirmId]," +
                "[PriceTotal],[DisText],[Dis],[VatBase],[VatType],[VatPer],[Vat],[TotalPrice],[Description],[GrStockDetailId],[Shipping],[Shipper],[ShipDate])" +
                "VALUES('" + txtCOSentId.Text + "','" + rdate + "',GETDATE(),'" + shipper + "','" + UserName + "','','1','1'," +
                "'','','','','','','','" + Summary.ToString("N2") + "','" + TxtDescription.Text + "','" + stock + "','','" + txtShippNumber.Text + "','" + Class.Function.GetDate(dtpShip.Value) + "')";
            ListSql.Add(sql);
            foreach (DataGridViewRow row in dgvHead.Rows)
            {
                try
                {
                    String strCQHeadId = row.Cells[0].Value.ToString();

                    sql = "INSERT INTO CO_STOCK_DETAIL([COHeadId],[CQHeadId],[Price])" +
                        "VALUES ('" + txtCOSentId.Text + "','" + strCQHeadId + "','')";
                    ListSql.Add(sql);
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            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 + ",'" + txtCOSentId.Text + "','" + strunit + "','" + shipType + "')";
                    ListSql.Add(sql);
                }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtCOSentId.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCOSentId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataReport(), 1, 0, txtCOSentId.Text);
                    rpt.ShowDialog();
                }
                if (CheckFrom == 0) { setNewForm(); }
                else if (CheckFrom == 1) { this.Close(); }
            }
        }
Ejemplo n.º 4
0
        private void insertAndUpdate()
        {
            String sql = "";
            List<String> ListSql = new List<String>();
            List<String> ListSqlQtyX = new List<String>();
            String arraydetailid = "";
            if (dgvTRDetail.Rows.Count > 0)
            {
                arraydetailid += dgvTRDetail.Rows[0].Cells[0].Value.ToString();
                for (int i = 1; i < dgvTRDetail.Rows.Count; i++)
                {
                    arraydetailid += "," + dgvTRDetail.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());
            }
            Int32 dCount;
            sql = "select count(TRHeadId) as count from TR_RE_HEAD where TRHeadId = '" + txtTRID.Text + "'";
            SqlDataReader reader = DBConnString.clsDB.QueryDataReader(sql);
            if (reader.Read())
            {
                dCount = Convert.ToInt32(reader["count"].ToString());
                if (dCount != 0)
                {
                    String sql1 = "DELETE TR_RE_WEIGHT WHERE TRHeadId = '" + txtTRID.Text + "' ";
                    ListSql.Add(sql1);
                    String sql2 = "DELETE TR_RE_DETAIL WHERE TRHeadId = '" + txtTRID.Text + "' ";
                    ListSql.Add(sql2);
                    String sql3 = "DELETE TR_RE_HEAD WHERE TRHeadId = '" + txtTRID.Text + "' ";
                    ListSql.Add(sql3);
                }
            }

            String cusid = Class.Function.GetTextId(txtBra.Text);
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String UserName = clsCash.sUserIdLogin;
            String PriceTotal = Convert.ToDouble(TxtPriceTotal.Text.Trim()) + "";
            String DisText = TxtDiscountText.Text.Trim().ToString();
            String Dis = Convert.ToDouble(TxtDiscount.Text.Trim()) + "";
            String VatBase = Convert.ToDouble(TxtBaseVat.Text.Trim()) + "";
            String VatPer = Convert.ToDouble(TxtPercentVat.Text.Trim()) + "";
            String Vat = Convert.ToDouble(TxtVat.Text.Trim()) + "";
            String TotalPrice = Convert.ToDouble(TxtAmountTotal.Text.Trim()) + "";
            String Description = txtDesc.Text.Trim();
            if (CmboxVat.SelectedIndex == 0) { VatType = "1"; }
            else if (CmboxVat.SelectedIndex == 1) { VatType = "7"; }
            else if (CmboxVat.SelectedIndex == 2) { VatType = "8"; }

            sql = "INSERT INTO TR_RE_HEAD([TRHeadId],[TRHeadDate],[TRHeadDateTime],[TRRound],[TRHeadStatusId],[TRHeadConfirmStatus],[TRTotalPrice],[TRDiscountText]," +
                "[TRDiscount],[TRBaseVat],[Tax_auto_id],[TRRateVat],[TRVat],[TRShipping],[TRSumPrice],[Description],[UserName],[CustomerId],[Reqs])" +
                "VALUES('" + txtTRID.Text + "','" + rdate + "',GETDATE(),'" + txtRou.Text + "','1','1','" + PriceTotal + "','" + DisText + "','" + Dis + "'," +
                "'" + VatBase + "','" + VatType + "','" + VatPer + "','" + Vat + "','" + textBox1.Text + "','" + TotalPrice + "','" + Description + "','" + UserName + "'," +
                "'" + cusid + "','')";
            ListSql.Add(sql);

            foreach (DataGridViewRow row in dgvTRDetail.Rows)
            {
                try
                {
                    String ProductId = row.Cells[0].Value.ToString();
                    String QuantityPack = Convert.ToDouble(row.Cells[2].Value.ToString()).ToString();
                    String QuantitySale = Convert.ToDouble(row.Cells[4].Value.ToString()).ToString();
                    String QuantityWeight = Convert.ToDouble(row.Cells[6].Value.ToString()).ToString();
                    String PricePerUnit = Convert.ToDouble(row.Cells[8].Value.ToString()).ToString();
                    String strDisText = row.Cells[9].Value.ToString().ToString();
                    String strDisPerUnit = Convert.ToDouble(row.Cells[10].Value.ToString()).ToString();
                    String strDiscountBth = Convert.ToDouble(row.Cells[11].Value.ToString()).ToString();
                    String data = row.Cells[12].Value.ToString();
                    String type = row.Cells[13].Value.ToString();
                    String PriceQuantity = Convert.ToDouble(row.Cells[14].Value.ToString()).ToString();

                    sql = "INSERT INTO TR_RE_DETAIL([TRHeadId],[ProductId],[TRDetailQuantityPack],[TRDetailQuantity],[TRDetailWeight]," +
                        "[TRDetailPriceUnit],[DiscountBth],[DisText],[PriceQuantity],[DetailType],[DisPerUnit]) " +
                        "VALUES ('" + txtTRID.Text + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale + "','" + QuantityWeight + "','" + PricePerUnit + "'," +
                        "'" + strDiscountBth + "','" + strDisText + "','" + PriceQuantity + "','" + type + "','" + strDisPerUnit + "')";
                    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 TR_RE_WEIGHT([TRWeight],[ProductId],[TRHeadId],[TRPackId],[TRPack]) " +
                                  "VALUES ('" + Weight + "','" + ProductId + "','" + txtTRID.Text + "','" + Pack + "','" + Quantity + "')";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ตรงรูปแบบ"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลใบโอนสินค้าใหม่เลขที่ " + txtTRID.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtTRID.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 5, 0);
                    rpt.ShowDialog();
                }
                if (CheckForm == 0) { setNewForm(); }
                else if (CheckForm == 1) { this.Close(); }
            }
        }
Ejemplo n.º 5
0
 private void toolStripButton6_Click(object sender, EventArgs e)
 {
     if (CheckSearch == 1)
     {
         StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataSE(), 6, 0);
         rpt.ShowDialog();
     }
     else if (CheckSearch == 2)
     {
         StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataRE(), 5, 0);
         rpt.ShowDialog();
     }
 }
Ejemplo n.º 6
0
        /*บันทึกใบเบิกสินค้าส่งไปฝากขายลงในฐานข้อมูล*/
        private void insertAndUpdate()
        {
            String sql = "";
            List<String> ListSql = new List<String>();
            String rid = txtReq.Text;
            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(CQHeadId) from CO_REQ_HEAD where CQHeadId = '" + txtReq.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE FROM CO_REQ_WEIGHT WHERE CQHeadId = '" + rid + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_REQ_DETAIL WHERE CQHeadId = '" + rid + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_REQ_HEAD WHERE CQHeadId = '" + rid + "' ";
                ListSql.Add(sql);
            }

            String cust = Class.Function.GetTextId(txtTotal.Text);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String UserName = clsCash.sUserIdLogin;
            String Desc = txtDesc.Text.Trim();
            Double Total = Convert.ToDouble(txtTotal.Text);

            sql = "INSERT INTO CO_REQ_HEAD([CQHeadId],[CQHeadDate],[CQHeadDateTime],[GrStockDetailId],[CustomerId],[UserName],[CQStatusId],[ConfirmId],[Description]," +
                "[COStatusId],[Total])" +
                "VALUES('" + rid + "','" + rdate + "',GETDATE(),'" + stock + "','" + cust + "','" + UserName + "','1','1','" + Desc + "','0','" + Total.ToString ("N2") + "')" +
                "";
            ListSql.Add(sql);
            int j = 0;

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

            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                getNewDetailID();
                j = j + 1;
                String strNewCQID=(strMax+j).ToString ();

                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();
                String PricePerUnit = Convert.ToDouble(row.Cells[8].Value.ToString()).ToString("N2");
                String data = row.Cells[9].Value.ToString();
                String type = row.Cells[10].Value.ToString();
                Double PriceQuantity = Convert.ToDouble(row.Cells[11].Value.ToString());
                sql = "INSERT INTO CO_REQ_DETAIL(CQDetailId,CQHeadId,ProductId,CQDetailQuantityPack,CQDetailQuantity,CQDetailWeight,CQDetailPriceUnit," +
                    "PriceQuantity,DisText,DisPerUnit,DiscountBth,DetailType) " +
                    "VALUES ('" + strNewCQID + "','" + rid + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale + "','" + QuantityWeight + "','" + PricePerUnit + "'," +
                    "'" + PriceQuantity.ToString("N2") +"','0.00','0.00','0.00','" + 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_REQ_WEIGHT(CQHeadId,ProductId,CQPackId,CQPack,CQWeight,CQDetailId) " +
                              "VALUES ('" + rid + "','" + ProductId + "'," + Pack + "," + Quantity + "," + Weight + ",'" + strNewCQID + "')";
                            ListSql.Add(sql);
                        }
                    }
                }

                try
                {
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ตรงรูปแบบ"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลใบเบิกใหม่เลขที่ " + rid + "\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()))
                        {
                        }
                    }
                }
                /*
                */

                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + rid + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 7, 0, txtReq.Text);
                    rpt.ShowDialog();
                }
                if (CheckFrom == 0) { setNewForm(); }
                else if (CheckFrom == 1) { this.Close(); }
            }
        }
Ejemplo n.º 7
0
        /*บันทึกข้อมูลยอดยกมาสินค้าฝากลงในฐานข้อมูล*/
        private void InsertValue()
        {
            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(CoBringHeadId) from CO_BRI_HEAD where CoBringHeadId = '" + txtCoBringHeadId.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE CO_BRI_DETAIL WHERE CoBringHeadId = '" + txtCoBringHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE CO_BRI_HEAD WHERE CoBringHeadId = '" + txtCoBringHeadId.Text + "' ";
                ListSql.Add(sql);
            }

            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String UserName = clsCash.sUserIdLogin;

            sql = "INSERT INTO [CO_BRI_HEAD] VALUES (" +
                "'" + txtCoBringHeadId.Text + "','" + rdate + "',GETDATE(),'" + stock + "','" + txtDesc.Text + "','" + UserName + "'" +
                ")";
            ListSql.Add(sql);
            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                try
                {
                    String strPack, strQtty;
                    String strProductId = row.Cells[0].Value.ToString();
                    if (row.Cells[2].Value.ToString() == "") { strPack = "0.00"; }
                    else { strPack = Convert.ToDouble(row.Cells[2].Value.ToString()).ToString("N2"); }
                    if (row.Cells[4].Value.ToString() == "") { strQtty = "0.00"; }
                    else { strQtty = Convert.ToDouble(row.Cells[4].Value.ToString()).ToString("N2"); }

                    sql = "INSERT INTO CO_BRI_DETAIL(CoBringHeadId,ProductId,Pack,Quantity)" +
                        "VALUES ('" + txtCoBringHeadId.Text + "','" + strProductId + "','" + strPack + "','" + strQtty + "')";
                    ListSql.Add(sql);
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtCoBringHeadId.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCoBringHeadId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataReport(), 12);
                    rpt.ShowDialog();
                }
                if (CheckFrom == 0) { setNewForm(); }
                else if (CheckFrom == 1) { this.Close(); }
            }
        }
Ejemplo n.º 8
0
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     if (HeadId == null) { MessageBox.Show("กรุณาเลือกรายการเพื่อพิมพ์รายงาน"); }
     else
     {
         StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataSent(), 12);
         rpt.ShowDialog();
     }
 }
Ejemplo n.º 9
0
        private void SaveDataSale()
        {
            String sql = "";
            List<String> ListSql = new List<String>();
            List<String> ListSqlQtyX = new List<String>();
            String arraydetailid = "";
            if (dgvSaleDetail.Rows.Count > 0)
            {
                arraydetailid += dgvSaleDetail.Rows[0].Cells[0].Value.ToString();
                for (int i = 1; i < dgvSaleDetail.Rows.Count; i++) { arraydetailid += "," + dgvSaleDetail.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 = '" + txtSaleId.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 = '" + txtSaleId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_SALE_DETAIL WHERE COSaleHeadId = '" + txtSaleId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_SALE_HEAD WHERE COSaleHeadId = '" + txtSaleId.Text + "' ";
                ListSql.Add(sql);
            }
            if (strReqId == txtRequis.Text)
            {
                String sqldeleteR = "update SALE_APP_HEAD set statusId='3',SaleHeadId=null where SdateId='" + txtRequis.Text + "'";
                SqlDataReader readerUpdateHead1 = DBConnString.clsDB.QueryDataReader(sqldeleteR);
            }
            else
            {
                String sqldeleteR = "update SALE_APP_HEAD set statusId='5',SaleHeadId=null where SdateId='" + strReqId + "'";
                SqlDataReader readerUpdateHead1 = DBConnString.clsDB.QueryDataReader(sqldeleteR);

                sqldeleteR = "update SALE_APP_HEAD set statusId='3',SaleHeadId=null where SdateId='" + txtRequis .Text + "'";
                readerUpdateHead1 = DBConnString.clsDB.QueryDataReader(sqldeleteR);
            }

            String supid = Class.Function.GetTextId(txtSupplier.Text);
            String shipid = Class.Function.GetTextId(txtShipper.Text);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String rdate = Class.Function.GetDate(dptSaleDate.Value);
            String UserName = clsCash.sUserIdLogin;
            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],[COSaleHeadPayTypeId],[ShipperId],[SdateId],[COHeadId],[COTotalPrice],[CODiscount],[COBaseVat],[Tax_auto_id],[CORateVat]," +
                "[COSaleVat],[COSaleShipping],[COSumPrice],[COCash],[CODeposit],[COCredit],[CODescription],[UserName],[CODiscountText],[Shipper],[GrStockDetailId])" +
                "VALUES('" + txtSaleId.Text + "','" + rdate + "',GETDATE(),'" + supid + "','1','1','" + strPayType + "','" + shipid + "'," +
                "'" + txtRequis.Text + "','','" + TxtPriceTotal.Text + "','" + TxtDiscount.Text + "','" + TxtBaseVat.Text + "','" + strVat + "'," +
                "'" + TxtPercentVat.Text + "','" + TxtVat.Text + "','" + textBox1.Text + "','" + TxtAmountTotal.Text + "',''," +
                "'','','" + TxtDescription.Text + "','" + UserName + "','" + TxtDiscountText.Text + "','" + txtShipp.Text + "','" + stock + "')";
            ListSql.Add(sql);
            foreach (DataGridViewRow row in dgvSaleDetail.Rows)
            {
                try
                {
                    String ProductId = row.Cells[0].Value.ToString();
                    String QuantityPack = Convert.ToDouble(row.Cells[2].Value.ToString()).ToString();
                    String QuantitySale = Convert.ToDouble(row.Cells[4].Value.ToString()).ToString();
                    String QuantityWeight = Convert.ToDouble(row.Cells[6].Value.ToString()).ToString();
                    String PricePerUnit = Convert.ToDouble(row.Cells[8].Value.ToString()).ToString();
                    String strDisText = row.Cells[9].Value.ToString().ToString();
                    String strDisPerUnit = Convert.ToDouble(row.Cells[10].Value.ToString()).ToString();
                    String strDiscountBth = Convert.ToDouble(row.Cells[11].Value.ToString()).ToString();
                    String data = row.Cells[12].Value.ToString();
                    String type = row.Cells[13].Value.ToString();
                    String PriceQuantity = Convert.ToDouble(row.Cells[14].Value.ToString()).ToString();

                    sql = "INSERT INTO CO_SALE_DETAIL(COSaleHeadId,ProductId,COSaleDetailQuantityPack,COSaleDetailQuantity,COSaleDetailWeight,COSaleDetailPriceUnit," +
                        "PriceQuantity,DisText,DisPerUnit,DiscountBth,DetailType) " +
                        "VALUES ('" + txtSaleId.Text + "','" + ProductId + "'," + QuantityPack + "," + QuantitySale + "," + QuantityWeight + "," + PricePerUnit + "," +
                        "" + PriceQuantity + ",'" + 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) " +
                                  "VALUES ('" + txtSaleId.Text + "','" + ProductId + "'," + Pack + "," + Quantity + "," + Weight + ")";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtSaleId.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtSaleId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 2, 0);
                    rpt.ShowDialog();
                }
                if (CheckForm == 0) { setNewForm(); }
                else if (CheckForm == 1) { this.Close(); }
            }
        }
Ejemplo n.º 10
0
        /*บันทึกข้อมูลของใบรับคืนสินค้าฝากจากลูกค้าลงในฐานข้อมูล*/
        private void saveDataSale()
        {
            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(CCHeadId) from CO_RECUST_HEAD where CCHeadId = '" + txtCCHeadId.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE FROM CO_RECUST_WEIGHT WHERE CCHeadId = '" + txtCCHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_RECUST_DETAIL WHERE CCHeadId = '" + txtCCHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_RECUST_HEAD WHERE CCHeadId = '" + txtCCHeadId.Text + "' ";
                ListSql.Add(sql);
            }
            String FromStatus;
            if (radioButton1.Checked == true) { FromStatus = "1"; }
            else { FromStatus = "2"; }
            String strDiscount = TxtDiscount.Text;
            String cust = Class.Function.GetTextId(txtCustomer.Text);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String UserName = clsCash.sUserIdLogin;
            Double Ship = Convert.ToDouble(textBox1.Text);
            if (CmboxVat.SelectedIndex == 0) { strVat = "1"; }
            else if (CmboxVat.SelectedIndex == 1) { strVat = "7"; }
            else if (CmboxVat.SelectedIndex == 2) { strVat = "8"; }
            sql = "INSERT INTO [CO_RECUST_HEAD]([CCHeadId],[CCHeadDate],[CCHeadDateTime],[CustomerId],[CCHeadStatusId],[CCHeadConfirmStatus],[CCTotalPrice]," +
                "[CCDiscount],[CCBaseVat],[Tax_auto_id],[CCRateVat],[CCVat],[CCShipping],[CCSumPrice],[CCDescription],[UserName],[CCDiscountText],[GrStockDetailId],[CCFromStatus])" +
                "VALUES('" + txtCCHeadId.Text + "','" + rdate + "',GETDATE(),'" + cust + "','1','1','" + TxtPriceTotal.Text + "'," +
                "'" + strDiscount + "','" + TxtBaseVat.Text + "','" + strVat + "','" + TxtPercentVat.Text + "','" + TxtVat.Text + "','" + Ship .ToString ("N2") + "'," +
                "'" + TxtAmountTotal.Text + "','" + TxtDescription.Text + "','" + UserName + "','" + TxtDiscountText.Text + "','" + stock + "','" + FromStatus + "')";
            ListSql.Add(sql);
            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                try
                {
                    String ProductId = row.Cells[0].Value.ToString();
                    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();
                    String PricePerUnit = 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();
                    String PriceQuantity = row.Cells[14].Value.ToString();
                    String strCQHeadId = row.Cells[15].Value.ToString();

                    sql = "INSERT INTO [CO_RECUST_DETAIL]([CCHeadId],[ProductId],[CCDetailQuantityPack],[CCDetailQuantity],[CCDetailWeight]," +
                        "[CDetailPriceUnit],[DiscountBth],[DisText],[PriceQuantity],[DetailType],[DisPerUnit])" +
                        "VALUES('" + txtCCHeadId.Text + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale + "','" + QuantityWeight + "'," +
                        "'" + PricePerUnit + "','" + strDiscountBth + "','" + strDisText + "','" + PriceQuantity + "','" + type + "','" + strDisPerUnit + "')";
                      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_RECUST_WEIGHT]([CCHeadId],[ProductId],[CCPackId],[CCPack],[CCWeight]) " +
                                  "VALUES ('" + txtCCHeadId.Text + "','" + ProductId + "'," + Pack + "," + Quantity + "," + Weight + ")";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลใบรับคืนสินค้าใหม่เลขที่ " + txtCCHeadId.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCCHeadId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataSale(), 9, 0);
                    rpt.ShowDialog();
                }
                if (CheckFrom == 0) { setNewForm(); }
                else if (CheckFrom == 1) { this.Close(); }
            }
        }
Ejemplo n.º 11
0
 private void toolStripButton4_Click(object sender, EventArgs e)
 {
     StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataReq(), 7, 0, strCQHeadId);
     rpt.ShowDialog();
 }
Ejemplo n.º 12
0
        /*บันทึกใบรับคืนสินค้าฝากในฐานข้อมูล*/
        private void SaveData()
        {
            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(CRHeadId) from CO_RE_HEAD where CRHeadId = '" + txtCRHeadId.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE FROM CO_RE_WEIGHT WHERE CRHeadId = '" + txtCRHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_RE_DETAIL WHERE CRHeadId = '" + txtCRHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_RE_HEAD WHERE CRHeadId = '" + txtCRHeadId.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM RECEIVE_SHIP WHERE ReceiveHeadId = '" + txtCRHeadId.Text + "' and shipType = '" + shipType + "' ";
                ListSql.Add(sql);
            }
            String stock = Class.Function.GetTextId(txtStock.Text);
            String shipid = Class.Function.GetTextId(txtShipper.Text);
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String UserName = clsCash.sUserIdLogin;
            Double Summary = Convert.ToDouble(txtSummary.Text);
            sql = "INSERT INTO CO_RE_HEAD([CRHeadId],[CRHeadDate],[CRHeadDateTime],[GrStockDetailId],[CRHeadStatusId],[CRHeadConfirmStatus],[ShipperId],[COHeadId]," +
                "[CRTotalPrice],[CRDiscount],[CRBaseVat],[Tax_auto_id],[CRRateVat],[CRVat],[CRShipping],[CRSumPrice],[CRDescription],[UserName],[CRDiscountText]," +
                "[Shipper],[ShipDate])" +
                "VALUES('" + txtCRHeadId.Text + "','" + rdate + "',GETDATE(),'" + stock + "','1','1','" + shipid + "',''," +
                "'','','','',''," +
                "'','','" + Summary.ToString("N2") + "','" + TxtDescription.Text + "','" + UserName + "','','" + txtShippNumber.Text + "','" + Class.Function.GetDate(dtpShip.Value) + "')";
            ListSql.Add(sql);
            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                try
                {
                    String ProductId = row.Cells[0].Value.ToString();
                    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();
                    String PricePerUnit = Convert.ToDouble(row.Cells[8].Value.ToString()).ToString("N2");
                    String data = row.Cells[9].Value.ToString();
                    String type = row.Cells[10].Value.ToString();
                    Double PriceQuantity = Convert.ToDouble(row.Cells[11].Value.ToString());

                    sql = "INSERT INTO CO_RE_DETAIL([CRHeadId],[ProductId],[CRDetailQuantityPack],[CRDetailQuantity],[CRDetailWeight]," +
                        "[CRDetailPriceUnit],[DiscountBth],[DisText],[PriceQuantity],[DetailType],[DisPerUnit])" +
                        "VALUES ('" + txtCRHeadId.Text + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale + "','" + QuantityWeight + "'," +
                        "'" + PricePerUnit + "','0.00','0.00','" + PriceQuantity.ToString ("N2") + "','" + type + "','0.00')";
                    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_RE_WEIGHT([CRWeight],[ProductId],[CRHeadId],[CRPackId],[CRPack])" +
                                  "VALUES ('" + Weight + "','" + ProductId + "','" + txtCRHeadId.Text + "','" + Pack + "','" + Quantity + "')";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            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 + ",'" + txtCRHeadId.Text + "','" + strunit + "'," + shipType + ")";
                    ListSql.Add(sql);
                }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtCRHeadId.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCRHeadId.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 3, 0);
                    rpt.ShowDialog();
                }
                if (CheckForm == 0) { setNewForm(); }
                else if (CheckForm == 1) { this.Close(); }
            }
        }
Ejemplo n.º 13
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (dgvStockKey.Rows.Count <= 0)
     {
         MessageBox.Show("กรุณาค้นหาข้อมูลก่อน");
     }
     else
     {
         StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataReport(), 10, 0);
         rpt.ShowDialog();
     }
 }
Ejemplo n.º 14
0
        private void SaveDataCD()
        {
            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(CDHeadId) from CO_REAM_HEAD where CDHeadId = '" + txtCDID.Text + "'";
            DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
            Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
            if (Count != 0)
            {
                sql = "DELETE FROM CO_REAM_WEIGHT WHERE CDHeadId = '" + txtCDID.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_REAM_DETAIL WHERE CDHeadId = '" + txtCDID.Text + "' ";
                ListSql.Add(sql);
                sql = "DELETE FROM CO_REAM_HEAD WHERE CDHeadId = '" + txtCDID.Text + "' ";
                ListSql.Add(sql);
            }
            String rdate = Class.Function.GetDate(dateTimePicker1.Value);
            String stock = Class.Function.GetTextId(txtStock.Text);
            String UserName = clsCash.sUserIdLogin;
            Double Price = Convert.ToDouble(TxtPriceTotal.Text);

            sql = "INSERT INTO CO_REAM_HEAD(" +
                "CDHeadId,CDHeadDate,CDHeadDateTime,CDTypeId,CDHeadStatusId," +
                "ConfirmId,CDTotalPrice,[Description],[UserName],CustomerId" +
                ")VALUES(" +
                "'" + txtCDID.Text + "','" + rdate + "',GETDATE(),'" + cmbType.SelectedValue + "','1'," +
                "'1','" + Price + "','" + txtDesc.Text + "','" + UserName + "','" + Class.Function.GetTextId(textBox1.Text) + "'" +
                ")";
            ListSql.Add(sql);

            //Set status RO
            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                if (row.Cells[11].Value.ToString() != "")
                {
                    String strROId = row.Cells[11].Value.ToString();
                    sql = "UPDATE SALE_APP_HEAD set statusId='7',SaleHeadId='" + txtCDID.Text + "' where SdateId='" + strROId + "' ";
                    ListSql.Add(sql);
                }
            }//End set status RO

            foreach (DataGridViewRow row in dgvDetail.Rows)
            {
                try
                {

                    String ProductId = row.Cells[0].Value.ToString();
                    Double QuantityPack = Convert.ToDouble(row.Cells[2].Value.ToString());
                    Double QuantitySale = Convert.ToDouble(row.Cells[4].Value.ToString());
                    Double QuantityWeight = Convert.ToDouble(row.Cells[6].Value.ToString());
                    Double PricePerUnit = Convert .ToDouble ( row.Cells[7].Value.ToString());
                    String data = row.Cells[8].Value.ToString();
                    String type = row.Cells[9].Value.ToString();
                    Double PriceQuantity = Convert.ToDouble(row.Cells[10].Value.ToString());
                    String SdateId = row.Cells[11].Value.ToString();
                    //String strSdateId = row.Cells[12].Value.ToString();

                    sql = "INSERT INTO CO_REAM_DETAIL(" +
                        "CDHeadId,ProductId,CDDetailQuantityPack,CDDetailQuantity,CDDetailWeight," +
                        "CDDetailPriceUnit,PriceQuantity,DetailType,SdateId" +
                        ")VALUES (" +
                        "'" + txtCDID.Text + "','" + ProductId + "','" + QuantityPack + "','" + QuantitySale + "','" + QuantityWeight + "'," +
                        "'" + PricePerUnit + "','" + PriceQuantity + "','" + type + "','" + SdateId + "'" +
                        ")";
                    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_REAM_WEIGHT([CDWeight],[ProductId],[CDHeadId],[CDPackId],[CDPack])" +
                                  "VALUES ('" + Weight + "','" + ProductId + "','" + txtCDID.Text + "','" + Pack + "','" + Quantity + "')";
                                ListSql.Add(sql);
                            }
                        }
                    }
                }
                catch { MessageBox.Show("error กรุณาป้อนข้อมูลให้ครบถ้วน"); return; }
            }

            if (MessageBox.Show("คุณต้องการบันทึกข้อมูลขายใหม่เลขที่ " + txtCDID.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()))
                        {
                        }
                    }
                }
                if (MessageBox.Show("บันทึกสำเร็จ คุณต้องการพิมพ์รายงาน " + txtCDID.Text + "\nใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StockAsiaDrink.COReport rpt = new StockAsiaDrink.COReport(DataPrice(), 4, 0);
                    rpt.ShowDialog();
                }
                if (CheckForm == 0) { setNewForm(); }
                else if (CheckForm == 1) { this.Close(); }
            }
        }