/Demos/XVideoRental/XVideoRental.Win/WinApplication.cs

https://github.com/tiaohai/eXpand · C# · 102 lines · 93 code · 9 blank · 0 comment · 17 complexity · 94e139fa4d4022086f797a6ab29e4845 MD5 · raw file

  1. using System;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4. using DevExpress.ExpressApp;
  5. using DevExpress.ExpressApp.Actions;
  6. using DevExpress.ExpressApp.Security;
  7. using DevExpress.ExpressApp.Xpo;
  8. using DevExpress.XtraSplashScreen;
  9. using DevExpress.XtraWaitForm;
  10. using Xpand.ExpressApp.Core;
  11. using Xpand.ExpressApp.Win;
  12. using SplashScreen = DevExpress.ExpressApp.Win.Utils.SplashScreen;
  13. namespace XVideoRental.Win {
  14. public partial class XVideoRentalWindowsFormsApplication : XpandWinApplication {
  15. public XVideoRentalWindowsFormsApplication() {
  16. InitializeComponent();
  17. DelayedViewItemsInitialization = true;
  18. LastLogonParametersRead += OnLastLogonParametersRead;
  19. SplashScreen = null;
  20. SplashScreenType = typeof(SplashScreen);
  21. }
  22. public override void UpdateSplash(string context, string caption, string description,
  23. params object[] additionalParams) {
  24. base.UpdateSplash(context, caption, description, additionalParams);
  25. if (IsSplashScreenManagerFormVisible() && typeof(WaitForm).IsAssignableFrom(SplashScreenType)) {
  26. if (!string.IsNullOrEmpty(caption)) {
  27. SplashScreenManager.Default.SetWaitFormCaption(caption);
  28. }
  29. if (!string.IsNullOrEmpty(description)) {
  30. SplashScreenManager.Default.SetWaitFormDescription(description);
  31. }
  32. Application.DoEvents();
  33. }
  34. }
  35. public override void StartSplash() {
  36. base.StartSplash();
  37. if (SplashScreenType != null) {
  38. SplashScreenManager.ShowForm(null, SplashScreenType, true, false, false);
  39. }
  40. }
  41. public override void StopSplash() {
  42. base.StopSplash();
  43. if (IsSplashScreenManagerFormVisible()) {
  44. SplashScreenManager.CloseForm(false, 0, null, true);
  45. }
  46. }
  47. protected override void Logon(PopupWindowShowActionExecuteEventArgs logonWindowArgs) {
  48. StartSplash();
  49. base.Logon(logonWindowArgs);
  50. }
  51. void OnLastLogonParametersRead(object sender, LastLogonParametersReadEventArgs e) {
  52. var logonParameters = e.LogonObject as AuthenticationStandardLogonParameters;
  53. if (logonParameters != null) {
  54. if (String.IsNullOrEmpty(logonParameters.UserName)) {
  55. logonParameters.UserName = "Admin";
  56. }
  57. }
  58. }
  59. protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
  60. args.ObjectSpaceProvider = new XPObjectSpaceProvider(args.ConnectionString, args.Connection);
  61. }
  62. void XVideoRentalWindowsFormsApplication_DatabaseVersionMismatch(object sender,
  63. DatabaseVersionMismatchEventArgs e) {
  64. if (this.DropDatabaseOnVersionMissmatch() > 0)
  65. Application.ExitThread();
  66. #if DEBUG
  67. e.Updater.Update();
  68. e.Handled = true;
  69. #else
  70. if (true) {
  71. e.Updater.Update();
  72. e.Handled = true;
  73. }
  74. else {
  75. throw new InvalidOperationException(
  76. "The application cannot connect to the specified database, because the latter doesn't exist or its version is older than that of the application.\r\n" +
  77. "This error occurred because the automatic database update was disabled when the application was started without debugging.\r\n" +
  78. "To avoid this error, you should either start the application under Visual Studio in debug mode, or modify the " +
  79. "source code of the 'DatabaseVersionMismatch' event handler to enable automatic database update, " +
  80. "or manually create a database using the 'DBUpdater' tool.\r\n" +
  81. "Anyway, refer to the 'Update Application and Database Versions' help topic at http://www.devexpress.com/Help/?document=ExpressApp/CustomDocument2795.htm " +
  82. "for more detailed information. If this doesn't help, please contact our Support Team at http://www.devexpress.com/Support/Center/");
  83. }
  84. #endif
  85. }
  86. void XVideoRentalWindowsFormsApplication_CustomizeLanguagesList(object sender, CustomizeLanguagesListEventArgs e) {
  87. string userLanguageName = Thread.CurrentThread.CurrentUICulture.Name;
  88. if (userLanguageName != "en-US" && e.Languages.IndexOf(userLanguageName) == -1) {
  89. e.Languages.Add(userLanguageName);
  90. }
  91. }
  92. }
  93. }