예제 #1
0
        /// <summary>
        /// 根据模型更新
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>是否成功</returns>
        public bool Update(Changestorage model, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var update = new LambdaUpdate <Changestorage>();

            if (!model.Id.IsNullOrEmpty())
            {
                update.Where(p => p.Id == model.Id);
            }
            if (!model.storageId.IsNullOrEmpty())
            {
                update.Set(p => p.storageId == model.storageId);
            }
            if (!model.ChangeTime.IsNullOrEmpty())
            {
                update.Set(p => p.ChangeTime == model.ChangeTime);
            }
            if (!model.ChangeType.IsNullOrEmpty())
            {
                update.Set(p => p.ChangeType == model.ChangeType);
            }
            if (!model.ChangeCount.IsNullOrEmpty())
            {
                update.Set(p => p.ChangeCount == model.ChangeCount);
            }
            if (!model.ChangeAfterCount.IsNullOrEmpty())
            {
                update.Set(p => p.ChangeAfterCount == model.ChangeAfterCount);
            }
            if (!model.ChangeContext.IsNullOrEmpty())
            {
                update.Set(p => p.ChangeContext == model.ChangeContext);
            }
            return(update.GetUpdateResult(connection, transaction));
        }
예제 #2
0
        /// <summary>
        /// 根据模型插入
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>是否成功</returns>
        public int InsertReturnKey(Changestorage model, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var insert = new LambdaInsert <Changestorage>();

            if (!model.storageId.IsNullOrEmpty())
            {
                insert.Insert(p => p.storageId == model.storageId);
            }
            if (!model.ChangeTime.IsNullOrEmpty())
            {
                insert.Insert(p => p.ChangeTime == model.ChangeTime);
            }
            if (!model.ChangeType.IsNullOrEmpty())
            {
                insert.Insert(p => p.ChangeType == model.ChangeType);
            }
            if (!model.ChangeCount.IsNullOrEmpty())
            {
                insert.Insert(p => p.ChangeCount == model.ChangeCount);
            }
            if (!model.ChangeAfterCount.IsNullOrEmpty())
            {
                insert.Insert(p => p.ChangeAfterCount == model.ChangeAfterCount);
            }
            if (!model.ChangeContext.IsNullOrEmpty())
            {
                insert.Insert(p => p.ChangeContext == model.ChangeContext);
            }
            return(insert.GetInsertResult(connection, transaction));
        }
예제 #3
0
 /// <summary>
 /// 库存变动统计
 /// </summary>
 /// <param name="change"></param>
 public ChangeStorages(Changestorage change)
 {
     //变动表Id
     this.Id = change.Id;
     //库存表Id
     this.storageId = change.Id;
     //变动时间
     this.ChangeTime = change.ChangeTime.ParseString();
     //变动类型
     this.ChangeType = change.ChangeType;
     //变动数量
     this.ChangeCount = change.ChangeCount;
     //变动后数量
     this.ChangeAfterCount = change.ChangeAfterCount;
     //变动描述
     this.ChangeContext = change.ChangeContext == null ? "" : change.ChangeContext;
 }
예제 #4
0
        /// <summary>
        /// 根据模型删除数据
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>是否成功</returns>
        public bool DeleteModel(Changestorage model = null, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var delete = new LambdaDelete <Changestorage>();

            if (model != null)
            {
                if (!model.Id.IsNullOrEmpty())
                {
                    delete.Where(p => p.Id == model.Id);
                }
                if (!model.storageId.IsNullOrEmpty())
                {
                    delete.Where(p => p.storageId == model.storageId);
                }
                if (!model.ChangeTime.IsNullOrEmpty())
                {
                    delete.Where(p => p.ChangeTime == model.ChangeTime);
                }
                if (!model.ChangeType.IsNullOrEmpty())
                {
                    delete.Where(p => p.ChangeType == model.ChangeType);
                }
                if (!model.ChangeCount.IsNullOrEmpty())
                {
                    delete.Where(p => p.ChangeCount == model.ChangeCount);
                }
                if (!model.ChangeAfterCount.IsNullOrEmpty())
                {
                    delete.Where(p => p.ChangeAfterCount == model.ChangeAfterCount);
                }
                if (!model.ChangeContext.IsNullOrEmpty())
                {
                    delete.Where(p => p.ChangeContext == model.ChangeContext);
                }
            }
            return(delete.GetDeleteResult(connection, transaction));
        }
예제 #5
0
        /// <summary>
        /// 数据条数
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>对象列表</returns>
        public int SelectCount(Changestorage model = null, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var query = new LambdaQuery <Changestorage>();

            if (model != null)
            {
                if (!model.Id.IsNullOrEmpty())
                {
                    query.Where(p => p.Id == model.Id);
                }
                if (!model.storageId.IsNullOrEmpty())
                {
                    query.Where(p => p.storageId == model.storageId);
                }
                if (!model.ChangeTime.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeTime == model.ChangeTime);
                }
                if (!model.ChangeType.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeType == model.ChangeType);
                }
                if (!model.ChangeCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeCount == model.ChangeCount);
                }
                if (!model.ChangeAfterCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeAfterCount == model.ChangeAfterCount);
                }
                if (!model.ChangeContext.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeContext == model.ChangeContext);
                }
            }
            return(query.GetQueryCount(connection, transaction));
        }
예제 #6
0
        /// <summary>
        /// 根据分页筛选数据
        /// </summary>
        /// <param name="Key">主键</param>
        /// <param name="start">开始数据</param>
        /// <param name="PageSize">页面长度</param>
        /// <param name="desc">排序</param>
        /// <param name="model">对象</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>对象列表</returns>
        public List <Changestorage> SelectByPage(string Key, int start, int PageSize, bool desc = true, Changestorage model = null, string SelectFiled = null, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var query = new LambdaQuery <Changestorage>();

            if (model != null)
            {
                if (!model.Id.IsNullOrEmpty())
                {
                    query.Where(p => p.Id == model.Id);
                }
                if (!model.storageId.IsNullOrEmpty())
                {
                    query.Where(p => p.storageId == model.storageId);
                }
                if (!model.ChangeTime.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeTime == model.ChangeTime);
                }
                if (!model.ChangeType.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeType == model.ChangeType);
                }
                if (!model.ChangeCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeCount == model.ChangeCount);
                }
                if (!model.ChangeAfterCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeAfterCount == model.ChangeAfterCount);
                }
                if (!model.ChangeContext.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeContext == model.ChangeContext);
                }
            }
            if (SelectFiled != null)
            {
                SelectFiled = SelectFiled.ToLowerInvariant();
                if (SelectFiled.Contains("id,"))
                {
                    query.Select(p => new { p.Id });
                }
                if (SelectFiled.Contains("storageid,"))
                {
                    query.Select(p => new { p.storageId });
                }
                if (SelectFiled.Contains("changetime,"))
                {
                    query.Select(p => new { p.ChangeTime });
                }
                if (SelectFiled.Contains("changetype,"))
                {
                    query.Select(p => new { p.ChangeType });
                }
                if (SelectFiled.Contains("changecount,"))
                {
                    query.Select(p => new { p.ChangeCount });
                }
                if (SelectFiled.Contains("changeaftercount,"))
                {
                    query.Select(p => new { p.ChangeAfterCount });
                }
                if (SelectFiled.Contains("changecontext,"))
                {
                    query.Select(p => new { p.ChangeContext });
                }
            }
            if (Key != null)
            {
                query.OrderByKey(Key, desc);
            }
            return(query.GetQueryPageList(start, PageSize, connection, transaction));
        }
예제 #7
0
        /// <summary>
        /// 筛选全部数据
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="connection">连接</param>
        /// <param name="transaction">事务</param>
        /// <returns>对象列表</returns>
        public List <Changestorage> SelectAll(Changestorage model = null, string SelectFiled = null, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            var query = new LambdaQuery <Changestorage>();

            if (model != null)
            {
                if (!model.Id.IsNullOrEmpty())
                {
                    query.Where(p => p.Id == model.Id);
                }
                if (!model.storageId.IsNullOrEmpty())
                {
                    query.Where(p => p.storageId == model.storageId);
                }
                if (!model.ChangeTime.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeTime == model.ChangeTime);
                }
                if (!model.ChangeType.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeType == model.ChangeType);
                }
                if (!model.ChangeCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeCount == model.ChangeCount);
                }
                if (!model.ChangeAfterCount.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeAfterCount == model.ChangeAfterCount);
                }
                if (!model.ChangeContext.IsNullOrEmpty())
                {
                    query.Where(p => p.ChangeContext == model.ChangeContext);
                }
            }
            if (SelectFiled != null)
            {
                SelectFiled = SelectFiled.ToLowerInvariant();
                if (SelectFiled.Contains("id,"))
                {
                    query.Select(p => new { p.Id });
                }
                if (SelectFiled.Contains("storageid,"))
                {
                    query.Select(p => new { p.storageId });
                }
                if (SelectFiled.Contains("changetime,"))
                {
                    query.Select(p => new { p.ChangeTime });
                }
                if (SelectFiled.Contains("changetype,"))
                {
                    query.Select(p => new { p.ChangeType });
                }
                if (SelectFiled.Contains("changecount,"))
                {
                    query.Select(p => new { p.ChangeCount });
                }
                if (SelectFiled.Contains("changeaftercount,"))
                {
                    query.Select(p => new { p.ChangeAfterCount });
                }
                if (SelectFiled.Contains("changecontext,"))
                {
                    query.Select(p => new { p.ChangeContext });
                }
            }
            return(query.GetQueryList(connection, transaction));
        }
예제 #8
0
        /// <summary>
        /// 创建记录改变
        /// </summary>
        /// <param name="ChangeContext"></param>
        /// <param name="ChangeCountType"></param>
        /// <param name="ChangeCount"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <param name="StorageId"></param>
        /// <param name="WarehouseId"></param>
        /// <param name="RawmaterialsId"></param>
        /// <param name="SKU"></param>
        /// <returns></returns>
        private bool CreateChange(string ChangeContext, string ChangeCountType, int ChangeCount, IDbConnection connection, IDbTransaction transaction, int StorageId, int WarehouseId, int RawmaterialsId, string SKU)
        {
            Storage storage;

            #region 若没有库存则新增库存
            if (StorageId == 0)
            {
                storage = StorageOper.Instance.SelectAll(new Storage {
                    Color = SKU, Raw_materialsId = RawmaterialsId, WarehouseId = WarehouseId
                }, null, connection, transaction).FirstOrDefault();
                if (storage != null)
                {
                    StorageId = storage.Id;
                }
                else
                {
                    storage = new Storage {
                        Color = SKU, Raw_materialsId = RawmaterialsId, WarehouseId = WarehouseId, stock = 0, freeze_stock = 0
                    };
                    StorageId  = StorageOper.Instance.InsertReturnKey(storage, connection, transaction);
                    storage.Id = StorageId;
                    if (StorageId <= 0)
                    {
                        return(false);
                    }
                }
            }
            #endregion
            else
            {
                storage = StorageOper.Instance.SelectById(StorageId);
            }
            //判断是增加类型还是减少类型
            var stock  = storage.stock.Value;
            var stocks = 0;
            if (ChangeCountType == "增加")
            {
                stocks = stock + ChangeCount;
            }
            else
            {
                stocks = stock - ChangeCount;
                if (stocks < 0)
                {
                    return(false);
                }
            }
            #region 变动处理
            Changestorage info = new Changestorage
            {
                storageId        = StorageId,
                ChangeTime       = DateTime.Now,
                ChangeType       = "手动输入调整",
                ChangeAfterCount = stocks,
                ChangeCount      = ChangeCountType + ChangeCount,
                ChangeContext    = ChangeContext
            };
            var OrderKey = ChangestorageOper.Instance.InsertReturnKey(info, connection, transaction);
            if (OrderKey <= 0)
            {
                return(false);
            }
            #endregion

            #region 仓库处理
            Storage stor = new Storage
            {
                Id    = StorageId,
                stock = stocks
            };
            if (!StorageOper.Instance.Update(stor, connection, transaction))
            {
                return(false);
            }
            #endregion

            return(true);
        }
예제 #9
0
 /// <summary>
 /// 根据分页筛选数据
 /// </summary>
 /// <param name="Key">主键</param>
 /// <param name="start">开始数据</param>
 /// <param name="PageSize">页面长度</param>
 /// <param name="desc">排序</param>
 /// <param name="model">对象</param>
 /// <returns>对象列表</returns>
 public List <Changestorage> SelectByPage(string Key, int start, int PageSize, bool desc, Changestorage model, string SelectFiled)
 {
     return(ChangestorageOper.Instance.SelectByPage(Key, start, PageSize, desc, model));
 }
예제 #10
0
 /// <summary>
 /// 数据条数
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>对象列表</returns>
 public int SelectCount(Changestorage model)
 {
     return(ChangestorageOper.Instance.SelectCount(model));
 }
예제 #11
0
 /// <summary>
 /// 筛选全部数据
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>对象列表</returns>
 public List <Changestorage> SelectByModel(Changestorage model)
 {
     return(ChangestorageOper.Instance.SelectAll(model));
 }
예제 #12
0
 /// <summary>
 /// 根据模型插入
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>是否成功</returns>
 public int InsertReturnKey(Changestorage model)
 {
     return(ChangestorageOper.Instance.InsertReturnKey(model));
 }
예제 #13
0
 /// <summary>
 /// 根据模型插入
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>是否成功</returns>
 public bool Insert(Changestorage model)
 {
     return(ChangestorageOper.Instance.Insert(model));
 }
예제 #14
0
 /// <summary>
 /// 根据模型更新
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>是否成功</returns>
 public bool Update(Changestorage model)
 {
     return(ChangestorageOper.Instance.Update(model));
 }
예제 #15
0
 /// <summary>
 /// 根据模型删除数据
 /// </summary>
 /// <param name="model">模型</param>
 /// <returns>是否成功</returns>
 public bool DeleteModel(Changestorage model)
 {
     return(ChangestorageOper.Instance.DeleteModel(model));
 }
예제 #16
0
        public bool UpdateStorage(int ReceiveId, IDbConnection connection, IDbTransaction transaction)
        {
            var Stock        = 0;
            var List_Storage = new List <Storage_View>();
            //查找到所有生产领料表Id
            var Receive_Material = Receive_MaterialsOper.Instance.SelectAll(new Receive_Materials {
                receiveId = ReceiveId
            }, null, connection, transaction);

            //查找该表的所有库存数据(颜色)
            List_Storage = Storage_ViewOper.Instance.SelectByKeys("Raw_materialsId", Receive_Material.Where(p => p.raw_materialsId != null).Select(p => p.raw_materialsId.Value.ToString()).ToList(), connection, transaction);
            foreach (var item in Receive_Material)
            {
                var Count            = item.BaseCount + item.additionalCount;
                var thisList_Storage = List_Storage.Where(p => p.Raw_materialsId == item.raw_materialsId && p.Color == item.SKU).ToList();
                if (Count > 0)
                {
                    //查找跟生产领料表Id对应的库存Id
                    for (var i = 0; i < thisList_Storage.Count; i++)
                    {
                        //判断是否要从其他仓库出库
                        if (Count > thisList_Storage[i].freeze_stock)
                        {
                            Count -= thisList_Storage[i].freeze_stock;
                            StorageOper.Instance.Update(new Storage {
                                Id = thisList_Storage[i].Id.Value, freeze_stock = 0, stock = thisList_Storage[i].stock - thisList_Storage[i].freeze_stock
                            }, connection, transaction);
                            #region 变动处理
                            Changestorage infos = new Changestorage
                            {
                                storageId        = thisList_Storage[i].Id.Value,
                                ChangeTime       = DateTime.Now,
                                ChangeType       = "生产领料",
                                ChangeAfterCount = thisList_Storage[i].stock - thisList_Storage[i].freeze_stock,
                                ChangeCount      = "减少" + thisList_Storage[i].freeze_stock,
                            };
                            if (!ChangestorageOper.Instance.Insert(infos, connection, transaction))
                            {
                                return(false);
                            }
                            #endregion
                            //所有库存都比冻结库存少
                            if (i == (List_Storage.Count - 1) && Count != 0)
                            {
                                return(false);
                            }
                        }
                        else if (Count != 0)
                        {
                            StorageOper.Instance.Update(new Storage {
                                Id = thisList_Storage[i].Id.Value, freeze_stock = thisList_Storage[i].freeze_stock - Count, stock = thisList_Storage[i].stock - Count
                            }, connection, transaction);
                            #region 变动处理
                            Changestorage infos = new Changestorage
                            {
                                storageId        = List_Storage[i].Id.Value,
                                ChangeTime       = DateTime.Now,
                                ChangeType       = "生产领料",
                                ChangeAfterCount = List_Storage[i].stock - Count,
                                ChangeCount      = "减少" + Count,
                            };
                            if (!ChangestorageOper.Instance.Insert(infos, connection, transaction))
                            {
                                Stock = (thisList_Storage[i].freeze_stock - Count).Value;
                                if (Stock == 0)
                                {
                                    return(false);
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            #region 修改订单状态
            Receive receive = new Receive
            {
                Id             = ReceiveId,
                receiveOutTime = DateTime.Now,
                receiveStatus  = "已出库"
            };
            if (!ReceiveOper.Instance.Update(receive, connection, transaction))
            {
                return(false);
            }
            #endregion
            return(true);
        }
예제 #17
0
        private bool CreateStorage(int WarehouseId, int deliverId, string RuKuNum, IDbConnection connection, IDbTransaction transaction)
        {
            #region 筛选出传入参数信息,若无数据则返回false
            var deliver   = DeliverOper.Instance.SelectById(deliverId, connection, transaction);
            var Warehouse = WarehouseOper.Instance.SelectById(WarehouseId, connection, transaction);
            if (deliver == null || Warehouse == null || deliver.IsStatus == "已入库")
            {
                return(false);
            }
            #endregion

            var storage = StorageOper.Instance.SelectAll(new Storage {
                Raw_materialsId = deliver.Raw_materialsId, WarehouseId = WarehouseId, Color = deliver.Color
            }, null, connection, transaction).FirstOrDefault();
            var returnKey        = 0;
            var ChangeAfterCount = 0;

            #region 若无记录则插入
            if (storage == null)
            {
                storage = new Storage {
                    Raw_materialsId = deliver.Raw_materialsId, WarehouseId = WarehouseId, freeze_stock = 0, stock = RuKuNum.ParseInt(), Color = deliver.Color
                };
                returnKey        = StorageOper.Instance.InsertReturnKey(storage, connection, transaction);
                ChangeAfterCount = deliver.buyerCount.Value;
                if (returnKey <= 0)
                {
                    return(false);
                }
            }
            #endregion

            #region 若有记录则修改
            else
            {
                storage.stock    = storage.stock + RuKuNum.ParseInt();
                ChangeAfterCount = storage.stock.Value;
                returnKey        = storage.Id;
                if (!StorageOper.Instance.Update(storage, connection, transaction))
                {
                    return(false);
                }
            }
            #endregion

            #region 变动处理
            Changestorage info = new Changestorage
            {
                storageId        = returnKey,
                ChangeTime       = DateTime.Now,
                ChangeType       = "采购入库",
                ChangeAfterCount = ChangeAfterCount,
                ChangeCount      = "增加" + RuKuNum,
            };
            if (!ChangestorageOper.Instance.Insert(info, connection, transaction))
            {
                return(false);
            }
            #endregion

            #region 修改入库状态
            deliver.IsStatus = "已入库";
            if (!DeliverOper.Instance.Update(deliver, connection, transaction))
            {
                return(false);
            }
            //判断是否全部入库,则修改采购表状态
            if (DeliverOper.Instance.SelectAll(new Deliver {
                buyerId = deliver.buyerId.Value, IsStatus = "待入库"
            }, null, connection, transaction).Count == 0)
            {
                ////账期
                //var AccountPeriod = Buyer_Producer_ViewOper.Instance.SelectById(deliver.Id).AccountPeriod;
                if (!BuyerOper.Instance.Update(new Buyer {
                    Id = deliver.buyerId.Value, buyerStatus = "已入库", wantmoney = 0
                }, connection, transaction))
                {
                    return(false);
                }
            }
            #endregion

            return(true);
        }