Exemplo n.º 1
0
        internal void InitializeCompleted()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                Types = new ObservableCollection <Transactions>();
                if (LoggedUserInfo.CurrLang == 0)
                {
                    Types.Add(new Transactions {
                        TransactionId = 0, TransactionName = "أمر الشراء"
                    });
                    Types.Add(new Transactions {
                        TransactionId = 1, TransactionName = "صباغة"
                    });
                    Types.Add(new Transactions {
                        TransactionId = 2, TransactionName = "Transfer"
                    });
                }
                else
                {
                    Types.Add(new Transactions {
                        TransactionId = 0, TransactionName = "Purshase Order"
                    });
                    Types.Add(new Transactions {
                        TransactionId = 1, TransactionName = "Dyeing"
                    });
                    Types.Add(new Transactions {
                        TransactionId = 2, TransactionName = "Transfer"
                    });
                }
                Client = new CRUD_ManagerServiceClient();
                GetItemPermissions(PermissionItemName.Reservation.ToString());
                ObservableCollection <GetItemOnhand_Result> OnHandList = new ObservableCollection <GetItemOnhand_Result>();
                Client.GetReservationMainDetailByFabricCompleted += (s, f) =>
                {
                    if (f.OnHandList != null)
                    {
                        OnHandList = f.OnHandList;
                    }
                    TransactionHeader = new TblReservationHeaderViewModel();
                    foreach (var variable in f.Result)
                    {
                        TransactionHeader.TransactionMainDetails.Add(ReservationMappers.MaptoViewModel(variable, f.mainFabricList, OnHandList));
                    }
                    Loading = false;
                };
                Client.GetAllSeasonsCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (SeasonList.All(x => x.Iserial != row.Iserial))
                        {
                            SeasonList.Add(new TblLkpSeason().InjectFrom(row) as TblLkpSeason);
                        }
                    }
                };
                Client.GetAllSeasonsAsync();
                Client.GetAllBrandsCompleted += (s, sv) =>
                {
                    BrandsList.Clear();
                    foreach (var variable in sv.Result.OrderBy(x => x.Brand_Code))
                    {
                        BrandsList.Add(variable);
                    }
                };
                Client.GetAllBrandsAsync(0);
                TransactionGuid   = Guid.NewGuid().ToString();
                TransactionHeader = new TblReservationHeaderViewModel {
                    DocDate = DateTime.Now.Date
                };
                SelectedMainDetails = new TblReservationMainDetailsViewModel();

                Client.GetReservationHeaderListCompleted += (d, i) =>
                {
                    foreach (var item in i.Result)
                    {
                        TransactionHeaderList.Add(ReservationMappers.MaptoViewModel(item));
                    }
                };

                lkpClient.GetTblBrandSectionLinkCompleted += (x, sv) =>
                {
                    BrandSectionList.Clear();
                    foreach (var row in sv.Result)
                    {
                        BrandSectionList.Add(row.TblLkpBrandSection1);
                    }
                };
                SalesorderList = new ObservableCollection <CRUD_ManagerServiceSalesOrderDto>();

                SalesorderList.CollectionChanged += SalesorderList_CollectionChanged;

                Client.GetPurchaseOrderSalesOrdersCompleted += (d, s) =>
                {
                    foreach (var variable in s.Result)
                    {
                        if (!SalesorderList.Any(
                                x =>
                                x.SalesOrder.Contains(variable.SalesOrder) &&
                                x.SalesOrderColor.Contains(variable.SalesOrderColor)) && !SelectedMainDetails.ReservationDetailsViewModelList.Any(x => x.SalesOrder.Contains(variable.SalesOrder) &&
                                                                                                                                                  x.SalesOrderColor.Contains(variable.SalesOrderColor)))
                        {
                            SalesorderList.Add(variable);
                        }
                    }
                };

                Client.GetPurchaseOrderLinesCompleted += (s, f) =>
                {
                    foreach (var item in f.Result.Where(item => !OrderLineList.Contains(FabricInspectionMapper.MapToOrderLine(item))))
                    {
                        OrderLineList.Add(FabricInspectionMapper.MapToOrderLine(item));
                    }
                    Loading = false;
                };


                Client.GetRecivedDyedOrdersCompleted += (s, f) =>
                {
                    foreach (var item in f.Result.Where(item => !OrderLineList.Contains(FabricInspectionMapper.MapToOrderLine(item))))
                    {
                        OrderLineList.Add(FabricInspectionMapper.MapToOrderLine(item));
                    }
                };
                Client.GetTransferInventDimLinesCompleted += (s, f) =>
                {
                    foreach (var item in f.Result.Where(item => !OrderLineList.Contains(FabricInspectionMapper.MapToOrderLine(item))))
                    {
                        OrderLineList.Add(FabricInspectionMapper.MapToOrderLine(item));
                    }
                };
                Client.GetReservationMainDetailsCompleted += (s, f) =>
                {
                    foreach (var variable in f.Result)
                    {
                        if (variable.Inspected)
                        {
                            Client.GetResInspectionListAsync(variable.LineNum, TransactionHeader.TransOrder);
                        }
                        //f.mainFabricList;
                        TransactionHeader.TransactionMainDetails.Add(ReservationMappers.MaptoViewModel(variable, f.mainFabricList));
                    }
                };

                Client.SaveReservationCompleted += (a, f) =>
                {
                    if (f.ErrorExists)
                    {
                        var visList = TransactionHeader.TransactionMainDetails.Where(x => f.Result.All(s => s.Fabric == x.Fabric && s.FabricColor == x.FabricColor));

                        foreach (var item in TransactionHeader.TransactionMainDetails)
                        {
                            item.ErrorVisbility = visList.Contains(item) ? Visibility.Visible : Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        var tblFabricInspectionDetail = f.Result.FirstOrDefault();
                        if (tblFabricInspectionDetail != null)
                        {
                            TransactionHeader.Iserial = tblFabricInspectionDetail.Tbl_ReservationHeader;
                        }
                        TransactionHeader.TransactionMainDetails.Clear();
                        foreach (var item in f.Result)
                        {
                            TransactionHeader.TransactionMainDetails.Add((TblReservationMainDetailsViewModel) new TblReservationMainDetailsViewModel().InjectFrom(item));
                        }
                        var currentUi = Thread.CurrentThread.CurrentUICulture;
                        if (currentUi.DisplayName == "العربية")
                        {
                            MessageBox.Show("Saved");
                        }
                        else
                        {
                            MessageBox.Show("Saved");
                        }
                    }
                };


                Client.GenerateReservationFromPlanCompleted += (s, sv) => Client.GetReservationMainDetailsAsync(TransactionHeader.Iserial);
                Client.GetSalesOrderReservationCompleted    += (s, sv) =>
                {
                    GenericMapper.InjectFromObCollection(SelectedMainDetails.ReservationDetailsViewModelList, sv.Result);
                    foreach (var item in (SelectedMainDetails.ReservationDetailsViewModelList))
                    {
                        item.Tbl_ReservationMainDetails = SelectedMainDetails.Iserial;
                    }
                };
                Client.ReservationLineNumCompleted += (s, p) =>
                {
                    var lines = new ObservableCollection <decimal>(p.Result);

                    if (TransactionHeader.TransactionMainDetails.Count() != 0)
                    {
                        foreach (var variable in TransactionHeader.TransactionMainDetails.Select(x => x.LineNum))
                        {
                            lines.Add(variable);
                        }
                    }
                    if (SortBy == null)
                    {
                        SortBy = "it.PURCHQTY";
                    }
                    if (TransactionHeader.TransactionType == 0)
                    {
                        Client.GetPurchaseOrderLinesAsync(OrderLineList.Count, PageSize, "ccm", TransactionHeader.TransOrder, lines, "it.PURCHQTY desc", Filter, ValuesObjects);
                    }
                    if (TransactionHeader.TransactionType == 1)
                    {
                        Client.GetRecivedDyedOrdersAsync(OrderLineList.Count, PageSize, TransactionHeader.TransOrder, lines, "it.PURCHQTY desc", Filter, ValuesObjects);
                    }
                    else if (TransactionHeader.TransactionType == 2)
                    {
                        Client.GetTransferInventDimLinesAsync(OrderLineList.Count, PageSize, "ccm", TransactionHeader.TransOrder, lines, "it.PURCHQTY desc", Filter, ValuesObjects);
                    }
                };
            }
        }