Ejemplo n.º 1
0
        private void btMonHoc_Search_Click(object sender, EventArgs e)
        {
            string text = txbSearch.Text;

            if (text == "")
            {
                return;
            }
            BUS_MonHoc       busMonHoc  = new BUS_MonHoc();
            EC_MonHoc        MonHoc1    = busMonHoc.Select_ByPrimaryKey(text);
            List <EC_MonHoc> listResult = new List <EC_MonHoc>();

            if (MonHoc1 != null)
            {
                listResult.Add(MonHoc1);
            }
            List <EC_MonHoc> listMonHoc2 = busMonHoc.SelectByFields("Ten_MonHoc", text);

            foreach (EC_MonHoc ec in listMonHoc2)
            {
                listResult.Add(ec);
            }
            dgSearchResult.Rows.Clear();
            foreach (EC_MonHoc ec in listResult)
            {
                dgSearchResult.Rows.Add(ec.Ma_MonHoc, ec.Ten_MonHoc, ec.Lop, null);
            }
        }
Ejemplo n.º 2
0
        void LoadForm()
        {
            cbTenMon.Items.Clear();
            cbLop.Items.Clear();
            cbLop.Items.Add("Tất cả");
            for (int j = 1; j <= 12; j++)
            {
                cbLop.Items.Add(j.ToString());
            }

            EC_LopHoc ecLop = new EC_LopHoc();
            EC_MonHoc ecMon = new EC_MonHoc();

            dgLopHoc.DataSource = ft.LopHoc_Select_Manager(ecLop, ecMon);

            List <EC_MonHoc> listMonHoc     = new BUS_MonHoc().SelectAll();
            List <string>    listTen_MonHoc = new List <string>();

            listTen_MonHoc.Add(listMonHoc[0].Ten_MonHoc);
            cbTenMon.Items.Add(listTen_MonHoc[0]);

            foreach (EC_MonHoc MonHoc in listMonHoc)
            {
                if (listTen_MonHoc.IndexOf(MonHoc.Ten_MonHoc) == -1)
                {
                    cbTenMon.Items.Add(MonHoc.Ten_MonHoc);
                }
                listTen_MonHoc.Add(MonHoc.Ten_MonHoc);
            }

            dtNgayBatdau.Value      = DateTime.Now;
            cbLop.SelectedIndex     = 12;
            cbTenMon.SelectedIndex  = 0;
            cbTrinhDo.SelectedIndex = 0;
        }
Ejemplo n.º 3
0
        //Hàm sửa
        public bool SuaDuLieu(EC_MonHoc ec)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "dbo.[MonHoc_Update]";
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                con.MoKetNoi();
                // Use connection object of base class
                cmd.Connection = con.connect;

                cmd.Parameters.AddWithValue("@Ma_MonHoc", ec.Ma_MonHoc);
                cmd.Parameters.AddWithValue("@Ten_MonHoc", ec.Ten_MonHoc);
                cmd.Parameters.AddWithValue("@Lop", ec.Lop);

                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("Lỗi khi sửa mon học: " + e.ToString());
                return(false);
            }
            finally
            {
                con.DongKetNoi();
                cmd.Dispose();
            }
        }
Ejemplo n.º 4
0
        private void btThem_MonHoc_Click(object sender, EventArgs e)
        {
            if (dgSearchResult.Rows.Count == 0)
            {
                return;
            }
            int count_Check = 0;
            List <EC_MonHoc> listChecked = new List <EC_MonHoc>();

            foreach (DataGridViewRow row in dgSearchResult.Rows)
            {
                if (row.Cells[3].Value != null)
                {
                    if (Convert.ToBoolean(row.Cells[3].Value.ToString()) == true)
                    {
                        count_Check++;
                        EC_MonHoc MonHoc = new BUS_MonHoc().Select_ByPrimaryKey(row.Cells[0].Value.ToString());
                        listChecked.Add(MonHoc);
                    }
                }
            }
            if (count_Check == 0)
            {
                MessageBox.Show("Chọn môn học để thêm!", "Thông báo");
                return;
            }
            List <EC_PhanCong_Day> listPhanCong_Day = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien);
            int count_Success = 0;

            foreach (EC_MonHoc i in listChecked)
            {
                bool check = true;
                foreach (EC_PhanCong_Day ec in listPhanCong_Day)
                {
                    if (ec.Ma_MonHoc == i.Ma_MonHoc)
                    {
                        check = false;
                    }
                }
                if (check == true)
                {
                    new BUS_PhanCong_Day().ThemDuLieu(new EC_PhanCong_Day(Ma_GiaoVien, i.Ma_MonHoc));
                    count_Success++;
                }
            }
            MessageBox.Show("Thêm thành công " + count_Success.ToString() + " môn học", "Thông báo");

            dgPhanCong_Day.Rows.Clear();
            List <EC_PhanCong_Day> list      = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien);
            BUS_MonHoc             busMonHoc = new BUS_MonHoc();
            int index = 1;

            foreach (EC_PhanCong_Day ec in listPhanCong_Day)
            {
                EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc);
                dgPhanCong_Day.Rows.Add(index.ToString(), MonHoc.Ma_MonHoc, MonHoc.Ten_MonHoc, MonHoc.Lop.ToString());
                index++;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of SinhVien</returns>
        internal List <EC_MonHoc> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <EC_MonHoc> list = new List <EC_MonHoc>();

            while (dataReader.Read())
            {
                EC_MonHoc businessObject = new EC_MonHoc();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(EC_MonHoc businessObject, IDataReader dataReader)
        {
            businessObject.Ma_MonHoc = dataReader.GetString(dataReader.GetOrdinal(EC_MonHoc.MonHocField.Ma_MonHoc.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(EC_MonHoc.MonHocField.Ten_MonHoc.ToString())))
            {
                businessObject.Ten_MonHoc = dataReader.GetString(dataReader.GetOrdinal(EC_MonHoc.MonHocField.Ten_MonHoc.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(EC_MonHoc.MonHocField.Ma_MonHoc.ToString())))
            {
                businessObject.Lop = dataReader.GetInt32(dataReader.GetOrdinal(EC_MonHoc.MonHocField.Lop.ToString()));
            }
        }
Ejemplo n.º 7
0
        void Load()
        {
            EC_GiaoVien GiaoVien = new BUS_GiaoVien().Select_ByPrimaryKey(Ma_GiaoVien);

            if (GiaoVien.Anh != null)
            {
                picAvt.Image = HinhAnh.ByteToImage(GiaoVien.Anh);
            }
            txbMa_GiaoVien.Text     = GiaoVien.Ma_GiaoVien;
            txbTen_GiaoVien.Text    = GiaoVien.Ten_GiaoVien;
            txbDiaChi.Text          = GiaoVien.DiaChi;
            txbEmail.Text           = GiaoVien.Email;
            txbSDT.Text             = GiaoVien.SDT;
            dtNgaySinh.Value        = GiaoVien.NgaySinh;
            cbGioiTinh.SelectedItem = GiaoVien.GioiTinh == true ? "Nam" : "Nữ";
            cbTrinhDo.SelectedItem  = GiaoVien.TrinhDo;

            List <EC_PhanCong_Day> listPhanCong_Day = new BUS_PhanCong_Day().SelectByFields("Ma_GiaoVien", Ma_GiaoVien);
            BUS_MonHoc             busMonHoc        = new BUS_MonHoc();
            int index = 1;

            foreach (EC_PhanCong_Day ec in listPhanCong_Day)
            {
                EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc);
                dgPhanCong_Day.Rows.Add(index.ToString(), MonHoc.Ma_MonHoc, MonHoc.Ten_MonHoc, MonHoc.Lop.ToString());
                index++;
            }

            index = 1;
            List <EC_LopHoc> listLopHoc = new BUS_LopHoc().SelectByFields("Ma_GiaoVien", Ma_GiaoVien);

            foreach (EC_LopHoc ec in listLopHoc)
            {
                List <EC_LichHoc> listBuoiHoc = new BUS_LichHoc().SelectByFields("Ma_LopHoc", ec.Ma_LopHoc);
                if (listBuoiHoc.Count == 0)
                {
                    continue;
                }
                List <EC_BuoiHoc_HocSinh> listBHHS = new BUS_BuoiHoc_HocSinh().SelectByFields("Ma_BuoiHoc", listBuoiHoc[0].Ma_BuoiHoc);
                EC_MonHoc MonHoc = busMonHoc.Select_ByPrimaryKey(ec.Ma_MonHoc);
                dgLopDay.Rows.Add(index.ToString(), ec.Ma_LopHoc, MonHoc.Ten_MonHoc, MonHoc.Lop, ec.SoBuoi, listBHHS.Count);
                index++;
            }
        }
Ejemplo n.º 8
0
        public DataTable LopHoc_Select_Manager(EC_LopHoc ecLop, EC_MonHoc ecMon)
        {
            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from LopHoc_Select_Manager(@Ten_MonHoc, @Lop, @Ma_GiaoVien, @TrinhDo, @TongSoBuoi)", con);

                cmd.Parameters.AddWithValue("@Ten_MonHoc", ecMon.Ten_MonHoc);
                cmd.Parameters.Add(new SqlParameter("@Lop", SqlDbType.Int)).Value = ecMon.Lop;
                cmd.Parameters.AddWithValue("@Ma_GiaoVien", ecLop.Ma_GiaoVien);
                cmd.Parameters.AddWithValue("@TrinhDo", ecLop.TrinhDo);
                cmd.Parameters.Add(new SqlParameter("@TongSoBuoi", SqlDbType.Int)).Value = ecLop.SoBuoi;

                SqlDataAdapter adt = new SqlDataAdapter(cmd);
                DataTable      tb  = new DataTable();
                adt.Fill(tb);
                con.Close();
                return(tb);
            }
        }
Ejemplo n.º 9
0
        public EC_MonHoc Select_ByPrimaryKey(string Ma_MonHoc)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[MonHoc_Select_By_Ma]";
            sqlCommand.CommandType = CommandType.StoredProcedure;


            try
            {
                sqlCommand.Parameters.AddWithValue("@Ma_MonHoc", Ma_MonHoc);

                con.MoKetNoi();
                // Use connection object of base class
                sqlCommand.Connection = con.connect;

                IDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    EC_MonHoc businessObject = new EC_MonHoc();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Lỗi khi lấy tất cả mon học.", ex);
            }
            finally
            {
                con.DongKetNoi();
                sqlCommand.Dispose();
            }
        }
Ejemplo n.º 10
0
        void LayDuLieu()
        {
            string MaGV;

            if (txbMaGV.Text == "" || txbMaGV.Text == null)
            {
                MaGV = "All";
            }
            else
            {
                MaGV = txbMaGV.Text;
            }
            string TrinhDo;

            if (cbTrinhDo.SelectedIndex == 0)
            {
                TrinhDo = "All";
            }
            else
            {
                TrinhDo = cbTrinhDo.SelectedItem.ToString();
            }
            string SoBuoi = txbSoBuoi.Text;

            for (int i = 0; i < SoBuoi.Length; i++)
            {
                if (SoBuoi[i] > 9 || SoBuoi[i] < 0)
                {
                    MessageBox.Show("Số buổi không hợp lệ!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            int SB;

            if (SoBuoi == "")
            {
                SB = 0;
            }
            else
            {
                SB = Int32.Parse(SoBuoi);
            }
            string TenMon;

            if (cbTenMon.SelectedIndex == 0)
            {
                TenMon = "All";
            }
            else
            {
                TenMon = cbTenMon.SelectedItem.ToString();
            }
            int Lop;

            if (cbLop.SelectedIndex == 0)
            {
                Lop = 0;
            }
            else
            {
                Lop = Convert.ToInt32(cbLop.SelectedItem);
            }
            EC_LopHoc ecLop = new EC_LopHoc("All", "All", "All", TrinhDo, 0, SB, dtNgayBatdau.Value);
            EC_MonHoc ecMon = new EC_MonHoc("All", TenMon, Lop);

            dgLopHoc.DataSource = ft.LopHoc_Select_Manager(ecLop, ecMon);
        }
Ejemplo n.º 11
0
 public DataTable LopHoc_Select_Manager(EC_LopHoc ecLop, EC_MonHoc ecMon)
 {
     return(ft.LopHoc_Select_Manager(ecLop, ecMon));
 }
Ejemplo n.º 12
0
 public void SuaDuLieu(EC_MonHoc ec)
 {
     sql.SuaDuLieu(ec);
 }
Ejemplo n.º 13
0
 public void ThemDuLieu(EC_MonHoc ec)
 {
     sql.ThemDuLieu(ec);
 }