コード例 #1
0
ファイル: frmSignIn.cs プロジェクト: etechuk/hcfcpc
        private void btnSign_Click(object sender, EventArgs e)
        {
            if (pSettings.Visible)
            {
                pSettings.Visible = false;
            }

            txtUser.Enabled = false;
            txtPass.Enabled = false;
            btnSign.Enabled = false;
            cpMain.Visible = true;
            bool go = true;

            DataSet ds = Program.DB.SelectAll("SELECT ID FROM Users WHERE Username='******';");
            if (ds.Tables.Count < 1)
            {
                MessageBox.Show("The username provided wasn't found.\nPlease check and try again.", "Username", MessageBoxButtons.OK, MessageBoxIcon.Information);
                go = false;
            }

            if (go)
            {
                ds = Program.DB.SelectAll("SELECT ID,UserGroup,Status,NameFirst,NameLast FROM Users WHERE Username='******' AND Password='******';");
                if (ds.Tables.Count < 1)
                {
                    MessageBox.Show("You've entered an incorrect password.\nPlease check and try again.", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    go = false;
                }
            }

            int status = 0;

            if (go && ds.Tables[0].Rows.Count < 1)
            {
                MessageBox.Show("The details you entered were not found.\nPlease check and try again.", "Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
                go = false;
            }
            else
            {
                if (ds.Tables.Count > 0)
                {
                    status = Convert.ToInt32(ds.Tables[0].Rows[0]["Status"].ToString());
                    switch (status)
                    {
                        case 2:
                            MessageBox.Show("The user you entered is currently disabled.\nPlease contact an administrator.", "Disabled", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            go = false;
                            break;
                        case 3:
                            MessageBox.Show("The user you entered is currently banned.\nPlease contact an administrator.", "Banned", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            go = false;
                            break;
                        case 4:
                            MessageBox.Show("The user you entered has been deleted.\nPlease contact an administrator.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            go = false;
                            break;
                    }
                }
                else
                {
                    go = false;
                }
            }

            if (!go)
            {
                txtUser.Enabled = true;
                txtPass.Enabled = true;
                txtPass.Text = "";
                btnSign.Enabled = true;
                cpMain.Visible = false;
                txtPass.Focus();
                return;
            }

            if (txtUser.Text.Length > 0 && cbxRemember.Checked)
            {
                Properties.Settings.Default.UserName = txtUser.Text.Trim();
                Properties.Settings.Default.UserRemember = cbxRemember.Checked;
            }
            else
            {
                Properties.Settings.Default.UserName = "";
                Properties.Settings.Default.UserRemember = false;
            }
            Properties.Settings.Default.Save();

            int iUserGroup = Convert.ToInt32(ds.Tables[0].Rows[0]["UserGroup"].ToString());
            Program.Global.UserIsAdmin = iUserGroup == 3 || iUserGroup == 4 ? true : false;
            Program.Global.UserID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString());
            Program.Global.UserSigned = true;
            Program.Global.UserFirstName = ds.Tables[0].Rows[0]["NameFirst"].ToString();
            Program.Global.UserLastName = ds.Tables[0].Rows[0]["NameLast"].ToString();

            cpMain.Visible = false;
            txtUser.Enabled = true;
            txtPass.Enabled = true;
            txtPass.Text = "";
            btnSign.Enabled = true;

            Hide();
            Form frmMain = new frmMain();
            frmMain.Show();
        }
コード例 #2
0
ファイル: frmSignIn.cs プロジェクト: etechuk/fexipc
        private void bwSign_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            spData.SlideOutButtonVisible = true;
            cpSign.IsRunning = false;
            cpSign.Visible = false;
            btnSign.Enabled = true;
            txtUser.Enabled = true;
            txtPass.Enabled = true;
            txtPass.Text = "";

            if (!Program.Globals.UserIsSigned)
            {
                txtPass.Focus();
            }
            else
            {
                Hide();
                Form frmMain = new frmMain();
                frmMain.Show();
            }
        }