Exemple #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 TblIncomeStatmentDesignDetailViewModel {
                TblIncomeStatmentDesignHeader = SelectedMainRow.Iserial
            };

            if (SelectedMainRow.DetailsList.Any())
            {
                newrow.RowOrder =
                    SelectedMainRow.DetailsList.OrderByDescending(x => x.RowOrder).FirstOrDefault().RowOrder + 1;
            }
            SelectedMainRow.DetailsList.Insert(currentRowIndex + 1, newrow);
            SelectedDetailRow = newrow;
        }
Exemple #2
0
        public IncomeStatmentDesignViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.IncomeStatmentDesign.ToString());
                Glclient = new GlServiceClient();

                MainRowList            = new SortableCollectionView <TblIncomeStatmentDesignHeaderViewModel>();
                SelectedMainRow        = new TblIncomeStatmentDesignHeaderViewModel();
                JournalAccountTypeList = new ObservableCollection <GenericTable>();
                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Label"
                });

                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Account"
                });

                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Account With Subs"
                });

                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Cost Of Good Sold"
                });

                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Income Tax"
                });
                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Seprator"
                });

                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Double Seprator"
                });
                JournalAccountTypeList.Add(new GenericTable
                {
                    Code = "Total"
                });

                Glclient.GetTblIncomeStatmentDesignHeaderCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblIncomeStatmentDesignHeaderViewModel();
                        newrow.InjectFrom(row);
                        MainRowList.Add(newrow);
                    }

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

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

                        newrow.InjectFrom(row);
                        if (row.Type.StartsWith("Account"))
                        {
                            newrow.Type          = row.Type;
                            newrow.AccountPerRow = new TblAccount {
                                Code = row.Description
                            };
                        }
                        SelectedMainRow.DetailsList.Add(newrow);
                    }
                    Loading         = false;
                    DetailFullCount = sv.fullCount;

                    if (SelectedMainRow.DetailsList.Count == 1)
                    {
                        SelectedDetailRow = SelectedMainRow.DetailsList.FirstOrDefault();
                    }

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

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

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

                GetMaindata();
            }
        }