Ejemplo n.º 1
0
        private async Task ExecuteRefreshOrders()
        {
            try
            {
                int?erpid      = SelectedOrder?.ERPID;
                int?orderid    = SelectedOrder?.OrderID;
                int?ao_erpid   = ActiveOrder?.ERPID;
                int?ao_orderid = ActiveOrder?.OrderID;
                _suborderid = SelectedSubOrder?.ID;
                _commandid  = SelectedCommand?.WMSID;

                var ao = _dbservicewms.GetOrders((int)EnumWMSOrderStatus.Active, (int)EnumWMSOrderStatus.Active).FirstOrDefault();
                if (ao != null)
                {
                    ActiveOrder = new ReleaseOrderViewModel
                    {
                        ERPID       = ao.ERP_ID,
                        OrderID     = ao.OrderID,
                        TUID        = ao.TU_ID,
                        BoxID       = ao.Box_ID,
                        SKUID       = ao.SKU_ID,
                        SKUBatch    = ao.SKU_Batch,
                        Destination = ao.Destination,
                        ReleaseTime = ao.ReleaseTime,
                        Status      = (EnumWMSOrderStatus)ao.Status
                    }
                }
                ;
                else
                {
                    ActiveOrder = null;
                }
//                if(ao_erpid != ActiveOrder?.ERPID || ao_orderid != ActiveOrder?.OrderID)
//                    await ExecuteRefreshCommandWMS();

                var orders = await _dbservicewms.GetOrdersDistinct(DateTime.Now.AddSeconds(1), DateTime.Now, (int)EnumWMSOrderStatus.OnTargetPart);

                _donotrefreshsuborder = true;
                DataListOrder.Clear();
                foreach (var p in orders)
                {
                    DataListOrder.Add(new ReleaseOrderViewModel
                    {
                        ERPID       = p.ERPID,
                        OrderID     = p.OrderID,
                        TUID        = p.TUID,
                        BoxID       = p.BoxID,
                        SKUID       = p.SKUID,
                        SKUBatch    = p.SKUBatch,
                        Destination = p.Destination,
                        ReleaseTime = p.ReleaseTime,
                        LastChange  = p.LastChange,
                        Status      = (EnumWMSOrderStatus)p.Status
                    });
                }
                foreach (var l in DataListOrder)
                {
                    l.Initialize(_warehouse);
                }
                _donotrefreshsuborder = false;
                if (orderid != null)
                {
                    SelectedOrder = DataListOrder.FirstOrDefault(p => p.ERPID == erpid && p.OrderID == orderid);
                }
                else
                {
                    SelectedOrder = DataListOrder.FirstOrDefault();
                }
                if (SelectedOrder == null)
                {
                    await ExecuteRefreshSubOrder();
                }
            }
            catch (Exception e)
            {
                _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                    string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
            }
        }