public static void FillData(ApplicationContext context, UserManager <User> _userManager) { if (!context.TypeOfDocuments.Any()) { TypeOfDocument pasport = new TypeOfDocument { Name = "Паспорт" }; TypeOfDocument pasport1 = new TypeOfDocument { Name = "ВоенныйБилет" }; TypeOfDocument pasport2 = new TypeOfDocument { Name = "СвидетельствоОрождении" }; context.TypeOfDocuments.AddRange(pasport, pasport1, pasport2); context.SaveChanges(); } if (!context.Countries.Any()) { Country country = new Country { CountryName = "Кыргызстан" }; Country country1 = new Country { CountryName = "Таджикистан" }; Country country2 = new Country { CountryName = "Казахстан" }; context.Countries.AddRange(country, country1, country2); context.SaveChanges(); } if (!context.LegalForms.Any()) { LegalForm legalForm = new LegalForm { LegalFormName = "ОсОО" }; LegalForm legalForm1 = new LegalForm { LegalFormName = "ОАО" }; LegalForm legalForm2 = new LegalForm { LegalFormName = "ЗАО" }; context.LegalForms.AddRange(legalForm, legalForm1, legalForm2); context.SaveChanges(); } if (!context.PropertyTypes.Any()) { PropertyType propertyType = new PropertyType { PropertyTypeName = "Государственная" }; PropertyType propertyType1 = new PropertyType { PropertyTypeName = "Частная" }; PropertyType propertyType2 = new PropertyType { PropertyTypeName = "Смешанная" }; context.PropertyTypes.AddRange(propertyType, propertyType1, propertyType2); context.SaveChanges(); } if (!context.Residencies.Any()) { Residency residency = new Residency { ResidencyName = "Резидент" }; Residency residency1 = new Residency { ResidencyName = "НеРезидент" }; context.Residencies.AddRange(residency, residency1); context.SaveChanges(); } if (!context.TaxInspections.Any()) { TaxInspection taxInspection = new TaxInspection { TaxInspectionName = "Ленинский" }; TaxInspection taxInspection1 = new TaxInspection { TaxInspectionName = "Свердловский" }; TaxInspection taxInspection2 = new TaxInspection { TaxInspectionName = "Октябрьский" }; context.TaxInspections.AddRange(taxInspection, taxInspection1, taxInspection2); context.SaveChanges(); } if (!context.TransactionTypes.Any()) { List <TransactionType> transactions = new List <TransactionType>(); transactions.Add(TransactionType.Create(TransactionTypesEnum.Debit)); transactions.Add(TransactionType.Create(TransactionTypesEnum.Credit)); context.TransactionTypes.AddRange(transactions); context.SaveChanges(); } if (!context.ExchangeRateTypes.Any()) { ExchangeRateType exchangeRateType = ExchangeRateType.Create(ExchangeRateTypesEnum.NBKR); ExchangeRateType exchangeRateType1 = ExchangeRateType.Create(ExchangeRateTypesEnum.Market); context.ExchangeRateTypes.AddRange(exchangeRateType, exchangeRateType1); context.SaveChanges(); } if (!context.TransferStates.Any()) { context.AddRange( TransferState.Create(TransferStatesEnum.Confirmed), TransferState.Create(TransferStatesEnum.NotConfirmed), TransferState.Create(TransferStatesEnum.Canceled), TransferState.Create(TransferStatesEnum.BalanceNotEnough), TransferState.Create(TransferStatesEnum.AccountIsLocked)); context.SaveChanges(); } if (!context.TypeOfTransfers.Any()) { context.AddRange( TypeOfTransfer.Create(TypeOfTransfersEnum.InnerTransfer), TypeOfTransfer.Create(TypeOfTransfersEnum.InterBankTransfer), TypeOfTransfer.Create(TypeOfTransfersEnum.Conversion)); context.SaveChanges(); } if (!context.Currencies.Any()) { context.Currencies.Add ( new Currency { Code = "123", Name = "SOM", IsNativeCurrency = true } ); context.SaveChanges(); } if (!context.OurBank.Any()) { Currency currency = context.Currencies.FirstOrDefault(n => n.IsNativeCurrency == true); Account bankAccount = new Account { Locked = false, CurrencyId = currency.Id, Number = "1234567890123456" }; context.Accounts.Add(bankAccount); context.SaveChanges(); BankInfo bank = new BankInfo { BankName = "OurBank", Email = "*****@*****.**" }; context.BankInfos.Add(bank); OurBank ourBank = new OurBank { BIK = "123", AccountId = bankAccount.Id, BankInfoId = bank.Id }; context.OurBank.Add(ourBank); context.SaveChanges(); } if (!context.IntervalTypes.Any()) { List <IntervalType> intervalTypes = new List <IntervalType>(); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceADay)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceAWeek)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceInTwoWeeks)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceAMonth)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceAQuarter)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceAHalfYear)); intervalTypes.Add(IntervalType.Create(IntervalTypesEnum.OnceAYear)); context.IntervalTypes.AddRange(intervalTypes); context.SaveChanges(); } if (!context.Roles.Any()) { context.Roles.AddRange ( new IdentityRole { Name = "admin", NormalizedName = "ADMIN" }, new IdentityRole { Name = "user", NormalizedName = "USER" } ); context.SaveChanges(); } if (context.Users.FirstOrDefault(u => u.UserName == "Admin") == null) { var result = _userManager.CreateAsync(new User { UserName = "******", Email = "*****@*****.**", IsTwoFactorOn = false, IsPasswordChanged = true, }, "Admin123@"); if (result.Result.Succeeded) { User user = context.Users.FirstOrDefault(u => u.UserName == "Admin"); IdentityRole role = context.Roles.FirstOrDefault(r => r.Name == "Admin"); context.UserRoles.Add(new IdentityUserRole <string> { RoleId = role.Id, UserId = user.Id }); context.SaveChanges(); } } if (!context.AddressTypes.Any()) { List <AddressType> addressTypes = new List <AddressType> { AddressType.Create(AddressTypesEnum.FactAddress), AddressType.Create(AddressTypesEnum.LegalAddress), AddressType.Create(AddressTypesEnum.BirthAddress) }; context.AddRange(addressTypes); context.SaveChanges(); //List<Address> adresses = context.Addresses.ToList(); //AddressType factaddress = // context.AddressTypes.FirstOrDefault(a => a.TypeName == AddressTypesEnum.FactAddress.ToString()); //AddressType legaladdress = // context.AddressTypes.FirstOrDefault(a => a.TypeName == AddressTypesEnum.LegalAddress.ToString()); //AddressType birthaddress = // context.AddressTypes.FirstOrDefault(a => a.TypeName == AddressTypesEnum.BirthAddress.ToString()); //foreach (Address address in adresses) //{ // switch (address.TypeOfAddress) // { // case "factaddress": address.AddressType = factaddress; // break; // case "legaladdress": address.AddressType = legaladdress; // break; // case "birthaddress": address.AddressType = birthaddress; // break; // } //} //context.UpdateRange(adresses); //context.SaveChanges(); } }
/// <summary> /// Bind a window to some commands to be executed by the viewmodel. /// </summary> /// <param name="win"></param> public void InitCommandBinding(Window win) { this.InitEditCommandBinding(win); win.CommandBindings.Add(new CommandBinding(AppCommand.Exit, (s, e) => { this.AppExit_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.About, (s, e) => { this.AppAbout_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.ProgramSettings, (s, e) => { this.AppProgramSettings_CommandExecuted(); e.Handled = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowToolWindow, (s, e) => { if (e == null) { return; } var toolwindowviewmodel = e.Parameter as IToolWindow; if (toolwindowviewmodel == null) { return; } if (toolwindowviewmodel is IRegisterableToolWindow) { IRegisterableToolWindow registerTW = toolwindowviewmodel as IRegisterableToolWindow; registerTW.SetToolWindowVisibility(this, !toolwindowviewmodel.IsVisible); } else { toolwindowviewmodel.SetToolWindowVisibility(!toolwindowviewmodel.IsVisible); } e.Handled = true; })); // Standard File New command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => { TypeOfDocument t = TypeOfDocument.EdiTextEditor; if (e != null) { e.Handled = true; if (e.Parameter != null) { if (e.Parameter is TypeOfDocument) { t = (TypeOfDocument)e.Parameter; } } } this.OnNew(t); } )); // Standard File Open command binding via ApplicationCommands enumeration win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) => { string t = string.Empty; if (e != null) { if (e.Parameter != null) { if (e.Parameter is string) { t = (string)e.Parameter; } } } this.OnOpen(t); e.Handled = true; } )); // Close Document command // Closes the FileViewModel document supplied in e.parameter // or the Active document win.CommandBindings.Add(new CommandBinding(AppCommand.CloseFile, (s, e) => { try { FileBaseViewModel f = null; if (e != null) { e.Handled = true; f = e.Parameter as FileBaseViewModel; } if (f != null) { this.Close(f); } else { if (this.ActiveDocument != null) { this.Close(this.ActiveDocument); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { try { if (e != null) { e.Handled = true; e.CanExecute = false; EdiViewModel f = null; if (e != null) { e.Handled = true; f = e.Parameter as EdiViewModel; } if (f != null) { e.CanExecute = f.CanClose(); } else { if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanClose(); } } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); // Change the WPF/TextEditor highlighting theme currently used in the application win.CommandBindings.Add(new CommandBinding(AppCommand.ViewTheme, (s, e) => this.ChangeThemeCmd_Executed(s, e, win.Dispatcher))); win.CommandBindings.Add(new CommandBinding(AppCommand.BrowseURL, (s, e) => { Process.Start(new ProcessStartInfo("https://github.com/Dirkster99/Edi")); })); win.CommandBindings.Add(new CommandBinding(AppCommand.ShowStartPage, (s, e) => { StartPageViewModel spage = this.GetStartPage(true); if (spage != null) { logger.InfoFormat("TRACE Before setting startpage as ActiveDocument"); this.ActiveDocument = spage; logger.InfoFormat("TRACE After setting startpage as ActiveDocument"); } })); win.CommandBindings.Add(new CommandBinding(AppCommand.ToggleOptimizeWorkspace, (s, e) => { logger.InfoFormat("TRACE AppCommand.ToggleOptimizeWorkspace parameter is {0}.", (e == null ? "(null)" : e.ToString())); try { var newViewSetting = !this.IsWorkspaceAreaOptimized; this.IsWorkspaceAreaOptimized = newViewSetting; } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); win.CommandBindings.Add(new CommandBinding(AppCommand.LoadFile, (s, e) => { try { logger.InfoFormat("TRACE AppCommand.LoadFile parameter is {0}.", (e == null ? "(null)" : e.ToString())); if (e == null) { return; } string filename = e.Parameter as string; if (filename == null) { return; } logger.InfoFormat("TRACE AppCommand.LoadFile with: '{0}'", filename); this.Open(filename); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); win.CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { this.OnSave(this.ActiveDocument, false); } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_UnknownError_Caption, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { if (e != null) { e.Handled = true; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSave(); } } })); win.CommandBindings.Add(new CommandBinding(ApplicationCommands.SaveAs, (s, e) => { try { if (e != null) { e.Handled = true; } if (this.ActiveDocument != null) { if (this.OnSave(this.ActiveDocument, true)) { var mruList = ServiceLocator.Current.GetInstance <IMRUListViewModel>(); mruList.UpdateEntry(this.ActiveDocument.FilePath); this.mSettingsManager.SessionData.LastActiveFile = this.ActiveDocument.FilePath; } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => { try { if (e != null) { e.Handled = true; e.CanExecute = false; if (this.ActiveDocument != null) { e.CanExecute = this.ActiveDocument.CanSaveAs(); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } } )); // Execute a command to save all edited files and current program settings win.CommandBindings.Add(new CommandBinding(AppCommand.SaveAll, (s, e) => { try { // Save all edited documents if (this.mFiles != null) // Close all open files and make sure there are no unsaved edits { // If there are any: Ask user if edits should be saved IFileBaseViewModel activeDoc = this.ActiveDocument; try { for (int i = 0; i < this.Files.Count; i++) { IFileBaseViewModel f = this.Files[i]; if (f != null) { if (f.IsDirty == true && f.CanSaveData == true) { this.ActiveDocument = f; this.OnSave(f); } } } } catch (Exception exp) { _MsgBox.Show(exp.ToString(), Edi.Util.Local.Strings.STR_MSG_UnknownError_Caption, MsgBoxButtons.OK); } finally { if (activeDoc != null) { this.ActiveDocument = activeDoc; } } } // Save program settings this.SaveConfigOnAppClosed(); } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } })); // Execute a command to export UML editor content as image win.CommandBindings.Add(new CommandBinding(AppCommand.ExportUMLToImage, (s, e) => { try { if (this.vm_DocumentViewModel != null) { if ((this.vm_DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready) == true) { this.vm_DocumentViewModel.ExecuteExport(s, e, this.ActiveDocument.FileName + ".png"); } } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => // Execute this command only if an UML document is currently active { if (this.vm_DocumentViewModel != null) { e.CanExecute = (this.vm_DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready); } else { e.CanExecute = false; } } )); // Execute a command to export Text editor content as highlighted image content win.CommandBindings.Add(new CommandBinding(AppCommand.ExportTextToHTML, (s, e) => { try { if (this.ActiveEdiDocument != null) { this.ActiveEdiDocument.ExportToHTML(this.ActiveDocument.FileName + ".html", this.mSettingsManager.SettingData.TextToHTML_ShowLineNumbers, this.mSettingsManager.SettingData.TextToHTML_AlternateLineBackground); } } catch (Exception exp) { logger.Error(exp.Message, exp); _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton, this.mAppCore.IssueTrackerLink, this.mAppCore.IssueTrackerLink, Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true); } }, (s, e) => // Execute this command only if a Text document is currently active { if (this.ActiveEdiDocument != null) { e.CanExecute = true; } else { e.CanExecute = false; } } )); /// <summary> /// Removes ALL MRU entries (even pinned entries) from the current list of entries. /// </summary> win.CommandBindings.Add(new CommandBinding(AppCommand.ClearAllMruItemsCommand, (s, e) => { this.GetToolWindowVM <RecentFilesViewModel>().MruList.Clear(); })); /// <summary> /// Gets a command that removes all items that are older /// than a given <see cref="GroupType"/>. /// Eg.: Remove all MRU entries older than yesterday. /// </summary> win.CommandBindings.Add(new CommandBinding(AppCommand.RemoveItemsOlderThanThisCommand, (s, e) => { if (e.Parameter is GroupType == false) { return; } var param = (GroupType)e.Parameter; this.GetToolWindowVM <RecentFilesViewModel>().MruList.RemoveEntryOlderThanThis(param); }, (s, e) => { if (e.Parameter is GroupType == false) { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.MovePinnedMruItemUPCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.MovePinnedEntry(MoveMRUItem.Up, param); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.MovePinnedMruItemDownCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.MovePinnedEntry(MoveMRUItem.Down, param); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.PinItemCommand, (s, e) => { this.GetToolWindowVM <RecentFilesViewModel>().MruList.PinUnpinEntry(true, e.Parameter as IMRUEntryViewModel); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = true; return; } e.CanExecute = false; })); win.CommandBindings.Add(new CommandBinding(AppCommand.UnPinItemCommand, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { return; } var param = e.Parameter as IMRUEntryViewModel; this.GetToolWindowVM <RecentFilesViewModel>().MruList.PinUnpinEntry(false, e.Parameter as IMRUEntryViewModel); }, (s, e) => { if (e.Parameter is IMRUEntryViewModel == false) { e.CanExecute = false; return; } if ((e.Parameter as IMRUEntryViewModel).IsPinned == 0) //Make sure it is pinned { e.CanExecute = false; return; } e.CanExecute = true; })); win.CommandBindings.Add(new CommandBinding(AppCommand.PinUnpin, (s, e) => { this.PinCommand_Executed(e.Parameter, e); })); win.CommandBindings.Add(new CommandBinding(AppCommand.RemoveMruEntry, (s, e) => { this.RemoveMRUEntry_Executed(e.Parameter, e); })); win.CommandBindings.Add(new CommandBinding(AppCommand.AddMruEntry, (s, e) => { this.AddMRUEntry_Executed(e.Parameter, e); })); }