コード例 #1
0
        private int DeleteTblWarehouse(TblWarehouse row)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblWarehouses
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    context.DeleteObject(oldRow);
                }

                context.SaveChanges();
            }
            return(row.Iserial);
        }
コード例 #2
0
 private TblWarehouse UpdateOrInsertTblWarehouse(TblWarehouse newRow, bool save, int index, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             context.TblWarehouses.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in context.TblWarehouses
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 GenericUpdate(oldRow, newRow, context);
             }
         }
         context.SaveChanges();
         return(newRow);
     }
 }
コード例 #3
0
        public TransferViewModel() : base(PermissionItemName.TransferForm)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                OpenItemSearch = new RelayCommand(() => {
                    try
                    {
                        if (SelectedMainRow.TblWarehouseFrom != null &&
                            !string.IsNullOrWhiteSpace(SelectedMainRow.TblWarehouseFrom.Code) &&
                            SelectedMainRow.TblWarehouseTo != null &&
                            !string.IsNullOrWhiteSpace(SelectedMainRow.TblWarehouseTo.Code))
                        {
                            var vm             = new ItemDimensionSearchViewModel();
                            vm.WarehouseCode   = SelectedMainRow.TblWarehouseFrom.Code;
                            vm.WarehouseToCode = SelectedMainRow.TblWarehouseTo.Code;
                            vm.SiteIserial     = SelectedMainRow.TblWarehouseFrom.TblSite;
                            vm.AppliedSearchResultList.CollectionChanged += (s, e) => {
                                // هنا هبدا اعبى الى جاى من السيرش
                                foreach (var item in vm.AppliedSearchResultList)
                                {
                                    var temp = SelectedMainRow.TblTransferDetails.FirstOrDefault(td => td.ItemDimFrom == item.ItemDimFromIserial &&
                                                                                                 td.ItemTransfer.ColorToId == item.ColorToId &&
                                                                                                 (td.ItemTransfer.SizeTo == item.SizeTo || (string.IsNullOrEmpty(td.ItemTransfer.SizeTo) && string.IsNullOrEmpty(item.SizeTo))) &&
                                                                                                 (td.ItemTransfer.BatchNoTo == item.BatchNoTo || (string.IsNullOrEmpty(td.ItemTransfer.BatchNoTo) && string.IsNullOrEmpty(item.BatchNoTo))));
                                    decimal allTransferedQuantity = SelectedMainRow.TblTransferDetails.Where(td =>
                                                                                                             td.ItemTransfer.ItemDimFromIserial == item.ItemDimFromIserial).Sum(td => td.ItemTransfer.TransferredQuantity);

                                    if (temp == null)// مش موجود
                                    {
                                        if ((item.AvailableQuantity < (allTransferedQuantity + item.TransferredQuantity) && item.PendingQuantity >= 0) ||
                                            ((item.AvailableQuantity + item.PendingQuantity) < (allTransferedQuantity + item.TransferredQuantity) && item.PendingQuantity >= 0))
                                        {
                                            MessageBox.Show(strings.CheckQuantities);
                                            return;
                                        }
                                        var transferDetail = new TransferDetail()
                                        {
                                            TransferHeader = SelectedMainRow.Iserial,
                                            ItemDimFrom    = item.ItemDimFromIserial,
                                            ItemDimTo      = item.ItemDimToIserial,
                                            Quantity       = item.TransferredQuantity,
                                            ItemTransfer   = item,
                                        };
                                        ValidateDetailRow(transferDetail);
                                    }
                                    else// لو موجود هحدث الكمية
                                    {
                                        if ((item.AvailableQuantity < (allTransferedQuantity - temp.ItemTransfer.AvailableQuantity + item.TransferredQuantity) && item.PendingQuantity >= 0) ||
                                            ((item.AvailableQuantity + item.PendingQuantity) < (allTransferedQuantity - temp.ItemTransfer.AvailableQuantity + item.TransferredQuantity) && item.PendingQuantity >= 0))
                                        {
                                            MessageBox.Show(strings.CheckQuantities);
                                            return;
                                        }
                                        temp.ItemTransfer.AvailableQuantity   = item.AvailableQuantity;
                                        temp.ItemTransfer.PendingQuantity     = item.PendingQuantity;
                                        temp.ItemTransfer.TransferredQuantity = item.TransferredQuantity;
                                        temp.Quantity = item.TransferredQuantity;
                                    }
                                }
                                RaisePropertyChanged(nameof(Total));
                            };
                            var childWindowSeach = new ItemDimensionSearchChildWindow(vm);
                            childWindowSeach.Show();
                            childWindowSeach.IsTransfer    = true;
                            childWindowSeach.QuantityTitle = strings.Transferred;
                            vm.FromTitle = string.Format("From {0}", SelectedMainRow.TblWarehouseFrom.Ename);
                            vm.ToTitle   = string.Format("To {0}", SelectedMainRow.TblWarehouseTo.Ename);
                            vm.Title     = strings.TransferItem;
                            _FormMode    = FormMode.Search;
                        }
                        else
                        {
                            MessageBox.Show(strings.PleaseSelectWarehouse);
                        }
                    }
                    catch (Exception ex) { throw ex; }
                });
                OpenFPItemSearch = new RelayCommand(() =>
                {
                    try
                    {
                        if (SelectedMainRow.TblWarehouseFrom != null &&
                            !string.IsNullOrWhiteSpace(SelectedMainRow.TblWarehouseFrom.Code) &&
                            SelectedMainRow.TblWarehouseTo != null &&
                            !string.IsNullOrWhiteSpace(SelectedMainRow.TblWarehouseTo.Code))
                        {
                            var vm = new ItemFPSearchViewModel();
                            vm.FPAppliedSearchResultList.CollectionChanged += (s, e) =>
                            {
                                if (vm.FPAppliedSearchResultList.Count > 0)
                                {
                                    var SearchItem = vm.FPAppliedSearchResultList.FirstOrDefault();
                                    if (SelectedMainRow.TblTransferDetails != null && SelectedMainRow.TblTransferDetails.Count > 0)
                                    {
                                        SelectedDetailRow.ItemFPName    = SearchItem.ItemPerRow.Name;
                                        SelectedDetailRow.ItemFPCode    = SearchItem.ItemPerRow.Code;
                                        SelectedDetailRow.ItemFPIserial = SearchItem.ItemPerRow.Iserial;

                                        foreach (var item in SelectedMainRow.TblTransferDetails)
                                        {
                                            if (item.ItemTransfer.ItemCode == SelectedDetailRow.ItemTransfer.ItemCode)
                                            {
                                                item.ItemFPName    = SearchItem.ItemPerRow.Name;
                                                item.ItemFPCode    = SearchItem.ItemPerRow.Code;
                                                item.ItemFPIserial = SearchItem.ItemPerRow.Iserial;
                                            }
                                        }
                                    }
                                }
                            };
                            var childWindowSeach = new ItemFPSearchChildWindow(vm);
                            childWindowSeach.Show();
                            _FormMode = FormMode.Search;
                        }
                        else
                        {
                            MessageBox.Show(strings.PleaseSelectWarehouse);
                        }
                    } catch (Exception ex) { throw ex; }
                });

                ApproveTransfer = new RelayCommand(() => {
                    if (SaveCommand.CanExecute(null))
                    {
                        SaveCommand.Execute(null);
                    }
                    SelectedMainRow.Approved    = true;
                    SelectedMainRow.ApproveDate = DateTime.Now;
                    SelectedMainRow.ApprovedBy  = LoggedUserInfo.Iserial;
                    if (SaveCommand.CanExecute(null))
                    {
                        SaveCommand.Execute(null);
                    }
                    if (SelectedMainRow.Approved)//كده نفذ فهعمل جديد
                    {
                        if (NewCommand.CanExecute(null))
                        {
                            NewCommand.Execute(null);
                        }
                    }
                }, () => CheckCanApprove());
                DeleteTransferDetail = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Delete)
                    {
                        if (SelectedMainRow.Iserial <= 0 || SelectedDetailRow.Iserial <= 0)
                        {
                            SelectedMainRow.TblTransferDetails.Remove(SelectedDetailRow);
                            if (SelectedMainRow.TblTransferDetails.Count == 0)
                            {
                                AddNewDetailRow(false);
                            }
                        }
                        else
                        {
                            DeleteDetailRow();
                        }
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                }, (o) => {
                    return(SelectedMainRow != null && !SelectedMainRow.Approved);
                });
                LoadingDetailRows = new RelayCommand <object>((o) =>
                {
                    var e = o as DataGridRowEventArgs;
                    //if (SelectedMainRow.TblTransferDetails.Count < PageSize)
                    //{
                    //    return;
                    //}
                    //if (SelectedMainRow.TblTransferDetails.Count - 2 < e.Row.GetIndex() && !Loading)
                    //{
                    //    GetDetailData();
                    //}
                });
                WarehouseClient.GetItemDimensionQuantitiesCompleted += (s, e) =>
                {
                    var temp = SelectedMainRow.TblTransferDetails.FirstOrDefault(ad =>
                                                                                 ad.ItemDimFrom == e.Result.ItemDimFromIserial);
                    var qtemp = e.Result.AvailableQuantity;
                    if (temp != null)
                    {
                        SelectedDetailRow = temp;
                    }
                    else//هعمل واحد جديد
                    {
                        temp = new TransferDetail()
                        {
                            TransferHeader = SelectedMainRow.Iserial,
                            ItemDimFrom    = e.Result.ItemDimFromIserial,
                            ItemDimTo      = e.Result.ItemDimToIserial,
                        };
                        temp.ItemTransfer.InjectFrom(e.Result);
                        temp.ItemTransfer.ColorPerRow.InjectFrom(e.Result.ColorPerRow);
                        temp.ItemTransfer.AvailableQuantity   = qtemp;
                        temp.ItemTransfer.TransferredQuantity = 0;
                        temp.Quantity = 0;
                        ValidateDetailRow(temp);
                    }
                };
                GetDetailItem = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Enter)
                    {
                        if (SelectedMainRow.TblWarehouseFrom == null || SelectedMainRow.TblWarehouseTo == null)
                        {
                            MessageBox.Show(strings.PleaseSelectWarehouse);
                            return;
                        }
                        WarehouseClient.GetItemDimensionQuantitiesAsync(
                            SelectedMainRow.TblWarehouseFrom.Code,
                            SelectedMainRow.TblWarehouseTo.Code,
                            ItemDimFromIserial,
                            SelectedMainRow.DocDate);
                    }
                });
                //SearchComboFrom = new RelayCommand<object>((o) =>
                //{
                //    if (((KeyEventArgs)(o)).Key == Key.F2)
                //    {if (SelectedMainRow.TblWarehouseFrom == null) SelectedMainRow.TblWarehouseFrom = new WarehouseService.TblWarehouse();
                //    new GenericSearchViewModel<TblWarehouse>().SearchLookup(WarehouseListFrom, SelectedMainRow.TblWarehouseFrom
                //            , new SilverlightCommands.RelayCommand((p) => { int x = 0;x++; }), "search warehouse", new Models.LookupItemModel(),
                //            new SilverlightCommands.RelayCommand((p) => { int y = 0;y++; }));
                //    }
                //});
                ReturnToBarcode = new RelayCommand <object>((o) =>
                {
                    //if (((KeyEventArgs)(o)).Key == Key.Enter)
                    //{
                    //    foreach (var item in SelectedMainRow.TblTransferDetails)
                    //    {
                    //        item.IsQuantityFocused = false;
                    //    }
                    //    IsRefFocused = true;
                    //}
                    RaisePropertyChanged(nameof(Total));
                });
                DetailSelectionChanged = new RelayCommand <object>((o) =>
                {
                    var e = o as SelectionChangedEventArgs;
                    // هنا هنقل الفوكس للكمية شوف بقى ازاى
                    IsRefFocused = false;
                    foreach (var item in SelectedMainRow.TblTransferDetails)
                    {
                        item.IsQuantityFocused = false;
                    }
                    SelectedDetailRow.IsQuantityFocused = true;
                });
                this.PremCompleted += (s, sv) =>
                {
                    if (this.CustomePermissions.SingleOrDefault(x => x.Code == "TransferApprove") != null)
                    {
                        CanApprove = true;
                    }
                };
                this.GetCustomePermissions(PermissionItemName.TransferForm.ToString());

                MainRowList = new ObservableCollection <TransferHeader>();
                AddNewMainRow(false);

                WarehouseClient.GetUserAsignedWarehousesForTransferCompleted += (s, e) =>
                {
                    UserWarehouseList.Clear();
                    foreach (var item in e.Result)
                    {
                        UserWarehouseList.Add(item);
                    }
                };
                WarehouseClient.GetUserAsignedWarehousesForTransferAsync(LoggedUserInfo.Iserial);

                WarehouseClient.GetTransferCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TransferHeader();
                        newrow.InjectFrom(row);
                        MainRowList.Add(newrow);
                    }
                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (SearchWindow != null)
                    {
                        SearchWindow.FullCount = sv.fullCount;
                        SearchWindow.Loading   = false;
                    }
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };
                WarehouseClient.GetTransferDetailCompleted += (s, sv) =>
                {
                    SelectedMainRow.TblTransferDetails.Clear();
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TransferDetail();
                        newrow.InjectFrom(row);
                        newrow.ItemTransfer.InjectFrom(row.ItemTransfer);
                        newrow.ItemTransfer.ColorPerRow.InjectFrom(row.ItemTransfer.ColorPerRow);
                        SelectedMainRow.TblTransferDetails.Add(newrow);
                    }
                    if (!SelectedMainRow.TblTransferDetails.Any())
                    {
                        AddNewDetailRow(false);
                    }
                    Loading = false;
                    RaisePropertyChanged(nameof(Total));
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                WarehouseClient.UpdateOrInsertTransferHeaderCompleted += (s, x) =>
                {
                    TransferHeader savedRow = null;
                    if (x.outindex >= 0)
                    {
                        savedRow = MainRowList.ElementAt(x.outindex);
                    }

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                        savedRow.TblWarehouseFrom = WarehouseListFrom.FirstOrDefault(w => w.Iserial == savedRow.WarehouseFrom);
                        savedRow.TblWarehouseTo   = WarehouseListTo.FirstOrDefault(w => w.Iserial == savedRow.WarehouseTo);
                        savedRow.TblTransferDetails.Clear();
                        foreach (var item in x.Result.TblTransferDetails)
                        {
                            var detailTemp = new TransferDetail();
                            detailTemp.InjectFrom(item);
                            detailTemp.ItemTransfer.InjectFrom(item.ItemTransfer);
                            detailTemp.ItemTransfer.ColorPerRow.InjectFrom(item.ItemTransfer.ColorPerRow);
                            savedRow.TblTransferDetails.Add(detailTemp);
                        }
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                    DeleteCommand.RaiseCanExecuteChanged();
                    ApproveTransfer.RaiseCanExecuteChanged();
                    DeleteTransferDetail.RaiseCanExecuteChanged();
                    // IsNewChanged();
                };
                WarehouseClient.UpdateOrInsertTransferDetailCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.TblTransferDetails.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                WarehouseClient.DeleteTransferCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                };
                WarehouseClient.DeleteTransferDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }
                    var oldrow = SelectedMainRow.TblTransferDetails.FirstOrDefault(x => x.Iserial == ev.Result.Iserial);
                    if (oldrow != null)
                    {
                        SelectedMainRow.TblTransferDetails.Remove(oldrow);
                    }
                    RaisePropertyChanged(nameof(Total));
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };

                WarehouseClient.GetLookUpWarehouseForTransferFromCompleted += (s, e) => {
                    foreach (var row in e.Result)
                    {
                        var newrow = new TblWarehouse();
                        newrow.InjectFrom(row);
                        WarehouseListFrom.Add(newrow);
                    }
                    Loading = false;
                };
                WarehouseClient.GetLookUpWarehouseForTransferToCompleted += (s, e) => {
                    foreach (var row in e.Result)
                    {
                        var newrow = new TblWarehouse();
                        newrow.InjectFrom(row);
                        WarehouseListTo.Add(newrow);
                    }
                    Loading = false;
                };

                GetComboData();
                GetMaindata();
            }
        }