Exemple #1
0
        private void Back_Click(object sender, EventArgs e)
        {
            this.Hide();
            select ff = new select();

            ff.Show();
            ff.Show();
        }
Exemple #2
0
        private void Login1_Click(object sender, EventArgs e)
        {
            SqlConnection  conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Szalma Szilard\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30");
            SqlDataAdapter sda  = new SqlDataAdapter("select count(*) from login where username ='******' and password ='******'", conn);
            DataTable      dt   = new DataTable();

            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                select ff = new select();
                ff.Show();
            }
            else
            {
                MessageBox.Show("please enter correct username and password", "alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnection con = new MySqlConnection("host=localhost;user=admin;password=123456;database=project");

            try
            {
                con.Open();//หน้า login
                string          sql    = "SELECT * FROM login WHERE Username='******' AND Password='******'";
                MySqlCommand    cmd    = new MySqlCommand(sql, con);
                MySqlDataReader reader = cmd.ExecuteReader();
                bool            check  = false;
                while (reader.Read())
                {
                    check            = true;                             //เเสดงว่า username password มีข้อมูลอยู่ในดาต้าเบส
                    Program.username = reader.GetString("Username");     //เป็นเลขาที่เก็บข้อมูล ดึงข้อมูลออกมาใช้เก็บไว้ในคอม
                    Program.status   = reader.GetString("status_login"); //ดึงข้อมูล status_login
                }
                con.Close();
                if (check == false)//ตรวจสอบข้อมูล
                {
                    MessageBox.Show("ไม่มี UsernameและPassword นี้");
                }
                else//ถ้ามี check= true
                {
                    if (Program.status == "")//การเช็คสถานะของผู้ใช้ว่าว่างไหม
                    {
                        select se = new select();
                        se.ShowDialog();
                    }
                    else//ถ้าสถานะไม่ว่าง แสดงว่ามีเลขที่ใบเสร็จ เอาเลขที่ใบเสร็จไปตรวจสอบว่าเป็นการสังประเภทไหน
                    {
                        try//คำสั่งการทำงานปกติ
                        {
                            MySqlConnection con1 = new MySqlConnection("host=localhost;user=admin;password=123456;database=project");
                            con1.Open();
                            string          sql2    = "SELECT * FROM receipt WHERE no_receipt = '" + Program.status + "'";
                            MySqlCommand    cmd1    = new MySqlCommand(sql2, con1);
                            MySqlDataReader reader1 = cmd1.ExecuteReader();
                            while (reader1.Read())
                            {
                                no_receiptfromDB = reader1.GetString("group_receipt");
                            }

                            if (no_receiptfromDB == "บุพเฟ่ต์")
                            {
                                storetable s = new storetable();
                                s.ShowDialog();
                            }
                            else if (no_receiptfromDB == "กลับบ้าน")
                            {
                                confirm s = new confirm();
                                s.ShowDialog();
                            }
                        }
                        catch (Exception ex) //ทำงานเกิดข้อผิดพลาด ตรวจสอบเงื่อนไข
                        {
                            MessageBox.Show("เกิดข้อผิดพลาดเกี่ยวกับฐานข้อมูล กรุณาลองใหม่อีกครั้ง" + ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("เกิดข้อผิดพลาดในการเชื่อมต่อฐานข้อมูล" + ex);
            }
        }