Esempio n. 1
0
        private void btnReportReceive_Click(object sender, EventArgs e)
        {
            if (intSaleReturnId == 0)
            {
                MessageBox.Show("กรุณาเลือกรายการก่อนค่ะ");
            }
            else
            {
                DialogResult dlg = MessageBox.Show("ต้องการพิมพ์รายงานหรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dlg == DialogResult.OK)
                {
                    SaleBackSupplier.rptSaleBack frm = new SaleBackSupplier.rptSaleBack();
                    frm.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้

                    frm.setSaleBackId = intSaleReturnId;
                    frm.ShowDialog();
                }
            }
        }
Esempio n. 2
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("คุณต้องการแก้ไขรายการส่งคืนสินค้าให้ผู้ขาย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    try
                    {
                        if (Class.Function.GetTextId(txtShipper.Text) == "") {
                            MessageBox.Show("กรุณาเลือกขนส่ง"); return;
                        }
                        if (Class.Function.GetTextId(txtSupplier.Text) == "")
                        {
                            MessageBox.Show("กรุณาเลือกผู้ขาย"); return;
                        }
                        List<string> sqladd = new List<string>();
                        String d = " DELETE FROM  SALEBACK_WEIGHT  WHERE SaleBackHeadId = " + lblSaleBackId.Text.Trim();
                        sqladd.Add(d);

                        d = " DELETE FROM  SALEBACK_DETAIL  WHERE SaleBackHeadId=" + lblSaleBackId.Text.Trim();
                        sqladd.Add(d);

                        d = " DELETE FROM  SALEBACK_Head WHERE SaleBackHeadId=" + lblSaleBackId.Text.Trim();
                        sqladd.Add(d);

                        if (Class.DBConnString.clsDB.ExecuteTransactionNonAlert(sqladd.ToArray()))
                        {
                            tr = Conn.BeginTransaction();
                            string sqlSave = sb.ToString();
                            sb.Remove(0, sb.Length);
                            sb.Append("INSERT INTO SALEBACK_HEAD (SaleBackHeadId,SaleBackHeadDate,SupplierId,Remark,SaleBackHeadDateTime, ");
                            sb.Append("ShipperId) ");
                            sb.Append(" VALUES (@SaleBackHeadId,@SaleBackHeadDate,@SupplierId,@Remark,@SaleBackHeadDateTime,");
                            sb.Append("@ShipperId) ");

                            sqlSave = sb.ToString();
                            com.Parameters.Clear();
                            com.Transaction = tr;
                            com.CommandText = sqlSave;
                            com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt32(lblSaleBackId.Text.Trim());
                            com.Parameters.Add("@SupplierId", SqlDbType.Int).Value = Convert.ToInt32(Class.Function.GetTextId(txtSupplier.Text));
                            com.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = rtbRemark.Text.Trim();
                            com.Parameters.Add("@ShipperId", SqlDbType.Int).Value = Convert.ToInt32(Class.Function.GetTextId(txtShipper.Text));
                            com.Parameters.Add("@SaleBackHeadDateTime", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                            com.Parameters.Add("@SaleBackHeadDate", SqlDbType.DateTime).Value = dptSaleBackDate.Value.ToString("dd/MM/yyyy");

                            com.ExecuteNonQuery();

                            //

                            string ProductId;

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

                                sb.Remove(0, sb.Length);
                                sb.Append("INSERT INTO SALEBACK_DETAIL (SaleBackHeadId,ReceiveHeadId,ProductId,SaleBackDetailQuantityPack,SaleBackDetailQuantity,SaleBackDetailPriceUnit,SaleBackDetailTotal,AmountProduct,State,ReceiveDate )");
                                sb.Append(" VALUES( @SaleBackHeadId,@ReceiveHeadId,@ProductId,@SaleBackDetailQuantityPack,@SaleBackDetailQuantity,@SaleBackDetailPriceUnit,@SaleBackDetailTotal,@AmountProduct,@State,@ReceiveDate)");

                                sqlSave = sb.ToString();
                                com.Parameters.Clear();
                                com.CommandText = sqlSave;
                                com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleBackId.Text.Trim());
                                com.Parameters.Add("@ReceiveHeadId", 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("@SaleBackDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[6].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@SaleBackDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@SaleBackDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", "")).ToString("#,##0.00");
                                com.Parameters.Add("@State", SqlDbType.Int).Value = Convert.ToInt16(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));
                                com.Parameters.Add("@ReceiveDate", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[1].Text.Replace(",", ""));

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

                                }

                                else
                                {
                                    com.Parameters.Add("@SaleBackDetailQuantityPack", SqlDbType.NVarChar).Value = "";
                                    com.Parameters.Add("@AmountProduct", SqlDbType.NVarChar).Value = "";

                                }
                                com.ExecuteNonQuery();

                                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 SALEBACK_WEIGHT (SaleBackWeight,SaleBackHeadId,SaleBackPack,ProductId )");
                                        sb.Append("VALUES( @SaleBackWeight,@SaleBackHeadId,@SaleBackPack,@ProductId)");
                                        sqlSave = sb.ToString();
                                        com.Parameters.Clear();
                                        com.CommandText = sqlSave;
                                        com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblSaleBackId.Text.Trim());
                                        com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                        com.Parameters.Add("@SaleBackWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");
                                        com.Parameters.Add("@SaleBackPack", SqlDbType.Float).Value = Convert.ToSingle(Packtextarr[j].ToString());

                                        com.ExecuteNonQuery();

                                    }

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

                                        com.ExecuteNonQuery();
                                    }
                                }
                            }
                            //lblSaleBackId.Text.Trim();
                            tr.Commit();

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

                            ///*

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

                                SaleBackSupplier.rptSaleBack rptSaleBack = new SaleBackSupplier.rptSaleBack();

                                rptSaleBack.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้

                                rptSaleBack.setSaleBackId = Convert.ToInt16(lblSaleBackId.Text);
                                rptSaleBack.ShowDialog();

                            }
                            else
                            {

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

                                Close();

                            }

                            ClearProductList();
                            ClearProductDetails();

                        }
                    }
                    catch (Exception ex)
                    {

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

                    }
                }

                ClearProductList();
        }
Esempio n. 3
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtSaleBackId.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาใส่หมายเลขใบส่งคืนสินค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSaleBackId.Focus();
                return;
            }
            if (Class.Function.GetTextId(txtSupplier.Text) == "") {
                MessageBox.Show("กรุณาเลือกผู้ขาย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (Class.Function.GetTextId(txtShipper.Text) == "")
            {
                MessageBox.Show("กรุณาเลือกขนส่ง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (MessageBox.Show("คุณต้องการบันทึกรายการส่งคืนสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                //GetShipperId(); //หาค่า ShipperId เพื่อใช้บันทึกลงในฐานข้อมูล

                tr = Conn.BeginTransaction();

                try
                {
                    string sqlSave;
                    sb.Remove(0, sb.Length);
                    sb.Append("INSERT INTO SALEBACK_HEAD (SaleBackHeadId,SaleBackHeadDate,SupplierId,Remark,SaleBackHeadDateTime, ");
                    sb.Append("ShipperId) ");
                    sb.Append(" VALUES (@SaleBackHeadId,@SaleBackHeadDate,@SupplierId,@Remark,@SaleBackHeadDateTime,");
                    sb.Append("@ShipperId) ");

                    sqlSave = sb.ToString();
                    com.Parameters.Clear();
                    com.Transaction = tr;
                    com.CommandText = sqlSave;
                    com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt32(txtSaleBackId.Text.Trim());
                    com.Parameters.Add("@SupplierId", SqlDbType.Int).Value = Convert.ToInt32(Class.Function.GetTextId(txtSupplier.Text));
                    com.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = rtbRemark.Text.Trim();
                    com.Parameters.Add("@ShipperId", SqlDbType.Int).Value = Convert.ToInt32(Class.Function.GetTextId(txtShipper.Text));

                    if (dptSaleBackDate.Value.ToString("dd/MM/yyyy") == DateTime.Now.ToString("dd/MM/yyyy"))
                    {
                        com.Parameters.Add("@SaleBackHeadDateTime", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                        com.Parameters.Add("@SaleBackHeadDate", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy");
                    }
                    else
                    {
                        com.Parameters.Add("@SaleBackHeadDateTime", SqlDbType.DateTime).Value = dptSaleBackDate.Value.ToString("dd/MM/yyyy HH:mm:ss");
                        com.Parameters.Add("@SaleBackHeadDate", SqlDbType.DateTime).Value = dptSaleBackDate.Value.ToString("dd/MM/yyyy");
                    }

                    com.ExecuteNonQuery();

                    string ProductId;

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

                        sb.Remove(0, sb.Length);

                        sb.Append("INSERT INTO SALEBACK_DETAIL (SaleBackHeadId,ReceiveHeadId,ProductId,SaleBackDetailQuantityPack,SaleBackDetailQuantity,SaleBackDetailPriceUnit,SaleBackDetailTotal,AmountProduct,State,ReceiveDate )");
                        sb.Append("");//Iyayben
                        sb.Append(" VALUES( @SaleBackHeadId,@ReceiveHeadId,@ProductId,@SaleBackDetailQuantityPack,@SaleBackDetailQuantity,@ReceiveDetailPriceUnit,@ReceiveDetailTotal,@AmountProduct,@State,@ReceiveDate)");
                        sqlSave = sb.ToString();

                        com.Parameters.Clear();
                        com.CommandText = sqlSave;
                        com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt32(txtSaleBackId.Text.Trim());
                        com.Parameters.Add("@ReceiveHeadId", 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("@SaleBackDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", ""));
                        }
                        else
                        {
                            com.Parameters.Add("@SaleBackDetailQuantityPack", SqlDbType.Float).Value = 0.00;
                        }
                        com.Parameters.Add("@SaleBackDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[6].Text.Replace(",", ""));
                        com.Parameters.Add("@ReceiveDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", "")).ToString("#,##0.0000");
                        com.Parameters.Add("@ReceiveDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", ""));
                        com.Parameters.Add("@AmountProduct", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[4].Text.Replace(",", "");
                        com.Parameters.Add("@State", SqlDbType.Int).Value = Convert.ToInt32(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));
                        com.Parameters.Add("@ReceiveDate", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[1].Text.Replace(",", ""));

                        com.ExecuteNonQuery();
                       //MaxDetailId();
                        string weightext = lsvProductList.Items[i].SubItems[9].Text.ToString();
                        string Packtext = lsvProductList.Items[i].SubItems[10].Text.ToString();

                        string[] weighttextarr = weightext.Split('#');
                        int len = weighttextarr.Length;
                        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 SALEBACK_WEIGHT (SaleBackWeight,SaleBackHeadId,SaleBackPack,ProductId )");
                                sb.Append("VALUES( @SaleBackWeight,@SaleBackHeadId,@SaleBackPack,@ProductId)");
                                sqlSave = sb.ToString();
                                com.Parameters.Clear();
                                com.CommandText = sqlSave;
                                com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt32(txtSaleBackId.Text.Trim());
                                com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                com.Parameters.Add("@SaleBackWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");
                                com.Parameters.Add("@SaleBackPack", SqlDbType.Float).Value = Convert.ToSingle(Packtextarr[j].ToString());

                                com.ExecuteNonQuery();

                            }

                        }
                        else if (weightext != "" && Packtext == "")
                        {
                            for (int j = 0; j < weighttextarr.Length - 1; j++)
                            {
                                sb.Remove(0, sb.Length);
                                sb.Append("INSERT INTO SALEBACK_WEIGHT (SaleBackWeight,SaleBackHeadId,ProductId )");
                                sb.Append("VALUES( @SaleBackWeight,@SaleBackHeadId,@ProductId)");
                                sqlSave = sb.ToString();
                                com.Parameters.Clear();
                                com.CommandText = sqlSave;
                                com.Parameters.Add("@SaleBackHeadId", SqlDbType.Int).Value = Convert.ToInt32(txtSaleBackId.Text.Trim());
                                com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                                com.Parameters.Add("@SaleBackWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00");

                                com.ExecuteNonQuery();
                            }
                        }

                    }

                    tr.Commit();

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

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

                        frm.setSaleBackId = Convert.ToInt32(txtSaleBackId.Text); ;
                        frm.ShowDialog();

                    }
                    ClearProductList();
                    ClearProductDetails();
                    txtSaleBackId.Focus();
                    SaleBackId();

                }

                catch (Exception ex)
                {

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

                }

            }
        }