Exemple #1
0
 private void gridviewLop_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     txtMalop.Enabled   = false;
     txtTenlop.Text     = gridviewLop.CurrentRow.Cells["TenLop"].Value.ToString();
     cboMamon.Text      = gridviewLop.CurrentRow.Cells["Mamon"].Value.ToString();
     cboMaGV.Text       = gridviewLop.CurrentRow.Cells["MaGV"].Value.ToString();
     txtMalop.Text      = gridviewLop.CurrentRow.Cells["Malop"].Value.ToString();
     cboMaca.Text       = gridviewLop.CurrentRow.Cells["Maca"].Value.ToString();
     cboMathoigian.Text = gridviewLop.CurrentRow.Cells["Mathoigian"].Value.ToString();
     cboMaphong.Text    = gridviewLop.CurrentRow.Cells["Maphong"].Value.ToString();
     string[] date = gridviewLop.CurrentRow.Cells["NgayBD"].Value.ToString().Split('/');
     string[] year = date[2].Split(' ');
     cboNgay.Text  = date[1];
     cboThang.Text = date[0];
     cboNam.Text   = year[0];
     string[] date1 = gridviewLop.CurrentRow.Cells["NgayKT"].Value.ToString().Split('/');
     string[] year1 = date1[2].Split(' ');
     cboNgay1.Text   = date1[1];
     cboThang1.Text  = date1[0];
     cboNam1.Text    = year1[0];
     txtSiso.Text    = DAO.GetFieldValues("select count(MaHocVien) from tblHocvien  where Malop ='" + txtMalop.Text + "'");
     txtSiso.Enabled = false;
 }
Exemple #2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMalop.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập mã lớp", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMalop.Focus();
                return;
            }
            if (txtTenlop.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tên lớp", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenlop.Focus();
                return;
            }
            if (cboMamon.SelectedIndex == -1)
            {
                MessageBox.Show("mã môn chưa tồn tại ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboMaGV.SelectedIndex == -1)
            {
                MessageBox.Show("mã giáo viên chưa tồn tại ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }

            if (cboMaca.SelectedIndex == -1)
            {
                MessageBox.Show("mã ca chưa tồn tại ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboNgay.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn ngày BĐ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboThang.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn tháng BĐ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboNam.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn Năm BĐ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboNgay1.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn ngày KT", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboThang1.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn tháng KT", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboNam1.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn Năm KT", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboMathoigian.SelectedIndex == -1)
            {
                MessageBox.Show("mã thời gian chưa tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboMaphong.SelectedIndex == -1)
            {
                MessageBox.Show("mã phòng chưa tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sqlCheckkey = "Select * from tblLophoc where MaLop = '" + txtMalop.Text.Trim() + "'";

            DAO.OpenConnection();

            if (DAO.checkKeyexit(sqlCheckkey))
            {
                MessageBox.Show("Mã lớp học đã tồn tại");
                DAO.CloseConnection();
                txtMalop.Focus();
                return;
            }
            else
            {
                string NgayBD;
                NgayBD = String.Format("{1}/{0}/{2}", cboNgay.Text, cboThang.Text, cboNam.Text);
                string NgayKT;
                NgayKT = String.Format("{1}/{0}/{2}", cboNgay1.Text, cboThang1.Text, cboNam1.Text);
                string siso;
                siso = string.Format(txtSiso.Text = DAO.GetFieldValues("select count(MaHocVien) from tblHocvien  where Malop ='" + txtMalop.Text + "'"));



                string sql = "insert into tblLophoc values('" + txtMalop.Text.Trim() + "',N'" + txtTenlop.Text.Trim() + "',N'" + cboMamon.Text.Trim() + "',N'" + cboMaGV.Text.Trim()
                             + "','" + NgayBD + "','" + NgayKT
                             + "',N'" + cboMaca.Text.Trim() + "',N'" + cboMathoigian.Text.Trim() + "','" + cboMaphong.Text.Trim()
                             + "','" + siso + "')";

                SqlCommand cmd = new SqlCommand(sql, DAO.conn);


                cmd.ExecuteNonQuery();
                LoaddatatoGridview();
                filldatatocombo();
                filldatatocombo1();
                filldatatocombo2();
                filldatatocombo3();

                DAO.CloseConnection();
            }
        }