Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddStockProductInfo(StockProductInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbStockProductInfo(");
            strSql.Append("ProductsID,isOK,isBad,sAppendTime,StorageID)");
            strSql.Append(" values (");
            strSql.Append("@ProductsID,@isOK,@isBad,@sAppendTime,@StorageID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ProductsID",  SqlDbType.Int,       4),
                new SqlParameter("@isOK",        SqlDbType.Decimal),
                new SqlParameter("@isBad",       SqlDbType.Decimal),
                new SqlParameter("@sAppendTime", SqlDbType.DateTime),
                new SqlParameter("@StorageID",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ProductsID;
            parameters[1].Value = model.isOK;
            parameters[2].Value = model.isBad;
            parameters[3].Value = model.sAppendTime;
            parameters[4].Value = model.StorageID;

            object obj = DbHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void UpdateStockProductInfo(StockProductInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbStockProductInfo set ");
            strSql.Append("ProductsID=@ProductsID,");
            strSql.Append("isOK=@isOK,");
            strSql.Append("isBad=@isBad,");
            strSql.Append("sAppendTime=@sAppendTime,");
            strSql.Append("StorageID=@StorageID");
            strSql.Append(" where StockProductID=@StockProductID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@StockProductID", SqlDbType.Int,       4),
                new SqlParameter("@ProductsID",     SqlDbType.Int,       4),
                new SqlParameter("@isOK",           SqlDbType.Decimal),
                new SqlParameter("@isBad",          SqlDbType.Decimal),
                new SqlParameter("@sAppendTime",    SqlDbType.DateTime),
                new SqlParameter("@StorageID",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.StockProductID;
            parameters[1].Value = model.ProductsID;
            parameters[2].Value = model.isOK;
            parameters[3].Value = model.isBad;
            parameters[4].Value = model.sAppendTime;
            parameters[5].Value = model.StorageID;

            DbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }
Esempio n. 3
0
        public void DoOrderReceipt(OrderReceiptRecordInfo model)
        {
            DateTime currTime = DateTime.Now;

            OrderReceipt orbBll   = new OrderReceipt();
            var          orbModel = orbBll.GetModel(model.OrderId);

            OrderReceiptProduct orpBll = new OrderReceiptProduct();
            var orpModel = orpBll.GetModel(model.OrderId, model.ProductId);

            orpModel.ReceiptQty += model.Qty;
            orpBll.UpdateQty(model.OrderId, model.ProductId, orpModel.ReceiptQty);

            StockProduct     spBll   = new StockProduct();
            StockProductInfo spModel = null;

            spModel = spBll.GetModel(Guid.Empty, model.ProductId);
            if (spModel == null)
            {
                var stepCode = (int)EnumData.EnumStep.收货;
                var stepName = EnumData.EnumStep.收货.ToString();
                spModel = new StockProductInfo(Guid.Empty, model.ProductId, model.Qty, orpModel.ReceiptQty, 0, stepCode.ToString(), stepName, EnumData.EnumIsDisable.启用.ToString(), "", "", currTime);

                spBll.Insert(spModel);
            }
            else
            {
                spModel.UnQty          += model.Qty;
                spModel.LastUpdatedDate = currTime;
                spBll.Update(spModel);
            }
        }
Esempio n. 4
0
        public IList <StockProductInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append(@"select count(*) from StockProduct ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), cmdParms);

            if (totalRecords == 0)
            {
                return(new List <StockProductInfo>());
            }

            sb.Clear();
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate) as RowNumber,
			          ProductId,CustomerId,Qty,UnQty,FreezeQty,StepCode,LastStepName,Status,StockLocations,WarnMsg,LastUpdatedDate
					  from StockProduct "                    );
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex);

            IList <StockProductInfo> list = new List <StockProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        StockProductInfo model = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(1);
                        model.CustomerId      = reader.GetGuid(2);
                        model.Qty             = reader.GetDouble(3);
                        model.UnQty           = reader.GetDouble(4);
                        model.FreezeQty       = reader.GetDouble(5);
                        model.StepCode        = reader.GetString(6);
                        model.LastStepName    = reader.GetString(7);
                        model.Status          = reader.GetString(8);
                        model.StockLocations  = reader.GetString(9);
                        model.WarnMsg         = reader.GetString(10);
                        model.LastUpdatedDate = reader.GetDateTime(11);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 5
0
        public IList <StockProductInfo> GetListByJoin(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms)
        {
            var sb         = new StringBuilder(500);
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            sb.Append(@"select * from(select row_number() over(order by sp.LastUpdatedDate desc) as RowNumber,
			          sp.ProductId,sp.CustomerId,sp.Qty,sp.UnQty,sp.FreezeQty,sp.StepCode,sp.LastStepName,sp.Status,sp.StockLocations,sp.LastUpdatedDate
                      ,c.Coded CustomerCode,c.Named CustomerName,p.ProductCode,p.ProductName
					  from StockProduct sp 
                      left join Customer c on c.Id = sp.CustomerId 
                      left join Product p on p.Id = sp.ProductId 
                      ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex);

            var list = new List <StockProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    var slpBll = new StockLocationProduct();

                    while (reader.Read())
                    {
                        var model = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(1);
                        model.CustomerId      = reader.GetGuid(2);
                        model.Qty             = reader.GetDouble(3);
                        model.UnQty           = reader.GetDouble(4);
                        model.FreezeQty       = reader.GetDouble(5);
                        model.StepCode        = reader.GetString(6);
                        model.LastStepName    = reader.GetString(7);
                        model.Status          = reader.GetString(8);
                        model.StockLocations  = reader.GetString(9);
                        model.LastUpdatedDate = reader.GetDateTime(10);

                        model.CustomerCode      = reader.IsDBNull(11) ? "" : reader.GetString(11);
                        model.CustomerName      = reader.IsDBNull(12) ? "" : reader.GetString(12);
                        model.ProductCode       = reader.IsDBNull(13) ? "" : reader.GetString(13);
                        model.ProductName       = reader.IsDBNull(14) ? "" : reader.GetString(14);
                        model.StockLocationName = slpBll.GetNameByProductId(model.ProductId);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 6
0
        public IList <StockProductInfo> GetListByJoin(string sqlWhere, params SqlParameter[] cmdParms)
        {
            var list = new List <StockProductInfo>();

            var sb = new StringBuilder(1000);

            sb.Append(@"select sp.ProductId,sp.CustomerId,sp.Qty,sp.UnQty,sp.FreezeQty,sp.StepCode,sp.LastStepName,sp.Status,sp.StockLocations,sp.LastUpdatedDate
                      ,c.Coded CustomerCode,c.Named CustomerName,p.ProductCode,p.ProductName
					  from StockProduct sp 
                      left join Customer c on c.Id = sp.CustomerId 
                      left join Product p on p.Id = sp.ProductId 
                      ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.Append("order by LastUpdatedDate desc ");

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    var slpBll = new StockLocationProduct();

                    while (reader.Read())
                    {
                        var model = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(0);
                        model.CustomerId      = reader.GetGuid(1);
                        model.Qty             = reader.GetDouble(2);
                        model.UnQty           = reader.GetDouble(3);
                        model.FreezeQty       = reader.GetDouble(4);
                        model.StepCode        = reader.GetString(5);
                        model.LastStepName    = reader.GetString(6);
                        model.Status          = reader.GetString(7);
                        model.StockLocations  = reader.GetString(8);
                        model.LastUpdatedDate = reader.GetDateTime(9);

                        model.CustomerCode      = reader.IsDBNull(10) ? "" : reader.GetString(10);
                        model.CustomerName      = reader.IsDBNull(11) ? "" : reader.GetString(11);
                        model.ProductCode       = reader.IsDBNull(12) ? "" : reader.GetString(12);
                        model.ProductName       = reader.IsDBNull(13) ? "" : reader.GetString(13);
                        model.StockLocationName = slpBll.GetNameByProductId(model.ProductId);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 7
0
        public StockProductInfo GetStockProductInfoModelByProductsID(int ProductsID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 StockProductID,ProductsID,isOK,isBad,sAppendTime,StorageID from tbStockProductInfo ");
            strSql.Append(" where ProductsID=@ProductsID order by sAppendTime desc ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ProductsID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ProductsID;

            StockProductInfo model = new StockProductInfo();
            DataSet          ds    = DbHelper.ExecuteDataset(CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["StockProductID"].ToString() != "")
                {
                    model.StockProductID = int.Parse(ds.Tables[0].Rows[0]["StockProductID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StorageID"].ToString() != "")
                {
                    model.StorageID = int.Parse(ds.Tables[0].Rows[0]["StorageID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductsID"].ToString() != "")
                {
                    model.ProductsID = int.Parse(ds.Tables[0].Rows[0]["ProductsID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["isOK"].ToString() != "")
                {
                    model.isOK = decimal.Parse(ds.Tables[0].Rows[0]["isOK"].ToString());
                }
                if (ds.Tables[0].Rows[0]["isBad"].ToString() != "")
                {
                    model.isBad = decimal.Parse(ds.Tables[0].Rows[0]["isBad"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sAppendTime"].ToString() != "")
                {
                    model.sAppendTime = DateTime.Parse(ds.Tables[0].Rows[0]["sAppendTime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 8
0
        public StockProductInfo GetModel(Guid productId, Guid customerId)
        {
            StockProductInfo model = null;

            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select top 1 ProductId,CustomerId,Qty,UnQty,FreezeQty,StepCode,LastStepName,Status,StockLocations,WarnMsg,LastUpdatedDate 
			            from StockProduct
						where ProductId = @ProductId and CustomerId = @CustomerId "                        );
            SqlParameter[] parms =
            {
                new SqlParameter("@ProductId",  SqlDbType.UniqueIdentifier),
                new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = productId;
            parms[1].Value = customerId;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), parms))
            {
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        model                 = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(0);
                        model.CustomerId      = reader.GetGuid(1);
                        model.Qty             = reader.GetDouble(2);
                        model.UnQty           = reader.GetDouble(3);
                        model.FreezeQty       = reader.GetDouble(4);
                        model.StepCode        = reader.GetString(5);
                        model.LastStepName    = reader.GetString(6);
                        model.Status          = reader.GetString(7);
                        model.StockLocations  = reader.GetString(8);
                        model.WarnMsg         = reader.GetString(9);
                        model.LastUpdatedDate = reader.GetDateTime(10);
                    }
                }
            }

            return(model);
        }
Esempio n. 9
0
        public IList <StockProductInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append(@"select ProductId,CustomerId,Qty,UnQty,FreezeQty,StepCode,LastStepName,Status,StockLocations,WarnMsg,LastUpdatedDate
                        from StockProduct ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.AppendFormat(" where 1=1 {0} ", sqlWhere);
            }
            sb.Append("order by LastUpdatedDate ");

            IList <StockProductInfo> list = new List <StockProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        StockProductInfo model = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(0);
                        model.CustomerId      = reader.GetGuid(1);
                        model.Qty             = reader.GetDouble(2);
                        model.UnQty           = reader.GetDouble(3);
                        model.FreezeQty       = reader.GetDouble(4);
                        model.StepCode        = reader.GetString(5);
                        model.LastStepName    = reader.GetString(6);
                        model.Status          = reader.GetString(7);
                        model.StockLocations  = reader.GetString(8);
                        model.WarnMsg         = reader.GetString(9);
                        model.LastUpdatedDate = reader.GetDateTime(10);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 10
0
        public int Insert(StockProductInfo model)
        {
            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"insert into StockProduct (ProductId,CustomerId,Qty,UnQty,FreezeQty,StepCode,LastStepName,Status,StockLocations,WarnMsg,LastUpdatedDate)
			            values
						(@ProductId,@CustomerId,@Qty,@UnQty,@FreezeQty,@StepCode,@LastStepName,@Status,@StockLocations,@WarnMsg,@LastUpdatedDate)
			            "            );

            SqlParameter[] parms =
            {
                new SqlParameter("@ProductId",       SqlDbType.UniqueIdentifier),
                new SqlParameter("@CustomerId",      SqlDbType.UniqueIdentifier),
                new SqlParameter("@Qty",             SqlDbType.Float),
                new SqlParameter("@UnQty",           SqlDbType.Float),
                new SqlParameter("@FreezeQty",       SqlDbType.Float),
                new SqlParameter("@StepCode",        SqlDbType.VarChar,            50),
                new SqlParameter("@LastStepName",    SqlDbType.NVarChar,           20),
                new SqlParameter("@Status",          SqlDbType.NVarChar,           20),
                new SqlParameter("@StockLocations",  SqlDbType.VarChar),
                new SqlParameter("@WarnMsg",         SqlDbType.NVarChar,          256),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value  = model.ProductId;
            parms[1].Value  = model.CustomerId;
            parms[2].Value  = model.Qty;
            parms[3].Value  = model.UnQty;
            parms[4].Value  = model.FreezeQty;
            parms[5].Value  = model.StepCode;
            parms[6].Value  = model.LastStepName;
            parms[7].Value  = model.Status;
            parms[8].Value  = model.StockLocations;
            parms[9].Value  = model.WarnMsg;
            parms[10].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString(), parms));
        }
Esempio n. 11
0
        public IList <StockProductInfo> GetList()
        {
            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select ProductId,CustomerId,Qty,UnQty,FreezeQty,StepCode,LastStepName,Status,StockLocations,WarnMsg,LastUpdatedDate 
			            from StockProduct
					    order by LastUpdatedDate "                    );

            IList <StockProductInfo> list = new List <StockProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.WmsDbConnString, CommandType.Text, sb.ToString()))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        StockProductInfo model = new StockProductInfo();
                        model.ProductId       = reader.GetGuid(0);
                        model.CustomerId      = reader.GetGuid(1);
                        model.Qty             = reader.GetDouble(2);
                        model.UnQty           = reader.GetDouble(3);
                        model.FreezeQty       = reader.GetDouble(4);
                        model.StepCode        = reader.GetString(5);
                        model.LastStepName    = reader.GetString(6);
                        model.Status          = reader.GetString(7);
                        model.StockLocations  = reader.GetString(8);
                        model.WarnMsg         = reader.GetString(9);
                        model.LastUpdatedDate = reader.GetDateTime(10);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 12
0
 public int Update(StockProductInfo model)
 {
     return(dal.Update(model));
 }
Esempio n. 13
0
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            if (this.userid > 0)
            {
                if (CheckUserPopedoms("X") || CheckUserPopedoms("7-2-1-5-5-3"))
                {
                    Act = HTTPRequest.GetString("Act");
                    if (Act == "Edit")
                    {
                        ProductsID = Utils.StrToInt(HTTPRequest.GetString("pid"), 0);

                        dList = DataUtils.GetStock_analysis(0, DateTime.Now, ProductsID);

                        //spi = tbStockProductInfo.GetStockProductInfoModelByProductsID(ProductsID);
                    }
                    if (dList != null)
                    {
                        if (ispost)
                        {
                            try
                            {
                                int     loop      = HTTPRequest.GetInt("loop", 0);
                                int     StorageID = 0;
                                decimal pBad      = 0;
                                if (loop > 0)
                                {
                                    for (int i = 0; i <= loop; i++)
                                    {
                                        StorageID = HTTPRequest.GetInt("StorageID_" + i, 0);
                                        if (StorageID > 0)
                                        {
                                            pBad = (HTTPRequest.GetString("Bad_" + i).Trim() != "") ? decimal.Parse(Utils.ChkSQL(HTTPRequest.GetString("Bad_" + i))) : 0;

                                            spi             = new StockProductInfo();
                                            spi.ProductsID  = ProductsID;
                                            spi.StorageID   = StorageID;
                                            spi.isBad       = pBad;
                                            spi.sAppendTime = DateTime.Now;

                                            tbStockProductInfo.AddStockProductInfo(spi);

                                            ProductsInfo _pi = new ProductsInfo();
                                            StorageInfo  _si = new StorageInfo();

                                            _pi = tbProductsInfo.GetProductsInfoModel(ProductsID);
                                            _si = tbStorageInfo.GetStorageInfoModel(StorageID);

                                            if (_pi != null && _si != null)
                                            {
                                                Logs.AddEventLog(this.userid, "修改实时库存." + _si.sName + "," + _pi.pName + ".Bad:" + pBad);
                                            }
                                            _pi = null;
                                            _si = null;
                                        }
                                    }
                                    AddMsgLine("更新成功!");
                                    AddScript("window.setTimeout('window.parent.HidBox();',1000);");
                                }
                            }
                            catch
                            {
                                AddErrLine("系统忙,请稍候!");
                                AddScript("window.setTimeout('window.parent.HidBox();',2000);");
                            }
                        }
                        else
                        {
                            StorageList = tbStorageInfo.GetStorageInfoList("").Tables[0];
                            if (StorageList != null)
                            {
                                StorageList.Columns.Add("Bad", Type.GetType("System.Decimal"));
                                DataTable dt = new DataTable();
                                dt = tbStockProductInfo.GetStockProductInfoListByNow(" sp.ProductsID=" + ProductsID).Tables[0];
                                if (dt != null)
                                {
                                    foreach (DataRow dr in dt.Rows)
                                    {
                                        foreach (DataRow drr in StorageList.Rows)
                                        {
                                            if (dr["StorageID"].ToString() == drr["StorageID"].ToString())
                                            {
                                                drr["Bad"] = dr["isBad"];
                                            }
                                        }
                                    }
                                }
                                StorageList.AcceptChanges();
                            }
                        }
                    }
                    else
                    {
                        AddErrLine("参数错误,请重试!");
                        AddScript("window.setTimeout('window.parent.HidBox();',2000);");
                    }
                }
                else
                {
                    AddErrLine("权限不足!");
                    AddScript("window.setTimeout('window.parent.HidBox();',2000);");
                }
            }
            else
            {
                AddErrLine("请先登录!");
                SetBackLink("login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer()));
                SetMetaRefresh(1, "login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer()));
            }
        }
Esempio n. 14
0
        public void DoProduct(Guid productId, Guid customerId, Guid slId, bool isIncrease, double qty, double unQty, double freezeQty, int stepCode, string status)
        {
            var spInfo        = dal.GetModel(productId, customerId);
            var sStepCode     = Common.GetStepCode(spInfo == null ? null : spInfo.StepCode, stepCode.ToString(), false);
            var sLastStepName = Enum.GetName(typeof(EnumData.EnumStep), stepCode);
            var currQty       = 0d;
            var currFreezeQty = 0d;

            if (!isIncrease)
            {
                #region 对库存货物“减”处理

                if (spInfo != null)
                {
                    if (unQty > 0)
                    {
                        currQty      += unQty;
                        spInfo.UnQty -= unQty;
                        if (spInfo.UnQty < 0)
                        {
                            throw new ArgumentException(MC.M_QtyInvalidError);
                        }
                    }
                    var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(spInfo.StockLocations);
                    var pslaInfo = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId));
                    if (pslaInfo != null)
                    {
                        pslaInfo.Qty       -= currQty;
                        pslaInfo.FreezeQty -= currFreezeQty;
                    }
                    spInfo.StockLocations = JsonConvert.SerializeObject(pslaList);

                    if (spInfo.StepCode == ((int)EnumData.EnumStep.收货).ToString() && spInfo.Qty == 0 && spInfo.UnQty == 0 && spInfo.FreezeQty == 0)
                    {
                        dal.Delete(productId, customerId);
                    }
                    else
                    {
                        dal.Update(spInfo);
                    }
                }

                #endregion
            }
            else
            {
                #region 对库存货物“增”处理

                if (spInfo != null)
                {
                    #region 已存在相应数据,则执行修改操作

                    if (unQty > 0)
                    {
                        spInfo.UnQty += unQty;
                        currQty      += unQty;
                    }
                    var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(spInfo.StockLocations);
                    var pslaInfo = pslaList.FirstOrDefault(m => m.StockLocationId.Equals(slId));
                    if (pslaInfo != null)
                    {
                        pslaInfo.Qty += unQty;
                    }
                    else
                    {
                        var slBll  = new StockLocation();
                        var slInfo = slBll.GetModel(slId);
                        if (slInfo == null)
                        {
                            throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, slId.ToString()));
                        }
                        pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, currQty, currFreezeQty, DateTime.Now));
                    }
                    spInfo.StockLocations = JsonConvert.SerializeObject(pslaList);

                    dal.Update(spInfo);

                    #endregion
                }
                else
                {
                    #region 否则执行新增操作

                    if (unQty > 0)
                    {
                        currQty += unQty;
                    }
                    var slBll  = new StockLocation();
                    var slInfo = slBll.GetModel(slId);
                    if (slInfo == null)
                    {
                        throw new ArgumentException(MC.GetString(MC.Params_Data_NotExist, slId.ToString()));
                    }

                    var pslaList = new List <ProductStockLocationAttrInfo>();
                    pslaList.Add(new ProductStockLocationAttrInfo(slId, slInfo.Code, slInfo.Named, currQty, currFreezeQty, DateTime.Now));

                    spInfo = new StockProductInfo(productId, customerId, qty, unQty, freezeQty, sStepCode, sLastStepName, status, JsonConvert.SerializeObject(pslaList), "", DateTime.Now);
                    dal.Insert(spInfo);

                    #endregion
                }

                #endregion
            }
        }
Esempio n. 15
0
        public IEnumerable <StockProductInfo> GetSelectProductListByStepName(int pageIndex, int pageSize, string stepName, object productId, object customerId, double qty)
        {
            var sqlWhere = new StringBuilder(100);

            if (EnumData.EnumStep.发货.ToString() == stepName)
            {
                sqlWhere.Append("and sp.Qty > 0 ");
            }
            else if (EnumData.EnumStep.拣货.ToString() == stepName)
            {
                sqlWhere.AppendFormat("and sp.FreezeQty > 0 and ProductId = '{0}' and CustomerId = '{1}' ", productId, customerId);
            }

            var spList = new List <StockProductInfo>();
            var list   = dal.GetListByJoin(pageIndex, pageSize, sqlWhere.ToString(), null);

            if (list != null && list.Count > 0)
            {
                var slBll  = new StockLocation();
                var slTemp = slBll.GetModelForTemp();
                var slList = slBll.GetList();
                foreach (var item in list)
                {
                    var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations);
                    if (EnumData.EnumStep.发货.ToString() == stepName || EnumData.EnumStep.拣货.ToString() == stepName)
                    {
                        pslaList.RemoveAll(m => m.StockLocationId.Equals(slTemp.Id));
                    }
                    foreach (var pslaItem in pslaList)
                    {
                        if (EnumData.EnumStep.发货.ToString() == stepName)
                        {
                            if (pslaItem.Qty <= 0)
                            {
                                continue;
                            }
                        }
                        else if (EnumData.EnumStep.拣货.ToString() == stepName)
                        {
                            if (pslaItem.FreezeQty <= 0)
                            {
                                continue;
                            }
                        }
                        var slInfo = slList.FirstOrDefault(m => m.Id.Equals(pslaItem.StockLocationId));
                        if (slInfo == null)
                        {
                            throw new ArgumentException(string.Format("{0}对应的库位数据不存在或已被删除", pslaItem.StockLocationId));
                        }
                        var spInfo = new StockProductInfo(item.ProductId, item.CustomerId, item.Qty, item.UnQty, item.FreezeQty, item.StepCode, item.LastStepName, item.Status, item.StockLocations, "", item.LastUpdatedDate);
                        spInfo.StockLocations    = "";
                        spInfo.StockLocationId   = slInfo.Id;
                        spInfo.StockLocationCode = slInfo.Code;
                        spInfo.StockLocationName = slInfo.Named;
                        spInfo.LastUpdatedDate   = pslaItem.LastUpdatedDate;
                        spInfo.Qty          = 0;
                        spInfo.ProductCode  = item.ProductCode;
                        spInfo.ProductName  = item.ProductName;
                        spInfo.CustomerCode = item.CustomerCode;
                        spInfo.CustomerName = item.CustomerName;

                        if (EnumData.EnumStep.拣货.ToString() == stepName)
                        {
                            spInfo.MaxQty = pslaItem.FreezeQty;
                        }
                        else
                        {
                            spInfo.MaxQty = pslaItem.Qty;
                        }

                        spList.Add(spInfo);
                    }
                }
                var q        = spList.OrderBy(m => m.LastUpdatedDate);
                var totalQty = 0d;
                foreach (var item in q)
                {
                    if (totalQty >= qty)
                    {
                        break;
                    }
                    item.IsBest = true;
                    totalQty   += item.MaxQty;
                }
            }

            return(spList);
        }
Esempio n. 16
0
 public int Insert(StockProductInfo model)
 {
     return(dal.Insert(model));
 }
Esempio n. 17
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public static void UpdateStockProductInfo(StockProductInfo model)
 {
     DatabaseProvider.GetInstance().UpdateStockProductInfo(model);
 }
Esempio n. 18
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public static int AddStockProductInfo(StockProductInfo model)
 {
     return(DatabaseProvider.GetInstance().AddStockProductInfo(model));
 }