예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (txtMaMon.Text.Trim() == "")
     {
         MessageBox.Show("Mã lớp chưa nhập", "Thông báo");
     }
     else
     {
         if (context.tblMONs.Find(txtMaMon.Text) != null)
         {
             MessageBox.Show("Mã môn đã tồn tại", "Thông báo");
         }
         else
         {
             tblMON m = new tblMON();
             m.TenMon = txtTenMon.Text;
             m.SoDVHT = Convert.ToInt32(numsdvht.Text);
             m.MaMon  = txtMaMon.Text;
             m.MaKhoa = cboKhoa.Text;
             m.HocKi  = txtHocKy.Text;
             MONHOCF mh = new MONHOCF();
             mh.Insert(m);
             dgrMON.DataSource = context.tblMONs.ToList();
             txtHocKy.Clear();
             txtMaMon.Clear();
             numsdvht.Value = 0;
             txtTenMon.Clear();
             cboKhoa.Text = "";
         }
     }
 }
예제 #2
0
        public bool Delete(tblMON model)
        {
            tblMON re = context.tblMONs.Find(model.MaMon);

            if (re == null)
            {
                return(false);
            }
            context.tblMONs.Remove(re);
            context.SaveChanges();
            return(true);
        }
예제 #3
0
        public bool Insert(tblMON model)
        {
            tblMON result = context.tblMONs.Find(model.MaMon);

            if (result != null)
            {
                return(false);
            }
            context.tblMONs.Add(model);
            context.SaveChanges();
            return(true);
        }
예제 #4
0
        public bool Update(tblMON model)
        {
            tblMON re = context.tblMONs.Find(model.MaMon);

            if (re == null)
            {
                return(false);
            }
            re.MaMon  = model.MaMon;
            re.MaKhoa = model.MaKhoa;
            re.SoDVHT = model.SoDVHT;
            re.HocKi  = model.HocKi;
            re.TenMon = model.TenMon;
            context.SaveChanges();
            return(true);
        }
예제 #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            string id = txtMaMon.Text.Trim();

            if (MessageBox.Show(string.Format("Sửa môn học có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                tblMON m = new tblMON();
                m.TenMon = txtTenMon.Text;
                m.SoDVHT = Convert.ToInt32(numsdvht.Text);
                m.MaMon  = txtMaMon.Text;
                m.MaKhoa = cboKhoa.Text;
                m.HocKi  = txtHocKy.Text;
                MONHOCF mh = new MONHOCF();
                mh.Update(m);
                dgrMON.DataSource = context.tblMONs.ToList();
            }
        }
예제 #6
0
        public tblMON FindEntity(string id)
        {
            tblMON result = context.tblMONs.Find(id);

            return(result);
        }