/// <summary>
        /// Requests that an order be created based on the contents of the DRP table for the specified <paramref name="drpPlanId"/>
        /// </summary>
        /// <param name="facility">The health facility for which to create an order</param>
        /// <returns>The constructed <see cref="T:GIIS.DataLayer.TransferOrderHeader"/> instance which was constructed from the <paramref name="drpPlanId"/></returns>
        /// <remarks>
        /// <list type="ordered">
        /// <item><description>The function will create a new TransferOrderHeader DAL object</description></item>
        /// <item><description>	The function will load a HealthFacility object from the gln and gln_parent identifiers in the DRP table assigning them to the DAO object</description></item>
        /// <item><description>	The function will set the order status to “Requested”</description></item>
        /// <item><description>	The function will set the order date to the plan date</description></item>
        /// <item><description>	The function will save the order header.</description></item>
        /// <item><description>	For each item in the DRP plan the function will create a TransferOrderDetail objects using the AddOrderLine function in the Logic class using the specified quantity, gtin provided.       /// </remarks></description></item>
        /// </list>
        /// </remarks>
        public TransferOrderHeader RequestOrder(Int32[] drpIds, Int32 modifiedBy)
        {
            // HACK: Get this into the DAL
            StringBuilder drpIdsFilter = new StringBuilder();

            foreach (var id in drpIds)
            {
                drpIdsFilter.AppendFormat("{0},", id);
            }
            drpIdsFilter.Remove(drpIdsFilter.Length - 1, 1);

            string sql = String.Format("SELECT drp_plan.*, drp_facility.gln_parent FROM drp_plan INNER JOIN drp_facility USING (gln) WHERE drp_id IN ({0})", drpIdsFilter);

            using (var dt = DBManager.ExecuteReaderCommand(sql, System.Data.CommandType.Text, null))
            {
                // Create the order header
                TransferOrderHeader retVal = new TransferOrderHeader()
                {
                    ModifiedBy  = modifiedBy,
                    ModifiedOn  = DateTime.Now,
                    OrderStatus = (int)OrderStatusType.Requested
                };

                // Convert the datatable to a streamed reader
                using (var rdr = dt.CreateDataReader())
                {
                    while (rdr.Read())
                    {
                        retVal.OrderSchedReplenishDate = retVal.OrderSchedReplenishDate == default(DateTime) ? Convert.ToDateTime(rdr["plan_date"]) : retVal.OrderSchedReplenishDate;
                        retVal.OrderFacilityFrom       = retVal.OrderFacilityFrom ?? Convert.ToString(rdr["gln_parent"]);
                        retVal.OrderFacilityTo         = retVal.OrderFacilityTo ?? Convert.ToString(rdr["gln"]);

                        // Create line items
                        // Get the item/lot
                        var itemLot = this.GetOldestLot(retVal.OrderFacilityFromObject, Convert.ToString(rdr["gtin"]));
                        if (itemLot == null)
                        {
                            throw new InvalidOperationException("Cannot find item specified in gtin");
                        }

                        // Dtl
                        TransferOrderDetail dtl = new TransferOrderDetail()
                        {
                            OrderDetailDescription = itemLot.ItemObject.Name,
                            OrderNum          = retVal.OrderNum,
                            OrderGtin         = itemLot.Gtin,
                            OrderGtinLotnum   = itemLot.LotNumber,
                            OrderQty          = Convert.ToDouble(rdr["planned_order_receipt"]),
                            OrderQtyInBaseUom = Convert.ToDouble(rdr["planned_order_receipt"]),
                            OrderUom          = ItemManufacturer.GetItemManufacturerByGtin(itemLot.Gtin).BaseUom
                        };
                        dtl.OrderDetailNum = TransferOrderDetail.Insert(dtl);
                    }
                }

                retVal.OrderNum = TransferOrderHeader.Insert(retVal);

                return(retVal);
            }
        }
 /// <summary>
 /// Update the order details
 /// </summary>
 /// <param name="order">The order whose details should be updated</param>
 /// <param name="modifiedBy">The identification of the user performing the update</param>
 private void UpdateOrderDetails(TransferOrderHeader order, Int32 modifiedBy)
 {
     // Update the details
     foreach (var dtl in TransferOrderDetail.GetTransferOrderDetailByOrderNum(order.OrderNum))
     {
         dtl.OrderDetailStatus = order.OrderStatus;
         this.UpdateOrderLine(dtl, modifiedBy);
     }
 }
    private int NewOrderDetail(string orderNumber, string gtin, double qty, string uom, string item)
    {
        TransferOrderDetail tod = new TransferOrderDetail();

        tod.OrderNum        = int.Parse(orderNumber);
        tod.OrderGtin       = gtin;
        tod.OrderGtinLotnum = "*";

        int quantity = 0;

        ItemManufacturer im = ItemManufacturer.GetItemManufacturerByGtin(gtin);

        if (uom.Equals(im.BaseUom))
        {
            quantity = (int)qty;
        }
        else if (uom.Equals(im.Alt1Uom))
        {
            quantity = (int)(qty * im.Alt1QtyPer);
        }
        else if (uom.Equals(im.Alt2Uom))
        {
            quantity = (int)(qty * im.Alt2QtyPer);
        }
        tod.OrderQty               = qty;
        tod.OrderQtyInBaseUom      = (double)quantity;
        tod.OrderUom               = uom;
        tod.ModifiedBy             = CurrentEnvironment.LoggedUser.Id;
        tod.ModifiedOn             = DateTime.Now;
        tod.OrderDetailDescription = item;
        tod.OrderDetailStatus      = 0; //requested

        int i = TransferOrderDetail.Insert(tod);

        return(i);
    }
        /// <summary>
        /// Request an order from a mini-drp run
        /// </summary>
        /// <param name="to">The facility which is the target of the drp run</param>
        /// <param name="modifiedBy">The user which is requesting the order from DRP run</param>
        public TransferOrderHeader RequestOrderFromDrp(HealthFacility to, Int32 modifiedBy)
        {
            // HACK: Currently this is running form SQL, should be run from DALs

            // TODO: Perform the mini-DRP run

            // Get the results of the run for the facility
            string sql = "GET_REPLENISHMENT_ORDER";

            using (var dt = DBManager.ExecuteReaderCommand(sql, System.Data.CommandType.StoredProcedure, new List <NpgsqlParameter>()
            {
                new NpgsqlParameter("HF_ID_IN", NpgsqlTypes.NpgsqlDbType.Varchar)
                {
                    Value = to.Code
                }
            }))
            {
                // Create the order header
                TransferOrderHeader retVal = new TransferOrderHeader()
                {
                    ModifiedBy              = modifiedBy,
                    ModifiedOn              = DateTime.Now,
                    OrderStatus             = (int)OrderStatusType.Requested,
                    OrderFacilityFrom       = to.Parent.Code,
                    OrderFacilityTo         = to.Code,
                    OrderSchedReplenishDate = DateTime.Now
                };

                List <TransferOrderDetail> dtls = new List <TransferOrderDetail>();

                // Convert the datatable to a streamed reader
                using (var rdr = dt.CreateDataReader())
                {
                    while (rdr.Read())
                    {
                        retVal.OrderSchedReplenishDate = retVal.OrderSchedReplenishDate == default(DateTime) ? Convert.ToDateTime(rdr["plan_date"]) : retVal.OrderSchedReplenishDate;

                        // Create line items
                        // Get the item/lot
                        var itemLot = this.GetOldestLot(retVal.OrderFacilityFromObject, Convert.ToString(rdr["gtin"]));
                        if (itemLot == null)
                        {
                            throw new InvalidOperationException("Cannot find item specified in gtin");
                        }

                        // Dtl
                        TransferOrderDetail dtl = new TransferOrderDetail()
                        {
                            OrderDetailDescription = Convert.ToString(rdr["name"]),
                            OrderNum          = retVal.OrderNum,
                            OrderGtin         = itemLot.Gtin,
                            OrderGtinLotnum   = itemLot.LotNumber,
                            OrderQty          = Convert.ToDouble(rdr["base_replenish_qty"]),
                            OrderQtyInBaseUom = Convert.ToDouble(rdr["base_replenish_qty"]),
                            OrderUom          = Convert.ToString(rdr["base_uom"])
                        };
                        dtls.Add(dtl);
                    }
                }

                retVal.OrderNum = TransferOrderHeader.Insert(retVal);
                foreach (var dtl in dtls)
                {
                    dtl.OrderNum = retVal.OrderNum;
                    TransferOrderDetail.Insert(dtl);
                }

                return(retVal);
            }
        }
 /// <summary>
 /// Remove an order line
 /// </summary>
 /// <param name="line">The order line which is to be removed from its parent order</param>
 /// <returns>The <see cref="T:GIIS.DataLayer.TransferOrderDetail"/> representing the line that was removed</returns>
 /// <remarks>
 /// The remove order line function is used to remove an order detail from a transfer order. The process is as follows:
 /// <list type="ordered">
 /// <item><description>	Load the current order line for the database using the order line #</description></item>
 /// <item><description>	Instantiate an instance of <see cref="T:GIIS.BusinessLogic.StockManagementLogic"/>  BLL class.</description></item>
 /// <item><description>	If the status of the current order line is:
 ///     <list type="table">
 ///         <listheader>
 ///             <term>State</term>
 ///             <description>Action</description>
 ///         </listheader>
 ///         <item><term>Released</term><description>Call the <see cref="M:GIIS.BusinessLogic.StockManagementLogic.Allocate(GIIS.DataLayer.HealthFacility, System.String, System.String, System.Int32)"/> method of the <see cref="T:GIIS.BusinessLogic.StockManagementLogic"/> instance to perform the de-allocation of the item.</description></item>
 ///         <item><term>Packed</term><description>Call the Allocate method of the <see cref="T:GIIS.BusinessLogic.StockManagementLogic"/>  instance to perform the de-allocation of the item.</description></item>
 ///         <item><term>Shipped</term><description>Throw an invalid operation exception as shipped orders (and their lines) cannot be edited</description></item>
 ///         <item><term>Cancelled</term><description>Throw an invalid operation exception as cancelled orders (and their lines) cannot be edited</description></item>
 ///     </list>
 /// </description></item>
 /// <item><description>	Delete the order line from the transfer order table.</description></item>
 /// </list>
 /// </remarks>
 public TransferOrderDetail RemoveOrderLine(TransferOrderDetail line, Int32 modifiedBy)
 {
     // Remove order line
     line.OrderQty = 0;
     return(this.UpdateOrderLine(line, modifiedBy));
 }
        /// <summary>
        /// Add an order line to the order defined by <paramref name="order"/>
        /// </summary>
        /// <param name="order">The order to which the line should be added</param>
        /// <param name="gtin">The global trade identification number of the item in the line</param>
        /// <param name="lot">(Optional) The lot number to be used. Note if null is passed in <paramref name="lot"/> then the oldest lot is used first</param>
        /// <param name="qty">The quantity of the item to be added to the order</param>
        /// <param name="uom">(Optional) The base unit of measure. If <paramref name="uom"/> is null then the default UOM for the item described by <paramref name="gtin"/> is used</param>
        /// <returns>The constructed and saved <see cref="T:GIIS.DataLayer.TransferOrderDetail"/></returns>
        /// <remarks>
        /// The add order line function is responsible for adding a new order line to the order detail. This function operates in the following manner:
        /// <list type="ordered">
        /// <item>
        ///     <description>[Guard Condition] If the order passed into the function IS in the “Packed” or “Shipped” state then throw an invalid state exception (sanity check)</description>
        /// </item>
        /// <item>
        ///     <description>Lookup the item by the GTIN provided in the function call.</description>
        /// </item>
        /// <item>
        ///     <description>[Guard Condition] If the lot number is provided, and the lot number is not a valid lot number for the item provided then throw an error code</description>
        /// </item>
        /// <item>
        ///     <description>If the current status of the order to which the detail is to be attached is “Released” then
        ///         <list type="ordered">
        ///             <item>
        ///                 <description>Instantiate a StockManagementLogic BLL class</description>
        ///             </item>
        ///             <item>Allocate the stock using the Allocate method</item>
        ///         </list>
        ///     </description>
        /// </item>
        /// <item>
        ///     <description>Set the unit of measure, quantity, gtin, etc. fields of the TransferOrderDetail instance to the parameters and fields derived from loaded Item.</description>
        /// </item>
        /// <item>
        ///     <description>Save the order line.</description>
        /// </item>
        ///</list>
        /// </remarks>
        public TransferOrderDetail AddOrderLine(TransferOrderHeader order, String gtin, String lot, Int32 qty, Uom uom, Int32 modifiedBy)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }

            // Sanity check
            if (order.OrderStatus == (int)OrderStatusType.Shipped ||
                order.OrderStatus == (int)OrderStatusType.Cancelled)
            {
                throw new IllegalStateException((OrderStatusType)order.OrderStatus, "TransferOrderHeader", "AddOrderLine");
            }

            // Lookup item by GTIN and optionally lot
            ItemLot item = null;

            if (!String.IsNullOrEmpty(lot))
            {
                item = ItemLot.GetItemLotByGtinAndLotNo(gtin, lot);
            }
            if (item == null)
            {               // not found - We get the item by lot
                item = ItemLot.GetItemLotByGtin(gtin);
                lot  = "*"; // null;
            }

            // Item still null?
            if (item == null)
            {
                throw new InvalidOperationException(String.Format("Cannot locate item with GTIN {0}", gtin));
            }

            // Construct the order detail
            TransferOrderDetail retVal = new TransferOrderDetail()
            {
                ModifiedBy             = modifiedBy,
                ModifiedOn             = DateTime.Now,
                OrderCustomItem        = false,
                OrderDetailDescription = item.ItemObject.Name,
                OrderDetailStatus      = order.OrderStatus,
                OrderGtin         = gtin,
                OrderGtinLotnum   = lot,
                OrderNum          = order.OrderNum,
                OrderQty          = qty,
                OrderQtyInBaseUom = qty,
                OrderUom          = uom.Name
            };

            // HACK: Overcome lack of transaction processing we have to be careful about how we do this
            ItemTransaction allocateTransaction = null;

            // Current state of order is released? We need to allocate this line item
            if (order.OrderStatus == (int)OrderStatusType.Released)
            {
                StockManagementLogic stockLogic = new StockManagementLogic();
                // We need to release this order ... If the lot was null we'll use the oldest lot number
                if (String.IsNullOrEmpty(lot))
                {
                    item = this.GetOldestLot(order.OrderFacilityFromObject, gtin);
                }

                // Allocation of specified lot
                allocateTransaction = stockLogic.Allocate(order.OrderFacilityFromObject, gtin, item.LotNumber, qty, null, modifiedBy);

                // Update order
                retVal.OrderGtinLotnum = item.LotNumber;
            }

            // Save
            retVal.OrderDetailNum = TransferOrderDetail.Insert(retVal);

            // HACK: Update the allocate transaction. This would be cleaned up with a transaction to back out changes (basically do the order detail then allocate)
            if (allocateTransaction != null)
            {
                allocateTransaction.RefId    = retVal.OrderNum.ToString();
                allocateTransaction.RefIdNum = retVal.OrderDetailNum;
                ItemTransaction.Update(allocateTransaction);
            }

            return(retVal);
        }
        /// <summary>
        /// Transfers stock from facility <paramref name="from"/> to facility <paramref name="to"/>
        /// </summary>
        /// <param name="from">The facility from which stock is being transferred</param>
        /// <param name="to">The facility to which stock is being transferred</param>
        /// <param name="gtin">The GTIN of the stock being transfered</param>
        /// <param name="lot">The lot of the stock being transferred</param>
        /// <param name="orderDetail">The order detail which informed this transfer</param>
        /// <param name="qty">The quantity of stock to be transferred</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.ItemTransaction"/> representing the transfers </returns>
        public List <ItemTransaction> Transfer(HealthFacility from, HealthFacility to, String gtin, String lot, TransferOrderDetail orderDetail, Int32 qty, Int32 modifiedBy)
        {
            // Validate parameters
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            else if (to == null)
            {
                throw new ArgumentNullException("to");
            }
            else if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }
            else if (String.IsNullOrEmpty(lot))
            {
                throw new ArgumentNullException("lot");
            }

            // Transfer type
            TransactionType transferType = TransactionType.GetTransactionTypeList().FirstOrDefault(o => o.Name == "Transfer");

            if (transferType == null)
            {
                throw new InvalidOperationException("Cannot find transaction type 'Transfer'");
            }

            // Lookup the current balances in both facilities
            HealthFacilityBalance fromBalance = this.GetCurrentBalance(from, gtin, lot),
                                  toBalance   = this.GetCurrentBalance(to, gtin, lot);

            // Validate the fromBalance has sufficient quantity to transfer
            //if (fromBalance.Balance < qty)
            //    throw new InvalidOperationException("Insufficient quantity in the 'from' facility to perform transfer");

            // Two ItemTransactions
            ItemTransaction fromTransaction = new ItemTransaction()
            {
                Gtin                                                              = gtin,
                GtinLot                                                           = lot,
                HealthFacilityCode                                                = from.Code,
                ModifiedBy                                                        = modifiedBy,
                ModifiedOn                                                        = DateTime.Now,
                RefId                                                             = orderDetail != null?orderDetail.OrderNum.ToString() : null,
                                                          RefIdNum                = orderDetail != null ? orderDetail.OrderDetailNum : 0,
                                                          TransactionDate         = DateTime.Now,
                                                          TransactionQtyInBaseUom = -qty, // transfer out
                                                          TransactionTypeId       = transferType.Id
            },
                            toTrasnaction = new ItemTransaction()
            {
                Gtin                                                              = gtin,
                GtinLot                                                           = lot,
                HealthFacilityCode                                                = to.Code,
                ModifiedBy                                                        = modifiedBy,
                ModifiedOn                                                        = DateTime.Now,
                RefId                                                             = orderDetail != null?orderDetail.OrderNum.ToString() : null,
                                                          RefIdNum                = orderDetail != null ? orderDetail.OrderDetailNum : 0,
                                                          TransactionDate         = DateTime.Now,
                                                          TransactionQtyInBaseUom = qty, // transfer in
                                                          TransactionTypeId       = transferType.Id
            };

            // Update balances
            fromBalance.Balance     -= qty;
            toBalance.Balance       += qty;
            toBalance.Received      += qty;
            fromBalance.Distributed += qty;

            // Save
            HealthFacilityBalance.Update(fromBalance);
            HealthFacilityBalance.Update(toBalance);
            fromTransaction.Id = ItemTransaction.Insert(fromTransaction);
            toTrasnaction.Id   = ItemTransaction.Insert(toTrasnaction);

            // Return
            return(new List <ItemTransaction>()
            {
                fromTransaction, toTrasnaction
            });
        }
    protected void btnAddDetail_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                string orderNumber = "";
                if (Request.QueryString["orderNum"] != null)
                {
                    orderNumber = Request.QueryString["orderNum"].ToString();
                }
                TransferOrderHeader toh = TransferOrderHeader.GetTransferOrderHeaderByOrderNum(int.Parse(orderNumber));

                OrderManagementLogic oml = new OrderManagementLogic();
                string gtin = ddlGtin.SelectedValue;
                string lot  = "*";
                if (ddlItemLot.SelectedIndex > 0)
                {
                    lot = ddlItemLot.SelectedValue;
                }

                int qty      = 0;
                int quantity = 0;
                if (!String.IsNullOrEmpty(txtQuantity.Text))
                {
                    qty = int.Parse(txtQuantity.Text);
                    string uom = ddlUom.SelectedValue;

                    ItemManufacturer im = ItemManufacturer.GetItemManufacturerByGtin(gtin);
                    if (uom.Equals(im.BaseUom))
                    {
                        quantity = qty;
                    }
                    else if (uom.Equals(im.Alt1Uom))
                    {
                        quantity = qty * im.Alt1QtyPer;
                    }
                    else if (uom.Equals(im.Alt2Uom))
                    {
                        quantity = qty * im.Alt2QtyPer;
                    }
                }
                Uom u = Uom.GetUomByName(ddlUom.SelectedValue); //GetuomByName

                TransferOrderDetail tod = TransferOrderDetail.GetTransferOrderDetailByOrderNumGtinLotNumber(int.Parse(orderNumber), gtin, lot);
                if (tod == null)
                {
                    TransferOrderDetail td = oml.AddOrderLine(toh, gtin, lot, quantity, u, CurrentEnvironment.LoggedUser.Id);

                    if (td != null)
                    {
                        //ClearControls(this);
                        gvGtinValue.DataBind();
                        ddlGtin.SelectedIndex = 0;
                        //ddlItemLot.SelectedIndex = 0;
                        txtQuantity.Text   = string.Empty;
                        lblSuccess.Visible = true;
                        lblWarning.Visible = false;
                        lblError.Visible   = false;
                    }
                    else
                    {
                        lblSuccess.Visible = false;
                        lblWarning.Visible = false;
                        lblError.Visible   = true;
                    }
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = true;
                    lblError.Visible   = false;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
Beispiel #9
0
        public override string SaveData()
        {
            _order.OrderStatus = 2; //初始态
            _order.EditStatus  = 0; //无人编辑

            if (_order.InWHCode == _order.OutWHCode && _order.OutWHCode != null && _order.InWHCode != null)
            {
                throw new Exception("调拨订单不允许调入和调出仓库相同!");
            }

            StringBuilder sb = new StringBuilder();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                try
                {
                    var tmp = edm.TransferOrder.SingleOrDefault(o => o.OrderCode == _order.OrderCode);
                    if (tmp == null)
                    {
                        edm.TransferOrder.AddObject(_order);
                    }
                    else
                    {
                        //判断该订单是否已经开始其他作业,如果是,则不允许覆盖
                        if (tmp.OrderStatus != 2)
                        {
                            throw new Exception("此订单(" + tmp.OrderCode + ")已开始其他作业,不允许再次上传!");
                        }

                        foreach (TransferOrderDetail oldDetail in tmp.TransferOrderDetail)
                        {
                            //如果实收数量为0,则直接删除
                            if (oldDetail.NumActual == null || oldDetail.NumActual == 0)
                            {
                                continue;
                            }
                            else
                            {
                                bool isExist = false;//是否新旧订单都有此商品
                                foreach (TransferOrderDetail newDetail in _order.TransferOrderDetail)
                                {
                                    //判断在当前的新excel中是否有此商品,如果有,则保存实收数量
                                    if (newDetail.CargoCode == oldDetail.CargoCode)
                                    {
                                        newDetail.NumActual = oldDetail.NumActual;
                                        isExist             = true;
                                        _order.OrderStatus  = 1;//部分已下发
                                        break;
                                    }
                                }
                                if (isExist)
                                {
                                    continue;
                                }
                                else
                                {
                                    //如果当前新excel没有此商品,则直接添加
                                    TransferOrderDetail td = new TransferOrderDetail();
                                    td.CargoCode       = oldDetail.CargoCode;
                                    td.CargoModel      = oldDetail.CargoModel;
                                    td.CargoName       = oldDetail.CargoName;
                                    td.CargoSpec       = oldDetail.CargoSpec;
                                    td.CargoUnits      = oldDetail.CargoUnits;
                                    td.Comment         = oldDetail.Comment;
                                    td.DetailRowNumber = oldDetail.DetailRowNumber;
                                    td.DetailRowStatus = oldDetail.DetailRowStatus;
                                    td.InWHCode        = oldDetail.InWHCode;
                                    td.InWHName        = oldDetail.InWHName;
                                    td.NCOrderCode     = oldDetail.NCOrderCode;
                                    td.NumActual       = oldDetail.NumActual;
                                    td.NumCurrentPlan  = oldDetail.NumCurrentPlan;
                                    td.NumOriginalPlan = oldDetail.NumOriginalPlan;
                                    td.OrderCode       = oldDetail.OrderCode;
                                    td.OrderCode       = oldDetail.OrderCode;
                                    td.OutWHCode       = oldDetail.OutWHCode;
                                    td.OutWHName       = oldDetail.OutWHName;
                                    td.ReleaseYear     = oldDetail.Reserve1;
                                    td.Reserve2        = oldDetail.Reserve2;
                                    if (td.NumActual != null && td.NumActual != 0)
                                    {
                                        _order.OrderStatus = 1;//部分已下发
                                    }

                                    _order.TransferOrderDetail.Add(td);
                                }
                            }
                        }

                        edm.TransferOrder.DeleteObject(tmp);
                        edm.SaveChanges();
                        edm.TransferOrder.AddObject(_order);
                    }

                    edm.SaveChanges();
                    sb.AppendLine("保存成功!");
                }
                catch (Exception ex)
                {
                    sb.Append("保存数据时发生异常:");
                    string msg = Utility.LogHelper.GetExceptionMsg(ex);
                    sb.Append(msg);

                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "调拨订单保存异常", ex);
                }
            }

            return(sb.ToString());
        }
Beispiel #10
0
        //行项目
        protected override void BindingOrderItem(object[] array)
        {
            if (_order.TransferOrderDetail == null)
            {
                _order.TransferOrderDetail = new EntityCollection <TransferOrderDetail>();
            }

            if (_itemDefine == null)
            {
                throw new ApplicationException("未发现行项目字段定义!");
            }

            if (_itemDefine.Count() == array.Count())
            {
                TransferOrderDetail orderItem = new TransferOrderDetail();
                for (int i = 0; i < array.Count(); i++)
                {
                    string fieldName  = Regex.Replace(_itemDefine[i].ToString(), @"\s", "");
                    string fieldValue = Regex.Replace(array[i].ToString(), @"\s", "");

                    switch (fieldName)
                    {
                    case "行号":
                        if (fieldValue.Contains("."))    //如果行号是10.000,则取10,去掉小数点后面的0
                        {
                            orderItem.DetailRowNumber = fieldValue.Substring(0, fieldValue.IndexOf("."));
                        }
                        else
                        {
                            orderItem.DetailRowNumber = fieldValue;
                        }
                        break;

                    case "存货编码":
                        orderItem.CargoCode = fieldValue;
                        string cargoCode = DbCommonMethod.ParsingCargoCode(fieldValue);
                        if (string.IsNullOrEmpty(cargoCode))
                        {
                            throw new ApplicationException("商品不存在:" + fieldValue);
                        }
                        break;

                    case "存货名称":
                        orderItem.CargoName = fieldValue;
                        break;

                    //case "产地":
                    //    break;
                    case "规格":
                        orderItem.CargoSpec = fieldValue;
                        break;

                    case "型号":
                        //过滤型号值,如果型号是90.000,则去90,去掉小数点后面的0
                        double dou;
                        string strModel = fieldValue;
                        double douModel = 0;
                        if (double.TryParse(fieldValue, out dou))
                        {
                            douModel = dou;
                        }

                        if (douModel != 0 && strModel.Contains("."))
                        {
                            string sdecimal = strModel.Substring(strModel.IndexOf(".") + 1, strModel.Length - strModel.IndexOf(".") - 1);
                            int    istring  = Convert.ToInt32(sdecimal);
                            if (istring == 0)
                            {
                                strModel = fieldValue.Substring(0, fieldValue.IndexOf("."));
                            }
                        }
                        orderItem.CargoModel = strModel;
                        break;

                    case "主计量单位":
                        orderItem.CargoUnits = fieldValue;
                        break;

                    //case "辅单位":
                    //    break;
                    //case "换算率":
                    //    break;
                    //case "辅数量":
                    //    break;
                    case "数量":
                        if (!string.IsNullOrEmpty(fieldValue))
                        {
                            double d;
                            if (double.TryParse(fieldValue, out d))
                            {
                                orderItem.NumOriginalPlan = d;
                            }
                        }
                        break;

                    //case "自由项":
                    //    break;
                    //case "批次号":
                    //    break;
                    case "生产日期":
                        if (!string.IsNullOrEmpty(fieldValue))
                        {
                            DateTime dt;
                            if (DateTime.TryParse(fieldValue, out dt))
                            {
                                orderItem.ReleaseYear = dt.Year.ToString();
                            }
                        }

                        break;

                    //case "失效日期":
                    //    break;
                    //case "是否赠品":
                    //    break;
                    case "调出仓库":
                        orderItem.InWHName = fieldValue;
                        orderItem.InWHCode = DbCommonMethod.ParsingWarehouse(fieldValue);
                        break;

                    case "调入仓库":
                        orderItem.OutWHName = fieldValue;
                        orderItem.OutWHCode = DbCommonMethod.ParsingWarehouse(fieldValue);
                        break;

                    //case "出货仓库":
                    //    break;
                    //case "调出部门":
                    //    break;
                    //case "业务员":
                    //    break;
                    //case "调入部门":
                    //    break;
                    //case "业务员":
                    //    break;
                    //case "出货部门":
                    //    break;
                    //case "业务员":
                    //    break;
                    //case "调出货位":
                    //    break;
                    //case "调入货位":
                    //    break;
                    //case "出货货位":
                    //    break;
                    //case "计划发货日":
                    //    break;
                    //case "计划到货日":
                    //    break;
                    //case "收货客户":
                    //    break;
                    //case "收货地区":
                    //    break;
                    //case "收货地址":
                    //    break;
                    //case "收货地点":
                    //    break;
                    //case "项目":
                    //    break;
                    //case "项目阶段":
                    //    break;
                    //case "发运方式":
                    //    break;
                    //case "非含税单价":
                    //    break;
                    //case "税率":
                    //    break;
                    //case "非含税金额":
                    //    break;
                    //case "含税金额":
                    //    break;
                    //case "询价含税价":
                    //    break;
                    //case "含税单价":
                    //    break;
                    //case "加价率":
                    //    break;
                    //case "询价非含税价":
                    //    break;
                    //case "已调出主数量":
                    //    break;
                    //case "已调出辅数量":
                    //    break;
                    //case "已调入主数量":
                    //    break;
                    //case "已调入辅数量":
                    //    break;
                    //case "调拨在途主数量":
                    //    break;
                    //case "调拨在途辅数量":
                    //    break;
                    //case "已发货主数量":
                    //    break;
                    //case "已发货辅数量":
                    //    break;
                    //case "签收主数量":
                    //    break;
                    //case "签收辅数量":
                    //    break;
                    //case "调出与调入已结算数量":
                    //    break;
                    //case "调出与出货方已经结算数量":
                    //    break;
                    //case "调出与出货方已经结算金额":
                    //    break;
                    //case "发运退回主数量":
                    //    break;
                    //case "发运退回辅数量":
                    //    break;
                    //case "发运途损主数量":
                    //    break;
                    //case "发运途损辅数量":
                    //    break;
                    //case "累计退回数量":
                    //    break;
                    //case "应发未出库数量":
                    //    break;
                    //case "来源单据类型":
                    //    break;
                    //case "来源单据号":
                    //    break;
                    //case "来源单据行号":
                    //    break;
                    //case "B-UDC1":
                    //    break;
                    //case "B-UDC2":
                    //    break;
                    //case "B-UDC3":
                    //    break;
                    //case "B-UDC4":
                    //    break;
                    //case "B-UDC5":
                    //    break;
                    //case "B-UDC6":
                    //    break;
                    //case "B-UDC7":
                    //    break;
                    //case "B-UDC8":
                    //    break;
                    //case "B-UDC9":
                    //    break;
                    //case "B-UDC10":
                    //    break;
                    //case "B-UDC11":
                    //    break;
                    //case "B-UDC12":
                    //    break;
                    //case "B-UDC13":
                    //    break;
                    //case "B-UDC14":
                    //    break;
                    //case "B-UDC15":
                    //    break;
                    //case "B-UDC16":
                    //    break;
                    //case "B-UDC17":
                    //    break;
                    //case "B-UDC18":
                    //    break;
                    //case "B-UDC19":
                    //    break;
                    //case "B-UDC20":
                    //    break;
                    //case "报价计量单位":
                    //    break;
                    //case "报价计量单位数量":
                    //    break;
                    //case "报价计量单位换算率":
                    //    break;
                    //case "报价计量单位原币含税净价":
                    //    break;
                    //case "报价计量单位原币无税净价":
                    default:
                        break;
                    }
                }

                orderItem.DetailRowStatus = 2;//初始态
                orderItem.OrderCode       = _order.OrderCode;
                orderItem.NCOrderCode     = _order.NCOrderCode;
                orderItem.TransferOrder   = _order;

                IEnumerable <KeyValuePair <string, object> > entityKeyValues =
                    new KeyValuePair <string, object>[] {
                    new KeyValuePair <string, object>("OrderCode", orderItem.OrderCode),
                    new KeyValuePair <string, object>("DetailRowNumber", orderItem.DetailRowNumber)
                };
                orderItem.EntityKey = new EntityKey("GoldEntities.TransferOrderDetail", entityKeyValues);
                _order.TransferOrderDetail.Add(orderItem);
            }
        }
    protected void gvGtinValue_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;

        TransferOrderHeader toh = null;
        string orderNumber      = Request.QueryString["OrderNum"];

        if (!string.IsNullOrEmpty(orderNumber))
        {
            toh = TransferOrderHeader.GetTransferOrderHeaderByOrderNum(int.Parse(orderNumber));
            if (toh.OrderStatus == 0)
            {
                e.Row.Cells[4].Visible = false;
            }
        }


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label   lblOrderGtin = (Label)e.Row.FindControl("lblOrderGtin");
            TextBox txtValue     = (TextBox)e.Row.FindControl("txtValue");
            Label   lblId        = (Label)e.Row.FindControl("lblId");
            Label   lblId2       = (Label)e.Row.FindControl("lblId2");
            Label   lblItem      = (Label)e.Row.FindControl("lblItem");
            Label   lblFromStock = (Label)e.Row.FindControl("lblDistrictStock");

            DropDownList ddlUom = (DropDownList)e.Row.FindControl("ddlUom");
            DataTable    dt     = ItemManufacturer.GetUomFromGtin(lblOrderGtin.Text);
            // List<Uom> uomList = Uom.GetUomList();
            ddlUom.DataSource = dt;
            ddlUom.DataBind();


            //if (toh != null) // && toh.OrderStatus == 0)
            //    ddlUom.Enabled = true;
            //else ddlUom.Enabled = false;

            string id  = lblId.Text;
            int    id2 = int.Parse(lblId2.Text);

            TransferOrderDetail tod = TransferOrderDetail.GetTransferOrderDetailByOrderNumAndOrderDetail(int.Parse(id), id2);

            // lblFromStock.Text = GIIS.DataLayer.HealthFacilityBalance.GetHealthFacilityBalanceByHealthFacilityCode(toh.OrderFacilityFrom).Find(o=>o.Gtin == tod.OrderGtin).Balance.ToString();
            lblFromStock.Text += " " + tod.OrderUom;

            if (tod != null)
            {
                txtValue.Text        = tod.OrderQty.ToString();
                ddlUom.SelectedValue = tod.OrderUom;
                ddlUom.Enabled       = false;
            }


            DropDownList     ddlItemLot = (DropDownList)e.Row.FindControl("ddlItemLot");
            ObjectDataSource odsItemLot = (ObjectDataSource)e.Row.FindControl("odsItemLot");

            odsItemLot.SelectParameters.Clear();
            odsItemLot.SelectParameters.Add("gtin", lblOrderGtin.Text);
            odsItemLot.DataBind();
            ddlItemLot.DataSource = odsItemLot;
            ddlItemLot.DataBind();
            if (tod.OrderDetailStatus > 0)
            {
                ddlItemLot.SelectedValue = tod.OrderGtinLotnum;
            }
            if (tod.OrderDetailStatus == 3)
            {
                txtValue.Enabled   = false;
                ddlItemLot.Enabled = false;
            }
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int index = 0;
                for (int rowIndex = 0; rowIndex < gvGtinValue.Rows.Count; rowIndex++)
                {
                    //extract the TextBox values

                    Label   lblOrderGtin = (Label)gvGtinValue.Rows[rowIndex].Cells[3].FindControl("lblOrderGtin");
                    TextBox txtValue     = (TextBox)gvGtinValue.Rows[rowIndex].Cells[5].FindControl("txtValue");
                    Label   lblId        = (Label)gvGtinValue.Rows[rowIndex].Cells[0].FindControl("lblId");
                    Label   lblId2       = (Label)gvGtinValue.Rows[rowIndex].Cells[1].FindControl("lblId2");
                    Label   lblItem      = (Label)gvGtinValue.Rows[rowIndex].Cells[2].FindControl("lblItem");
                    //DropDownList ddlHealthFacilityFrom = (DropDownList)gvGtinValue.Rows[rowIndex].Cells[1].FindControl("ddlHealthFacilityFrom");
                    //DropDownList ddlHealthFacilityTo = (DropDownList)gvGtinValue.Rows[rowIndex].Cells[1].FindControl("ddlHealthFacilityTo");
                    DropDownList ddlUom           = (DropDownList)gvGtinValue.Rows[rowIndex].Cells[6].FindControl("ddlUom");
                    DropDownList ddlGtinLotNumber = (DropDownList)gvGtinValue.Rows[rowIndex].Cells[4].FindControl("ddlItemLot");

                    string id  = lblId.Text;
                    int    id2 = int.Parse(lblId2.Text);

                    string orderNumber = "";
                    if (Request.QueryString["orderNum"] != null)
                    {
                        orderNumber = Request.QueryString["orderNum"].ToString();
                    }

                    TransferOrderDetail tod = TransferOrderDetail.GetTransferOrderDetailByOrderNumAndOrderDetail(int.Parse(id), id2);

                    if (tod != null)
                    {
                        if (!String.IsNullOrEmpty(txtValue.Text))
                        {
                            tod.OrderNum          = int.Parse(orderNumber);
                            tod.OrderGtin         = lblOrderGtin.Text;
                            tod.OrderQty          = double.Parse(txtValue.Text);
                            tod.OrderQtyInBaseUom = tod.OrderQty;
                            tod.OrderUom          = ddlUom.SelectedValue;
                            tod.OrderGtinLotnum   = ddlGtinLotNumber.SelectedValue;
                            tod.OrderDetailStatus = GetStatusId(txtOrderStatus.Text);

                            OrderManagementLogic oml = new OrderManagementLogic();
                            TransferOrderDetail  t   = oml.UpdateOrderLine(tod, CurrentEnvironment.LoggedUser.Id);
                            int updated = TransferOrderDetail.Update(tod);
                            index = updated;
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(txtValue.Text))
                        {
                            tod                        = new TransferOrderDetail();
                            tod.OrderNum               = int.Parse(orderNumber);
                            tod.OrderGtin              = lblOrderGtin.Text;
                            tod.OrderGtinLotnum        = "*";
                            tod.OrderQty               = double.Parse(txtValue.Text);
                            tod.OrderQtyInBaseUom      = tod.OrderQty;
                            tod.OrderUom               = ddlUom.SelectedValue;
                            tod.ModifiedBy             = CurrentEnvironment.LoggedUser.Id;
                            tod.ModifiedOn             = DateTime.Now;
                            tod.OrderDetailDescription = lblItem.Text;
                            tod.OrderDetailStatus      = 0; //requested
                            //employ gtinparent logic + uom logic

                            int updated = TransferOrderDetail.Insert(tod);
                            index = updated;
                        }
                    }
                }
                if (index > 0)
                {
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = false;
                    lblError.Visible   = true;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            List <string> actionList        = null;
            string        sessionNameAction = "";
            if (CurrentEnvironment.LoggedUser != null)
            {
                sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id;
                actionList        = (List <string>)Session[sessionNameAction];
            }

            if ((actionList != null) && actionList.Contains("ViewTransferOrderDetails") && (CurrentEnvironment.LoggedUser != null))
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["TransferOrderDetail-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "TransferOrderDetail");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("TransferOrderDetail-dictionary" + language, wtList);
                }

                this.lblOrderNum.Text = wtList["TransferOrderDetailOrderNum"];
                //this.lblOrderDetailNum.Text = wtList["TransferOrderDetailOrderDetailNum"];
                //this.lblOrderGtin.Text = wtList["TransferOrderDetailOrderGtin"];
                //this.lblOrderGtinLotnum.Text = wtList["TransferOrderDetailOrderGtinLotnum"];
                //this.lblOrderCustomItem.Text = wtList["TransferOrderDetailOrderCustomItem"];
                //this.lblOrderDetailDescription.Text = wtList["TransferOrderDetailOrderDetailDescription"];
                //this.lblOrderUom.Text = wtList["TransferOrderDetailOrderUom"];
                //this.lblOrderQtyInBaseUom.Text = wtList["TransferOrderDetailOrderQtyInBaseUom"];
                //this.lblOrderDetailStatus.Text = wtList["TransferOrderDetailOrderDetailStatus"];
                //this.lblRevNum.Text = wtList["TransferOrderDetailRevNum"];


                //gvGtinValue.Columns[2].HeaderText = wtList["TransferOrderDetailOrderItem"];
                gvGtinValue.Columns[4].HeaderText = wtList["TransferOrderDetailOrderGtin"];
                gvGtinValue.Columns[5].HeaderText = wtList["TransferOrderDetailOrderGtinLotnum"];
                gvGtinValue.Columns[6].HeaderText = wtList["TransferOrderDetailOrderQtyInBaseUom"];
                gvGtinValue.Columns[7].HeaderText = wtList["TransferOrderDetailOrderUom"];


                //    this.btnAdd.Visible = actionList.Contains("AddTransferOrderDetail");
                //    this.btnAdd.Text = wtList["TransferOrderDetailAddButton"];

                btnRelease.Visible = false;
                btnPack.Visible    = false;
                btnShip.Visible    = false;
                btnCancel.Visible  = false;

                if (Request.QueryString["orderNum"] != null)
                {
                    string orderNumber = Request.QueryString["orderNum"].ToString();

                    //Requested = 0,
                    //Released = 1,
                    //Packed = 2,
                    //Shipped = 3,
                    //Cancelled = -1

                    TransferOrderHeader orderheader = TransferOrderHeader.GetTransferOrderHeaderByOrderNum(int.Parse(orderNumber));

                    txtOrderNum.Text = orderheader.OrderNum.ToString();
                    txtOrderSchedReplenishDate.Text = orderheader.OrderSchedReplenishDate.ToString("dd-MMM-yyyy");
                    txtOrderFacilityFrom.Text       = orderheader.OrderFacilityFromObject.Name;
                    txtOrderFacilityTo.Text         = orderheader.OrderFacilityToObject.Name;
                    int ostatus = orderheader.OrderStatus;
                    switch (ostatus)
                    {
                    case 0:
                        txtOrderStatus.Text = "Requested";
                        break;

                    case 1:
                        txtOrderStatus.Text = "Released";
                        break;

                    case 2:
                        txtOrderStatus.Text = "Packed";
                        break;

                    case 3:
                        txtOrderStatus.Text = "Shipped";
                        break;

                    case -1:
                        txtOrderStatus.Text = "Canceled";
                        break;
                    }
                    txtOrderCarrier.Text = orderheader.OrderCarrier;

                    List <TransferOrderDetail> orderDetailList = TransferOrderDetail.GetTransferOrderDetailByOrderNumAsList(int.Parse(orderNumber), CurrentEnvironment.LoggedUser.HealthFacility.Code);

                    if (orderDetailList.Count >= 1)
                    {
                        if (orderheader.OrderStatus == 0)
                        {
                            btnRelease.Visible  = true;
                            btnCancel.Visible   = true;
                            gvCreateTOD.Visible = false;
                            gvGtinValue.Visible = true;
                            ddlItemLot.Visible  = false;
                        }
                        else if (orderheader.OrderStatus == 1)
                        {
                            btnPack.Visible     = true;
                            btnCancel.Visible   = true;
                            gvCreateTOD.Visible = false;
                            gvGtinValue.Visible = true;
                        }
                        else if (orderheader.OrderStatus == 2)
                        {
                            btnShip.Visible     = true;
                            btnCancel.Visible   = true;
                            gvCreateTOD.Visible = false;
                            gvGtinValue.Visible = true;
                        }
                        else if (orderheader.OrderStatus == 3)
                        {
                            btnAdd.Visible       = false;
                            ddlGtin.Visible      = false;
                            ddlItemLot.Visible   = false;
                            ddlUom.Visible       = false;
                            txtQuantity.Visible  = false;
                            btnEdit.Visible      = false;
                            btnAddDetail.Visible = false;
                            tbl.Visible          = false;
                        }
                        else if (orderheader.OrderStatus == -1)
                        {
                            btnAdd.Visible       = false;
                            ddlGtin.Visible      = false;
                            ddlItemLot.Visible   = false;
                            ddlUom.Visible       = false;
                            txtQuantity.Visible  = false;
                            btnEdit.Visible      = false;
                            btnAddDetail.Visible = false;
                            tbl.Visible          = false;
                        }
                        hlPrintPackingSlip.Visible = orderheader.OrderStatus > 0;

                        hlPrintPackingSlip.NavigateUrl = String.Format("{0}/Pack_Order_Report.pdf?j_username={1}&j_password={2}&OrderNum={3}",
                                                                       ConfigurationManager.AppSettings["JasperServer"],
                                                                       ConfigurationManager.AppSettings["JasperUser"],
                                                                       ConfigurationManager.AppSettings["JasperPassword"],
                                                                       orderheader.OrderNum);
                        odsGtinValue.SelectParameters.Clear();
                        odsGtinValue.SelectParameters.Add("orderNumber", orderNumber);
                        odsGtinValue.SelectParameters.Add("healthFacilityCode", CurrentEnvironment.LoggedUser.HealthFacility.Code);
                        gvGtinValue.DataSourceID = "odsGtinValue";
                        gvGtinValue.DataBind();

                        //List<Uom> uomList = Uom.GetUomList();
                        //ddlUom.DataSource = uomList;
                        //ddlUom.DataBind();

                        DataTable dt = HealthFacilityBalance.GetItemManufacturerBalanceForDropDown(CurrentEnvironment.LoggedUser.HealthFacilityId);
                        ddlGtin.DataSource = dt;
                        ddlGtin.DataBind();
                    }
                    else
                    {
                        gvCreateTOD.Visible = true;
                        gvGtinValue.Visible = false;
                        odsCreateTOD.SelectParameters.Clear();
                        odsCreateTOD.SelectParameters.Add("healthFacilityCode", CurrentEnvironment.LoggedUser.HealthFacility.Code);
                        gvCreateTOD.DataSourceID = "odsCreateTOD";
                        gvCreateTOD.DataBind();
                        btnAdd.Visible = true;

                        //hide cotrols
                        tbl.Visible          = false;
                        ddlGtin.Visible      = false;
                        ddlItemLot.Visible   = false;
                        ddlUom.Visible       = false;
                        txtQuantity.Visible  = false;
                        btnEdit.Visible      = false;
                        btnAddDetail.Visible = false;
                    }
                }
            }
        }
    }
        /// <summary>
        /// Updates the specified <paramref name="orderLine"/> based on business rules
        /// </summary>
        /// <param name="orderLine">The <see cref="T:GIIS.DataLayer.TransferOrderDetail"/> line to be updated</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.TransferOrderDetail"/> which was updated</returns>
        /// <remarks>
        /// <list type="ordered">
        /// <item><description>	Load the current order line for the database using the order line #</description></item>
        /// <item><description>	Instantiate an instance of StockManagementLogic BLL class.</description></item>
        /// <item><description>	If the status of the current order line is:
        ///     <list type="table">
        ///         <listHeader>
        ///             <term>State</term>
        ///             <description>Actions</description>
        ///         </listHeader>
        ///         <item>
        ///             <term>Requested</term>
        ///             <description>
        ///                 <list type="ordered">
        ///                     <item><description>[Guard Condition] Ensure the new state is either “Cancelled”, “Requested” or “Released” otherwise throw an invalid state transition exception</description></item>
        ///                     <item><description>Update the quantity and status of the  order detail item</description></item>
        ///                     <item><description>If the new state is “Released” then call the Allocate function of the StockManagementLogic instance to allocate the specified order detail.</description></item>
        ///                     <item><description>Save the order detail</description></item>
        ///                 </list>
        ///             </description>
        ///         </item>
        ///         <item>
        ///             <term>Released</term>
        ///             <description>
        ///                 <list type="ordered">
        ///                     <item><description>[Guard Condition] Ensure the new state is either “Cancelled”, “Released” or “Packed” otherwise thrown an invalid state transition exception</description></item>
        ///                     <item><description>If the current state is “Released” then
        ///                         <list type="ordered">
        ///                             <item><description>Calculate the difference in quantity from the “old” record and “new” record</description></item>
        ///                             <item><description>Call the Allocate method of the StockManagementLogic instance to perform the additional allocation/de-allocation.</description></item>
        ///                         </list>
        ///                     </description></item>
        ///                     <item><description>	Update the quantity and status of the order detail item.</description></item>
        ///                     <item><description>If the new state is “Cancelled” then call the Allocate method of the StockManagementLogic instance to perform the de-allocation of the item.</description></item>
        ///                     <item><description>Save the order detail</description></item>
        ///                 </list>
        ///             </description>
        ///         </item>
        ///         <item>
        ///             <term>Packed</term>
        ///             <description>
        ///                 <list type="ordered">
        ///                     <item><description>[Guard Condition] Ensure the new state is either “Cancelled”, “Packed” or “Shipped”</description></item>
        ///                     <item><description>Update the quantity and status of the order detail item.</description></item>
        ///                     <item><description>If the new state is “cancelled” then call the Allocate method of the StockManagementLogic instance to perform the de-allocation of the item.</description></item>
        ///                     <item><description>If the new state is “Shipped” then
        ///                         <list type="ordered">
        ///                             <item><description>Call the allocate method of the StockManagementLogic instance to perform the de-allocation of the line item.</description></item>
        ///                             <item><description>Call the Transfer method of the StockManagementLogic instance to perform the transfer transactions between the source and target facilities.</description></item>
        ///                         </list>
        ///                     </description></item>
        ///                     <item><description>Save the order detail</description></item>
        ///                 </list>
        ///             </description>
        ///         </item>
        ///         <item>
        ///             <term>Shipped</term>
        ///             <description>Throw an invalid operation exception as shipped orders (and their lines) cannot be edited</description>
        ///         </item>
        ///         <item>
        ///             <term>Cancelled</term>
        ///             <description>Throw an invalid operation exception as cancelled orders (and their lines) cannot be edited</description>
        ///         </item>
        ///     </list>
        /// </description></item>
        /// </list>
        /// </remarks>
        public TransferOrderDetail UpdateOrderLine(TransferOrderDetail orderLine, Int32 modifiedBy)
        {
            if (orderLine == null)
            {
                throw new ArgumentNullException("orderLine");
            }
            else if (orderLine.OrderDetailNum == default(Int32))
            {
                throw new ArgumentException("Order line is not saved", "orderLine");
            }

            // Load the current order line from the database
            TransferOrderDetail currentOrderLine   = TransferOrderDetail.GetTransferOrderDetailByOrderDetailNum(orderLine.OrderDetailNum);
            TransferOrderHeader currentOrderHeader = TransferOrderHeader.GetTransferOrderHeaderByOrderNum(orderLine.OrderNum);

            // Can't change the GTIN with this function
            if (orderLine.OrderGtin != currentOrderLine.OrderGtin)
            {
                throw new InvalidOperationException("Cannot change the GTIN with this function. Remove the order line first and add another order-line with the new GTIN");
            }

            // New order lot number is null?  We need to get oldest lot
            if (String.IsNullOrEmpty(orderLine.OrderGtinLotnum) || orderLine.OrderGtinLotnum == "*")
            {
                ItemLot itemLot = GetOldestLot(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin); //currentOrderLine.OrderGtinLotnum;
                if (itemLot != null)
                {
                    orderLine.OrderGtinLotnum = itemLot.LotNumber;
                }
            }

            StockManagementLogic stockLogic = new StockManagementLogic();

            // Apply rules
            switch ((OrderStatusType)currentOrderLine.OrderDetailStatus)
            {
            case OrderStatusType.Requested:
                // State transitions
                if (orderLine.OrderDetailStatus != (int)OrderStatusType.Cancelled &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Released &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Requested)
                {
                    throw new IllegalStateException((OrderStatusType)orderLine.OrderDetailStatus, "TransferOrderDetail", "UpdateOrderLine");
                }

                // Allocate the data if this is a transition
                if (orderLine.OrderDetailStatus == (int)OrderStatusType.Released)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, (int)orderLine.OrderQty, orderLine, modifiedBy);
                }

                break;

            case OrderStatusType.Released:

                // Guard conditions
                if (orderLine.OrderDetailStatus != (int)OrderStatusType.Cancelled &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Released &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Packed)
                {
                    throw new IllegalStateException((OrderStatusType)orderLine.OrderDetailStatus, "TransferOrderDetail", "UpdateOrderLine");
                }

                // We need to adjust the allocations?
                if (currentOrderLine.OrderQty != orderLine.OrderQty)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, (int)(orderLine.OrderQty - currentOrderLine.OrderQty), orderLine, modifiedBy);
                }

                // Released -> Cancelled = Deallocate
                if (orderLine.OrderDetailStatus == (int)OrderStatusType.Cancelled)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, -(int)orderLine.OrderQty, orderLine, modifiedBy);
                }

                break;

            case OrderStatusType.Packed:
                // Guard conditions
                if (orderLine.OrderDetailStatus != (int)OrderStatusType.Cancelled &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Packed &&
                    orderLine.OrderDetailStatus != (int)OrderStatusType.Shipped)
                {
                    throw new IllegalStateException((OrderStatusType)orderLine.OrderDetailStatus, "TransferOrderDetail", "UpdateOrderLine");
                }

                // We need to adjust the allocations?
                if (currentOrderLine.OrderQty != orderLine.OrderQty)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, (int)(orderLine.OrderQty - currentOrderLine.OrderQty), orderLine, modifiedBy);
                }

                // Packed -> Cancelled = Deallocate
                if (orderLine.OrderDetailStatus == (int)OrderStatusType.Cancelled)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, -(int)orderLine.OrderQty, orderLine, modifiedBy);
                }
                // Packed -> Shipped = Deallocate then Transfer
                else if (orderLine.OrderDetailStatus == (int)OrderStatusType.Shipped)
                {
                    stockLogic.Allocate(currentOrderHeader.OrderFacilityFromObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, -(int)orderLine.OrderQty, orderLine, modifiedBy);
                    stockLogic.Transfer(currentOrderHeader.OrderFacilityFromObject, currentOrderHeader.OrderFacilityToObject, orderLine.OrderGtin, orderLine.OrderGtinLotnum, orderLine, (int)orderLine.OrderQty, modifiedBy);
                }

                break;

            case OrderStatusType.Shipped:
                throw new InvalidOperationException("Shipped orders cannot be modified " + orderLine.OrderDetailNum.ToString());

            case OrderStatusType.Cancelled:
                throw new InvalidOperationException("Cancelled orders cannot be modified");
            }

            // Update
            orderLine.ModifiedBy = modifiedBy;
            orderLine.ModifiedOn = DateTime.Now;
            TransferOrderDetail.Update(orderLine);

            // Return the order line
            return(orderLine);
        }
        /// <summary>
        /// Allocate stock
        /// </summary>
        /// <param name="facility">The facility in which to allocate stock</param>
        /// <param name="gtin">The GTIN of the stock to be allocated</param>
        /// <param name="lot">The lot number of stock to be allocated</param>
        /// <param name="qty">The amount of stock to be allocated</param>
        /// <returns>The <see cref="T:GIIS.DataLayer.ItemTransaction"/> representing the allocation</returns>
        public ItemTransaction Allocate(HealthFacility facility, String gtin, String lot, Int32 qty, TransferOrderDetail orderLine, Int32 modifiedBy)
        {
            // Sanity check
            if (facility == null)
            {
                throw new ArgumentNullException("facility");
            }
            else if (String.IsNullOrEmpty(gtin))
            {
                throw new ArgumentNullException("gtin");
            }
            else if (String.IsNullOrEmpty(lot))
            {
                throw new ArgumentNullException("lot");
            }

            // Adjustment type
            TransactionType allocationType = TransactionType.GetTransactionTypeList().FirstOrDefault(o => o.Name == "Allocation");

            if (allocationType == null)
            {
                throw new InvalidOperationException("Cannot find transaction type 'Allocation'");
            }

            // Get current balance and ensure we have enough to do the balance
            var balance = this.GetCurrentBalance(facility, gtin, lot);

            //if (qty > 0 && balance.Balance < qty)
            //    throw new InvalidOperationException(String.Format("Cannot de-allocate more stock than is available (Request: {0},  Available:{1}, GTIN: {2})", qty, balance, ItemLot.GetItemLotByGtin(gtin).ItemObject.Name));
            //else if (qty < 0 && balance.Allocated < -qty)
            //    throw new InvalidOperationException("Cannot de-allocate more stock than is currently allocated");

            // Create an item transaction
            ItemTransaction retVal = new ItemTransaction()
            {
                Gtin                                                              = gtin,
                GtinLot                                                           = lot,
                HealthFacilityCode                                                = facility.Code,
                ModifiedBy                                                        = modifiedBy,
                ModifiedOn                                                        = DateTime.Now,
                RefId                                                             = orderLine != null?orderLine.OrderNum.ToString() : null,
                                                          RefIdNum                = orderLine != null ? orderLine.OrderDetailNum : 0,
                                                          TransactionDate         = DateTime.Now,
                                                          TransactionQtyInBaseUom = qty,
                                                          TransactionTypeId       = allocationType.Id
            };

            // Update the balance
            //balance.Balance -= qty;
            balance.Allocated += qty;

            // Save
            HealthFacilityBalance.Update(balance);
            retVal.Id = ItemTransaction.Insert(retVal);

            return(retVal);
        }
Beispiel #16
0
        public void SuccessfulCompleteOrderManagementFlowTest()
        {
            try
            {
                // Order logic
                OrderManagementLogic orderLogic = new OrderManagementLogic();


                HealthFacility from      = HealthFacility.GetHealthFacilityByCode("HF888");
                HealthFacility to        = HealthFacility.GetHealthFacilityByCode("HF999");
                DateTime       orderDate = DateTime.Now;

                // Step 1 : Create an Order
                var orderHeader = orderLogic.RequestOrder(from, to, orderDate, 1);

                // Assert that Step 1 actually creates the Order Header
                Assert.IsNotNull(orderHeader.OrderNum);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual(orderDate, orderHeader.OrderSchedReplenishDate);
                Assert.AreEqual((int)OrderStatusType.Requested, orderHeader.OrderStatus);

                // Step 2 : Create order line items
                var orderLine = orderLogic.AddOrderLine(orderHeader, TestData.GTIN_UNDER_TEST, null, 100, Uom.GetUomById(1), 1);
                // Assert line item was created with most recent lot #
                Assert.AreEqual(orderHeader.OrderNum, orderLine.OrderNum);
                Assert.AreEqual(TestData.GTIN_UNDER_TEST, orderLine.OrderGtin);
                Assert.AreEqual(TestData.GTIN_LOT_USE_FIRST, orderLine.OrderGtinLotnum);
                Assert.AreEqual((int)OrderStatusType.Requested, orderLine.OrderDetailStatus);

                // Step 3 : Release the order
                orderHeader = orderLogic.ReleaseOrder(orderHeader, 1);

                // Assert header is updated
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus);

                // Assert that there was a stock transaction for allocation
                var txAllocate = TransactionType.GetTransactionTypeList().First(o => o.Name == "Allocation");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txAllocate.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == 100), "No allocation could be found");

                // Step 4: Pack the order
                orderHeader = orderLogic.PackOrder(orderHeader, 1);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus);

                // Step 5: Ship the order
                orderHeader = orderLogic.ShipOrder(orderHeader, 1);
                Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id);
                Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id);
                Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus);

                // Assert lines are updated
                orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0];
                Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus);

                // Assert allocations are made
                var txTrasnfer = TransactionType.GetTransactionTypeList().First(o => o.Name == "Transfer");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txAllocate.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == -100), "No de-allocation could be found");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txTrasnfer.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == -100), "No transfer out could be found");
                Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF999" &&
                                                                              o.Gtin == TestData.GTIN_UNDER_TEST &&
                                                                              o.GtinLot == TestData.GTIN_LOT_USE_FIRST &&
                                                                              o.TransactionTypeId == txTrasnfer.Id &&
                                                                              o.RefId == orderHeader.OrderNum.ToString() &&
                                                                              o.RefIdNum == orderLine.OrderDetailNum &&
                                                                              o.TransactionQtyInBaseUom == 100), "No transfer in could be found");
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
Beispiel #17
0
        /// <summary>
        /// 从DataTable中获取采购订单明细实体列表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private List <DAL.TransferOrderDetail> GetModelDetailFromDataTable(DataTable dt, out string msg)
        {
            try
            {
                List <DAL.TransferOrderDetail> list = new List <DAL.TransferOrderDetail>();
                msg = "";

                //接口协议文档中定义的字段
                Dictionary <string, string> dataFieldNameDic = new Dictionary <string, string>();

                dataFieldNameDic.Add("NCOrderCode", "订单编号");
                dataFieldNameDic.Add("DetailRowNumber", "行号");
                dataFieldNameDic.Add("CargoCode", "存货编码");
                dataFieldNameDic.Add("CargoName", "存货名称");
                dataFieldNameDic.Add("CargoSpec", "规格");
                dataFieldNameDic.Add("CargoModel", "型号");
                dataFieldNameDic.Add("CargoUnits", "主计量单位");
                dataFieldNameDic.Add("CargoUnitsAssist", "辅单位");
                dataFieldNameDic.Add("ChangeRatio", "换算率");
                dataFieldNameDic.Add("NumOriginalPlanAssist", "辅数量");
                dataFieldNameDic.Add("NumOriginalPlan", "数量");
                dataFieldNameDic.Add("Lot", "批次号");
                dataFieldNameDic.Add("ProductDate", "生产日期");
                dataFieldNameDic.Add("OutWHName", "调出仓库");
                dataFieldNameDic.Add("InWHName", "调入仓库");
                dataFieldNameDic.Add("OutWHNameAssist", "出货仓库");
                dataFieldNameDic.Add("OutDept", "调出部门");
                dataFieldNameDic.Add("OutOperator", "调出部门业务员");
                dataFieldNameDic.Add("InDept", "调入部门");
                dataFieldNameDic.Add("InOperator", "调入部门业务员");
                dataFieldNameDic.Add("OutDeptAssist", "出货部门");
                dataFieldNameDic.Add("OutOperatorAssist", "出货部门业务员姓名");
                dataFieldNameDic.Add("OutArea", "调出货位");
                dataFieldNameDic.Add("InArea", "调入货位");
                dataFieldNameDic.Add("OutAreaAssist", "出货货位");

                if (dt == null || dt.Rows.Count == 0)
                {
                    msg = "用友系统返回数据集中无数据!";
                    return(new List <TransferOrderDetail>());
                }

                StringBuilder errorColName = new StringBuilder();
                //检查数据集中是否存在指定字段
                foreach (KeyValuePair <string, string> kvp in dataFieldNameDic)
                {
                    if (dt.Columns.Contains(kvp.Key) == false)
                    {
                        errorColName.Append(Environment.NewLine);
                        errorColName.Append(kvp.Value);
                        errorColName.Append("-");
                        errorColName.Append(kvp.Key);
                    }
                }
                if (errorColName.Length > 0)
                {
                    errorColName.Insert(0, "用友系统返回的数据集中未包含如下字段,不能进行有效解析!");
                    msg = errorColName.ToString();
                    return(new List <TransferOrderDetail>());;
                }

                //遍历数据集创建实体
                foreach (DataRow dr in dt.Rows)
                {
                    TransferOrderDetail newModel = new TransferOrderDetail();

                    newModel.NCOrderCode     = DataCheckHelper.GetCellString(dr["NCOrderCode"]);
                    newModel.DetailRowNumber = DataCheckHelper.GetCellString(dr["DetailRowNumber"]);

                    newModel.CargoCode = DataCheckHelper.GetCellString(dr["CargoCode"]);
                    string cargoCode = DbCommonMethod.ParsingCargoCode(newModel.CargoCode);
                    if (string.IsNullOrEmpty(cargoCode))
                    {
                        throw new ApplicationException("单号" + newModel.NCOrderCode + ",商品不存在:" + newModel.CargoCode);
                    }

                    newModel.CargoName  = DataCheckHelper.GetCellString(dr["CargoName"]);
                    newModel.CargoSpec  = DataCheckHelper.GetCellString(dr["CargoSpec"]);
                    newModel.CargoModel = DataCheckHelper.GetCellString(dr["CargoModel"]);
                    newModel.CargoUnits = DataCheckHelper.GetCellString(dr["CargoUnits"]);
                    //newModel = DataCheckHelper.GetCellString(dr["CargoUnitsAssist"]);
                    //newModel = DataCheckHelper.GetCellString(dr["ChangeRatio"]);
                    //newModel = DataCheckHelper.GetCellString(dr["NumOriginalPlanAssist"]);

                    //数量
                    if (!string.IsNullOrEmpty(DataCheckHelper.GetCellString(dr["NumOriginalPlan"])))
                    {
                        double d;
                        if (double.TryParse(DataCheckHelper.GetCellString(dr["NumOriginalPlan"]), out d))
                        {
                            newModel.NumOriginalPlan = d;
                        }
                    }

                    //newModel = DataCheckHelper.GetCellString(dr["Lot"]);
                    //newModel = DataCheckHelper.GetCellString(dr["ProductDate"]);

                    newModel.OutWHName = DataCheckHelper.GetCellString(dr["OutWHName"]);
                    if (newModel.OutWHName != "")
                    {
                        newModel.OutWHCode = DbCommonMethod.ParsingWarehouse(newModel.OutWHName);
                        throw new ApplicationException("单号" + newModel.NCOrderCode + ",仓库不存在:" + newModel.OutWHName);
                    }

                    newModel.InWHName = DataCheckHelper.GetCellString(dr["InWHName"]);
                    if (newModel.InWHName != "")
                    {
                        newModel.InWHCode = DbCommonMethod.ParsingWarehouse(newModel.InWHName);
                        throw new ApplicationException("单号" + newModel.NCOrderCode + ",仓库不存在:" + newModel.InWHName);
                    }

                    //newModel = DataCheckHelper.GetCellString(dr["OutWHNameAssist"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutDept"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutOperator"]);
                    //newModel = DataCheckHelper.GetCellString(dr["InDept"]);
                    //newModel = DataCheckHelper.GetCellString(dr["InOperator"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutDeptAssist"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutOperatorAssist"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutArea"]);
                    //newModel = DataCheckHelper.GetCellString(dr["InArea"]);
                    //newModel = DataCheckHelper.GetCellString(dr["OutAreaAssist"]);

                    newModel.DetailRowStatus = 2;//初始态
                    newModel.OrderCode       = newModel.OrderCode;
                    newModel.NCOrderCode     = newModel.NCOrderCode;

                    List <TransferOrderDetail> existTransferOrderDetail = (from r in list where r.NCOrderCode == newModel.NCOrderCode && r.DetailRowNumber == newModel.DetailRowNumber select r).ToList <TransferOrderDetail>();
                    if (existTransferOrderDetail == null || existTransferOrderDetail.Count == 0)//过滤重复数据
                    {
                        list.Add(newModel);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(new List <TransferOrderDetail>());;
            }
        }