Example #1
0
        public void AddNewMainRow(bool checkLastRow)
        {
            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;
                }
            }
            if (AllowAdd != true)
            {
                MessageBox.Show(strings.AllowAddMsg);
                return;
            }
            var newrow = new TblGlRuleHeaderViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
Example #2
0
        public void SaveOldRow(TblGlRuleHeaderViewModel oldRow)
        {
            if (oldRow != null)
            {
                var valiationCollection = new List <ValidationResult>();

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

                if (isvalid)
                {
                    var save = oldRow.Iserial == 0;
                    if (AllowUpdate != true && !save)
                    {
                        MessageBox.Show(strings.AllowUpdateMsg);
                        return;
                    }
                    var saveRow = new TblGlRuleHeader();
                    saveRow.InjectFrom(oldRow);

                    Glclient.UpdateOrInsertTblGlRuleHeadersAsync(saveRow, save, MainRowList.IndexOf(oldRow),
                                                                 LoggedUserInfo.DatabasEname);
                }
            }
        }
Example #3
0
        public GlRuleViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.GlRule.ToString());
                Glclient = new GlServiceClient();

                Glclient.GetGlInventoryGroupAsync(LoggedUserInfo.DatabasEname);

                Glclient.GetGlInventoryGroupCompleted += (s, sv) =>
                {
                    GlInventoryGroupList = sv.Result;
                };
                var journalAccountTypeClient = new GlServiceClient();
                journalAccountTypeClient.GetGenericCompleted += (s, sv) =>
                {
                    JournalAccountTypeList       = sv.Result;
                    JournalAccountTypeListFilter = new ObservableCollection <GenericTable>(sv.Result.Where(x => x.Iserial == 0 || x.Iserial == 8));
                    var newrow = JournalAccountTypeListFilter.FirstOrDefault(x => x.Iserial == 0);
                    newrow.Code  = "Group";
                    newrow.Ename = "Group";
                    newrow.Aname = "Group";
                };
                journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname);

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

                var tblCostCenterOptionClient = new GlServiceClient();
                tblCostCenterOptionClient.GetGenericCompleted += (s, sv) => { CostCenterOptionList = sv.Result; };
                tblCostCenterOptionClient.GetGenericAsync("tblCostCenterOption", "%%", "%%", "%%", "Iserial", "ASC",

                                                          LoggedUserInfo.DatabasEname);

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

                MainRowList     = new SortableCollectionView <TblGlRuleHeaderViewModel>();
                SelectedMainRow = new TblGlRuleHeaderViewModel();

                Glclient.GetTblGlRuleHeaderCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlRuleHeaderViewModel();
                        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);
                    }
                };

                Glclient.UpdateOrInsertTblGlRuleHeadersCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                };
                Glclient.DeleteTblGlRuleHeaderCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }

                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                    if (!MainRowList.Any())
                    {
                        AddNewMainRow(false);
                    }
                };

                Glclient.GetTblGlRuleMainDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlRuleMainDetailViewModel();

                        newrow.EntityAccountPerRow = new Entity();

                        newrow.EntityAccountPerRow =
                            sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == row.TblJournalAccountType &&
                                                         x.Iserial == row.EntityAccount);

                        if (row.TblJournalAccountType1 != null)
                        {
                            newrow.JournalAccountTypePerRow = new GenericTable();
                            newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType1);
                        }
                        if (row.TblCostCenterType1 != null)
                        {
                            newrow.CostCenterTypePerRow = new GenericTable();
                            newrow.CostCenterTypePerRow.InjectFrom(row.TblCostCenterType1);
                        }
                        if (row.TblCostCenterOption1 != null)
                        {
                            newrow.CostCenterOptionPerRow = new GenericTable();
                            newrow.CostCenterOptionPerRow.InjectFrom(row.TblCostCenterOption1);
                        }
                        if (row.TblCostAllocationMethod1 != null)
                        {
                            newrow.CostAllocationMethodPerRow = new GenericTable();
                            newrow.CostAllocationMethodPerRow.InjectFrom(row.TblCostAllocationMethod1);
                        }
                        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 == 0)
                    {
                        AddNewDetailRow(false);
                    }
                };

                Glclient.UpdateOrInsertTblGlRuleMainDetailsCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        SelectedDetailRow.DetailsList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                };
                Glclient.DeleteTblGlRuleMainDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }

                    var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        SelectedMainRow.DetailsList.Remove(oldrow);
                    }
                    if (!SelectedMainRow.DetailsList.Any())
                    {
                        AddNewDetailRow(false);
                    }
                };

                Glclient.GetTblGlRuleDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlRuleDetailViewModel
                        {
                            CostCenterPerRow         = row.TblCostCenter1,
                            TblCostCenterType        = SelectedDetailRow.TblCostCenterType,
                            CostCenterTypePerRow     = SelectedDetailRow.CostCenterTypePerRow,
                            JournalAccountTypePerRow = JournalAccountTypeListFilter.FirstOrDefault(x => x.Iserial == row.TblJournalAccountType)
                        };

                        if (row.TblJournalAccountType != null)
                        {
                            newrow.GlInventoryGroupPerRow =
                                GlInventoryGroupList.FirstOrDefault(
                                    x =>
                                    x.TblJournalAccountType == row.TblJournalAccountType &&
                                    x.Iserial == row.GlInventoryGroup);
                        }

                        newrow.InjectFrom(row);

                        SelectedDetailRow.DetailsList.Add(newrow);
                    }
                    Loading            = false;
                    DetailSubFullCount = sv.fullCount;

                    if (SelectedDetailRow.DetailsList.Any() &&
                        (SelectedSubDetailRow == null))
                    {
                        SelectedSubDetailRow = SelectedDetailRow.DetailsList.FirstOrDefault();
                    }

                    if (DetailSubFullCount == 0 && SelectedDetailRow.DetailsList.Count == 0)
                    {
                        AddNewSubDetailRow(false);
                    }
                };

                Glclient.UpdateOrInsertTblGlRuleDetailsCompleted += (s, x) =>
                {
                    var savedRow = (TblGlRuleDetailViewModel)SelectedDetailRow.DetailsList.GetItemAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                    Loading = false;
                };

                Glclient.DeleteTblGlRuleDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    Loading = false;
                    var oldrow = SelectedDetailRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        SelectedDetailRow.DetailsList.Remove(oldrow);
                    }
                    if (!SelectedDetailRow.DetailsList.Any())
                    {
                        AddNewSubDetailRow(false);
                    }
                };

                GetMaindata();
            }
        }