예제 #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 TblMarkupViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
예제 #2
0
        public MarkupViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.Markup.ToString());
                Glclient = new GlServiceClient();

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

                DirectionList = new ObservableCollection <GenericTable>
                {
                    new GenericTable {
                        Iserial = 1, Code = "1", Ename = "1", Aname = "1"
                    },
                    new GenericTable {
                        Iserial = -1, Code = "-1", Ename = "-1", Aname = "-1"
                    }
                };

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

                Glclient.GetTblMarkupCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblMarkupViewModel {
                            MarkupGroupPerRow = new GenericTable()
                        };
                        newrow.MarkupGroupPerRow.InjectFrom(row.TblMarkupGroup1);
                        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.UpdateOrInsertTblMarkupsCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                };
                Glclient.DeleteTblMarkupCompleted += (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);
                    }
                };

                GetMaindata();
            }
        }