示例#1
0
        private void btn_exit_Click(object sender, EventArgs e)
        {
            EmpStart emp_start = new EmpStart();

            emp_start.Show();
            this.Hide();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from Login where username = '******' and password= '******'";
                cmd.ExecuteNonQuery();
                DataTable        dt = new DataTable();
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                i = Convert.ToInt32(dt.Rows.Count.ToString());
                Console.WriteLine(i);

                //login
                if (i == 0)
                {
                    MessageBox.Show("fail");
                    Console.WriteLine("login failed: " + tb_usern.Text + ";" + tb_pass.Text + "");
                }
                //admin login
                else if (i != 0 && tb_usern.Text == "admin")
                {
                    AdminStart a = new AdminStart();
                    Console.WriteLine("logged in as admin");
                    this.Hide();
                    a.Show();
                }
                //emp login
                else
                {
                    EmpStart em = new EmpStart();
                    Console.WriteLine("logged in as emplyee");
                    this.Hide();
                    em.Show();
                }

                con.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }