protected void ButtonOK_Click(object sender, EventArgs e) { bool done = false; StringBuilder stringBuilder = new StringBuilder(); if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { try { MachineBusiness business = new MachineBusiness(); Machine module = business.QueryByGuid(guid); if (module != null) { string currentIp = module.Ip; this.InitializeUpdateModule(module); module.Ip = this.TextBoxIP.Text; module.Netmask = this.TextBoxNetmask.Text; module.Gateway = this.TextBoxGateway.Text; done = business.Update(module); if (done) { stringBuilder.Append("修改检测仪成功!"); string message = string.Empty; MachineSetup setup = new MachineSetup(); message = setup.Ip(module, currentIp); stringBuilder.Append(message); } else { stringBuilder.Append("修改检测仪失败!"); } } else { stringBuilder.Append("检测仪不存在!"); } } catch (Exception exception) { stringBuilder.Append("修改检测仪错误!"); Variable.Logger.Log(exception); } } } this.LabelMessage.Text = stringBuilder.ToString(); this.InitializeBind(); }
protected void ButtonAlarm_Click(object sender, EventArgs e) { if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); if ((value != null) && (!string.IsNullOrEmpty(value.Guid))) { DetectorBusiness detectorBusiness = new DetectorBusiness(); List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid); Random random = new Random(); if ((detectors != null) && (detectors.Count > 0)) { for (int i = 0; i < detectors.Count; i++) { Detector current = detectors[i]; switch (current.DetectorType.Type) { case DetectorTypes.Switch: current.Value = (ushort)random.Next(0, 2); break; case DetectorTypes.DoubleArea: byte valueA = (byte)random.Next(0, byte.MaxValue); byte valueB = (byte)random.Next(0, byte.MaxValue); current.Value = (ushort)((valueA * 0x100) + valueB); break; } } string ipValue = value.Ip; IPAddress ip = IPAddress.Parse(ipValue); IPEndPoint remoteEP = new IPEndPoint(ip, Variable.Port); List<AbstractInstruction> instructions = new List<AbstractInstruction>(); AlarmInstruction instruction = new AlarmInstruction(detectors); instructions.Add(instruction); Terminal.ExecuteInstruction(remoteEP, instructions); } } } } }
protected void ButtonOK_Click(object sender, EventArgs e) { bool done = false; StringBuilder stringBuilder = new StringBuilder(); MachineBusiness business = new MachineBusiness(); if (this.CheckBoxListMachines.Items != null) { List<Machine> machines = new List<Machine>(); for (int i = 0; i < this.CheckBoxListMachines.Items.Count; i++) { if (this.CheckBoxListMachines.Items[i].Selected) { Machine machine = new Machine(); machine.Guid = this.CheckBoxListMachines.Items[i].Value; machines.Add(machine); } } if ((machines != null) && (machines.Count > 0)) { int success = 0; int fail = 0; for (int i = 0; i < machines.Count; i++) { string imageFile = this.MapPath(machines[i].FloorPlanHref); this.UploadFileDelete(imageFile); done = business.Delete(machines[i]); if (done) { success++; } else { fail++; } } stringBuilder.Append(string.Format("删除{0}个检测仪成功!", success)); stringBuilder.Append(string.Format("删除{0}个检测仪失败!", fail)); } } this.LabelMessage.Text = stringBuilder.ToString(); this.InitializeBind(); }
public string Ip(Machine value, string currentIp) { string result = null; StringBuilder stringBuilder = new StringBuilder(); string ipValue = value.Ip; string netmaskValue = value.Netmask; string gatewayValue = value.Gateway; IPAddress ip = IPAddress.Parse(currentIp); IPEndPoint remoteEP = new IPEndPoint(ip, Variable.Port); List<AbstractInstruction> instructions = new List<AbstractInstruction>(); IpInstruction instruction = new IpInstruction(ipValue, netmaskValue, gatewayValue); instructions.Add(instruction); ProcessResult processResult = Terminal.ExecuteInstruction(remoteEP, instructions); if (processResult != null) { stringBuilder.Append(processResult.Message); if (!processResult.Done) { MachineBusiness business = new MachineBusiness(); value.Ip = currentIp; bool done = business.Update(value); if (done) { stringBuilder.Append("恢复检测仪IP地址成功!"); } else { stringBuilder.Append(string.Format("恢复检测仪IP地址失败,请重新设置检测仪IP地址为{0}!", currentIp)); } } } result = stringBuilder.ToString(); return result; }
protected void ButtonOK_Click(object sender, EventArgs e) { StringBuilder stringBuilder = new StringBuilder(); DateTime now = DateTime.Now; DateTime beginDate = new DateTime(now.Year, now.Month, 1); DateTime endDate = beginDate.AddMonths(1).AddSeconds(-1); try { if (!string.IsNullOrEmpty(this.TextBoxBeginDate.Text)) { beginDate = DateTime.Parse(this.TextBoxBeginDate.Text); } if (!string.IsNullOrEmpty(this.TextBoxEndDate.Text)) { endDate = DateTime.Parse(this.TextBoxEndDate.Text); endDate = endDate.AddDays(1).AddSeconds(-1); } } finally { } if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness machineBusiness = new MachineBusiness(); this.Machine = machineBusiness.QueryByGuid(guid); if (this.Machine != null) { if (!string.IsNullOrEmpty(this.Machine.RoomId)) { RoomBusiness roomBusiness = new RoomBusiness(); this.Room = roomBusiness.QueryByGuid(this.Machine.RoomId); } if (!string.IsNullOrEmpty(this.Machine.Guid)) { DetectorBusiness detectorBusiness = new DetectorBusiness(); this.Detectors = detectorBusiness.QueryByMachine(this.Machine.Guid); this.NormalDataCaches = detectorBusiness.QueryNormalDataCacheByMachine(this.Machine.Guid, beginDate, endDate); this.AlarmDataCaches = detectorBusiness.QueryAlarmDataCacheByMachine(this.Machine.Guid, beginDate, endDate); MessageCacheBusiness messageCacheBusiness = new MessageCacheBusiness(); this.MessageCaches = messageCacheBusiness.QueryByMachine(this.Machine.Guid, beginDate, endDate); } } } else { stringBuilder.Append("没有选择检测仪!"); } } this.LabelMessage.Text = stringBuilder.ToString(); }
private void InitializeBindMachine() { if (this.DropDownListCurrentRooms.SelectedValue != null) { MachineBusiness business = new MachineBusiness(); string roomId = this.DropDownListCurrentRooms.SelectedValue; List<Machine> machines = business.QueryByRoom(roomId); Machine emptyMachine = new Machine(); machines.Insert(0, emptyMachine); this.DropDownListMachines.DataSource = machines; this.DropDownListMachines.DataTextField = "Name"; this.DropDownListMachines.DataValueField = "Guid"; this.DropDownListMachines.DataBind(); } }
private void InitializeBindInput() { this.TextBoxIP.Text = string.Empty; this.TextBoxNetmask.Text = string.Empty; this.TextBoxGateway.Text = string.Empty; if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); this.TextBoxIP.Text = value.Ip; this.TextBoxNetmask.Text = value.Netmask; this.TextBoxGateway.Text = value.Gateway; } } }
protected void ButtonOK_Click(object sender, EventArgs e) { bool done = false; StringBuilder stringBuilder = new StringBuilder(); if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { try { MachineBusiness business = new MachineBusiness(); Machine module = business.QueryByGuid(guid); if (module != null) { this.InitializeUpdateModule(module); int intervalValue = int.Parse(this.TextBoxInterval.Text); module.RoomId = this.DropDownListRooms.SelectedValue; module.Name = this.TextBoxName.Text; module.Ip = this.TextBoxIP.Text; module.Interval = intervalValue; module.Mobile = this.TextBoxMobile.Text; Machine machine = business.QueryByNameOrIp(module.Name, module.RoomId, module.Ip); if ((machine == null) || (string.Equals(machine.Guid, module.Guid, StringComparison.CurrentCulture))) { done = business.Update(module); if (done) { stringBuilder.Append("修改检测仪成功!"); machine = business.QueryByNameOrIp(module.Name, module.RoomId, module.Ip); if (machine != null) { string imageFile = this.MapPath(machine.FloorPlanHref); this.UploadFileSave(this.FileUploadFloorPlan, imageFile); string message = string.Empty; MachineSetup setup = new MachineSetup(); // 设置检测仪上传数据时间间隔 message = setup.Interval(machine); stringBuilder.Append(message); // 设置检测仪时间 if (this.RadioButtonListTime.SelectedValue != null) { bool sync = false; try { sync = bool.Parse(this.RadioButtonListTime.SelectedValue); } finally { } if (sync) { message = setup.Time(machine); stringBuilder.Append(message); } } } } else { stringBuilder.Append("修改检测仪失败!"); } } else { stringBuilder.Append("检测仪已经存在(名称或IP地址相同)!"); } } else { stringBuilder.Append("检测仪不存在!"); } } catch (Exception exception) { stringBuilder.Append("修改检测仪错误!"); Variable.Logger.Log(exception); } } } this.LabelMessage.Text = stringBuilder.ToString(); this.InitializeBind(); }
private void InitializeBindInput() { this.RefreshUser(); User sessionUser = this.Session[Constant.SESSION_KEY_USER] as User; this.DropDownListRooms.DataSource = sessionUser.Rooms; this.DropDownListRooms.DataTextField = "Name"; this.DropDownListRooms.DataValueField = "Guid"; this.DropDownListRooms.DataBind(); const string KeyText = "Key"; const string ValueText = "Value"; DataTable dataTable = new DataTable(); dataTable.Columns.Add(KeyText); dataTable.Columns.Add(ValueText); dataTable.Rows.Add(new object[] { "是", true }); dataTable.Rows.Add(new object[] { "否", false }); this.RadioButtonListTime.DataSource = dataTable; this.RadioButtonListTime.DataTextField = KeyText; this.RadioButtonListTime.DataValueField = ValueText; this.RadioButtonListTime.DataBind(); this.TextBoxName.Text = string.Empty; this.TextBoxIP.Text = string.Empty; this.TextBoxInterval.Text = string.Empty; this.TextBoxMobile.Text = string.Empty; this.RadioButtonListTime.SelectedIndex = 0; this.ImageFloorPlan.ImageUrl = string.Empty; if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); this.DropDownListRooms.SelectedValue = value.RoomId; this.TextBoxName.Text = value.Name; this.TextBoxIP.Text = value.Ip; this.TextBoxInterval.Text = value.Interval.ToString(); this.TextBoxMobile.Text = value.Mobile; this.ImageFloorPlan.ImageUrl = value.FloorPlanHref; } } }
private void InitializeBindMachine() { if (this.DropDownListRooms.SelectedValue != null) { MachineBusiness business = new MachineBusiness(); string roomId = this.DropDownListRooms.SelectedValue; List<Machine> machines = business.QueryByRoom(roomId); Machine emptyMachine = new Machine(); machines.Insert(0, emptyMachine); this.DropDownListMachines.DataSource = machines; this.DropDownListMachines.DataTextField = "Name"; this.DropDownListMachines.DataValueField = "Guid"; this.DropDownListMachines.DataBind(); if (!string.IsNullOrEmpty(this.MachineId)) { for (int i = 0; i < machines.Count; i++) { if (string.Equals(this.MachineId, machines[i].Guid, StringComparison.CurrentCultureIgnoreCase)) { this.DropDownListMachines.SelectedValue = this.MachineId; break; } } } } }
private void InitializeBindInput() { if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); if (value != null) { this.RoomId = value.RoomId; this.MachineId = value.Guid; this.ImageFloorPlan.ImageUrl = value.FloorPlanHref; this.ImageFloorPlan.Visible = true; } } } }
protected void ButtonMessage_Click(object sender, EventArgs e) { if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); if ((value != null) && (!string.IsNullOrEmpty(value.Guid))) { DetectorBusiness detectorBusiness = new DetectorBusiness(); List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid); Random random = new Random(); if ((detectors != null) && (detectors.Count > 0)) { int address = random.Next(0, detectors.Count); Detector detector = detectors[address]; bool result = false; int resultRandom = random.Next(0, 2); if (resultRandom == 0) { result = true; } string ipValue = value.Ip; IPAddress ip = IPAddress.Parse(ipValue); IPEndPoint remoteEP = new IPEndPoint(ip, Variable.Port); List<AbstractInstruction> instructions = new List<AbstractInstruction>(); MessageInstruction instruction = new MessageInstruction(detector.DetectorType.Code, result, DateTime.Now); instructions.Add(instruction); Terminal.ExecuteInstruction(remoteEP, instructions); } } } } }
protected void ButtonOK_Click(object sender, EventArgs e) { bool done = false; StringBuilder stringBuilder = new StringBuilder(); if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { try { MachineBusiness business = new MachineBusiness(); Machine module = business.QueryByGuid(guid); if (module != null) { this.InitializeUpdateModule(module); module.Alarm = bool.Parse(this.RadioButtonListMobileAlarm.SelectedValue); module.MobileA = this.TextBoxMobileA.Text; module.MobileB = this.TextBoxMobileB.Text; module.MobileC = this.TextBoxMobileC.Text; done = business.Update(module); if (done) { stringBuilder.Append("修改检测仪成功!"); string message = string.Empty; MachineSetup setup = new MachineSetup(); message = setup.Threshold(module); stringBuilder.Append(message); message = setup.MobileAlarm(module); stringBuilder.Append(message); message = setup.Mobile(module); stringBuilder.Append(message); } else { stringBuilder.Append("修改检测仪失败!"); } } else { stringBuilder.Append("检测仪不存在!"); } } catch (Exception exception) { stringBuilder.Append("修改检测仪错误!"); Variable.Logger.Log(exception); } } } this.LabelMessage.Text = stringBuilder.ToString(); this.InitializeBind(); }
private void InitializeBindInput() { this.GridViewDetectors.DataSource = null; this.GridViewDetectors.DataBind(); this.RadioButtonListMobileAlarm.SelectedValue = false.ToString(); this.TextBoxMobileA.Text = string.Empty; this.TextBoxMobileB.Text = string.Empty; this.TextBoxMobileC.Text = string.Empty; if (this.DropDownListMachines.SelectedValue != null) { string guid = this.DropDownListMachines.SelectedValue; if (!string.IsNullOrEmpty(guid)) { MachineBusiness business = new MachineBusiness(); Machine value = business.QueryByGuid(guid); if ((value != null) && (!string.IsNullOrEmpty(value.Guid))) { DetectorBusiness detectorBusiness = new DetectorBusiness(); List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid); DataTable dataTable = new DataTable(); dataTable.Columns.Add("C1"); dataTable.Columns.Add("C2"); dataTable.Columns.Add("C3"); dataTable.Columns.Add("C4"); dataTable.Columns.Add("C5"); dataTable.Columns.Add("C6"); for (int i = 0; i < detectors.Count; i++) { object[] datas = new object[dataTable.Columns.Count]; datas[0] = detectors[i].Serial; datas[1] = detectors[i].DetectorType.Name; if (detectors[i].DetectorType.Type == Support.Resource.DetectorTypes.Switch) { datas[2] = detectors[i].DetectorType.DescriptionA; datas[3] = detectors[i].DetectorType.DescriptionB; datas[4] = string.Empty; datas[5] = string.Empty; } else { datas[2] = string.Format("{0}阀值下限{1}{2}", detectors[i].DetectorType.DescriptionA, detectors[i].MinimumA, detectors[i].DetectorType.UnitA); datas[3] = string.Format("{0}阀值上限{1}{2}", detectors[i].DetectorType.DescriptionA, detectors[i].MaximumA, detectors[i].DetectorType.UnitA); datas[4] = string.Format("{0}阀值下限{1}{2}", detectors[i].DetectorType.DescriptionB, detectors[i].MinimumB, detectors[i].DetectorType.UnitB); datas[5] = string.Format("{0}阀值上限{1}{2}", detectors[i].DetectorType.DescriptionB, detectors[i].MaximumB, detectors[i].DetectorType.UnitB); } dataTable.Rows.Add(datas); } this.GridViewDetectors.DataSource = dataTable; this.GridViewDetectors.DataBind(); this.RadioButtonListMobileAlarm.SelectedValue = value.Alarm.ToString(); this.TextBoxMobileA.Text = value.MobileA; this.TextBoxMobileB.Text = value.MobileB; this.TextBoxMobileC.Text = value.MobileC; } } } }
protected void ButtonOK_Click(object sender, EventArgs e) { bool done = false; StringBuilder stringBuilder = new StringBuilder(); try { MachineBusiness business = new MachineBusiness(); Machine module = new Machine(); this.InitializeInsertModule(module); int intervalValue = int.Parse(this.TextBoxInterval.Text); module.RoomId = this.DropDownListRooms.SelectedValue; module.Name = this.TextBoxName.Text; module.Ip = this.TextBoxIP.Text; module.Netmask = string.Empty; module.Gateway = string.Empty; module.Mac = string.Empty; module.MobileA = string.Empty; module.MobileB = string.Empty; module.MobileC = string.Empty; module.Alarm = false; module.Interval = intervalValue; module.Mobile = this.TextBoxMobile.Text; Machine machine = business.QueryByNameOrIp(module.Name, module.RoomId, module.Ip); if (machine == null) { done = business.Insert(module); if (done) { stringBuilder.Append("新增检测仪成功!"); machine = business.QueryByNameOrIp(module.Name, module.RoomId, module.Ip); if (machine != null) { string imageFile = this.MapPath(machine.FloorPlanHref); this.UploadFileSave(this.FileUploadFloorPlan, imageFile); string message = string.Empty; MachineSetup setup = new MachineSetup(); // 设置检测仪上传数据时间间隔 message = setup.Interval(machine); stringBuilder.Append(message); // 设置检测仪时间 if (this.RadioButtonListTime.SelectedValue != null) { bool sync = false; try { sync = bool.Parse(this.RadioButtonListTime.SelectedValue); } finally { } if (sync) { message = setup.Time(machine); stringBuilder.Append(message); } } } } else { stringBuilder.Append("新增检测仪失败!"); } } else { stringBuilder.Append("检测仪已经存在(名称或IP地址相同)!"); } } catch (Exception exception) { stringBuilder.Append("新增检测仪错误!"); Variable.Logger.Log(exception); } this.LabelMessage.Text = stringBuilder.ToString(); this.InitializeBind(); }
public override ProcessResult Process(string ip, InstructionTask instructionTask) { ProcessResult result = new ProcessResult(); result.Done = false; result.Message = string.Empty; bool right = true; List<DataCache> dataCaches = new List<DataCache>(); List<Detector> detectors = new List<Detector>(); if ((instructionTask != null) && (instructionTask.Instructions != null) && (instructionTask.Instructions.Count > 0)) { for (int i = 0; i < instructionTask.Instructions.Count; i++) { AlarmInstruction instruction = instructionTask.Instructions[i] as AlarmInstruction; if (instruction == null) { right = false; break; } else { if (instruction.Detectors != null) { for (int j = 0; j < instruction.Detectors.Count; j++) { detectors.Add(instruction.Detectors[j]); } } } } } if (right) { MachineBusiness machineBusiness = new MachineBusiness(); Machine machine = machineBusiness.QueryByIp(ip); if (machine != null) { DetectorBusiness detectorBusiness = new DetectorBusiness(); List<Detector> currentDetectors = detectorBusiness.QueryByMachine(machine.Guid); if ((currentDetectors != null) && (currentDetectors.Count == detectors.Count)) { for (int i = 0; i < detectors.Count; i++) { string userId = this.GetType().Name; DateTime now = DateTime.Now; DataCache dataCache = new DataCache(); dataCache.InsertUserId = ip; dataCache.InsertTime = now; dataCache.UpdateUserId = userId; dataCache.UpdateTime = now; dataCache.Remark = string.Empty; dataCache.Validity = true; dataCache.DetectorId = currentDetectors[i].Guid; byte[] values = BitConverter.GetBytes(detectors[i].Value); Array.Reverse(values); currentDetectors[i].Decode(values); dataCache.Value = currentDetectors[i].Value; dataCache.RefreshTime = now; dataCache.Newest = true; dataCaches.Add(dataCache); } } } DataCacheBusiness dataCacheBusiness = new DataCacheBusiness(); result.Done = dataCacheBusiness.Insert(dataCaches); } return result; }
public override ProcessResult Process(string ip, InstructionTask instructionTask) { ProcessResult result = new ProcessResult(); result.Done = false; result.Message = string.Empty; if ((instructionTask != null) && (instructionTask.Instructions != null) && (instructionTask.Instructions.Count > 0)) { for (int i = 0; i < instructionTask.Instructions.Count; i++) { MessageInstruction instruction = instructionTask.Instructions[i] as MessageInstruction; if (instruction != null) { string userId = this.GetType().Name; DateTime now = DateTime.Now; MessageCache messageCache = new MessageCache(); messageCache.InsertUserId = ip; messageCache.InsertTime = now; messageCache.UpdateUserId = userId; messageCache.UpdateTime = now; messageCache.Remark = string.Empty; messageCache.Validity = true; messageCache.Ip = ip; messageCache.Code = instruction.Code; messageCache.Result = instruction.Result; messageCache.SendTime = instruction.SendTime; MachineBusiness machineBusiness = new MachineBusiness(); Machine machine = machineBusiness.QueryByIp(ip); if (machine != null) { messageCache.MachineId = machine.Guid; } messageCache.RefreshTime = now; MessageCacheBusiness messageCacheBusiness = new MessageCacheBusiness(); result.Done = messageCacheBusiness.Insert(messageCache); } } } return result; }