示例#1
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (CustomerId== 0)
            {
                MessageBox.Show("กรุณาเลือกชื่อลูกค้าด้วยค่ะ (o_O) ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSearchCustomer.Focus();
                return;
            }
            if (rtbdescription.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาใส่เหตุผลที่คืนสินค้าด้วย ( ^}{^ )", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                rtbdescription.Focus();
                return;
            }

            Sale.frmCalMoneySaleReturn frmCal = new KTCERP.Sale.frmCalMoneySaleReturn(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;

                if (MessageBox.Show("คุณต้องการแก้ไขรายการส่งคืนสินค้าให้ผู้ขาย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    tr = Conn.BeginTransaction();

                    try
                    {
                        sb.Remove(0, sb.Length);
                        sb.Append(" UPDATE SALERETURN_HEAD ");
                        sb.Append("SET SaleReturnHeadDate=@SaleReturnHeadDate,CustomerId=@CustomerId,description=@description,SaleReturnHeadDateTime=@SaleReturnHeadDateTime ");
                        sb.Append("WHERE SaleReturnHeadId=@SaleReturnHeadId");

                        sb.Append(" DELETE FROM  SALERETURN_DETAIL  ");
                        sb.Append("WHERE SaleReturnHeadId=@SaleReturnHeadId");

                        sb.Append(" DELETE FROM  SALERETURN_WEIGHT  ");
                        sb.Append("WHERE SaleReturnHeadId = @SaleReturnHeadId");

                        string sqlSave = sb.ToString();

                        com.Parameters.Clear();
                        com.Transaction = tr;
                        com.CommandText = sqlSave;
                        com.Parameters.Add("@SaleReturnHeadDate", SqlDbType.DateTime).Value = dptSaleReturnDate.Value.ToString("dd/MM/yyyy");
                        com.Parameters.Add("@CustomerId", SqlDbType.Int).Value = CustomerId;
                        com.Parameters.Add("@description", SqlDbType.NVarChar).Value = rtbdescription.Text;
                        com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                        com.Parameters.Add("@SaleReturnHeadDateTime", SqlDbType.DateTime).Value = dptSaleReturnDate.Value.ToString("dd/MM/yyyy HH:mm:ss");

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

                        //**/

                        string ProductId;

                        //for (int i = 0; i <= lsvProductList.Items.Count - 1; i++)
                        //{
                        //    ProductId = lsvProductList.Items[i].SubItems[3].Text;

                        //    sb.Remove(0, sb.Length);
                        //    sb.Append("INSERT INTO SALERETURN_DETAIL (SaleReturnHeadId,SaleHeadId,ProductId,SaleReturnDetailQuantityPack,SaleReturnDetailQuantity,SaleReturnDetailPriceUnit,SaleReturnDetailTotal,AmountProduct,status,SaleDate )");
                        //    sb.Append(" VALUES( @SaleReturnHeadId,@SaleHeadId,@ProductId,@SaleReturnDetailQuantityPack,@SaleReturnDetailQuantity,@SaleReturnDetailPriceUnit,@SaleReturnDetailTotal,@AmountProduct,@status,@SaleDate)");

                        //    sqlSave = sb.ToString();
                        //    com.Parameters.Clear();
                        //    com.CommandText = sqlSave;
                        //    com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                        //    //if (lsvProductList.Items[i].SubItems[0].Text.Replace(",", "") != "")
                        //    //{
                        //    //    com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                        //    //}
                        //    //else
                        //    //{
                        //    //    com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = "0";

                        //    //}
                        //    com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text ;
                        //    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                        //    com.Parameters.Add("@SaleReturnDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[6].Text.Replace(",", ""));
                        //    com.Parameters.Add("@SaleReturnDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", ""));
                        //    com.Parameters.Add("@SaleReturnDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", ""));
                        //    com.Parameters.Add("@status", SqlDbType.Int).Value = Convert.ToInt16(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));
                        //    if (lsvProductList.Items[i].SubItems[1].Text.Replace(",", "") != "")
                        //    {
                        //        com.Parameters.Add("@SaleDate", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[1].Text.Replace(",", ""));
                        //    }
                        //    else
                        //    {
                        //        com.Parameters.Add("@SaleDate", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[1].Text.Replace(",", "");
                        //    }
                        //    if (lsvProductList.Items[i].SubItems[4].Text.Replace(",", "") != "")
                        //    {
                        //        com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", ""));
                        //    }
                        //    else
                        //    {
                        //        com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = 0.00;
                        //    }
                        //    if (lsvProductList.Items[i].SubItems[8].Text.Replace(",", "") != "")
                        //    {
                        //        com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", ""));
                        //    }
                        //    else
                        //    {
                        //        com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = 0.00;
                        //    }
                        //    com.ExecuteNonQuery();
                        //    //MessageBox.Show(sqlSave);

                        //    string weightext = lsvProductList.Items[i].SubItems[9].Text.Replace(" ", "#");
                        //    string[] weighttextarr = weightext.Split('#');
                        //    int len = weighttextarr.Length;

                        //    string Packtext = lsvProductList.Items[i].SubItems[10].Text.Replace(" ", "#");
                        //    string[] Packtextarr = Packtext.Split('#');
                        //    int lenPack = Packtextarr.Length;

                        //    if (weightext != "" && Packtext != "")
                        //    {

                        //        for (int j = 0; j < weighttextarr.Length - 1; j++)
                        //        {
                        //            sb.Remove(0, sb.Length);
                        //            sb.Append(" INSERT INTO SALERETURN_WEIGHT (SaleReturnHeadId,SaleReturnWeight,ProductId,SalePack,SaleHeadId )");
                        //            sb.Append(" VALUES(@SaleReturnHeadId,@SaleReturnWeight,@ProductId,@SalePack,@SaleHeadId)");
                        //            sqlSave = sb.ToString();
                        //            com.Parameters.Clear();
                        //            com.CommandText = sqlSave;
                        //            com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                        //            com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", ""); ;
                        //            com.Parameters.Add("@SaleReturnWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString());
                        //            com.Parameters.Add("@SalePack", SqlDbType.Float).Value = Convert.ToSingle(Packtextarr[j].ToString());
                        //            com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;

                        //            com.ExecuteNonQuery();

                        //        }
                        //        //MessageBox.Show(sqlSave);

                        //    }
                        //    else if (weightext != "" && Packtext == "")
                        //    {
                        //        for (int j = 0; j < weighttextarr.Length - 1; j++)
                        //        {
                        //            sb.Remove(0, sb.Length);
                        //            sb.Append(" INSERT INTO SALERETURN_WEIGHT (SaleReturnHeadId,SaleReturnWeight,ProductId,SaleHeadId )");
                        //            sb.Append(" VALUES(@SaleReturnHeadId,@SaleReturnWeight,@ProductId,@SaleHeadId)");
                        //            sqlSave = sb.ToString();
                        //            com.Parameters.Clear();
                        //            com.CommandText = sqlSave;
                        //            com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                        //            com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", ""); ;
                        //            com.Parameters.Add("@SaleReturnWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString());
                        //            com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;
                        //            com.ExecuteNonQuery();

                        //        }
                        //        //MessageBox.Show(sqlSave);
                        //    }
                        //}
                        for (int i = 0; i <= lsvProductList.Items.Count - 1; i++)
                        {
                            //ProductId = lsvProductList.Items[i].SubItems[1].Text;

                            sb.Remove(0, sb.Length);
                            if (lsvProductList.Items[i].SubItems[1].Text.Replace(",", "") != "")
                            {
                                sb.Append("INSERT INTO SALERETURN_DETAIL (SaleReturnHeadId,SaleHeadId,ProductId,SaleReturnDetailQuantityPack,SaleReturnDetailQuantity,SaleReturnDetailPriceUnit,SaleReturnDetailTotal,AmountProduct,status,SaleDate)");
                                sb.Append(" VALUES(@SaleReturnHeadId,@SaleHeadId,@ProductId,@SaleReturnDetailQuantityPack,@SaleReturnDetailQuantity,@SaleReturnDetailPriceUnit,@SaleReturnDetailTotal,@AmountProduct,@status,@SaleDate )");
                                sqlSave = sb.ToString();

                                com.Parameters.Clear();
                                com.CommandText = sqlSave;
                                com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                                com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;
                                com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                if (lsvProductList.Items[i].SubItems[8].Text.Replace(",", "") != "")
                                {
                                    com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", ""));
                                }
                                else
                                {
                                    com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = 0.00;
                                }
                                com.Parameters.Add("@SaleReturnDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[6].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@SaleReturnDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", ""));
                                com.Parameters.Add("@SaleReturnDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", ""));
                                com.Parameters.Add("@status", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));

                                com.Parameters.Add("@SaleDate", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[1].Text.Replace(",", ""));

                                if (lsvProductList.Items[i].SubItems[4].Text.Replace(",", "") != "")
                                {
                                    com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", ""));
                                }
                                else
                                {
                                    com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = 0.00;
                                }

                                com.ExecuteNonQuery();
                            }
                            else
                            {
                                sb.Append("INSERT INTO SALERETURN_DETAIL (SaleReturnHeadId,SaleHeadId,ProductId,SaleReturnDetailQuantityPack,SaleReturnDetailQuantity,SaleReturnDetailPriceUnit,SaleReturnDetailTotal,AmountProduct,status)");
                                sb.Append(" VALUES(@SaleReturnHeadId,@SaleHeadId,@ProductId,@SaleReturnDetailQuantityPack,@SaleReturnDetailQuantity,@SaleReturnDetailPriceUnit,@SaleReturnDetailTotal,@AmountProduct,@status )");
                                sqlSave = sb.ToString();

                                com.Parameters.Clear();
                                com.CommandText = sqlSave;
                                com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                                com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;
                                com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                if (lsvProductList.Items[i].SubItems[8].Text.Replace(",", "") != "")
                                {
                                    com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", ""));
                                }
                                else
                                {
                                    com.Parameters.Add("@SaleReturnDetailQuantityPack", SqlDbType.Float).Value = 0.00;
                                }
                                com.Parameters.Add("@SaleReturnDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[6].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@SaleReturnDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", ""));
                                com.Parameters.Add("@SaleReturnDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", ""));
                                com.Parameters.Add("@status", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));

                                if (lsvProductList.Items[i].SubItems[4].Text.Replace(",", "") != "")
                                {
                                    com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", ""));
                                }
                                else
                                {
                                    com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = 0.00;
                                }

                                com.ExecuteNonQuery();
                            }

                            string weightext = lsvProductList.Items[i].SubItems[9].Text.ToString();
                            string[] weighttextarr = weightext.Split('#');
                            int len = weighttextarr.Length;

                            string packtext = lsvProductList.Items[i].SubItems[10].Text.ToString();
                            string[] packtextarr = packtext.Split('#');
                            int lenpack = packtextarr.Length;

                            if (weightext != "" && packtext != "")
                            {

                                for (int j = 0; j < weighttextarr.Length - 1; j++)
                                {
                                    sb.Remove(0, sb.Length);
                                    sb.Append("INSERT INTO SALERETURN_WEIGHT (SaleReturnWeight,ProductId,SaleReturnHeadId,SalePack,SaleHeadId)");
                                    sb.Append(" VALUES( @SaleReturnWeight,@ProductId,@SaleReturnHeadId,@SalePack,@SaleHeadId)");
                                    sqlSave = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave;

                                    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                    com.Parameters.Add("@SaleReturnHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                                    com.Parameters.Add("@SalePack", SqlDbType.Float).Value = Convert.ToSingle(packtextarr[j].ToString());
                                    com.Parameters.Add("@SaleReturnWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");
                                    com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;

                                    com.ExecuteNonQuery();
                                }
                            }
                            else if (weightext != "" && packtext == "")
                            {

                                for (int j = 0; j < weighttextarr.Length - 1; j++)
                                {
                                    sb.Remove(0, sb.Length);
                                    sb.Append("INSERT INTO SALERETURN_WEIGHT (SaleReturnWeight,ProductId,SaleReturnHeadId,SaleHeadId)");
                                    sb.Append(" VALUES( @SaleReturnWeight,@ProductId,@SaleReturnHeadId,@SaleHeadId)");
                                    sqlSave = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave;
                                    com.Parameters.Add("@SaleReturnWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");
                                    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                    com.Parameters.Add("@SaleReturnHeadId", SqlDbType.NVarChar).Value = Convert.ToInt16(lblSaleReturnId.Text.Trim());
                                    com.Parameters.Add("@SaleHeadId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text;

                                    com.ExecuteNonQuery();
                                }

                            }

                        }

                        tr.Commit();

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

                        ///*

                        DialogResult dlg = MessageBox.Show("ต้องการพิมพ์รายงานหรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (dlg == DialogResult.OK)
                        {
                            SaleReturn.rptSaleReturn rptSaleReturn = new SaleReturn.rptSaleReturn();
                            rptSaleReturn.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                            rptSaleReturn.setSaleReturnId = Convert.ToInt16(lblSaleReturnId.Text);
                            rptSaleReturn.ShowDialog();

                        }
                        else
                        {

                            //MessageBox.Show("ปรับปรุงสำเร็จ");

                        }

                    Close();

                    }
                    catch (Exception ex)
                    {

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

                    }
                }

                //ClearProductList();
                //clsCash.sStatusCash = "0";
        }
示例#2
0
 private void btnReportReceive_Click(object sender, EventArgs e)
 {
     if (intSaleReturnId == 0)
     {
         MessageBox.Show("กรุณาเลือกรายการก่อนค่ะ");
     }
     else
     {
         DialogResult dlg = MessageBox.Show("ต้องการพิมพ์รายงานหรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         SaleReturn.rptSaleReturn rptSaleReturn = new SaleReturn.rptSaleReturn();
         rptSaleReturn.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
         rptSaleReturn.setSaleReturnId = intSaleReturnId;
         rptSaleReturn.ShowDialog();
     }
 }