private void frmMain_Load(object sender, EventArgs e) { //Double click panelHeader.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDoubleClick); panelFooter.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDoubleClick); grdBanNang.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDoubleClick); grdKhachHang.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDoubleClick); // if (SqlConn == null || SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } CapNhatDuLieuGridView(); if (SqlConn.State == ConnectionState.Open) { TienIch.tshienthi ts = new tshienthi(); ts.LoadAll(SqlConn); s_Header = ts.Header; s_Footer = ts.Footer; i_SoDongHienThi = ts.SoDongHienThi; iThoiGianHienThiDuLieu = ts.TGHienThi; TienIch.DsTraXe ds = new DsTraXe(); DataTable dt_TraXe = ds.LoadDsHienThiThongBao(SqlConn); } iTocDoHieuUngThongBaoTraXe = Database.TocDoHieuUngThongBaoTraXe; //view lblTenCty.Text = s_Header; lblThongBaoTraXe.Text = s_Footer; grvBanNangCol_BanNang.Caption = String.Format("{0}" + Environment.NewLine + "{1}", "BÀN", "NÂNG"); grvBanNangCol_TGConLai.Caption = String.Format("{0}" + Environment.NewLine + "{1}", "TG", "BẮT ĐẦU"); grvBanNangCol_TGSuaChua.Caption = String.Format("{0}" + Environment.NewLine + "{1}", "TG", "SỬA"); grvBanNangCol_TGConLai.Caption = String.Format("{0}" + Environment.NewLine + "{1}", "TG", "CÒN LẠI"); // lblThongBaoTraXe.ForeColor = Database.MauChuThongBaoTraXe; // FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; WindowState = FormWindowState.Maximized; TopMost = true; // SetTimer(); }
void CapNhatDuLieuGridView() { int i_TGConLai = 0; if (SqlConn == null || SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } if (SqlConn.State == ConnectionState.Open) { try { //Cập nhật thông số TienIch.tshienthi ts = new tshienthi(); ts.LoadAll(SqlConn); s_Header = ts.Header; s_Footer = ts.Footer; i_SoDongHienThi = ts.SoDongHienThi; iThoiGianHienThiDuLieu = ts.TGHienThi; // TienIch.DsKhachHang dskhachhang = new DsKhachHang(); dt_KhachHang = dskhachhang.LoadDSKHChoSuaChua(SqlConn); if (bHienThiDuLieuMoi) //định kỳ 5s hiển thị dữ liệu { if (dt_KhachHang != null && dt_KhachHang.Rows.Count > 0) { DataTable dt_dsKH = new DataTable(); if (dt_KhachHang.Rows.Count < i_SoDongHienThi) { dt_dsKH = dt_KhachHang.Copy(); iDsKhachHangIndex = 0; } else { dt_dsKH = dt_KhachHang.Clone(); if (iDsKhachHangIndex >= dt_KhachHang.Rows.Count) { iDsKhachHangIndex = 0; } for (int i = 0; i < i_SoDongHienThi; i++) { if ((iDsKhachHangIndex + i) < dt_KhachHang.Rows.Count) { dt_dsKH.ImportRow(dt_KhachHang.Rows[iDsKhachHangIndex + i]); } else { break; } } iDsKhachHangIndex += i_SoDongHienThi; if (iDsKhachHangIndex >= dt_KhachHang.Rows.Count) { iDsKhachHangIndex = 0; } } grdKhachHang.DataSource = dt_dsKH; } else { grdKhachHang.DataSource = dt_KhachHang; iDsKhachHangIndex = 0; } } /////////////////////////////////////////////// TienIch.DsBanNang dsbannang = new DsBanNang(); dt_BanNang = dsbannang.LoadAll(SqlConn); try { if (dt_BanNang != null && dt_BanNang.Rows.Count > 0) { dt_BanNang.Columns.Add("thoigianconlai", typeof(decimal)).DefaultValue = 0; dt_BanNang.Columns.Add("trangthaibn", typeof(string)).DefaultValue = ""; foreach (DataRow r in dt_BanNang.Rows) { TrangThai.TrangThaiBanNang TT_TrangThai = (TrangThai.TrangThaiBanNang)Convert.ToInt16(r["trangthai"].ToString()); r["trangthaibn"] = TienIch.TrangThai.TrangThaiBanNang2String((TrangThai.TrangThaiBanNang)Convert.ToInt16(r["trangthai"].ToString())); DateTime TGCapNhat = r["thoigianbd"] == DBNull.Value ? DateTime.Now : Convert.ToDateTime(r["thoigianbd"]); TimeSpan diff = DateTime.Now.Subtract(TGCapNhat); Int32 minutes = Convert.ToInt32(Math.Ceiling(diff.TotalMinutes)); //Làm tròn lên để hiển thị khớp với bảng LED if (r["tongthoigian"] == DBNull.Value) { r["tongthoigian"] = 0; } i_TGConLai = Convert.ToInt32(minutes) >= Convert.ToInt32(r["tongthoigian"]) ? 0 : Convert.ToInt32(r["tongthoigian"]) - Convert.ToInt32(minutes); r["thoigianconlai"] = i_TGConLai; if (TT_TrangThai != TrangThai.TrangThaiBanNang.DangSuaChua) { r["hoten"] = ""; r["thoigianbd"] = DateTime.MinValue; r["biensoxe"] = ""; r["thoigianconlai"] = -1; r["tongthoigian"] = -1; } } } } catch { } if (bHienThiDuLieuMoi) //định kỳ 5s hiển thị dữ liệu { if (dt_BanNang != null && dt_BanNang.Rows.Count > 0) { DataTable dt_HienThi = new DataTable(); if (dt_BanNang.Rows.Count < i_SoDongHienThi) { dt_HienThi = dt_BanNang.Copy(); iDsBanNangIndex = 0; } else { dt_HienThi = dt_BanNang.Clone(); if (iDsBanNangIndex >= dt_BanNang.Rows.Count) { iDsBanNangIndex = 0; } for (int i = 0; i < i_SoDongHienThi; i++) { if ((iDsBanNangIndex + i) < dt_BanNang.Rows.Count) { dt_HienThi.ImportRow(dt_BanNang.Rows[iDsBanNangIndex + i]); } else { break; } } iDsBanNangIndex += i_SoDongHienThi; if (iDsBanNangIndex >= dt_BanNang.Rows.Count) { iDsBanNangIndex = 0; } } grdBanNang.DataSource = dt_HienThi; } else { grdBanNang.DataSource = dt_BanNang; iDsBanNangIndex = 0; } } ////////////////////////////////////////////////////////////////////////////////////// DsTraXe ds_TraXe = new DsTraXe(); // Hiển thị lên grid dt_TraXe = ds_TraXe.LoadDsChuaLayXe(SqlConn); if (bHienThiDuLieuMoi) //định kỳ 5s hiển thị dữ liệu { if (dt_TraXe != null && dt_TraXe.Rows.Count > 0) { DataTable dt_HienThi = new DataTable(); if (dt_TraXe.Rows.Count < i_SoDongHienThi) { dt_HienThi = dt_TraXe.Copy(); iDsTraXeIndex = 0; } else { dt_HienThi = dt_TraXe.Clone(); if (iDsTraXeIndex >= dt_TraXe.Rows.Count) { iDsTraXeIndex = 0; } for (int i = 0; i < i_SoDongHienThi; i++) { if ((iDsTraXeIndex + i) < dt_TraXe.Rows.Count) { dt_HienThi.ImportRow(dt_TraXe.Rows[iDsTraXeIndex + i]); } else { break; } } iDsTraXeIndex += i_SoDongHienThi; if (iDsTraXeIndex >= dt_TraXe.Rows.Count) { iDsTraXeIndex = 0; } } grdTraXe.DataSource = dt_HienThi; } else { grdTraXe.DataSource = dt_TraXe; iDsTraXeIndex = 0; } } // Chạy chữ footer DataTable dt_KQTraXe = ds_TraXe.LoadDsHienThiThongBao(SqlConn); if (dt_KQTraXe != null && dt_KQTraXe.Rows.Count > 0) { if (dt_ThongBaoLayXe == null) { dt_ThongBaoLayXe = dt_KQTraXe.Clone();// Clone() only clones the table structure. It does not also clone the data. } for (int i = 0; i < dt_KQTraXe.Rows.Count; i++) { bool isDupe = false; for (int j = 0; j < dt_ThongBaoLayXe.Rows.Count; j++) { if (dt_KQTraXe.Rows[i][0].ToString() == dt_ThongBaoLayXe.Rows[j][0].ToString()) { isDupe = true; break; } } if (!isDupe) { dt_ThongBaoLayXe.ImportRow(dt_KQTraXe.Rows[i]); } } } } catch { } } }