private void cmdExchange_Click(object sender, EventArgs e)
        {
            receive.frmCalculate frmCal = new KTCERP.receive.frmCalculate(lblCash.Text);
            frmCal.StartPosition = FormStartPosition.CenterParent;
            frmCal.ShowDialog();
            double CashTotal = clsCash.sCashMoney;
            double Discount = clsCash.sDiscount;
            double DiscountPersent = clsCash.sDiscountPercent;

            lblNetDC.Text = Discount.ToString("#,##0.00");

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

                try
                {

                    string sqlSave2;
                    string ProductId;

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

                        sb.Remove(0, sb.Length);
                        sb.Append(" UPDATE OUTSIDE_STOCK_DETAIL ");
                        sb.Append("SET OutsideStockDetail_DiscountBth=@OutsideStockDetail_DiscountBth,OutsideStockDetail_DiscountPercent=@OutsideStockDetail_DiscountPercent,OutsideStockDetail_PriceUnit=@OutsideStockDetail_PriceUnit,OutsideStockDetail_PoSupplier=@OutsideStockDetail_PoSupplier,OutsideStockDetail_PackingSupplier=@OutsideStockDetail_PackingSupplier,PoNumber=@PoNumber ");
                        sb.Append("WHERE OutsideStockDetailId=@OutsideStockDetailId");
                        sqlSave2 = sb.ToString();

                        com.Parameters.Clear();
                        com.CommandText = sqlSave2;
                        com.Parameters.Add("@OutsideStockDetailId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[16].Text.Replace(",", "");
                        com.Parameters.Add("@OutsideStockDetail_DiscountBth", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", "")).ToString("#,##0.00");
                        com.Parameters.Add("@OutsideStockDetail_DiscountPercent", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[13].Text.Replace(",", ""));
                        com.Parameters.Add("@OutsideStockDetail_PriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[10].Text.Replace(",", "")).ToString("#,##0.00");
                        com.Parameters.Add("@OutsideStockDetail_PoSupplier", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                        com.Parameters.Add("@OutsideStockDetail_PackingSupplier", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[1].Text.Replace(",", "");
                        com.Parameters.Add("@PoNumber", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");

                        com.ExecuteNonQuery();
                    }

                   // tr.Commit();
                    MessageBox.Show("แก้ไขราคาสำเร็จ");
                    Close();

                }
                catch (Exception ex)
                {

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

                   // tr.Rollback();

                }
            }
        }
Exemplo n.º 2
0
        private void cmdExchange_Click(object sender, EventArgs e)
        {
            receive.frmCalculate frmCal = new KTCERP.receive.frmCalculate(lblCash.Text);
            frmCal.StartPosition = FormStartPosition.CenterParent;
            frmCal.ShowDialog();
            double CashTotal = clsCash.sCashMoney;
            double Discount = clsCash.sDiscount;
            double DiscountPersent = clsCash.sDiscountPercent;

            lblNetDC.Text = Discount.ToString("#,##0.00");

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

                try
                {

                    string sqlSave2;
                    sb.Remove(0, sb.Length);
                    sb.Append(" UPDATE RECEIVE_HEAD ");
                    sb.Append("SET ReceiveDiscount=@ReceiveDiscount ");
                    sb.Append("WHERE ReceiveHeadId=@ReceiveHeadId");

                    sqlSave2 = sb.ToString();

                    com.Parameters.Clear();
                    com.Transaction = tr;
                    com.CommandText = sqlSave2;
                    com.Parameters.Add("@ReceiveHeadId", SqlDbType.NVarChar).Value = lblRecId.Text.Trim();
                    com.Parameters.Add("@ReceiveDiscount", SqlDbType.Float).Value = Discount;

                    com.ExecuteNonQuery();

                    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(" UPDATE RECEIVE_DETAIL ");
                        sb.Append("SET DiscountBth=@DiscountBth,DiscountPercent=@DiscountPercent,ReceiveDetailPriceUnit=@ReceiveDetailPriceUnit ");
                        sb.Append("WHERE ReceiveDetailId=@ReceiveDetailId");
                        sqlSave2 = sb.ToString();

                        com.Parameters.Clear();
                        com.CommandText = sqlSave2;
                        com.Parameters.Add("@ReceiveDetailId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[18].Text.Replace(",", "");
                        com.Parameters.Add("@ReceiveDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", "")).ToString("#,##0.0000");
                        com.Parameters.Add("@DiscountBth", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[14].Text.Replace(",", ""));
                        com.Parameters.Add("@DiscountPercent", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[15].Text.Replace(",", ""));
                        com.ExecuteNonQuery();

                    }

                    tr.Commit();
                    MessageBox.Show("แก้ไขราคาสำเร็จ");
                    Close();

                }
                catch (Exception ex)
                {

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

                }
            }
        }
Exemplo n.º 3
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            receive.frmCalculate frmCal = new KTCERP.receive.frmCalculate(lblNet.Text);
            frmCal.StartPosition = FormStartPosition.CenterParent;
            frmCal.ShowDialog();
            double CashTotal = clsCash.sCashMoney;
            double Discount = clsCash.sDiscount;

            if (cboDrawId.Text == "")
            {
                cboDrawId.Focus();
                return;
            }
            if (MessageBox.Show("คุณต้องการบันทึกรายการสั่งซื้อสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                    tr = Conn.BeginTransaction();

                    try
                    {

                        string sqlSave2;
                        sb.Remove(0, sb.Length);
                        sb.Append(" UPDATE RECEIVE_HEAD ");
                        sb.Append("SET ReceiveHeadDate=@ReceiveHeadDate,ShipperId=@ShipperId,ReceiveHeadDateTime=@ReceiveHeadDateTime,ReceiveTypeId=@ReceiveTypeId,DrawId=@DrawId,LocationProductId=@LocationProductId,ReceiveDiscount=@ReceiveDiscount,EmployerId=@EmployerId,UserName=@UserName ");
                        sb.Append("WHERE ReceiveHeadId=@ReceiveHeadId");

                        sb.Append(" DELETE FROM  RECEIVE_DETAIL  ");
                        sb.Append("WHERE ReceiveHeadId=@ReceiveHeadId");

                        sb.Append(" DELETE FROM  RECEIVE_WEIGHT  ");
                        sb.Append("WHERE ReceiveHeadId = @ReceiveHeadId");

                        sqlSave2 = sb.ToString();

                        com.Parameters.Clear();
                        com.Transaction = tr;
                        com.CommandText = sqlSave2;
                        com.Parameters.Add("@EmployerId", SqlDbType.NVarChar).Value = intEmployerId;
                        com.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userId;
                        com.Parameters.Add("@ReceiveHeadId", SqlDbType.NVarChar).Value = lblRecId.Text.Trim();
                        com.Parameters.Add("@ReceiveHeadDate", SqlDbType.DateTime).Value = dptRecDate.Value.ToString("dd/MM/yyyy");
                        com.Parameters.Add("@ReceiveHeadDateTime", SqlDbType.DateTime).Value = dptRecDate.Value.ToString("dd/MM/yyyy HH:mm:ss");
                        com.Parameters.Add("@ShipperId", SqlDbType.Int).Value = intShipperId;
                        com.Parameters.Add("@ReceiveTypeId", SqlDbType.NVarChar).Value = cboReceiveType.SelectedValue.ToString();
                        com.Parameters.Add("@DrawId", SqlDbType.NVarChar).Value = txtDrawId.Text.Trim();
                        com.Parameters.Add("@LocationProductId", SqlDbType.NVarChar).Value = cboDrawId.SelectedValue.ToString();
                        com.Parameters.Add("@ReceiveDiscount", SqlDbType.Float).Value = Discount;

                        com.ExecuteNonQuery();

                        //**/

                        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 RECEIVE_DETAIL (ReceiveHeadId,SupplierId,ProductId,ReceiveDetailQuantityPack,ReceiveDetailQuantity,ReceiveDetailPriceUnit,ReceiveDetailTotal,AmountProduct,ShippingId,Invoice,DateBillShipping,DateBillSupplier)");
                            sb.Append(" VALUES( @ReceiveHeadId,@SupplierId,@ProductId,@ReceiveDetailQuantityPack,@ReceiveDetailQuantity,@ReceiveDetailPriceUnit,@ReceiveDetailTotal,@AmountProduct,@ShippingId,@Invoice,@DateBillShipping,@DateBillSupplier)");

                            sqlSave2 = sb.ToString();

                            com.Parameters.Clear();
                            com.CommandText = sqlSave2;
                            com.Parameters.Add("@ReceiveHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblRecId.Text.Trim());
                            com.Parameters.Add("@SupplierId", SqlDbType.Int).Value = Convert.ToInt16(lsvProductList.Items[i].SubItems[14].Text.Replace(",", ""));
                            com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[3].Text.Replace(",", "");
                            com.Parameters.Add("@ShippingId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[1].Text.Replace(",", "");
                            com.Parameters.Add("@Invoice", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[2].Text.Replace(",", "");
                            if (lsvProductList.Items[i].SubItems[9].Text.Replace(",", "") != "")
                            {
                                com.Parameters.Add("@ReceiveDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[9].Text.Replace(",", ""));
                            }
                            else
                            {
                                com.Parameters.Add("@ReceiveDetailQuantityPack", SqlDbType.NVarChar).Value = "";
                            }
                            if (lsvProductList.Items[i].SubItems[5].Text.Replace(",", "") != "")
                            {
                                com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[5].Text.Replace(",", ""));
                            }
                            else
                            {
                                com.Parameters.Add("@AmountProduct", SqlDbType.NVarChar).Value = "0"; ;
                            }
                            com.Parameters.Add("@ReceiveDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[7].Text.Replace(",", "")).ToString("#,##0.00");
                            com.Parameters.Add("@ReceiveDetailPriceUnit", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", "")).ToString("#,##0.0000");
                            com.Parameters.Add("@ReceiveDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[13].Text.Replace(",", "")).ToString("#,##0.00");
                            com.Parameters.Add("@DateBillShipping", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[15].Text.Replace(",", "")); //("dd/MM/yyyy");
                            com.Parameters.Add("@DateBillSupplier", SqlDbType.DateTime).Value = Convert.ToDateTime(lsvProductList.Items[i].SubItems[16].Text.Replace(",", "")); //("dd/MM/yyyy");
                            com.ExecuteNonQuery();

                            string weightext = lsvProductList.Items[i].SubItems[10].Text.ToString();
                            string Packtext = lsvProductList.Items[i].SubItems[11].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 RECEIVE_WEIGHT (ReceiveHeadId,ProductId,ReceiveWeight,ReceivePack)");
                                    sb.Append(" VALUES( @ReceiveHeadId,@ProductId,@ReceiveWeight,@ReceivePack)");
                                    sqlSave2 = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave2;
                                    com.Parameters.Add("@ReceiveHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblRecId.Text.Trim());
                                    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[3].Text.Replace(",", "");
                                    com.Parameters.Add("@ReceiveWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString());
                                    com.Parameters.Add("@ReceivePack", SqlDbType.Float).Value = Convert.ToSingle(Packtextarr[j].ToString());
                                    com.ExecuteNonQuery();

                                }

                            }
                            else
                            {
                                for (int j = 0; j < weighttextarr.Length - 1; j++)
                                {
                                    sb.Remove(0, sb.Length);
                                    sb.Append("INSERT INTO RECEIVE_WEIGHT (ReceiveHeadId,ProductId,ReceiveWeight )");
                                    sb.Append(" VALUES( @ReceiveHeadId,@ProductId,@ReceiveWeight)");
                                    sqlSave2 = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave2;
                                    com.Parameters.Add("@ReceiveHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblRecId.Text.Trim());
                                    com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[3].Text.Replace(",", "");
                                    com.Parameters.Add("@ReceiveWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString());
                                    com.ExecuteNonQuery();

                                }
                            }

                        }

                        tr.Commit();

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

                        ///*

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

                        }
                        else
                        {

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

                        }
                        Close();

                    }
                    catch (Exception ex)
                    {

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

                    }
                }
        }