/// <summary> /// 新增設備 /// </summary> private void NewDevice() { string IP = string.Format("{0}.{1}.{2}.{3}", tbIP1.Text, tbIP2.Text, tbIP3.Text, tbIP4.Text); bool isEnable = cbEnable.SelectedIndex == 0 ? true : false; int type = cbType.SelectedIndex; //先檢查此設定是否存在;// if (DaoSQL.Instance.isExistMachine(IP, tbPort.Text.ToInt()) == true) { DialogResult BoxRet = MessageBoxEx.Show(this, string.Format("IP:{0} 端口:{1} 設定已存在.\r\n是否要覆蓋此設備資訊?", IP, tbPort.Text), "訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (BoxRet != DialogResult.Yes) { return; } } //DaoErrMsg Ret = DaoSQL.Instance.AddNewMachine(tbName.Text, tbLocation.Text.PadLeft(2, '0'), tbMachineNo.Text.ToInt(), IP, tbPort.Text.ToInt(), isEnable, type); DaoErrMsg Ret = DaoSQL.Instance.AddNewMachine(tbName.Text, tbLocation.Text, tbMachineNo.Text.ToInt(), IP, tbPort.Text.ToInt(), isEnable, type); if (Ret.isError == false) { MessageBoxEx.Show(this, "新增設備成功", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.Yes; this.Close(); } else { MessageBoxEx.Show(this, string.Format("新增設備失敗\r\n{0}", Ret.ErrorMsg), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnBackup_Click(object sender, EventArgs e) { DialogResult Ret = MessageBoxEx.Show(this, "確定要上傳本地端[車型代號]及[操作員代號]至伺服器??", "訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Ret != DialogResult.Yes) { return; } this.Cursor = Cursors.AppStarting; string Msg = string.Empty; DbCheckState DbState = MyNetworkPlacesDbTest(out Msg); switch (DbState) { case DbCheckState.eDB_FOUND: //查遠端資料庫存在,更新指定資料表;// DaoErrMsg Err = DaoSQL.Instance.UploadLocalDatabase(tbPathDb.Text); if (Err.isError) { MessageBoxEx.Show(this, Err.ErrorMsg, "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBoxEx.Show(this, "[車型代號]及[操作員代號]資訊已上傳成功", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case DbCheckState.eDB_NOT_FOUND: //查遠端資料庫不存在,直接上傳本地端的DB;// DaoSQL.Instance.CloseDatabase(); string DestPath = Path.GetDirectoryName(tbPathDb.Text); string FileName = Path.GetFileName(tbPathDb.Text); if (DestPath == null) { DestPath = tbPathDb.Text; FileName = DaoConfigFile.Instance.m_FileDatabase; } else if (FileName == null || FileName.Length == 0 || Path.GetExtension(FileName) != "mdb") { FileName = DaoConfigFile.Instance.m_FileDatabase; } NetTranslate.Transport(DaoConfigFile.Instance.FileDatabase, DestPath, FileName); MessageBoxEx.Show(this, "[車型代號]及[操作員代號]資訊已上傳成功", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); DaoSQL.Instance.OpenDatabase(); break; } this.Cursor = Cursors.Default; }
/// <summary> /// 新增按鈕按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnNew_Click(object sender, EventArgs e) { string IP = string.Format("{0}.{1}.{2}.{3}", tbIP1.Text, tbIP2.Text, tbIP3.Text, tbIP4.Text); bool isEnable = cbEnable.SelectedIndex == 0 ? true : false; DaoErrMsg Ret = DaoMSSQL.Instance.AddNewMachine(tbName.Text, tbNumber.Text.ToInt(), IP, tbPort.Text.ToInt(), isEnable); if (Ret.isError == false) { MessageBoxEx.Show(this, "新增指紋機成功", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.Yes; this.Close(); } else { MessageBoxEx.Show(this, string.Format("新增指紋機失敗\r\n{0}", Ret.ErrorMsg), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ShowMenu(DataGridView dgv, MouseEventArgs args) { // 取得 RowIndex // 方法 1:透過 HitTest() int RowIndex = dgv.HitTest(args.X, args.Y).RowIndex; // 方法 2:CurrentRow //int RowIndex = dgv.CurrentRow.Index; if (RowIndex < 0) { return; } dgv.CurrentCell = dgv.Rows[RowIndex].Cells[0]; ContextMenuStrip menu = new ContextMenuStrip(); ToolStripMenuItem item = new ToolStripMenuItem("删除員工資料"); item.Click += (sender, e) => { string Serial = dgv.Rows[RowIndex].Cells["員工編號"].Value.ToString(); if (MessageBoxEx.Show(this, string.Format("確定要刪除員工編號 {0} ?", Serial), "警告!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DaoErrMsg Msg = DaoMSSQL.Instance.DeleteEmployees(Serial); if (Msg.isError == false) { dgv.Rows.RemoveAt(RowIndex); MessageBoxEx.Show(this, string.Format("已刪除員工編號 {0} ?", Serial), "訊息!!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }; menu.Items.Add(item); // 四種指定 ContextMenuStrip 位置方式 // 方法 1 menu.Show(dgv, new Point(args.X, args.Y)); // 方法 2 //menu.Show(dgv, args.Location); // 方法 3 //menu.Show(Cursor.Position); // 方法 4:DataGridView 也有 PointToClient() 可以使用 //menu.Show(dgv, dgv.PointToClient(Cursor.Position)); }
private void BtnUpdate_MouseUp(object sender, MouseEventArgs e) { DialogResult Ret = MessageBoxEx.Show(this, "確定要更新本地端[車型代號]及[操作員代號]資訊??", "訊息", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Ret != DialogResult.Yes) { return; } this.Cursor = Cursors.AppStarting; string Msg = string.Empty; ServerDbControl.DbCheckState DbState = ServerDbControl.MyNetworkPlacesDbTest(out Msg); switch (DbState) { case ServerDbControl.DbCheckState.eDB_FOUND: string ServerDbPath = DaoSQL.Instance.GetServerDbPath(); DaoErrMsg Err = DaoSQL.Instance.UpdateLocalDatabase(ServerDbPath); if (Err.isError) { MessageBoxEx.Show(this, Err.ErrorMsg, "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBoxEx.Show(this, "[車型代號]及[操作員代號]已更新", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case ServerDbControl.DbCheckState.eDB_NOT_FOUND: case ServerDbControl.DbCheckState.eDB_PATH_ERROR: MessageBoxEx.Show(this, string.Format("更新失敗!\r\n錯誤資訊:{0}", Msg), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; case ServerDbControl.DbCheckState.eDB_PATH_FIELD_EMPTY: MessageBoxEx.Show(this, "沒有設定[伺服器備份路徑]及[伺服器資料庫路徑]", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } this.Cursor = Cursors.Default; }
/// <summary> /// 覆蓋現有設備資訊 /// </summary> private void SaveDevice() { string IP = string.Format("{0}.{1}.{2}.{3}", tbIP1.Text, tbIP2.Text, tbIP3.Text, tbIP4.Text); bool isEnable = cbEnable.SelectedIndex == 0 ? true : false; int type = cbType.SelectedIndex; //DaoErrMsg Ret = DaoSQL.Instance.SaveMachine(m_ID, tbName.Text, tbLocation.Text.PadLeft(2, '0'), tbMachineNo.Text.ToInt(), IP, tbPort.Text.ToInt(), isEnable, type); DaoErrMsg Ret = DaoSQL.Instance.SaveMachine(m_ID, tbName.Text, tbLocation.Text, tbMachineNo.Text.ToInt(), IP, tbPort.Text.ToInt(), isEnable, type); if (Ret.isError == false) { MessageBoxEx.Show(this, "儲存設備成功", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.Yes; this.Close(); } else { MessageBoxEx.Show(this, string.Format("儲存設備失敗\r\n{0}", Ret.ErrorMsg), "訊息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnSave_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("Type", typeof(string)); dt.Columns.Add("ADDR", typeof(string)); dt.Rows.Add("Local", tbPathBackup.Text); dt.Rows.Add("Server", tbPathServer.Text); dt.Rows.Add("ServerAccount", tbAccount.Text); dt.Rows.Add("ServerPW", tbPW.Text); dt.Rows.Add("Report", tbPathReport.Text); dt.Rows.Add("Database", tbPathDb.Text); DaoErrMsg Msg = DaoSQL.Instance.UpdateBackupInfo(dt); if (Msg.isError == false) { MessageBoxEx.Show(this, "資訊儲存成功.", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 讀取excel文件 /// </summary> /// <param name="filePath">文件路徑</param> private bool ReadFromExcelFile(string filePath) { IWorkbook wk = null; string extension = System.IO.Path.GetExtension(filePath); try { FileStream fs = File.OpenRead(filePath); if (extension.Equals(".xls")) { //把xls文件中的數據寫入wk中 wk = new HSSFWorkbook(fs); } else { //把xlsx文件中的數據寫入wk中 wk = new XSSFWorkbook(fs); } fs.Close(); //讀取當前表數據 ISheet sheet = wk.GetSheetAt(0); //讀取當前行數據,LastRowNum是當前表的總行數-1(注意) IRow row = sheet.GetRow(0); //取得指定標頭的行數;// List <string> CaptureColumnName = new List <string> { "指定序號", "工號", "中文名稱", "英文名稱", "卡號", "別名", "語音", "通訊電話", "行動電話" }; List <int> CaptureNo = new List <int>(); for (int j = 0; j < row.LastCellNum; j++) { ICell value = row.GetCell(j); if (value == null) { continue; } if (CaptureColumnName.Contains(value.ToString())) { CaptureNo.Add(j); } } List <PersonnelContent> Personnel = new List <PersonnelContent>(); string text = string.Empty; for (int i = 1; i <= sheet.LastRowNum; i++) { //讀取當前行數據 row = sheet.GetRow(i); if (row != null) { PersonnelContent content = new PersonnelContent(); //LastCellNum 是當前行的總列數 for (int j = 0; j < row.LastCellNum; j++) { if (CaptureNo.Contains(j) == false) { continue; } ICell value = row.GetCell(j); if (value == null) { continue; } int ContentIndex = CaptureNo.FindIndex(a => a.Equals(j)); switch (ContentIndex) { case 0: content.Key = value.ToString(); break; case 1: content.JobNumber = value.ToString(); break; case 2: content.ChineseName = value.ToString(); break; case 3: content.EnglicshName = value.ToString(); content.Phone = value.ToString(); break; case 4: content.CardNumber = value.ToString(); break; case 5: content.Alias = value.ToString(); break; case 6: content.Voice = value.ToString(); break; case 7: content.TEL = value.ToString(); break; case 8: //content.Phone = value.ToString(); break; } } Personnel.Add(content); } } DaoErrMsg err = DaoSQL.Instance.UpdatePersonnel(Personnel); if (err.isError == true) { return(false); } } catch (Exception e) { MessageBoxEx.Show(this, string.Format("{0}匯入錯誤,{1}", filePath, e.Message), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); }