Example #1
0
File: Log_in.cs Project: ysnna/QLXe
        private void button_LOGIN_Click(object sender, EventArgs e)
        {
            MY_DB          db      = new MY_DB();
            STUDENT        student = new STUDENT();
            SqlDataAdapter da      = new SqlDataAdapter();
            DataTable      dt      = new DataTable();
            SqlCommand     cmd     = new SqlCommand("select * from Login", db.getConnection);

            //cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = txtUsername.Text;
            //cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = txtPassword.Text;
            da.SelectCommand = cmd;
            da.Fill(dt);
            int count = dt.Rows.Count;

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    if (txtUsername.Text == dt.Rows[i]["username"].ToString() && txtPassword.Text == dt.Rows[i]["password"].ToString())
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
                if (this.DialogResult != DialogResult.OK)
                {
                    MessageBox.Show("Invalid Username or Password", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
File: Log_in.cs Project: ysnna/QLXe
        private void ButtonRegister_Click(object sender, EventArgs e)
        {
            if (chkAdmin.Checked == true)
            {
                MY_DB          db  = new MY_DB();
                SqlCommand     cmm = new SqlCommand("select * from Login", db.getConnection);
                SqlDataAdapter da  = new SqlDataAdapter();
                DataTable      dt  = new DataTable();
                da.SelectCommand = cmm;
                da.Fill(dt);
                int        countRow = dt.Rows.Count;
                SqlCommand cmd      = new SqlCommand("insert into Login (id, username, password)" +
                                                     " values (@id, @user, @pass)", db.getConnection);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value       = countRow;
                cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = txtUsername.Text;
                cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = txtPassword.Text;

                db.openConnection();
                if (cmd.ExecuteNonQuery() == 1)
                {
                    db.closeConnection();
                }
                else
                {
                    db.closeConnection();
                }
                da.InsertCommand = cmd;
                da.Update(dt);
                MessageBox.Show("Sign up successful", "Adding...", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #3
0
        private void buttonFind_Click(object sender, EventArgs e)
        {
            #region Tìm kiếm theo ID của Thầy

            /*
             * if (IsNumber(txtSearch.Text) == true)
             * {
             *  int id = int.Parse(txtSearch.Text);
             *  SqlCommand cmd = new SqlCommand("select id, fname, lname, bdate, gender, phone, address, picture from Std where id = " + id);
             *  DataTable table = student.getStudents(cmd);
             *  if (table.Rows.Count >= 0)
             *  {
             *      TextBoxID.Text = table.Rows[0]["id"].ToString();
             *      TextBoxFname.Text = table.Rows[0]["fname"].ToString();
             *      TextBoxLname.Text = table.Rows[0]["lname"].ToString();
             *      DateTimePicker1.Value = (DateTime)table.Rows[0]["bdate"];
             *      if (table.Rows[0]["gender"].ToString() == "Female")
             *      {
             *          RadioButtonFemale.Checked = true;
             *      }
             *      else RadioButtonMale.Checked = true;
             *      TextBoxPhone.Text = table.Rows[0]["phone"].ToString();
             *      TextBoxAddress.Text = table.Rows[0]["address"].ToString();
             *      byte[] pic = (byte[])table.Rows[0]["picture"];
             *      MemoryStream picture = new MemoryStream(pic);
             *      PictureBoxStudentImage.Image = Image.FromStream(picture);
             *      MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  }
             *  else MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *
             * }
             * else
             * {
             *  studentsListForm up = new studentsListForm();
             *  up.ShowDialog();
             *
             * }
             */
            #endregion
            MY_DB mydb = new MY_DB();
            if (IsNumber(TextBoxSearch.Text))   //tìm kiếm theo ID
            {
                int        id      = int.Parse(TextBoxSearch.Text);
                SqlCommand command = new SqlCommand("SELECT id, fname, lname, bdate, gender, phone, address, picture from Std where id = " + id + "or phone = " + id, mydb.getConnection);
                //SqlCommand comand = new SqlCommand(query + id, db.GetConnection);
                DataTable      table   = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    TextBoxID.Text        = table.Rows[0]["id"].ToString();
                    TextBoxFname.Text     = table.Rows[0]["fname"].ToString();
                    TextBoxLname.Text     = table.Rows[0]["lname"].ToString();
                    DateTimePicker1.Value = (DateTime)table.Rows[0]["bdate"];
                    if (table.Rows[0]["gender"].ToString() == "Female")
                    {
                        RadioButtonFemale.Checked = true;
                    }
                    else
                    {
                        RadioButtonMale.Checked = true;
                    }
                    TextBoxPhone.Text   = table.Rows[0]["phone"].ToString();
                    TextBoxAddress.Text = table.Rows[0]["address"].ToString();
                    byte[]       pic     = (byte[])table.Rows[0]["picture"];
                    MemoryStream picture = new MemoryStream(pic);
                    PictureBoxStudentImage.Image = Image.FromStream(picture);
                }
                else
                {
                    MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else  //Tìm theo tên
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Std WHERE fname = @name", mydb.getConnection);
                command.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBoxSearch.Text;
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    AdvancedSearch find = new AdvancedSearch();
                    find.DataGridView1.DataSource = student.getStudents(command);
                    find.DataGridView1.ReadOnly   = true;
                    DataGridViewImageColumn picCol = new DataGridViewImageColumn();
                    find.DataGridView1.RowTemplate.Height = 90;
                    picCol             = (DataGridViewImageColumn)find.DataGridView1.Columns[7];
                    picCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
                    find.DataGridView1.AllowUserToAddRows = false;
                    find.Show();
                }
                else
                {
                    MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }