Esempio n. 1
0
 private void btnXoaGV_Click(object sender, EventArgs e)
 {
     if (btnXoaGV.Enabled == true)
     {
         string       err = null;
         DialogResult r   = MessageBox.Show(null, "Bạn có chắc xóa giáo viên " + txtTenGV.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             try
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 GiaoVien gv = new GiaoVien();
                 gv.MaGV            = Int32.Parse(txtMaGV.Text);
                 gv.TenGV           = txtTenGV.Text;
                 et.Entry(gv).State = EntityState.Deleted;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
                 QLGiaoVien_Load(sender, e);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Lỗi " + ex.Message);
             }
         }
     }
 }
Esempio n. 2
0
 private void btnXoaPH_Click(object sender, EventArgs e)
 {
     if (btnXoaPH.Enabled == true)
     {
         string       err = null;
         DialogResult r   = MessageBox.Show(null, "Bạn có chắc xóa phòng " + txtTenPH.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             try
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 PhongHoc ph = new PhongHoc();
                 ph.MaPH            = Int32.Parse(txtMaPH.Text);
                 et.Entry(ph).State = EntityState.Deleted;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Lỗi " + ex.Message);
             }
             QLPhongHoc_Load(sender, e);
         }
     }
 }
Esempio n. 3
0
 private void btnXoaBan_Click(object sender, EventArgs e)
 {
     if (btnXoaBan.Enabled == true)
     {
         DialogResult r = MessageBox.Show(null, "Bạn có chắc xóa ban " + txtTenBan.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             try
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Ban bdel = new Ban();
                 bdel.MaBan           = Int32.Parse(txtMaBan.Text);
                 bdel.TenBan          = txtTenBan.Text;
                 et.Entry(bdel).State = EntityState.Deleted;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
                 QLBan_Load(sender, e);
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Xóa lỗi! Lỗi " + ex.Message);
             }
         }
     }
 }
Esempio n. 4
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     if (k == 1)
     {
         try
         {
             if (t == 1)
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 GiaoVien gv = new GiaoVien();
                 gv.MaGV            = Int32.Parse(txtMaGV.Text);
                 gv.TenGV           = txtTenGV.Text;
                 gv.GioiTinh        = txtGioiTinh.Text;
                 gv.SDT             = txtSDT.Text;
                 gv.ChucVu          = txtChucVu.Text;
                 gv.Email           = txtEmail.Text;
                 gv.MaBM            = Int32.Parse(txtMaBM.Text);
                 et.Entry(gv).State = EntityState.Added;
                 et.SaveChanges();
                 MessageBox.Show("Thêm thành công!");
             }
             else
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 GiaoVien gv = new GiaoVien();
                 gv.MaGV            = Int32.Parse(txtMaGV.Text);
                 gv.TenGV           = txtTenGV.Text;
                 gv.GioiTinh        = txtGioiTinh.Text;
                 gv.SDT             = txtSDT.Text;
                 gv.ChucVu          = txtChucVu.Text;
                 gv.Email           = txtEmail.Text;
                 gv.MaBM            = Int32.Parse(txtMaBM.Text);
                 et.Entry(gv).State = EntityState.Modified;
                 et.SaveChanges();
                 MessageBox.Show("Sửa thành công!");
             }
             QLGiaoVien_Load(sender, e);
         }
         catch (Exception ex)
         {
             MessageBox.Show("Lỗi " + ex.Message);
         }
     }
     else
     {
         QLGiaoVien_Load(sender, e);
     }
 }
Esempio n. 5
0
 private void btnXoaBM_Click(object sender, EventArgs e)
 {
     if (btnXoaBM.Enabled == true)
     {
         DialogResult r = MessageBox.Show(null, "Bạn có chắc xóa bộ môn " + txtTenBM.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
             BoMon bmdel = new BoMon();
             bmdel.MaBM            = Int32.Parse(txtMaBM.Text);
             et.Entry(bmdel).State = EntityState.Deleted;
             et.SaveChanges();
             MessageBox.Show("Đã xóa!");
             QLBoMon_Load(sender, e);
         }
     }
 }
Esempio n. 6
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     if (k == 1)
     {
         try
         {
             if (t == 1)
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Lop lop = new Lop();
                 lop.MaLop           = Int32.Parse(txtMaLH.Text);
                 lop.TenLop          = txtTenLH.Text;
                 lop.SoHocSinh       = Int32.Parse(txtSoHS.Text);
                 lop.MaBan           = Int32.Parse(txtMaBan.Text);
                 et.Entry(lop).State = EntityState.Added;
                 et.SaveChanges();
                 MessageBox.Show("Thêm thành công!");
             }
             else
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Lop lop = new Lop();
                 lop.MaLop           = Int32.Parse(txtMaLH.Text);
                 lop.TenLop          = txtTenLH.Text;
                 lop.SoHocSinh       = Int32.Parse(txtSoHS.Text);
                 lop.MaBan           = Int32.Parse(txtMaBan.Text);
                 et.Entry(lop).State = EntityState.Modified;
                 et.SaveChanges();
                 MessageBox.Show("Sửa thành công!");
             }
             QLLop_Load(sender, e);
         }
         catch (Exception ex)
         {
             MessageBox.Show("Lỗi " + ex.Message);
         }
     }
     else
     {
         QLLop_Load(sender, e);
     }
 }
Esempio n. 7
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     if (k == 1)
     {
         try
         {
             if (t == 1)
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 PhongHoc ph = new PhongHoc();
                 ph.MaPH            = Int32.Parse(txtMaPH.Text);
                 ph.TenPH           = txtTenPH.Text;
                 ph.DungLuong       = Int32.Parse(txtDungLuong.Text);
                 et.Entry(ph).State = EntityState.Added;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
             }
             else
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 PhongHoc ph = new PhongHoc();
                 ph.MaPH            = Int32.Parse(txtMaPH.Text);
                 ph.TenPH           = txtTenPH.Text;
                 ph.DungLuong       = Int32.Parse(txtDungLuong.Text);
                 et.Entry(ph).State = EntityState.Modified;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Lỗi " + ex.Message);
         }
         QLPhongHoc_Load(sender, e);
     }
     else
     {
         QLPhongHoc_Load(sender, e);
     }
 }
Esempio n. 8
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     if (k == 1)
     {
         try
         {
             if (t == 1)
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Ban b = new Ban();
                 b.MaBan           = Int32.Parse(txtMaBan.Text);
                 b.TenBan          = txtTenBan.Text;
                 et.Entry(b).State = EntityState.Added;
                 et.SaveChanges();
                 MessageBox.Show("Thêm thành công!");
             }
             else
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Ban bnew = new Ban();
                 bnew.MaBan           = Int32.Parse(txtMaBan.Text);
                 bnew.TenBan          = txtTenBan.Text;
                 et.Entry(bnew).State = EntityState.Modified;
                 et.SaveChanges();
                 MessageBox.Show("Sửa thành công!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Lỗi " + ex.Message);
         }
         QLBan_Load(sender, e);
     }
     else
     {
         QLBan_Load(sender, e);
     }
 }
Esempio n. 9
0
 private void btnXoaLop_Click(object sender, EventArgs e)
 {
     if (btnXoaLop.Enabled == true)
     {
         DialogResult r = MessageBox.Show(null, "Bạn có chắc xóa lớp " + txtTenLH.Text + " không!", "Cân nhắc", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             try
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 Lop lop = new Lop();
                 lop.MaLop           = Int32.Parse(txtMaLH.Text);
                 et.Entry(lop).State = EntityState.Deleted;
                 et.SaveChanges();
                 MessageBox.Show("Đã xóa!");
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Lỗi " + ex.Message);
             }
             QLLop_Load(sender, e);
         }
     }
 }
Esempio n. 10
0
 private void btnReload_Click(object sender, EventArgs e)
 {
     if (k == 1)
     {
         try
         {
             if (t == 1)
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 MonHoc mh = new MonHoc();
                 mh.MaMH            = Int32.Parse(txtMaMH.Text);
                 mh.TenMH           = txtTenMH.Text;
                 et.Entry(mh).State = EntityState.Added;
                 et.SaveChanges();
             }
             else
             {
                 XepThoiKhoaBieuEntities et = new XepThoiKhoaBieuEntities();
                 MonHoc mh = new MonHoc();
                 mh.MaMH            = Int32.Parse(txtMaMH.Text);
                 mh.TenMH           = txtTenMH.Text;
                 et.Entry(mh).State = EntityState.Modified;
                 et.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Lỗi " + ex.Message);
         }
         QLMonHoc_Load(sender, e);
     }
     else
     {
         QLMonHoc_Load(sender, e);
     }
 }
Esempio n. 11
0
        private void dgvRangBuoc_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            XepThoiKhoaBieuEntities xl = new XepThoiKhoaBieuEntities();
            int r = dgvRangBuoc.CurrentCell.RowIndex;

            if (r >= 0 && r < dgvRangBuoc.RowCount)
            {
                switch (xet)
                {
                case 1:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string tenGV = null;
                    string TenMH = null;
                    int    magv  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    mamh  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    var    teng  =
                        from d in xl.GiaoViens
                        where d.MaGV == magv
                        select d;
                    var tenm =
                        from d in xl.MonHocs
                        where d.MaMH == mamh
                        select d;
                    foreach (var gv in teng)
                    {
                        tenGV = gv.TenGV;
                    }
                    foreach (var mh in tenm)
                    {
                        TenMH = mh.TenMH;
                    }
                    txt2.Text = tenGV;
                    txt3.Text = TenMH;
                    txt4.Text = dgvRangBuoc.Rows[r].Cells[3].Value.ToString();
                    txt4.Show();
                    lbl4.Show();
                    txt5.Hide();
                    lbl5.Hide();
                    break;
                }

                case 2:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string tenLop   = null;
                    string TenPhong = null;
                    int    malop    = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    maphong  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    var    tenl     =
                        from d in xl.Lops
                        where d.MaLop == malop
                        select d;
                    var tenp =
                        from d in xl.PhongHocs
                        where d.MaPH == maphong
                        select d;
                    foreach (var lh in tenl)
                    {
                        tenLop = lh.TenLop;
                    }
                    foreach (var ph in tenp)
                    {
                        TenPhong = ph.TenPH;
                    }
                    txt2.Text = tenLop;
                    txt3.Text = TenPhong;
                    txt4.Hide();
                    lbl4.Hide();
                    txt5.Hide();
                    lbl5.Hide();
                    break;
                }

                case 3:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string TenLop = null;
                    string TenMH  = null;
                    int    malop  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    mamh   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    var    tenl   =
                        from d in xl.Lops
                        where d.MaLop == malop
                        select d;
                    var tenm =
                        from d in xl.MonHocs
                        where d.MaMH == mamh
                        select d;
                    foreach (var lh in tenl)
                    {
                        TenLop = lh.TenLop;
                    }
                    foreach (var mh in tenm)
                    {
                        TenMH = mh.TenMH;
                    }
                    txt2.Text = TenLop;
                    txt3.Text = TenMH;
                    txt4.Text = dgvRangBuoc.Rows[r].Cells[3].Value.ToString();
                    txt4.Show();
                    lbl4.Show();
                    txt5.Hide();
                    lbl5.Hide();
                    break;
                }

                case 4:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string TenLop = null;
                    string TenMH  = null;
                    string TenGV  = null;
                    string TenPH  = null;
                    int    magv   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    malop  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    int    mamh   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[3].Value.ToString());
                    int    maph   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[4].Value.ToString());

                    var tenl =
                        from d in xl.Lops
                        where d.MaLop == malop
                        select d;
                    var tenm =
                        from d in xl.MonHocs
                        where d.MaMH == mamh
                        select d;
                    var tengv =
                        from d in xl.GiaoViens
                        where d.MaGV == magv
                        select d;
                    var tenph =
                        from d in xl.PhongHocs
                        where d.MaPH == maph
                        select d;
                    foreach (var lh in tenl)
                    {
                        TenLop = lh.TenLop;
                    }
                    foreach (var mh in tenm)
                    {
                        TenMH = mh.TenMH;
                    }
                    foreach (var gv in tengv)
                    {
                        TenGV = gv.TenGV;
                    }
                    foreach (var ph in tenph)
                    {
                        TenPH = ph.TenPH;
                    }
                    txt2.Text = TenGV;
                    txt3.Text = TenLop;
                    txt4.Text = TenMH;
                    txt5.Text = TenPH;
                    txt4.Show();
                    txt5.Show();
                    lbl4.Show();
                    lbl5.Show();
                    break;
                }

                case 5:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string TenLop = null;
                    string TenMH  = null;
                    int    malop  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    mamh   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    var    tenl   =
                        from d in xl.Lops
                        where d.MaLop == malop
                        select d;
                    var tenm =
                        from d in xl.MonHocs
                        where d.MaMH == mamh
                        select d;
                    foreach (var lh in tenl)
                    {
                        TenLop = lh.TenLop;
                    }
                    foreach (var mh in tenm)
                    {
                        TenMH = mh.TenMH;
                    }
                    txt2.Text = TenLop;
                    txt3.Text = TenMH;
                    txt4.Text = dgvRangBuoc.Rows[r].Cells[3].Value.ToString();
                    txt4.Show();
                    lbl4.Show();
                    txt5.Hide();
                    lbl5.Hide();
                    break;
                }

                case 6:
                {
                    txt1.Text = dgvRangBuoc.Rows[r].Cells[0].Value.ToString();
                    string TenLop = null;
                    string TenMH  = null;
                    string TenGV  = null;
                    string TenPH  = null;
                    string Time   = null;
                    int    malop  = Int32.Parse(dgvRangBuoc.Rows[r].Cells[1].Value.ToString());
                    int    mamh   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[2].Value.ToString());
                    int    magv   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[0].Value.ToString());
                    int    maph   = Int32.Parse(dgvRangBuoc.Rows[r].Cells[3].Value.ToString());
                    int    matiet = Int32.Parse(dgvRangBuoc.Rows[r].Cells[4].Value.ToString());
                    var    tenl   =
                        from d in xl.Lops
                        where d.MaLop == malop
                        select d;
                    var tenm =
                        from d in xl.MonHocs
                        where d.MaMH == mamh
                        select d;
                    var tengv =
                        from d in xl.GiaoViens
                        where d.MaGV == magv
                        select d;
                    var tenph =
                        from d in xl.PhongHocs
                        where d.MaPH == maph
                        select d;
                    var time =
                        from d in xl.Tiets
                        where d.STT == matiet
                        select d;
                    foreach (var gv in tengv)
                    {
                        TenGV = gv.TenGV;
                    }
                    foreach (var lh in tenl)
                    {
                        TenLop = lh.TenLop;
                    }
                    foreach (var mh in tenm)
                    {
                        TenMH = mh.TenMH;
                    }
                    foreach (var ph in tenph)
                    {
                        TenPH = ph.TenPH;
                    }
                    foreach (var t in time)
                    {
                        Time = t.Time;
                    }
                    txt1.Text = TenGV;
                    txt2.Text = TenLop;
                    txt3.Text = TenMH;
                    txt4.Text = TenPH;
                    txt5.Text = Time;
                    txt4.Show();
                    lbl4.Show();
                    txt5.Show();
                    lbl5.Show();
                    lbl1.Text = "Tên GV";
                    lbl2.Text = "Tên Lớp";
                    lbl3.Text = "Tên MH";
                    lbl4.Text = "Tên PH";
                    lbl5.Text = "Time";
                    break;
                }
                }
                lbl1.Show();
                lbl2.Show();
                lbl3.Show();
                txt1.Show();
                txt2.Show();
                txt3.Show();
            }
        }
Esempio n. 12
0
        public void XepTKB()
        {
            int them = 0;

            for (int i = 0; i < GiaoVien_LopHoc.Count - 1; i++)
            {
                for (int j = 0; j < Lop_T_MH.Count - 1; j++)
                {
                    if (GiaoVien_LopHoc[i].MaLop == Lop_T_MH[j].MaLop && GiaoVien_LopHoc[i].MaMh == Lop_T_MH[j].MaMH)
                    {
                        XepThoiKhoaBieuEntities xl   = new XepThoiKhoaBieuEntities();
                        ThoiKhoaBieu            tkb1 = new ThoiKhoaBieu();
                        tkb1.MaGV   = GiaoVien_LopHoc[i].MaGV;
                        tkb1.MaLop  = GiaoVien_LopHoc[i].MaLop;
                        tkb1.MaMH   = GiaoVien_LopHoc[i].MaMh;
                        tkb1.MaTiet = Lop_T_MH[j].MaTiet;
                        tkb1.MaPH   = GiaoVien_LopHoc[i].MaPH;
                        tkb.Add(tkb1);
                        //xl.Entry(tkb1).State = EntityState.Added;
                        //xl.SaveChanges();
                        them++;
                    }
                }
            }
            MessageBox.Show("Da xep xong " + them + " tiet hoc!");

            //DataTable dt = new DataTable();
            //dt = bl.ExecuteQueryDataSet("select * from ThoiKhoaBieu", CommandType.Text);
            //dgvRangBuoc.DataSource = dt;

            try
            {
                dgvRangBuoc.Show();
                foreach (DataGridViewRow r in dgvRangBuoc.Rows)
                {
                    dgvRangBuoc.Rows.Clear();
                }
                int i = 0;
                for (int k = 0; k < tkb.Count - 1; k++)
                {
                    dgvRangBuoc.Rows.Add();
                    dgvRangBuoc.Rows[i].Cells[0].Value = tkb[k].MaGV;
                    dgvRangBuoc.Rows[i].Cells[1].Value = tkb[k].MaLop;
                    dgvRangBuoc.Rows[i].Cells[2].Value = tkb[k].MaMH;
                    dgvRangBuoc.Rows[i].Cells[3].Value = tkb[k].MaPH;
                    dgvRangBuoc.Rows[i].Cells[4].Value = tkb[k].MaTiet;
                    i++;
                    xet       = 6;
                    lbl2.Text = "Tên Lớp";
                    lbl3.Text = "Tên MH";
                    dgvRangBuoc.Columns[0].HeaderText = "Mã GV";
                    dgvRangBuoc.Columns[1].HeaderText = "Mã Lớp";
                    dgvRangBuoc.Columns[2].HeaderText = "Mã MH";
                    dgvRangBuoc.Columns[3].HeaderText = "Mã PH";
                    dgvRangBuoc.Columns[4].HeaderText = "Mã Tiết";
                }
                lbl1.Hide();
                lbl2.Hide();
                lbl3.Hide();
                lbl4.Hide();
                lbl5.Hide();
                txt1.Hide();
                txt2.Hide();
                txt3.Hide();
                txt4.Hide();
                txt5.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show("lỗi! " + ex.Message);
            }
        }
Esempio n. 13
0
        public void XThoiKhoaBieu()
        {
            try
            {
                XepThoiKhoaBieuEntities xl = new XepThoiKhoaBieuEntities();

                var giaovien =
                    from d in xl.GiaoViens
                    select d;
                var monhoc =
                    from d in xl.MonHocs
                    select d;
                var lop =
                    from d in xl.Lops
                    select d;
                var phong =
                    from d in xl.PhongHocs
                    select d;

                foreach (var gt in giaovien)
                {
                    GiaoVien gv = new GiaoVien();
                    gv.MaGV  = gt.MaGV;
                    gv.TenGV = gt.TenGV;
                    gv.MaBM  = gt.MaBM;
                    givi.Add(gv);
                    g++;
                }

                foreach (var gt in monhoc)
                {
                    MonHoc MH = new MonHoc();
                    MH.MaMH  = gt.MaMH;
                    MH.TenMH = gt.TenMH;
                    MH.MaBM  = gt.MaBM;
                    moho.Add(MH);
                    m++;
                }

                foreach (var gt in lop)
                {
                    Lop LOP = new Lop();
                    LOP.MaLop  = gt.MaLop;
                    LOP.TenLop = gt.TenLop;
                    loho.Add(LOP);
                    l++;
                }

                foreach (var gt in phong)
                {
                    PhongHoc PH = new PhongHoc();
                    PH.MaPH  = gt.MaPH;
                    PH.TenPH = gt.TenPH;
                    phho.Add(PH);
                    p++;
                }

                int dem;
                dem = 1;

                //Giáo viên nào dạy môn nào
                for (int i = 0; i < g; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        int cv;
                        if (givi[i].MaBM == moho[j].MaBM)
                        {
                            GV_MH gvmh = new GV_MH();
                            gvmh.stt  = dem;
                            gvmh.MaGV = givi[i].MaGV;
                            gvmh.MaMH = moho[j].MaMH;
                            cv        = SoSanh(Int32.Parse(givi[i].MaGV.ToString()));
                            switch (cv)
                            {
                            case 0:
                            {
                                gvmh.Sotiet = 18;
                                break;
                            }

                            case 1:
                            {
                                gvmh.Sotiet = 2;
                                break;
                            }

                            case 2:
                            {
                                gvmh.Sotiet = 4;
                                break;
                            }

                            case 3:
                            {
                                gvmh.Sotiet = 15;
                                break;
                            }

                            case 4:
                            {
                                gvmh.Sotiet = 17;
                                break;
                            }

                            case 5:
                            {
                                gvmh.Sotiet = 9;
                                break;
                            }

                            case 6:
                            {
                                gvmh.Sotiet = 0;
                                break;
                            }
                            }
                            GVMHTable.Add(gvmh);
                            dem++;
                        }
                    }
                }
                int ph = 0;
                //Lớp nào học phòng nào
                dem = 1;
                int check = 0;
                for (int i = 0; i < l; i++)
                {
                    if (Compare(loho[i].TenLop.ToString(), "12") == true ||
                        (Compare(loho[i].TenLop.ToString(), "11") == true && loho[i].MaBan == 1))
                    {
                        Lop_Phong lopphong = new Lop_Phong();
                        lopphong.stt   = dem;
                        lopphong.MaLop = loho[i].MaLop;
                        lopphong.MaPH  = phho[ph].MaPH;
                        lopphong.Buoi  = "Sáng";
                        dem++;
                        LPTable.Add(lopphong);
                        check++;
                    }
                    else
                    {
                        Lop_Phong lopphong = new Lop_Phong();
                        lopphong.stt   = dem;
                        lopphong.MaLop = loho[i].MaLop;
                        lopphong.MaPH  = phho[ph].MaPH;
                        lopphong.Buoi  = "Chiều";
                        dem++;
                        LPTable.Add(lopphong);
                        check++;
                    }
                    if (check >= 2)
                    {
                        ph++;
                        check = 0;
                    }
                }
                //Lớp nào học môn nào
                dem = 1;
                for (int i = 0; i < l; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        Lop_MH lopmh = new Lop_MH();
                        lopmh.stt   = dem;
                        lopmh.MaLop = loho[i].MaLop;
                        lopmh.MaMH  = moho[j].MaMH;
                        if (loho[i].MaLop <= 11) //Lớp 10
                        {
                            if (lopmh.MaMH == 1) //toán
                            {
                                lopmh.sotiet = 5;
                            }
                            else if (lopmh.MaMH == 5)//văn
                            {
                                lopmh.sotiet = 4;
                            }
                            else if (lopmh.MaMH == 3 || lopmh.MaMH == 6)//hóa, anh
                            {
                                lopmh.sotiet = 3;
                            }
                            else if (lopmh.MaMH == 2 || lopmh.MaMH == 4 || lopmh.MaMH == 8 || lopmh.MaMH == 11 || lopmh.MaMH == 12 || lopmh.MaMH == 13)//lý, địa, sinh, tin,TD,QP
                            {
                                lopmh.sotiet = 2;
                            }
                            else if (lopmh.MaMH != 14) //các môn còn lại khác tiếng pháp
                            {
                                lopmh.sotiet = 1;
                            }
                        }
                        else if (loho[i].MaLop > 11 && loho[i].MaLop <= 21)//lớp 11
                        {
                            if (lopmh.MaMH == 1)
                            {
                                lopmh.sotiet = 5;
                            }
                            else if (lopmh.MaMH == 5 || lopmh.MaMH == 6)//Anh, Văn
                            {
                                lopmh.sotiet = 4;
                            }
                            else if (lopmh.MaMH == 2 || lopmh.MaMH == 3)//Lý, Hóa
                            {
                                lopmh.sotiet = 3;
                            }
                            else if (lopmh.MaMH == 4 || lopmh.MaMH == 12 || lopmh.MaMH == 13)// Sinh, TD,QP
                            {
                                lopmh.sotiet = 2;
                            }
                            else if (lopmh.MaMH != 14)//các môn còn lại khác tiếng pháp
                            {
                                lopmh.sotiet = 1;
                            }
                        }
                        else //lớp 12
                        {
                            if (lopmh.MaMH == 1) //Toán
                            {
                                lopmh.sotiet = 4;
                            }
                            else if (lopmh.MaMH == 6)//Anh
                            {
                                lopmh.sotiet = 3;
                            }
                            else if (lopmh.MaMH == 2 || lopmh.MaMH == 3 || lopmh.MaMH == 4 || lopmh.MaMH == 5)//lý, hóa, sinh, văn
                            {
                                lopmh.sotiet = 3;
                            }
                            else if (lopmh.MaMH == 7 || lopmh.MaMH == 11 || lopmh.MaMH == 12 || lopmh.MaMH == 13)//sử, tin,TD,QP
                            {
                                lopmh.sotiet = 2;
                            }
                            else if (lopmh.MaMH != 14)//các môn còn lại khác tiếng pháp
                            {
                                lopmh.sotiet = 1;
                            }
                        }
                        Lop_Monhoc.Add(lopmh);
                        dem++;
                    }
                }

                //Giáo viên nào dạy lớp nào
                dem = 1;
                Random ra = new Random();
                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < l; j++)
                    {
                        GV_Lop gvl = new GV_Lop();
                        gvl.stt   = dem;
                        gvl.MaLop = loho[j].MaLop;
                        gvl.MaMh  = moho[i].MaMH;
                        chon      = new List <Chon>();
                        int nchon = 0;
                        for (int l = 0; l < GVMHTable.Count - 1; l++)
                        {
                            if (GVMHTable[l].MaMH == gvl.MaMh)
                            {
                                Chon ch = new Chon();
                                ch.stt  = nchon;
                                ch.MAGV = GVMHTable[l].MaGV;
                                chon.Add(ch);
                                nchon++;
                            }
                        }

                        int a;
                        if (nchon > 1)
                        {
                            a = ra.Next(nchon);
                        }
                        else
                        {
                            a = 0;
                        }
                        int magv = chon[a].MAGV;
                        gvl.MaGV = magv;
                        for (int l = 0; l < LPTable.Count - 1; l++)
                        {
                            if (LPTable[l].MaLop == loho[j].MaLop)
                            {
                                gvl.MaPH = LPTable[l].MaPH;
                                break;
                            }
                        }
                        GiaoVien_LopHoc.Add(gvl);
                        dem++;
                    }
                }

                int tiet = 0;
                dem = 1;
                Random rd  = new Random();
                Random rd1 = new Random();

                for (int it = 0; it < l; it++)
                {
                    List <int> chonMh = new List <int>();
                    int        sotiet = 0;
                    for (int i = 0; i < moho.Count - 1; i++) ////bỏ thể dục + quốc phòng
                    {
                        sotiet = 0;
                        if (moho[i].MaMH != 12 && moho[i].MaMH != 13)
                        {
                            for (int j = 0; j < Lop_Monhoc.Count - 1; j++)
                            {
                                if (Lop_Monhoc[j].MaMH == moho[i].MaMH && Lop_Monhoc[j].MaLop == loho[it].MaLop)
                                {
                                    sotiet = Lop_Monhoc[j].sotiet;
                                    break;
                                }
                            }
                            for (int j = 0; j < sotiet; j++) //Số lần xuất hiện môn học trong List chonMh
                            {
                                chonMh.Add(Lop_Monhoc[i].MaMH);
                            }
                        }
                    }

                    if (Compare(loho[it].TenLop.ToString(), "12") == true ||
                        (Compare(loho[it].TenLop.ToString(), "11") == true && loho[it].MaBan == 1))
                    {
                        for (int th = 0; th < 6; th++)
                        {
                            for (int i = 1; i <= 5; i++)//lớp buổi sáng
                            {
                                Lop_Tiet_MH lgvmh = new Lop_Tiet_MH();
                                tiet = i + 10 * th;
                                if (tiet == 1)
                                {
                                }
                                else if (tiet == 29 || tiet == 30 || tiet == 25)
                                {
                                }
                                else
                                {
                                    int vt;
                                    if (chonMh.Count > 1)
                                    {
                                        vt = rd.Next(chonMh.Count - 1);
                                    }
                                    else
                                    {
                                        vt = 0;
                                    }
                                    lgvmh.stt    = dem;
                                    lgvmh.MaLop  = loho[it].MaLop;
                                    lgvmh.MaMH   = chonMh[vt];
                                    lgvmh.MaTiet = tiet;
                                    if (chonMh.Count > 1)
                                    {
                                        chonMh.RemoveAt(vt);
                                    }
                                    Lop_T_MH.Add(lgvmh);
                                    dem++;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int th = 0; th < 6; th++)
                        {
                            for (int i = 6; i <= 10; i++)//lớp buổi chieu
                            {
                                Lop_Tiet_MH lgvmh = new Lop_Tiet_MH();
                                tiet = i + 10 * th;
                                if (tiet == 10)
                                {
                                }
                                else if (tiet == 59 || tiet == 60 || tiet == 50)
                                {
                                }
                                else
                                {
                                    int vt;
                                    if (chonMh.Count > 1)
                                    {
                                        vt = rd1.Next(chonMh.Count - 1);
                                    }
                                    else
                                    {
                                        vt = 0;
                                    }
                                    lgvmh.stt    = dem;
                                    lgvmh.MaLop  = loho[it].MaLop;
                                    lgvmh.MaMH   = chonMh[vt];
                                    lgvmh.MaTiet = tiet;
                                    if (chonMh.Count > 1)
                                    {
                                        chonMh.RemoveAt(vt);
                                    }
                                    Lop_T_MH.Add(lgvmh);
                                    dem++;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi! " + ex.Message);
            }
        }
Esempio n. 14
0
 private void btnXemTKB_Click(object sender, EventArgs e)
 {
     if (btnXemTKB.Enabled == true)
     {
         XemTKB xtkb = new XemTKB();
         XepThoiKhoaBieuEntities xl = new XepThoiKhoaBieuEntities();
         for (int ni = 0; ni < 6; ni++)
         {
             xtkb.dgvTKB.Rows.Add();
             if (ni == 0)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 2";
             }
             if (ni == 1)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 3";
             }
             if (ni == 2)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 4";
             }
             if (ni == 3)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 5";
             }
             if (ni == 4)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 6";
             }
             if (ni == 5)
             {
                 xtkb.dgvTKB.Rows[ni].Cells[0].Value = "Thứ 7";
             }
         }
         var tenl =
             from d in xl.Lops
             select d;
         int cel = 1;
         foreach (var lh in tenl)
         {
             xtkb.dgvTKB.Columns[cel].HeaderText = lh.TenLop;
             string t2   = null;
             string t3   = null;
             string t4   = null;
             string t5   = null;
             string t6   = null;
             string t7   = null;
             int    dem2 = 1;
             int    dem3 = 1;
             int    dem4 = 1;
             int    dem5 = 1;
             int    dem6 = 1;
             int    dem7 = 1;
             var    ttkb =
                 from d in tkb
                 where d.MaLop == lh.MaLop
                 orderby d.MaTiet
                 select d;
             foreach (var t in ttkb)
             {
                 if (t.MaTiet <= 10)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem2 < 4)
                         {
                             t2 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t2 += gv.TenMH;
                         }
                         dem2++;
                     }
                     if (Compare(lh.TenLop.ToString(), "12") == true ||
                         (Compare(lh.TenLop.ToString(), "11") == true && lh.MaBan == 1))
                     {
                         if (dem2 == 5)
                         {
                             t2 = "Chào cờ, " + t2;
                         }
                     }
                     else
                     {
                         if (dem2 == 5)
                         {
                             t2 += ", Chào cờ";
                         }
                     }
                     xtkb.dgvTKB.Rows[0].Cells[cel].Value = t2;
                 }
                 else if (t.MaTiet > 10 && t.MaTiet <= 20)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem3 < 5)
                         {
                             t3 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t3 += gv.TenMH;
                         }
                         dem3++;
                     }
                     xtkb.dgvTKB.Rows[1].Cells[cel].Value = t3;
                 }
                 else if (t.MaTiet > 20 && t.MaTiet <= 30)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem4 < 5)
                         {
                             t4 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t4 += gv.TenMH;
                         }
                         dem4++;
                     }
                     xtkb.dgvTKB.Rows[2].Cells[cel].Value = t4;
                 }
                 else if (t.MaTiet > 30 && t.MaTiet <= 40)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem5 < 5)
                         {
                             t5 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t5 += gv.TenMH;
                         }
                         dem5++;
                     }
                     xtkb.dgvTKB.Rows[3].Cells[cel].Value = t5;
                 }
                 else if (t.MaTiet > 40 && t.MaTiet <= 50)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem6 < 4)
                         {
                             t6 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t6 += gv.TenMH;
                         }
                         dem6++;
                     }
                     xtkb.dgvTKB.Rows[4].Cells[cel].Value = t6;
                 }
                 else if (t.MaTiet > 50 && t.MaTiet <= 60)
                 {
                     var tenm =
                         from d in xl.MonHocs
                         where d.MaMH == t.MaMH
                         select d;
                     foreach (var gv in tenm)
                     {
                         if (dem7 < 3)
                         {
                             t7 += gv.TenMH + ", ";
                         }
                         else
                         {
                             t7 += gv.TenMH;
                         }
                         dem7++;
                     }
                     xtkb.dgvTKB.Rows[5].Cells[cel].Value = t7;
                 }
             }
             cel++;
         }
         xtkb.ShowDialog();
     }
 }
Esempio n. 15
0
        public XThoiKhoaBieu()
        {
            XepThoiKhoaBieuEntities xl   = new XepThoiKhoaBieuEntities();
            List <GiaoVien>         givi = new List <GiaoVien>();
            List <MonHoc>           moho = new List <MonHoc>();
            List <Lop>      loho         = new List <Lop>();
            List <PhongHoc> phho         = new List <PhongHoc>();

            GVMHTable = new List <GV_MH>();
            LPTable   = new List <Lop_Phong>();
            int g;
            int m;
            int l;
            int p;
            var giaovien =
                from d in xl.GiaoViens
                select d;
            var monhoc =
                from d in xl.MonHocs
                select d;
            var lop =
                from d in xl.Lops
                select d;
            var phong =
                from d in xl.PhongHocs
                select d;

            foreach (var gt in giaovien)
            {
                g = 0;
                GiaoVien gv = new GiaoVien();
                gv.MaGV  = gt.MaGV;
                gv.TenGV = gt.TenGV;
                gv.MaBM  = gt.MaBM;
                givi.Add(gv);
                g++;
            }
            foreach (var gt in monhoc)
            {
                m = 0;
                MonHoc MH = new MonHoc();
                MH.MaMH  = gt.MaMH;
                MH.TenMH = gt.TenMH;
                MH.MaBM  = gt.MaBM;
                moho.Add(MH);
                m++;
            }
            foreach (var gt in lop)
            {
                l = 0;
                Lop LOP = new Lop();
                LOP.MaLop  = gt.MaLop;
                LOP.TenLop = gt.TenLop;
                loho.Add(LOP);
                l++;
            }
            foreach (var gt in phong)
            {
                p = 0;
                PhongHoc PH = new PhongHoc();
                PH.MaPH  = gt.MaPH;
                PH.TenPH = gt.TenPH;
                phho.Add(PH);
                p++;
            }
            int dem;

            dem = 0;
            ////Giáo viên nào dạy môn nào
            //for(int i=0;i<g;i++)
            //{
            //    for(int j=0;j<m;j++)
            //    {
            //        if (givi[i].MaBM == moho[j].MaBM)
            //        {
            //            GVMHTable[dem].stt = dem;
            //            GVMHTable[dem].MaGV = givi[i].MaGV;
            //            GVMHTable[dem].MaMH = moho[j].MaMH;
            //            dem++;
            //        }
            //    }
            //}
            //int ph = 0;
            ////Lớp nào học phòng nào
            //for (int i = 0; i < l; i++)
            //{
            //    if (Compare(loho[i].TenLop.ToString(),"12")==true
            //        || (Compare(loho[i].TenLop.ToString(), "11") == true && loho[i].MaBan == 1))
            //    {
            //        LPTable[dem].stt = dem;
            //        LPTable[dem].MaLop = loho[i].MaLop;
            //        LPTable[dem].MaPH = phho[ph++].MaPH;
            //        LPTable[dem].Buoi = "Sáng";
            //        dem++;
            //    }
            //    else
            //    {
            //        LPTable[dem].stt = dem;
            //        LPTable[dem].MaLop = loho[i].MaLop;
            //        LPTable[dem].MaPH = phho[ph++].MaPH;
            //        LPTable[dem].Buoi = "Chiều";
            //        dem++;
            //    }
            //}
            ////Lớp nào học môn nào
            //dem = 0;
            //for (int i = 0; i < l; i++)
            //{
            //    for (int j = 0; j < m; j++)
            //    {
            //        Lop_Monhoc[dem].stt = dem;
            //        Lop_Monhoc[dem].MaLop = loho[i].MaLop;
            //        Lop_Monhoc[dem].MaMH = moho[i].MaMH;
            //        dem++;
            //    }
            //}
        }