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_adjust"; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( Util.HasMoreRow(ds) ) throw new BizException("the table adjust 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.adjustid, stock_con.newsysno as stocksysno, create_con.newsysno as createusersysno, audit_con.newsysno as auditusersysno, audit_con.newsysno as outusersysno, createtime, audittime,audittime as outtime, auditstatus, note, '1' as status from ipp2003..st_adjust as old, ippconvert..sys_user as create_con, ippconvert..sys_user as audit_con, ippconvert..stock as stock_con where old.createusersysno *= create_con.oldsysno and old.auditusersysno *= audit_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 audit * abandon -1 * origin 0 * verified 1 */ int newStatus = (int)AppEnum.AdjustStatus.Origin; int auditStatus = Util.TrimIntNull(dr["auditStatus"]); if ( auditStatus == -1 ) newStatus = (int)AppEnum.AdjustStatus.Abandon; else if ( auditStatus == 0 ) newStatus = (int)AppEnum.AdjustStatus.Origin; else if ( auditStatus == 1) newStatus = (int)AppEnum.AdjustStatus.OutStock; else throw new BizException("old adjust status out of range"); AdjustInfo oInfo = new AdjustInfo(); map(oInfo, dr); oInfo.Status = newStatus; if ( new AdjustDac().ImportMaster(oInfo)!= 1) { throw new BizException("master expected one row error"); } //insert item string sql_item = @"select '0' as sysno, AdjustSysNo, con_product.newsysno as productsysno, adjustqty, adjustcost from ipp2003..St_Adjust_Item sti, ippconvert..productbasic as con_product where sti.productsysno = con_product.oldsysno and AdjustSysNo=" + oInfo.SysNo; DataSet ds_item = SqlHelper.ExecuteDataSet(sql_item); if ( !Util.HasMoreRow(ds_item) ) continue; foreach(DataRow drItem in ds_item.Tables[0].Rows) { AdjustItemInfo oItem = new AdjustItemInfo(); map(oItem, drItem); if ( oItem.AdjustCost == 0 ) oItem.AdjustCost = AppConst.IntNull; int resultitem = new AdjustDac().InsertItem(oItem); if ( resultitem < 1 ) throw new BizException("insert item row < 1"); //������� if ( oInfo.Status == (int)AppEnum.AdjustStatus.Origin && oItem.AdjustQty < 0 ) { InventoryManager.GetInstance().SetAvailableQty(oInfo.StockSysNo, oItem.ProductSysNo, -1*oItem.AdjustQty); } } } string sqlMaxSysNo = "select top 1 sysno from ipp2003..st_adjust 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_Adjust_Sequence"); } while( newSysNo < maxSysNo); scope.Complete(); } }
public void Create(AdjustInfo 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_Adjust_Sequence"); oParam.AdjustID = getAdjustID(oParam.SysNo); //���������¼ int rowsAffected = new AdjustDac().InsertMaster(oParam); if(rowsAffected != 1) throw new BizException("insert adjust master error"); foreach( AdjustItemInfo item in oParam.itemHash.Values) { item.AdjustSysNo = oParam.SysNo; rowsAffected = new AdjustDac().InsertItem(item); if ( rowsAffected != 1) throw new BizException("insert adjust item error"); if ( item.AdjustQty < 0 ) {//��Ҫռ�ÿ�� InventoryManager.GetInstance().SetAvailableQty(oParam.StockSysNo, item.ProductSysNo, -1*item.AdjustQty); } } scope.Complete(); } }