private void F_Main_Load(object sender, EventArgs e) { sql = F_DangNhap.SQL_con_object as SQLConnect; nguoi = F_DangNhap.person_object as NguoiDung; barButtonItem2.Caption = "Thông tin kết nối : Tên Server \"" + sql.getConn().DataSource + "\" ; Cơ sở dữ liệu \"" + sql.getConn().Database + "\" || Tài khoản đang đăng nhập : " + nguoi.TenDangNhap; System.Timers.Timer timer = new System.Timers.Timer(1000); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Start(); switch (nguoi.Cap) { case 0: break; case 1: this.barButtonItem_CapQuyen.Enabled = false; break; case 2: this.barButtonItem_CapQuyen.Enabled = false; this.barButtonItem_tiepNhan.Enabled = false; this.barButtonItem_ThemToChuc.Enabled = false; this.barButtonItem_ThemDuAn.Enabled = false; break; } }
private void ShowAllData(double nam_thang) { DataColumn[] column = { c0, c1, c2, c3, c4, c6, c7, c8, c9, c10, c11 }; string cmd = ""; if (!checkEdit1.Checked) { cmd = "SELECT ROW_NUMBER() OVER(ORDER BY TenDuan asc) AS Row#,TenDuan,CONVERT(NVARCHAR, Ngaygiao, 103) as Ngaygiao,CONVERT(NVARCHAR, Thoihan, 103) as Thoihan,(DATEPART(YY,Thoihan - GETDATE()) - 1900) as soNam,DATEPART(MONTH,Thoihan - GETDATE()) as soThang,Diadiem,DMDvhc.TenDvhc ,SoQD,CONVERT(NVARCHAR, NgayQD, 103) as NgayQD,DMHinhthucsudung.TenHinhthuc,TinhtrangPL FROM Giaodat,DMHinhthucsudung,DMDvhc WHERE Giaodat.MaDvhc = DMDvhc.MaDvhc and Giaodat.MaHinhthuc = DMHinhthucsudung.MaHinhthuc"; } else { cmd = "SELECT ROW_NUMBER() OVER(ORDER BY TenDuan asc) AS Row#,TenDuan,CONVERT(NVARCHAR, Ngaygiao, 103) as Ngaygiao,CONVERT(NVARCHAR, Thoihan, 103) as Thoihan,(DATEPART(YY,Thoihan - GETDATE()) - 1900) as soNam,DATEPART(MONTH,Thoihan - GETDATE()) as soThang,Diadiem,DMDvhc.TenDvhc ,SoQD,CONVERT(NVARCHAR, NgayQD, 103) as NgayQD,DMHinhthucsudung.TenHinhthuc,TinhtrangPL FROM Giaodat,DMHinhthucsudung,DMDvhc WHERE (DMHinhthucsudung.MaHinhthuc = 'DT-KCN-THN' or DMHinhthucsudung.MaHinhthuc = 'DT-KCN-TML' or DMHinhthucsudung.MaHinhthuc = 'DT-THN' or DMHinhthucsudung.MaHinhthuc = 'DT-TML') and Giaodat.MaDvhc = DMDvhc.MaDvhc and Giaodat.MaHinhthuc = DMHinhthucsudung.MaHinhthuc"; } conn = sql.getConn(); conn.Open(); SqlCommand c = new SqlCommand(cmd, conn); SqlDataReader reader = c.ExecuteReader(); DataRow row; table_DSDuAn.BeginLoadData(); while (reader.Read()) { int i = 0, j = 0; int soNam, soThang; double compare = 0; row = table_DSDuAn.NewRow(); foreach (DataColumn col in column) { switch (i) { case 0: row[i] = int.Parse(reader.GetValue(j).ToString().Trim()); break; case 4: soNam = int.Parse(reader.GetValue(j).ToString().Trim()); j++; soThang = int.Parse(reader.GetValue(j).ToString().Trim()); if (soThang >= 10) { compare = double.Parse(soNam + "." + soThang); } else { compare = double.Parse(soNam + ".0" + soThang); } if (soNam < 0) { row[i] = "Đã hết hạn"; } else { if (soNam == 0) { row[i] = "gần " + soThang + " tháng"; } else { row[i] = "gần " + soNam + " năm, " + soThang + " tháng"; } } break; default: row[i] = reader.GetValue(j).ToString().Trim(); break; } i++; j++; } if (nam_thang == -1) { table_DSDuAn.Rows.Add(row); } if (nam_thang == 0) { if (row[4].ToString().Equals("Đã hết hạn")) { table_DSDuAn.Rows.Add(row); } } if (nam_thang > 0) { if (!row[4].ToString().Equals("Đã hết hạn")) { if (nam_thang >= compare) { table_DSDuAn.Rows.Add(row); } } } } table_DSDuAn.EndLoadData(); reader.Close(); c.Dispose(); conn.Close(); }