private void btnLoad_Click(object sender, EventArgs e) { DateTime dti_TuNgay = Convert.ToDateTime(txtTuNgay.EditValue); DateTime dti_DenNgay = Convert.ToDateTime(txtDenNgay.EditValue); if (dti_TuNgay == Convert.ToDateTime(null)) { dti_TuNgay = DateTime.Today; } if (dti_DenNgay == Convert.ToDateTime(null)) { dti_DenNgay = dti_TuNgay; } if (dti_TuNgay == Convert.ToDateTime(null) || dti_DenNgay == Convert.ToDateTime(null)) { return; } string s_TuNgay = dti_TuNgay.ToString("yyyy-MM-dd") + " 00:00"; string s_DenNgay = dti_DenNgay.ToString("yyyy-MM-dd") + " 23:59"; dt_BaoCao = new DataTable(); string sql = "select * from baocao where time between '" + s_TuNgay + "' and '" + s_DenNgay + "'"; dt_BaoCao = ThuVien.SQLiteLoad(sqlConn, sql); grdDuLieu.DataSource = dt_BaoCao; if (dt_BaoCao != null && dt_BaoCao.Rows.Count > 0) { grvDuLieu.FocusedRowHandle = 0; } }
private void refreshToolStripButton_Click(object sender, EventArgs e) { int i_TongBanNang = 0; int i_BanNangBan = 0; if (m_dbConnection == null || m_dbConnection.State != ConnectionState.Open) { m_dbConnection = new SQLiteConnection("Data Source=sled.sqlite;Version=3;"); m_dbConnection.Open(); } if (m_dbConnection.State == ConnectionState.Open) { try { string sql = "select * from bannang order by id asc"; dt_HoatDongBanNang = ThuVien.SQLiteLoad(m_dbConnection, sql); if (dt_HoatDongBanNang != null && dt_HoatDongBanNang.Rows.Count > 0) { dt_HoatDongBanNang.Columns.Add("thoigianconlai", typeof(decimal)).DefaultValue = 0; i_TongBanNang = dt_HoatDongBanNang.Rows.Count; foreach (DataRow r in dt_HoatDongBanNang.Rows) { if (Convert.ToInt32(r["counter"]) == 0) { r["trangthai"] = "Rảnh"; r["khachhang"] = ""; r["biensoxe"] = ""; r["thoigianconlai"] = 0; } else { DateTime TGCapNhat = Convert.ToDateTime(r["time"]); TimeSpan diff = DateTime.Now.Subtract(TGCapNhat); double minutes = diff.TotalMinutes; r["thoigianconlai"] = Convert.ToInt32(minutes) >= Convert.ToInt32(r["counter"]) ? 0 : Convert.ToInt32(r["counter"]) - Convert.ToInt32(minutes); r["trangthai"] = "Bận"; i_BanNangBan++; } } } txtTrangThaiBanNang.Caption = String.Format("Hoạt động: {0}/{1}", i_BanNangBan, i_TongBanNang); grdDuLieu.DataSource = dt_HoatDongBanNang; if (dt_HoatDongBanNang != null && dt_HoatDongBanNang.Rows.Count > 0) { grvDuLieu.FocusedRowHandle = 0; } } catch { } } }
private void frmMain_Load(object sender, EventArgs e) { //this.WindowState = System.Windows.Forms.FormWindowState.Maximized; try { string sFileDataBase = Application.ExecutablePath; int i_Index = sFileDataBase.LastIndexOf('\\'); sFileDataBase = sFileDataBase.Substring(0, i_Index).Trim('\\'); sFileDataBase = sFileDataBase + "\\" + s_Database; if (File.Exists(sFileDataBase) == false) { CreatNewDatabase(); } } catch { } if (m_dbConnection == null || m_dbConnection.State != ConnectionState.Open) { m_dbConnection = new SQLiteConnection("Data Source=sled.sqlite;Version=3;"); m_dbConnection.Open(); } if (m_dbConnection.State == ConnectionState.Open) { try { string sql = "select * from port order by time asc"; DataTable dt = ThuVien.SQLiteLoad(m_dbConnection, sql); if (dt != null && dt.Rows.Count > 0) { DataRow r = dt.Rows[dt.Rows.Count - 1]; s_SerialPort = r["name"].ToString(); } } catch { } } txtTTCongGiaoTiep.Caption = s_SerialPort; refreshToolStripButton_Click(null, null); }
private void btnDongY_Click(object sender, EventArgs e) { if (cbbSerialPorts.SelectedIndex > -1) { if (SQLiteCon == null || SQLiteCon.State != ConnectionState.Open) { SQLiteCon = new SQLiteConnection("Data Source=sled.sqlite;Version=3;"); SQLiteCon.Open(); } if (SQLiteCon.State == ConnectionState.Open) { string sql = "select * from port"; DataTable dt = ThuVien.SQLiteLoad(SQLiteCon, sql); sql = "insert into port (id,name, baud) values (1,'" + cbbSerialPorts.SelectedItem.ToString() + "', 115200)"; if (dt != null && dt.Rows.Count > 0) { DataRow[] r_Col = dt.Select("id=1"); if (r_Col != null && r_Col.Length > 0) { sql = "UPDATE port SET name = '" + cbbSerialPorts.SelectedItem.ToString() + "' WHERE ID = 1"; } } try { SQLiteCommand command = new SQLiteCommand(sql, SQLiteCon); command.ExecuteNonQuery(); } catch { } } b_ThayDoi = true; } else { MessageBox.Show("Dữ liệu không hợp lệ", "Lỗi!"); } this.Close(); }
private void btnLuu_Click(object sender, EventArgs e) { if (dt_BaoCao != null && dt_BaoCao.Rows.Count > 0) { XoaDuLieuBaoCao_ThangTruoc(); try { SaveFileDialog objSaveFileDialog = new SaveFileDialog(); objSaveFileDialog.Filter = "Excel2003 Excel|*.xls|Excel2007 Excel|*.xlsx"; objSaveFileDialog.ShowDialog(); if (!string.IsNullOrEmpty(objSaveFileDialog.FileName.Trim())) { string[] strList = objSaveFileDialog.FileName.Split('.'); if (strList.Length > 0) { string s_FilePath = objSaveFileDialog.FileName; switch (strList[strList.Length - 1].ToString().Trim()) { case "xls": grdDuLieu.ExportToXls(objSaveFileDialog.FileName); break; case "xlsx": grdDuLieu.ExportToXlsx(objSaveFileDialog.FileName); break; } Excel.Application oxl = new Excel.Application(); int i_SoCot = dt_BaoCao.Columns.Count; int i_SoDong = dt_BaoCao.Rows.Count; Excel.Workbook owb = oxl.Workbooks.Open(s_FilePath, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value); Excel._Worksheet osheet = (Excel._Worksheet)owb.ActiveSheet; oxl.ActiveWindow.DisplayGridlines = true; int i_SoDongTieuDe = 5; for (int i_Dong = 0; i_Dong < i_SoDongTieuDe; i_Dong++)//insert các dòng tiêu đề { osheet.get_Range(ThuVien.ColumnExcel(i_Dong) + "1", ThuVien.ColumnExcel(i_Dong) + "1").EntireRow.Insert(Missing.Value); } oxl.ActiveWindow.DisplayZeros = false; //Định dạng phần header. //Thiết lập vùng điền dữ liệu. int rowStart_h = 1; int columnStart_h = 1; int rowEnd_h = rowStart_h + i_SoDongTieuDe + 1; int columnEnd_h = dt_BaoCao.Columns.Count + 2; // Ô bắt đầu điền dữ liệu Excel.Range c1 = (Excel.Range)osheet.Cells[rowStart_h, columnStart_h]; // Ô kết thúc điền dữ liệu Excel.Range c2 = (Excel.Range)osheet.Cells[rowEnd_h, columnEnd_h]; //Căn giữa vùng dữ liệu osheet.get_Range(c1, c2).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; osheet.get_Range(c1, c2).Font.Bold = true; //Định dạng phần footer. int rowStart_f = i_SoDongTieuDe + i_SoDong + 4; int rowEnd_f = i_SoDongTieuDe + i_SoDong + 6; Excel.Range c3 = (Excel.Range)osheet.Cells[rowStart_f, columnStart_h]; Excel.Range c4 = (Excel.Range)osheet.Cells[rowEnd_f, columnEnd_h]; osheet.get_Range(c3, c4).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; //set font chữ từ đầu dòng đến cuối dòng dữ liệu Excel.Range orange = osheet.get_Range("A1", ThuVien.ColumnExcel(i_SoCot + 1) + (i_SoDongTieuDe + 1).ToString()); orange.Font.Bold = true; orange = osheet.get_Range("A1", ThuVien.ColumnExcel(i_SoCot) + (i_SoDongTieuDe + i_SoDong + 6).ToString()); orange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; orange.WrapText = false; orange.RowHeight = 180; orange.Cells.Interior.Color = System.Drawing.Color.White; orange.EntireRow.AutoFit(); orange = osheet.get_Range("A" + (i_SoDongTieuDe + 2).ToString(), ThuVien.ColumnExcel(i_SoCot - 3) + (i_SoDongTieuDe + i_SoDong + 2).ToString()); orange.Cells.BorderAround(4, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); for (int i = i_SoDongTieuDe + 2; i <= i_SoDongTieuDe + i_SoDong + 2; i++) { orange = osheet.get_Range("A" + i.ToString(), ThuVien.ColumnExcel(i_SoCot - 1) + i.ToString()); orange.Cells.BorderAround(4, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, 0); } osheet.PageSetup.LeftMargin = 20; osheet.PageSetup.RightMargin = 20; osheet.PageSetup.TopMargin = 30; osheet.PageSetup.CenterFooter = "Trang : &P/&N"; oxl.Visible = true; orange = osheet.get_Range("A1", ThuVien.ColumnExcel(i_SoCot) + (i_SoDongTieuDe + i_SoDong + 6).ToString()); orange.Cells.Font.Size = 11; orange.EntireColumn.AutoFit(); osheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape; osheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA4; osheet.Cells[3, 3] = "BÁO CÁO HOẠT ĐỘNG BÀN NÂNG"; osheet.Cells[3, 3].Font.Bold = true; osheet.Cells[3, 3].Font.Size = 16; osheet.Cells[i_SoDongTieuDe + i_SoDong + 5, 4] = "Người lập biểu"; osheet.Cells[i_SoDongTieuDe + i_SoDong + 6, 4] = "(Ký tên, đóng dấu)"; string s_NgayIn = "Ngày " + DateTime.Today.Day + " tháng " + DateTime.Today.Month + " năm " + DateTime.Today.Year; osheet.Cells[i_SoDongTieuDe + i_SoDong + 4, 4] = s_NgayIn; } } } catch { } } else { MessageBox.Show("Không tìm thấy dữ liệu báo cáo!", "Thông báo"); } }
private void TuyChinhBanNang(int mode) { string s_time = DateTime.Now.ToString("yymmddhhmmssfff"); if (s_SerialPort == null || s_SerialPort == "") { MessageBox.Show("Bạn chưa thiết lập cổng COM", "Cảnh báo"); } else { try { string s_QuangCao = ""; string s_TTKhachHang = ""; string s_Counter = ""; string s_TTBienSoXe = ""; string s_KTV = ""; bool b_TaoMoi = true; Decimal d_TongTG = 0; string s_BanNang = grvDuLieu.GetRowCellValue(grvDuLieu.FocusedRowHandle, "id").ToString(); string sql = "select * from bannang where id = " + s_BanNang; DataTable dt = ThuVien.SQLiteLoad(m_dbConnection, sql); if (dt != null && dt.Rows.Count > 0) { DataRow r = dt.Rows[dt.Rows.Count - 1]; if (r["maql"].ToString() == "0") { //sql = "UPDATE bannang SET maql = '" + s_time + "' WHERE id = " + s_BanNang; s_MaQL = s_time; } else { s_MaQL = r["maql"].ToString(); s_TTKhachHang = r["khachhang"].ToString(); s_TTBienSoXe = r["biensoxe"].ToString(); b_TaoMoi = false; } d_TongTG = Convert.ToDecimal(r["counter"]); s_Counter = r["counter"].ToString(); s_KTV = r["ktv"].ToString(); s_QuangCao = r["greetings"].ToString(); } if (mode > -1) { switch (mode) { case 0: frmTiepNhanXe frmTNX = new frmTiepNhanXe(m_dbConnection, s_SerialPort, s_BanNang, b_TaoMoi, s_MaQL, s_TTKhachHang, s_TTBienSoXe, s_KTV, d_TongTG); frmTNX.ShowDialog(); break; case 1: frmDCTGSuaChua frmDCTG = new frmDCTGSuaChua(m_dbConnection, s_SerialPort, s_BanNang, d_TongTG); frmDCTG.ShowDialog(); break; case 2: frmTraXe frmTX = new frmTraXe(m_dbConnection, s_SerialPort, s_BanNang, s_MaQL, s_TTKhachHang, s_TTBienSoXe, s_KTV, d_TongTG, b_TaoMoi); frmTX.ShowDialog(); break; case 3: frmTTCauHinhBN frmTTCHBN = new frmTTCauHinhBN(m_dbConnection, s_SerialPort, s_BanNang, s_QuangCao, s_KTV); frmTTCHBN.ShowDialog(); break; default: break; } refreshToolStripButton_Click(null, null); } } catch { validationForm_FormClosed(null, null); } } }