Example #1
0
        public void AddNewSubDetailRow(bool checkLastRow)
        {
            var currentRowIndex = (SelectedMainRow.SubDetailList.IndexOf(SelectedSubDetailRow));

            if (checkLastRow)
            {
                var lastrow             = SelectedMainRow.SubDetailList.ElementAtOrDefault(currentRowIndex);
                var valiationCollection = new List <ValidationResult>();

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

                if (!isvalid)
                {
                    return;
                }
            }
            if (AllowUpdate != true)
            {
                MessageBox.Show(strings.AllowAddMsg);
                return;
            }

            var newrow = new TblJournalSettingCostCenterViewModel
            {
                TblJournalSetting = SelectedMainRow.Iserial,
            };

            SelectedMainRow.SubDetailList.Insert(currentRowIndex + 1, newrow);
            SelectedSubDetailRow = newrow;
            if (ExportGrid != null)
            {
                ExportGrid.BeginEdit();
            }
        }
Example #2
0
        public JournalSettingViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.JournalSetting.ToString());
                Glclient = new GlServiceClient();

                MainRowList     = new ObservableCollection <TblJournalSettingViewModel>();
                SelectedMainRow = new TblJournalSettingViewModel();

                var journalAccountTypeClient = new GlServiceClient();
                journalAccountTypeClient.GetGenericCompleted += (s, sv) =>
                {
                    JournalAccountTypeList = sv.Result;
                };
                journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname);


                Glclient.GetTblJournalSettingCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblJournalSettingViewModel();
                        newrow.InjectFrom(row);

                        MainRowList.Add(newrow);
                    }

                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (MainRowList.Any() && (SelectedMainRow == null))
                    {
                        SelectedMainRow = MainRowList.FirstOrDefault();
                    }
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                    if (Export)
                    {
                        Export      = false;
                        AllowExport = true;
                        //ExportGrid.ExportExcel("Account");
                    }
                };

                Glclient.UpdateOrInsertTblJournalSettingsCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                    Loading = false;
                };
                Glclient.DeleteTblJournalSettingCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    foreach (var item in ev.Result.ToList())
                    {
                        var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == item);
                        if (oldrow != null)
                        {
                            MainRowList.Remove(oldrow);
                        }
                    }

                    if (!MainRowList.Any())
                    {
                        AddNewMainRow(false);
                    }
                };

                Glclient.GetTblJournalSettingEntityCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblJournalSettingEntityViewModel();
                        newrow.JournalAccountTypePerRow = new GenericTable();
                        newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType1);

                        newrow.JournalPerRow = new TblJournal();
                        newrow.JournalPerRow.InjectFrom(row.TblJournal1);
                        newrow.EntityPerRow =
                            sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == row.TblJournalAccountType &&
                                                         x.Iserial == row.EntityAccount && x.scope == row.Scope);
                        newrow.InjectFrom(row);
                        SelectedMainRow.DetailsList.Add(newrow);
                    }
                    Loading         = false;
                    DetailFullCount = sv.fullCount;
                    if (SelectedMainRow.DetailsList.Any() && (SelectedDetailRow == null))
                    {
                        SelectedDetailRow = SelectedMainRow.DetailsList.FirstOrDefault();
                    }

                    if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count(x => x.Iserial >= 0) == 0)
                    {
                        AddNewDetailRow(false);
                    }

                    if (Export)
                    {
                        AllowExport = true;
                        Export      = false;
                    }
                };

                Glclient.UpdateOrInsertTblJournalSettingEntitysCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.DetailsList.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                    Loading = false;
                };

                Glclient.DeleteTblJournalSettingEntityCompleted += (s, ev) =>
                {
                    Loading = false;

                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    foreach (var item in ev.Result.ToList())
                    {
                        var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == item);
                        if (oldrow != null)
                        {
                            SelectedMainRow.DetailsList.Remove(oldrow);
                        }
                    }
                    if (!SelectedMainRow.DetailsList.Any())
                    {
                        AddNewDetailRow(false);
                    }
                };

                var glRuleTypeClient = new GlServiceClient();
                glRuleTypeClient.GetGenericCompleted += (s, sv) => { CostCenterTypeList = sv.Result; };
                glRuleTypeClient.GetGenericAsync("TblCostCenterType", "%%", "%%", "%%", "Iserial", "ASC",
                                                 LoggedUserInfo.DatabasEname);

                Glclient.GetTblJournalSettingCostCenterCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblJournalSettingCostCenterViewModel();
                        if (row.TblCostCenter1 != null)
                        {
                            newrow.CostCenterPerRow = new TblCostCenter();
                            newrow.CostCenterPerRow.InjectFrom(row.TblCostCenter1);

                            if (row.TblCostCenter1.TblCostCenterType1 != null)
                            {
                                newrow.CostCenterTypePerRow.InjectFrom(row.TblCostCenter1.TblCostCenterType1);
                            }
                        }


                        newrow.InjectFrom(row);

                        SelectedMainRow.SubDetailList.Add(newrow);
                    }
                    Loading            = false;
                    DetailSubFullCount = sv.fullCount;

                    if (SelectedMainRow.SubDetailList.Any() &&
                        (SelectedSubDetailRow == null))
                    {
                        SelectedSubDetailRow = SelectedMainRow.SubDetailList.FirstOrDefault();
                    }

                    if (DetailSubFullCount == 0 && SelectedMainRow.SubDetailList.Count(x => x.Iserial >= 0) == 0)
                    {
                        AddNewSubDetailRow(false);
                    }
                    if (ExportGrid != null)
                    {
                        ExportGrid.ScrollIntoView(SelectedSubDetailRow, ExportGrid.Columns[1]);
                        ExportGrid.CurrentColumn = ExportGrid.Columns[1];
                        ExportGrid.Focus();
                    }
                };

                Glclient.UpdateOrInsertTblJournalSettingCostCentersCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.SubDetailList.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                    Loading = false;
                };

                Glclient.DeleteTblJournalSettingCostCenterCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    foreach (var item in ev.Result.ToList())
                    {
                        var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == item);
                        if (oldrow != null)
                        {
                            SelectedMainRow.DetailsList.Remove(oldrow);
                        }
                    }
                    if (!SelectedMainRow.SubDetailList.Any())
                    {
                        AddNewSubDetailRow(false);
                    }
                };

                GetMaindata();
            }
        }