Ejemplo n.º 1
0
        private void ValidateDetailRow(AdjustmentTempDetail adjustmentDetail)
        {
            var valiationCollection = new List <ValidationResult>();
            var isvalid             = Validator.TryValidateObject(SelectedDetailRow, new ValidationContext(SelectedDetailRow, null, null), valiationCollection, true);

            if (!isvalid)
            {
                SelectedMainRow.TblAdjustmentTempDetails.Remove(SelectedDetailRow);
                SelectedMainRow.TblAdjustmentTempDetails.Add(adjustmentDetail);
            }
            else
            {
                SelectedMainRow.TblAdjustmentTempDetails.Add(adjustmentDetail);
            }
            SelectedDetailRow = adjustmentDetail;
            RaisePropertyChanged(nameof(TotalCounted));
            RaisePropertyChanged(nameof(TotalAvailable));
        }
Ejemplo n.º 2
0
        public void AddNewDetailRow(bool checkLastRow)
        {
            var currentRowIndex = (SelectedMainRow.TblAdjustmentTempDetails.IndexOf(SelectedDetailRow));

            if (!checkLastRow || currentRowIndex == (SelectedMainRow.TblAdjustmentTempDetails.Count - 1))
            {
                if (checkLastRow && SelectedDetailRow != null)
                {
                    var valiationCollection = new List <ValidationResult>();
                    var isvalid             = Validator.TryValidateObject(SelectedDetailRow, new ValidationContext(
                                                                              SelectedDetailRow, null, null), valiationCollection, true);
                    if (!isvalid)
                    {
                        return;
                    }
                }
                SelectedMainRow.TblAdjustmentTempDetails.Insert(currentRowIndex + 1, SelectedDetailRow = new AdjustmentTempDetail
                {
                    AdjustmentHeaderIserial = SelectedMainRow.Iserial
                });
                RaisePropertyChanged(nameof(TotalCounted));
                RaisePropertyChanged(nameof(TotalAvailable));
            }
        }
Ejemplo n.º 3
0
        public AdjustmentTempViewModel(bool hasCost) : base(PermissionItemName.Adjustment)
        {
            this.hasCost = hasCost;
            if (!DesignerProperties.IsInDesignTool)
            {
                OpenItemSearch = new RelayCommand <object>((o) =>
                {
                    try
                    {
                        if (SelectedMainRow.TblWarehouse != null && !string.IsNullOrWhiteSpace(SelectedMainRow.TblWarehouse.Code))
                        {
                            var vm           = new ItemDimensionAdjustmentSearchViewModel();
                            vm.WarehouseCode = SelectedMainRow.TblWarehouse.Code;
                            vm.SiteIserial   = SelectedMainRow.TblWarehouse.TblSite;
                            vm.DocDate       = SelectedMainRow.DocDate;
                            vm.AppliedSearchResultList.CollectionChanged += (s, e) =>
                            {
                                // هنا هبدا اعبى الى جاى من السيرش
                                foreach (var item in vm.AppliedSearchResultList)
                                {
                                    var temp = SelectedMainRow.TblAdjustmentTempDetails.FirstOrDefault(td =>
                                                                                                       td.ItemDimIserial == item.ItemDimFromIserial);
                                    if (0 == item.DifferenceQuantity)
                                    {
                                        continue;
                                    }
                                    if (temp == null)// مش موجود
                                    {
                                        var adjustmentDetail = new AdjustmentTempDetail()
                                        {
                                            AdjustmentHeaderIserial = SelectedMainRow.Iserial,
                                            ItemDimIserial          = item.ItemDimFromIserial,
                                            AvailableQuantity       = item.AvailableQuantity,
                                            CountedQuantity         = item.CountedQuantity,
                                            DifferenceQuantity      = item.DifferenceQuantity,
                                            ItemAdjustment          = item,
                                        };
                                        ValidateDetailRow(adjustmentDetail);
                                        SaveDetailRow();
                                    }
                                    else// لو موجود هحدث الكمية
                                    {
                                        temp.ItemAdjustment.AvailableQuantity  = item.AvailableQuantity;
                                        temp.ItemAdjustment.CountedQuantity    = item.CountedQuantity;
                                        temp.ItemAdjustment.DifferenceQuantity = item.DifferenceQuantity;
                                        temp.AvailableQuantity  = item.AvailableQuantity;
                                        temp.CountedQuantity    = item.CountedQuantity;
                                        temp.DifferenceQuantity = item.DifferenceQuantity;
                                        SelectedDetailRow       = temp;
                                        SaveDetailRow();
                                    }
                                }
                                RaisePropertyChanged(nameof(TotalCounted));
                                RaisePropertyChanged(nameof(TotalAvailable));
                            };
                            var childWindowSeach = new ItemDimensionAdjustmentSearchChildWindow(vm, ((AdjustmentView)o).hasCost);
                            childWindowSeach.Show();
                            vm.Title  = strings.Adjustment;
                            _FormMode = FormMode.Search;
                        }
                        else
                        {
                            MessageBox.Show(strings.PleaseSelectWarehouse);
                        }
                    }
                    catch (Exception ex) { throw ex; }
                });

                DeleteAdjustmentDetail = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Delete)
                    {
                        DeleteDetailRow();
                    }
                }, (o) =>
                {
                    return(SelectedMainRow != null && !SelectedMainRow.Approved);
                });
                LoadingDetailRows = new RelayCommand <object>((o) =>
                {
                    var e = o as DataGridRowEventArgs;
                    if (SelectedMainRow.TblAdjustmentTempDetails.Count < PageSize)
                    {
                        return;
                    }
                    if (SelectedMainRow.TblAdjustmentTempDetails.Count - 2 < e.Row.GetIndex() && !Loading)
                    {
                        GetDetailData();
                    }
                });

                WarehouseClient.GetAdjustmentTempDetailCompleted += (s, e) =>
                {
                    AdjustmentTempDetail temp = new AdjustmentTempDetail();
                    temp.InjectFrom(e.Result);
                    ValidateDetailRow(temp);
                    SelectedDetailRow.ItemAdjustment.CountedQuantity += 1;
                    if (ItemDimQuantity >= 0)
                    {
                        SelectedDetailRow.ItemAdjustment.CountedQuantity += ItemDimQuantity;
                    }
                    SelectedDetailRow.CountedQuantity    = SelectedDetailRow.ItemAdjustment.CountedQuantity;
                    SelectedDetailRow.DifferenceQuantity = SelectedDetailRow.ItemAdjustment.DifferenceQuantity;
                    SaveDetailRow();
                    ItemDimQuantityStr = string.Empty;
                    ItemDimIserialStr  = string.Empty;
                    RaisePropertyChanged(nameof(TotalCounted));
                    RaisePropertyChanged(nameof(TotalAvailable));
                };
                WarehouseClient.GetItemDimensionQuantitiesByDateCompleted += (s, e) =>
                {
                    InsertOrUpdateItemDetail(e.Result);
                };
                GetDetailItem = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Enter)
                    {
                        if (SelectedMainRow.TblWarehouse == null)
                        {
                            MessageBox.Show(strings.PleaseSelectWarehouse);
                            return;
                        }
                        WarehouseClient.GetItemDimensionQuantitiesByDateAsync(
                            SelectedMainRow.TblWarehouse.Code,
                            ItemDimIserial,
                            SelectedMainRow.DocDate);
                    }
                });
                TempRecordLostFocus = new RelayCommand <object>((o) =>
                {
                    if (SelectedMainRow.TblWarehouse == null)
                    {
                        MessageBox.Show(strings.PleaseSelectWarehouse);
                        return;
                    }
                    WarehouseClient.GetItemDimensionQuantitiesByDateAsync(
                        SelectedMainRow.TblWarehouse.Code,
                        SelectedDetailRow.ItemDimIserial,
                        SelectedMainRow.DocDate);
                    isQuantityTextChanged = true;
                });

                ReturnToBarcode = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Enter)
                    {
                        foreach (var item in SelectedMainRow.TblAdjustmentTempDetails)
                        {
                            item.IsQuantityFocused = false;
                        }
                        IsRefFocused = true;
                    }
                });
                DetailSelectionChanged = new RelayCommand <object>((o) =>
                {
                    //var e = o as SelectionChangedEventArgs;
                    //// هنا هنقل الفوكس للكمية شوف بقى ازاى
                    //IsRefFocused = false;
                    //foreach (var item in SelectedMainRow.TblAdjustmentTempDetails)
                    //{
                    //    item.IsQuantityFocused = false;
                    //}
                    //SelectedDetailRow.IsQuantityFocused = true;
                });

                WarehouseClient.GetAdjustmentTempDetailsCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new AdjustmentTempDetail();
                        newrow.InjectFrom(row);
                        SelectedMainRow.TblAdjustmentTempDetails.Add(newrow);
                    }
                    RaisePropertyChanged(nameof(TotalCounted));
                    RaisePropertyChanged(nameof(TotalAvailable));
                    Loading = false;
                    if (IsExport && grid != null)
                    {
                        IsExport = false;
                        SelectedMainRow.TblAdjustmentTempDetails.Select(aTD => new {
                            ItemDim         = aTD.ItemDimIserial,
                            ItemId          = aTD.ItemAdjustment.ItemId,
                            ItemName        = aTD.ItemAdjustment.ItemName,
                            itemCode        = aTD.ItemAdjustment.ItemCode,
                            Color           = aTD.ItemAdjustment.ColorFromCode,
                            Size            = aTD.ItemAdjustment.SizeFrom,
                            BatchNo         = aTD.ItemAdjustment.BatchNoFrom,
                            Available       = aTD.ItemAdjustment.AvailableQuantity,
                            OldQuantity     = aTD.OldQuantity,
                            CountedQuantity = aTD.CountedQuantity,
                            Differance      = aTD.DifferenceQuantity,
                        })
                        .ExportExcel(fileStream, "Adjustment Items");
                    }
                };

                WarehouseClient.UpdateOrInsertAdjustmentTempDetailCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.TblAdjustmentTempDetails.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                };
                WarehouseClient.DeleteAdjustmentTempDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }
                    var oldrow = SelectedMainRow.TblAdjustmentTempDetails.FirstOrDefault(x => x.Iserial == ev.Result.Iserial);
                    if (oldrow != null)
                    {
                        SelectedMainRow.TblAdjustmentTempDetails.Remove(oldrow);
                    }
                    RaisePropertyChanged(nameof(TotalCounted));
                    RaisePropertyChanged(nameof(TotalAvailable));
                };
                Approve = new RelayCommand <object>((o) => {
                    view = o as ControlsOverride.ChildWindowsOverride;
                    WarehouseClient.ApproveAdjustmentTempDetailAsync(SelectedMainRow.Iserial);
                });
                WarehouseClient.ApproveAdjustmentTempDetailCompleted += (s, e) =>
                {
                    if (e.Error != null)
                    {
                        throw e.Error;
                    }
                    if (view != null)
                    {
                        view.Close();
                    }
                };

                ExportToExcel = new RelayCommand <object>((o) => {
                    IsExport    = true;
                    grid        = o as Os.Controls.DataGrid.OsGrid;
                    var sDialog = new SaveFileDialog {
                        Filter = "Excel Files(*.xls)|*.xls"
                    };
                    if (sDialog.ShowDialog() == true)
                    {
                        fileStream = sDialog.OpenFile();
                    }
                    if (SelectedMainRow != null)
                    {
                        SelectedMainRow.TblAdjustmentTempDetails.Clear();
                        WarehouseClient.GetAdjustmentTempDetailsAsync(0, int.MaxValue, SelectedMainRow.Iserial, null);
                    }
                });
                Exit = new RelayCommand <object>((o) => {
                    var view = o as ControlsOverride.ChildWindowsOverride;
                    if (view != null)
                    {
                        view.Close();
                    }
                });

                SearchDetails = new RelayCommand <object>((o) => {
                    if (((KeyEventArgs)(o)).Key == Key.Enter)
                    {
                        SelectedMainRow.TblAdjustmentTempDetails.Clear();// هنفضى الريكوردات
                        GetDetailData();
                    }
                });
            }
        }