private void btnTestConnect_Click(object sender, EventArgs e) { DateTime dt = new DateTime(); if (!CheckValue()) { return; } QHKS.TConnInfo connInfo = Pub.ValueToConnInfo(IsBigMac, MacSN, 1, MacConnType, MacIPAddress, MacPort, MacConnPWD, MacPhysicsAddress); DeviceObject.objKS.Init(ref connInfo); this.Enabled = false; bool ret = DeviceObject.objKS.PubTimeGet(ref dt); string msg = DeviceObject.objKS.ErrMsg; if (ret) { msg = msg + "\r\n\r\n" + dt; } if (ret) { Pub.MessageBoxShow(msg, MessageBoxIcon.Information); } else { Pub.ShowErrorMsg(msg); } this.Enabled = true; }
protected void GetMacConnType(string MacSN, ref byte IsBigMac, ref string MacConnType, ref string IP, ref int Port, ref string MacPhysicsAddress, ref string Version) { MacConnType = ""; IP = ""; Port = 0; MacPhysicsAddress = ""; IsBigMac = 0; Version = ""; for (int i = 0; i < dataGrid.RowCount; i++) { if (dataGrid[2, i].Value.ToString() == MacSN) { byte.TryParse(dataGrid[3, i].Value.ToString(), out IsBigMac); MacConnType = dataGrid[5, i].Value.ToString(); IP = dataGrid[6, i].Value.ToString(); int.TryParse(dataGrid[7, i].Value.ToString(), out Port); MacPhysicsAddress = dataGrid[9, i].Value.ToString(); if (dataGrid[12, i].Value != null) { Version = dataGrid[12, i].Value.ToString(); } if (Version == "") { QHKS.TConnInfo connInfo = GetRowConnInfo(i); DeviceObject.objKS.Init(ref connInfo); if (DeviceObject.objKS.SysDeviceInfoGet(ref Version)) { dataGrid[12, i].Value = Version; } } break; } } }
protected QHKS.TConnInfo GetRowConnInfo(int RowIndex) { byte IsBigMac = Convert.ToByte(dataGrid[3, RowIndex].Value); int MacSN = Convert.ToInt32(dataGrid[2, RowIndex].Value.ToString()); byte MacType = Convert.ToByte(GetMacType(dataGrid[2, RowIndex].Value.ToString())); string MacConnType = dataGrid[5, RowIndex].Value.ToString(); string MacIPAddress = dataGrid[6, RowIndex].Value.ToString(); string MacPort = dataGrid[7, RowIndex].Value.ToString(); string MacConnPWD = dataGrid[8, RowIndex].Value.ToString(); string MacPhysicsAddress = dataGrid[9, RowIndex].Value.ToString(); QHKS.TConnInfo connInfo = Pub.ValueToConnInfo(IsBigMac, MacSN, MacType, MacConnType, MacIPAddress, MacPort, MacConnPWD, MacPhysicsAddress); return(connInfo); }
public QHKS.TConnInfo ValueToConnInfo(byte IsBigMac, int MacSN, byte MacType, string MacConnType, string MacIPAddress, string MacPort, string MacConnPWD, string MacPhysicsAddress) { QHKS.TConnInfo connInfo = new QHKS.TConnInfo(); connInfo.IsBigMac = SystemInfo.IsBigMacAdd ? (byte)1 : (byte)0; connInfo.CommPort = ""; connInfo.NetHost = ""; connInfo.Password = 0; if (MacConnType.ToUpper() == MacConnTypeString.USB) { connInfo.ConnType = 0; } else if (MacConnType.ToUpper() == MacConnTypeString.Comm) { connInfo.ConnType = 1; connInfo.CommPort = MacPort; connInfo.CommBaudRate = Convert.ToInt32(MacConnPWD); } else if (MacConnType.ToUpper() == MacConnTypeString.LAN) { connInfo.ConnType = 2; connInfo.NetHost = MacIPAddress; connInfo.NetPort = Convert.ToInt32(MacPort); if (IsNumeric(MacConnPWD)) { connInfo.Password = Convert.ToInt32(MacConnPWD); } } else if (MacConnType.ToUpper() == MacConnTypeString.GPRS) { connInfo.ConnType = 3; connInfo.NetHost = MacIPAddress; connInfo.NetPort = Convert.ToInt32(MacPort); if (IsNumeric(MacConnPWD)) { connInfo.Password = Convert.ToInt32(MacConnPWD); } } connInfo.MacSN = MacSN; connInfo.MacType = MacType; if ((MacType == 32) || (MacType == 33) || (MacType == 34) || (MacType == 35) || (MacType == 36)) { connInfo.MacType = Convert.ToByte(MacType - 30); } connInfo.MacAddress = MacPhysicsAddress; return(connInfo); }
private void btnTestConnect_Click(object sender, EventArgs e) { DateTime dt = new DateTime(); if (!CheckValue()) { return; } byte byt = 0; byte.TryParse(MacType, out byt); if (byt >= 32) { byt = Convert.ToByte(byt - 30); } QHKS.TConnInfo connInfo = Pub.ValueToConnInfo(IsBigMac, MacSN, byt, MacConnType, MacIPAddress, MacPort, MacConnPWD, MacPhysicsAddress); DeviceObject.objKS.Init(ref connInfo); this.Enabled = false; bool ret = DeviceObject.objKS.PubTimeGet(ref dt); string msg = DeviceObject.objKS.ErrMsg; if (ret) { msg = msg + "\r\n\r\n" + dt; } if (ret) { if (connInfo.ConnType != 3) { string SN = ""; if (DeviceObject.objKS.SysGetSN(ref SN)) { MacPhysicsAddress = SN; txtWANAddress.Text = SN; } } Pub.MessageBoxShow(msg, MessageBoxIcon.Information); } else { Pub.ShowErrorMsg(msg); } this.Enabled = true; }
private void button3_Click(object sender, EventArgs e) { msgGrid.Rows.Clear(); if (dlgFolder.ShowDialog() != DialogResult.OK) { return; } string path = dlgFolder.SelectedPath; if (path.Substring(path.Length - 1, 1) != "\\") { path = path + "\\"; } QHKS.TConnInfo connInfo = new QHKS.TConnInfo(); connInfo.MacSN = SystemInfo.IsBigMacAdd ? 65535 : 255; connInfo.MacType = 255; DeviceObject.objKS.Init(ref connInfo); DeviceObject.objKS.InitBlackUSBFile(path); int max = cardGrid.RowCount; int cnt = 0; for (int i = 0; i < max; i++) { if (!Pub.ValueToBool(cardGrid[0, i].Value)) { continue; } DeviceObject.objKS.PubBlackInit(cardGrid[1, i].Value.ToString(), cnt == 0, true); cnt++; } if (cnt == max) { DeviceObject.objKS.PubBlackClearUSB(); } DeviceObject.objKS.PubBlackDataUSB(); string msg = Pub.GetResText(formCode, "MsgCardBlackSuccess", "") + "\r\n\r\n" + path + "Black.dat"; ShowMsg(msg); Pub.MessageBoxShow(msg, MessageBoxIcon.Information); }
private void btnOk_Click(object sender, EventArgs e) { DateTime dt = new DateTime(); if (!db.GetServerDate(ref dt)) { return; } if (!CheckValue()) { return; } byte byt = 0; byte.TryParse(MacType, out byt); if (byt >= 32) { byt = Convert.ToByte(byt - 30); } byte IsBigMac = SystemInfo.IsBigMacAdd ? (byte)1 : (byte)0; QHKS.TConnInfo connInfo = Pub.ValueToConnInfo(IsBigMac, MacSN, byt, MacConnType, MacIPAddress, MacPort, MacConnPWD, MacPhysicsAddress); DeviceObject.objKS.Init(ref connInfo); this.Enabled = false; bool ret = DeviceObject.objKS.PubTimeSet(dt); string msg = btnOk.Text + "\r\n\r\n" + DeviceObject.objKS.ErrMsg; if (ret) { Pub.MessageBoxShow(msg, MessageBoxIcon.Information); } else { Pub.ShowErrorMsg(msg); } this.Enabled = true; }
public void ReadSocketData(string SocketData) { if (SocketData == "") { return; } int MacSN = Convert.ToInt32(SocketData.Substring(10, 2), 16); byte MacType = Convert.ToByte(SocketData.Substring(12, 2), 16); if (MacType != 1) { return; } if (HasWan) { timer1.Enabled = false; } string IP = ""; int Port = 0; string MacConnType = ""; string MacPhysicsAddress = ""; byte IsBigMac = 0; int LogID = 0; bool LogIsExists = true; int logCount = 0; string Version = ""; GetMacConnType(MacSN.ToString(), ref IsBigMac, ref MacConnType, ref IP, ref Port, ref MacPhysicsAddress, ref Version); if (RealList.IndexOf(SocketData) == -1) { LogIsExists = false; RealList.Add(SocketData); while (RealList.Count > maxCount) { RealList.RemoveAt(0); } if (readData.ReadDataReal(SocketData, db, textFormat, MacSN, Version, ref logCount, ref LogID, ShowRealDataProcess)) { for (int i = 0; i < dataGrid.RowCount; i++) { if (dataGrid[2, i].Value.ToString() == MacSN.ToString()) { int DataCount = 0; if (dataGrid[11, i].Value != null) { int.TryParse(dataGrid[11, i].Value.ToString(), out DataCount); } DataCount += logCount; dataGrid[11, i].Value = DataCount; break; } } } } else { readData.ReadDataReal(SocketData, db, textFormat, MacSN, Version, ref logCount, ref LogID, null); } if (!LogIsExists || LogID > 0) { QHKS.TConnInfo connInfo = new QHKS.TConnInfo(); connInfo.ConnType = (byte)(MacConnType == MacConnTypeString.LAN ? 2 : 3); connInfo.MacSN = MacSN; connInfo.IsBigMac = IsBigMac; connInfo.MacType = MacType; connInfo.NetHost = IP; connInfo.NetPort = Port; connInfo.MacAddress = MacPhysicsAddress; DeviceObject.objKS.Init(ref connInfo); DeviceObject.objKS.PubRealOk(LogID); } if (HasWan) { timer1.Enabled = true; } Application.DoEvents(); }
private void btnEdit_Click(object sender, EventArgs e) { if (dataGrid.SelectedRows.Count < 1) { return; } bool ret = false; string errMsg = ""; frmPubFindMacEdit frm = new frmPubFindMacEdit(); frm.NetMask = dataGrid.SelectedRows[0].Cells[6].Value.ToString(); frm.Gateway = dataGrid.SelectedRows[0].Cells[5].Value.ToString(); if (FindType == 0) { if (SystemInfo.IsNewMJ) { UInt32 devSN = Convert.ToUInt32(dataGrid.SelectedRows[0].Cells[1].Value.ToString()); frm.IP = dataGrid.SelectedRows[0].Cells[3].Value.ToString(); frm.Port = Convert.ToInt32(dataGrid.SelectedRows[0].Cells[7].Value.ToString()); if (frm.ShowDialog() != DialogResult.OK) { return; } AccessV2API.TYPE_Network network = new AccessV2API.TYPE_Network(); network.DevAddr = frm.IP; network.DevPort = Convert.ToUInt32(frm.Port); network.GateWay = frm.Gateway; network.NetMask = frm.NetMask; ret = DeviceObject.objMJNew.SetNetwork(devSN, network); } else { QHKS.TMJConnInfo connInfo = new QHKS.TMJConnInfo(); connInfo.ConnType = 1; connInfo.MacSN = dataGrid.SelectedRows[0].Cells[1].Value.ToString(); connInfo.NetHost = dataGrid.SelectedRows[0].Cells[3].Value.ToString(); connInfo.NetPort = Convert.ToInt32(dataGrid.SelectedRows[0].Cells[7].Value.ToString()); connInfo.CardProtocol = SystemInfo.CardProtocol; frm.IP = connInfo.NetHost; frm.Port = connInfo.NetPort; if (frm.ShowDialog() != DialogResult.OK) { return; } DeviceObject.objMJ.Init(ref connInfo); QHKS.TMJFindMacInfo macInfo = new QHKS.TMJFindMacInfo(); macInfo.MacSN = connInfo.MacSN; macInfo.IP = frm.IP; macInfo.NetMask = frm.NetMask; macInfo.Gateway = frm.Gateway; macInfo.Port = frm.Port; ret = DeviceObject.objMJ.NetMacSetInfo(60000, ref macInfo); } } else { QHKS.TConnInfo connInfo = new QHKS.TConnInfo(); connInfo.ConnType = 2; connInfo.MacSN = Convert.ToInt32(dataGrid.SelectedRows[0].Cells[1].Value.ToString()); connInfo.IsBigMac = Convert.ToByte(dataGrid.SelectedRows[0].Cells[2].Value); if (FindType == 1) { connInfo.MacType = 1; } else { string s = dataGrid.SelectedRows[0].Cells[4].Value.ToString(); if (!Pub.IsNumeric(s)) { s = s.Substring(1, 2); } connInfo.MacType = Convert.ToByte(Convert.ToInt32(s) - 30); } connInfo.NetHost = dataGrid.SelectedRows[0].Cells[3].Value.ToString(); connInfo.NetPort = Convert.ToInt32(dataGrid.SelectedRows[0].Cells[7].Value.ToString()); frm.IP = connInfo.NetHost; frm.Port = connInfo.NetPort; if (frm.ShowDialog() != DialogResult.OK) { return; } QHKS.TTCPIPSet ipSet = new QHKS.TTCPIPSet(); ipSet.IP = frm.IP; ipSet.NetMask = frm.NetMask; ipSet.Gateway = frm.Gateway; ipSet.Port = frm.Port; DeviceObject.objKS.Init(ref connInfo); ret = DeviceObject.objKS.PubTCPIPSet(ref ipSet); errMsg = DeviceObject.objKS.ErrMsg; } if (ret) { dataGrid.SelectedRows[0].Cells[3].Value = frm.IP; dataGrid.SelectedRows[0].Cells[6].Value = frm.NetMask; dataGrid.SelectedRows[0].Cells[5].Value = frm.Gateway; dataGrid.SelectedRows[0].Cells[7].Value = frm.Port; Pub.MessageBoxShow(Pub.GetResText(formCode, "Msg001", ""), MessageBoxIcon.Information); } else { Pub.MessageBoxShow(Pub.GetResText(formCode, "Error001", "") + "\r\n\r\n" + errMsg); } }