private void btnAdd_Click(object sender, EventArgs e) { int num = 0; long value = 0L; int.TryParse(this.txtNumber.Text, out num); long.TryParse(this.ddlStores.SelectedValue, out value); string text = this.txtRemark.Text.Trim(); string text2 = this.ddlStores.SelectedItem.Text; if (num <= 0) { this.ShowMsg("设备数量不能为空,设备数量只能输入正整数型数值!", false); } else if (this.ddlStores.SelectedIndex == 0) { this.ShowMsg("请选择放置的门店!", false); } else if (string.IsNullOrEmpty(text) || text.Length > 15) { this.ShowMsg("备注不能为空,长度必须小于或等于15个字符", false); } else { DeviceApplyResultJson deviceApplyResultJson = WXStoreHelper.ApplyEquipment(num, text, text, value); if (deviceApplyResultJson.errcode.Equals(ReturnCode.请求成功)) { HiCache.Remove("Devices"); this.ShowMsg("新增设备成功", true); } } }
public bool AddDevice(int quantity, string applyReason, string comment = null, long?poiId = null) { DeviceApplyResultJson deviceApplyResultJson = ShakeAroundApi.DeviceApply(_accessToken, quantity, applyReason, comment, poiId, 10000); if (deviceApplyResultJson.errcode != ReturnCode.请求成功) { throw new Exception(deviceApplyResultJson.errmsg); } return(true); }
private YYDevice GetYYDevice(string token, int Times = 0) { //查询是否有申请未返回状态 YYApply YYApply = Entity.YYApply.FirstOrDefault(n => n.State == 1); if (YYApply == null) { string Reason = "新加商店设备"; DeviceApplyResultJson Device = WXAPI.DeviceApply(token, Reason); if (Device.errcode == ReturnCode.请求成功) { YYApply = new YYApply(); YYApply.AddTime = DateTime.Now; YYApply.Reason = Reason; YYApply.ApplyId = Device.data.apply_id.ToString(); YYApply.Num = 50; YYApply.State = 1; if (Device.data.audit_status == 0) { YYApply.State = 0; } Entity.YYApply.AddObject(YYApply); Entity.SaveChanges(); if (Device.data.audit_status == 2) { YYApply.State = 2; } } } if (YYApply.State == 1) { YYApply = GetYYApply(token, YYApply); } if (YYApply.State == 0) { if (Times < 5) { Thread.Sleep(5000); return(GetYYDevice(token, Times++)); } } if (YYApply.State == 2) { int ApplyId = Int32.Parse(YYApply.ApplyId); DeviceSearchResultJson Devices = WXAPI.SearchDeviceByApplyId(token, ApplyId); if (Devices.errcode == ReturnCode.请求成功) { List <DeviceSearch_Data_Devices> DeviceList = Devices.data.devices; foreach (var p in DeviceList) { var minor = p.minor.ToString(); var savedata = this.Entity.YYDevice.FirstOrDefault(o => o.Minor == minor); if (savedata == null) { //设备入库 YYDevice YY = new YYDevice(); YY.DevId = p.device_id.ToString(); YY.UUID = p.uuid; YY.Major = p.major.ToString(); YY.Minor = p.minor.ToString(); YY.UId = 0; YY.PageId = string.Empty; YY.AddTime = DateTime.Now; YY.ActState = 0; YY.State = 1; Entity.YYDevice.AddObject(YY); } } Entity.SaveChanges(); } } YYDevice YYDevice = Entity.YYDevice.FirstOrDefault(n => n.UId == 0 && n.State == 1); return(YYDevice); }