Esempio n. 1
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            string maGV  = cb_maGV.Text;
            string tenGV = tb_tengv.Text;
            string tenDN = tb_tenDN.Text;
            string mk    = tb_mk.Text;

            if (tenDN == "" || mk == "")
            {
                MessageBox.Show("Tên đăng nhập hoặc mật khẩu  không được để trống!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
            else
            {
                Connect_DB.openConn();
                string     lenh = @"insert into taikhoan(magiaovien,matkhau,tentaikhoan)
                            values (" + maGV + ",N'" + mk + "','" + tenDN + "')";
                SqlCommand cmd  = new SqlCommand(lenh, Connect_DB.conn);
                cmd.CommandType = CommandType.Text;
                int a = cmd.ExecuteNonQuery();
                if (a > 0)
                {
                    MessageBox.Show("Thêm thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                }
                QuanLyTaiKhoan_Load(sender, e);
                Connect_DB.closeConn();
            }
        }
Esempio n. 2
0
        private void btn_tao_Click(object sender, EventArgs e)
        {
            string name     = txt_tenhs.Text;
            string gioitinh = cb_gioitinh.Text;
            string diachi   = txt_diachi.Text;
            string lop      = txt_lop.Text;
            string email    = txt_email.Text;
            string sdt      = txt_sdt.Text;
            string hokhau   = txt_hokhau.Text;
            string matruong = cb_matruong.Text;
            string ngaysinh = dtp_ngaysinh.Value.ToString("MM/dd/yyyy");


            Connect_DB.openConn();
            string     lenh = @" insert into hocsinh(hoten, gioitinh, diachi, lop, email, sdt, hokhau, matruong, ngaysinh)
                            values(N'" + name + "', N'" + gioitinh + "', '" + diachi + "', N'" + lop + "', N'" + email + "', N'" + sdt + "', N'" + hokhau + "', " + matruong + ", '" + ngaysinh + "')";
            SqlCommand cmd  = new SqlCommand(lenh, Connect_DB.conn);

            cmd.CommandType = CommandType.Text;
            int a = cmd.ExecuteNonQuery();

            if (a > 0)
            {
                MessageBox.Show("Thêm thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
            Connect_DB.closeConn();
        }
Esempio n. 3
0
        private void QuanLyTaiKhoan_Load(object sender, EventArgs e)
        {
            Connect_DB.openConn();
            string     query = "select  giaovien.magiaovien , hoten, mataikhoan, tentaikhoan,matkhau from taikhoan inner join giaovien on taikhoan.magiaovien = giaovien.magiaovien; ";
            SqlCommand cmd   = new SqlCommand(query, Connect_DB.connect());

            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adt = new SqlDataAdapter(cmd);
            DataTable      dtb = new DataTable();

            adt.Fill(dtb);
            dgv_taikhoan.DataSource = dtb;

            // Select mã giáo viên cho combobox

            string         queryMGV = "Select * from giaovien";
            SqlCommand     cmd2     = new SqlCommand(queryMGV, Connect_DB.conn);
            SqlDataAdapter da       = new SqlDataAdapter(cmd2);
            DataSet        ds       = new DataSet();

            da.Fill(ds);
            cb_maGV.DataSource    = ds.Tables[0];
            cb_maGV.ValueMember   = "magiaovien";
            cb_maGV.DisplayMember = "magiaovien";
            cb_maGV.Enabled       = true;
            Connect_DB.closeConn();
        }
Esempio n. 4
0
        private void btn_delete_Click(object sender, EventArgs e)
        {
            string maTk = tb_matk.Text.ToString();

            if (maTk == null || maTk == "")
            {
                MessageBox.Show("Bạn phải chọn tài khoản để xóa!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
            else
            {
                Connect_DB.openConn();
                string     lenh = @"delete taikhoan where mataikhoan =" + maTk;
                SqlCommand cmd  = new SqlCommand(lenh, Connect_DB.conn);
                cmd.CommandType = CommandType.Text;
                int a = cmd.ExecuteNonQuery();
                if (a > 0)
                {
                    MessageBox.Show("Xóa thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                }
                QuanLyTaiKhoan_Load(sender, e);
                tb_matk.Text  = null;
                tb_tenDN.Text = null;
                tb_mk.Text    = null;
                Connect_DB.closeConn();
            }
        }
Esempio n. 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            String        tendn = txtTenDN.Text;
            String        mk    = txtMK.Text;
            SqlConnection conn  = Connect_DB.connect();

            conn.Open();
            string queryString = "SELECT * FROM taikhoan where tentaikhoan = @tentaikhoan and matkhau = @matkhau;";

            SqlCommand command = new SqlCommand(queryString, conn);

            command.Parameters.Add("@tentaikhoan", SqlDbType.NVarChar, 50).Value = tendn;
            command.Parameters.Add("@matkhau", SqlDbType.NVarChar, 255).Value    = Hash(mk);
            using (SqlDataReader reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    reader.Close();
                    conn.Close();
                    this.Hide();
                    TrangChu tc = new TrangChu();
                    tc.Show();
                }
                else
                {
                    reader.Close();
                    conn.Close();
                    MessageBox.Show("Tên đăng nhập hoặc mật khẩu k đúng");
                }
            }
        }
Esempio n. 6
0
        private void tab_QLHS_Click(object sender, EventArgs e)
        {
            Connect_DB.openConn();
            SqlCommand cmd = new SqlCommand("Select * from hocsinh", Connect_DB.connect());

            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adt  = new SqlDataAdapter(cmd);
            DataTable      dtb  = new DataTable();
            DataTable      dtb2 = new DataTable();

            adt.Fill(dtb);
            adt.Fill(dtb2);
            dgv_Capnhat.DataSource = dtb;
            dgv_XoaHS.DataSource   = dtb2;
            Connect_DB.closeConn();
        }
Esempio n. 7
0
        private void cb_maGV_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Connect_DB.openConn();
            String maGV = cb_maGV.Text.ToString();

            if (maGV != null || maGV != "")
            {
                string         queryMGV = @"select * from giaovien where magiaovien=" + maGV;
                SqlCommand     cmd2     = new SqlCommand(queryMGV, Connect_DB.conn);
                SqlDataAdapter da       = new SqlDataAdapter(cmd2);
                DataSet        ds       = new DataSet();
                da.Fill(ds);
                string tenGV = ds.Tables[0].Rows[0].Field <string>(1);
                tb_tengv.Text = tenGV;
                Connect_DB.closeConn();
            }
        }
Esempio n. 8
0
        private void QuanLyHocSinh_Load(object sender, EventArgs e)
        {
            // Fill data to combobox mã trường
            Connect_DB.openConn();
            string         query = "Select * from truongthcs";
            SqlCommand     cmd   = new SqlCommand(query, Connect_DB.conn);
            SqlDataAdapter da    = new SqlDataAdapter(cmd);
            DataSet        ds    = new DataSet();

            da.Fill(ds);
            cb_matruong.DataSource    = ds.Tables[0];
            cb_matruong.ValueMember   = "matruong";
            cb_matruong.DisplayMember = "matruong";
            cb_matruong.Enabled       = true;


            cb_gioitinh.Items.Add("Nam");
            cb_gioitinh.Items.Add("Nữ");
        }
Esempio n. 9
0
        private void btn_hoanthanh_Click(object sender, EventArgs e)
        {
            DialogResult dl = MessageBox.Show("Bạn có chắc muốn thay đổi", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dl == DialogResult.Yes)
            {
                string ngaysinh = dtp_ngaysinh.Value.ToString("MM/dd/yyyy");
                string query    = @"update hocsinh set hoten = N'" + txt_hoten.Text + "' , gioitinh=N'" + cb_gioitinh.Text + "', diachi=N'" + txt_diachi.Text + "', lop = N'" + txt_lop.Text + "', email=N'" + txt_email.Text + "' , sdt=N'" + txt_sdt.Text + "',hokhau=N'" + txt_hokhau.Text + "',matruong = " + txt_matruong.Text + ", ngaysinh='" + ngaysinh + "'" +
                                  "where mahocsinh =" + txt_mahs.Text;
                Connect_DB.openConn();
                SqlCommand cmd = new SqlCommand(query, Connect_DB.conn);
                cmd.CommandType = CommandType.Text;
                int a = cmd.ExecuteNonQuery();
                Connect_DB.closeConn();
                if (a > 0)
                {
                    MessageBox.Show("Sửa thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                    this.Close();
                }
            }
        }
Esempio n. 10
0
        private void btn_update_Click(object sender, EventArgs e)
        {
            string maTk  = tb_matk.Text;
            string tenDN = tb_tenDN.Text;
            string mk    = tb_mk.Text;

            Connect_DB.openConn();
            string     lenh = @"update taikhoan set tentaikhoan = N'" + tenDN + "' , matkhau=N'" + mk + "' where mataikhoan = " + maTk;
            SqlCommand cmd  = new SqlCommand(lenh, Connect_DB.conn);

            cmd.CommandType = CommandType.Text;
            int a = cmd.ExecuteNonQuery();

            if (a > 0)
            {
                MessageBox.Show("Cập nhật thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
            QuanLyTaiKhoan_Load(sender, e);
            tb_matk.Text  = null;
            tb_tenDN.Text = null;
            tb_mk.Text    = null;
            Connect_DB.closeConn();
        }
Esempio n. 11
0
        private void dgv_XoaHS_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = new DataGridViewRow();

            if (e.ColumnIndex == 0)
            {
                DialogResult dl = MessageBox.Show("Bạn có chắc muốn xóa", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dl == DialogResult.Yes)
                {
                    row = dgv_XoaHS.Rows[e.RowIndex];
                    string query = @"delete hocsinh where mahocsinh =" + row.Cells[1].Value.ToString();
                    Connect_DB.openConn();
                    SqlCommand cmd = new SqlCommand(query, Connect_DB.conn);
                    cmd.CommandType = CommandType.Text;
                    int a = cmd.ExecuteNonQuery();
                    Connect_DB.closeConn();
                    if (a > 0)
                    {
                        MessageBox.Show("Xóa thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                        dgv_XoaHS.Rows.Remove(row);
                    }
                }
            }
        }