Exemple #1
0
        public int InsertItem(TransferItemInfo oParam)
        {
            string sql = @"INSERT INTO St_Transfer_Item
                            (
                            TransferSysNo, ProductSysNo, TransferType,
                            TransferQty, TransferCost
                            )
                            VALUES (
                            @TransferSysNo, @ProductSysNo, @TransferType,
                            @TransferQty, @TransferCost
                            );set @SysNo = SCOPE_IDENTITY();";
            SqlCommand cmd = new SqlCommand(sql);

            SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
            SqlParameter paramTransferSysNo = new SqlParameter("@TransferSysNo", SqlDbType.Int,4);
            SqlParameter paramProductSysNo = new SqlParameter("@ProductSysNo", SqlDbType.Int,4);
            SqlParameter paramTransferType = new SqlParameter("@TransferType", SqlDbType.Int,4);
            SqlParameter paramTransferQty = new SqlParameter("@TransferQty", SqlDbType.Int,4);
            SqlParameter paramTransferCost = new SqlParameter("@TransferCost", SqlDbType.Decimal,9);

            paramSysNo.Direction = ParameterDirection.Output;

            if ( oParam.TransferSysNo != AppConst.IntNull)
                paramTransferSysNo.Value = oParam.TransferSysNo;
            else
                paramTransferSysNo.Value = System.DBNull.Value;
            if ( oParam.ProductSysNo != AppConst.IntNull)
                paramProductSysNo.Value = oParam.ProductSysNo;
            else
                paramProductSysNo.Value = System.DBNull.Value;
            if ( oParam.TransferType != AppConst.IntNull)
                paramTransferType.Value = oParam.TransferType;
            else
                paramTransferType.Value = System.DBNull.Value;
            if ( oParam.TransferQty != AppConst.IntNull)
                paramTransferQty.Value = oParam.TransferQty;
            else
                paramTransferQty.Value = System.DBNull.Value;
            if ( oParam.TransferCost != AppConst.DecimalNull)
                paramTransferCost.Value = oParam.TransferCost;
            else
                paramTransferCost.Value = System.DBNull.Value;

            cmd.Parameters.Add(paramSysNo);
            cmd.Parameters.Add(paramTransferSysNo);
            cmd.Parameters.Add(paramProductSysNo);
            cmd.Parameters.Add(paramTransferType);
            cmd.Parameters.Add(paramTransferQty);
            cmd.Parameters.Add(paramTransferCost);

            return SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo);
        }
Exemple #2
0
 private void map(TransferItemInfo oParam, DataRow tempdr)
 {
     oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]);
     oParam.TransferSysNo = Util.TrimIntNull(tempdr["TransferSysNo"]);
     oParam.ProductSysNo = Util.TrimIntNull(tempdr["ProductSysNo"]);
     oParam.TransferType = Util.TrimIntNull(tempdr["TransferType"]);
     oParam.TransferQty = Util.TrimIntNull(tempdr["TransferQty"]);
     oParam.TransferCost = Util.TrimDecimalNull(tempdr["TransferCost"]);
 }
Exemple #3
0
        /// <summary>
        /// ���������ͳɱ�
        /// �����souce�� �ɱ��ӵ�ǰ���ݿ�����ȡ
        /// </summary>
        /// <param name="masterInfo"></param>
        /// <param name="itemInfo"></param>
        public void UpdateItem(TransferInfo masterInfo, TransferItemInfo itemInfo)
        {
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {

                //�����dz�ʼ
                if ( getCurrentStatus(masterInfo.SysNo) != (int)AppEnum.TransferStatus.Origin )
                    throw new BizException("status is not origin now,  update item qty failed");

                //��ȡ������ֵ
                TransferItemInfo oldItemInfo = masterInfo.itemHash[itemInfo.ProductSysNo] as TransferItemInfo;
                int deltQty = itemInfo.TransferQty - oldItemInfo.TransferQty;

                //���±����ϸ ( ������ӱ����ϸ������ԣ���Ҫ�����ﴦ��һ�£�
                itemInfo.SysNo = oldItemInfo.SysNo;
                itemInfo.TransferSysNo = oldItemInfo.TransferSysNo;
                itemInfo.TransferType = oldItemInfo.TransferType;

                //����source�ijɱ����¿��
                if ( itemInfo.TransferType == (int)AppEnum.TransferItemType.Source)
                {
                    ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(itemInfo.ProductSysNo);
                    itemInfo.TransferCost = priceInfo.UnitCost;
                    InventoryManager.GetInstance().SetAvailableQty(masterInfo.StockSysNo, itemInfo.ProductSysNo, deltQty);
                }

                //����item�����ݿ�
                if ( 1 != new TransferDac().UpdateItem(itemInfo.SysNo, deltQty, itemInfo.TransferCost))
                    throw new BizException("expected one-row update failed, update item qty failed");

                //���� itemInfo �� masterInfo ע:���ݿ���³ɹ��Ժ�Ÿ�����
                masterInfo.itemHash.Remove(itemInfo.ProductSysNo);
                masterInfo.itemHash.Add(itemInfo.ProductSysNo, itemInfo);

                scope.Complete();
            }
        }
Exemple #4
0
        public TransferInfo Load(int transferSysNo)
        {
            TransferInfo masterInfo;

            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                string masterSql = "select * from st_transfer where sysno = " + transferSysNo;
                DataSet masterDs = SqlHelper.ExecuteDataSet(masterSql);
                if ( !Util.HasMoreRow(masterDs))
                    throw new BizException("there is no this transfer sysno");

                masterInfo = new TransferInfo();
                map(masterInfo, masterDs.Tables[0].Rows[0]);

                string itemSql = "select * from st_transfer_item where transfersysno=" + transferSysNo;
                DataSet itemDs = SqlHelper.ExecuteDataSet(itemSql);
                if ( Util.HasMoreRow(itemDs))
                {
                    foreach(DataRow dr in itemDs.Tables[0].Rows)
                    {
                        TransferItemInfo item = new TransferItemInfo();
                        map(item, dr);
                        masterInfo.itemHash.Add(item.ProductSysNo, item);
                    }
                }
                scope.Complete();
            }

            return masterInfo;
        }
Exemple #5
0
        public void InsertItem(TransferInfo masterInfo, TransferItemInfo itemInfo)
        {
            if ( masterInfo.itemHash.ContainsKey(itemInfo.ProductSysNo))
            {
                throw new BizException("item duplicated!");
            }

            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {

                //�����dz�ʼ
                if ( getCurrentStatus(masterInfo.SysNo) != (int)AppEnum.TransferStatus.Origin )
                    throw new BizException("status is not origin now,  add item failed");

                //���¿��
                if ( itemInfo.TransferType == (int)AppEnum.TransferItemType.Source )
                {
                    ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(itemInfo.ProductSysNo);
                    itemInfo.TransferCost = priceInfo.UnitCost;
                    InventoryManager.GetInstance().SetAvailableQty(masterInfo.StockSysNo, itemInfo.ProductSysNo, itemInfo.TransferQty);
                }

                //����item�����ݿ�
                if ( 1 != new TransferDac().InsertItem(itemInfo))
                    throw new BizException("expected one-row update failed, add item failed");

                //����itemInfo �� masterInfo
                masterInfo.itemHash.Add(itemInfo.ProductSysNo, itemInfo);

                scope.Complete();
            }
        }
Exemple #6
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();
            }
        }