예제 #1
0
        private static void SetupStaticTestProject()
        {
            AssetsRoot = Path.Combine(AppContext.BaseDirectory, "bin");
            RestoredTestProjectDirectory = Path.Combine(AssetsRoot, s_testdirName);

            // Ignore Delete Failure
            try
            {
                Directory.Delete(RestoredTestProjectDirectory, true);
            }
            catch (Exception) { }

            Directory.CreateDirectory(RestoredTestProjectDirectory);

            // Todo: this is a hack until corefx is on nuget.org remove this After RC 2 Release
            NuGetConfig.Write(RestoredTestProjectDirectory);

            var newCommand = new NewCommand();

            newCommand.WorkingDirectory = RestoredTestProjectDirectory;
            newCommand.Execute().Should().Pass();

            var restoreCommand = new RestoreCommand();

            restoreCommand.WorkingDirectory = RestoredTestProjectDirectory;
            restoreCommand.Execute("/p:SkipInvalidConfigurations=true")
            .Should().Pass();
        }
예제 #2
0
파일: Getter.cs 프로젝트: 448333839/PS03
        public List <Profile> GetWIfiProfiles()
        {
            var    cmd         = new NewCommand("netsh wlan show profiles");
            string rawProfiles = cmd.Execute();

            if (rawProfiles.StartsWith("The Wireless"))
            {
                return(new List <Profile>());
            }

            List <Profile> profiles   = _dataOps.ExtractProfiles(rawProfiles);
            string         getPassCmd = "";


            for (int i = 0; i < profiles.Count; i++)
            {
                getPassCmd += "netsh wlan show profile name=\"" + profiles[i].Action + "\"" + " key=clear";
                if (i + 1 != profiles.Count)
                {
                    getPassCmd += " && ";
                }
            }

            var PwCmd = new NewCommand(getPassCmd);
            var rawPasswordProfiles = PwCmd.Execute();
            var Cp = _dataOps.GetClearProfiles(rawPasswordProfiles, profiles);

            foreach (var p in profiles)
            {
                p.AppName = "WiFi";
            }
            return(Cp);
        }
예제 #3
0
        public void before_all()
        {
            // setup
            _command = new NewCommand();
            _fileSystem = new FileSystem();
            _zipService = new ZipFileService(_fileSystem);
            _commandInput = new NewCommandInput();

            tmpDir = FileSystem.Combine("Templating", Guid.NewGuid().ToString());
            repoZip = FileSystem.Combine("Templating", "repo.zip");
            _zipService.ExtractTo(repoZip, tmpDir, ExplodeOptions.DeleteDestination);

            solutionFile = FileSystem.Combine("Templating", "sample", "myproject.txt");
            oldContents = _fileSystem.ReadStringFromFile(solutionFile);
            solutionDir = _fileSystem.GetDirectory(solutionFile);

            _commandInput.GitFlag = "file:///{0}".ToFormat(_fileSystem.GetFullPath(tmpDir).Replace("\\", "/"));
            _commandInput.ProjectName = "MyProject";
            _commandInput.SolutionFlag = solutionFile;
            _commandInput.OutputFlag = solutionDir;
            _commandInput.RakeFlag = "init.rb";

            _commandResult = _command.Execute(_commandInput);

            newSolutionContents = _fileSystem.ReadStringFromFile(solutionFile);
        }
예제 #4
0
        public void before_all()
        {
            // setup
            _command      = new NewCommand();
            _fileSystem   = new FileSystem();
            _zipService   = new ZipFileService(_fileSystem);
            _commandInput = new NewCommandInput();

            tmpDir  = FileSystem.Combine("Templating", Guid.NewGuid().ToString());
            repoZip = FileSystem.Combine("Templating", "repo.zip");
            _zipService.ExtractTo(repoZip, tmpDir, ExplodeOptions.DeleteDestination);

            solutionFile = FileSystem.Combine("Templating", "sample", "myproject.txt");
            oldContents  = _fileSystem.ReadStringFromFile(solutionFile);
            solutionDir  = _fileSystem.GetDirectory(solutionFile);

            _commandInput.GitFlag      = "file:///{0}".ToFormat(_fileSystem.GetFullPath(tmpDir).Replace("\\", "/"));
            _commandInput.ProjectName  = "MyProject";
            _commandInput.SolutionFlag = solutionFile;
            _commandInput.OutputFlag   = solutionDir;
            _commandInput.RakeFlag     = "init.rb";

            _commandResult = _command.Execute(_commandInput);

            newSolutionContents = _fileSystem.ReadStringFromFile(solutionFile);
        }
예제 #5
0
파일: Program.cs 프로젝트: DeckHubApp/cli
        public static async Task Main(string[] args)
        {
            if (args.Length > 0 && args[0].Equals("new", StringComparison.OrdinalIgnoreCase))
            {
                var newCommand = new NewCommand(args);
                await newCommand.Execute();

                return;
            }

            BuildWebHost(args).Run();
        }
예제 #6
0
 void DeleteTourCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         Tours.Remove(SelectedTour);
         NewCommand.Execute(null);
     }
     else
     {
         ErrorProvider.ShowError(e.Error, Navigator);
     }
     dataClient.DeleteTourCompleted -= DeleteTourCompleted;
     Busy = false;
 }
        private void DeleteAction(object obj)
        {
            MessageBoxResult result = MessageBox.Show("Yakin Hapus Data ? ", "Perhatian", MessageBoxButton.YesNo, MessageBoxImage.Question);

            try
            {
                if (result == MessageBoxResult.Yes)
                {
                    if (context.Delete(SelectedItem))
                    {
                        Message.Success("Data Berhasil Dihapus");
                        NewCommand.Execute(null);
                        BarangSourceView.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                Message.Error(ex.Message);
            }
        }
        /// <summary>
        /// Обрабатывает нажатие клавиши.
        /// </summary>
        /// <param name="sender">Объект-отправитель.</param>
        /// <param name="e">Передаваемые данные.</param>
        public async void OnPageKeyDown(object sender, KeyRoutedEventArgs e)
        {
            switch (e.Key)
            {
            case VirtualKey.Control: _isCtrlKeyPressed = true; break;

            case VirtualKey.Shift: _isShiftKeyPressed = true; break;

            case VirtualKey.Delete: DeleteCommand.Execute(SelectedItem.ID); break;

            case VirtualKey.Space: Items[SelectedItem.ID].Orientation
                    = Items[SelectedItem.ID].Orientation == Orientation.Horizontal
                        ? Orientation.Vertical : Orientation.Horizontal; break;

            case VirtualKey.Left: Items[SelectedItem.ID].X -= 25; break;

            case VirtualKey.Right: Items[SelectedItem.ID].X += 25; break;

            case VirtualKey.Up: Items[SelectedItem.ID].Y -= 25; break;

            case VirtualKey.Down: Items[SelectedItem.ID].Y += 25; break;
            }

            if (_isCtrlKeyPressed && _isShiftKeyPressed)
            {
                switch (e.Key)
                {
                case VirtualKey.S: await SaveAsAsync(); break;
                }
            }
            else if (_isCtrlKeyPressed)
            {
                switch (e.Key)
                {
                case VirtualKey.N: NewCommand.Execute(null); break;

                case VirtualKey.S: SaveGridCommand.Execute(null); break;
                }
            }
        }
예제 #9
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();
            }
        }
예제 #10
0
 protected Workspace()
 {
     NewCommand.Execute(null);
     NewCommand.Execute(null);
     NewCommand.Execute(false);
 }
예제 #11
0
        public StoreVisaMachineViewModel() : base(PermissionItemName.StoreVisaMachine)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                MainRowList = new ObservableCollection <StoreVisaMachine>();

                BankDepositClient.GetVisaMachineCompleted += (s, sv) =>
                {
                    MainRowList.Clear();
                    if (sv.Result.Count > 0)
                    {
                        var storeVisaMachine = sv.Result.FirstOrDefault();
                        DiscountPercent = storeVisaMachine.DiscountPercent;
                        EntityPerRow    = new GlService.Entity()
                        {
                            Iserial = storeVisaMachine.EntityAccount,
                            TblJournalAccountType = JournalAccountTypePerRow.Iserial,
                            Code = storeVisaMachine.EntityCode,
                        };
                    }
                    else
                    {
                        DiscountPercent = 0;
                        EntityPerRow    = new GlService.Entity();
                    }
                    foreach (var row in sv.Result)
                    {
                        MainRowList.Add(row);
                    }
                    Loading = false;
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };
                BankDepositClient.UpdateOrInsertVisaMachineCompleted += (s, x) =>
                {
                    if (x.Error != null)
                    {
                        MessageBox.Show(Helper.GetInnerExceptionMessage(x.Error));
                    }
                    Loading = false;
                    MainRowList.Clear();
                    foreach (var item in x.Result)
                    {
                        var savedRow = MainRowList.FirstOrDefault(r => r.StoreVisaMachineIserial == item.StoreVisaMachineIserial);
                        if (savedRow != null)
                        {
                            savedRow.InjectFrom(item);
                            BankRec = BankList.FirstOrDefault(c => c.Iserial == savedRow.BankIserial);
                        }
                        else
                        {
                            MainRowList.Add(item);
                        }
                    }
                    if (x.Result.Count > 0)
                    {
                        MessageBox.Show(strings.SavedMessage);
                    }
                    DeleteCommand.RaiseCanExecuteChanged();
                    IsNewChanged();
                };

                #region Delete

                DeleteDetail = new RelayCommand <object>((o) => {
                    if (((KeyEventArgs)(o)).Key == Key.Delete)
                    {
                        if (SelectedMainRow.StoreVisaMachineIserial <= 0 || SelectedMainRow.VisaMachineIserial <= 0)
                        {
                            MainRowList.Remove(SelectedMainRow);
                            if (MainRowList.Count == 0)
                            {
                                AddNewMainRow(false);
                            }
                        }
                        else
                        {
                            DeleteMainRow();
                        }
                    }
                });
                BankDepositClient.DeleteVisaMachineCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = MainRowList.FirstOrDefault(x => x.StoreVisaMachineIserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                };

                #endregion

                NewVisaCommand = new RelayCommand <object>((o) => {
                    if (((KeyEventArgs)(o)).Key == Key.Down)
                    {
                        NewCommand.Execute(null);
                    }
                });

                BankDepositClient.GetLookUpStoreCompleted += (s, e) =>
                {
                    StoreList = e.Result;
                };
                BankDepositClient.GetLookUpBankCompleted += (s, e) =>
                {
                    BankList = e.Result;
                };

                GetComboData();
                AddNewMainRow(false);
            }
        }
예제 #12
0
        public BankStatementViewModel() : base(PermissionItemName.BankStatement)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                ApproveBankStat = 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());
                DeleteBankStatDetail = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Delete)
                    {
                        if (SelectedMainRow.Iserial <= 0 || SelectedDetailRow.Iserial <= 0)
                        {
                            SelectedMainRow.TblBankStatDetails.Remove(SelectedDetailRow);
                            if (SelectedMainRow.TblBankStatDetails.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.TblBankStatDetails.Count < PageSize)
                    {
                        return;
                    }
                    if (SelectedMainRow.TblBankStatDetails.Count - 2 < e.Row.GetIndex() && !Loading)
                    {
                        GetDetailData();
                    }
                });

                NewDetail = new RelayCommand <object>((o) =>
                {
                    var e = o as SelectionChangedEventArgs;
                    if (((KeyEventArgs)(o)).Key == Key.Down)
                    {
                        AddNewDetailRow(false);
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                });
                this.PremCompleted += (s, sv) =>
                {
                    if (this.CustomePermissions.SingleOrDefault(x => x.Code == "BankStatApprove") != null)
                    {
                        CanApprove = true;
                    }
                };
                this.GetCustomePermissions(PermissionItemName.BankStatement.ToString());

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

                BankStatClient.GetBankStatHeaderCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new BankStatHeader();
                        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);
                    }
                };
                BankStatClient.GetBankStatDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new BankStatDetail();
                        newrow.InjectFrom(row);
                        //newrow.TblBankTransactionType1 = BankTransactionTypeList.FirstOrDefault(btt => btt.Iserial == newrow.TblBankTransactionType);
                        SelectedMainRow.TblBankStatDetails.Add(newrow);
                    }
                    if (!SelectedMainRow.TblBankStatDetails.Any())
                    {
                        AddNewDetailRow(false);
                    }
                    Loading = false;
                    RaisePropertyChanged(nameof(Total));
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                BankStatClient.UpdateOrInsertBankStatHeaderCompleted += (s, x) =>
                {
                    BankStatHeader savedRow = null;
                    if (x.outindex >= 0)
                    {
                        savedRow = MainRowList.ElementAt(x.outindex);
                    }

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                        savedRow.TblBank1     = BankList.FirstOrDefault(b => b.Iserial == savedRow.TblBank);
                        savedRow.TblCurrency1 = CurrencyList.FirstOrDefault(c => c.Iserial == savedRow.TblCurrency);
                        savedRow.TblBankStatDetails.Clear();
                        foreach (var item in x.Result.TblBankStatDetails)
                        {
                            var detailTemp = new BankStatDetail();
                            detailTemp.InjectFrom(item);
                            savedRow.TblBankStatDetails.Add(detailTemp);
                        }
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                    DeleteCommand.RaiseCanExecuteChanged();
                    ApproveBankStat.RaiseCanExecuteChanged();
                    DeleteBankStatDetail.RaiseCanExecuteChanged();
                    IsNewChanged();
                };
                BankStatClient.UpdateOrInsertBankStatDetailCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.TblBankStatDetails.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                        savedRow.TblBankTransactionType1 = BankTransactionTypeList.FirstOrDefault(bt => bt.Iserial == savedRow.TblBankTransactionType);
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                BankStatClient.DeleteBankStatHeaderCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

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

                BankStatClient.IsBankStatHeaderHasMatchedRowsCompleted += (s, e) =>
                {
                    if (SelectedMainRow.Iserial == e.Iserial)
                    {
                        hasMatched = e.Result;
                    }
                    else
                    {
                        hasMatched = false;
                    }
                    RaisePropertyChanged(nameof(IsReadOnly));
                };

                BankStatClient.GetLookUpBankTransactionTypeCompleted += (s, e) =>
                {
                    BankTransactionTypeList = e.Result;
                };
                BankStatClient.GetLookUpBankCompleted += (s, e) =>
                {
                    BankList = e.Result;
                };
                BankStatClient.GetLookUpCurrencyCompleted += (s, e) =>
                {
                    CurrencyList = e.Result;
                };

                BankStatClient.InsertImportedItemsCompleted += (s, e) =>
                {
                    for (int i = 0; i < RemainningImportList.Count; i = i + step)
                    {
                        bool approve = (i + step >= RemainningImportList.Count);                                       //هل دى اخر لفة
                        var  temp    = new ObservableCollection <ImportedBankStatement>(RemainningImportList.Skip(i).Take(step));
                        BankStatClient.InsertRemainingImportedItemsAsync(e.Result, temp, LoggedUserInfo.DatabasEname); // First Time
                        requestes++;
                    }
                    ImportHeaderIserial = e.Result;
                    Loading             = false;
                };
                BankStatClient.InsertRemainingImportedItemsCompleted += (s, e) =>
                {
                    requestes--;// على اساس ان الريكويست اسرع من الريسبونس

                    foreach (var item in e.Result)
                    {
                        error += item + "\r\n";
                    }
                    if (e.Error != null)
                    {
                        requestes = -1;
                        throw e.Error;
                    }
                    else if (requestes == 0)// كده ده اخر واحد
                    {
                        if (string.IsNullOrWhiteSpace(error))
                        {
                            MessageBox.Show("Import Completed Succesfully");
                            //هجيب الريكورد الى اتحفظ ده اعرضه بقى
                            BankStatClient.GetBankStatHeaderByIserialAsync(ImportHeaderIserial, LoggedUserInfo.DatabasEname);
                            ImportHeaderIserial = -1;
                            return;
                        }
                        BankStatClient.DeleteBankStatByIserialAsync(ImportHeaderIserial, LoggedUserInfo.DatabasEname);
                        ImportHeaderIserial = -1;
                        if (MessageBox.Show("Import Completed, Do you want to view logs?", "Info", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            new LogView(error).Show();
                            error = "";
                        }
                    }
                };
                BankStatClient.GetBankStatHeaderByIserialCompleted += (s, e) =>
                {
                    SelectedMainRow.InjectFrom(e.Result);
                    SelectedMainRow.TblBank1     = BankList.FirstOrDefault(b => b.Iserial == SelectedMainRow.TblBank);
                    SelectedMainRow.TblCurrency1 = CurrencyList.FirstOrDefault(c => c.Iserial == SelectedMainRow.TblCurrency);
                    if (SelectedMainRow.TblBankStatDetails != null)
                    {
                        SelectedMainRow.TblBankStatDetails = new ObservableCollection <BankStatDetail>();
                    }
                    RaisePropertyChanged(nameof(SelectedMainRow));
                    DeleteCommand.RaiseCanExecuteChanged();
                    ApproveBankStat.RaiseCanExecuteChanged();
                    DeleteBankStatDetail.RaiseCanExecuteChanged();
                    IsNewChanged();
                    GetDetailData();
                };
                BankStatClient.InsertExcelFileDateCompleted += (s, e) => {
                    //if (e.Error != null) MessageBox.Show(e.Error.Message);
                };
                ImportFromExcelCommand = new RelayCommand(() => {
                    if (!ValidHeaderData())
                    {
                        return;
                    }
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter         = "Excel Files (*.xls)|*.xls";
                    if (ofd.ShowDialog() == true)
                    {
                        var importedList = new ObservableCollection <ImportedBankStatement>();
                        var fs           = ofd.File.OpenRead();

                        var book  = Workbook.Open(fs);
                        var sheet = book.Worksheets[0];

                        var dataList = new ObservableCollection <Models.Excel.CellModel>();
                        for (int i = sheet.Cells.FirstColIndex; i < sheet.Cells.LastColIndex + 1; i++)
                        {
                            for (int j = sheet.Cells.FirstRowIndex; j < sheet.Cells.LastRowIndex + 1; j++)
                            {
                                var cellModel = new Models.Excel.CellModel()
                                {
                                    Column = i,
                                    Row    = j,
                                    Value  = sheet.Cells[j, i].StringValue.ToUpper(),
                                };
                                dataList.Add(cellModel);
                                if (i == 1)
                                {
                                    var t = sheet.Cells[j, i].StringValue.ToUpper().Split('-');
                                    if (t.Length == 3)
                                    {
                                        cellModel.Day    = t[0];
                                        cellModel.Mounth = t[1];
                                        cellModel.Year   = t[2];
                                    }
                                }
                            }
                        }
                        TblBankStatHeader headerRow = new TblBankStatHeader();
                        headerRow.InjectFrom(SelectedMainRow);
                        BankStatClient.InsertExcelFileDateAsync(headerRow, dataList, LoggedUserInfo.DatabasEname);// new ObservableCollection<Models.Excel.CellModel>(dataList.Take(300)));
                        //int docDateIndex = 0, transactionTypeIndex = 0, descriptionIndex = 0, amountIndex = 0, chequeNoIndex = 0, depositNoIndex = 0;
                        //FillList(importedList, sheet, ref docDateIndex, ref transactionTypeIndex, ref descriptionIndex, ref amountIndex, ref chequeNoIndex, ref depositNoIndex);
                        //InsertImportedDetail(importedList);
                    }
                });
                MatchCommand = new RelayCommand(() => {
                    if (SelectedMainRow.Iserial <= 0)
                    {
                        MessageBox.Show("Bank Statement must save first");
                        return;
                    }
                    var matchingView            = new BankStatementMatchView();
                    var matchingViewModel       = new BankStatementMatchViewModel();
                    matchingViewModel.HeaderRow = SelectedMainRow;
                    matchingView.DataContext    = matchingViewModel;
                    matchingView.Show();
                });

                GetComboData();
                GetMaindata();
            }
        }