Ejemplo n.º 1
0
        public Main()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
            Microsoft.Win32.RegistryKey dbc = key.OpenSubKey("software\\WisoftWatchClient", true);
            //注册热键(窗体句柄,热键ID,辅助键,实键)   
            RegisterHotKey(this.Handle, 888, (int)KeyModifiers.Ctrl ,  Keys.N);
            RegisterHotKey(this.Handle, 999,  ((int)KeyModifiers.Ctrl + (int)KeyModifiers.Shift),  Keys.A);
                     string username  = ConfigurationManager.AppSettings["Username"];
                     string password  = ConfigurationManager.AppSettings["Password"];
                     bool   checkpass = true;
                     string errorstr  = "";
                    
                                if (dbc == null || dbc.GetValue("Username") == null)
            {
                                {
                             checkpass = false;
                             errorstr  = "对不起,您的设置可能有问题,请重新设置!";

                            
                }
            }
                            else if (string.IsNullOrEmpty(username))
            {
                                {
                             checkpass = false;
                             errorstr  = "您好像是第一次登录系统,请设置用户名密码";

                            
                }
            }
                            else if (PersonDao.getAllPersonInfo(username, password).Count != 1)
            {
                                {
                             checkpass = false;
                             errorstr  = "您的用户名密码好像不正确,请设置用户名密码";

                            
                }
            }
                            else if (dbc.GetValue("Version").ToString() != "0.4.3")
            {
                                {
                             System.Diagnostics.Process.Start("notepad.exe", System.Environment.CurrentDirectory + "\\releasenote.txt");

                             dbc.SetValue("Version", "0.4.3");

                            
                }
            }
                    
                                if (!checkpass)
            {
                         MessageBox.Show(errorstr);

                Dbconfig db = new Dbconfig();
                if (db.ShowDialog() != DialogResult.OK)
                {
                    //this.Load += new EventHandler(main_Load);
                    this.Close();
                    System.Windows.Forms.Application.Exit();
                    //return;
                }
                else
                {
                    if (dbc.GetValue("Version").ToString() != "0.4.3")
                    {
                                        {
                                     System.Diagnostics.Process.Start("notepad.exe", System.Environment.CurrentDirectory + "\\releasenote.txt");

                                     dbc.SetValue("Version", "0.4.3");

                                    
                        }
                    }
                    InitializeComponent();
                    username = ConfigurationManager.AppSettings["Username"];
                    if (string.IsNullOrEmpty(username))
                    {
                        this.Text = this.Text + "--未登录";
                    }
                    else
                    {
                        this.Text = this.Text + "--" + username;
                    }
                }
            }
            else
            {
                try {
                    SqlDBUtil.CheckDBState();
                } catch (Exception) {
                    MessageBox.Show("数据库异常", "DBERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    System.Windows.Forms.Application.Exit();
                }
                GlobalParams.User = PersonDao.getAllPersonInfo(username, password)[0];
                InitializeComponent();
                this.Text = this.Text + "--" + username;
            }

            this.notifyIcon1.Visible = true;

            this.notifyIcon1.MouseClick += new MouseEventHandler(notifyIcon1_Click);
            this.SizeChanged            += new EventHandler(Main_MinimumSizeChanged);
            this.Closing += new CancelEventHandler(Main_Closing);
            LoadModules();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }