Beispiel #1
0
        public void AddNewMainRow(bool checkLastRow)
        {
            if (AllowAdd != true)
            {
                MessageBox.Show(strings.AllowAddMsg);
                return;
            }
            var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow));

            if (checkLastRow)
            {
                var valiationCollection = new List <ValidationResult>();

                var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true);

                if (!isvalid)
                {
                    return;
                }
            }

            var firstOrDefault = BrandList.FirstOrDefault();

            var newrow = new TblStandardBomHeaderViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
            if (firstOrDefault != null)
            {
                newrow.Brand = firstOrDefault.Brand_Code;
            }
        }
Beispiel #2
0
        public StandardBomViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                GetItemPermissions(PermissionItemName.StandardBomForm.ToString());
                GetSeason();
                var calculationClient = new CRUD_ManagerServiceClient();
                calculationClient.GetGenericCompleted += (s, sv) =>
                {
                    BomCalcMethodList = sv.Result;
                };
                calculationClient.GetGenericAsync("BOM_CalcMethod", "%%", "%%", "%%", "Iserial", "ASC");
                //Client.GetTblPaymentScheduleCompleted += (s, sv) =>
                //{
                //    PaymentScheduleList = sv.Result;
                //};
                //Client.GetTblPaymentScheduleAsync(0, int.MaxValue, "it.Iserial", null, null);
                var uomClient = new CRUD_ManagerServiceClient();
                uomClient.GetGenericCompleted += (s, sv) =>
                {
                    UomList = sv.Result;
                };
                uomClient.GetGenericAsync("tbl_lkp_UoM", "%%", "%%", "%%", "Iserial", "ASC");

                MainRowList     = new SortableCollectionView <TblStandardBomHeaderViewModel>();
                SelectedMainRow = new TblStandardBomHeaderViewModel();
                //
                MainRowList.CollectionChanged += MainRowList_CollectionChanged;

                var factorGroupClient = new CRUD_ManagerServiceClient();
                factorGroupClient.GetGenericCompleted += (s, sv) =>
                {
                    FactoryGroupList = sv.Result;
                };
                factorGroupClient.GetGenericAsync("TblFactoryGroup", "%%", "%%", "%%", "Iserial", "ASC");

                var complixtyGroupClient = new CRUD_ManagerServiceClient();
                complixtyGroupClient.GetGenericCompleted += (s, sv) =>
                {
                    //complix GroupList = sv.Result;
                };
                factorGroupClient.GetGenericAsync("TblFactoryGroup", "%%", "%%", "%%", "Iserial", "ASC");

                Client.GetAllBrandsCompleted += (s, sv) =>
                {
                    BrandList = sv.Result;
                };
                Client.GetAllBrandsAsync(LoggedUserInfo.Iserial);

                Client.GetTblStandardBOMHeaderCompleted += (s, sv) =>
                {
                    Loading = false;
                    if (sv.Result != null)
                    {
                        foreach (var row in sv.Result)
                        {
                            var newrow = new TblStandardBomHeaderViewModel();

                            newrow.InjectFrom(row);
                            if (!MainRowList.Contains(newrow))
                            {
                                newrow.SeasonPerRow          = new TblLkpSeason();
                                newrow.FactoryGroupPerRow    = new GenericTable();
                                newrow.ComplexityGroupPerRow = new GenericTable();
                                if (BrandSectionList.All(x => x.Iserial != row.TblLkpBrandSection1.Iserial))
                                {
                                    BrandSectionList.Add(new LkpData.TblLkpBrandSection().InjectFrom(row.TblLkpBrandSection1) as LkpData.TblLkpBrandSection);
                                }
                                if (SeasonList.All(x => x.Iserial != row.TblLkpSeason))
                                {
                                    SeasonList.Add(new TblLkpSeason().InjectFrom(row.TblLkpSeason1) as TblLkpSeason);
                                }
                                newrow.FactoryGroupPerRow = new GenericTable().InjectFrom(row.TblFactoryGroup1) as GenericTable;
                                if (row.TblComplexityGroup1 != null)
                                {
                                    newrow.ComplexityGroupPerRow = new GenericTable().InjectFrom(row.TblComplexityGroup1) as GenericTable;
                                }
                                newrow.SectionPerRow = row.TblLkpBrandSection1;

                                newrow.SeasonPerRow = SeasonList.FirstOrDefault(x => x.Iserial == newrow.TblLkpSeason);

                                MainRowList.Add(newrow);
                            }
                        }
                    }
                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (MainRowList.Any() && (SelectedMainRow == null || SelectedMainRow.Iserial == 0))
                    {
                        SelectedMainRow = MainRowList.FirstOrDefault();
                    }

                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }

                    if (Export)
                    {
                        Export = false;

                        var handler = ExportCompleted;
                        if (handler != null)
                        {
                            handler(this, EventArgs.Empty);
                        }
                        //ExportGrid.ExportExcel("Style");
                    }
                };
                GetMaindata();
                Client.UpdateOrInsertTblStandardBOMHeaderCompleted += (s, sv) =>
                {
                    var savedRow = MainRowList.ElementAt(sv.outindex);

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(sv.Result);
                    }

                    Loading = false;
                };

                Client.DeleteTblStandardBOMHeaderCompleted += (s, ev) =>
                {
                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result.Iserial);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                    Loading = false;
                    if (!MainRowList.Any())
                    {
                        AddNewMainRow(false);
                    }
                };

                Client.DeleteTblStandardBOMCompleted += (s, sv) =>
                {
                    Loading = false;
                    if (sv.Error != null)
                    {
                        throw sv.Error;
                    }

                    var oldrow = SelectedMainRow.BomList.FirstOrDefault(x => x.Iserial == sv.Result);
                    if (oldrow != null)
                    {
                        SelectedMainRow.BomList.Remove(oldrow);
                    }
                };

                Client.GetTblStandardBOMCompleted += (s, sv) =>
                {
                    SelectedMainRow.BomList.Clear();
                    foreach (var row in sv.Result)
                    {
                        var newrow = new BomViewModel
                        {
                            BOM_CalcMethodPerRow = new GenericTable().InjectFrom(row.BOM_CalcMethod) as GenericTable,
                            BOM_FabricTypePerRow = new GenericTable().InjectFrom(row.BOM_FabricType) as GenericTable
                        };

                        newrow.ColorPerRow = new TblColor();
                        newrow.ColorPerRow = row.TblColor1;

                        newrow.InjectFrom(row);
                        newrow.ItemPerRow = sv.itemsList.SingleOrDefault(x => x.Iserial == row.BOM_Fabric);

                        SelectedMainRow.BomList.Add(newrow);
                    }
                    if (SelectedMainRow.BomList.Count == 0)
                    {
                        AddBom(false);
                    }
                };

                Client.UpdateOrInsertTblStandardBOMCompleted += (s, sv) =>
                {
                    Loading = false;
                    if (sv.Error != null)
                    {
                        MessageBox.Show(sv.Error.Message);
                        return;
                    }

                    GetSalesOrderBom();
                };
            }
        }