Example #1
0
        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_transfer";
            DataSet ds = SqlHelper.ExecuteDataSet(sql);
            if ( Util.HasMoreRow(ds) )
                throw new BizException("the table transfer 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.transferid, 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_transfer 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.TransferStatus.Origin;
                    int auditStatus = Util.TrimIntNull(dr["auditStatus"]);
                    if ( auditStatus == -1 )
                        newStatus = (int)AppEnum.TransferStatus.Abandon;
                    else if ( auditStatus == 0 )
                        newStatus = (int)AppEnum.TransferStatus.Origin;
                    else if ( auditStatus == 1)
                        newStatus = (int)AppEnum.TransferStatus.OutStock;
                    else
                        throw new BizException("old transfer status out of range");

                    TransferInfo  oInfo = new TransferInfo();
                    map(oInfo, dr);
                    oInfo.Status = newStatus;

                    if ( new TransferDac().InsertMaster(oInfo)!= 1)
                    {
                        throw new BizException("master expected one row error");
                    }

                    //insert item
                    string sql_item = @"select '0' as sysno,
                                        TransferSysNo, con_product.newsysno as productsysno, transferqty, transfercost, transferstatus as transfertype
                                    from
                                        ipp2003..St_Transfer_Item sti, ippconvert..productbasic as con_product
                                    where sti.productsysno = con_product.oldsysno and TransferSysNo=" + oInfo.SysNo;

                    DataSet ds_item = SqlHelper.ExecuteDataSet(sql_item);
                    if ( !Util.HasMoreRow(ds_item) )
                        continue;
                    foreach(DataRow drItem in ds_item.Tables[0].Rows)
                    {
                        TransferItemInfo oItem = new TransferItemInfo();
                        map(oItem, drItem);

                        if ( oItem.TransferCost == 0 )
                            oItem.TransferCost = AppConst.IntNull;

                        int resultitem = new TransferDac().InsertItem(oItem);
                        if ( resultitem < 1 )
                            throw new BizException("insert item row < 1");

                        if ( oInfo.Status == (int)AppEnum.TransferStatus.Origin && oItem.TransferType == (int)AppEnum.TransferItemType.Source )
                        {
                            InventoryManager.GetInstance().SetAvailableQty(oInfo.StockSysNo, oItem.ProductSysNo, oItem.TransferQty);
                        }
                    }
                }

                string sqlMaxSysNo = "select top 1 sysno from ipp2003..st_transfer 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_Transfer_Sequence");
                } while( newSysNo < maxSysNo);

            scope.Complete();
            }
        }
Example #2
0
        public void Create(TransferInfo 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_Transfer_Sequence");
                oParam.TransferID = getTransferID(oParam.SysNo);
                //���������¼
                int rowsAffected = new TransferDac().InsertMaster(oParam);
                if(rowsAffected != 1)
                    throw new BizException("insert transfer master error");
                foreach( TransferItemInfo item in oParam.itemHash.Values)
                {
                    item.TransferSysNo = oParam.SysNo;

                    //����source�ijɱ�
                    if ( item.TransferType == (int)AppEnum.TransferItemType.Source)
                    {
                        ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(item.ProductSysNo);
                        item.TransferCost = priceInfo.UnitCost;
                    }

                    rowsAffected = new TransferDac().InsertItem(item);
                    if ( rowsAffected != 1)
                        throw new BizException("insert transfer item error");
                    if ( item.TransferType == (int)AppEnum.TransferItemType.Source )
                    {//��Ҫռ�ÿ��
                        InventoryManager.GetInstance().SetAvailableQty(oParam.StockSysNo, item.ProductSysNo, item.TransferQty);
                    }

                }

                scope.Complete();
            }
        }