Пример #1
0
        //Timer T;

        public async void CreateOrder()
        {
            var Orders = await Api.Controller.getLstOrderNotFinishAsync(Setting.SelectedLine.ID);

            if (Orders != null)
            {
                if (Orders.Count > 0)
                {
                    return;
                }
            }
            var ProductionDtl = new ProductionDtl()
            {
                Amount       = Setting.DefaultLots,
                Factory_ID   = 1,
                Working_Date = App.TodayDate,
                Shift_ID     = 1,
                Line_ID      = Setting.SelectedLine.ID,
                Product_ID   = Setting.SelectedProduct.ID,
                Message      = "waiting"
            };

            if (Api.Controller.CreateOrder(ProductionDtl))
            {
                //LstOrderNotFinish.Clear();
                //Api.Controller.getLstOrderNotFinish(2)?.ForEach(x => LstOrderNotFinish.Add(x));
                //MessageBox.Show("Create order successfully");
            }
            else
            {
                MessageBox.Show("Create order failed, something happened");
            }
        }
Пример #2
0
        public bool ConfirmOrder(ProductionDtl obj)
        {
            obj.Finished = true;
            var jsonObj = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

            using (var content = new StringContent(jsonObj, Encoding.UTF8, "application/json"))
            {
                try
                {
                    var ret = _httpClient.PutAsync("production-dtl", content).Result;
                    return(ret.IsSuccessStatusCode);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Пример #3
0
        public bool CreateOrder(ProductionDtl obj)
        {
            var jsonObj = JsonConvert.SerializeObject(obj);

            using (var content = new StringContent(jsonObj, Encoding.UTF8, "application/json"))
            {
                try
                {
                    var ret = _httpClient.PostAsync("production-dtl", content).Result;
                    var res = ret.Content.ReadAsStringAsync().Result;
                    return(ret.IsSuccessStatusCode);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Пример #4
0
        public async void CreateOrder()
        {
            //var Plan = await Api.Controller.GetProductionPlanAsync(Setting.SelectedLine.ID);
            var Orders = await Api.Controller.getLstOrderNotFinishAsync(Setting.SelectedLine.ID);

            if (Orders != null)
            {
                var Order = Orders.Where(x => x.ID == Setting.SelectedProduct.ID).FirstOrDefault();
                if (Order != null)
                {
                    MessageBox.Show("Please confirm current order");
                    return;
                }
            }

            var ProductionDtl = new ProductionDtl()
            {
                Amount       = Amount,
                Factory_ID   = 1,
                Working_Date = App.TodayDate,
                Shift_ID     = App.CurrentShift,
                Line_ID      = Setting.SelectedLine.ID,
                Product_ID   = Setting.SelectedProduct.ID,
                Message      = "waiting"
            };

            if (Api.Controller.CreateOrder(ProductionDtl))
            {
                //LstOrderNotFinish.Clear();
                //Api.Controller.getLstOrderNotFinish(2)?.ForEach(x => LstOrderNotFinish.Add(x));
                MessageBox.Show("Create order successfully");
            }
            else
            {
                MessageBox.Show("Create order failed, something happened");
            }
        }
Пример #5
0
        public void CreateOrder()
        {
            var ProductionDtl = new ProductionDtl()
            {
                Amount       = Amount,
                Factory_ID   = 1,
                Working_Date = App.TodayDate,
                Shift_ID     = App.CurrentShift,
                Line_ID      = Setting.SelectedLine.ID,
                Product_ID   = Setting.SelectedProduct.ID,
                Message      = "WAITTING"
            };

            if (Api.Controller.CreateOrder(ProductionDtl))
            {
                LstOrderNotFinish.Clear();
                Api.Controller.getLstOrderNotFinish(Setting.SelectedLine.ID)?.ForEach(x => LstOrderNotFinish.Add(x));
                MessageBox.Show("Create order successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Create order failed, something happened", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #6
0
        private async void UpdateUILoop(CancellationToken token)
        {
            try
            {
                //var ProductionPlan1 = await Api.Controller.GetLinePlan(new ProductionPlan()
                //{
                //    Factory_ID = 1,
                //    Working_Date = TodayDate,
                //    Product_ID = Setting.SelectedProduct.ID,
                //    Line_ID = Setting.SelectedLine.ID,
                //    Shift_ID = CurrentShift
                //});
                var Plans = Api.Controller.GetProductionPlan(Setting.SelectedLine.ID).Where(x => x.Is_Active == true).ToList();
                if (Plans == null)
                {
                    IN.CountingSensor.OnPinValueChanged -= CountingSensor_OnPinValueChanged;
                    return;
                }
                else
                {
                    IN.CountingSensor.OnPinValueChanged += CountingSensor_OnPinValueChanged;
                }

                while (true)
                {
                    token.ThrowIfCancellationRequested();
                    ProductionDtl LastOrder = null;
                    var           Orders    = await Api.Controller.getLstOrderNotFinishAsync(Setting.SelectedLine.ID);

                    if (Orders != null)
                    {
                        if (Orders.Count > 0)
                        {
                            LastOrder = Orders.Where(x => x.Product_ID == Setting.SelectedProduct.ID).First();
                        }
                    }
                    if (LastOrder != null)
                    {
                        UnconfirmOrder = LastOrder;
                        OrderDuration  = "No action";

                        if (WorkingStatus == WorkingStatus.Stop)
                        {
                            Duration      = DateTime.Now - StartTime;
                            OrderDuration = $"{LastOrder.Message?.ToUpper()} | {Duration.ToString("hh\\:mm\\:ss")}";
                        }
                        else if (WorkingStatus == WorkingStatus.Order)
                        {
                            StartTime     = DateTime.Now;
                            OrderDuration = $"{LastOrder.Message?.ToUpper()} | {Duration.ToString("hh\\:mm\\:ss")}";
                        }
                        else
                        {
                            StartTime = DateTime.Now;
                        }
                    }
                    else
                    {
                        OrderDuration  = "No Order";
                        UnconfirmOrder = null;
                    }
                    //var ProductionPlan = Api.Controller.GetProductionPlan(Setting.SelectedLine.ID);
                    //var ProductionPlan = await Api.Controller.GetProductionPlan(new ProductionPlan()
                    //{
                    //    Factory_ID = 1,
                    //    Working_Date = TodayDate,
                    //    Product_ID = Setting.SelectedProduct.ID,
                    //    Line_ID = Setting.SelectedLine.ID,
                    //    Shift_ID = CurrentShift
                    //});
                    Plans = (await Api.Controller.GetProductionPlanAsync(Setting.SelectedLine.ID)).ToList();
                    if (Plans != null)
                    {
                        var Plan = Plans.Where(x => x.Product_ID == Setting.SelectedProduct.ID &&
                                               x.Working_Date == TodayDate).FirstOrDefault();
                        if (Plan == null)
                        {
                            foreach (ProductionPlan P in Plans)
                            {
                                if (P.Working_Date != TodayDate)
                                {
                                    P.Is_Active = false;
                                    await Api.Controller.UpdatePlan(P);
                                }
                            }
                            var success = Api.Controller.NewProductionPlan(new ProductionPlan()
                            {
                                Product_ID = Setting.SelectedProduct.ID,
                                //Name = Setting.SelectedProduct.Name,
                                Factory_ID    = 1,
                                Line_ID       = Setting.SelectedLine.ID,
                                Working_Date  = App.TodayDate,
                                Ordered_Qty   = PlanView.order,
                                Remain_Qty    = PlanView.remain,
                                Good_Prod_Qty = PlanView.elapsed,
                                Is_Active     = true
                                                //Shift_ID = SelectedShift.ID,
                            });
                        }
                        else
                        {
                            PlanView.elapsed = Plan.Good_Prod_Qty;
                            PlanView.remain  = Plan.Remain_Qty;
                            PlanView.order   = Plan.Ordered_Qty;
                        }

                        if (PlanView.remain > 0)
                        {
                            if (PlanView.remain <= Setting.DefaultLevel)
                            {
                                WorkingStatus = WorkingStatus.Order;
                                Ellipse       = new SolidColorBrush(Colors.Orange);
                            }
                            else if (PlanView.remain > Setting.DefaultLevel)
                            {
                                WorkingStatus = WorkingStatus.Normal;
                                Ellipse       = new SolidColorBrush(Colors.Green);
                            }
                        }
                        if (PlanView.remain == 0)
                        {
                            WorkingStatus = WorkingStatus.Stop;
                            Ellipse       = new SolidColorBrush(Colors.Red);
                        }
                    }
                    await Task.Delay(1000);
                }
            }
            catch
            {
            }
        }