Esempio 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 TblPositionRouteViewModel
            {
                TblPositionRouteHeader = SelectedMainRow.Iserial,
                DocDate = SelectedMainRow.DocDate
            };

            SelectedMainRow.DetailsList.Insert(currentRowIndex + 1, newrow);
            SelectedDetailRow = newrow;
        }
Esempio n. 2
0
        public void SaveOldDetailRow(TblPositionRouteViewModel oldRow)
        {
            if (!Loading)
            {
                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 TblPositionRoute();
                        saveRow.InjectFrom(oldRow);

                        if (SelectedMainRow != null && SelectedMainRow.DetailsList != null)
                        {
                            Loading = true;

                            Glclient.UpdateOrInsertTblPositionRouteAsync(saveRow, save, SelectedMainRow.DetailsList.IndexOf(oldRow),
                                                                         LoggedUserInfo.DatabasEname);
                        }
                    }
                }
            }
        }
Esempio n. 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();
            }
        }