Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)

        {
            //
            if (txtboxUsername.Text == "" || txtboxPassword.Text == "" || comboBox1.Text == "")
            {
                MessageBox.Show("Login Details cannot be blank");
            }
            //

            if (attempt < 4)
            {
                SqlConnection  con = new SqlConnection("Data Source=WIN-O8HG7K9J35G;Initial Catalog=cmblogin;Integrated Security=True");
                SqlCommand     cmd = new SqlCommand("select * from StaffRegister where username='******' and password = '******'", con);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);
                string cmbItemValue = comboBox1.SelectedItem?.ToString();

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (dt.Rows[i]["DesignationID"].ToString() == cmbItemValue)
                        {
                            MessageBox.Show("You are login as a " + dt.Rows[i][6], "LOGIN");
                            if (comboBox1.SelectedIndex == 0)
                            {
                                this.Hide();
                                ChiefNurse cn = new ChiefNurse(comboBox1.Text);
                                cn.Show();
                            }
                            else if (comboBox1.SelectedIndex == 1)
                            {
                                this.Hide();
                                Doctor ss = new Doctor(comboBox1.Text);
                                ss.ShowDialog();
                            }

                            else if (comboBox1.SelectedIndex == 2)
                            {
                                this.Hide();
                                Nurse ss = new Nurse(comboBox1.Text);
                                ss.Show();
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect login details." + attempt);
                    //MessageBox.Show("Try again. " + attempt, "Information", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Information);
                }
            }
            else if (attempt == 4)
            {
                MessageBox.Show("Login attempts exceeded");
                txtboxUsername.Enabled = false;
                txtboxPassword.Enabled = false;
                this.Close();
            }
            attempt++;
        }