Esempio n. 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (dataGridViewX1.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridViewX1.Rows.Count; i++)
                {
                    string makhoa, machuongtrinhhoc, magv, maphonghoc, mangayhoc, maca;
                    makhoa           = new KhoaHocBUS().GetMa_TheoTen(dataGridViewX1.Rows[i].Cells[2].Value.ToString());
                    machuongtrinhhoc = new ChuongTrinhHocBUS().GetMa_TheoTen(dataGridViewX1.Rows[i].Cells[3].Value.ToString());
                    magv             = new GiangVienBUS().GetMa_TheoTen(dataGridViewX1.Rows[i].Cells[10].Value.ToString());
                    maphonghoc       = new PhongHocBUS().GetMa_TheoTen_PhongHoc(dataGridViewX1.Rows[i].Cells[11].Value.ToString());
                    mangayhoc        = new NgayHocBUS().GetMa_TheoTen(dataGridViewX1.Rows[i].Cells[6].Value.ToString());
                    maca             = new CaHocBUS().GetMa_TheoTen(dataGridViewX1.Rows[i].Cells[7].Value.ToString());
                    _objlop          = new Lop(
                        _objlopbus.Lop_NextID(),
                        dataGridViewX1.Rows[i].Cells[1].Value.ToString(),
                        makhoa,
                        machuongtrinhhoc,
                        DateTime.Parse(dataGridViewX1.Rows[i].Cells[4].Value.ToString()),
                        DateTime.Parse(dataGridViewX1.Rows[i].Cells[5].Value.ToString()),
                        maca,
                        mangayhoc,
                        magv,
                        maphonghoc);

                    if (_objlopbus.AddLop(_objlop))
                    {
                        dataGridViewX1.Rows.Remove(dataGridViewX1.Rows[i]);
                        i--;
                        LoadData();
                    }
                    else
                    {
                        string a = dataGridViewX1.Rows[i].Cells[0].Value.ToString();
                        MessageBox.Show("Lưu dòng " + a + " thất bại");
                    }
                }


                if (dataGridViewX1.Rows.Count == 0)
                {
                    MessageBox.Show("Lưu thành công");
                }

                dtipNgayBatDau.Text  = "";
                dtipNgayKetThuc.Text = "";
            }
            else
            {
                MessageBox.Show("Không có dữ liệu để lưu ! ", "Thống báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }