Пример #1
0
 private void พมพสลปToolStripMenuItem_Click(object sender, EventArgs e)
 {
     String strSaleHeadId = rowSelect().Cells[1].Value.ToString();
     String sub = strSaleHeadId.Substring(0, 2);
     if (sub == "SC" || sub == "SO")
     {
         if (dataGridView1.SelectedRows.Count == 0 && dataGridView4.SelectedRows.Count == 0) { return; }
         SalePosNew.frmCallReport rpt = new SalePosNew.frmCallReport(Slip(), 11);
         rpt.ShowDialog();
     }
     else
     {
         Sale.rptSlip rptShowSaleSelect = new KTCERP.Sale.rptSlip();
         rptShowSaleSelect.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
         rptShowSaleSelect.setSaleId = Convert.ToInt32(strSaleHeadId);
         rptShowSaleSelect.ShowDialog();
     }
 }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (!DBConnString.clsDB.IsConnected()) return;
     Sale.rptSlip rptShowSaleSelect = new KTCERP.Sale.rptSlip();
     rptShowSaleSelect.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
     rptShowSaleSelect.setSaleId = Convert.ToInt32(SaleId);
     rptShowSaleSelect.ShowDialog();
 }
Пример #3
0
        private void cmdExchange_Click(object sender, EventArgs e)
        {
            // แสดงค่ารหัสรอบที่ขาย
            SaleId();
            MaxLogSaleId();
            //
            Sale.frmCalculateMoney frmCal = new KTCERP.Sale.frmCalculateMoney(lblNet.Text);
            frmCal.StartPosition = FormStartPosition.CenterParent;
            frmCal.ShowDialog();
            double CashTotal = clsCash.sCashMoney;
            double Discount = clsCash.sDiscount;

            double CreditTotal = clsCash.sCredit;
            double Exchange = clsCash.sExchange;
            string TypeCash = clsCash.sTypeCash;
            float SaleTotalCal = 0;
            float SaleTotal = 0;
            if (clsCash.sStatusCash == "1" || clsCash.sStatusCash == "2")
            {
                if (MessageBox.Show("คุณต้องการบันทึกรายการสั่งซื้อสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    tr = Conn.BeginTransaction();
                    //SaleId();
                    try
                    {
                        string sqlSave;
                        sb.Remove(0, sb.Length);
                        sb.Append("INSERT INTO SALE_HEAD(SaleHeadId,SaleHeadDate,CustomerId,SaleHeadStatusId,SaleHeadPayTypeId,Discount,Cash,SaleVat,SaleShipping,SaleVarious,SaleHeadDateTime,UserName,SaleHeadSaleTypeId )");
                        sb.Append(" VALUES (@SaleHeadId,@SaleHeadDate,@CustomerId,@SaleHeadStatus,@SaleHeadPayType,@Discount,@Cash,@SaleVat,@SaleShipping,@SaleVarious,@SaleHeadDateTime,@UserName,@SaleHeadSaleTypeId)");

                        sqlSave = sb.ToString();

                        com.Parameters.Clear();
                        com.Transaction = tr;
                        com.CommandText = sqlSave;
                        com.Parameters.Add("@saleHeadId", SqlDbType.Int).Value = saleId;
                       // com.Parameters.Add("@saleHeadDate", SqlDbType.DateTime).Value = dptSaleDate.Value.ToString("dd/MM/yyyy");

                        if (dptSaleDate.Value.ToString("dd/MM/yyyy") == DateTime.Now.ToString("dd/MM/yyyy"))
                        {
                            //MessageBox.Show("datnow" + DateTime.Now);
                            com.Parameters.Add("@SaleHeadDateTime", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                            com.Parameters.Add("@saleHeadDate", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy");
                        }
                        else
                        {
                            com.Parameters.Add("@SaleHeadDateTime", SqlDbType.DateTime).Value = dptSaleDate.Value.ToString("dd/MM/yyyy HH:mm:ss");
                            com.Parameters.Add("@saleHeadDate", SqlDbType.DateTime).Value = dptSaleDate.Value.ToString("dd/MM/yyyy");
                        }
                        com.Parameters.Add("@CustomerId", SqlDbType.NVarChar).Value = CustomerId;
                        com.Parameters.Add("@SaleHeadStatus", SqlDbType.NVarChar).Value = 1;
                        com.Parameters.Add("@SaleHeadPayType", SqlDbType.NVarChar).Value = clsCash.sStatusCash;
                        com.Parameters.Add("@Discount", SqlDbType.Float).Value = Discount;
                        com.Parameters.Add("@Cash", SqlDbType.Float).Value = CashTotal;
                        com.Parameters.Add("@SaleVat", SqlDbType.Float).Value = Convert.ToSingle(lblNetVAT.Text);
                        com.Parameters.Add("@SaleShipping", SqlDbType.Float).Value = Convert.ToSingle(lblShipping.Text);
                        com.Parameters.Add("@SaleVarious", SqlDbType.Float).Value = Convert.ToSingle(lblVarious.Text);
                        com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userId;
                        com.Parameters.Add("@SaleHeadSaleTypeId", SqlDbType.Int).Value = cboTypeSale.SelectedValue.ToString();

                        com.ExecuteNonQuery();
                        //MessageBox.Show(sqlSave);

                        for (int i = 0; i <= lsvProductList.Items.Count - 1; i++)
                        {

                            sb.Remove(0, sb.Length);
                            sb.Append("INSERT INTO SALE_DETAIL (SaleHeadId,ProductId,SaleDetailQuantity,SaleDetailPriceUnit,SaleDetailTotal,AmountProduct )");
                            sb.Append(" VALUES( @SaleHeadId,@ProductId,@SaleDetailQuantity,@SaleDetailPriceUnit,@SaleDetailTotal,@AmountProduct)");

                            sqlSave = sb.ToString();

                            com.Parameters.Clear();
                            com.CommandText = sqlSave;
                            com.Parameters.Add("@SaleHeadId", SqlDbType.Int).Value = saleId;
                            com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                            com.Parameters.Add("@SaleDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", "")).ToString("#,##0.00");
                            com.Parameters.Add("@SaleDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[7].Text.Replace(",", "")).ToString("#,##0.0000");
                            com.Parameters.Add("@SaleDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", "")).ToString("#,##0.00");
                            if (lsvProductList.Items[i].SubItems[2].Text.Replace(",", "") != "")
                            {
                                com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[2].Text.Replace(",", ""));
                            }
                            else
                            {
                                com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = 0;
                            }
                            com.ExecuteNonQuery();
                            //MessageBox.Show(sqlSave);
                            SaleTotalCal = SaleTotalCal + (Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", ""))) * (Convert.ToSingle(lsvProductList.Items[i].SubItems[7].Text.Replace(",", "")));
                            SaleTotal = SaleTotal + (Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", "")));

                                            string weightext = lsvProductList.Items[i].SubItems[6].Text.ToString();

                                            string[] weighttextarr = weightext.Split('#');
                                            int len = weighttextarr.Length;

                                            if (weightext != "")
                                            {

                                                for (int j = 0; j < weighttextarr.Length - 1; j++)
                                                {
                                                    sb.Remove(0, sb.Length);

                                                    sb.Append("INSERT INTO SALE_WEIGHT (SaleWeight,ProductId,SaleHeadId)");
                                                    sb.Append(" VALUES(@saleWeight,@ProductId,@saleHeadId)");
                                                    sqlSave = sb.ToString();
                                                    com.Parameters.Clear();
                                                    com.CommandText = sqlSave;
                                                    com.Parameters.Add("@saleHeadId", SqlDbType.Int).Value = saleId;
                                                    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                                                    com.Parameters.Add("@saleWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");

                                                    com.ExecuteNonQuery();

                                                    //MessageBox.Show(sqlSave);
                                                }
                                            }
                            //บันทึกลูกหนี้
                            if (clsCash.sStatusCash == "2")
                            {
                                sb.Remove(0, sb.Length);

                                sb.Append("INSERT INTO RECEIVABLE (ReceivableDate, CustomerId, ReceivebleType, ReceivebleTopic, SaleHeadId, ProductId, Amount, UnitPrice)");
                                sb.Append(" VALUES(@ReceivableDate,@CustomerId,@ReceivebleType,@ReceivebleTopic,@SaleHeadId,@ProductId,@Amount,@UnitPrice)");

                                sqlSave = sb.ToString();
                                com.Parameters.Clear();
                                com.CommandText = sqlSave;

                                com.Parameters.Add("@ReceivableDate", SqlDbType.DateTime).Value = dptSaleDate.Value.ToString("dd/MM/yyyy");
                                com.Parameters.Add("@CustomerId", SqlDbType.Int).Value = CustomerId;
                                com.Parameters.Add("@ReceivebleType", SqlDbType.Int).Value = 0; // 0 = ตั้งหนี้จากการขายที่ยังไม่ยืนนยัน , 1= ตั้งหนี้จากการขายที่ยืนยัน , 2=ชำระหนี้//
                                com.Parameters.Add("@ReceivebleTopic", SqlDbType.NVarChar).Value = "ค้างชำระค่าสินค้า ";
                                com.Parameters.Add("@SaleHeadId", SqlDbType.Int).Value = saleId;
                                com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                                com.Parameters.Add("@Amount", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@UnitPrice", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[7].Text.Replace(",", "")).ToString("#,##0.00");
                                com.ExecuteNonQuery();

                            }

                        }
                        // บันทึก log

                        sb.Remove(0, sb.Length);
                        sb.Append("INSERT INTO LOGSALE(LogSaleId,SaleHeadId,LogSaleDateTime,LogSaleTransection,LogsaleTotalCal,LogsaleTotal,UserName)");
                        sb.Append(" VALUES (@LogSaleId,@SaleHeadId,@LogSaleDateTime,@LogSaleTransection,@LogsaleTotalCal,@LogsaleTotal,@UserName)");

                        sqlSave = sb.ToString();

                        com.Parameters.Clear();
                        com.Transaction = tr;
                        com.CommandText = sqlSave;
                        //LogSaleId
                        com.Parameters.Add("@LogSaleId", SqlDbType.Int).Value = LogSaleId;
                        com.Parameters.Add("@saleHeadId", SqlDbType.Int).Value = saleId;
                        com.Parameters.Add("@LogSaleDateTime", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                        com.Parameters.Add("@LogSaleTransection", SqlDbType.Int).Value = lsvProductList.Items.Count;
                        com.Parameters.Add("@LogsaleTotalCal", SqlDbType.Float).Value = SaleTotalCal.ToString("#,##0.00");
                        com.Parameters.Add("@LogsaleTotal", SqlDbType.Float).Value = SaleTotal.ToString("#,##0.00");
                        com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userId;
                        com.ExecuteNonQuery();

                        for (int i = 0; i <= lsvProductList.Items.Count - 1; i++)
                        {
                            sb.Remove(0, sb.Length);
                            sb.Append("INSERT INTO LOGSALEDETAIL ( LogSaleId,ProductId,Quantity,UnitPrice)");
                            sb.Append(" VALUES( @LogSaleId,@ProductId,@Quantity,@UnitPrice)");

                            sqlSave = sb.ToString();

                            com.Parameters.Clear();
                            com.CommandText = sqlSave;
                            com.Parameters.Add("@LogSaleId", SqlDbType.Int).Value = LogSaleId;
                            com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                            com.Parameters.Add("@Quantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", "")).ToString("#,##0.00");
                            com.Parameters.Add("@UnitPrice", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[7].Text.Replace(",", "")).ToString("#,##0.00");
                            com.ExecuteNonQuery();

                        }
                        tr.Commit();

                        //                      ต้องการ print หรือไม่

                        //if (selectdb == "7CTR")
                        //{
                            DialogResult dlg = MessageBox.Show("ต้องการพิมพ์  Slipt การขาย หรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                            if (dlg == DialogResult.OK)
                            {

                                Sale.rptSlip rptSale = new KTCERP.Sale.rptSlip();

                                rptSale.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                                rptSale.setSaleId = intSaleId;
                                rptSale.ShowDialog();
                            }
                        //}
                        //if (selectdb == "7SEA_SARA")
                        //{
                        //    DialogResult dlg = MessageBox.Show("ต้องการพิมพ์ Slipt หรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        //    if (dlg == DialogResult.OK)
                        //    {

                        //        Sale.rptSlip rptSale = new KTCERP.Sale.rptSlip();

                        //        rptSale.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                        //        rptSale.setSaleId = intSaleId;
                        //        rptSale.ShowDialog();
                        //    }
                        //}
                        //if (selectdb == "trangtest")
                        //{
                        //    DialogResult dlg = MessageBox.Show("ต้องการพิมพ์ Slipt หรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        //    if (dlg == DialogResult.OK)
                        //    {

                        //        Sale.rptSlip rptSale = new KTCERP.Sale.rptSlip();

                        //        rptSale.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                        //        rptSale.setSaleId = intSaleId;
                        //        rptSale.ShowDialog();
                        //    }

                        ClearProductList();
                        ClearProductDetails();

                        ClearCommit();

                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show("ไม่สามารถบันทึกรายการสั่งซื้อได้ เนื่องจาก " + ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        //cmdSave.Focus();
                        tr.Rollback();

                    }
                }

                ClearProductList();
                clsCash.sStatusCash = "0";

                if (selectdb == "7CTR")
                {
                    CustomerId = 472;
                    cusname = "ลูกค้าทั่วไป";
                }
                if (selectdb == "7SEA_SARA")
                {
                    CustomerId = 1;
                    cusname = "ลูกค้าทั่วไป";
                }
                if (selectdb == "trangtest")
                {
                    CustomerId = 472;
                    cusname = "ลูกค้าทั่วไป";
                }

                txtCustomer.Text = cusname;
                this.Text = "หน้าจอขาย  : [" + CustomerId + "] " + cusname + " ยังไม่บันทึกในฐานข้อมูล ";
            }
        }
Пример #4
0
 private void btnPrintBill_Click(object sender, EventArgs e)
 {
     Sale.rptSlip rptShowSaleSelect = new KTCERP.Sale.rptSlip();
     rptShowSaleSelect.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
     rptShowSaleSelect.setSaleId = Convert.ToInt16(SaleId);
     rptShowSaleSelect.ShowDialog();
 }