Esempio n. 1
0
        /// <summary>
        /// 查询库存数量
        /// </summary>
        /// <returns></returns>
        public ActionResult GetNum()
        {
            SO_StockMakeBodyInfo bodyInfo = BLLFactory <SO_StockMakeBody> .Instance.FindByID(selectId);

            SearchCondition condition = new SearchCondition();

            condition.AddCondition("F_GoodsId", bodyInfo.F_GoodsId, SqlOperator.Equal);
            condition.AddCondition("F_WarehouseId", bodyInfo.F_WarehouseId, SqlOperator.Equal);
            condition.AddCondition("F_CargoPositionId", bodyInfo.F_CargoPositionId, SqlOperator.Equal);
            Sys_StockInfo Info = BLLFactory <Sys_Stock> .Instance.Find(GetConditionStr(condition))[0];

            return(Content(JsonAppHelper.ToJson(Info)));
        }
Esempio n. 2
0
        /// <summary>
        ///审核单据
        /// </summary>
        /// <param name="date">审核日期</param>
        /// <param name="Id">审核单据</param>
        /// <param name="user">审核人</param>
        public string Audit(string date, string user, string Id, List <PI_ReturnBodyInfo> stockinfo)
        {
            string SqlAuditSel = "select F_Status from PI_ReturnHead where F_Id='" + Id + "'";
            string AuditState  = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();

            if (AuditState == "1")
            {
                return("单据已被审核");
            }
            else
            {
                using (DbTransactionScope <PI_ReturnHeadInfo> dbtran = base.CreateTransactionScope())
                {
                    try
                    {
                        Hashtable hash = new Hashtable();
                        //查询所有库存信息
                        List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                        PI_ReturnHeadInfo hinfo = BLLFactory <PI_ReturnHead> .Instance.FindByID(Id);

                        SearchCondition condition = new SearchCondition();
                        //condition.AddCondition("F_EnCode", hinfo.F_InStockCode, SqlOperator.Equal);
                        //PI_HeadInfo pih = BLLFactory<PI_Head>.Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];


                        for (int i = 0; i < stockinfo.Count; i++)
                        {
                            //查询子表信息
                            condition = new SearchCondition();
                            condition.AddCondition("F_Id", stockinfo[i].F_Id, SqlOperator.Equal);
                            PI_ReturnBodyInfo bodyinfo = BLLFactory <PI_ReturnBody> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

                            if (bodyinfo.F_WarehouseId == "" || bodyinfo.F_CargoPositionId == "")
                            {
                                return("该单据中仓库或仓位为空,审核未通过");
                            }

                            Sys_StockInfo stock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_WarehouseId && u.F_CargoPositionId == bodyinfo.F_CargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId && u.F_Batch == bodyinfo.F_SerialNum);

                            //查询库存表是否存在该仓库中的产品

                            if (stock == null)
                            {
                                dbtran.RollBack();
                                return("该仓库无此产品");
                            }

                            if (stock.F_Number - bodyinfo.F_ReturnNum < 0)
                            {
                                return("产品数量发生了变化,请重新选择审核退回");
                            }

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

                                //标记为已退货
                                //hash = new Hashtable();
                                //hash.Add("F_DocumentNum", 1);
                                //PI_Head.Instance.Update(pih.F_Id, hash, dbtran.Transaction);

                                //添加履历
                                Sys_InReturnHistoryInfo inRec = new Sys_InReturnHistoryInfo();
                                inRec.F_Id                = Guid.NewGuid().ToString();
                                inRec.F_EnCode            = bodyinfo.F_OrderNo;
                                inRec.F_Batch             = bodyinfo.F_SerialNum;
                                inRec.F_Vendor            = bodyinfo.F_Vendor;
                                inRec.F_VendorName        = bodyinfo.F_VendorName;
                                inRec.F_Verify            = user;
                                inRec.F_Maker             = hinfo.F_Maker;
                                inRec.F_Contacts          = hinfo.F_Contacts;
                                inRec.F_TelePhone         = hinfo.F_TelePhone;
                                inRec.F_Address           = hinfo.F_Address;
                                inRec.F_VeriDate          = DateTime.Now;
                                inRec.F_WarehouseId       = bodyinfo.F_WarehouseId;
                                inRec.F_WarehouseName     = bodyinfo.F_WarehouseName;
                                inRec.F_GoodsName         = bodyinfo.F_GoodsName;
                                inRec.F_GoodsId           = bodyinfo.F_GoodsId;
                                inRec.F_CargoPositionId   = bodyinfo.F_CargoPositionId;
                                inRec.F_CargoPositionName = bodyinfo.F_CargoPositionName;
                                inRec.F_SpecifModel       = bodyinfo.F_SpecifModel;
                                inRec.F_SellingPrice      = bodyinfo.F_SellingPrice;
                                inRec.F_PurchasePrice     = bodyinfo.F_PurchasePrice;
                                inRec.F_Unit              = bodyinfo.F_Unit;
                                inRec.F_InStockNum        = bodyinfo.F_InStockNum;
                                inRec.F_ReturnNum         = bodyinfo.F_ReturnNum;
                                inRec.F_CreatorTime       = DateTime.Now;
                                Sys_InReturnHistory.Instance.Insert(inRec, dbtran.Transaction);


                                //添加库存履历
                                Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo();
                                instockHistory.F_Id                = Guid.NewGuid().ToString();
                                instockHistory.F_EnCode            = bodyinfo.F_OrderNo;
                                instockHistory.F_Batch             = bodyinfo.F_SerialNum;
                                instockHistory.F_Vendor            = hinfo.F_Vendor;
                                instockHistory.F_VendorName        = bodyinfo.F_VendorName;
                                instockHistory.F_Verify            = user;
                                instockHistory.F_Maker             = hinfo.F_Maker;
                                instockHistory.F_Contacts          = hinfo.F_Contacts;
                                instockHistory.F_TelePhone         = hinfo.F_TelePhone;
                                instockHistory.F_Address           = hinfo.F_Address;
                                instockHistory.F_VeriDate          = DateTime.Now;
                                instockHistory.F_WarehouseId       = bodyinfo.F_WarehouseId;
                                instockHistory.F_WarehouseName     = bodyinfo.F_WarehouseName;
                                instockHistory.F_BllCategory       = "入库退货";
                                instockHistory.F_GoodsName         = bodyinfo.F_GoodsName;
                                instockHistory.F_GoodsId           = bodyinfo.F_GoodsId;
                                instockHistory.F_CargoPositionId   = bodyinfo.F_CargoPositionId;
                                instockHistory.F_CargoPositionName = bodyinfo.F_CargoPositionName;
                                instockHistory.F_SpecifModel       = bodyinfo.F_SpecifModel;
                                instockHistory.F_Unit              = bodyinfo.F_Unit;
                                instockHistory.F_OperationNum      = 0 - bodyinfo.F_ReturnNum;
                                instockHistory.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction);


                                //更新主表入库状态
                                hash = new Hashtable();
                                hash.Add("F_State", 1);
                                PI_ReturnHead.Instance.Update(bodyinfo.F_HId, hash, dbtran.Transaction);
                            }
                            else
                            {
                                return(bodyinfo.F_WarehouseName + "仓库库存不足,产品:" + bodyinfo.F_GoodsName + "库存为:" + stock.F_Number);
                            }

                            //更新审核状态
                            string sql = string.Format("update PI_ReturnHead set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                            hash = new Hashtable();
                            base.ExecuteNonQuery(sql, hash, dbtran.Transaction);
                        }
                        dbtran.Commit();
                        return("单据审核成功");
                    }
                    catch (Exception ex)
                    {
                        dbtran.RollBack();
                        return("操作失败");

                        throw ex;
                    }
                }
            }
        }
Esempio n. 3
0
        public void Status(string F_Id, string userName, List <SO_StockMakeBodyInfo> info)
        {
            using (DbTransactionScope <SO_StockMakeHeadInfo> dbtran = base.CreateTransactionScope())
            {
                DateTime time = DateTime.Now;
                try
                {
                    //更新登记单主表审核状态,审核人,审核时间
                    SO_StockMakeHeadInfo head = SO_StockMakeHead.Instance.FindByID(F_Id, dbtran.Transaction);
                    head.F_Status   = 1;
                    head.F_Verify   = userName;
                    head.F_VeriDate = DateTime.Now.ToShortDateString();
                    SO_StockMakeHead.Instance.Update(head, F_Id, dbtran.Transaction);
                    //查询所有库存
                    List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                    //库存更新履历
                    List <Sys_StockHistoryInfo> StockHisList = new List <Sys_StockHistoryInfo>();
                    //添加盘点履历
                    List <Sys_StockMaskHistoryInfo> list = new List <Sys_StockMaskHistoryInfo>();

                    //更新产品库存
                    foreach (SO_StockMakeBodyInfo item in info)
                    {
                        Sys_StockInfo Info = StockList.Find(u => u.F_WarehouseId == item.F_WarehouseId && u.F_CargoPositionId == item.F_CargoPositionId && u.F_GoodsId == item.F_GoodsId);
                        Hashtable     hash = new Hashtable();
                        hash.Add("F_Number", item.F_RealNumber);
                        Sys_Stock.Instance.Update(Info.F_Id, hash, dbtran.Transaction);


                        //添加盘点履历
                        Sys_StockMaskHistoryInfo maskInfo = new Sys_StockMaskHistoryInfo();
                        maskInfo.F_GoodsId           = item.F_GoodsId;
                        maskInfo.F_GoodsName         = item.F_GoodsName;
                        maskInfo.F_WarehouseId       = item.F_WarehouseId;
                        maskInfo.F_WarehouseName     = item.F_WarehouseName;
                        maskInfo.F_CargoPositionId   = item.F_CargoPositionId;
                        maskInfo.F_CargoPositionName = item.F_CargoPositionName;
                        maskInfo.F_Unit        = item.F_Unit;
                        maskInfo.F_Batch       = item.F_Batch;
                        maskInfo.F_Date        = time;
                        maskInfo.F_Description = item.F_Description;
                        maskInfo.F_EnCode      = head.F_EnCode;
                        maskInfo.F_Number      = item.F_Number;
                        maskInfo.F_RealNumber  = int.Parse(item.F_RealNumber);
                        maskInfo.F_Unit        = item.F_Unit;
                        maskInfo.F_DiffNumber  = Math.Abs(int.Parse(item.F_RealNumber) - item.F_Number);
                        list.Add(maskInfo);

                        //添加库存信息
                        Sys_StockHistoryInfo HistoryInfo = new Sys_StockHistoryInfo();
                        HistoryInfo.F_CargoPositionId   = item.F_CargoPositionId;
                        HistoryInfo.F_CargoPositionName = item.F_CargoPositionName;
                        HistoryInfo.F_WarehouseId       = item.F_WarehouseId;
                        HistoryInfo.F_WarehouseName     = item.F_WarehouseName;
                        HistoryInfo.F_EnCode            = head.F_EnCode;
                        HistoryInfo.F_Batch             = item.F_Batch;
                        HistoryInfo.F_BllCategory       = "盘点";
                        HistoryInfo.F_OperationNum      = int.Parse(item.F_RealNumber) - item.F_Number;
                        HistoryInfo.F_SpecifModel       = item.F_SpecifModel;
                        HistoryInfo.F_Vendor            = userName;
                        HistoryInfo.F_GoodsId           = item.F_GoodsId;
                        HistoryInfo.F_GoodsName         = item.F_GoodsName;
                        HistoryInfo.F_Unit = item.F_Unit;
                        //HistoryInfo.F_VendorName = head.;
                        //HistoryInfo.F_Contacts = head.F_Contacts;
                        //HistoryInfo.F_TelePhone = head.F_TelePhone;
                        HistoryInfo.F_Maker  = head.F_Operator;
                        HistoryInfo.F_Verify = head.F_Verify;


                        StockHisList.Add(HistoryInfo);
                    }
                    Sys_StockHistory.Instance.InsertRange(StockHisList, dbtran.Transaction);
                    //添盘点记录
                    Sys_StockMaskHistory.Instance.InsertRange(list, dbtran.Transaction);
                    dbtran.Commit();
                }
                catch (Exception ex)
                {
                    dbtran.RollBack();
                    throw ex;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///审核单据
        /// </summary>
        /// <param name="date">审核日期</param>
        /// <param name="Id">审核单据</param>
        /// <param name="user">审核人</param>
        public string Audit(string date, string user, string Id, List <Allocation_BodyInfo> DbInfo)
        {
            string SqlAuditSel = "select F_Status from Allocation_Head where F_Id='" + Id + "'";
            string AuditState  = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();

            if (AuditState == "1")
            {
                return("单据已被审核");
            }
            else
            {
                using (DbTransactionScope <Allocation_HeadInfo> dbtran = base.CreateTransactionScope())
                {
                    try
                    {
                        Hashtable            hash      = new Hashtable();
                        List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                        //查询主表信息
                        Allocation_HeadInfo hinfo = BLLFactory <Allocation_Head> .Instance.FindByID(Id);

                        for (int i = 0; i < DbInfo.Count; i++)
                        {
                            //查询子表信息
                            SearchCondition condition = new SearchCondition();
                            condition.AddCondition("F_Id", DbInfo[i].F_Id, SqlOperator.Equal);
                            Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty))[0];

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

                            if (bodyinfo.F_OutWareId == "" || bodyinfo.F_OutCargoPositionId == "" || bodyinfo.F_InWareId == "" || bodyinfo.F_InCargoPositionId == "")
                            {
                                return("该单据中仓库或仓位为空,审核未通过");
                            }

                            //查询库存表是否存在该仓库中的产品
                            Sys_StockInfo stock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_OutWareId && u.F_CargoPositionId == bodyinfo.F_OutCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId && u.F_Batch == bodyinfo.F_SerialNum);

                            if (stock == null)
                            {
                                dbtran.RollBack();
                                return("该仓库无此产品");
                            }

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

                                //添加库存履历
                                Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo();
                                instockHistory.F_Id                = Guid.NewGuid().ToString();
                                instockHistory.F_WarehouseId       = bodyinfo.F_OutWareId;
                                instockHistory.F_EnCode            = bodyinfo.F_OrderNo;
                                instockHistory.F_Batch             = bodyinfo.F_SerialNum;
                                instockHistory.F_Verify            = user;
                                instockHistory.F_Maker             = hinfo.F_Maker;
                                instockHistory.F_VeriDate          = DateTime.Now;
                                instockHistory.F_WarehouseName     = bodyinfo.F_OutWareName;
                                instockHistory.F_BllCategory       = "调出";
                                instockHistory.F_GoodsName         = bodyinfo.F_GoodsName;
                                instockHistory.F_GoodsId           = bodyinfo.F_GoodsId;
                                instockHistory.F_CargoPositionId   = bodyinfo.F_OutCargoPositionId;
                                instockHistory.F_CargoPositionName = bodyinfo.F_OutCargoPositionName;
                                instockHistory.F_SpecifModel       = bodyinfo.F_SpecifModel;
                                instockHistory.F_Unit              = bodyinfo.F_Unit;
                                instockHistory.F_OperationNum      = 0 - bodyinfo.F_DbNum;
                                instockHistory.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instockHistory, 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.F_Number);
                            }

                            Sys_StockInfo instock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_InWareId && u.F_CargoPositionId == bodyinfo.F_InCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId);
                            //如果不存在
                            if (instock == null)
                            {
                                //新添加一条数据
                                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_CargoPositionId   = bodyinfo.F_InCargoPositionId;
                                entity.F_CargoPositionName = bodyinfo.F_InCargoPositionName;
                                entity.F_Batch             = bodyinfo.F_SerialNum;
                                entity.F_Unit              = bodyinfo.F_Unit;
                                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_EnCode               = bodyinfo.F_OrderNo;
                                Dbinfo.F_Batch                = bodyinfo.F_SerialNum;
                                Dbinfo.F_GoodsName            = bodyinfo.F_GoodsName;
                                Dbinfo.F_Verify               = user;
                                Dbinfo.F_Maker                = hinfo.F_Maker;
                                Dbinfo.F_VeriDate             = DateTime.Now;
                                Dbinfo.F_OutWareId            = bodyinfo.F_OutWareId;
                                Dbinfo.F_InWareId             = bodyinfo.F_InWareId;
                                Dbinfo.F_OutWareName          = bodyinfo.F_OutWareName;
                                Dbinfo.F_InCargoPositionId    = bodyinfo.F_InCargoPositionId;
                                Dbinfo.F_InCargoPositionName  = bodyinfo.F_InCargoPositionName;
                                Dbinfo.F_OutCargoPositionId   = bodyinfo.F_OutCargoPositionId;
                                Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName;
                                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);

                                //添加库存履历
                                Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo();
                                instockHistory.F_Id                = Guid.NewGuid().ToString();
                                instockHistory.F_WarehouseId       = bodyinfo.F_OutWareId;
                                instockHistory.F_EnCode            = bodyinfo.F_OrderNo;
                                instockHistory.F_Batch             = bodyinfo.F_SerialNum;
                                instockHistory.F_Verify            = user;
                                instockHistory.F_Maker             = hinfo.F_Maker;
                                instockHistory.F_VeriDate          = DateTime.Now;
                                instockHistory.F_WarehouseName     = bodyinfo.F_InWareName;
                                instockHistory.F_BllCategory       = "调入";
                                instockHistory.F_GoodsName         = bodyinfo.F_GoodsName;
                                instockHistory.F_GoodsId           = bodyinfo.F_GoodsId;
                                instockHistory.F_CargoPositionId   = bodyinfo.F_InCargoPositionName;
                                instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionId;
                                instockHistory.F_SpecifModel       = bodyinfo.F_SpecifModel;
                                instockHistory.F_Unit              = bodyinfo.F_Unit;
                                instockHistory.F_OperationNum      = bodyinfo.F_DbNum;
                                instockHistory.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction);

                                //更新入库状态
                                hash = new Hashtable();
                                hash.Add("F_AlreadyOperatedNum", 1);
                                Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction);
                            }
                            //如果存在
                            else
                            {
                                //增加库存
                                hash = new Hashtable();
                                hash.Add("F_Number", instock.F_Number + bodyinfo.F_DbNum);
                                Sys_Stock.Instance.Update(instock.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_Verify               = user;
                                Dbinfo.F_Maker                = hinfo.F_Maker;
                                Dbinfo.F_VeriDate             = DateTime.Now;
                                Dbinfo.F_EnCode               = bodyinfo.F_OrderNo;
                                Dbinfo.F_Batch                = bodyinfo.F_SerialNum;
                                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_InCargoPositionId    = bodyinfo.F_InCargoPositionId;
                                Dbinfo.F_InCargoPositionName  = bodyinfo.F_InCargoPositionName;
                                Dbinfo.F_OutCargoPositionId   = bodyinfo.F_OutCargoPositionId;
                                Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName;
                                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);


                                //添加库存履历
                                Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo();
                                instockHistory.F_Id                = Guid.NewGuid().ToString();
                                instockHistory.F_WarehouseId       = bodyinfo.F_InWareId;
                                instockHistory.F_WarehouseName     = bodyinfo.F_InWareName;
                                instockHistory.F_EnCode            = bodyinfo.F_OrderNo;
                                instockHistory.F_Batch             = bodyinfo.F_SerialNum;
                                instockHistory.F_Verify            = user;
                                instockHistory.F_Maker             = hinfo.F_Maker;
                                instockHistory.F_VeriDate          = DateTime.Now;
                                instockHistory.F_BllCategory       = "调入";
                                instockHistory.F_GoodsName         = bodyinfo.F_GoodsName;
                                instockHistory.F_GoodsId           = bodyinfo.F_GoodsId;
                                instockHistory.F_CargoPositionId   = bodyinfo.F_InCargoPositionId;
                                instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionName;
                                instockHistory.F_SpecifModel       = bodyinfo.F_SpecifModel;
                                instockHistory.F_Unit              = bodyinfo.F_Unit;
                                instockHistory.F_OperationNum      = bodyinfo.F_DbNum;
                                instockHistory.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction);
                            }
                        }

                        //更新审核状态
                        string sql = string.Format("update Allocation_Head set F_Status=1,F_AccountDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                        hash = new Hashtable();
                        base.ExecuteNonQuery(sql, hash, dbtran.Transaction);

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

                        throw ex;
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 产品入库操作
        /// </summary>
        /// <param name="Batch"></param>
        /// <param name="stockinfo"></param>
        /// <returns></returns>
        public string InStock(string Batch, List <PI_BodyInfo> stockinfo)
        {
            using (DbTransactionScope <PI_BodyInfo> dbtran = base.CreateTransactionScope())
            {
                try
                {
                    //查询入库单是否审核
                    string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + stockinfo[0].F_HId + "'";
                    string AuditState  = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();
                    if (AuditState == "0")
                    {
                        return("该入库单未审核,不能进行入库操作");
                    }

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

                        if (stock == null)
                        {
                            item.IsHave = false;
                        }
                        else
                        {
                            item.IsHave      = true;
                            item.StockID     = stock[0].F_Id;
                            item.StockNumber = stock[0].F_Number;
                        }
                    }
                    foreach (PI_BodyInfo item in stockinfo)
                    {
                        //判断是否入库
                        PI_BodyInfo binfo = BLLFactory <PI_Body> .Instance.FindByID(item.F_Id);

                        if (binfo.F_AlreadyOperatedNum == "")
                        {
                            binfo.F_AlreadyOperatedNum = "0";
                        }
                        if (int.Parse(binfo.F_AlreadyOperatedNum) > 0)
                        {
                            return("该单据已入库,不能重复执行入库操作");
                        }
                        //查询库存表是否存在该仓库中的产品
                        //没有
                        if (!item.IsHave)
                        {
                            //新添加一条数据
                            Sys_StockInfo entity = new Sys_StockInfo();
                            entity.F_Id                = Guid.NewGuid().ToString();
                            entity.F_Batch             = item.F_OrderNo;
                            entity.F_CargoPositionId   = item.F_CargoPositionId;
                            entity.F_CargoPositionName = item.F_CargoPositionName;
                            entity.F_WarehouseId       = item.F_WarehouseId;
                            entity.F_WarehouseName     = item.F_WarehouseName;
                            entity.F_GoodsName         = item.F_GoodsName;
                            entity.F_GoodsId           = item.F_GoodsId;
                            entity.F_SpecifModel       = item.F_SpecifModel;
                            entity.F_SellingPrice      = item.F_SellingPrice;
                            entity.F_PurchasePrice     = item.F_PurchasePrice;
                            entity.F_Unit              = item.F_Unit;
                            entity.F_Number            = item.F_InStockNum;
                            Sys_Stock.Instance.Insert(entity, dbtran.Transaction);

                            //添加履历
                            Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                            inRec.F_Id                = Guid.NewGuid().ToString();
                            inRec.F_WarehouseId       = item.F_WarehouseId;
                            inRec.F_WarehouseName     = item.F_WarehouseName;
                            inRec.F_GoodsName         = item.F_GoodsName;
                            inRec.F_GoodsId           = item.F_GoodsId;
                            inRec.F_CargoPositionId   = item.F_CargoPositionId;
                            inRec.F_CargoPositionName = item.F_CargoPositionName;
                            inRec.F_SpecifModel       = item.F_SpecifModel;
                            inRec.F_SellingPrice      = item.F_SellingPrice;
                            inRec.F_PurchasePrice     = item.F_PurchasePrice;
                            inRec.F_Unit              = item.F_Unit;
                            inRec.F_InStockNum        = item.F_InStockNum;
                            inRec.F_CreatorTime       = DateTime.Now;
                            Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);


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

                            //更新主表入库状态
                            hash = new Hashtable();
                            hash.Add("F_State", 1);
                            PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);
                        }
                        else
                        {
                            //更新前库存数量
                            Hashtable hash = new Hashtable();
                            hash.Add("F_Number", item.StockNumber + item.F_InStockNum);
                            Sys_Stock.Instance.Update(item.StockID, hash, dbtran.Transaction);
                            for (int i = 0; i < stockinfo.Count; i++)
                            {
                                if (stockinfo[i].StockID == item.StockID)
                                {
                                    stockinfo[i].StockNumber += item.F_InStockNum;
                                }
                            }

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

                            //更新主表入库状态
                            hash = new Hashtable();
                            hash.Add("F_State", 1);
                            PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);


                            //添加履历
                            Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                            inRec.F_Id                = Guid.NewGuid().ToString();
                            inRec.F_WarehouseId       = item.F_WarehouseId;
                            inRec.F_WarehouseName     = item.F_WarehouseName;
                            inRec.F_GoodsName         = item.F_GoodsName;
                            inRec.F_GoodsId           = item.F_GoodsId;
                            inRec.F_CargoPositionId   = item.F_CargoPositionId;
                            inRec.F_CargoPositionName = item.F_CargoPositionName;
                            inRec.F_SpecifModel       = item.F_SpecifModel;
                            inRec.F_SellingPrice      = item.F_SellingPrice;
                            inRec.F_PurchasePrice     = item.F_PurchasePrice;
                            inRec.F_Unit              = item.F_Unit;
                            inRec.F_InStockNum        = item.F_InStockNum;
                            inRec.F_CreatorTime       = DateTime.Now;
                            Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);
                        }
                    }
                    dbtran.Commit();
                    return("操作成功");
                }
                catch (Exception ex)
                {
                    dbtran.RollBack();
                    return("操作失败");

                    throw ex;
                }
            }

            //try
            //{
            //    //循环获取子表信息
            //    for (int i = 0; i < stockinfo.Count; i++)
            //    {
            //        string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + stockinfo[i].F_HId + "'";
            //        string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();
            //        if (AuditState == "0")
            //        {
            //            return "该入库单未审核,不能进行入库操作";
            //        }

            //        string state = "select F_AlreadyOperatedNum from PI_Body where F_Id='" + stockinfo[i].F_Id + "'";
            //        DataTable dt = this.GetDataTableBySql(state);
            //        //判断是否已入库
            //        string AoNum = dt.Rows[0][0].ToString();
            //        if (AoNum == "")
            //        {
            //            AoNum = "0";
            //        }
            //        if (int.Parse(AoNum) > 0)
            //        {
            //            return "该单据已入库,不能重复执行入库操作";
            //        }

            //        //查询库存表是否存在该仓库中的产品
            //        string sql = "select F_Id,F_Number from Sys_Stock where F_GoodsId='" + stockinfo[i].F_GoodsId + "' and F_WarehouseId='" + stockinfo[i].F_WarehouseId + "'";

            //        //如果没有则添加一条数据
            //        if (this.GetDataTableBySql(sql).Rows.Count == 0)
            //        {
            //            //新添加一条数据
            //            Sys_StockInfo entity = new Sys_StockInfo();
            //            entity.F_Id = Guid.NewGuid().ToString();
            //            entity.F_Batch = stockinfo[i].F_OrderNo;
            //            entity.F_CargoPositionId = stockinfo[i].F_CargoPositionId;
            //            entity.F_CargoPositionName = stockinfo[i].F_CargoPositionName;
            //            entity.F_WarehouseId = stockinfo[i].F_WarehouseId;
            //            entity.F_WarehouseName = stockinfo[i].F_WarehouseName;
            //            entity.F_GoodsName = stockinfo[i].F_GoodsName;
            //            entity.F_GoodsId = stockinfo[i].F_GoodsId;
            //            entity.F_SpecifModel = stockinfo[i].F_SpecifModel;
            //            entity.F_SellingPrice = stockinfo[i].F_SellingPrice;
            //            entity.F_PurchasePrice = stockinfo[i].F_PurchasePrice;
            //            entity.F_Unit = stockinfo[i].F_Unit;
            //            entity.F_Number = stockinfo[i].F_InStockNum;
            //            Sys_Stock.Instance.Insert(entity);

            //            //添加履历
            //            Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
            //            inRec.F_Id = Guid.NewGuid().ToString();
            //            inRec.F_WarehouseId = stockinfo[i].F_WarehouseId;
            //            inRec.F_WarehouseName = stockinfo[i].F_WarehouseName;
            //            inRec.F_GoodsName = stockinfo[i].F_GoodsName;
            //            inRec.F_GoodsId = stockinfo[i].F_GoodsId;
            //            inRec.F_CargoPositionId = stockinfo[i].F_CargoPositionId;
            //            inRec.F_CargoPositionName = stockinfo[i].F_CargoPositionName;
            //            inRec.F_SpecifModel = stockinfo[i].F_SpecifModel;
            //            inRec.F_SellingPrice = stockinfo[i].F_SellingPrice;
            //            inRec.F_PurchasePrice = stockinfo[i].F_PurchasePrice;
            //            inRec.F_Unit = stockinfo[i].F_Unit;
            //            inRec.F_InStockNum = stockinfo[i].F_InStockNum;
            //            inRec.F_CreatorTime = DateTime.Now;

            //            Sys_InRecords.Instance.Insert(inRec);

            //            //更新子表入库状态
            //            string upState = "update PI_Body set F_AlreadyOperatedNum='1' where F_Id='" + stockinfo[i].F_Id + "'";
            //            Hashtable hash = new Hashtable();
            //            base.ExecuteNonQuery(upState, hash);

            //            //更新主表入库状态
            //            string upStateH = "update PI_Head set F_State='1' where F_Id='" + stockinfo[i].F_HId + "'";
            //            Hashtable hash1 = new Hashtable();
            //            base.ExecuteNonQuery(upStateH, hash1);
            //        }
            //        //存在就更新库存
            //        else
            //        {
            //            //更新前库存数量
            //            int oldnum = int.Parse(this.GetDataTableBySql(sql).Rows[0][1].ToString());
            //            //要入库的数量
            //            int instockNum = stockinfo[i].F_InStockNum;
            //            //更新后库存数量
            //            int num = oldnum + instockNum;
            //            string Str = "update Sys_Stock set F_Number='" + num + "' where F_Id='" + this.GetDataTableBySql(sql).Rows[0][0].ToString() + "'";
            //            Hashtable hash = new Hashtable();
            //            base.ExecuteNonQuery(Str, hash);

            //            //更新子表入库状态
            //            string upState = "update PI_Body set F_AlreadyOperatedNum='1' where F_Id='" + stockinfo[i].F_Id + "'";
            //            Hashtable hash1 = new Hashtable();
            //            base.ExecuteNonQuery(upState, hash1);

            //            //更新主表入库状态
            //            string upStateH = "update PI_Head set F_State='1' where F_Id='" + stockinfo[i].F_HId + "'";
            //            Hashtable hash2 = new Hashtable();
            //            base.ExecuteNonQuery(upStateH, hash2);

            //            //添加履历
            //            Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
            //            inRec.F_Id = Guid.NewGuid().ToString();
            //            inRec.F_WarehouseId = stockinfo[i].F_WarehouseId;
            //            inRec.F_WarehouseName = stockinfo[i].F_WarehouseName;
            //            inRec.F_GoodsName = stockinfo[i].F_GoodsName;
            //            inRec.F_GoodsId = stockinfo[i].F_GoodsId;
            //            inRec.F_CargoPositionId = stockinfo[i].F_CargoPositionId;
            //            inRec.F_CargoPositionName = stockinfo[i].F_CargoPositionName;
            //            inRec.F_SpecifModel = stockinfo[i].F_SpecifModel;
            //            inRec.F_SellingPrice = stockinfo[i].F_SellingPrice;
            //            inRec.F_PurchasePrice = stockinfo[i].F_PurchasePrice;
            //            inRec.F_Unit = stockinfo[i].F_Unit;
            //            inRec.F_InStockNum = stockinfo[i].F_InStockNum;
            //            inRec.F_CreatorTime = DateTime.Now;
            //            Sys_InRecords.Instance.Insert(inRec);
            //        }
            //    }
            //    return "操作成功";
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
        }
Esempio n. 6
0
        public string SaveTra(Sys_TransferInfo info)
        {
            try
            {
                using (DbTransactionScope <Sys_TransferInfo> dbtran = base.CreateTransactionScope())
                {
                    int JNum = int.Parse(info.F_Number) - int.Parse(info.F_TransferNum);
                    if (JNum < 0)
                    {
                        return("该产品数量不足");
                    }
                    else
                    {
                        //减少库存数量
                        Hashtable has = new Hashtable();
                        this.ExecuteNonQuery(string.Format("update Sys_Stock set F_Number='{0}' where F_Id='{1}'", JNum, info.F_StockId), has);

                        //判断转移的货位是否存在此产品
                        string SelGoods = string.Format("select * from Sys_Stock where F_GoodsId='{0}' and F_WarehouseId='{1}'  and F_CargoPositionId='{2}'", info.F_GoodsId, info.F_TransferWarHouseId, info.F_TransferCargoId);
                        int    count    = this.GetDataTableBySql(SelGoods).Rows.Count;
                        if (count > 0)
                        {
                            //存在则添加库存
                            Hashtable hash            = new Hashtable();
                            string    UpStockGoodsNum = string.Format("update Sys_Stock set F_Number=F_Number+{0} where  F_GoodsId='{1}' and F_WarehouseId='{2}'  and F_CargoPositionId='{3}'", info.F_TransferNum, info.F_GoodsId, info.F_TransferWarHouseId, info.F_TransferCargoId);
                            this.ExecuteNonQuery(UpStockGoodsNum);
                            // 添加物品转移履历
                            Sys_Transfer.Instance.Insert(info);
                        }
                        else
                        {
                            //获取产品信息
                            DataTable dt = this.GetDataTableBySql("select F_Batch,F_ProDate,F_ExpiratDate,F_CategoryID,F_Unit,F_SellingPrice from Sys_Stock where F_Id='" + info.F_StockId + "'");
                            //否则添加产品
                            Sys_StockInfo StockInfo = new Sys_StockInfo();
                            StockInfo.F_Number            = int.Parse(info.F_TransferNum);
                            StockInfo.F_WarehouseId       = info.F_TransferWarHouseId;
                            StockInfo.F_WarehouseName     = info.F_TransferWarHouse;
                            StockInfo.F_GoodsId           = info.F_GoodsId;
                            StockInfo.F_GoodsName         = info.F_GoodsName;
                            StockInfo.F_CargoPositionId   = info.F_TransferCargoId;
                            StockInfo.F_CargoPositionName = info.F_TransferCargo;
                            StockInfo.F_EnCode            = info.F_EnCode;
                            StockInfo.F_Batch             = dt.Rows[0][0].ToString();
                            StockInfo.F_ProDate           = dt.Rows[0][1].ToString();
                            StockInfo.F_ExpiratDate       = dt.Rows[0][2].ToString();
                            StockInfo.F_CategoryID        = dt.Rows[0][3].ToString();
                            StockInfo.F_Unit          = dt.Rows[0][4].ToString();
                            StockInfo.F_SellingPrice  = dt.Rows[0][5].ToString();
                            StockInfo.F_CreatorTime   = DateTime.Now;
                            StockInfo.F_CreatorUserId = info.F_CreatorUserId;

                            BLLFactory <Sys_Stock> .Instance.Insert(StockInfo);

                            //添加物品转移履历
                            Sys_Transfer.Instance.Insert(info);
                        }
                    }
                    return("转移成功");
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Esempio n. 7
0
        /// <summary>
        ///审核单据
        /// </summary>
        /// <param name="date">审核日期</param>
        /// <param name="Id">审核单据</param>
        /// <param name="user">审核人</param>
        public string Audit(string date, string user, string Id, List <PI_BodyInfo> stockinfo)
        {
            string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + Id + "'";
            string AuditState  = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();

            if (AuditState == "1")
            {
                return("单据已被审核");
            }
            else
            {
                using (DbTransactionScope <PI_HeadInfo> dbtran = base.CreateTransactionScope())
                {
                    try
                    {
                        //查询所有库存信息
                        List <Sys_StockInfo> stockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                        //查询主表信息
                        PI_HeadInfo hinfo = BLLFactory <PI_Head> .Instance.FindByID(Id);


                        foreach (PI_BodyInfo item in stockinfo)
                        {
                            //判断是否入库
                            PI_BodyInfo binfo = BLLFactory <PI_Body> .Instance.FindByID(item.F_Id);

                            if (binfo.F_AlreadyOperatedNum == "")
                            {
                                binfo.F_AlreadyOperatedNum = "0";
                            }
                            if (int.Parse(binfo.F_AlreadyOperatedNum) > 0)
                            {
                                return("该单据已入库,不能重复执行入库操作");
                            }

                            if (binfo.F_WarehouseId == "" || binfo.F_CargoPositionId == "")
                            {
                                return("该单据中仓库或仓位为空,审核未通过");
                            }

                            Sys_StockInfo stock = stockList.Find(u => u.F_WarehouseId == binfo.F_WarehouseId && u.F_CargoPositionId == binfo.F_CargoPositionId && u.F_GoodsId == binfo.F_GoodsId && u.F_Batch == binfo.F_SerialNum);
                            if (stock == null)
                            {
                                item.IsHave = false;
                            }
                            else
                            {
                                item.IsHave      = true;
                                item.StockID     = stock.F_Id;
                                item.StockNumber = stock.F_Number;
                            }

                            //查询库存表是否存在该仓库中的产品
                            //没有
                            if (!item.IsHave)
                            {
                                //新添加一条数据 库存表
                                Sys_StockInfo entity = new Sys_StockInfo();
                                entity.F_Id = Guid.NewGuid().ToString();
                                entity.F_CargoPositionId   = item.F_CargoPositionId;
                                entity.F_CargoPositionName = item.F_CargoPositionName;
                                entity.F_WarehouseId       = item.F_WarehouseId;
                                entity.F_WarehouseName     = item.F_WarehouseName;
                                entity.F_GoodsName         = item.F_FullName;
                                entity.F_Batch             = item.F_SerialNum;
                                entity.F_GoodsId           = item.F_GoodsId;
                                entity.F_SpecifModel       = item.F_SpecifModel;
                                entity.F_SellingPrice      = item.F_SellingPrice;
                                entity.F_PurchasePrice     = item.F_PurchasePrice;
                                entity.F_Unit   = item.F_Unit;
                                entity.F_Number = item.F_InStockNum;
                                Sys_Stock.Instance.Insert(entity, dbtran.Transaction);

                                //更新审核状态
                                string    sql  = string.Format("update PI_Head set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                                Hashtable hash = new Hashtable();
                                base.ExecuteNonQuery(sql, hash, dbtran.Transaction);

                                //添加入库履历 入库履历
                                Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                                inRec.F_Id                = Guid.NewGuid().ToString();
                                inRec.F_WarehouseId       = item.F_WarehouseId;
                                inRec.F_Vendor            = hinfo.F_Vendor;
                                inRec.F_VendorName        = hinfo.F_VendorName;
                                inRec.F_Contacts          = hinfo.F_Contacts;
                                inRec.F_TelePhone         = hinfo.F_TelePhone;
                                inRec.F_Verify            = user;
                                inRec.F_Maker             = hinfo.F_Maker;
                                inRec.F_VeriDate          = DateTime.Now;
                                inRec.F_EnCode            = item.F_OrderNo;
                                inRec.F_Batch             = item.F_SerialNum;
                                inRec.F_WarehouseName     = item.F_WarehouseName;
                                inRec.F_GoodsName         = item.F_FullName;
                                inRec.F_GoodsId           = item.F_GoodsId;
                                inRec.F_CargoPositionId   = item.F_CargoPositionId;
                                inRec.F_CargoPositionName = item.F_CargoPositionName;
                                inRec.F_SpecifModel       = item.F_SpecifModel;
                                inRec.F_SellingPrice      = item.F_SellingPrice;
                                inRec.F_PurchasePrice     = item.F_PurchasePrice;
                                inRec.F_Unit              = item.F_Unit;
                                inRec.F_InStockNum        = item.F_InStockNum;
                                inRec.F_CreatorTime       = DateTime.Now;
                                Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);



                                //添加  库存履历
                                Sys_StockHistoryInfo instock = new Sys_StockHistoryInfo();
                                instock.F_Id                = Guid.NewGuid().ToString();
                                instock.F_WarehouseId       = item.F_WarehouseId;
                                instock.F_Vendor            = hinfo.F_Vendor;
                                instock.F_VendorName        = hinfo.F_VendorName;
                                instock.F_Contacts          = hinfo.F_Contacts;
                                instock.F_TelePhone         = hinfo.F_TelePhone;
                                instock.F_Verify            = user;
                                instock.F_Maker             = hinfo.F_Maker;
                                instock.F_VeriDate          = DateTime.Now;
                                instock.F_EnCode            = item.F_OrderNo;
                                instock.F_Batch             = item.F_SerialNum;
                                instock.F_WarehouseName     = item.F_WarehouseName;
                                instock.F_BllCategory       = "入库";
                                instock.F_GoodsName         = item.F_FullName;
                                instock.F_GoodsId           = item.F_GoodsId;
                                instock.F_CargoPositionId   = item.F_CargoPositionId;
                                instock.F_CargoPositionName = item.F_CargoPositionName;
                                instock.F_SpecifModel       = item.F_SpecifModel;
                                instock.F_SellingPrice      = item.F_SellingPrice;
                                instock.F_PurchasePrice     = item.F_PurchasePrice;
                                instock.F_Unit              = item.F_Unit;
                                instock.F_OperationNum      = item.F_InStockNum;
                                instock.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instock, dbtran.Transaction);



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

                                //更新主表入库状态
                                hash = new Hashtable();
                                hash.Add("F_State", 1);
                                PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);
                            }
                            else
                            {
                                //更新前库存数量
                                Hashtable hash = new Hashtable();
                                hash.Add("F_Number", item.StockNumber + item.F_InStockNum);
                                Sys_Stock.Instance.Update(item.StockID, hash, dbtran.Transaction);
                                for (int i = 0; i < stockinfo.Count; i++)
                                {
                                    if (stockinfo[i].StockID == item.StockID)
                                    {
                                        stockinfo[i].StockNumber += item.F_InStockNum;
                                    }
                                }

                                //更新审核状态
                                string sql = string.Format("update PI_Head set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                                hash = new Hashtable();
                                base.ExecuteNonQuery(sql, hash, dbtran.Transaction);

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

                                //更新主表入库状态
                                hash = new Hashtable();
                                hash.Add("F_State", 1);
                                PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);


                                //添加履历
                                Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                                inRec.F_Id                = Guid.NewGuid().ToString();
                                inRec.F_WarehouseId       = item.F_WarehouseId;
                                inRec.F_EnCode            = item.F_OrderNo;
                                inRec.F_Batch             = item.F_SerialNum;
                                inRec.F_Vendor            = hinfo.F_Vendor;
                                inRec.F_VendorName        = hinfo.F_VendorName;
                                inRec.F_Contacts          = hinfo.F_Contacts;
                                inRec.F_TelePhone         = hinfo.F_TelePhone;
                                inRec.F_Verify            = user;
                                inRec.F_Maker             = hinfo.F_Maker;
                                inRec.F_VeriDate          = DateTime.Now;
                                inRec.F_WarehouseName     = item.F_WarehouseName;
                                inRec.F_GoodsName         = item.F_FullName;
                                inRec.F_GoodsId           = item.F_GoodsId;
                                inRec.F_CargoPositionId   = item.F_CargoPositionId;
                                inRec.F_CargoPositionName = item.F_CargoPositionName;
                                inRec.F_SpecifModel       = item.F_SpecifModel;
                                inRec.F_SellingPrice      = item.F_SellingPrice;
                                inRec.F_PurchasePrice     = item.F_PurchasePrice;
                                inRec.F_Unit              = item.F_Unit;
                                inRec.F_InStockNum        = item.F_InStockNum;
                                inRec.F_CreatorTime       = DateTime.Now;
                                Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);

                                //添加库存履历
                                Sys_StockHistoryInfo instock = new Sys_StockHistoryInfo();
                                instock.F_Id                = Guid.NewGuid().ToString();
                                instock.F_WarehouseId       = item.F_WarehouseId;
                                instock.F_EnCode            = item.F_OrderNo;
                                instock.F_Batch             = item.F_SerialNum;
                                instock.F_Vendor            = hinfo.F_Vendor;
                                instock.F_VendorName        = hinfo.F_VendorName;
                                instock.F_Contacts          = hinfo.F_Contacts;
                                instock.F_TelePhone         = hinfo.F_TelePhone;
                                instock.F_Verify            = user;
                                instock.F_Maker             = hinfo.F_Maker;
                                instock.F_VeriDate          = DateTime.Now;
                                instock.F_WarehouseName     = item.F_WarehouseName;
                                instock.F_BllCategory       = "入库";
                                instock.F_GoodsName         = item.F_FullName;
                                instock.F_GoodsId           = item.F_GoodsId;
                                instock.F_CargoPositionId   = item.F_CargoPositionId;
                                instock.F_CargoPositionName = item.F_CargoPositionName;
                                instock.F_SpecifModel       = item.F_SpecifModel;
                                instock.F_SellingPrice      = item.F_SellingPrice;
                                instock.F_PurchasePrice     = item.F_PurchasePrice;
                                instock.F_Unit              = item.F_Unit;
                                instock.F_OperationNum      = item.F_InStockNum;
                                instock.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instock, dbtran.Transaction);
                            }
                        }
                        dbtran.Commit();
                        return("单据审核成功");
                    }
                    catch (Exception ex)
                    {
                        dbtran.RollBack();
                        return("操作失败");

                        throw ex;
                    }
                }
            }
        }
Esempio n. 8
0
        public string VerifyReturnGoods(string Id, string user)
        {
            using (DbTransactionScope <SO_ReturnedStockHeadInfo> dbtran = base.CreateTransactionScope())
            {
                try
                {
                    DateTime time = DateTime.Now;
                    //查询到退货子表单据
                    SO_ReturnedStockHeadInfo HeadInfo = BLLFactory <SO_ReturnedStockHead> .Instance.FindByID(Id);

                    SearchCondition search = new SearchCondition();
                    search.AddCondition("F_Hid", Id, SqlOperator.Equal);
                    List <SO_ReturnedStockBodyInfo> ReBodyinfo = BLLFactory <SO_ReturnedStockBody> .Instance.Find(search.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty).Replace("Where (1=1)", " ( 1 = 1 ) "));

                    //查询出所有产品的库存
                    List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                    //添加库存记录
                    List <Sys_StockHistoryInfo> HisList = new List <Sys_StockHistoryInfo>();
                    //添加出库记录
                    List <Sys_OutReturnInfo> list = new List <Sys_OutReturnInfo>();
                    //更新 产品库存
                    foreach (SO_ReturnedStockBodyInfo item in ReBodyinfo)
                    {
                        Sys_StockInfo StockInfo = StockList.Find(u => u.F_WarehouseId == item.F_WarehouseId && u.F_CargoPositionId == item.F_CargoPositionId && u.F_GoodsId == item.F_GoodsId);
                        Hashtable     hash      = new Hashtable();
                        hash.Add("F_Number", StockInfo.F_Number + item.F_ReturnNum);
                        Sys_Stock.Instance.Update(StockInfo.F_Id, hash, dbtran.Transaction);


                        Sys_OutReturnInfo outRec = new Sys_OutReturnInfo();
                        outRec.F_Id                = Guid.NewGuid().ToString();
                        outRec.F_EnCode            = HeadInfo.F_EnCode;
                        outRec.F_Batch             = item.F_EnCode;
                        outRec.F_Vendor            = HeadInfo.F_CustomerId;
                        outRec.F_VendorName        = HeadInfo.F_CustomerName;
                        outRec.F_Verify            = user;
                        outRec.F_Maker             = HeadInfo.F_Operator;
                        outRec.F_Contacts          = HeadInfo.F_Contacts;
                        outRec.F_TelePhone         = HeadInfo.F_TelePhone;
                        outRec.F_Address           = HeadInfo.F_Address;
                        outRec.F_VeriDate          = time;
                        outRec.F_WarehouseId       = item.F_WarehouseId;
                        outRec.F_WarehouseName     = item.F_WarehouseName;
                        outRec.F_GoodsName         = item.F_GoodsName;
                        outRec.F_GoodsId           = item.F_GoodsId;
                        outRec.F_CargoPositionId   = item.F_CargoPositionId;
                        outRec.F_CargoPositionName = item.F_CargoPositionName;
                        outRec.F_SpecifModel       = item.F_SpecifModel;
                        outRec.F_SellingPrice      = item.F_SellingPrice.ToString();
                        outRec.F_PurchasePrice     = item.F_PurchasePrice.ToString();
                        outRec.F_Unit              = item.F_Unit;
                        outRec.F_OutStockNum       = item.F_OutStockNum;
                        outRec.F_ReturnNum         = item.F_ReturnNum;
                        outRec.F_CreatorTime       = time;
                        list.Add(outRec);


                        //产品库存变更信息
                        Sys_StockHistoryInfo HistoryInfo = new Sys_StockHistoryInfo();
                        HistoryInfo.F_CargoPositionId   = item.F_CargoPositionId;
                        HistoryInfo.F_CargoPositionName = item.F_CargoPositionName;
                        HistoryInfo.F_GoodsName         = item.F_GoodsName;
                        HistoryInfo.F_Batch             = item.F_Batch;
                        HistoryInfo.F_WarehouseId       = item.F_WarehouseId;
                        HistoryInfo.F_WarehouseName     = item.F_WarehouseName;
                        HistoryInfo.F_BllCategory       = "出库退回";
                        HistoryInfo.F_OperationNum      = item.F_ReturnNum;
                        HistoryInfo.F_VendorName        = HeadInfo.F_CustomerName;
                        HistoryInfo.F_Contacts          = HeadInfo.F_Contacts;
                        HistoryInfo.F_TelePhone         = HeadInfo.F_TelePhone;
                        HistoryInfo.F_Address           = HeadInfo.F_Address;
                        HistoryInfo.F_Maker             = HeadInfo.F_Operator;
                        HistoryInfo.F_Verify            = HeadInfo.F_AuditingUser;
                        HistoryInfo.F_VeriDate          = time;
                        HistoryInfo.F_Unit        = item.F_Unit;
                        HistoryInfo.F_CreatorTime = time;
                        HistoryInfo.F_Description = HeadInfo.F_Description;
                        HistoryInfo.F_EnCode      = HeadInfo.F_EnCode;
                        HisList.Add(HistoryInfo);
                    }
                    Sys_OutReturn.Instance.InsertRange(list, dbtran.Transaction);
                    Sys_StockHistory.Instance.InsertRange(HisList, dbtran.Transaction);
                    //更该审核标识
                    Hashtable has = new Hashtable();
                    has.Add("F_AuditingUser", user);
                    has.Add("F_VeriDate", time);
                    has.Add("F_Status", 1);
                    SO_ReturnedStockHead.Instance.Update(Id, has, dbtran.Transaction);
                    dbtran.Commit();
                    return("操作成功");
                }
                catch (Exception)
                {
                    dbtran.RollBack();
                    return("操作失败");
                }
            }
        }
Esempio n. 9
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;
                }
            }
        }