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();
                };
            }
        }