Example #1
0
        /// <summary>
        /// 产品入库操作
        /// </summary>
        /// <param name="Batch"></param>
        /// <param name="stockinfo"></param>
        /// <returns></returns>
        public string InStock(string Batch, string id)
        {
            using (DbTransactionScope <Allocation_BodyInfo> dbtran = base.CreateTransactionScope())
            {
                try
                {
                    //查询子表信息
                    SearchCondition condition = new SearchCondition();
                    condition.AddCondition("F_Id", id, SqlOperator.Equal);
                    Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

                    //查询主表判断是否审核
                    condition = new SearchCondition();
                    condition.AddCondition("F_Id", bodyinfo.F_HId, SqlOperator.Equal);
                    Allocation_HeadInfo headinfo = BLLFactory <Allocation_Head> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

                    if (headinfo.F_Status == 0)
                    {
                        return("该调拨单未审核,不能进行出库操作");
                    }

                    //判断是否已入库
                    if (bodyinfo.F_AlreadyOperatedNum == null)//F_AlreadyOperatedNum--0未入库  1已入库
                    {
                        bodyinfo.F_AlreadyOperatedNum = 0;
                    }
                    if (bodyinfo.F_AlreadyOperatedNum > 0)
                    {
                        return("该单据已入库,不能重复执行入库操作");
                    }

                    //判断该调拨单是否出库
                    if (bodyinfo.F_FreeTerm1 == null)//F_FreeTerm1--0未出库  1已出库
                    {
                        bodyinfo.F_FreeTerm1 = "0";
                        return("调拨单中产品未出库,不能进行入库操作");
                    }

                    if (int.Parse(bodyinfo.F_FreeTerm1) > 0)
                    {
                        //查询库存表是否存在该仓库中的产品
                        condition = new SearchCondition();
                        condition.AddCondition("F_GoodsId", bodyinfo.F_GoodsId, SqlOperator.Equal);
                        condition.AddCondition("F_WarehouseId", bodyinfo.F_InWareId, SqlOperator.Equal);
                        List <Sys_StockInfo> stock = BLLFactory <Sys_Stock> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty));

                        //如果不存在
                        if (stock.Count == 0)
                        {
                            //新添加一条数据
                            Sys_StockInfo entity = new Sys_StockInfo();
                            entity.F_Id            = Guid.NewGuid().ToString();
                            entity.F_GoodsId       = bodyinfo.F_GoodsId;
                            entity.F_GoodsName     = bodyinfo.F_GoodsName;
                            entity.F_WarehouseId   = bodyinfo.F_InWareId;
                            entity.F_WarehouseName = bodyinfo.F_InWareName;
                            entity.F_Number        = bodyinfo.F_DbNum;
                            Sys_Stock.Instance.Insert(entity, dbtran.Transaction);

                            //添加履历
                            Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo();
                            Dbinfo.F_Id          = Guid.NewGuid().ToString();
                            Dbinfo.F_GoodsId     = bodyinfo.F_GoodsId;
                            Dbinfo.F_InWareName  = bodyinfo.F_InWareName;
                            Dbinfo.F_GoodsName   = bodyinfo.F_GoodsName;
                            Dbinfo.F_OutWareId   = bodyinfo.F_OutWareId;
                            Dbinfo.F_InWareId    = bodyinfo.F_InWareId;
                            Dbinfo.F_OutWareName = bodyinfo.F_OutWareName;
                            Dbinfo.F_Unit        = bodyinfo.F_Unit;
                            Dbinfo.F_DBNum       = bodyinfo.F_DbNum;
                            Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel;
                            Dbinfo.F_CreatorTime = DateTime.Now;

                            Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction);

                            //更新入库状态
                            Hashtable hash = new Hashtable();
                            hash.Add("F_AlreadyOperatedNum", 1);
                            Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction);
                        }
                        //如果存在
                        else
                        {
                            //增加库存
                            Hashtable hash = new Hashtable();
                            hash.Add("F_Number", stock[0].F_Number + bodyinfo.F_DbNum);
                            Sys_Stock.Instance.Update(stock[0].F_Id, hash, dbtran.Transaction);

                            //更新入库状态
                            hash = new Hashtable();
                            hash.Add("F_AlreadyOperatedNum", 1);
                            Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction);

                            //添加履历
                            Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo();
                            Dbinfo.F_Id          = Guid.NewGuid().ToString();
                            Dbinfo.F_GoodsId     = bodyinfo.F_GoodsId;
                            Dbinfo.F_InWareName  = bodyinfo.F_InWareName;
                            Dbinfo.F_GoodsName   = bodyinfo.F_GoodsName;
                            Dbinfo.F_OutWareId   = bodyinfo.F_OutWareId;
                            Dbinfo.F_InWareId    = bodyinfo.F_InWareId;
                            Dbinfo.F_OutWareName = bodyinfo.F_OutWareName;
                            Dbinfo.F_Unit        = bodyinfo.F_Unit;
                            Dbinfo.F_DBNum       = bodyinfo.F_DbNum;
                            Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel;
                            Dbinfo.F_CreatorTime = DateTime.Now;

                            Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction);
                        }
                    }

                    dbtran.Commit();
                    return("操作成功");
                }
                catch (Exception ex)
                {
                    dbtran.RollBack();
                    return("操作失败");

                    throw ex;
                }
            }
        }
Example #2
0
        public string OutStock(string Batch, string id)
        {
            using (DbTransactionScope <Allocation_BodyInfo> dbtran = base.CreateTransactionScope())
            {
                try
                {
                    //查询子表信息
                    SearchCondition condition = new SearchCondition();
                    condition.AddCondition("F_Id", id, SqlOperator.Equal);
                    Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

                    //查询主表判断是否审核
                    condition = new SearchCondition();
                    condition.AddCondition("F_Id", bodyinfo.F_HId, SqlOperator.Equal);
                    Allocation_HeadInfo headinfo = BLLFactory <Allocation_Head> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

                    if (headinfo.F_Status == 0)
                    {
                        return("该调拨单未审核,不能进行出库操作");
                    }

                    //判断是否出库
                    if (bodyinfo.F_FreeTerm1 == "") //F_FreeTerm1--0未出库  1已出库
                    {
                        bodyinfo.F_FreeTerm1 = "0";
                    }
                    if (int.Parse(bodyinfo.F_FreeTerm1) > 0)
                    {
                        return("该单据已出库,不能重复执行出库操作");
                    }

                    //查询库存表是否存在该仓库中的产品
                    condition = new SearchCondition();
                    condition.AddCondition("F_GoodsId", bodyinfo.F_GoodsId, SqlOperator.Equal);
                    condition.AddCondition("F_WarehouseId", bodyinfo.F_OutWareId, SqlOperator.Equal);
                    List <Sys_StockInfo> stock = BLLFactory <Sys_Stock> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty));

                    if (stock.Count == 0)
                    {
                        return("该仓库无此产品");
                    }

                    //判断库存数量是否足够
                    if (stock[0].F_Number > bodyinfo.F_DbNum)
                    {
                        //扣减库存
                        Hashtable hash = new Hashtable();
                        hash.Add("F_Number", stock[0].F_Number - bodyinfo.F_DbNum);
                        Sys_Stock.Instance.Update(stock[0].F_Id, hash, dbtran.Transaction);

                        //更新出库状态
                        hash = new Hashtable();
                        hash.Add("F_FreeTerm1", 1);
                        Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction);
                    }
                    else
                    {
                        return(bodyinfo.F_OutWareName + "仓库库存不足,当前产品" + bodyinfo.F_GoodsName + "库存为" + stock[0].F_Number);
                    }

                    dbtran.Commit();
                    return("操作成功");
                }
                catch (Exception ex)
                {
                    dbtran.RollBack();
                    return("操作失败");

                    throw ex;
                }
            }
        }