Ejemplo n.º 1
0
 private void btnInvOriginal_Click(object sender, EventArgs e)
 {
     SalePos7CSK.rptInvOriginal frm = new rptInvOriginal();
     frm.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
     frm.setSaleId = Convert.ToInt32(SaleId);
     frm.ShowDialog();
 }
Ejemplo n.º 2
0
        private void cmdExchange_Click(object sender, EventArgs e)
        {
            if (txtRate.Text.Trim() == "0.00")
            {
                MessageBox.Show("กรุณาใส่ค่า Rate ด้วยค่ะ และคำนวณเงินด้วยค่ะ!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtRate.Focus();
                return;
            }
            if (cboRate.Text.Trim() == "ไม่ระบุ")
            {
                MessageBox.Show("กรุณาใส่ สกุลเงิน ด้วยค่ะ และคำนวณเงินด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cboRate.Focus();
                return;
            }
            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;

            if (clsCash.sStatusCash == "1" || clsCash.sStatusCash == "2" || clsCash.sStatusCash == "3" || clsCash.sStatusCash == "4" || clsCash.sStatusCash == "5")
            {
                if (txtRate.Text.Trim() == "0.00")
                {
                    MessageBox.Show("กรุณาใส่ค่า Rate ด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtRate.Focus();
                    return;
                }
                if (cboRate.Text.Trim() == "ไม่ระบุ")
                {
                    MessageBox.Show("กรุณาใส่ สกุลเงิน ด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cboRate.Focus();
                    return;
                }

                if (lblSaleId.Text.Trim() == "")
                {
                    MessageBox.Show("กรุณาใส่หมายเลขใบสั่งซื้อด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lblSaleId.Focus();
                    return;
                }

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

                    try
                    {
                        sb.Remove(0, sb.Length);
                        sb.Append("UPDATE SALE_HEAD ");
                        sb.Append("SET SaleHeadPayTypeId=@SaleHeadPayType,SaleVat=@NetVAT,SaleShipping=@Shipping, ");
                        sb.Append("SaleVarious=@Various,Discount=@Discount,Cash=@Cash,CustomerId=@CustomerId,");
                        sb.Append("SaleHeadDate=@SaleHeadDate,SaleHeadDateTime=@SaleHeadDateTime, ");
                        sb.Append("SaleHeadDrawId=@SaleHeadDrawId,DrawId=@DrawId,SaleHeadStatusId=@SaleHeadStatus,");
                        sb.Append("SaleCurrencyId=@SaleCurrencyId,Rate=@Rate,NoInv=@NoInv,LoadingId=@Loading,FeederId=@Feeder,FinalDestenationId=@Destinatic, ");
                        sb.Append("BrokerName=@BrokerName,BrokerAddress=@BrokerAddress ");
                        sb.Append("WHERE SaleHeadId=@SaleHeadId");

                        sb.Append(" DELETE FROM  SALE_DETAIL  ");
                        sb.Append("WHERE SaleHeadId=@SaleHeadId");

                        sb.Append(" DELETE FROM  SALE_WEIGHT  ");
                        sb.Append("WHERE SaleHeadId = @SaleHeadId");
                        sqlSave = sb.ToString();

                        com.Parameters.Clear();
                        com.Transaction = tr;
                        com.CommandText = sqlSave;
                        com.Parameters.Add("@saleHeadId", SqlDbType.NVarChar).Value = lblSaleId.Text.Trim();
                        com.Parameters.Add("@SaleHeadPayType", SqlDbType.NVarChar).Value = clsCash.sStatusCash;
                        com.Parameters.Add("@Shipping", SqlDbType.Float).Value = Convert.ToSingle(lblShipping.Text.Trim());
                        com.Parameters.Add("@Various", SqlDbType.Float).Value = Convert.ToSingle(lblVarious.Text.Trim());
                        com.Parameters.Add("@NetVAT", SqlDbType.Float).Value = Convert.ToSingle(lblNetVAT.Text.Trim());
                        com.Parameters.Add("@Discount", SqlDbType.Float).Value = Convert.ToSingle(Discount);
                        com.Parameters.Add("@Cash", SqlDbType.Float).Value = Convert.ToSingle(CashTotal);
                        com.Parameters.Add("@SaleHeadDate", SqlDbType.DateTime).Value = DateTime.Now.ToString("dd/MM/yyyy");
                        com.Parameters.Add("@SaleHeadDateTime", SqlDbType.DateTime).Value = dptSaleDate.Value.ToString("dd/MM/yyyy HH:mm:ss");
                        com.Parameters.Add("@SaleHeadDrawId", SqlDbType.NVarChar).Value = txtDrawId.Text.Trim();
                        com.Parameters.Add("@DrawId", SqlDbType.NVarChar).Value = cboDrawId.SelectedValue.ToString();
                        com.Parameters.Add("@SaleHeadStatus", SqlDbType.Int).Value = 1;
                        com.Parameters.Add("@CustomerId", SqlDbType.Int).Value = CustomerId;
                        com.Parameters.Add("@Rate", SqlDbType.Float).Value = Convert.ToSingle(txtRate.Text.Trim());
                        com.Parameters.Add("@SaleCurrencyId", SqlDbType.Int).Value = cboRate.SelectedValue.ToString();
                        com.Parameters.Add("@NoInv", SqlDbType.NVarChar).Value = txtNoInv.Text.Trim();
                        com.Parameters.Add("@Loading", SqlDbType.NVarChar).Value = cboloading.SelectedValue.ToString();
                        com.Parameters.Add("@Feeder", SqlDbType.NVarChar).Value = cboFeeder.SelectedValue.ToString();
                        com.Parameters.Add("@Destinatic", SqlDbType.NVarChar).Value = cboDestinatic.SelectedValue.ToString();
                        com.Parameters.Add("@BrokerName", SqlDbType.NVarChar).Value = txtBroker.Text.Trim();
                        com.Parameters.Add("@BrokerAddress", SqlDbType.NVarChar).Value = txtBrokerAddress.Text.Trim();

                        com.ExecuteNonQuery();
                        // MessageBox.Show(sqlSave+"**salehead**");

                        //
                        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,SaleDetailQuantityPack,SaleDetailPriceUnitInter )");
                            sb.Append(" VALUES( @SaleHeadId,@ProductId,@SaleDetailQuantity,@SaleDetailPriceUnit,@SaleDetailTotal,@AmountProduct,@SaleDetailQuantityPack,@SaleDetailPriceUnitInter )");

                            sqlSave = sb.ToString();
                            com.Parameters.Clear();
                            com.CommandText = sqlSave;
                            com.Parameters.Add("@SaleHeadId", SqlDbType.Int).Value = lblSaleId.Text.Trim();
                            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[9].Text.Replace(",", "")).ToString("#,##0.0000");
                            com.Parameters.Add("@SaleDetailTotal", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[11].Text.Replace(",", "")).ToString("#,##0.00");
                            com.Parameters.Add("@AmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[2].Text.Replace(",", ""));
                            com.Parameters.Add("@SaleDetailPriceUnitInter", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", ""));
                            if (lsvProductList.Items[i].SubItems[12].Text.Replace(",", "") != "")
                            {
                                com.Parameters.Add("@SaleDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[12].Text.Replace(",", "")).ToString("#,##0.00");
                            }
                            else
                            {
                                com.Parameters.Add("@SaleDetailQuantityPack", SqlDbType.Float).Value = 0;
                            }
                            com.ExecuteNonQuery();
                            //MessageBox.Show(sqlSave+"**saledetail**");

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

                            string packtext = lsvProductList.Items[i].SubItems[7].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 SALE_WEIGHT (SaleWeight,ProductId,SaleHeadId,SalePack)");
                            //        sb.Append(" VALUES(@saleWeight,@ProductId,@saleHeadId,@SalePack)");
                            //        sqlSave = sb.ToString();
                            //        com.Parameters.Clear();
                            //        com.CommandText = sqlSave;
                            //        com.Parameters.Add("@saleHeadId", SqlDbType.NVarChar).Value = lblSaleId.Text.Trim();
                            //        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());
                            //        com.Parameters.Add("@SalePack", SqlDbType.Float).Value = Convert.ToSingle(packtextarr[j].ToString());

                            //        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 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.NVarChar).Value = lblSaleId.Text.Trim();
                            //        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());

                            //        com.ExecuteNonQuery();

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

                            //}

                            string balesNumber = lsvProductList.Items[i].SubItems[13].Text.ToString();
                            string[] balesNumberarr = balesNumber.Split('#');
                            int lenbalesNumber = balesNumberarr.Length;

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

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

                                    sb.Append("INSERT INTO SALE_WEIGHT (SaleWeight,ProductId,SaleHeadId,SalePack,BalesNumber)");
                                    sb.Append(" VALUES(@saleWeight,@ProductId,@saleHeadId,@SalePack,@BalesNumber)");
                                    sqlSave = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave;
                                    com.Parameters.Add("@saleHeadId", SqlDbType.NVarChar).Value = lblSaleId.Text.Trim();
                                    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.Parameters.Add("@SalePack", SqlDbType.Float).Value = Convert.ToSingle(packtextarr[j].ToString());
                                    com.Parameters.Add("@BalesNumber", SqlDbType.Int).Value = Convert.ToInt16(balesNumberarr[j].ToString());
                                    com.ExecuteNonQuery();

                                }
                            }
                            else if (weightext != "" && packtext == "" && balesNumber != "")
                            {

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

                                    sb.Append("INSERT INTO SALE_WEIGHT (SaleWeight,ProductId,SaleHeadId,BalesNumber)");
                                    sb.Append(" VALUES(@saleWeight,@ProductId,@saleHeadId,@BalesNumber)");
                                    sqlSave = sb.ToString();
                                    com.Parameters.Clear();
                                    com.CommandText = sqlSave;
                                    com.Parameters.Add("@saleHeadId", SqlDbType.NVarChar).Value = lblSaleId.Text.Trim();
                                    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.Parameters.Add("@BalesNumber", SqlDbType.Int).Value = Convert.ToInt16(balesNumberarr[j].ToString());

                                    com.ExecuteNonQuery();

                                }

                            }
                            else if (weightext != "" && packtext == "" && balesNumber == "")
                            {

                                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.NVarChar).Value = lblSaleId.Text.Trim();
                                    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();

                                }

                            }

                            //บันทึกลูกหนี้
                            if (clsCash.sStatusCash == "2")
                            {
                                sb.Remove(0, sb.Length);
                                sb.Append("DELETE FROM  RECEIVABLE  ");
                                sb.Append("WHERE SaleHeadId = @SaleHeadId");
                                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 = lblSaleId.Text.Trim();
                                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[8].Text.Replace(",", "")).ToString("#,##0.00");
                                com.ExecuteNonQuery();
                                //MessageBox.Show(sqlSave);

                            }

                        }

                        tr.Commit();

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

                        ///*

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

                            SalePos7CSK.rptInvOriginal rptSale = new rptInvOriginal();
                            rptSale.StartPosition = FormStartPosition.CenterScreen;   // กำหนด frm ย่อย ให้อยู่ตรงกลาง
                            rptSale.setSaleId = Convert.ToInt16(lblSaleId.Text.Trim());
                            rptSale.ShowDialog();
                        }
                        else
                        {

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

                            Close();

                        }

                    }
                    catch (Exception ex)
                    {

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

                        tr.Rollback();

                    }
                }
                Close();

            }
        }