private void btnGetMacSN_Click(object sender, EventArgs e) { if (RegisterInfo.IsValid || RegisterInfo.IsTest) { if (RegisterInfo.EndDate < DateTime.Now) { Pub.MessageBoxShow(RegisterInfo.StateText); return; } } if (!CheckValue()) { return; } TDIConnInfo connInfo = Pub.ValueToDIConnInfo(MacSN, MacSN_GPRS, MacConnType, MacIP, MacPort, MacConnPWD, IsGPRS, MacSeriesTypeId, SeaSeriesPwd, MacSeriesUserName); this.Enabled = false; bool ret = false; string Online = ""; string msg = ""; try { switch (MacSeriesTypeId) { case 2: string syncTime = ""; string url = "http://" + MacIP + "/action/GetSysParam"; ret = DeviceObject.objFK623.POST_GetResponse(url, MacSeriesUserName, SeaSeriesPwd, ref syncTime); if (ret) { if (syncTime != "") { jsonBody <GetSysParam> answer = JsonConvert.DeserializeObject <jsonBody <GetSysParam> >(syncTime); txtMacSN.Text = answer.info.DeviceID.ToString(); Pub.MessageBoxShow(Pub.GetResText("", "MsgReadEndData", "")); Application.DoEvents(); } } else { ret = false; Pub.MessageBoxShow(Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", "")); } break; case 3: string cmd = "GetDeviceInfo"; DeviceCmd getDeviceCmd = new DeviceCmd(cmd); StringBuilder jsonStringBuilder = new StringBuilder(JsonConvert.SerializeObject(getDeviceCmd)); int pwd = 0; int.TryParse(MacConnPWD, out pwd); if (DeviceObject.socKetClient.Open(MacIP, Convert.ToInt32(MacPort), pwd)) { if (DeviceObject.socKetClient.SendData(ref jsonStringBuilder)) { int state = DeviceObject.socKetClient.JsonRecive(jsonStringBuilder); if (state == 0) { _ResultInfo <DeviceInfo> deviceInfo = JsonConvert.DeserializeObject <_ResultInfo <DeviceInfo> >(jsonStringBuilder.ToString()); string deviceId = deviceInfo.result_data.deviceId; string deviceName = deviceInfo.result_data.name; txtMacSN.Text = deviceId; ret = true; Pub.MessageBoxShow(Pub.GetResText("", "MsgReadEndData", "")); } else { ret = false; msg = DeviceObject.socKetClient.GetStarState(state); } } else { ret = false; Pub.MessageBoxShow(Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", "")); } } else { ret = false; Pub.MessageBoxShow(Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", "")); } DeviceObject.socKetClient.Close(); break; } if (ret) { Online = Pub.GetResText(formCode, "Online", ""); SystemInfo.db.ExecSQL(Pub.GetSQL(DBCode.DB_000300, new string[] { "304", Online , "", MacSN_GPRS })); } else { Online = Pub.GetResText(formCode, "Offline", ""); SystemInfo.db.ExecSQL(Pub.GetSQL(DBCode.DB_000300, new string[] { "305", Online, MacSN_GPRS })); } } catch (Exception E) { msg = E.Message; } this.Enabled = true; }
private void btnTestConnect_Click(object sender, EventArgs e) { if (!CheckValue()) { return; } TDIConnInfo connInfo = Pub.ValueToDIConnInfo(MacSN, MacSN_GPRS, MacConnType, MacIP, MacPort, MacConnPWD, IsGPRS, MacSeriesTypeId, SeaSeriesPwd, MacSeriesUserName); this.Enabled = false; string dt = ""; bool ret = false; string msg = ""; string Online = ""; DateTime dTime = new DateTime(); try { switch (MacSeriesTypeId) { case 2: if (RegisterInfo.IsValid || RegisterInfo.IsTest) { if (RegisterInfo.EndDate < DateTime.Now) { Pub.MessageBoxShow(RegisterInfo.StateText); return; } } try { string url = "http://" + MacIP + "/action/GetSysTime"; string syncTime = ""; ret = DeviceObject.objFK623.POST_GetResponse(url, MacSeriesUserName, SeaSeriesPwd, ref syncTime); if (ret) { if (syncTime != "") { jsonBody <SeaSeriesSyncTime> answer = JsonConvert.DeserializeObject <jsonBody <SeaSeriesSyncTime> >(syncTime); msg = Pub.GetResText("", "FK_RUN_SUCCESS", "") + "\r\n\r\n" + answer.info.Year + "-" + answer.info.Month + "-" + answer.info.Day + " " + answer.info.Hour + ":" + answer.info.Minute + ":" + answer.info.Second; FK623Attend.SeaBody = Pub.GetResText("", "FK_RUN_SUCCESS", ""); } else { ret = false; msg = Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", "") + "\r\n\r\n" + DeviceObject.objFK623.SeaBodyStr(); } } else { msg = Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", ""); } } catch (Exception E) { msg = E.Message; } break; case 3: if (RegisterInfo.IsValid || RegisterInfo.IsTest) { if (RegisterInfo.EndDate < DateTime.Now) { Pub.MessageBoxShow(RegisterInfo.StateText); return; } } string cmd = "GetDeviceInfo"; DeviceCmd getDeviceCmd = new DeviceCmd(cmd); StringBuilder jsonStringBuilder = new StringBuilder(JsonConvert.SerializeObject(getDeviceCmd)); int pwd = 0; int.TryParse(MacConnPWD, out pwd); if (DeviceObject.socKetClient.Open(MacIP, Convert.ToInt32(MacPort), pwd)) { if (DeviceObject.socKetClient.SendData(ref jsonStringBuilder)) { int state = DeviceObject.socKetClient.JsonRecive(jsonStringBuilder); if (state == 0) { _ResultInfo <DeviceInfo> deviceInfo = JsonConvert.DeserializeObject <_ResultInfo <DeviceInfo> >(jsonStringBuilder.ToString()); string deviceId = deviceInfo.result_data.deviceId; string deviceName = deviceInfo.result_data.name; ret = true; msg = Pub.GetResText("", "FK_RUN_SUCCESS", "") + "\r\n\r\n" + deviceId + "\r\n\r\n" + deviceName; } else { msg = DeviceObject.socKetClient.GetStarState(state); } } else { ret = false; msg = Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", ""); } } else { ret = false; msg = Pub.GetResText("", "FK_RUNERR_NO_OPEN_COMM", ""); } DeviceObject.socKetClient.Close(); break; default: DeviceObject.objFK623.Close(); DeviceObject.objFK623.InitConn(connInfo); DeviceObject.objFK623.Open(); ret = DeviceObject.objFK623.GetDeviceTime(ref dTime); DeviceObject.objFK623.Close(); if (ret) { dt = dTime.ToString(); } msg = DeviceObject.objFK623.ErrMsg; if (ret) { msg = msg + "\r\n\r\n" + dt; } break; } if (ret) { Online = Pub.GetResText(formCode, "Online", ""); SystemInfo.db.ExecSQL(Pub.GetSQL(DBCode.DB_000300, new string[] { "304", Online , "", MacSN_GPRS })); Pub.MessageBoxShow(msg, MessageBoxIcon.Information); } else { Online = Pub.GetResText(formCode, "Offline", ""); SystemInfo.db.ExecSQL(Pub.GetSQL(DBCode.DB_000300, new string[] { "305", Online, MacSN_GPRS })); Pub.MessageBoxShow(msg); } } catch (Exception E) { Pub.MessageBoxShow(E.Message); } finally { this.Enabled = true; } }