//自动生成出入库单
        public int PostBuild(string billCode, out string msg)
        {
            msg = string.Empty;
            var    rowsAffected = 0;
            string sql          = String.Format(@"    select MAX(t1.BillState) as BillState,t2.WarehouseCode,max(t2.WarehouseName) as WarehouseName,t2.InventoryCode,max(t2.InventoryName) as InventoryName,sum(t2.DValue) as DValue from WMS_BN_TakeStockMain as t1
inner join WMS_BN_TakeStockDetail as t2 on t1.BillCode=t2.BillCode where t1.BillCode='{0}' 
group by t2.WarehouseCode,t2.Inventorycode", billCode);
            var    list         = db.Sql(sql).QueryMany <dynamic>();
            var    res          = list[1].DValue;

            if (list[0].BillState == 2)
            {
                msg = "已锁定的数据不能重复提交!";
                return(0);
            }
            db.UseTransaction(true);
            foreach (var item in list)
            {
                res = item.DValue;
                WMS_BN_BillMain master = new WMS_BN_BillMain();
                if (item.DValue > 0)
                {
                    master.BillType      = 6;
                    master.WarehouseCode = item.WarehouseCode;
                    master.WarehouseName = item.WarehouseName;
                    master.Remark        = "盘盈入库";
                }
                else if (item.DValue < 0)
                {
                    master.BillType      = 7;
                    master.WarehouseCode = item.WarehouseCode;
                    master.WarehouseName = item.WarehouseName;
                    master.Remark        = "盘亏出库";
                }
                else
                {
                    continue;
                }
                var sc = new sys_codeService().Getsys_codeByTypeAndID("BillType", Convert.ToInt16(master.BillType));
                master.BillCode     = MmsHelper.GetOrderNumber("WMS_BN_BillMain", "BillCode", sc.Description, "", "");
                master.CreateTime   = DateTime.Now;
                master.CreatePerson = MmsHelper.GetUserName();

                rowsAffected = db.Sql(@"insert into WMS_BN_BillMain (BillCode,BillType,WarehouseCode,WarehouseName,Remark,
CreatePerson,CreateTime) values(@0,@1,@2,@3,@4,@5,@6)", master.BillCode, master.BillType,
                                      master.WarehouseCode, master.WarehouseName, master.Remark, master.CreatePerson, master.CreateTime).Execute();
                if (rowsAffected < 0)
                {
                    db.Rollback();
                    return(rowsAffected);
                }

                var detailList = (from p in list where p.WarehouseCode == item.WarehouseCode select p).ToList();
                foreach (var it in detailList)
                {
                    WMS_BN_BillDetail detail = new WMS_BN_BillDetail();
                    detail.PBillCode     = billCode;
                    detail.BillCode      = master.BillCode;
                    detail.InventoryCode = it.InventoryCode;
                    detail.InventoryName = it.InventoryName;

                    detail.MateNum    = Math.Abs(item.DValue);
                    detail.ConfirmNum = Math.Abs(item.DValue);

                    rowsAffected = db.Insert <WMS_BN_BillDetail>("WMS_BN_BillDetail", detail)
                                   .AutoMap(x => x.ID)
                                   .Execute();
                    if (rowsAffected < 0)
                    {
                        db.Rollback();
                        return(rowsAffected);
                    }
                }
            }
            sql          = string.Format(@"update WMS_BN_TakeStockMain set BillState='2' where BillCode='{0}'", billCode);
            rowsAffected = db.Sql(sql).Execute();

            if (rowsAffected < 0)
            {
                db.Rollback();
                return(rowsAffected);
            }
            msg = "操作成功!";
            db.Commit();

            return(rowsAffected);
        }
Exemple #2
0
        public int PostBuild(string billCode, out string msg)
        {
            msg = string.Empty;
            int rowsAffected = 0;

            db.UseTransaction(true);
            string sql  = string.Format(@"select a.BillCode,a.Remark, a.InWarehouseCode,a.InWarehouseName,a.OutWarehouseCode,a.OutWarehouseName,
b.InventoryCode,b.InventoryName,b.ConfirmNum,b.Unit from WMS_BN_TransfersMain a
 left join WMS_BN_TransfersDetail b on a.BillCode=b.BillCode where a.IsEnable=1 and
b.IsEnable=1 and b.BillCode='{0}'", billCode);
            var    list = db.Sql(sql).QueryMany <dynamic>();

            if (list.Count <= 0)
            {
                msg = "没有数据!";
                return(0);
            }
            //foreach (var item in list)
            //{
            WMS_BN_BillMain master = new WMS_BN_BillMain();
            var             sc     = new sys_codeService().Getsys_codeByTypeAndID("BillType", 7);

            master.BillCode      = MmsHelper.GetOrderNumber("WMS_BN_BillMain", "BillCode", sc.Description, "", "");
            master.BillType      = 7;
            master.WarehouseCode = list[0].OutWarehouseCode;
            master.WarehouseName = list[0].OutWarehouseName;
            master.Remark        = list[0].Remark;
            master.CreateTime    = DateTime.Now;
            master.CreatePerson  = MmsHelper.GetUserName();
            master.ApproveState  = "1";

            rowsAffected = db.Sql(@"insert into WMS_BN_BillMain (ID,BillCode,BillType,WarehouseCode,WarehouseName,Remark,ApproveState,
CreatePerson,CreateTime) values(((select MAX(id)+1 from WMS_BN_BillMain)),@0,@1,@2,@3,@4,@5,@6,@7)", master.BillCode, master.BillType,
                                  master.WarehouseCode, master.WarehouseName, master.Remark, master.ApproveState, master.CreatePerson, master.CreateTime).Execute();
            if (rowsAffected < 0)
            {
                db.Rollback();
                return(rowsAffected);
            }
            //var detailList = (from p in list where p.OutWarehouseID == item.OutWarehouseID select p).ToList();
            //var detailList = (from p in list where p.OutWarehouseID == item.OutWarehouseID select p).ToList();

            foreach (var it in list)
            {
                WMS_BN_BillDetail detail = new WMS_BN_BillDetail();
                detail.PBillCode     = billCode;
                detail.BillCode      = master.BillCode;
                detail.InventoryCode = it.InventoryCode;
                detail.InventoryName = it.InventoryName;

                detail.MateNum    = it.ConfirmNum;
                detail.ConfirmNum = it.ConfirmNum;

                rowsAffected = db.Insert <WMS_BN_BillDetail>("WMS_BN_BillDetail", detail)
                               .AutoMap(x => x.ID)
                               .Execute();
                if (rowsAffected < 0)
                {
                    db.Rollback();
                    return(rowsAffected);
                }
            }

            sc = new sys_codeService().Getsys_codeByTypeAndID("BillType", 6);
            master.BillCode      = MmsHelper.GetOrderNumber("WMS_BN_BillMain", "BillCode", sc.Description, "", "");
            master.BillType      = 6;
            master.WarehouseCode = list[0].InWarehouseCode;
            master.WarehouseName = list[0].InWarehouseName;
            master.Remark        = list[0].Remark;
            master.CreateTime    = DateTime.Now;
            master.CreatePerson  = MmsHelper.GetUserName();
            master.ApproveState  = "1";
            rowsAffected         = db.Sql(@"insert into WMS_BN_BillMain (ID,BillCode,BillType,WarehouseCode,WarehouseName,Remark,ApproveState,
CreatePerson,CreateTime) values(((select MAX(id)+1 from WMS_BN_BillMain)),@0,@1,@2,@3,@4,@5,@6,@7)", master.BillCode, master.BillType,
                                          master.WarehouseCode, master.WarehouseName, master.Remark, master.ApproveState, master.CreatePerson, master.CreateTime).Execute();
            if (rowsAffected < 0)
            {
                db.Rollback();
                return(rowsAffected);
            }
            //detailList = (from p in list where p.InWarehouseID == item.InWarehouseID select p).ToList();
            foreach (var it in list)
            {
                WMS_BN_BillDetail detail = new WMS_BN_BillDetail();
                detail.PBillCode     = billCode;
                detail.BillCode      = master.BillCode;
                detail.InventoryCode = it.InventoryCode;
                detail.InventoryName = it.InventoryName;

                detail.MateNum    = it.ConfirmNum;
                detail.ConfirmNum = it.ConfirmNum;

                rowsAffected = db.Insert <WMS_BN_BillDetail>("WMS_BN_BillDetail", detail)
                               .AutoMap(x => x.ID)
                               .Execute();
                if (rowsAffected < 0)
                {
                    db.Rollback();
                    return(rowsAffected);
                }
            }
            //}
            sql          = string.Format(@"update WMS_BN_TransfersMain set ApproveState='2',ApprovePerson='{0}',ApproveTime='{1}' where BillCode='{2}'", MmsHelper.GetUserName(), DateTime.Now, billCode);
            rowsAffected = db.Sql(sql).Execute();

            if (rowsAffected < 0)
            {
                db.Rollback();
                return(rowsAffected);
            }
            msg = "操作成功!";
            db.Commit();

            return(rowsAffected);
        }