private void laSinhVien_Click(object sender, EventArgs e) { frmDTSinhVien frmDTSinhVien = new frmDTSinhVien(); frmDTSinhVien.WindowState = FormWindowState.Maximized; frmDTSinhVien.Show(); //this.Close(); }
private void windowsUIButtonPanelCloseButton_Click(object sender, EventArgs e) { this.Close(); frmDTSinhVien frmDTSinhVien = new frmDTSinhVien(); frmDTSinhVien.WindowState = FormWindowState.Maximized; frmDTSinhVien.Show(); }
private void btnXoaSV_ItemClick(object sender, ItemClickEventArgs e) { String hoTen = gridVSinhVien.Columns.View.GetFocusedRowCellValue("hoTen").ToString(); String maSV = gridVSinhVien.Columns.View.GetFocusedRowCellValue("maSV").ToString(); DialogResult dialogResult = MessageBox.Show("Bạn có chắc chắn muốn xóa \n Sinh viên: " + hoTen + "\n Mã số: " + maSV, "Cảnh báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand sqlCmd = new SqlCommand("xoaSinhVien", con) { CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.AddWithValue("@maSV", maSV); sqlCmd.ExecuteNonQuery(); sqlCmd = new SqlCommand("deleteTaiKhoan", con) { CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.AddWithValue("@tenTK", maSV); sqlCmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Xóa thành công ^^"); this.Close(); frmDTSinhVien frmDTSinhVien = new frmDTSinhVien(); frmDTSinhVien.WindowState = FormWindowState.Maximized; frmDTSinhVien.Show(); } else if (dialogResult == DialogResult.No) { //do something else } }
private void windowsUIButtonPanelMain_Click(object sender, EventArgs e) { if (thaoTac.Equals("Them")) { if (strFilePath == "") { /*if (ImageByArray.Length != 0) * ImageByArray = new byte[] { };*/ MessageBox.Show("Vui lòng chọn hình đại diện ^^"); OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Images(.jpg,.png)|*.png;*.jpg"; if (ofd.ShowDialog() == DialogResult.OK) { strFilePath = ofd.FileName; picSinhVien.Image = new Bitmap(strFilePath); } Image temp = new Bitmap(strFilePath); MemoryStream strm = new MemoryStream(); temp.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg); ImageByArray = strm.ToArray(); } else { Image temp = new Bitmap(strFilePath); MemoryStream strm = new MemoryStream(); temp.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg); ImageByArray = strm.ToArray(); } if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand sqlCmd = new SqlCommand("SV_Insert", con) { CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.AddWithValue("@maSV", txtMaSV.Text); sqlCmd.Parameters.AddWithValue("@hoTen", txtHoTen.Text); if (radNam.Checked == true) { sqlCmd.Parameters.AddWithValue("@gioiTinh", "Nam"); } else { sqlCmd.Parameters.AddWithValue("@gioiTinh", "Nữ"); } sqlCmd.Parameters.AddWithValue("@diaChi", txtDiaChi.Text); sqlCmd.Parameters.AddWithValue("@SDT", txtMSoDT.Text); sqlCmd.Parameters.AddWithValue("@ngaySinh", Convert.ToDateTime(txtNgaySinh.Text)); sqlCmd.Parameters.AddWithValue("@noiSinh", txtNoiSinh.Text); sqlCmd.Parameters.AddWithValue("@maLop", cbLop.Text.Substring(cbLop.Text.LastIndexOf(' ') + 1)); //sqlCmd.Parameters.AddWithValue("@maNganh", cbNganh.Text.Substring(cbNganh.Text.LastIndexOf(' ') + 1)); sqlCmd.Parameters.AddWithValue("@quyen", 3); sqlCmd.Parameters.AddWithValue("@khoa", txtMKhoaHoc.Text); sqlCmd.Parameters.AddWithValue("@hinh", ImageByArray); sqlCmd.Parameters.AddWithValue("@email", txtEmail.Text); sqlCmd.ExecuteNonQuery(); sqlCmd = new SqlCommand("themTaiKhoan", con) { CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.AddWithValue("@tenTK", txtMaSV.Text); sqlCmd.Parameters.AddWithValue("@matKhau", "1"); sqlCmd.Parameters.AddWithValue("@quyen", 3); sqlCmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Lưu thành công ^^"); this.Close(); frmDTSinhVien frmDTSinhVien = new frmDTSinhVien(); frmDTSinhVien.WindowState = FormWindowState.Maximized; frmDTSinhVien.Show(); } else { if (strFilePath != "" && ImageByArray != null) { /*if (ImageByArray.Length != 0) * ImageByArray = new byte[] { }; * MessageBox.Show("Vui lòng chọn hình đại diện ^^"); * OpenFileDialog ofd = new OpenFileDialog(); * ofd.Filter = "Images(.jpg,.png)|*.png;*.jpg"; * if (ofd.ShowDialog() == DialogResult.OK) * { * strFilePath = ofd.FileName; * picSinhVien.Image = new Bitmap(strFilePath); * }*/ Image temp = new Bitmap(strFilePath); MemoryStream strm = new MemoryStream(); temp.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg); ImageByArray = strm.ToArray(); } else { if (ImageByArray == null) { Image temp = new Bitmap(strFilePath); MemoryStream strm = new MemoryStream(); temp.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg); ImageByArray = strm.ToArray(); } //picGiangVien.Image = Image.FromStream(new MemoryStream(ImageByArray)); } if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand sqlCmd = new SqlCommand("SV_Update", con) { CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.AddWithValue("@maSV", txtMaSV.Text); sqlCmd.Parameters.AddWithValue("@hoTen", txtHoTen.Text); if (radNam.Checked == true) { sqlCmd.Parameters.AddWithValue("@gioiTinh", "Nam"); } else { sqlCmd.Parameters.AddWithValue("@gioiTinh", "Nữ"); } sqlCmd.Parameters.AddWithValue("@diaChi", txtDiaChi.Text); sqlCmd.Parameters.AddWithValue("@SDT", txtMSoDT.Text); sqlCmd.Parameters.AddWithValue("@ngaySinh", Convert.ToDateTime(txtNgaySinh.Text)); sqlCmd.Parameters.AddWithValue("@noiSinh", txtNoiSinh.Text); sqlCmd.Parameters.AddWithValue("@maLop", cbLop.Text.Substring(cbLop.Text.LastIndexOf(' ') + 1)); //sqlCmd.Parameters.AddWithValue("@maNganh", cbNganh.Text.Substring(cbNganh.Text.LastIndexOf(' ') + 1)); sqlCmd.Parameters.AddWithValue("@quyen", 3); sqlCmd.Parameters.AddWithValue("@khoa", txtMKhoaHoc.Text); sqlCmd.Parameters.AddWithValue("@hinh", ImageByArray); sqlCmd.Parameters.AddWithValue("@email", txtEmail.Text); sqlCmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Lưu thành công ^^"); this.Close(); frmDTSinhVien frmDTSinhVien = new frmDTSinhVien(); frmDTSinhVien.WindowState = FormWindowState.Maximized; frmDTSinhVien.Show(); } }