public void Create(LendInfo oParam) { TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { oParam.SysNo = SequenceDac.GetInstance().Create("St_Lend_Sequence"); oParam.LendID = getLendID(oParam.SysNo); //建立主表记录 int rowsAffected = new LendDac().InsertMaster(oParam); if (rowsAffected != 1) { throw new BizException("insert lend master error"); } foreach (LendItemInfo item in oParam.itemHash.Values) { item.LendSysNo = oParam.SysNo; rowsAffected = new LendDac().InsertItem(item); if (rowsAffected != 1) { throw new BizException("insert lend item error"); } InventoryManager.GetInstance().SetAvailableQty(oParam.StockSysNo, item.ProductSysNo, item.LendQty); } scope.Complete(); } }
public void Import() { /* 涉及的问题 * 1 还货记录的处理 * 2 库存的处理 * 3 状态的处理 * 4 还有单据id的对应,这个要特别注意 */ if (!AppConfig.IsImportable) { throw new BizException("Is Importable is false"); } string sql = " select top 1 sysno from st_lend"; DataSet ds = SqlHelper.ExecuteDataSet(sql); if (Util.HasMoreRow(ds)) { throw new BizException("the table lend is not empty"); } TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { string sql_old = @"select old.sysno, old.lendid, stock_con.newsysno as stocksysno, lender_con.newsysno as lendusersysno, create_con.newsysno as createusersysno, audit_con.newsysno as auditusersysno, out_con.newsysno as outusersysno, createtime, audittime,outstocktime as outtime, productstatus, auditstatus, memo as note, '1' as status from ipp2003..st_lend as old, ippconvert..sys_user as lender_con, ippconvert..sys_user as create_con, ippconvert..sys_user as audit_con, ippconvert..sys_user as out_con, ippconvert..stock as stock_con where old.employeesysno = lender_con.oldsysno and old.createusersysno = create_con.oldsysno and old.auditusersysno = audit_con.oldsysno and old.outstockusersysno = out_con.oldsysno and old.stocksysno = stock_con.oldsysno order by old.sysno" ; DataSet ds_old = SqlHelper.ExecuteDataSet(sql_old); if (!Util.HasMoreRow(ds_old)) { return; } foreach (DataRow dr in ds_old.Tables[0].Rows) { /* newStatus aduit product * abandon -1 n/a * origin 0 n/a * verified 1 n/a * outstock n/a 1 * returnpartly n/a 2 * returnall n/a 3 */ int newStatus = (int)AppEnum.LendStatus.Origin; int auditStatus = Util.TrimIntNull(dr["auditStatus"]); int productStatus = Util.TrimIntNull(dr["productStatus"]); if (auditStatus == -1) { newStatus = (int)AppEnum.LendStatus.Abandon; } if (auditStatus == 0) { newStatus = (int)AppEnum.LendStatus.Origin; } if (auditStatus == 1) { newStatus = (int)AppEnum.LendStatus.Verified; } if (productStatus == 1) { newStatus = (int)AppEnum.LendStatus.OutStock; } if (productStatus == 2) { newStatus = (int)AppEnum.LendStatus.ReturnPartly; } if (productStatus == 3) { newStatus = (int)AppEnum.LendStatus.ReturnAll; } LendInfo oInfo = new LendInfo(); map(oInfo, dr); oInfo.Status = newStatus; if (new LendDac().ImportMaster(oInfo) != 1) { throw new BizException("master expected one row error"); } //insert item string sql_item = @"select '0' as sysno, LendSysNo, con_product.newsysno as productsysno, lendqty, returnqty, restoretime as ExpectReturnTime from ipp2003..St_Lend_Item sli, ippconvert..productbasic as con_product where sli.productsysno = con_product.oldsysno and LendSysNo=" + oInfo.SysNo; DataSet ds_item = SqlHelper.ExecuteDataSet(sql_item); if (!Util.HasMoreRow(ds_item)) { continue; } foreach (DataRow drItem in ds_item.Tables[0].Rows) { LendItemInfo oItem = new LendItemInfo(); map(oItem, drItem); int resultitem = new LendDac().InsertItem(oItem); if (resultitem < 1) { throw new BizException("insert item row < 1"); } if (Util.TrimIntNull(drItem["returnqty"]) != 0) { LendReturnInfo oReturn = new LendReturnInfo(); oReturn.LendSysNo = oItem.LendSysNo; oReturn.ProductSysNo = oItem.ProductSysNo; oReturn.ReturnTime = oInfo.OutTime.AddDays(30); oReturn.ReturnQty = Util.TrimIntNull(drItem["returnqty"]); int resultReturn = new LendDac().InsertReturn(oReturn); if (resultReturn != 1) { throw new BizException("return item one-row expected error"); } } if (oItem.LendQty - Util.TrimIntNull(drItem["returnqty"]) != 0) { InventoryManager.GetInstance().SetImportLendQty(oInfo.StockSysNo, oItem.ProductSysNo, oItem.LendQty - Util.TrimIntNull(drItem["returnqty"])); } //调整库存 if (oInfo.Status == (int)AppEnum.LendStatus.Origin || oInfo.Status == (int)AppEnum.LendStatus.Verified) { InventoryManager.GetInstance().SetAvailableQty(oInfo.StockSysNo, oItem.ProductSysNo, oItem.LendQty); } } } string sqlMaxSysNo = "select top 1 sysno from ipp2003..st_lend order by sysno desc"; DataSet dsMax = SqlHelper.ExecuteDataSet(sqlMaxSysNo); if (!Util.HasMoreRow(dsMax)) { throw new BizException("got max sysno error"); } int maxSysNo = Util.TrimIntNull(dsMax.Tables[0].Rows[0]["sysno"]); // 将自动生成的sysno填到目前的最大单据号 int newSysNo; do { newSysNo = SequenceDac.GetInstance().Create("St_Lend_Sequence"); } while(newSysNo < maxSysNo); scope.Complete(); } }