Esempio n. 1
0
        public CostCenterOrganizationUnitViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                GetItemPermissions(PermissionItemName.CostCenterOrganizationUnit.ToString());
                MainRowList = new ObservableCollection <TblCostCenterOrganizationUnitViewModel>();

                //var CostCenterTypeClient = new GlServiceClient();
                //CostCenterTypeClient.GetGenericCompleted += (s, sv) => { DepreciationMethodList = sv.Result; };
                //CostCenterTypeClient.GetGenericAsync("TblDepreciationMethod", "%%", "%%", "%%", "Iserial", "ASC",
                //    LoggedUserInfo.DatabasEname);
                Glclient.UpdateOrInsertTblCostCenterOrganizationUnitsCompleted += (s, x) =>
                {
                    if (x.Error != null)
                    {
                        MessageBox.Show(x.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(x.outindex).InjectFrom(x.Result);
                    }
                    catch (Exception)
                    {
                    }
                    Loading = false;
                };

                Glclient.GetTblCostCenterAsync(0, int.MaxValue, null, "It.Iserial", null, null, LoggedUserInfo.DatabasEname, LoggedUserInfo.Iserial, 0, 0);
                Glclient.GetTblCostCenterCompleted += (s, sv) =>
                {
                    CostCenterList = sv.Result;
                };
                Glclient.DeleteTblCostCenterOrganizationUnitCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    SelectedMainRow = new TblCostCenterOrganizationUnitViewModel();
                };
                Glclient.GetPayrollOrganizationUnitAsync();
                Glclient.GetPayrollOrganizationUnitCompleted += (s, sv) =>
                {
                    PayrollOrganizationUnitList = sv.Result;
                };
                Glclient.GetTblCostCenterOrganizationUnitCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblCostCenterOrganizationUnitViewModel();
                        newrow.InjectFrom(row);

                        newrow.CostCenterPerRow = new TblCostCenter();
                        if (row.TblCostCenter1 != null)
                        {
                            newrow.CostCenterPerRow = row.TblCostCenter1;
                        }

                        //newrow.SumCostCenterPerRow = new TblCostCenter();
                        //if (row.TblCostCenter2 != null) newrow.SumCostCenterPerRow = row.TblCostCenter2;
                        MainRowList.Add(newrow);
                    }

                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (MainRowList.Any() && (SelectedMainRow == null))
                    {
                        SelectedMainRow = MainRowList.FirstOrDefault();
                    }
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };
                GetMaindata();
            }
        }