Beispiel #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 TblPositionRouteHeaderViewModel();

            MainRowList.Insert(currentRowIndex + 1, newrow);
            SelectedMainRow = newrow;
        }
Beispiel #2
0
        public void SaveOldRow(TblPositionRouteHeaderViewModel 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 TblPositionRouteHeader();
                    saveRow.InjectFrom(oldRow);

                    if (Loading == false)
                    {
                        Loading = true;
                        Glclient.UpdateOrInsertTblPositionRouteHeaderAsync(saveRow, save, MainRowList.IndexOf(oldRow),
                                                                           LoggedUserInfo.DatabasEname);
                    }
                }
            }
        }
Beispiel #3
0
        public PositionRouteViewModel()
        {
            if (!IsDesignTime)
            {
                GetItemPermissions(PermissionItemName.PositionRoute.ToString());
                Glclient = new GlServiceClient();
                Client.GetEmpPositionAsync("");
                Client.GetEmpPositionCompleted += (s, sv) =>
                {
                    PositionList = sv.Result;
                };


                MainRowList     = new ObservableCollection <TblPositionRouteHeaderViewModel>();
                SelectedMainRow = new TblPositionRouteHeaderViewModel();
                PositionList    = new ObservableCollection <string>();
                Glclient.GetTblPositionRouteHeaderCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblPositionRouteHeaderViewModel();
                        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.UpdateOrInsertTblPositionRouteHeaderCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                    Loading = false;
                };
                Glclient.DeleteTblPositionRouteHeaderCompleted += (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.GetTblPositionRouteCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblPositionRouteViewModel();

                        newrow.InjectFrom(row);
                        newrow.FromStorePerRow = new CRUDManagerService.TblStore().InjectFrom(row.TblStore) as CRUDManagerService.TblStore;
                        newrow.ToStorePerRow   = new CRUDManagerService.TblStore().InjectFrom(row.TblStore1) as CRUDManagerService.TblStore;
                        if (sv.EmpList.FirstOrDefault(w => w.Emplid == newrow.Emplid) != null)
                        {
                            newrow.EmpPerRow = new CRUDManagerService.EmployeesView().InjectFrom(sv.EmpList.FirstOrDefault(w => w.Emplid == newrow.Emplid)) as CRUDManagerService.EmployeesView;
                        }
                        else
                        {
                            newrow.EmpPerRow = new CRUDManagerService.EmployeesView()
                            {
                                Emplid = newrow.Emplid
                            };
                        }
                        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.UpdateOrInsertTblPositionRouteCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        SelectedMainRow.DetailsList.ElementAt(ev.outindex).InjectFrom(ev.Result);
                    }
                    catch (Exception)
                    {
                    }
                    Loading = false;
                };
                Glclient.DeleteTblPositionRouteCompleted += (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);
                    }
                };
                GetMaindata();
            }
        }