Ejemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.txtLoginName.Text.Trim()))
            {
                MessageBox.Show("Please input login name.", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.txtLoginName.Focus();
                return;
            }
            if (String.IsNullOrEmpty(this.txtPassword.Text.Trim()))
            {
                MessageBox.Show("Please input the password.", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.txtPassword.Focus();
                return;
            }


            String passWord = RijndaelAlgorithm.Encrypt(this.txtPassword.Text.Trim());
            String userName = this.txtLoginName.Text.Trim().ToLower();

            DataRow[] dtUsers = userInfoList.Select("[LoginName] = '" + userName + "' And [Password] = '" + passWord + "' AND Approved = 'True'");

            if (dtUsers.Length > 0)
            {
                var      version       = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                DateTime buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(
                                                                          TimeSpan.TicksPerDay * version.Build +            // days since 1 January 2000
                                                                          TimeSpan.TicksPerSecond * 2 * version.Revision)); /* seconds since midnight,
                                                                                                                             * (multiply by 2 to get original) */
                if (buildDateTime < Convert.ToDateTime(dtUsers[0]["VersionTime"]))                                          //Compare with allowed version build time
                {
                    MessageBox.Show("The version of this program is out dated, please install the latest version. Application is closing......", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.Close();
                }

                StrPublicUserName = userName;

                funcLib.releaseExclusiveControlOverDataTable();

                MainForm MF = new MainForm();
                MF.WindowState = FormWindowState.Maximized;
                MF.Show();
                this.Hide();
            }
            else
            {
                numberOfTry -= 1;

                if (numberOfTry == 0)
                {
                    MessageBox.Show("Failed 3 times. Application is closing......", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }

                MessageBox.Show("Either Login name or password is wrong, please input again", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtPassword.Focus();
            }
        }