Example #1
0
 public void loadData()
 {
     using (MonhocEntities db = new MonhocEntities())
     {
         list = db.Monhocs.ToList <Monhoc>();
         hihi = new BindingList <Monhoc>(list);
         tableData.DataSource = hihi;
     }
     //tableData.AutoGenerateColumns = false;
 }
Example #2
0
 public void btnSave_Click(object sender, EventArgs e)
 {
     mh.IDMH     = tbIDDDDDDDDDD.Text.Trim();
     mh.MA_HK    = tbMMH.Text.Trim();
     mh.TenMH    = tbMH.Text.Trim();
     mh.SoTC     = Convert.ToInt32(tbTC.Text.Trim());
     mh.LyThuyet = Convert.ToInt32(tbLT.Text.Trim());
     mh.ThucHanh = Convert.ToInt32(tbTH.Text.Trim());
     //mh.ThucHanh = Convert.ToInt32(tbTH.Text.Trim());
     using (MonhocEntities db = new MonhocEntities())
     {
         db.Entry(mh).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MonhocEntities db = new MonhocEntities())
         {
             var entry = db.Entry(mh);
             if (entry.State == EntityState.Detached)
             {
                 db.Monhocs.Attach(mh);
             }
             db.Monhocs.Remove(mh);
             db.SaveChanges();
             MessageBox.Show("Deleted Successfully");
         }
     }
 }
Example #4
0
        private void Insert()
        {
            mh.IDMH     = txtID.Text.Trim();
            mh.MA_HK    = txtMMH.Text.Trim();
            mh.TenMH    = txtTenMH.Text.Trim();
            mh.SoTC     = Convert.ToInt32(txtTC.Text.Trim());
            mh.LyThuyet = Convert.ToInt32(txtLT.Text.Trim());
            mh.ThucHanh = Convert.ToInt32(txtTH.Text.Trim());

            using (MonhocEntities db = new MonhocEntities())
            {
                db.Monhocs.Add(mh);
                db.SaveChanges();
            }
            Form1 f = new Form1();

            MessageBox.Show("Added Successfully");
            this.Hide();
            f.loadData();
        }
Example #5
0
        private void tableData_DoubleClick(object sender, EventArgs e)
        {
            if (tableData.CurrentRow.Index != -1)
            {
                mh.IDMH = Convert.ToString(tableData.CurrentRow.Cells["IDMH"].Value);
                using (MonhocEntities db = new MonhocEntities())
                {
                    mh = db.Monhocs.Where(x => x.IDMH == mh.IDMH).FirstOrDefault();
                    edit.tbIDDDDDDDDDD.Text = mh.IDMH.ToString();
                    edit.tbMMH.Text         = this.tableData.CurrentRow.Cells[1].Value.ToString();
                    edit.tbMH.Text          = this.tableData.CurrentRow.Cells[2].Value.ToString();
                    edit.tbTC.Text          = this.tableData.CurrentRow.Cells[3].Value.ToString();
                    edit.tbTH.Text          = this.tableData.CurrentRow.Cells[4].Value.ToString();
                    edit.tbLT.Text          = this.tableData.CurrentRow.Cells[5].Value.ToString();
                    //string lt = this.tableData.CurrentRow.Cells[5].Value.ToString();
                    //edit.tbLT.Text = lt;

                    edit.ShowDialog();
                }
            }
        }