private void btnPT_Click(object sender, EventArgs e) { cn.Open(); string sql = "select TKB.* from TKBieu TKB"; List <PhongTrong> list = new List <PhongTrong>(); SqlCommand cmd = new SqlCommand(sql, cn); SqlDataReader dr = cmd.ExecuteReader(); int IDPhong, TietBD, TietKT; string TenPhong; DateTime Ngay; int[,] tiet = new int[10, 14]; string[] TenP = new string[10]; while (dr.Read()) { IDPhong = dr.GetInt32(0); TietBD = dr.GetInt32(2); TietKT = dr.GetInt32(3); Ngay = dr.GetDateTime(4); if (Ngay.Date == Convert.ToDateTime(dtpPT.Text)) { for (int i = TietBD; i <= TietKT; i++) { tiet[IDPhong - 1, i] = 1; } } } dr.Close(); sql = "select P.MaPhong, P.TenPhong from Phong P"; cmd = new SqlCommand(sql, cn); dr = cmd.ExecuteReader(); while (dr.Read()) { IDPhong = dr.GetInt32(0); TenPhong = dr.GetString(1); TenP[IDPhong - 1] = TenPhong; } dr.Close(); for (int i = 0; i < 10; i++) { string tt = ""; for (int j = 1; j <= 13; j++) { if (tiet[i, j] != 1) { tt += j + ", "; } } tt = tt.TrimEnd(' '); tt = tt.TrimEnd(','); PhongTrong room = new PhongTrong(TenP[i], tt, Convert.ToDateTime(dtpPT.Text)); list.Add(room); } dgvTKB.DataSource = list; cn.Close(); }
public List <PhongTrong> ListPTr() { List <PhongTrong> list = new List <PhongTrong>(); string query = "ListPhongTrong"; DataTable table = new DataTable(); table = SQL.ThuVienSQL.Instance.Execute_Query(query); foreach (DataRow i in table.Rows) { PhongTrong tkhd = new PhongTrong(i); list.Add(tkhd); } return(list); }
private void btnPT_Click(object sender, EventArgs e) { cn.Open(); string sql = "select * from TKBieu"; List <PhongTrong> list = new List <PhongTrong>(); SqlCommand cmd = new SqlCommand(sql, cn); SqlDataReader dr = cmd.ExecuteReader(); int IDPhong, TietBD, TietKT; DateTime Ngay; int[,] tiet = new int[3, 10] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; while (dr.Read()) { IDPhong = dr.GetInt32(0); TietBD = dr.GetInt32(2); TietKT = dr.GetInt32(3); Ngay = dr.GetDateTime(4); if (Ngay.Date == Convert.ToDateTime(dtpPT.Text)) { for (int i = TietBD; i <= TietKT; i++) { tiet[IDPhong - 1, i] = 1; } } } dr.Close(); for (int i = 0; i < 3; i++) { string tt = ""; for (int j = 1; j <= 9; j++) { if (tiet[i, j] != 1) { tt += j + ", "; } } tt = tt.TrimEnd(' '); tt = tt.TrimEnd(','); PhongTrong room = new PhongTrong(i + 1, tt, Convert.ToDateTime(dtpPT.Text)); list.Add(room); } dgvTKB.DataSource = list; cn.Close(); }