private void btnKHNhanXe_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { DialogResult dialogResult = XtraMessageBox.Show("Khách đã nhận xe, xe sẽ được xóa khỏi danh sách ?", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { if (SqlConn == null || SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } if (SqlConn.State == ConnectionState.Open) { try { string s_MaQL = grvTraXe.GetRowCellValue(grvTraXe.FocusedRowHandle, "maql").ToString(); DsTraXe ds = new DsTraXe(); ds.UpdateTrangThai(SqlConn, s_MaQL); } catch { } finally { CapNhatDuLieuGridView(); } } } else if (dialogResult == DialogResult.No) { } }
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(); }
private void btnGoi_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (SqlConn == null || SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } if (SqlConn.State == ConnectionState.Open) { try { string s_MaQL = grvTraXe.GetRowCellValue(grvTraXe.FocusedRowHandle, "maql").ToString(); DsTraXe ds = new DsTraXe(); ds.UpdateTrangThaiGoiLayXe(SqlConn, s_MaQL, TrangThai.TraiThaiGoiLayXe.DangGoi); } catch { } finally { CapNhatDuLieuGridView(); } } }
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 { } } }
private void timer1_Tick(object sender, EventArgs e) { if (this.SqlConn == null || this.SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } if (this.bDuocPhepGoi) { try { if (this.SqlConn != null && this.SqlConn.State == ConnectionState.Open) { DsTraXe ds_TraXe = new DsTraXe(); DataTable dtDSGoi = ds_TraXe.LoadDsGoiLayXe(SqlConn); if (dtDSGoi != null && dtDSGoi.Rows.Count > 0) { tmrThongBao.Stop(); foreach (DataRow r in dtDSGoi.Select("", "")) { string s_BienSoXe = r["biensoxe"].ToString(); string s_TenKH = r["hoten"].ToString(); string s_MaQL = r["maql"].ToString(); if (chkGoiTenKH.Checked == false) { TienIch.Media.GoiKhachHangNhanXe(s_BienSoXe.Replace("-", "").Trim()); } else { string text = "Mời khách hàng " + s_TenKH + " biển số xe " + s_BienSoXe + " đến nhận xe"; PlayMp3FromUrl("nhanxe.mp3", text, Voice.hatieumai); } ds_TraXe.UpdateTrangThaiGoiLayXe(this.SqlConn, s_MaQL, TrangThai.TraiThaiGoiLayXe.DaGoi); //Thread.Sleep(THOIGIANNGHI); } tmrThongBao.Start(); } } } catch { } } if (this.bDuocPhepThongBao) { this.bDuocPhepThongBao = false; tmrThongBao.Stop(); try { if (this.SqlConn != null && this.SqlConn.State == ConnectionState.Open) { DsThongBao ds_Thongbao = new DsThongBao(); DataTable dt_ThongBao = ds_Thongbao.LoadDsHienThiThongBao(SqlConn); if (dt_ThongBao != null && dt_ThongBao.Rows.Count > 0) { DataRow r = dt_ThongBao.Rows[0]; string s_ThongBao = r["noidung"].ToString(); if (chkGoiTenKH.Checked == true) { PlayMp3FromUrl("thongbao.mp3", s_ThongBao, Voice.hatieumai); } } } } catch { } finally { tmrThongBao.Stop(); tmrThongBao.Start(); } } }
void CapNhatDuLieuGridView() { int i_TongBanNang = 0; int i_BanNangBan = 0; int i_TGConLai = 0; int i_BanNang_SelectIndex = 0; int i_KhachHang_SelectIndex = 0; int i_TraXe_SelectIndex = 0; string s_BanNangSuaChuaXong = ""; if (SqlConn == null || SqlConn.State != ConnectionState.Open) { Database.Open(ref this.SqlConn); } if (SqlConn.State == ConnectionState.Open) { try { i_BanNang_SelectIndex = grvBanNang.FocusedRowHandle; i_KhachHang_SelectIndex = grvKhachHang.FocusedRowHandle; i_TraXe_SelectIndex = grvTraXe.FocusedRowHandle; TienIch.DsKhachHang dskhachhang = new DsKhachHang(); DataTable dt_DsKH = dskhachhang.LoadDSKHChoSuaChua(SqlConn); grdKhachHang.DataSource = dt_DsKH; TienIch.DsBanNang dsbannang = new DsBanNang(); DataTable dt_DsBN = dsbannang.LoadTheoTrangThaiKichHoat(SqlConn, TrangThai.TrangThaiKichHoatBanNang.HoatDong); TienIch.DsTraXe ds_TraXe = new DsTraXe(); DataTable dt_TraXe = ds_TraXe.LoadDsChuaLayXe(SqlConn); grdTraXe.DataSource = dt_TraXe; try { if (dt_DsBN != null && dt_DsBN.Rows.Count > 0) { dt_DsBN.Columns.Add("thoigianconlai", typeof(decimal)).DefaultValue = 0; dt_DsBN.Columns.Add("trangthaibn", typeof(string)).DefaultValue = ""; i_TongBanNang = dt_DsBN.Rows.Count; foreach (DataRow r in dt_DsBN.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); //double minutes = diff.TotalMinutes; 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; } if (i_TGConLai <= 0 && TT_TrangThai == TrangThai.TrangThaiBanNang.DangSuaChua) { s_BanNangSuaChuaXong += String.Format("[{0}]", r["maql"].ToString()); } } } lblSLBanNang.Caption = String.Format("Hoạt động: {0}/{1}", i_BanNangBan, i_TongBanNang); grdBanNang.DataSource = dt_DsBN; grvBanNang.FocusedRowHandle = i_BanNang_SelectIndex; grvKhachHang.FocusedRowHandle = i_KhachHang_SelectIndex; grvTraXe.FocusedRowHandle = i_TraXe_SelectIndex; } catch { } } catch { } finally { if (s_BanNangSuaChuaXong != s_NhacNhoTraXe) { s_NhacNhoTraXe = s_BanNangSuaChuaXong; if (s_NhacNhoTraXe != "") { ntfNhacNho.Visible = true; ntfNhacNho.Icon = SystemIcons.Exclamation; ntfNhacNho.BalloonTipTitle = "IKY-LED"; ntfNhacNho.BalloonTipText = "Bàn nâng " + s_NhacNhoTraXe + " đã sửa chữa xong"; ntfNhacNho.BalloonTipIcon = ToolTipIcon.Warning; ntfNhacNho.ShowBalloonTip(10000); } } } } }