Exemplo n.º 1
0
        /// <summary>
        /// Prompts user (if reqd) to select preferred language
        /// </summary>
        public static bool SetCulture()
        {
            bool isDefault = false;

            if (!String.IsNullOrEmpty(Common.AppPreferences.Language))
            {
                ResourceUtils.SetCulture(Common.AppPreferences.Language);
                ResourceUtils.InstallLanguageForUser();
                return(true);
            }

            var installedLanguages = ResourceUtils.EnumerateInstalledLanguages();

            if (installedLanguages.Count() == 0)
            {
                MessageBox.Show("No language extensions found.  Exiting", Common.AppPreferences.AppName);
                return(false);
            }

            if (installedLanguages.Count() > 1)
            {
                var cultureInfo = LanguageSelectForm.SelectLanguage();
                if (cultureInfo == null)
                {
                    MessageBox.Show("English will be set as default", Common.AppPreferences.AppName);
                    ResourceUtils.SetEnglishCulture();
                    Common.AppPreferences.Language = "en";
                }
                else
                {
                    ResourceUtils.SetCulture(cultureInfo.Name);
                    Common.AppPreferences.Language = cultureInfo.Name;
                    isDefault = LanguageSelectForm.IsDefault;
                }

                if (isDefault)
                {
                    Common.AppPreferences.Save();
                }
            }
            else
            {
                ResourceUtils.SetCulture(installedLanguages.ElementAt(0));
            }

            ResourceUtils.InstallLanguageForUser();

            return(true);
        }
Exemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                //处理未捕获的异常 Add by ChengSk - 20180809
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理  UI线程异常 Add by ChengSk - 20180809
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常 Add by ChengSk - 20180809
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandleException);

                // nLength = Marshal.SizeOf(typeof(stWeightBaseInfo));
#if REALEASE
                GlobalDataInterface.CreatErorrFile();
#endif

                // int nLength = Marshal.SizeOf(typeof(stGlobal));

                //语言选择功能
                GlobalDataInterface.selectLanguage = Common.Commonfunction.GetAppSetting("选择的语言");

                //string path; //Add by xcw - 20191031
                //string currentPath = System.AppDomain.CurrentDomain.BaseDirectory;
                //PrintProtocol.logoPathName = currentPath + PrintProtocol.logoPathName;  //更改LOGO标签地址(相对地址转绝对地址)
                //string currentDefaultPath = currentPath + "config\\";
                //path = currentDefaultPath + "languagekind.txt"; //Add by xcw - 20191031
                //if (!Directory.Exists(currentDefaultPath))
                //{
                //    Directory.CreateDirectory(currentDefaultPath);
                //}

                //if (!File.Exists(path))
                //{
                //    FileStream fs = File.Create(path);
                //    fs.Close();
                //}


                //StreamReader sr = new StreamReader(path, Encoding.Default);
                //string m = sr.ReadToEnd();//显示内容
                //m = m.Replace("\r\n", ""); //Add by xcw - 20191031
                //sr.Close();
                //GlobalDataInterface.selectLanguage = m;
                //MessageBox.Show(GlobalDataInterface.selectLanguage);
                if (GlobalDataInterface.selectLanguage == "" || GlobalDataInterface.selectLanguage == "null")
                //if (true)
                {
                    LanguageSelectForm languageSelectForm = new LanguageSelectForm();
                    languageSelectForm.ShowDialog();
                }
                Thread.CurrentThread.CurrentUICulture   = new System.Globalization.CultureInfo(GlobalDataInterface.selectLanguage);
                GlobalDataInterface.selectLanguageIndex = LanguageContainer.LanguageVersionIndex(GlobalDataInterface.selectLanguage);

                //信息提示框按钮附名称
                //MessageBoxManager.OK = "OK";
                //MessageBoxManager.No = "No";
                //MessageBoxManager.Yes = "Yes";
                //MessageBoxManager.Cancel = "Cancel";
                //MessageBoxManager.Retry = "Retry";
                //MessageBoxManager.Ignore = "Ignore";
                //MessageBoxManager.Abort = "Abort";
                //MessageBoxManager.Register();
                MessageBoxManager.OK     = LanguageContainer.ProgramMessageBoxManagerOK[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.No     = LanguageContainer.ProgramMessageBoxManagerNo[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Yes    = LanguageContainer.ProgramMessageBoxManagerYes[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Cancel = LanguageContainer.ProgramMessageBoxManagerCancel[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Retry  = LanguageContainer.ProgramMessageBoxManagerRetry[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Ignore = LanguageContainer.ProgramMessageBoxManagerIgnore[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Abort  = LanguageContainer.ProgramMessageBoxManagerAbort[GlobalDataInterface.selectLanguageIndex];
                MessageBoxManager.Register();

                ////显示启动界面线程
                Thread thSplash = new Thread(new ThreadStart(ShowSplashForm));
                thSplash.Priority     = ThreadPriority.Normal;
                thSplash.IsBackground = true;
                thSplash.Start();
                //初始化系统线程
                Thread thInitialSysterm = new Thread(new ThreadStart(InitialSysterm));
                thInitialSysterm.Priority     = ThreadPriority.Highest;
                thInitialSysterm.IsBackground = true;
                thInitialSysterm.Start();
                thInitialSysterm.Join();

                if (m_splashForm != null)
                {
                    m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.Close(); }));
                }
                thSplash.Join();

                //模拟测试广播通信代码 正常工作时注释掉
                Thread thSendBroadcast = new Thread(new ThreadStart(sendBroadcast));
                thSendBroadcast.IsBackground = true;
                thSendBroadcast.Start();

                if (IsSystemContinue)
                {
                    ////语言选择功能
                    //GlobalDataInterface.selectLanguage = Common.Commonfunction.GetAppSetting("选择的语言"); //Note by ChengSk - 20180723 代码放到网络连接之前
                    //if (GlobalDataInterface.selectLanguage == "null")
                    //{
                    //    LanguageSelectForm languageSelectForm = new LanguageSelectForm();
                    //    languageSelectForm.ShowDialog();
                    //}
                    //Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GlobalDataInterface.selectLanguage);
                    //GlobalDataInterface.selectLanguageIndex = LanguageContainer.LanguageVersionIndex(GlobalDataInterface.selectLanguage);

                    //数据库配置功能  Add by ChengSk 20140320  ---START---
                    GlobalDataInterface.currentDatabase = Common.Commonfunction.GetAppSetting("当前数据库");
                    GlobalDataInterface.dataBaseConn    = "data source=" + Common.Commonfunction.GetAppSetting("数据源") +
                                                          ";database=" + Common.Commonfunction.GetAppSetting("数据库") +
                                                          ";user="******"用户名") +
                                                          ";pwd=" + Common.Commonfunction.GetAppSetting("密码");
                    bool          isConnSuccess = false;
                    SqlConnection conn          = new SqlConnection(GlobalDataInterface.dataBaseConn);
                    try
                    {
                        conn.Open();
                        isConnSuccess = true;
                        conn.Close();   //Add 20180919
                        conn.Dispose(); //Add 20180919
                    }
                    catch (Exception ex)
                    {
                        isConnSuccess = false;
                    }
                    if (GlobalDataInterface.currentDatabase == "null" || !isConnSuccess)
                    {
                        DatabaseSetForm databaseSetForm = new DatabaseSetForm();
                        databaseSetForm.ShowDialog();
                        if (GlobalDataInterface.DatabaseSet)
                        {
                            return;
                        }
                    }
                    GlobalDataInterface.databaseOperation = new DB.DataBaseOperation();
                    // ---END-- -


                    GlobalDataInterface.mainform = new MainForm();
                    Application.Run(GlobalDataInterface.mainform);
                }

                global.DestroyTCPServerMarsterSocket(); //Add by ChengSk - 20180723
#if REALEASE
                System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
                int handleCount = p.HandleCount;  //程序的句柄数     Add by ChengSk - 20180906
                GlobalDataInterface.WriteErrorInfo("程序即将退出...,当前句柄数量:" + handleCount.ToString());
                GlobalDataInterface.CloseErorrFile();
#endif
                Application.ThreadException -= new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandleException);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Program中函数Main出错:" + ex + "\n代码定位:" + ex.StackTrace);
#if REALEASE
                System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
                int handleCount = p.HandleCount;  //程序的句柄数     Add by ChengSk - 20180906
                GlobalDataInterface.WriteErrorInfo("程序即将退出...,当前句柄数量:" + handleCount.ToString());
                GlobalDataInterface.WriteErrorInfo(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "Program中函数Main出错:" + ex + "\n代码定位:" + ex.StackTrace);
#endif
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 语言切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 语言切换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LanguageSelectForm languageSelectForm = new LanguageSelectForm(1);

            languageSelectForm.ShowDialog();
        }