Пример #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BllShipmentTable GetModel(string slipNumber)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 SLIP_NUMBER,ORDER_SLIP_NUMBER,SERIAL_NUMBER,SLIP_DATE,ARRIVAL_DATE,AMOUNT,CURRENCY_CODE,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_TIME,LAST_UPDATE_USER,AMOUNT_INCLUDED_TAX,AMOUNT_WITHOUT_TAX,TAX_RATE,TAX_AMOUNT,COMPANY_CODE ");
            strSql.Append(" from BLL_SHIPMENT ");
            strSql.Append(" where SLIP_NUMBER=@SLIP_NUMBER ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = slipNumber;

            BllShipmentTable shipModel = new BllShipmentTable();
            DataSet          ds        = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                shipModel.SLIP_NUMBER       = ds.Tables[0].Rows[0]["SLIP_NUMBER"].ToString();
                shipModel.ORDER_SLIP_NUMBER = ds.Tables[0].Rows[0]["ORDER_SLIP_NUMBER"].ToString();
                shipModel.SERIAL_NUMBER     = ds.Tables[0].Rows[0]["SERIAL_NUMBER"].ToString();
                if (ds.Tables[0].Rows[0]["SLIP_DATE"].ToString() != "")
                {
                    shipModel.SLIP_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["SLIP_DATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ARRIVAL_DATE"].ToString() != "")
                {
                    shipModel.ARRIVAL_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["ARRIVAL_DATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AMOUNT"].ToString() != "")
                {
                    shipModel.AMOUNT = decimal.Parse(ds.Tables[0].Rows[0]["AMOUNT"].ToString());
                }
                shipModel.CURRENCY_CODE = ds.Tables[0].Rows[0]["CURRENCY_CODE"].ToString();
                if (ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString() != "")
                {
                    shipModel.STATUS_FLAG = int.Parse(ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString());
                }
                shipModel.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString();
                if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "")
                {
                    shipModel.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString() != "")
                {
                    shipModel.LAST_UPDATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString());
                }
                shipModel.LAST_UPDATE_USER = ds.Tables[0].Rows[0]["LAST_UPDATE_USER"].ToString();
                if (ds.Tables[0].Rows[0]["AMOUNT_INCLUDED_TAX"].ToString() != "")
                {
                    shipModel.AMOUNT_INCLUDED_TAX = decimal.Parse(ds.Tables[0].Rows[0]["AMOUNT_INCLUDED_TAX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AMOUNT_WITHOUT_TAX"].ToString() != "")
                {
                    shipModel.AMOUNT_WITHOUT_TAX = decimal.Parse(ds.Tables[0].Rows[0]["AMOUNT_WITHOUT_TAX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TAX_RATE"].ToString() != "")
                {
                    shipModel.TAX_RATE = decimal.Parse(ds.Tables[0].Rows[0]["TAX_RATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TAX_AMOUNT"].ToString() != "")
                {
                    shipModel.TAX_AMOUNT = decimal.Parse(ds.Tables[0].Rows[0]["TAX_AMOUNT"].ToString());
                }
                shipModel.COMPANY_CODE = ds.Tables[0].Rows[0]["COMPANY_CODE"].ToString();

                strSql = new StringBuilder();
                strSql.Append("select  * from BLL_SHIPMENT_LINE ");
                strSql.Append(" where SLIP_NUMBER=@SLIP_NUMBER ");
                SqlParameter[] lineParam =
                {
                    new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 50)
                };
                lineParam[0].Value = slipNumber;
                ds = DbHelperSQL.Query(strSql.ToString(), lineParam);
                BllShipmentLineTable lineModel = null;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    lineModel             = new BllShipmentLineTable();
                    lineModel.SLIP_NUMBER = CConvert.ToString(row["SLIP_NUMBER"]);
                    lineModel.LINE_NUMBER = CConvert.ToInt32(row["LINE_NUMBER"]);
                    lineModel.DEPARTUAL_WAREHOUSE_CODE = CConvert.ToString(row["DEPARTUAL_WAREHOUSE_CODE"]);
                    lineModel.PRODUCT_CODE             = CConvert.ToString(row["PRODUCT_CODE"]);
                    lineModel.QUANTITY    = CConvert.ToDecimal(row["QUANTITY"]);
                    lineModel.UNIT_CODE   = CConvert.ToString(row["UNIT_CODE"]);
                    lineModel.PRICE       = CConvert.ToDecimal(row["PRICE"]);
                    lineModel.AMOUNT      = CConvert.ToDecimal(row["AMOUNT"]);
                    lineModel.MEMO        = CConvert.ToString(row["MEMO"]);
                    lineModel.STATUS_FLAG = CConvert.ToInt32(row["STATUS_FLAG"]);
                    if (!string.IsNullOrEmpty(lineModel.SLIP_NUMBER))
                    {
                        shipModel.AddItems(lineModel);
                    }
                }
                return(shipModel);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// 出库确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool isExsit = false;

            ht = new Hashtable();
            foreach (DataGridViewRow dgvr in dgvData.Rows)
            {
                if (Convert.ToBoolean(dgvr.Cells["SHIPMENT_CHK"].Value))
                {
                    if (!Convert.ToBoolean(dgvr.Cells["SHIPMENT_FLAG"].Value))
                    {
                        MessageBox.Show("出库条件未满足,请检查订单信息(合同编号,预付款)。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    if (CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value) > 0)
                    {
                        string slipNumber = CConvert.ToString(dgvr.Cells["TRUE_SLIP_NUMBER"].Value);

                        //预付金额
                        decimal DepositAmount = (new BDepositArr()).GetArrAmount(slipNumber);
                        try
                        {
                            if (CConvert.ToDecimal(dgvr.Cells["SHIPMENT_DEPOSIT"].Value) / 100 > DepositAmount / CConvert.ToDecimal(dgvr.Cells["AMOUNT_INCLUDED_TAX"].Value))
                            {
                                MessageBox.Show("出库时预付款金额未支付或支付不足。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }
                        catch (Exception ex) { }
                    }

                    if (CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value) + CConvert.ToDecimal(dgvr.Cells["SHIPMENT_QUANTITY"].Value) > CConvert.ToDecimal(dgvr.Cells["ORDER_QUANTITY"].Value))
                    {
                        MessageBox.Show("本次出库数量与已出库数量之和不能大于销售数量。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    string key = CConvert.ToString(dgvr.Cells["WAREHOUSE_CODE"].Value) + "_" + CConvert.ToString(dgvr.Cells["PRODUCT_CODE"].Value);
                    foreach (DictionaryEntry de in ht)
                    {
                        if (key.Equals(de.Key))
                        {
                            ht[key] = CConvert.ToDecimal(de.Value) + CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value);
                            isExsit = true;
                            break;
                        }
                    }
                    if (!isExsit)
                    {
                        ht.Add(key, CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value));
                    }
                }
            }

            foreach (DictionaryEntry de in ht)
            {
                string [] arry      = CConvert.ToString(de.Key).Split('_');
                string    warehouse = arry[0];
                string    product   = arry[1];
                decimal   quantity  = CConvert.ToDecimal(de.Value);
                if (bShipment.GetStock(warehouse, product) < quantity)
                {
                    MessageBox.Show("在库数不足。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }

            if (MessageBox.Show("确定要出库吗?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                List <BllShipmentTable> datas         = new List <BllShipmentTable>();
                BllShipmentTable        shipmentTable = null;
                DateTime currentDate       = DateTime.Now;
                string   currentSlipNumber = "";
                int      i           = 1;
                decimal  totalAmount = 0;
                foreach (DataGridViewRow dgvr in dgvData.Rows)
                {
                    if (Convert.ToBoolean(dgvr.Cells["SHIPMENT_CHK"].Value) && CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value) > 0)
                    {
                        string slipNumber = CConvert.ToString(dgvr.Cells["TRUE_SLIP_NUMBER"].Value);

                        if (currentSlipNumber != slipNumber)
                        {
                            if (currentSlipNumber != "")
                            {
                                shipmentTable.AMOUNT = totalAmount;
                                shipmentTable.AMOUNT_INCLUDED_TAX = totalAmount;

                                shipmentTable.AMOUNT_WITHOUT_TAX = WithoutAmount(totalAmount, shipmentTable.TAX_RATE);
                                shipmentTable.TAX_AMOUNT         = totalAmount - shipmentTable.AMOUNT_WITHOUT_TAX;
                                datas.Add(shipmentTable);
                                totalAmount = 0;
                            }
                            currentSlipNumber = slipNumber;
                            shipmentTable     = new BllShipmentTable();
                            i = 1;
                            shipmentTable.ORDER_SLIP_NUMBER = slipNumber;

                            shipmentTable.SERIAL_NUMBER = CConvert.ToString(dgvr.Cells["SERIAL_NUMBER"].Value);
                            shipmentTable.SLIP_DATE     = currentDate;
                            shipmentTable.ARRIVAL_DATE  = CConvert.ToDateTime(dgvr.Cells["DEPARTUAL_DATE"].Value);
                            shipmentTable.TAX_RATE      = CConvert.ToDecimal(dgvr.Cells["TAX_RATE"].Value);

                            shipmentTable.CURRENCY_CODE      = CConvert.ToString(dgvr.Cells["CURRENCY_CODE"].Value);
                            shipmentTable.STATUS_FLAG        = CConstant.INIT;
                            shipmentTable.CREATE_USER        = UserTable.CODE;
                            shipmentTable.LAST_UPDATE_USER   = UserTable.CODE;
                            shipmentTable.COMPANY_CODE       = UserTable.COMPANY_CODE;
                            shipmentTable.CHECK_NUMBER       = CConvert.ToString(dgvr.Cells["CHECK_NUMBER"].Value);
                            shipmentTable.CUSTOMER_PO_NUMBER = CConvert.ToString(dgvr.Cells["CUSTOMER_PO_NUMBER"].Value);
                        }
                        BllShipmentLineTable shipmentLineTable = new BllShipmentLineTable();
                        shipmentLineTable.LINE_NUMBER              = i++;
                        shipmentLineTable.ORDER_LINE_NUMBER        = CConvert.ToInt32(dgvr.Cells["LINE_NUMBER"].Value);
                        shipmentLineTable.DEPARTUAL_WAREHOUSE_CODE = CConvert.ToString(dgvr.Cells["WAREHOUSE_CODE"].Value);
                        shipmentLineTable.PRODUCT_CODE             = CConvert.ToString(dgvr.Cells["PRODUCT_CODE"].Value);
                        shipmentLineTable.QUANTITY    = CConvert.ToDecimal(dgvr.Cells["QUANTITY"].Value);
                        shipmentLineTable.UNIT_CODE   = CConvert.ToString(dgvr.Cells["UNIT_CODE"].Value);
                        shipmentLineTable.PRICE       = CConvert.ToDecimal(dgvr.Cells["PRICE"].Value);
                        shipmentLineTable.AMOUNT      = shipmentLineTable.QUANTITY * shipmentLineTable.PRICE;
                        shipmentLineTable.MEMO        = CConvert.ToString(dgvr.Cells["LINE_MEMO"].Value);
                        shipmentLineTable.STATUS_FLAG = CConstant.INIT;
                        totalAmount += CConvert.ToDecimal(shipmentLineTable.PRICE * shipmentLineTable.QUANTITY);
                        shipmentTable.AddItems(shipmentLineTable);
                    }
                }

                if (shipmentTable != null)
                {
                    shipmentTable.AMOUNT = totalAmount;
                    shipmentTable.AMOUNT_INCLUDED_TAX = totalAmount;
                    shipmentTable.AMOUNT_WITHOUT_TAX  = WithoutAmount(totalAmount, shipmentTable.TAX_RATE);
                    shipmentTable.TAX_AMOUNT          = totalAmount - shipmentTable.AMOUNT_WITHOUT_TAX;
                    datas.Add(shipmentTable);
                }

                //数据表的更新
                if (datas.Count > 0)
                {
                    try
                    {
                        int ret = bShipment.Add(datas);
                        if (ret > 0)
                        {
                            MessageBox.Show("出库确认成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            BindData(false);
                        }
                        else
                        {
                            MessageBox.Show("出库确认失败,请重试或与管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        MessageBox.Show("出库确认失败,请重试或与管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Logger.Error("出库确认失败。", ex);
                    }
                }
                else
                {
                    MessageBox.Show("请先择需要出库的数据,或出库数量小于等于零。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }