예제 #1
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            LoginFrm loginF   = new LoginFrm();
            Patient  patientF = new Patient();

            //Progress bar starting
            progressBar1.Style = ProgressBarStyle.Marquee;
            progressBar1.MarqueeAnimationSpeed = 30;

            var updatedLines = new List <string>();

            using (StreamReader reader = new StreamReader(@"C:\Users\Aron\Desktop\ARON\C#\K.txt"))
            {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    int counter = 1;
                    updatedLines.Add(line);
                    //Spliting the username and password using a Split metthod
                    string[] data = line.Split(':');
                    if (data[0] == UserNtxtbx.Text.Trim() && data[1] == PassWtxtb.Text.Trim())
                    {
                        MessageBox.Show("LOGIN SUCCESSFULLY", "PROGRAM", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Hide();
                        patientF.Show();
                        reader.ReadToEnd();
                        counter++;
                        break;
                    }
                    //Else statement for invalid username or password
                    else
                    {
                        MessageBox.Show("INVALID USERNAME OR PASSWORD", "PROGRAM", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Show();
                        UserNtxtbx.Text = "";
                        PassWtxtb.Text  = "";
                        break;
                    }
                }
                reader.Close();
            }
        }
예제 #2
0
파일: LoginFrm.cs 프로젝트: ARON97/C-POE
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            LoginFrm loginF = new LoginFrm();
            Menu     MenuF  = new Menu();

            //Progress bar starting
            progressBar1.Style = ProgressBarStyle.Marquee;
            progressBar1.MarqueeAnimationSpeed = 30;

            //Throwing an exception in the try block when the database is not found
            try
            {
                //Establishing the connection
                SqlConnection con = new SqlConnection(cs);
                SqlCommand    cmd = new SqlCommand("Select * from Login_tbl where UserName=@username and Password=@password", con);
                cmd.Parameters.AddWithValue("@username", UserNtxtbx.Text);
                cmd.Parameters.AddWithValue("@password", PassWtxtb.Text);
                con.Open();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet        ds    = new DataSet();
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;
                //if count is 1, the open the menu form
                if (count == 1)
                {
                    MessageBox.Show("LOGIN SUCCESSFULLY", "LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Hide();
                    Menu menuF = new Menu();
                    menuF.Show();
                }
                else
                {
                    MessageBox.Show("Please enter a valid username or password!!!", "Unsuccesful Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            //The block of code that handles an exception when the application cannot connect to the database
            catch (SqlException ex)
            {
                MessageBox.Show("Sorry for the inconvenience. An unexpected error occur.", "Unable to connect to database" + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {

            LoginFrm loginF = new LoginFrm();
            Menu MenuF = new Menu();

            //Progress bar starting
            progressBar1.Style = ProgressBarStyle.Marquee;
            progressBar1.MarqueeAnimationSpeed = 30;

            
                //Establishing the connection
                SqlConnection con = new SqlConnection(cs);
                SqlCommand cmd = new SqlCommand("Select * from Login_tbl where UserName=@username and Password=@password", con);
                cmd.Parameters.AddWithValue("@username", UserNtxtbx.Text);
                cmd.Parameters.AddWithValue("@password", PassWtxtb.Text);
                con.Open();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;
                //if count is 1, the open the menu form
                if (count == 1)
                {
                    MessageBox.Show("LOGIN SUCCESSFULLY", "LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Hide();
                    Menu menuF = new Menu();
                    menuF.Show();
                }
                else
                {
                    MessageBox.Show("Please enter a valid username or password!!!", "Unsuccesful Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }