private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("确定" + InfoSys.CardTypeStrRead + InfoSys.MethodOpenCard + "?", InfoSys.CardTypeStrRead + InfoSys.MethodOpenCard, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } pf.BeginLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); if (!CheckValue()) { pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); return; } if (!pf.SeedIC()) { this.lbCardType.Text = InfoSys.StrSeekFailure; pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); return; } this.lbSerialNumber.Text = pf.getSnr().ToString("X"); //保存远程服务器数据库 string str = DataTransfer.OpenCardRead(this.lbSerialNumber.Text, "", "", "0"); JavaScriptObject result = (JavaScriptObject)JavaScriptConvert.DeserializeObject(str); if (!bool.Parse(result["Result"].ToString())) { string txt = result["Message"].ToString(); MessageBox.Show(txt); pf.Log(txt); pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); return; } int mode = 4; //以B密码认证 int sec = 1; //扇区 int block = 0; string key = pf.getKeyA(); //读卡密码 string keyNew = pf.getKeyB(); //读卡密码 string result_WriteIC = ""; string result_AuthIC = ""; //设置扇区1内容 sec = 1; //认证卡密码B result_AuthIC = CardCommon.AuthIC(icdev, mode, sec, key); pf.AuthLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard, sec, result_AuthIC); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块0,数据块0为卡类型(1字节) block = 0; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, (InfoSys.CardTypeRead).PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrRead, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); return; } } else { this.lbState.Text = InfoSys.StrCannotOpen + InfoSys.StrOpenFailure; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); return; } for (int i = 0; i < pf.getSize(); i++) { result_AuthIC = CardCommon.AuthIC(icdev, mode, i, key); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块3,密码eeeeeeeeeeee block = 3; CardCommon.WritePWD(icdev, i, block, keyNew, InfoSys.KeyControl, keyNew); } } SerialNumber_old = ""; this.lbCardType.Text = InfoSys.CardTypeRead; this.lbState.Text = InfoSys.StrOpenSuccess; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrRead, InfoSys.MethodOpenCard); }
private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("确定" + InfoSys.CardTypeStrDevice + InfoSys.MethodOpenCard + "?", InfoSys.CardTypeStrDevice + InfoSys.MethodOpenCard, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } pf.BeginLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); if (!CheckValue()) { pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); return; } if (!pf.SeedIC()) { this.lbCardType.Text = InfoSys.StrSeekFailure; pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); return; } this.lbSerialNumber.Text = pf.getSnr().ToString("X"); //保存远程服务器数据库 string str = DataTransfer.OpenCardDevice(this.lbSerialNumber.Text, AddressCode1, AddressCode2, AddressCode3, YearExploitation, AlertAvailableWater, AlertAvailableElectric, TypeCode, MeterPulse, AlertWaterLevel, StationType, StationCode, Frequency); JavaScriptObject result = (JavaScriptObject)JavaScriptConvert.DeserializeObject(str); if (!bool.Parse(result["Result"].ToString())) { string txt = result["Message"].ToString(); MessageBox.Show(txt); pf.Log(txt); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); return; } int mode = 4; //以B密码认证 int sec = 1; //扇区 int block = 0; string key = pf.getKeyA(); //读卡密码 string keyNew = pf.getKeyB(); //读卡密码 string result_WriteIC = ""; string result_AuthIC = ""; //设置扇区1内容 sec = 1; //认证卡密码B result_AuthIC = CardCommon.AuthIC(icdev, mode, sec, key); pf.AuthLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard, sec, result_AuthIC); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块0,数据块0为卡类型(1字节)、行政区划码(3字节)、镇(乡)村编码(3字节)、测站编码(1字节)、年度可开采水量(4字节)、可用水量提醒值(2字节)、可用水量提醒值(2字节) block = 0; string hex_AddressCode3 = int.Parse(AddressCode3).ToString("X").PadLeft(2, '0'); double d_YearExploitation = Tools.StringToDoubleMultiply10(YearExploitation, 0); string hex_AlertAvailableWater = int.Parse(AlertAvailableWater).ToString("X").PadLeft(4, '0'); string hex_AlertAvailableElectric = int.Parse(AlertAvailableElectric).ToString("X").PadLeft(4, '0'); result_WriteIC = CardCommon.WriteIC(icdev, sec, block, InfoSys.CardTypeDevice + AddressCode1 + AddressCode2 + hex_AddressCode3 + d_YearExploitation.ToString().PadLeft(8, '0') + hex_AlertAvailableWater + hex_AlertAvailableElectric); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrDevice, InfoSys.StrModifyFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodModifyCard); return; } //写数据块1,数据块1为流量计类型(1字节)、电表脉冲数(2字节bcd码)、水位报警值(4字节) block = 1; string hex_TypeCode = int.Parse(TypeCode).ToString("X").PadLeft(2, '0'); double d_AlertWaterLevel = Tools.StringToDoubleMultiply10(AlertWaterLevel, 0); result_WriteIC = CardCommon.WriteIC(icdev, sec, block, (hex_TypeCode + MeterPulse.ToString().PadLeft(4, '0') + d_AlertWaterLevel.ToString().PadLeft(8, '0')).PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrDevice, InfoSys.StrModifyFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodModifyCard); return; } //写数据块2,数据块2为站类型(1字节)、地址码(2字节) block = 2; string hex_StationType = int.Parse(StationType).ToString("X").PadLeft(2, '0'); string hex_StationCode = int.Parse(StationCode).ToString("X").PadLeft(4, '0'); result_WriteIC = CardCommon.WriteIC(icdev, sec, block, (hex_StationType + hex_StationCode).PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrDevice, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); return; } } else { this.lbState.Text = InfoSys.StrCannotOpen + InfoSys.StrOpenFailure; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); return; } for (int i = 0; i < pf.getSize(); i++) { result_AuthIC = CardCommon.AuthIC(icdev, mode, i, key); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块3,密码eeeeeeeeeeee block = 3; CardCommon.WritePWD(icdev, i, block, keyNew, InfoSys.KeyControl, keyNew); } } SerialNumber_old = ""; this.lbCardType.Text = InfoSys.CardTypeDevice; this.lbState.Text = InfoSys.StrOpenSuccess; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrDevice, InfoSys.MethodOpenCard); }
private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("确定" + InfoSys.CardTypeStrNetSet + InfoSys.MethodOpenCard + "?", InfoSys.CardTypeStrNetSet + InfoSys.MethodOpenCard, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } pf.BeginLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); if (!CheckValue()) { pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } if (!pf.SeedIC()) { this.lbCardType.Text = InfoSys.StrSeekFailure; pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } this.lbSerialNumber.Text = pf.getSnr().ToString("X"); //保存远程服务器数据库 string str = DataTransfer.OpenCardNetSet(this.lbSerialNumber.Text, IP, Port, IsDomain, APN, UserName, Password); JavaScriptObject result = (JavaScriptObject)JavaScriptConvert.DeserializeObject(str); if (!bool.Parse(result["Result"].ToString())) { string txt = result["Message"].ToString(); MessageBox.Show(txt); pf.Log(txt); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } int mode = 4; //以B密码认证 int sec = 1; //扇区 int block = 0; string key = pf.getKeyA(); //读卡密码 string keyNew = pf.getKeyB(); //读卡密码 string result_WriteIC = ""; string result_AuthIC = ""; string hex_IP = HexStringUtility.StrToHexString(IP); string hex_Port = HexStringUtility.StrToHexString(Port); string hex_APN = HexStringUtility.StrToHexString(APN); string hex_UserName = HexStringUtility.StrToHexString(UserName); string hex_Password = HexStringUtility.StrToHexString(Password); string len_IP = (hex_IP.Length / 2).ToString("X").PadLeft(2, '0'); string len_Port = (hex_Port.Length / 2).ToString("X").PadLeft(2, '0'); string len_APN = (hex_APN.Length / 2).ToString("X").PadLeft(2, '0'); string len_UserName = (hex_UserName.Length / 2).ToString("X").PadLeft(2, '0'); string len_Password = (hex_Password.Length / 2).ToString("X").PadLeft(2, '0'); //设置扇区1内容 sec = 1; //认证卡密码B result_AuthIC = CardCommon.AuthIC(icdev, mode, sec, key); pf.AuthLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard, sec, result_AuthIC); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块0,数据块0为卡类型(1字节)、是否域名访问(1字节)、有效IP地址长度(1字节)、有效端口号长度(1字节) //APN名称长度(1字节)、APN用户名长度(1字节)、APN密码长度(1字节) block = 0; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, (InfoSys.CardTypeNetSet + IsDomain + len_IP + len_Port + len_APN + len_UserName + len_Password).PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } //写数据块1,IP地址或域名地址 block = 1; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, hex_IP.PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } //写数据块2,端口号(5字节) block = 2; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, hex_Port.PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } } else { this.lbState.Text = InfoSys.StrCannotOpen + InfoSys.StrOpenFailure; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } //设置扇区2内容 sec = 2; //认证卡密码B result_AuthIC = CardCommon.AuthIC(icdev, mode, sec, key); pf.AuthLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard, sec, result_AuthIC); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块0,APN名称 block = 0; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, hex_APN.PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } //写数据块1,用户名 block = 1; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, hex_UserName.PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } //写数据块2,密码 block = 2; result_WriteIC = CardCommon.WriteIC(icdev, sec, block, hex_Password.PadRight(32, '0')); if (result_WriteIC != "") { this.lbState.Text = InfoSys.InfoWriteFailure(sec, block, InfoSys.CardTypeStrNetSet, InfoSys.StrOpenFailure); pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); return; } } for (int i = 0; i < pf.getSize(); i++) { result_AuthIC = CardCommon.AuthIC(icdev, mode, i, key); if (result_AuthIC == InfoSys.StrAuthSuccess) { //写数据块3,密码eeeeeeeeeeee block = 3; CardCommon.WritePWD(icdev, i, block, keyNew, InfoSys.KeyControl, keyNew); } } SerialNumber_old = ""; this.lbCardType.Text = InfoSys.CardTypeNetSet; this.lbState.Text = InfoSys.StrOpenSuccess; pf.Log(this.lbState.Text); pf.EndLog(InfoSys.CardTypeStrNetSet, InfoSys.MethodOpenCard); }