/// <summary> /// 回调方法-配置器当扇区重置返回时 /// </summary> private void SelChsForm_OnChsCleanReponse(uint iCardNo, string strErrInfo) { if (string.IsNullOrEmpty(strErrInfo)) { try { this.Invoke(new EventHandler(delegate { //CMessageBox.ShowSucc(string.Format("恭喜您,扇区重置成功!"), Config.DialogTitle); //字体颜色恢复默认 rbList[_rbInt].ForeColor = Color.Black; _ChsCleanList.Remove(_rbInt); btnChsClean.Text = "扇区选择"; //删除数据库卡片数据 IDAL.ICard objDAL = DALFactory.DALFactory.Card(); IList <CardManage.Model.Card> CleanCard = objDAL.GetListByWhere(1, string.Format("cardno = {0}", iCardNo)); if (CleanCard.Count > 0 && !objDAL.Delete(CleanCard[0].ID)) { CMessageBox.ShowError(string.Format("恭喜您,扇区重置成功,但是删除数据库卡片数据失败!"), Config.DialogTitle); return; } CMessageBox.ShowSucc(string.Format("恭喜您,扇区重置和保存卡片数据到数据库都成功!"), Config.DialogTitle); })); } catch { } } else { CMessageBox.ShowError(string.Format("操作失败,错误原因如下:\r\n{0}", strErrInfo), Config.DialogTitle); } }
protected override void BtnOK_Click(object sender, EventArgs e) { //验证逻辑 string strOldPassword = txtOldPassword.Text; string strNewPassword = txtNewPassword.Text; string strNewConfirmPassword = txtNewConfirmPassword.Text; if (strOldPassword.Equals("") || strNewPassword.Equals("") || strNewConfirmPassword.Equals("")) { CMessageBox.ShowError("旧密码、新密码和确认密码都必须填写!", Config.DialogTitle); txtOldPassword.Focus(); return; } if (!strNewPassword.Equals(strNewConfirmPassword)) { CMessageBox.ShowError("新密码和确认密码不一致,请重新输入!", Config.DialogTitle); txtNewPassword.Focus(); return; } CardManage.IDAL.IUserInfo objUser = CardManage.DALFactory.DALFactory.UserInfo(); bool bIfSucc = objUser.ChangePassword(RunVariable.CurrentUserInfo.ID, Functions.Md5_32(strOldPassword), Functions.Md5_32(strNewPassword), out string strErrorInfo); if (!bIfSucc) { CMessageBox.ShowError(string.Format("对不起,修改密码错误,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle); return; } CMessageBox.ShowSucc("恭喜您,密码修改成功!", Config.DialogTitle); this.DialogResult = DialogResult.OK; }
/// <summary> /// 创建选择的数据 /// </summary> private void DeleteSelectedData(object state) { bool bIfSucc = false; string strErrMessag = "未知错误"; SetButtonEnabled(false); try { if (this._FormIfClose) { return; } Model.SelecedTreeNodeData objSelecedTreeNodeData = (Model.SelecedTreeNodeData)state; if (!(objSelecedTreeNodeData.SelectedDataList == null || objSelecedTreeNodeData.SelectedDataList.Count == 0)) { IDAL.IBuilding objDalBuilding = DALFactory.DALFactory.Building(); IDAL.ISys objDalSys = DALFactory.DALFactory.Sys(); foreach (Model.NodeData objData in objSelecedTreeNodeData.SelectedDataList) { if (objData.Flag.Equals(-1)) { //全部 bIfSucc = objDalSys.DeleteData(0); } else if (objData.Flag >= 0 && objData.Flag <= 3) { bool bSucc = objDalBuilding.Delete(objData.ID); if (bSucc) { bIfSucc = bSucc; } } } } if (bIfSucc) { InitTree(); } } catch (Exception err) { strErrMessag = err.Message; } if (bIfSucc) { RefreshTreeByThread(); } SetButtonEnabled(true); if (bIfSucc) { CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle); //当建筑信息删除时,通知其他已开启的树 Manager.GetInstance().BuildingDataChangeNotice(); } else { CMessageBox.ShowError(string.Format("对不起,删除失败,错误原因:\r\n{0}", strErrMessag), Config.DialogTitle); } }
/// <summary> /// 扇区重置 /// </summary> private void BtnChsClean_Click(object sender, EventArgs e) { string strErrMessage = ""; if (btnChsClean.Text == "扇区选择") { if (MessageBox.Show("更改写入扇区可能导致扇区混乱,确定更改写入扇区吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } //更改写入扇区,并更改配置文件 RunVariable.CurrentSetting.OtherSetting.Chs = _rbInt; if (!SysConfiger.SaveSetting(RunVariable.CurrentSetting, RunVariable.IniPathAndFileName, out strErrMessage)) { CMessageBox.ShowError(string.Format("对不起,保存配置失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle); } else { Manager.GetInstance().SettingChangeNotice(); CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功!"), Config.DialogTitle); } this.btnCancel.PerformClick(); } else { if (CardConfiger.GetInstance().Switch.Equals(ConfigerBase.ESwitch.CLOSE)) { if (MessageBox.Show("制卡串口当前已关闭,请先开启后再重试,确定现在开启吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty); } else { if (MessageBox.Show("当前操作会清除扇区所有数据\n确定现在重置扇区吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } if (!CardConfiger.GetInstance().ChsClean(_rbInt.ToString(), out strErrMessage)) { CMessageBox.ShowError(string.Format("重置扇区失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle); } } } }
/// <summary> /// 删除数据 /// </summary> /// <param name="selectedItems">当前选择的所有项</param> protected override void OnDelete(ListView.SelectedListViewItemCollection selectedItems) { if (MessageBox.Show(string.Format("删除{0}数据的同时会把下属的建筑数据以及卡片信息一起删除,请慎重选择,确定要删除当前选择的{1}数据吗?", this._DataTypeName, this._DataTypeName), Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int iSuccNum = 0; int iFaultNum = 0; foreach (ListViewItem selectedItem in selectedItems) { Building objModel = (Building)selectedItem.Tag; IDAL.IBuilding objDal = DALFactory.DALFactory.Building(); if (objDal.Delete(objModel.ID)) { iSuccNum++; } else { iFaultNum++; } } if (iSuccNum == 0) { CMessageBox.ShowError("对不起,删除失败!", Config.DialogTitle); } else if (iFaultNum == 0) { CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle); } else { CMessageBox.ShowSucc(string.Format("{0}个删除成功,{1}个删除失败", iSuccNum, iFaultNum), Config.DialogTitle); } if (iSuccNum > 0) { //重新刷新列表 BindLVData(0, this.CurrentSqlWhere); //当建筑信息删除时,通知其他已开启的树 Manager.GetInstance().BuildingDataChangeNotice(); } }
/// <summary> /// 删除数据 /// </summary> /// <param name="selectedItems">当前选择的行项</param> protected override void OnDelete(ListView.SelectedListViewItemCollection selectedItems) { if (MessageBox.Show(string.Format("确定要删除当前选择的卡片信息吗?"), Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int iSuccNum = 0; int iFaultNum = 0; foreach (ListViewItem selectedItem in selectedItems) { Card objModel = (Card)selectedItem.Tag; IDAL.ICard objDal = DALFactory.DALFactory.Card(); if (objDal.Delete(objModel.ID)) { iSuccNum++; } else { iFaultNum++; } } if (iSuccNum > 0) { //重新刷新列表 BindLVData(0, this.CurrentSqlWhere); } if (iSuccNum == 0) { CMessageBox.ShowError("对不起,删除失败!", Config.DialogTitle); } else if (iFaultNum == 0) { CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle); } else { CMessageBox.ShowSucc(string.Format("{0}个删除成功,{1}个删除失败", iSuccNum, iFaultNum), Config.DialogTitle); } }
private void BtnCheckDBSetting_Click(object sender, EventArgs e) { DBSetting objDBSetting = GetSettingFromUI(); if (!CheckDBSettings(objDBSetting, out string strErrInfo)) { CMessageBox.ShowError(string.Format("数据库配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); return; } DBLinkTestForm objModal = new DBLinkTestForm(string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDBSetting.DB_IP, "3308", objDBSetting.DB_User, objDBSetting.DB_Password, System.Text.Encoding.Default.HeaderName.ToString(), objDBSetting.DB_Name)); if (objModal.ShowDialog() == DialogResult.OK) { CMessageBox.ShowSucc(string.Format("恭喜您,数据库连接成功!"), Config.DialogTitle); } else if (objModal.ShowDialog() == DialogResult.No) { CMessageBox.ShowError(string.Format("对不起,数据库连接失败!请重新配置软件参数!"), Config.DialogTitle); File.Delete(RunVariable.IniPathAndFileName); } }
/// <summary> /// 创建全部数据 /// </summary> private void DeleteAllData(object state) { bool bIfSucc = false; string strErrMessag = "未知错误"; SetButtonEnabled(false); try { if (this._FormIfClose) { return; } IDAL.ISys objDal = DALFactory.DALFactory.Sys(); bIfSucc = objDal.DeleteData(0); if (bIfSucc) { InitTree(); } } catch (Exception err) { strErrMessag = err.Message; } if (bIfSucc) { RefreshTreeByThread(); } //SetButtonEnabled(true); if (bIfSucc) { CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle); //当建筑信息删除时,通知其他已开启的树 //Manager.GetInstance().BuildingDataChangeNotice(); } else { CMessageBox.ShowError(string.Format("对不起,删除失败,错误原因:\r\n{0}", strErrMessag), Config.DialogTitle); } }
/// <summary> /// 回调方法-配置器当写卡返回时 /// </summary> private void CardViewForm_OnWriteCardReponse(uint iCardNo, string strErrInfo) { if (this._LastCard == null) { return; } if (iCardNo != uint.MaxValue && string.IsNullOrEmpty(strErrInfo)) { try { this.Invoke(new EventHandler(delegate { txtCardNo.Text = iCardNo.ToString(); this._LastCard.CardNo = iCardNo; //保存数据库 IDAL.ICard objDAL = DALFactory.DALFactory.Card(); if (!_UpdateFlag) { int iNewID = objDAL.Add(this._LastCard, out string strErrorInfo); if (iNewID <= 0) { CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle); return; } } else { bool bIfSucc = objDAL.Update(this._LastCard, out string strErrorInfo); if (!bIfSucc) { CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle); return; } } Manager.GetInstance().CardDataChangeNotice(); CMessageBox.ShowSucc(string.Format("恭喜您,写卡和保存卡片数据到数据库都成功!"), Config.DialogTitle); })); }
private void TsbSaveDebugContent_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog() { Filter = " txt files(*.txt)|*.txt", //设置文件类型 RestoreDirectory = true //保存对话框是否记忆上次打开的目录 }; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { StreamWriter aWriter = new StreamWriter(saveFileDialog1.OpenFile()); aWriter.Write(Regex.Replace(this.tbxComunicateData.Text, "\n", "\r\n", RegexOptions.IgnoreCase)); aWriter.Close(); aWriter = null; CMessageBox.ShowSucc("保存文件成功!", Config.DialogTitle); } catch (Exception err) { CMessageBox.ShowError(string.Format("保存文件失败,错误原因:{0}", err), Config.DialogTitle); } } }
protected override void BtnOK_Click(object sender, EventArgs e) { string strSyncTimePL = txtSyncPL.Text.Trim(); if (string.IsNullOrEmpty(strSyncTimePL) || !Functions.IsInt(strSyncTimePL)) { tabControl1.SelectedTab = tabPage4; txtSyncPL.Focus(); CMessageBox.ShowError(string.Format("时间同步频率不能为空,且必须为大于等于1的整数"), Config.DialogTitle); return; } else { int iSyncTimePL = Convert.ToInt32(strSyncTimePL); if (iSyncTimePL < 1) { tabControl1.SelectedTab = tabPage4; txtSyncPL.Focus(); CMessageBox.ShowError(string.Format("时间同步频率必须为大于等于1的整数"), Config.DialogTitle); return; } } string strChs = tBChs.Text.Trim(); if (string.IsNullOrEmpty(strChs) || !Functions.IsInt(strChs)) { tabControl1.SelectedTab = tabPage4; tBChs.Focus(); CMessageBox.ShowError(string.Format("默认扇区不能为空,且必须为大于0小于16的整数"), Config.DialogTitle); return; } else { int iChs = Convert.ToInt32(strChs); if (iChs < 1) { tabControl1.SelectedTab = tabPage4; txtSyncPL.Focus(); CMessageBox.ShowError(string.Format("默认扇区必须为大于0小于16的整数"), Config.DialogTitle); return; } } //验证逻辑 Setting objSetting = GetSettingFromUI(); if (!SysConfiger.CheckSettings(objSetting, out string strErrInfo)) { if (strErrInfo.IndexOf("数据库") >= 0 && strErrInfo.IndexOf("制卡") < 0 && strErrInfo.IndexOf("监控") < 0) { //只有数据库配置错误 tabControl1.SelectedTab = tabPage1; } else if (strErrInfo.IndexOf("制卡") >= 0 && strErrInfo.IndexOf("数据库") < 0 && strErrInfo.IndexOf("监控") < 0) { //只有写卡配置错误 tabControl1.SelectedTab = tabPage2; } else if (strErrInfo.IndexOf("监控") >= 0 && strErrInfo.IndexOf("数据库") < 0 && strErrInfo.IndexOf("制卡") < 0) { //只有写卡配置错误 tabControl1.SelectedTab = tabPage3; } CMessageBox.ShowError(string.Format("配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); } else { if (!SysConfiger.SaveSetting(objSetting, RunVariable.IniPathAndFileName, out strErrInfo)) { CMessageBox.ShowError(string.Format("对不起,保存配置失败,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); } else { if (this._IfLoginBefore) { CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功!"), Config.DialogTitle); } else { Manager.GetInstance().SettingChangeNotice(); CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功,要使数据库的配置生效,必须重新启动系统,数据库以外的配置可即刻生效!"), Config.DialogTitle); } this.DialogResult = DialogResult.OK; } } }
/// <summary> /// 回调方法-配置器当成功打开时 /// </summary> /// <param name="strNotice"></param> private void CardViewForm_OnStartSucc() { ShowComStatus(); CMessageBox.ShowSucc(string.Format("恭喜您,制卡串口开启成功!"), Config.DialogTitle); }
/// <summary> /// 创建楼层房间 /// </summary> private void TaskProcess(object state) { int iSuccNum = 0; int iFaultNum = 0; SetButtonEnabled(false); try { Model.BuidingBatchCondition objCondition = (Model.BuidingBatchCondition)state; if (objCondition != null) { if (!(objCondition.UnitID <= 0 || objCondition.BeginCode >= objCondition.EndCode)) { string strBegin = FormatRoomCode(objCondition.BeginCode); string strEnd = FormatRoomCode(objCondition.EndCode); int iBeginFLoor = Convert.ToInt32(strBegin.Substring(0, 2)); int iEndFLoor = Convert.ToInt32(strEnd.Substring(0, 2)); int iBeginRoom = Convert.ToInt32(strBegin.Substring(2, 2)); int iEndRoom = Convert.ToInt32(strEnd.Substring(2, 2)); IList <Model.Building> listRoom = new List <Model.Building>(); if (iBeginFLoor < iEndFLoor) { for (int f = iBeginFLoor; f <= iEndFLoor; f++) { for (int r = iBeginRoom; r <= iEndRoom; r++) { Model.Building objModel = new Model.Building() { Flag = 3, FID = objCondition.UnitID, ID = 0, BName = BQ2(f) + BQ2(r), Code = f * 100 + r, Contact = "", Tel = "", BuildingSerialNo = "" }; listRoom.Add(objModel); } } } else { for (int r = iBeginRoom; r <= iEndRoom; r++) { Model.Building objModel = new Model.Building() { Flag = 3, FID = objCondition.UnitID, ID = 0, Code = iBeginFLoor * 100 + r }; objModel.BName = FormatRoomCode(objModel.Code); objModel.Contact = ""; objModel.Tel = ""; objModel.BuildingSerialNo = ""; listRoom.Add(objModel); } } string strErrorInfo = ""; if (!(listRoom == null || listRoom.Count == 0)) { IDAL.IBuilding objDAL = DALFactory.DALFactory.Building(); foreach (Model.Building objModel in listRoom) { if (this._FormIfClose) { return; } int iNewID = objDAL.Add(objModel, out strErrorInfo); if (iNewID <= 0) { iFaultNum++; ShowNotice(string.Format("创建楼层房间{0}数据失败,(原因:{1})!", objModel.BName, strErrorInfo)); } else { iSuccNum++; ShowNotice(string.Format("创建楼层房间{0}数据成功!", objModel.BName)); } } } ShowNotice(string.Format("\r\n生成报告:成功数{0},失败数{1},总计:{2}!\r\n\r\n", iSuccNum, iFaultNum, (iSuccNum + iFaultNum))); } } } catch (Exception err) { ShowNotice(string.Format("创建房间数据失败,(原因:{0})!", err.Message)); } SetButtonEnabled(true); if (iSuccNum > 0) { Manager.GetInstance().BuildingDataChangeNotice(); } CMessageBox.ShowSucc("生成结束!", Config.DialogTitle); }
protected override void BtnOK_Click(object sender, EventArgs e) { DBSetting objDBSetting = GetSettingFromUI(); if (!CheckDBSettings(objDBSetting, out string strErrInfo)) { CMessageBox.ShowError(string.Format("数据库配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); return; } Setting objAllSetting = new Setting() { //数据库 DBSetting = objDBSetting, //制卡串口 WriteComProperty = new Classes.ComProperty() }; objAllSetting.WriteComProperty.PortName = ""; objAllSetting.WriteComProperty.BaudRate = 9600; objAllSetting.WriteComProperty.DataBits = 8; objAllSetting.WriteComProperty.StopBits = System.IO.Ports.StopBits.One; objAllSetting.WriteComProperty.Parity = System.IO.Ports.Parity.None; //监控串口 objAllSetting.MonitorComProperty = new Classes.ComProperty() { PortName = "", BaudRate = 19200, DataBits = 8, StopBits = System.IO.Ports.StopBits.One, Parity = System.IO.Ports.Parity.None }; //其他配置 objAllSetting.OtherSetting = new OtherSetting() { SyncTimePL = 10, SyncAuto = 0, Chs = 1 }; if (this._OldSetting != null) { //制卡串口 if (this._OldSetting.WriteComProperty != null) { objAllSetting.WriteComProperty.BaudRate = this._OldSetting.WriteComProperty.BaudRate; objAllSetting.WriteComProperty.DataBits = this._OldSetting.WriteComProperty.DataBits; objAllSetting.WriteComProperty.StopBits = this._OldSetting.WriteComProperty.StopBits; objAllSetting.WriteComProperty.Parity = this._OldSetting.WriteComProperty.Parity; } //监控串口 if (this._OldSetting.MonitorComProperty != null) { objAllSetting.MonitorComProperty.BaudRate = this._OldSetting.MonitorComProperty.BaudRate; objAllSetting.MonitorComProperty.DataBits = this._OldSetting.MonitorComProperty.DataBits; objAllSetting.MonitorComProperty.StopBits = this._OldSetting.MonitorComProperty.StopBits; objAllSetting.MonitorComProperty.Parity = this._OldSetting.MonitorComProperty.Parity; } //其他配置 if (this._OldSetting.OtherSetting != null) { objAllSetting.OtherSetting.SyncTimePL = this._OldSetting.OtherSetting.SyncTimePL; objAllSetting.OtherSetting.SyncAuto = this._OldSetting.OtherSetting.SyncAuto; objAllSetting.OtherSetting.Chs = this._OldSetting.OtherSetting.Chs; } } if (!SysConfiger.SaveSetting(objAllSetting, RunVariable.IniPathAndFileName, out strErrInfo)) { CMessageBox.ShowError(string.Format("对不起,保存数据库配置失败,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle); } else { CMessageBox.ShowSucc(string.Format("恭喜您,保存数据库配置成功!"), Config.DialogTitle); this.DialogResult = DialogResult.OK; } }
private void MDIParent1_Load(object sender, EventArgs e) { //总管理器 Manager.GetInstance().OnSettingChange += new Manager.SettingChangeHandler(OnSettingChange); //配置器 //CardConfiger.GetInstance().OnNotice += new ConfigerBase.NoticeHandler(CardConfiger_OnNotice); CardConfiger.GetInstance().OnStartFault += new ConfigerBase.StartFaultHandler(CardConfiger_OnStartFault); CardConfiger.GetInstance().OnStartSucc += new ConfigerBase.StartSuccHandler(CardConfiger_OnStartSucc); CardConfiger.GetInstance().OnStopFault += new ConfigerBase.StopFaultHandler(CardConfiger_OnStopFault); CardConfiger.GetInstance().OnStopSucc += new ConfigerBase.StopSuccHandler(CardConfiger_OnStopSucc); //监控器 CardMonitor.GetInstance().OnStartFault += new ConfigerBase.StartFaultHandler(CardMonitor_OnStartFault); CardMonitor.GetInstance().OnStartSucc += new ConfigerBase.StartSuccHandler(CardMonitor_OnStartSucc); CardMonitor.GetInstance().OnStopFault += new ConfigerBase.StopFaultHandler(CardMonitor_OnStopFault); CardMonitor.GetInstance().OnStopSucc += new ConfigerBase.StopSuccHandler(CardMonitor_OnStopSucc); this.Hide(); //全局变量初始化 //运行配置 RunVariable.IfDebug = GetDebugStatus();//是否是调试模式,如果是调试模式则在已发送的命令输出区输出指令码 RunVariable.IniPathAndFileName = string.Format("{0}\\{1}", Application.StartupPath, Config.IniFileName); string strErrInfo = ""; bool bIfLoop = true; DialogResult dResult; string strErrMessage = ""; //1.创建数据库或使用现有数据库 //1.判断文件是否在 if (!IOHelper.Exists(RunVariable.IniPathAndFileName)) { dResult = MessageBox.Show("未找到数据库配置文件,进入系统前必须配置好数据库,如需新建数据库请按[是]键,使用现有的数据库请按[否]键,退出系统请按[取消]键?", Config.DialogTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dResult == DialogResult.Yes) { //创建数据库 DBServerSettingForm objModalDBServerForm = new DBServerSettingForm("数据库服务器配置", true, RunVariable.CurrentUserInfo, new WindowSize(365, 288)); dResult = objModalDBServerForm.ShowDialog(); if (dResult == DialogResult.OK) { //连接成功,创建数据库 DBSetting objDBSetting = objModalDBServerForm.GetDBSetting(); if (objDBSetting != null) { string strSqlContent = Properties.Resources.db; DBManager objDM = new DBManager(objDBSetting.DB_IP, objDBSetting.DB_User, objDBSetting.DB_Password); bool bIfCanLink = objDM.CheckCanLink(); if (bIfCanLink) { string strDBName = Config.DefaultDBName; if (!objDM.IsExists(strDBName)) { bool bIfCreateSucc = objDM.CreateBySql(strDBName, strSqlContent, out strErrMessage); if (!bIfCreateSucc) { //退出系统 CMessageBox.ShowError(string.Format("数据库创建失败,请重新开启软件重试,错误原因\r\n{0}", strErrMessage), Config.DialogTitle); bIfLoop = false; Application.Exit(); } else { CMessageBox.ShowSucc("恭喜你,数据库创建成功!", Config.DialogTitle); } } Model.Setting objAllSetting = new Setting(); //数据库 objAllSetting.DBSetting = new DBSetting(); objAllSetting.DBSetting.DB_IP = objDBSetting.DB_IP; objAllSetting.DBSetting.DB_Name = strDBName; objAllSetting.DBSetting.DB_User = objDBSetting.DB_User; objAllSetting.DBSetting.DB_Password = objDBSetting.DB_Password; //制卡串口 objAllSetting.WriteComProperty = new Classes.ComProperty(); objAllSetting.WriteComProperty.BaudRate = 9600; objAllSetting.WriteComProperty.DataBits = 8; objAllSetting.WriteComProperty.StopBits = System.IO.Ports.StopBits.One; objAllSetting.WriteComProperty.Parity = System.IO.Ports.Parity.None; //监控串口 objAllSetting.MonitorComProperty = new Classes.ComProperty(); objAllSetting.MonitorComProperty.BaudRate = 19200; objAllSetting.MonitorComProperty.DataBits = 8; objAllSetting.MonitorComProperty.StopBits = System.IO.Ports.StopBits.One; objAllSetting.MonitorComProperty.Parity = System.IO.Ports.Parity.None; //其他配置 objAllSetting.OtherSetting = new OtherSetting(); objAllSetting.OtherSetting.SyncTimePL = 10; objAllSetting.OtherSetting.Chs = 1; objAllSetting.OtherSetting.SyncAuto = 0; SysConfiger.SaveSetting(objAllSetting, RunVariable.IniPathAndFileName, out strErrMessage); } else { //退出系统 CMessageBox.ShowError("数据库服务器连接失败,请重新开启软件重试!", Config.DialogTitle); bIfLoop = false; Application.Exit(); } } else { //退出系统 bIfLoop = false; Application.Exit(); } } else { //退出系统 bIfLoop = false; Application.Exit(); } } else if (dResult == DialogResult.No) { //使用现有的数据库 //弹出配置串口 DBSettingForm objModalSysForm = new DBSettingForm("数据库设置", true, RunVariable.CurrentUserInfo, new WindowSize(382, 339)); if (objModalSysForm.ShowDialog() != DialogResult.OK) { bIfLoop = false; Application.Exit(); } else { bIfLoop = true; } } else { //退出系统 bIfLoop = false; Application.Exit(); } } //2.加载配置文件 while (bIfLoop) { //2.配置文件载入验证 RunVariable.CurrentSetting = SysConfiger.LoadSetting(RunVariable.IniPathAndFileName, out strErrInfo); if (RunVariable.CurrentSetting == null || !strErrInfo.Equals("")) { CMessageBox.ShowError(string.Format("无法载入系统配置文件,错误信息如下:\r\n{0}", strErrInfo), Config.DialogTitle); bIfLoop = false; Application.Exit(); } //3.数据库连接验证 DBSetting objDb = RunVariable.CurrentSetting.DBSetting; string strConnectStringTest = string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDb.DB_IP, "3308", objDb.DB_User, objDb.DB_Password, Encoding.Default.HeaderName.ToString(), objDb.DB_Name); string strConnectStringReal = string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDb.DB_IP, "3308", objDb.DB_User, objDb.DB_Password, System.Text.Encoding.Default.HeaderName.ToString(), objDb.DB_Name); DBLinkTestForm objDBLinkModal = new DBLinkTestForm(strConnectStringTest); if (objDBLinkModal.ShowDialog() == DialogResult.OK) { //数据库连接成功 RunVariable.ConnectionString = strConnectStringReal; CardManage.DBUtility.DbHelperSQL.connectionString = RunVariable.ConnectionString; LoginForm objLoginForm = new LoginForm("用户登录", true, null, new Model.WindowSize(350, 260)); if (objLoginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { LayoutManager.GetInstance().InitLayout(this); CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty); CardMonitor.GetInstance().Start(RunVariable.CurrentSetting.MonitorComProperty); CardMonitor.GetInstance().SetSyncTimePL(RunVariable.CurrentSetting.OtherSetting.SyncTimePL * 60); CardMonitor.GetInstance().StartTask(RunVariable.CurrentSetting.OtherSetting.SyncAuto); UpdateStatusDesc(); this.Show(); bIfLoop = false; } else { bIfLoop = false; Application.Exit(); } } else if (objDBLinkModal.ShowDialog() == DialogResult.No) { if (MessageBox.Show("数据库连接失败,需要配置好数据库信息才能进入系统,如需马上配置请按[是]键,退出系统请按[否]键?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //弹出配置串口 DBSettingForm objModalSysForm = new DBSettingForm("数据库设置", true, RunVariable.CurrentUserInfo, new WindowSize(382, 339)); if (objModalSysForm.ShowDialog() != DialogResult.OK) { bIfLoop = false; Application.Exit(); } } else { bIfLoop = false; Application.Exit(); } } else { bIfLoop = false; Application.Exit(); } } }