private void button1_Click(object sender, EventArgs e) { string err = ""; err = getErr(); if (err != "") { MessageBox.Show(err); return; } AppConfig.SaveValue("Config", "IsConfigruation", "1"); AppConfig.SaveValue("Config", "DBName", txtDBName.Text.Trim()); AppConfig.SaveValue("Config", "DBServer", txtDBServer.Text.Trim()); AppConfig.SaveValue("Config", "DBUserName", txtDBUserName.Text.Trim()); AppConfig.SaveValue("Config", "DBPassWd", CryptDes.EncryptDES(txtPassWd.Text, "EncryDes")); AppConfig.SaveValue("LED", "CardType", comboBox2.Text); //卡型号 AppConfig.SaveValue("LED", "ComPort", comboBox1.Text); //串口 AppConfig.SaveValue("LED", "ComBaudRate", txt_ComBaudRate.Text); //波特率 AppConfig.SaveValue("LED", "ComDelay", "1000"); //延时 AppConfig.SaveValue("LED", "LedNum", "0"); AppConfig.SaveValue("LED", "LedWidth", txt_LedWidth.Text); //屏宽 AppConfig.SaveValue("LED", "LedHeight", txt_ledHeght.Text); //屏高 if (radioButton1.Checked) { AppConfig.SaveValue("LED", "LedColor", "1");//双色屏 } if (radioButton2.Checked) { AppConfig.SaveValue("LED", "LedColor", "2");//单色屏 } MessageBox.Show("修改成功,更改后的配置将在系统重启后生效!", "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void btnSave_Click(object sender, EventArgs e) { if (!Regex.IsMatch(this.txtKeyA.Text.Trim(), "[A-Za-z0-9]{6}")) { MessageBox.Show("A密码必须为六位的字母和数字的组合", "天大天科IC卡初始化系统", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Regex.IsMatch(this.txtKeyB.Text.Trim(), "[A-Za-z0-9]{6}")) { MessageBox.Show("B密码必须为六位的字母和数字的组合", "天大天科IC卡初始化系统", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.txtKeyA.Text.Trim() != this.txtKeyAAgain.Text.Trim()) { MessageBox.Show("A密码与确认密码不一致", "天大天科IC卡初始化系统", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.txtKeyB.Text.Trim() != this.txtKeyBAgain.Text.Trim()) { MessageBox.Show("B密码与确认密码不一致", "天大天科IC卡初始化系统", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string strKeyA = CryptDes.ToHex(this.txtKeyA.Text.Trim(), "gb2312", false);; strKeyA = CryptDes.EncryptDES(strKeyA, "EncryDes"); string strA = CryptDes.DecryptDES(strKeyA, "EncryDes"); ini.IniWriteValue("Key", "KeyA", strKeyA); string strKeyB = CryptDes.ToHex(this.txtKeyB.Text.Trim(), "gb2312", false); strKeyB = CryptDes.EncryptDES(strKeyB, "EncryDes"); ini.IniWriteValue("Key", "KeyB", strKeyB); MessageBox.Show("密码设置成功!", "天大天科IC卡初始化系统", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void button1_Click(object sender, EventArgs e) { //保存信息 if (this.txtOperatePassword.Text.Trim() == "") { MessageBox.Show("请输入操作密码!", "天大天科", MessageBoxButtons.AbortRetryIgnore); return; } if (txtOperatePassword.Text == "tdtk") { //config配置 AppConfig.SaveValue("Config", "IsConfigruation", "1"); AppConfig.SaveValue("Config", "DBName", txtDBName.Text.Trim()); AppConfig.SaveValue("Config", "DBServer", txtDBServer.Text.Trim()); AppConfig.SaveValue("Config", "DBUserName", txtDBUserName.Text.Trim()); AppConfig.SaveValue("Config", "DBPassWd", CryptDes.EncryptDES(txtPassWd.Text, "EncryDes")); //led配置 AppConfig.SaveValue("LED", "ISConfigruation", "2"); AppConfig.SaveValue("LED", "ComPort", comboBox1.Text); //串口通讯: 计算机串口号 AppConfig.SaveValue("LED", "Baudrate", txt_ComBaudRate.Text); //波特率串口通讯: 通讯速率 AppConfig.SaveValue("LED", "LedWidth", txt_LedWidth.Text); //区域宽 AppConfig.SaveValue("LED", "LedHeight", txt_ledHeght.Text); //区域高 AppConfig.SaveValue("LED", "CharColor", txt_CharColor.Text); //文字颜色 AppConfig.SaveValue("LED", "Title", this.txtTitle.Text.Trim()); AppConfig.SaveValue("LED", "X", this.txtX.Text.Trim()); AppConfig.SaveValue("LED", "Y", this.txtY.Text.Trim()); //AppConfig.SaveValue("LED","mDevID",textBox2.Text);//通讯设备编号 MessageBox.Show("修改成功,更改后的配置将在系统重启后生效!", "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Information); IsClosed = true; this.Close(); } else { MessageBox.Show("您输入的密码不正确!", "天大天科", MessageBoxButtons.AbortRetryIgnore); } }
public IC_CheckCardNO() { InitializeComponent(); port = Convert.ToInt32(ini.IniReadValue("ICCard", "Port")); baud = Convert.ToInt64(ini.IniReadValue("ICCard", "Baud")); strKeyA = CryptDes.DecryptDES(ini.IniReadValue("Key", "KeyA"), "EncryDes"); strKeyB = CryptDes.DecryptDES(ini.IniReadValue("Key", "KeyB"), "EncryDes"); }
private void Main_Load(object sender, EventArgs e) { //form加载页面时执行 if (AppConfig.ReadValue("Config", "IsConfigruation") == "1" && AppConfig.ReadValue("LED", "ISConfigruation") == "2") { //config配置 txtDBName.Text = AppConfig.ReadValue("Config", "DBName"); txtDBServer.Text = AppConfig.ReadValue("Config", "DBServer"); txtDBUserName.Text = AppConfig.ReadValue("Config", "DBUserName"); txtPassWd.Text = CryptDes.DecryptDES(AppConfig.ReadValue("Config", "DBPassWd"), "EncryDes"); this.Text = this.Text + AppConfig.ReadValue("Config", "Version"); //led配置 ComPort = short.Parse(AppConfig.ReadValue("LED", "ComPort")); //串口通讯: 计算机串口号 comboBox1.Text = ComPort.ToString(); Baudrate = int.Parse(AppConfig.ReadValue("LED", "Baudrate")); //波特率串口通讯: 通讯速率 txt_ComBaudRate.Text = Baudrate.ToString(); LedWidth = short.Parse(AppConfig.ReadValue("LED", "LedWidth")); //区域宽 txt_LedWidth.Text = LedWidth.ToString(); LedHeight = short.Parse(AppConfig.ReadValue("LED", "LedHeight")); //区域高 txt_ledHeght.Text = LedHeight.ToString(); CharColor = short.Parse(AppConfig.ReadValue("LED", "CharColor")); //文字颜色 txt_CharColor.Text = CharColor.ToString(); this.txtTitle.Text = AppConfig.ReadValue("LED", "Title"); //没有报警时显示的标题 this.txtX.Text = AppConfig.ReadValue("LED", "X"); //显示标题的x坐标 this.txtY.Text = AppConfig.ReadValue("LED", "Y"); //显示标题的y坐标 SqlHelp.ConnString = "Data Source=" + txtDBServer.Text + ";Initial Catalog=" + txtDBName.Text + ";User ID=" + txtDBUserName.Text + ";Password="******"数据库配置错误," + exc.Message.ToString(), "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Error); Show(); this.Activate(); } //------------------------------------------------------------------------------------------------ } else { MessageBox.Show("请设置报警系统数据库和LED屏设置", "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Information); Show(); WindowState = FormWindowState.Normal; txtPassWd.Text = ""; txtPassWd.Text = CryptDes.DecryptDES(AppConfig.ReadValue("Config", "DBPassWd"), "EncryDes"); } }
string strOperateType = ""; //操作方式 人工,升序,降序 public IC_Initial() { InitializeComponent(); try { strKeyA = CryptDes.DecryptDES(ini.IniReadValue("Key", "KeyA"), "EncryDes"); strKeyB = CryptDes.DecryptDES(ini.IniReadValue("Key", "KeyB"), "EncryDes"); DbHelperSQL.ComboxBind(this.cbxCoalKind, "TT_CoalKind", "CoalKindName", "CoalKindCode", "1=1", "CoalKindName"); this.lblBeginCardNO.Visible = false; this.txtBeginCardNO.Visible = false; } catch { MessageBox.Show("请确认App.config文件中数据库设置是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Form1_Load(object sender, EventArgs e) { if (AppConfig.ReadValue("Config", "IsConfigruation") == "1") { txtDBName.Text = AppConfig.ReadValue("Config", "DBName"); txtDBServer.Text = AppConfig.ReadValue("Config", "DBServer"); txtDBUserName.Text = AppConfig.ReadValue("Config", "DBUserName"); txtPassWd.Text = CryptDes.DecryptDES(AppConfig.ReadValue("Config", "DBPassWd"), "EncryDes"); this.Text = this.Text + AppConfig.ReadValue("Config", "Version"); CardType = short.Parse(AppConfig.ReadValue("LED", "CardType")); ComPort = short.Parse(AppConfig.ReadValue("LED", "ComPort")); ComBaudRate = int.Parse(AppConfig.ReadValue("LED", "ComBaudRate")); ComDelay = short.Parse(AppConfig.ReadValue("LED", "ComDelay")); LedNum = short.Parse(AppConfig.ReadValue("LED", "LedNum")); LedWidth = short.Parse(AppConfig.ReadValue("LED", "LedWidth")); LedHeight = short.Parse(AppConfig.ReadValue("LED", "LedHeight")); LedColor = short.Parse(AppConfig.ReadValue("LED", "LedColor")); SqlHelp.ConnString = "Data Source=" + txtDBServer.Text + ";Initial Catalog=" + txtDBName.Text + ";User ID=" + txtDBUserName.Text + ";Password="******"Data Source=" + txtDBServer.Text + ";Initial Catalog=" + txtDBName.Text + ";User ID=" + txtDBUserName.Text + ";Password="******"数据库配置错误," + exc.Message.ToString(), "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Error); Show(); this.Activate(); } //------------------------------------------------------------------------------------------------ } else { MessageBox.Show("请设置报警系统数据库和LED屏设置", "循环报警系统", MessageBoxButtons.OK, MessageBoxIcon.Information); Show(); WindowState = FormWindowState.Normal; txtPassWd.Text = ""; txtPassWd.Text = CryptDes.DecryptDES(AppConfig.ReadValue("Config", "DBPassWd"), "EncryDes"); } }
private void timer_start_Tick(object sender, EventArgs e) { ulong ulCardID = 0; int iLen = 0; bool bolExist = false; if ((int)ptr > 0) { int i = RWCard.rf_card(ptr, 1, ref ulCardID); if (i != 0) { lblTips.Text = "请检查读写器上是否有卡!"; return; } else { if (ulCardIDAll == ulCardID) { return; } this.txtCardID.Text = ulCardID.ToString(); if (strOperateType == "") { if (this.txtCardNO.Text.Trim().Length == 0) { this.lblTips.Text = "请输入IC卡号"; return; } return; } bolExist = DbHelperSQL.isExistCardID(ulCardID.ToString(), strType); if (this.txtCardNO.Text.Trim().Length == 0) { this.lblTips.Text = "请输入IC卡号"; return; } else { if (!DbHelperSQL.bolIsNumber(this.txtCardNO.Text.Trim(), iLen)) { this.lblTips.Text = "输入的IC卡号只能为" + iLen.ToString() + "位的数字"; return; } } bool bolExistCardNO = false; if (bolExist) { bolExistCardNO = DbHelperSQL.isExistCardNO(this.txtCardNO.Text.Trim(), ulCardID.ToString(), strType); } else { bolExistCardNO = DbHelperSQL.isExistCardNO(this.txtCardNO.Text.Trim(), "", strType); } if (bolExistCardNO) { lblTips.Text = "您输入的卡号已经存在!"; return; } } if (bolExist) { int iChangePsw = -1; i = RWCard.rf_load_key_hex(ptr, 0, 0, "ffffffffffff"); i = RWCard.rf_load_key_hex(ptr, 4, 0, "ffffffffffff"); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { //加载已存在密码 i = RWCard.rf_card(ptr, 1, ref ulCardID); i = RWCard.rf_load_key_hex(ptr, 0, 0, strKeyA); i = RWCard.rf_load_key_hex(ptr, 4, 0, strKeyB); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { lblTips.Text = "初始化密码验证失败!"; return; } } else { iChangePsw = RWCard.rf_changeb3(ptr, 0, CryptDes.UnHex(strKeyA, "gb2312"), 0, 0, 0, 1, 0, CryptDes.UnHex(strKeyB, "gb2312")); } } else { //DialogResult result = MessageBox.Show("该卡已经初始化过,是否再初始化一遍", "天大天科IC卡初始化系统", MessageBoxButtons.YesNo, MessageBoxIcon.Information); //if (result == DialogResult.Yes) //{ i = RWCard.rf_load_key_hex(ptr, 0, 0, strKeyA); i = RWCard.rf_load_key_hex(ptr, 4, 0, strKeyB); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { lblTips.Text = "密码验证失败!"; return; } //} } ///往第二块写入卡号+卡类型标识(1:标识卡 2:准运卡)+状态(1:正常)+煤种(4位) string str = ""; //要写入第一块的数据 str = this.txtCardNO.Text.Trim() + strType + "1"; if (strType == "1") { str += this.cbxCoalKind.SelectedValue.ToString().PadLeft(4, '0'); } str = str.PadRight(32, '0'); i = RWCard.rf_write_hex(ptr, 1, str); if (i != 0) { lblTips.Text = "IC卡初始化写失败!"; bolW = false; return; } if (bolW) { bolSave = DbHelperSQL.bolInsertInitialCard(this.txtCardNO.Text.Trim(), ulCardID.ToString(), strType); } if (bolW && bolSave) { RWCard.rf_beep(ptr, 20); lblTips.Text = "IC卡初始化成功,请刷另一张卡!"; if (strOperateType == "asc") { this.txtCardNO.Text = (Convert.ToDecimal(this.txtCardNO.Text.Trim()) + 1).ToString(); } else if (strOperateType == "desc") { this.txtCardNO.Text = (Convert.ToDecimal(this.txtCardNO.Text.Trim()) - 1).ToString(); } else if (strOperateType == "") { this.txtCardNO.Text = ""; } ulCardIDAll = ulCardID; } else { lblTips.Text = "IC卡初始化失败,请刷另一张卡!"; } bolW = true; bolSave = true; txtCardNO.Focus(); } }
private void btnSave_Click(object sender, EventArgs e) { if (this.strOperateType != "") { if (this.btnSave.Text == "开始初始化") { if (this.txtBeginCardNO.Text.Trim() == "") { MessageBox.Show("请输入起始卡号!"); return; } int iLen0 = Convert.ToInt32(ini.IniReadValue("ICCard", "CardNoLen")); if (!DbHelperSQL.bolIsNumber(this.txtCardNO.Text.Trim(), iLen0)) { this.lblTips.Text = "起始卡号只能为" + iLen0.ToString() + "位的数字!"; return; } bool bolExistCardNO = DbHelperSQL.isExistCardNO(this.txtBeginCardNO.Text.Trim(), "", strType); if (bolExistCardNO) { MessageBox.Show("您输入的起始卡号已经存在,请重新输入!"); return; } timer_start.Enabled = true; this.btnSave.Text = "结束初始化"; this.txtBeginCardNO.Enabled = false; this.txtCardNO.Enabled = false; } else if (this.btnSave.Text == "结束初始化") { timer_start.Enabled = false; this.btnSave.Text = "开始初始化"; this.txtBeginCardNO.Enabled = true; this.txtCardNO.Enabled = false; } return; } ulong ulCardID = 0; int iLen = 0; bool bolExist = false; if ((int)ptr > 0) { int i = RWCard.rf_card(ptr, 1, ref ulCardID); if (i != 0) { lblTips.Text = "请检查读写器上是否有卡!"; return; } else { bolExist = DbHelperSQL.isExistCardID(ulCardID.ToString(), strType); if (this.txtCardNO.Text.Trim().Length == 0) { this.lblTips.Text = "请输入IC卡号"; return; } else { iLen = Convert.ToInt32(ini.IniReadValue("ICCard", "CardNoLen")); if (!DbHelperSQL.bolIsNumber(this.txtCardNO.Text.Trim(), iLen)) { this.lblTips.Text = "输入的IC卡号只能为" + iLen.ToString() + "位的数字"; return; } } bool bolExistCardNO = false; if (bolExist) { bolExistCardNO = DbHelperSQL.isExistCardNO(this.txtCardNO.Text.Trim(), ulCardID.ToString(), strType); } else { bolExistCardNO = DbHelperSQL.isExistCardNO(this.txtCardNO.Text.Trim(), "", strType); } if (bolExistCardNO) { lblTips.Text = "您输入的卡号已经存在,请重新输入卡号!"; return; } } if (!bolExist) { int iChangePsw = -1; i = RWCard.rf_load_key_hex(ptr, 0, 0, "ffffffffffff"); i = RWCard.rf_load_key_hex(ptr, 4, 0, "ffffffffffff"); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { //加载已存在密码 i = RWCard.rf_card(ptr, 1, ref ulCardID); i = RWCard.rf_load_key_hex(ptr, 0, 0, strKeyA); i = RWCard.rf_load_key_hex(ptr, 4, 0, strKeyB); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { lblTips.Text = "初始化密码验证失败!"; return; } } else { iChangePsw = RWCard.rf_changeb3(ptr, 0, CryptDes.UnHex(strKeyA, "gb2312"), 0, 0, 0, 1, 0, CryptDes.UnHex(strKeyB, "gb2312")); } } else { DialogResult result = MessageBox.Show("该卡已经初始化过,是否再初始化一遍", "天大天科卡初始化系统", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { i = RWCard.rf_load_key_hex(ptr, 0, 0, strKeyA); i = RWCard.rf_load_key_hex(ptr, 4, 0, strKeyA); i = RWCard.rf_authentication(ptr, 0, 0); if (i != 0) { lblTips.Text = "密码验证失败!"; return; } } else { return; } } //往第二块写入卡号+卡类型标识(1:标识卡 2:准运卡)+状态(1:正常) string str = ""; //要写入第一块的数据 str = this.txtCardNO.Text.Trim() + strType + "1"; if (strType == "1") { str += this.cbxCoalKind.SelectedValue.ToString().PadLeft(4, '0'); } str = str.PadRight(32, '0'); i = RWCard.rf_write_hex(ptr, 1, str); if (i != 0) { bolW = false; } if (bolW) { bolSave = DbHelperSQL.bolInsertInitialCard(this.txtCardNO.Text.Trim(), ulCardID.ToString(), strType); } if (bolW && bolSave) { RWCard.rf_beep(ptr, 20); lblTips.Text = "IC卡初始化成功,请刷另一张卡!"; this.txtCardNO.Text = ""; } else { lblTips.Text = "IC卡初始化失败,请刷另一张卡!"; } bolSave = true; bolSave = true; txtCardNO.Focus(); } }