Пример #1
0
        /// <summary>
        /// 4.销售
        /// </summary>
        private void ManagerXS()
        {
            bool bolState = false;

            try
            {
                KPS.Model.XiaoShouInfo _Modelinfo = (KPS.Model.XiaoShouInfo)_control.GetSaveData();
                _Modelinfo.DataType = thisdeviceinfo.DeviceID;

                KPS.BLL.XiaoShouManager xiaoshoumanager = new XiaoShouManager();
                if (ModelData != null)
                {
                    _Modelinfo.ID = ((XiaoShouInfo)ModelData).ID;
                    bolState      = xiaoshoumanager.Update(_Modelinfo);

                    ShowMsgStateInfo(bolState, ModelData);
                }
                else
                {
                    KPS.BLL.InventoryManager InventoryMg = new InventoryManager();
                    InventoryUpState         _stateinfo  = InventoryMg.Sell(_Modelinfo);
                    switch (_stateinfo)
                    {
                    case InventoryUpState.Succed:
                        bolState = xiaoshoumanager.Add(_Modelinfo);
                        ShowMsgStateInfo(bolState, ModelData);
                        break;

                    case InventoryUpState.ProductLacking:
                        MessageBox.Show("库存不足,无法新增销售记录!(可通过新增购进记录来增加库存)");
                        break;

                    case InventoryUpState.ProductNoExt:
                        MessageBox.Show("未找到符合条件的产品购进记录!(请核对 产品名称+生产厂家+注册证号+批号 是否正确)");
                        break;

                    case InventoryUpState.SysTemError:
                        MessageBox.Show("处理失败!");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsgStateInfo(bolState, ModelData);
                bolState = false;
            }
        }
        /// <summary>
        /// 销售(当添加产品的销售记录时,则通过此方法更新已有产品的销售记录)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public InventoryUpState Sell(KPS.Model.XiaoShouInfo model)
        {
            InventoryUpState _state       = InventoryUpState.SysTemError;
            bool             _RecordIsExt = false;
            int _ToltalRecordCount        = 0;
            int _RecordID = -1;

            int _GouJinRecordID = -1;

            #region 更新销售记录的GJID(购进记录编号)
            string           StrSQLA     = "select ID FROM PSI_GouJin where p_cpmc=@p_cpmc and p_zczh=@p_zczh and p_zzs=@p_zzs and p_ph=@p_ph";
            OleDbParameter[] parametersA =
            {
                new OleDbParameter("@p_cpmc", OleDbType.VarChar, 255),
                new OleDbParameter("@p_zczh", OleDbType.VarChar, 255),
                new OleDbParameter("@p_zzs",  OleDbType.VarChar, 255),
                new OleDbParameter("@p_ph",   OleDbType.VarChar, 255)
            };
            parametersA[0].Value = model.p_cpmc;
            parametersA[1].Value = model.p_zczh;
            parametersA[2].Value = model.p_zzs;
            parametersA[3].Value = model.p_ph;
            DataSet _ds = DbHelperOleDb.Query(StrSQLA.ToString(), parametersA);
            if (_ds != null && _ds.Tables[0].Rows.Count > 0)
            {
                try
                {
                    _GouJinRecordID = Convert.ToInt32(_ds.Tables[0].Rows[0]["ID"]);
                    model.GJID      = _GouJinRecordID;
                }
                catch (Exception ex)
                {}
            }

            #endregion
            if (_GouJinRecordID > -1)
            {
                #region 判断产品记录是否已存在
                StringBuilder strQuerySQL = new StringBuilder();
                strQuerySQL.Append("select ID,p_date,p_cpmc,p_ggxh,p_clmc,p_ph,p_dw,p_sl1,p_mjph,p_zzs,p_zczh,p_gys,p_sl2,p_jsr,DataType,RemarkInfo ");
                strQuerySQL.Append(" FROM PSI_Inventory where p_cpmc=@p_cpmc and p_zczh=@p_zczh and p_zzs=@p_zzs and p_ph=@p_ph");
                OleDbParameter[] parameters =
                {
                    new OleDbParameter("@p_cpmc", OleDbType.VarChar, 255),
                    new OleDbParameter("@p_zczh", OleDbType.VarChar, 255),
                    new OleDbParameter("@p_zzs",  OleDbType.VarChar, 255),
                    new OleDbParameter("@p_ph",   OleDbType.VarChar, 255)
                };
                parameters[0].Value = model.p_cpmc;
                parameters[1].Value = model.p_zczh;
                parameters[2].Value = model.p_zzs;
                parameters[3].Value = model.p_ph;

                _ds = DbHelperOleDb.Query(strQuerySQL.ToString(), parameters);
                if (_ds != null && _ds.Tables[0].Rows.Count > 0)
                {
                    try
                    {
                        _ToltalRecordCount = Convert.ToInt32(_ds.Tables[0].Rows[0]["p_sl1"]);
                        _RecordID          = Convert.ToInt32(_ds.Tables[0].Rows[0]["ID"]);
                        _RecordIsExt       = true;
                    }
                    catch (Exception ex)
                    {
                        _state = InventoryUpState.SysTemError;
                    }
                }
                else
                {
                    _RecordIsExt = false;
                }
                #endregion
            }
            if (_RecordIsExt)
            {
                #region 存在产品的购进记录时
                if (model.p_sl1.Value > _ToltalRecordCount)
                {
                    _state = InventoryUpState.ProductLacking;
                }
                else
                {
                    int SurplusNumber = _ToltalRecordCount - model.p_sl1.Value;//统计总数量
                    #region 更新产品库存数量
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("update PSI_Inventory set ");
                    strSql.Append("p_sl1=@p_sl1,");
                    strSql.Append("p_date=@p_date");
                    strSql.Append(" where ID=@ID");
                    OleDbParameter[] upparameters =
                    {
                        new OleDbParameter("@p_sl1",  OleDbType.Integer, 4),
                        new OleDbParameter("@p_date", OleDbType.Date),
                        new OleDbParameter("@ID",     OleDbType.Integer, 4)
                    };
                    upparameters[0].Value = SurplusNumber;
                    upparameters[1].Value = DateTime.Now;
                    upparameters[2].Value = _RecordID;

                    int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), upparameters);
                    if (rows > 0)
                    {
                        _state = InventoryUpState.Succed;
                    }
                    else
                    {
                        _state = InventoryUpState.ProductNoExt;
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                _state = InventoryUpState.ProductNoExt;
            }

            return(_state);
        }