Ejemplo n.º 1
0
        private void btnCapNhatAnhSinhVien_Click(object sender, EventArgs e)
        {
            try
            {
                MemoryStream streamm = new MemoryStream();
                pictureBoxSV.Image.Save(streamm, ImageFormat.Jpeg);

                MyDbContextDataContext myDb = new MyDbContextDataContext();
                SinhVien sv = new SinhVien();
                sv         = myDb.SinhViens.Where(p => p.MaSV == txtMaSV.Text).Single();
                sv.MaSV    = txtMaSV.Text;
                sv.TenSV   = txtHoTen.Text;
                sv.MaLop   = txtMaLop.Text;
                sv.HinhAnh = streamm.ToArray();
                if (rbNam.Checked == true)
                {
                    sv.GioiTinh = "Nam";
                }
                else
                {
                    sv.GioiTinh = "Nữ";
                }
                myDb.SubmitChanges();
                HienThiDuLieuLenListView();
                MessageBox.Show("Cập Nhật Thành Công");
            }
            catch (Exception)
            {
                MessageBox.Show("Cập Nhật Thất Bại!");
            }
        }
Ejemplo n.º 2
0
 private void LoadHinhAnh()
 {
     try
     {
         MyDbContextDataContext myDb = new MyDbContextDataContext();
         SinhVien sv = myDb.SinhViens.Where(p => p.MaSV == txtMaSV.Text).FirstOrDefault();
         if (sv == null)
         {
             return;
         }
         MemoryStream me  = new MemoryStream(sv.HinhAnh.ToArray());
         Image        img = Image.FromStream(me);
         if (img == null)
         {
             return;
         }
         pictureBoxSV.Image = img;
     }
     catch (Exception)
     {
         MessageBox.Show("Lỗi Kết Nối !!!");
     }
 }
Ejemplo n.º 3
0
 private void btnThem_Click_1(object sender, EventArgs e)
 {
     try
     {
         if (txtMaSV.Text == "" || txtHoTen.Text == "" || txtMaLop.Text == "" || cbKhoa.SelectedIndex == -1)
         {
             MessageBox.Show("Vui lòng nhập đầy đủ thông tin");
         }
         else
         {
             MemoryStream streamm = new MemoryStream();
             pictureBoxSV.Image.Save(streamm, ImageFormat.Jpeg);
             MyDbContextDataContext myDb = new MyDbContextDataContext();
             SinhVien sv = new SinhVien();
             sv.MaSV    = txtMaSV.Text;
             sv.TenSV   = txtHoTen.Text;
             sv.MaLop   = txtMaLop.Text;
             sv.HinhAnh = streamm.ToArray();
             if (rbNam.Checked == true)
             {
                 sv.GioiTinh = "Nam";
             }
             else if (rbNu.Checked == true)
             {
                 sv.GioiTinh = "Nữ";
             }
             myDb.SinhViens.InsertOnSubmit(sv);
             myDb.SubmitChanges();
             HienThiDuLieuLenListView();
             MessageBox.Show("Thêm Sinh Viên Thành Công !");
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Lỗi Kết Nối");
     }
 }