示例#1
0
        public async Task <IActionResult> PutGiaovien(Giaovien giaovien)
        {
            //if (id != giaovien.Magiaovien)
            //{
            //    return BadRequest();
            //}

            _context.Entry(giaovien).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!GiaovienExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(NoContent());
        }
示例#2
0
        public string getNewID()
        {
            Giaovien obj   = null;
            string   newID = "GV0001";

            try
            {
                dbConnect.Open();
                obj = (from Giaovien p in dbConnect.db
                       orderby p.Ma descending
                       select p).FirstOrDefault();
                dbConnect.Close();

                int i = 0;
                if (obj != null && int.TryParse(obj.Ma.Substring(2), out i))
                {
                    newID = "GV" + (i + 1).ToString("D4");
                }
                return(newID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(newID);
            }
            finally
            {
                dbConnect.Close();
            }
        }
示例#3
0
        /// <summary>
        /// thêm môn học
        /// </summary>
        /// <param name="mamh"></param>
        /// <param name="tenmh"></param>
        /// <param name="sochi"></param>
        public void add(string ma, string hoten, string ngaysinh, string gioitinh, string diachi, string dienthoai, string email, string makhoa, string trinhdo, string cmnd, string quoctich, string nangkhieu)
        {
            Giaovien obj = new Giaovien();

            obj.Ma        = ma;
            obj.Hoten     = hoten;
            obj.Ngaysinh  = ngaysinh;
            obj.Gioitinh  = gioitinh;
            obj.Diachi    = diachi;
            obj.Dienthoai = dienthoai;

            obj.Email     = email;
            obj.Makhoa    = makhoa;
            obj.Trinhdo   = trinhdo;
            obj.Cmnd      = cmnd;
            obj.Quoctich  = quoctich;
            obj.Nangkhieu = nangkhieu;

            try
            {
                dbConnect.Open();
                dbConnect.db.Store(obj);
                dbConnect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnect.Close();
            }
        }
示例#4
0
        /// <summary>
        /// Kiểm tra mã môn học có trong csdl chưa
        /// </summary>
        /// <param name="mamh"></param>
        /// <returns></returns>
        public bool isExist(string cmnd)
        {
            Giaovien obj = this.getByCmnd(cmnd);

            if (obj == null)
            {
                return(false);
            }
            return(true);
        }
示例#5
0
        private void btLuu_Click(object sender, EventArgs e)
        {
            gv = new Giaovien();
            try
            {
                if (datetimeNgaySinh.Value < DateTime.Today)
                {
                    gv.ngaysinhGV = datetimeNgaySinh.Value;
                    //gv.maGV = int.Parse(txtMaGV.Text);
                    gv.hotenGV = txtHoten.Text;
                    gv.maHT    = txtMaHT.Text;

                    if (rdbNam.Checked == true)
                    {
                        gv.gioitinhGV = true;
                    }
                    else if (rdbNu.Checked == true)
                    {
                        gv.gioitinhGV = false;
                    }
                    gv.chucvuGV    = txtChucvu.Text;
                    gv.diachiGV    = txtDiachi.Text;
                    gv.trinhdoGV   = txtTrinhdo.Text;
                    gv.dienthoaiGV = txtDienthoai.Text;
                    gv.soCMNDGV    = txtCMND.Text;
                    gv.chuyenmonGV = txtChuyenmon.Text;
                    gv.maMH        = int.Parse(txtMaMH.Text);


                    GiaoVienBus bus = new GiaoVienBus();
                    int         ret;
                    ret = bus.insert(gv);
                    bus.close();
                    if (ret < 0)
                    {
                        MessageBox.Show("Khong ghi duoc du lieu", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Ghi thanh cong", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Nhập sai ngày!!!", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Chưa nhập đầy đủ dữ liệu!!!", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#6
0
 private void bntLuu2_Click(object sender, EventArgs e)
 {
     if (bntThem2.Visible == true)
     {
         if (textTen2.Text.Trim() == "" || textGT2.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập dữ liệu vào khung thông tin");
         }
         else
         {
             Giaovien GV = new Giaovien();
             GV.Name    = textTen2.Text.Trim();
             GV.GT1     = textGT2.Text.Trim();
             GV.NS1     = textNS3.Value;
             GV.Mon1    = textMon.Text.Trim();
             GV.ChucVu1 = textCV.Text.Trim();
             bool ktra = new Connection2().ThemGV(GV);
             if (ktra == true)
             {
                 MessageBox.Show("Thêm dữ liệu thành công");
                 dataGV.DataSource = new Connection2().LoadData();
             }
             else
             {
                 MessageBox.Show("Không thể thêm được học sinh mới. Hãy thử lại");
             }
         }
     }
     if (bntSua.Visible == true)
     {
         Giaovien GV = new Giaovien();
         GV.ID1     = textMa2.Text.Trim();
         GV.Name    = textTen2.Text.Trim();
         GV.GT1     = textGT2.Text.Trim();
         GV.NS1     = textNS3.Value;
         GV.Mon1    = textMon.Text.Trim();
         GV.ChucVu1 = textCV.Text.Trim();
         bool ktra = new Connection2().SuaGV(GV);
         if (ktra == true)
         {
             MessageBox.Show("Sửa dữ liệu thành công");
             dataGV.DataSource = new Connection2().LoadData();
         }
         else
         {
             MessageBox.Show("Không thể Sửa được học sinh mới. Hãy thử lại");
         }
     }
 }
示例#7
0
        public async Task <ActionResult <Giaovien> > PostGiaovien([FromBody] Giaovien giaovien)
        {
            _context.Giaovien.Add(giaovien);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (GiaovienExists(giaovien.Magiaovien))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetGiaovien", new { id = giaovien.Magiaovien }, giaovien));
        }
示例#8
0
 public int kiemtradb_magv(string magv)
 {
     try
     {
         dbConnect.Open();
         Giaovien gvchk = (from Giaovien p in dbConnect.db
                           where p.Ma == magv
                           select p).SingleOrDefault();
         if (gvchk == null)
         {
             return(0);
         }
         else
         {
             return(1);
         }
     }
     finally
     {
         dbConnect.Close();
     }
 }
示例#9
0
        public Giaovien getByCmnd(string cmnd)
        {
            Giaovien obj = null;

            try
            {
                dbConnect.Open();
                obj = (from Giaovien o in dbConnect.db
                       where o.Cmnd == cmnd
                       select o).FirstOrDefault();
                dbConnect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnect.Close();
            }

            return(obj);
        }
示例#10
0
        /// <summary>
        /// cập nhật môn học
        /// </summary>
        /// <param name="mamh"></param>
        /// <param name="tenmh"></param>
        /// <param name="sochi"></param>
        public void update(string ma, string hoten, string ngaysinh, string gioitinh, string diachi, string dienthoai, string email, string makhoa, string trinhdo, string cmnd, string quoctich, string nangkhieu)
        {
            try
            {
                dbConnect.Open();
                Giaovien obj = (from Giaovien o in dbConnect.db
                                where o.Ma == ma
                                select o).FirstOrDefault();
                if (obj != null)
                {
                    obj.Hoten     = hoten;
                    obj.Ngaysinh  = ngaysinh;
                    obj.Gioitinh  = gioitinh;
                    obj.Diachi    = diachi;
                    obj.Dienthoai = dienthoai;

                    obj.Email     = email;
                    obj.Makhoa    = makhoa;
                    obj.Trinhdo   = trinhdo;
                    obj.Cmnd      = cmnd;
                    obj.Quoctich  = quoctich;
                    obj.Nangkhieu = nangkhieu;

                    dbConnect.db.Store(obj);
                }

                dbConnect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnect.Close();
            }
        }
示例#11
0
        /// <summary>
        /// xóa môn học
        /// </summary>
        /// <param name="ma"></param>
        public void delete(string ma)
        {
            try
            {
                dbConnect.Open();
                Giaovien obj = (from Giaovien o in dbConnect.db
                                where o.Ma == ma
                                select o).FirstOrDefault();
                if (obj != null)
                {
                    dbConnect.db.Delete(obj);
                }

                dbConnect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnect.Close();
            }
        }
示例#12
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (isEmpty())
            {
                return;
            }
            connect();
            Giaovien gv = new Giaovien();

            try
            {
                if (dtpngaysinh.Value < DateTime.Today)
                {
                    gv.maGV       = int.Parse(txtMaGV.Text);
                    gv.ngaysinhGV = dtpngaysinh.Value;
                    gv.maHT       = txtMaHT.Text;
                    gv.hotenGV    = txtHoten.Text;

                    if (rdbnam.Checked == true)
                    {
                        gv.gioitinhGV = true;
                    }
                    else if (rdbnu.Checked == true)
                    {
                        gv.gioitinhGV = false;
                    }
                    gv.chucvuGV    = txtChucvu.Text;
                    gv.chuyenmonGV = txtChuyenmon.Text;
                    gv.diachiGV    = txtDiaChi.Text;
                    gv.dienthoaiGV = txtDienthoai.Text;
                    gv.maMH        = int.Parse(cbbMaMonHoc.SelectedValue.ToString());
                    if (cbbLopQuanLy.Text == "")
                    {
                        gv.LopQuanLy = -1;
                    }
                    else
                    {
                        gv.LopQuanLy = int.Parse(cbbLopQuanLy.SelectedValue.ToString());
                    }
                    gv.soCMNDGV  = txtCMND.Text;
                    gv.trinhdoGV = txtTrinhdo.Text;

                    SqlCommand proc = new SqlCommand("sp_SUAGIAOVIEN", conn);
                    proc.CommandType = CommandType.StoredProcedure;
                    proc.Parameters.Add("@Ma", SqlDbType.Int).Value             = gv.maGV;
                    proc.Parameters.Add("@MaHienThi", SqlDbType.VarChar).Value  = gv.maHT == "" ? DBNull.Value : (object)gv.maHT;
                    proc.Parameters.Add("@hoten", SqlDbType.NVarChar).Value     = gv.hotenGV == "" ? DBNull.Value : (object)gv.hotenGV;
                    proc.Parameters.Add("@ngaysinh", SqlDbType.Date).Value      = gv.ngaysinhGV;
                    proc.Parameters.Add("@gioitinh", SqlDbType.Bit).Value       = gv.gioitinhGV;
                    proc.Parameters.Add("@diachi", SqlDbType.NVarChar).Value    = gv.diachiGV == "" ? DBNull.Value : (object)gv.diachiGV;
                    proc.Parameters.Add("@dienthoai", SqlDbType.VarChar).Value  = gv.dienthoaiGV == "" ? DBNull.Value : (object)gv.dienthoaiGV;
                    proc.Parameters.Add("@cmnd", SqlDbType.VarChar).Value       = gv.soCMNDGV == "" ? DBNull.Value : (object)gv.soCMNDGV;
                    proc.Parameters.Add("@trinhdo", SqlDbType.NVarChar).Value   = gv.trinhdoGV == "" ? DBNull.Value : (object)gv.trinhdoGV;
                    proc.Parameters.Add("@chuyenmon", SqlDbType.NVarChar).Value = gv.chuyenmonGV == "" ? DBNull.Value : (object)gv.chuyenmonGV;
                    proc.Parameters.Add("@chucvu", SqlDbType.NVarChar).Value    = gv.chucvuGV == "" ? DBNull.Value : (object)gv.chucvuGV;
                    proc.Parameters.Add("@maMH", SqlDbType.Int).Value           = gv.maMH;
                    if (gv.LopQuanLy == -1)
                    {
                        proc.Parameters.Add("@malop", SqlDbType.Int).Value = DBNull.Value;
                    }
                    else
                    {
                        proc.Parameters.Add("@malop", SqlDbType.Int).Value = gv.LopQuanLy;
                    }
                    proc.ExecuteNonQuery();
                    MessageBox.Show("Cập nhật thành công");

                    //GiaoVienBus bus = new GiaoVienBus();
                    //int ret;
                    //ret = bus.update(gv);
                    //bus.close();
                    //if (ret < 0)
                    //{
                    //    MessageBox.Show("Không ghi được dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Ghi thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //    btnLuuThemMoi.Enabled = false;
                    //    btnCapNhat.Enabled = true;
                    //    btnSua.Enabled = true;
                    //    btnXoa.Enabled = true;
                    //    txtChucvu.Enabled = false;
                    //    txtChuyenmon.Enabled = false;
                    //    txtCMND.Enabled = false;
                    //    txtDiaChi.Enabled = false;
                    //    txtDienthoai.Enabled = false;
                    //    txtHoten.Enabled = false;
                    //    txtMaHT.Enabled = false;
                    //    txtTrinhdo.Enabled = false;
                    //    rdbnam.Enabled = false;
                    //    rdbnu.Enabled = false;
                    //    cbbLopQuanLy.Enabled = false;
                    //    cbbMaMonHoc.Enabled = false;
                    //    dtpngaysinh.Enabled = false;
                    //}
                }
                else
                {
                    MessageBox.Show("Nhập sai ngày!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Chưa nhập đầy đủ dữ liệu!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            btnCapNhat.Enabled   = false;
            btnThem.Enabled      = true;
            btnSua.Enabled       = true;
            btnXoa.Enabled       = true;
            btnHuy.Enabled       = false;
            txtChucvu.Enabled    = false;
            txtChuyenmon.Enabled = false;
            txtCMND.Enabled      = false;
            txtDiaChi.Enabled    = false;
            txtDienthoai.Enabled = false;
            txtHoten.Enabled     = false;
            txtMaHT.Enabled      = false;
            txtTrinhdo.Enabled   = false;
            rdbnam.Enabled       = false;
            rdbnu.Enabled        = false;
            cbbLopQuanLy.Enabled = false;
            cbbMaMonHoc.Enabled  = false;
            dtpngaysinh.Enabled  = false;
            dgvgiaovien.Enabled  = true;
            dt.Clear();
            getdata();
            disconect();
        }