Ejemplo n.º 1
0
        public void AddNewDetailRow(bool checkLastRow)
        {
            var currentRowIndex = (SelectedMainRow.DetailsList.IndexOf(SelectedDetailRow));

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

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

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

            var newrow = new TblGlGenEntityViewModel
            {
                TblGlGenEntityGroup   = SelectedMainRow.Iserial,
                TblJournalAccountType = MainJournalAccoutType.Iserial
            };

            SelectedMainRow.DetailsList.Insert(currentRowIndex + 1, newrow);
            SelectedDetailRow = newrow;
        }
Ejemplo n.º 2
0
        public void SaveOldDetailRow(TblGlGenEntityViewModel 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 TblGlGenEntity();
                    saveRow.InjectFrom(oldRow);

                    if (SelectedMainRow != null && SelectedMainRow.DetailsList != null)
                    {
                        Glclient.UpdateOrInsertTblGlGenEntityAsync(saveRow, save, SelectedMainRow.DetailsList.IndexOf(oldRow),
                                                                   LoggedUserInfo.DatabasEname);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public GlGenEntityViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.GlGenEntity.ToString());
                Glclient = new GlServiceClient();

                Glclient.GetTblJournalAccountTypeCompleted += (s, sv) =>
                {
                    JournalAccountTypeList = sv.Result;
                };
                Glclient.GetTblJournalAccountTypeAsync(true, LoggedUserInfo.DatabasEname);

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

                Glclient.GetTblGlGenEntityGroupCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlGenEntityGroupViewModel();
                        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.UpdateOrInsertTblGlGenEntityGroupCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                    Loading = false;
                };
                Glclient.DeleteTblGlGenEntityGroupCompleted += (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.GetTblGlGenEntityCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblGlGenEntityViewModel();

                        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.UpdateOrInsertTblGlGenEntityCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        SelectedMainRow.DetailsList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                };
                Glclient.DeleteTblGlGenEntityCompleted += (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);
                    }
                };
            }
        }