private void CreateFloorTableFiles() { #region 楼层映射表参数属性 iniFileControl ini = new iniFileControl(Application.StartupPath + @"\CloudAdd.ini"); if (ini.ExistINIFile())//验证是否存在文件,存在就读取 { } else { //ini.IniWriteValue("权限标识", "colAuthFlag", ""); //ini.IniWriteValue("按键名称", "colKeyName", ""); //ini.IniWriteValue("实际楼层", "colActualFloor", ""); //ini.IniWriteValue("端子号", "colDevNo", ""); //ini.IniWriteValue("检测楼层", "colDevCheckFloor", ""); ini.IniWriteValue("云服务配置", "地址", "http://smartcard.jia-r.com/smartCard/syncdata/device/elevator/getCloudElevatorList"); ini.IniWriteValue("云楼层对应表配置", "地址", "http://smartcard.jia-r.com/smartCard/syncdata/device/elevator/getElevatorFloorConfig"); } #endregion }
//获取项目编号 private void Btn_ReadcloudFloorTable_GetData_Click(object sender, EventArgs e) { try { if (TextEdit_ProNo.Text.Length < 8) { HintProvider.ShowAutoCloseDialog(null, string.Format("请输入8位项目编号")); return; } //string HttpAddress = "15w07q0502.51mypc.cn:15234/smartCard/syncdata/device/elevator/getCloudElevatorList?";//http地址 string _uSysCode = TextEdit_ProNo.Text;//传递的参数 00000126; //string _sAppKey = ""; DateTime currentTime = System.DateTime.Now; string createTime = currentTime.ToString("yyyyMMddHHmmss"); string _MD5 = "projectId" + createTime + "1177BE55278MMN5412365UHBN85214BE"; string _sSign = Md5Func(_MD5); string postString = "projectId=" + _uSysCode + "&sign=" + _sSign + "&createTime=" + createTime; //传递的参数 00000126 byte[] postData = Encoding.UTF8.GetBytes(postString); //编码 //RunLog.Log("获取项目请求: ccccccccccccc POSTString " + postString); iniFileControl ReadIniConfig = new iniFileControl(Application.StartupPath + @"\CloudAdd.ini"); string socketHttp = ReadIniConfig.IniReadValue("云服务配置", "地址"); //string url = "http://test.smartcard.jia-r.com/smartCard/syncdata/device/elevator/getCloudElevatorList";//地址 string url = socketHttp; WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //采取POST方式 byte[] responseData = webClient.UploadData(url, "POST", postData); //得到返回字符流 string srcString = Encoding.UTF8.GetString(responseData); //解码 //RunLog.Log("接收项目: ccccccccccccc srcString " + srcString); //srcString = CommonUtils.ToHex(srcString, "utf-8", true); //CloudFloorTableBaseInfo FloorTableSerializer = JsonConvert.DeserializeObject<CloudFloorTableBaseInfo>(srcString); //string Test = Md5Func("projectId201903091355181177BE55278MMN5412365UHBN85214BE"); comboBox_FloorName.Items.Clear(); //清空列表 for (int i = 0; i <= 112; i++) { try { string JsonData = cutJson(srcString, "data", i); if (JsonData == null) { return; } CloudFloorTableBaseInfo FloorTable = JsonConvert.DeserializeObject <CloudFloorTableBaseInfo>(JsonData); string f_deviceName = FloorTable.deviceName; f_deviceUnique = FloorTable.deviceUnique; //comboBox_FloorName // 添加项目 comboBox_FloorName.DropDownStyle = ComboBoxStyle.DropDownList; comboBox_FloorName.Items.Add(f_deviceName); //添加list var Listueq = new { ID = i, deviceName = f_deviceName, deviceUnique = f_deviceUnique }; list.Add(Listueq); } catch (Exception ex) { RunLog.Log(ex); } } } catch (Exception elog) { string errMsg = "获取项目编号失败"; HintProvider.ShowAutoCloseDialog(null, string.Format("通讯失败,错误:{0}", errMsg)); RunLog.Log(elog); } //string JsonData = cutJson(srcString, "data", 1); //CloudFloorTableBaseInfo FloorTable = JsonConvert.DeserializeObject<CloudFloorTableBaseInfo>(JsonData); }
private void Btn_ReadcloudFloorTable_OK_Click(object sender, EventArgs e) { try { string devUnique = string.Empty; if (list != null) { foreach (var one in list) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(one); PropertyDescriptor pdID = pdc.Find("deviceUnique", true); string lhcodeunique = pdID.GetValue(one).ToString(); PropertyDescriptor pdDevName = pdc.Find("deviceName", true); string lhcodedeviceName = pdDevName.GetValue(one).ToString(); if (lhcodedeviceName == comboBox_FloorName.Text.ToString()) { devUnique = lhcodeunique; } } } string _uSysCode = devUnique;//传递的参数 0000012610080; DateTime currentTime = System.DateTime.Now; string createTime = currentTime.ToString("yyyyMMddHHmmss"); string _MD5 = "deviceUnique" + createTime + "1177BE55278MMN5412365UHBN85214BE"; string _sSign = Md5Func(_MD5); RunLog.Log("_MD5" + _MD5); string postString = /*"projectId=" + TextEdit_ProNo.Text.ToString() + */ "deviceUnique=" + _uSysCode + "&sign=" + _sSign + "&createTime=" + createTime; //传递的参数 00000126 byte[] postData = Encoding.UTF8.GetBytes(postString); //编码 //RunLog.Log("请求: ccccccccccccc deviceUnique " + _uSysCode); //RunLog.Log("请求: ccccccccccccc POSTString " + postString); iniFileControl ReadIniConfig = new iniFileControl(Application.StartupPath + @"\CloudAdd.ini"); string socketHttp = ReadIniConfig.IniReadValue("云楼层对应表配置", "地址"); //string url = "http://test.smartcard.jia-r.com/smartCard/syncdata/device/elevator/getElevatorFloorConfig";//地址 string url = socketHttp.ToString(); WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //采取POST方式 byte[] responseData = webClient.UploadData(url, "POST", postData); //得到返回字符流 string srcString = Encoding.UTF8.GetString(responseData); //解码 RunLog.Log("1 云接收 :ccccccccccccc srcString " + srcString + "Length = " + srcString.Length); if (srcString.Length == 50) { HintProvider.ShowAutoCloseDialog(null, string.Format("获取楼层映射表异常,请前往物业后台重置。")); this.Close(); return; } ResponseInfo FloorTable = JsonConvert.DeserializeObject <ResponseInfo>(srcString); RunLog.Log("2 云接收 :ccccccccccccc srcString " + srcString); this.Close(); SendCloudFloorHex = FloorTable; // RunLog.Log("Read 实际楼层对比:SendCloudFloorHex ********* :" + FloorTable.data.logicFloor); this.DialogResult = DialogResult.OK; } catch (Exception ex) { string errMsg = "获取楼层对应表失败"; HintProvider.ShowAutoCloseDialog(null, string.Format("通讯失败,错误:{0}", errMsg)); RunLog.Log(ex); } }