protected override void OnFormClosing(FormClosingEventArgs e) { if (Options.SettingInitializer.GetProgramSetting().ShowExitDialog) { MessageBox.VDialogResult result = PersianMessageBox.Show(this, "مایل به خروج از برنامه هستید؟", "تایید خروج", new Njit.MessageBox.VDialogButton[] { new Njit.MessageBox.VDialogButton(MessageBox.VDialogResult.Yes), new Njit.MessageBox.VDialogButton(MessageBox.VDialogResult.No) }, MessageBox.VDialogIcon.Question, MessageBox.VDialogDefaultButton.Button1, System.Windows.Forms.RightToLeft.Yes, false, null, null, "ApplicationExit", "پیام خروج از برنامه", new MessageBox.VDialogButton[] { new MessageBox.VDialogButton(MessageBox.VDialogResult.No) }); if (result != MessageBox.VDialogResult.Yes) { this.ShutdownWhenExit = false; e.Cancel = true; } } base.OnFormClosing(e); }
protected override void OnShown(EventArgs e) { base.OnShown(e); if (this.SingleInstanceProgram) { if (CloseIfNotMainInstance()) { return; } } try { lastInputLanguage = Application.CurrentInputLanguage; InputLanguage persianLang = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("fa-IR")); if (persianLang == null) { persianLang = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("fa")); } if (persianLang != null) { Application.CurrentInputLanguage = persianLang; } } catch { } if (this.DesignMode) { return; } if (Options.SettingInitializer == null) { throw new Exception("تنظیمات برنامه پیاده سازی نشده است"); } Options.SettingInitializer.GetProgramSetting().CloseSplashScreen(); if (Options.SettingInitializer != null) { if (!Options.SettingInitializer.GetUserSetting().Login()) { Options.SettingInitializer.GetProgramSetting().ShowExitDialog = false; this.Close(); return; } } UpdateDatabases(); DateTime serverDateTime = Options.SettingInitializer.GetDataAccess().Connection.GetServerDateTime(); TimeSpan timeDifference = serverDateTime.Subtract(DateTime.Now); do { if (timeDifference.TotalMinutes >= Options.SettingInitializer.GetProgramSetting().MinuteDifferenceWithServerToShowMessage || timeDifference.TotalMinutes <= -Options.SettingInitializer.GetProgramSetting().MinuteDifferenceWithServerToShowMessage) { MessageBox.VDialogResult dResult = PersianMessageBox.Show(this, string.Format("این سیستم {0} با سرور اختلاف ساعت دارد\r\nساعت سرور: {1}", timeDifference.GetText(), serverDateTime.ToLongTimeString()), "اختلاف ساعت", new MessageBox.VDialogButton[] { new MessageBox.VDialogButton(MessageBox.VDialogResult.OK, "تایید"), new MessageBox.VDialogButton("تغییر تاریخ / ساعت", ChangeSystemDate, true), new MessageBox.VDialogButton(MessageBox.VDialogResult.Cancel, "خروج از برنامه") }, MessageBox.VDialogIcon.Warning, MessageBox.VDialogDefaultButton.Button1, System.Windows.Forms.RightToLeft.Yes, false, null, null, null, null, null); if (dResult == MessageBox.VDialogResult.Cancel) { Options.SettingInitializer.GetProgramSetting().ShowExitDialog = false; this.Close(); return; } } Njit.Sql.DataAccess da = new Sql.DataAccess(Options.SettingInitializer.GetSqlSetting().DatabaseConnection.ConnectionString); serverDateTime = da.Connection.GetServerDateTime(); timeDifference = serverDateTime.Subtract(DateTime.Now); da.Dispose(); }while (timeDifference.TotalHours >= Options.SettingInitializer.GetProgramSetting().AllowableHourDifferenceWithServer || timeDifference.TotalHours <= -Options.SettingInitializer.GetProgramSetting().AllowableHourDifferenceWithServer); if (this.RegisterSystemUtilityServer) { int registeredChannels = 0; Exception exception = null; try { System.Runtime.Remoting.Channels.Tcp.TcpChannel _TcpChannel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel(Options.SettingInitializer.GetProgramSetting().NetworkPort); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_TcpChannel, false); registeredChannels++; } catch (Exception ex) { exception = ex; } try { System.Collections.IDictionary properties = new System.Collections.Hashtable(); properties["name"] = "tcp6"; properties["port"] = Options.SettingInitializer.GetProgramSetting().NetworkPort; properties["bindTo"] = "[::]"; System.Runtime.Remoting.Channels.Tcp.TcpServerChannel _TcpChannelV6 = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(properties, null); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_TcpChannelV6, false); registeredChannels++; } catch (Exception ex) { exception = ex; } if (registeredChannels > 0) { try { System.Runtime.Remoting.RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off; System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(Njit.Common.SystemUtility), Options.SettingInitializer.GetProgramSetting().NetworkName, System.Runtime.Remoting.WellKnownObjectMode.Singleton); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در راه اندازی سرور" + "\r\n\r\n" + ex.Message); } } else { PersianMessageBox.Show(this, "خطا در راه اندازی سرور" + "\r\n\r\n" + exception.Message); } } try { Cursor = Cursors.WaitCursor; Njit.Common.SystemUtility systemUtility = Options.SystemUtility; systemUtility.SendMessage(System.Net.Dns.GetHostName(), "--HelloWorld"); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در اتصال به سرور" + "\r\n" + "اتصال به نرم افزار بر روی سرور با خطا مواجه شده است" + "\r\n" + "توجه داشته باشید که این نرم افزار باید بر روی سرور اجرا شده باشد و یک کاربر وارد سیستم شده باشد" + "\r\n\r\n" + ex.Message); } finally { Cursor = Cursors.Default; } }