public MonHocXml[] layDSMonHoc_Tu_GUI() { List<MonHocXml> listMonHoc = new List<MonHocXml>(); for (int i = 0; i < dtgv_ThoiKhoaBieu.Rows.Count - 1; i++) { for (int j = 2; j <= 7; j++) { if (dtgv_ThoiKhoaBieu.Rows[i].Cells[j].Value.ToString().CompareTo("")!=0) { MonHocXml mon = new MonHocXml(); switch (j) { case 2: mon.TenThu = "2"; break; case 3: mon.TenThu = "3"; break; case 4: mon.TenThu = "4"; break; case 5: mon.TenThu = "5"; break; case 6: mon.TenThu = "6"; break; case 7: mon.TenThu = "7"; break; } mon.TenMon = dtgv_ThoiKhoaBieu.Rows[i].Cells[j].Value.ToString(); if (i <= 4) { mon.TenBuoi = "Sáng"; } else { mon.TenBuoi = "Chiều"; } mon.Tiet = i + 1; listMonHoc.Add(mon); } } } MonHocXml[] dsMonHoc = listMonHoc.ToArray(); return dsMonHoc; }
public void taoThoiKhoaBieu(int maLop, MonHocXml[] dsMonHoc) { if (lop.layThoiKhoaBieu_Tu_MaLop(maLop) != null) { bool[] dsDanhDau = new bool[dsMonHoc.Length]; ThoiKhoaBieu tkb = new ThoiKhoaBieu(); for (int i = 0; i < dsMonHoc.Length; i++) { if (dsDanhDau[i] == false) { Thu thu = new Thu(); thu.TenThu = dsMonHoc[i].TenThu; Mon mon = new Mon(); mon.TenBuoi = dsMonHoc[i].TenBuoi; mon.TenMon = dsMonHoc[i].TenMon; mon.Tiet = dsMonHoc[i].Tiet.ToString(); thu.DsMon.Add(mon); for (int j = i + 1; j < dsMonHoc.Length; j++) { if (dsMonHoc[i].TenThu.CompareTo(dsMonHoc[j].TenThu) == 0) { Mon mon1 = new Mon(); mon1.TenBuoi = dsMonHoc[j].TenBuoi; mon1.TenMon = dsMonHoc[j].TenMon; mon1.Tiet = dsMonHoc[j].Tiet.ToString(); thu.DsMon.Add(mon1); dsDanhDau[j] = true; } } tkb.DsThu.Add(thu); } } XmlDocument tailieu = new XmlDocument(); XmlElement nodeGoc = tailieu.CreateElement("ThoiKhoaBieu"); for (int i = 0; i < tkb.DsThu.Count; i++) { XmlElement thu = tailieu.CreateElement("Thu"); thu.SetAttribute("tenThu", tkb.DsThu[i].TenThu); for (int j = 0; j < tkb.DsThu[i].DsMon.Count; j++) { XmlElement mon = tailieu.CreateElement("Mon"); mon.SetAttribute("tenMon", tkb.DsThu[i].DsMon[j].TenMon); mon.SetAttribute("tiet", tkb.DsThu[i].DsMon[j].Tiet); mon.SetAttribute("tenBuoi", tkb.DsThu[i].DsMon[j].TenBuoi); thu.AppendChild(mon); } nodeGoc.AppendChild(thu); } tailieu.AppendChild(nodeGoc); string thoikhoabieu_lop = tailieu.InnerXml; string capNhatThoiKhoaBieu_MaLop = "sp_CapNhatThoiKhoaBieu_MaLop"; SqlParameter para1 = new SqlParameter("@maLop", maLop); SqlParameter para2 = new SqlParameter("@thoiKhoaBieu", thoikhoabieu_lop); DataProvider.executeStoreProcedureNonQuery(capNhatThoiKhoaBieu_MaLop, para1,para2); } }
public MonHocXml[] layDanhSachMonHoc(int maLop) { if (lop.layThoiKhoaBieu_Tu_MaLop(maLop) != null) { string e = lop.layThoiKhoaBieu_Tu_MaLop(maLop); doc.LoadXml(lop.layThoiKhoaBieu_Tu_MaLop(maLop)); XmlNode nodeGoc = doc.SelectSingleNode("/ThoiKhoaBieu"); XmlNodeList dsMon_NodeList = nodeGoc.SelectNodes("//Mon"); MonHocXml[] dsMon = new MonHocXml[dsMon_NodeList.Count]; for (int i = 0; i < dsMon_NodeList.Count; i++) { MonHocXml mon = new MonHocXml(); string a = dsMon_NodeList[i].Attributes["tenMon"].Value.ToString(); mon.TenMon = dsMon_NodeList[i].Attributes["tenMon"].Value.ToString(); mon.Tiet = Convert.ToInt32(dsMon_NodeList[i].Attributes["tiet"].Value); mon.TenBuoi = dsMon_NodeList[i].Attributes["tenBuoi"].Value.ToString(); mon.TenThu = dsMon_NodeList[i].ParentNode.Attributes["tenThu"].Value.ToString(); dsMon[i] = mon; } return dsMon; } return null; }