Esempio n. 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 TblVisaMachineViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
Esempio n. 2
0
        public VisaMachineViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.VisaMachineForm.ToString());
                Glclient        = new GlServiceClient();
                MainRowList     = new SortableCollectionView <TblVisaMachineViewModel>();
                SelectedMainRow = new TblVisaMachineViewModel();


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

                Glclient.GetTblVisaMachineCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblVisaMachineViewModel();
                        newrow.TblbankPerRow = new TblBank();
                        newrow.InjectFrom(row);

                        if (row.TblBank1 != null)
                        {
                            newrow.TblbankPerRow.InjectFrom(row.TblBank1);
                        }

                        newrow.JournalAccountTypePerRow = new GlService.GenericTable();
                        if (newrow.TblJournalAccountType.HasValue)
                        {
                            newrow.JournalAccountTypePerRow =
                                JournalAccountTypeList.FirstOrDefault(jAT => jAT.Iserial == newrow.TblJournalAccountType.Value);
                        }

                        var entity = sv.EntityAccounts.FirstOrDefault(x => x.TblJournalAccountType == newrow.TblJournalAccountType &&
                                                                      x.Iserial == row.EntityAccount);
                        if (entity != null)
                        {
                            newrow.EntityPerRow.InjectFrom(entity); newrow.RaiseEntityChanged();
                        }


                        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;
                        ExportGrid.ExportExcel("VisaMachines");
                    }
                };

                Glclient.UpdateOrInsertTblVisaMachineCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                };
                Glclient.DeleteTblVisaMachineCompleted += (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.GetVisaMachineBanksCompleted += (s, sv) =>
                {
                    BankList = sv.Result;
                };

                Glclient.GetVisaMachineBanksAsync(LoggedUserInfo.DatabasEname);

                GetMaindata();
            }
        }