private void button2_Click(object sender, EventArgs e) { if (this.comboBox1.SelectedIndex < 1) { SafeSetText(textBox2, "请选择一个终端", false); setAllButtonEnable(true); return; } string deviceNo = this.comboBox1.Text.ToString().Trim(); Device device = DeviceModule.GetDeviceByFullDeviceNo(deviceNo); string resDeviceNo = DeviceModule.GetDeviceNoMain(deviceNo); Device resDevice = DeviceModule.GetDeviceByFullDeviceNo(resDeviceNo); if (resDeviceNo.Length != 15) { SafeSetText(textBox2, "终端编号错误!" + resDeviceNo, false); setAllButtonEnable(true); return; } CmdToDtuClosePump cmd6 = new CmdToDtuClosePump(); cmd6.AddressField = DeviceModule.DeviceNo_Normal2Hex(deviceNo); cmd6.StationType = (byte)device.StationType; cmd6.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd6.RawDataChar = cmd6.WriteMsg(dateTimePicker1.Value); cmd6.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd6.RawDataChar); this.textBox2.Text = cmd6.RawDataStr; }
private bool CheckSerialPort() { using (DeviceModule device = new DeviceModule()) { return(device.GetRFIDDevice().Where(x => x.Port == txtComPort.Text).FirstOrDefault() == null ? true : false); } }
public void initDataGridView() { try { IList <Device> deviceList = DeviceModule.GetAllDevice(); if (this.deviceLists == null || this.deviceLists.Count != deviceList.Count) { this.deviceLists = deviceList; //防止界面表格重复添加数据 if (this.deviceListsDataGridView != null && this.deviceListsDataGridView.Rows != null) { this.deviceListsDataGridView.Rows.Clear(); } initData(deviceList); } } catch (Exception e) { if (showErrorLog) { string error = string.Format("在初始化datagride,读取数据库时出错,错误信息{0}", e.Message); logHelper.Error(error); } } finally { } }
private JavaScriptObject getDeviceNo(HttpRequest request) { string DeviceNo = request["DeviceNo"] ?? ""; JavaScriptObject result = new JavaScriptObject(); result.Add("Result", false); result.Add("Message", ""); try { Device device = DeviceModule.GetDeviceByFullDeviceNo(DeviceNo); if (device != null) { result["Result"] = true; result["Message"] = "设备已存在"; } else { result["Message"] = "设备不存在"; } } catch (Exception exception) { result["Message"] = exception.Message; myLogger.Error(exception.Message); } return(result); }
void Save() { if (SystemProperties.ShowMessage.MessageQuestion(SystemProperties.MessageNotification.YouWantToSave, "Device Config") == DialogResult.Yes) { if (CheckSerialPort()) { if (!string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtComPort.Text) && !string.IsNullOrWhiteSpace(txtBaundRate.Text) && !string.IsNullOrWhiteSpace(txtDataBits.Text) && !string.IsNullOrWhiteSpace(cmbParity.Text) && !string.IsNullOrWhiteSpace(cmbStopBits.Text)) { using (DeviceModule device = new DeviceModule()) { device.Save(SetDeviceConfig(false), ref MsgReturned); SystemProperties.ShowMessage.MessageInformation(MsgReturned, "Device Config"); SystemProperties.Cleared(this, false, true, true); } } else { SystemProperties.ShowMessage.MessageError(SystemProperties.MessageNotification.CheckInput + Environment.NewLine + Environment.NewLine + "Devie Name" + Environment.NewLine + "Port" + Environment.NewLine + "Baund Rate" + Environment.NewLine + "Data Bits" + Environment.NewLine + "Stop Bits" + Environment.NewLine + "Parity", "Device Config"); } } else { SystemProperties.ShowMessage.MessageError("Device Serial port is already exists " + Environment.NewLine + "Serial port: " + txtComPort.Text, "Device Config"); } } LoadDevice(); }
private JavaScriptObject CardUserWaterLog(HttpRequest request) { string SerialNumber = request["SerialNumber"] ?? ""; string UserNo = request["UserNo"] ?? ""; string DeviceNo = request["DeviceNo"] ?? ""; string StartTime = request["StartTime"] ?? ""; string StartResidualWater = request["StartResidualWater"] ?? ""; string StartResidualElectric = request["StartResidualElectric"] ?? ""; string EndTime = request["EndTime"] ?? ""; string EndResidualWater = request["EndResidualWater"] ?? ""; string EndResidualElectric = request["EndResidualElectric"] ?? ""; JavaScriptObject result = new JavaScriptObject(); result.Add("Result", false); result.Add("Message", ""); try { CardUser cu = CardUserModule.GetCardUserBySerialNumber(SerialNumber); if (cu == null) { result["Message"] = "卡序列号" + SerialNumber + "的用水户不存在!"; return(result); } Device device = DeviceModule.GetDeviceByFullDeviceNo(DeviceNo); if (device == null) { result["Message"] = "设备长编号" + DeviceNo + "不存在!"; return(result); } CardUserWaterLog cuwLog = new CardUserWaterLog(); cuwLog.SerialNumber = SerialNumber; cuwLog.WateUserId = cu.WaterUserId; cuwLog.UserNo = UserNo; cuwLog.DeviceId = device.Id; cuwLog.DeviceNo = DeviceNo; cuwLog.StartTime = DateTime.Parse(StartTime); cuwLog.StartResidualWater = decimal.Parse(StartResidualWater); cuwLog.StartResidualElectric = decimal.Parse(StartResidualElectric); cuwLog.EndTime = DateTime.Parse(EndTime); cuwLog.EndResidualWater = decimal.Parse(EndResidualWater); cuwLog.EndResidualElectric = decimal.Parse(EndResidualElectric); cuwLog.WaterUsed = decimal.Parse(EndResidualWater) - decimal.Parse(StartResidualWater); cuwLog.ElectricUsed = decimal.Parse(EndResidualElectric) - decimal.Parse(StartResidualElectric); cuwLog.Duration = Convert.ToDecimal((DateTime.Parse(EndTime) - DateTime.Parse(StartTime)).TotalSeconds); CardUserWaterLogModule.AddCardUserWaterLog(cuwLog); result["Result"] = true; } catch (Exception ex) { result["Message"] = "用户用水保存出错!"; myLogger.Error(ex.Message); } return(result); }
void DeleteRoomDevice(string RoomCodes) { T_RoomDevie RD = new T_RoomDevie(); RD.RoomCode = RoomCodes; using (DeviceModule DM = new DeviceModule()) { DM.Delete(RD); } }
void GetRoomDevice(string RoomCodes) { using (DeviceModule DM = new DeviceModule()) { var value = DM.GetDeviceAvailable().Where(x => x.RoomCode == RoomCodes).FirstOrDefault(); if (value != null) { COMSerial = value.SerialPort; DeviceName = value.DeviceName; txtDeviceDescription.Text = value.DeviceCode; } } }
public string GetDeviceNodeInfosByMnId(string loginIdentifer, string mnID, bool isRecursive, bool isExport) { JavaScriptObject obj2 = new JavaScriptObject(); JavaScriptArray array = new JavaScriptArray(); obj2.Add("Result", false); obj2.Add("Message", ""); obj2.Add("DeviceNodes", array); obj2.Add("ExcelURL", ""); LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if (loginUser == null) { obj2["Message"] = "未登录"; return(JavaScriptConvert.SerializeObject(obj2)); } if (loginUser.LoginTimeout) { obj2["Message"] = "登录超时"; return(JavaScriptConvert.SerializeObject(obj2)); } loginUser.LastOperateTime = DateTime.Now; CommonUtil.WaitMainLibInit(); if (DistrictModule.ReturnDistrictInfo(long.Parse(mnID)) == null) { obj2["Message"] = "noExiste"; } else { Device node = null; List <long> allDevicesForManageID = null; if (isRecursive) { allDevicesForManageID = DeviceModule.GetAllDevicesForManageID(long.Parse(mnID)); } else { allDevicesForManageID = DeviceModule.GetDevicesForManageID(long.Parse(mnID)); } for (int i = 0; i < allDevicesForManageID.Count; i++) { node = DeviceModule.GetDeviceByID(allDevicesForManageID[i]); if (node != null) { array.Add(this.DeviceNodeToJson(node)); } } obj2["Result"] = true; } return(JavaScriptConvert.SerializeObject(obj2)); }
public string GetDeviceList(string loginIdentifer, string LoginAddress, string deviceNo) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); JavaScriptArray objList = new JavaScriptArray(); obj2.Add("List", objList); LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if (loginUser == null) { obj2["Message"] = "未登录"; return(JavaScriptConvert.SerializeObject(obj2)); } if (loginUser.LoginTimeout) { obj2["Message"] = "登录超时"; return(JavaScriptConvert.SerializeObject(obj2)); } loginUser.LastOperateTime = DateTime.Now; SysUser user = SysUserModule.GetUser(loginUser.UserId); if (user != null) { List <long> list_DistrictID = DistrictModule.GetAllDistrictID(user.DistrictId); List <Device> list_Device = DeviceModule.GetAllDevice(); foreach (Device device in list_Device) { if (list_DistrictID.Contains(device.DistrictId)) { if (deviceNo == "" || DeviceModule.GetFullDeviceNoByID(device.Id).Contains(deviceNo)) { objList.Add(DeviceNodeToJson(device)); } } } obj2["Result"] = true; obj2["Message"] = ""; } else { obj2["Message"] = "未查找到用户"; } return(JavaScriptConvert.SerializeObject(obj2)); }
private JavaScriptObject ClosePumpCmd(HttpRequest request) { string DeviceNo = request["DeviceNo"] ?? ""; string SendTime = request["SendTime"] ?? ""; JavaScriptObject result = new JavaScriptObject(); result.Add("Result", false); result.Add("Message", ""); try { DateTime OperationTime = DateTime.Parse(SendTime); CmdToDtuClosePump cmd = new CmdToDtuClosePump(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); byte[] bs = cmd.WriteMsg(OperationTime); string str = HexStringUtility.ByteArrayToHexString(bs); Device device = DeviceModule.GetDeviceByFullDeviceNo(DeviceNo); if (device == null) { result["Message"] = "设备长编号" + DeviceNo + "不存在!"; } else { DeviceOperation op = new DeviceOperation(); op.DeviceNo = DeviceNo; op.DeviceName = device.DeviceName; op.OperationTime = OperationTime; op.OperationType = "远程关泵"; op.RawData = str; op.Remark = ""; op.UserId = 0; op.UserName = "******"; op.State = "发送成功"; DeviceOperationModule.AddDeviceOperation(op); result["Result"] = true; } } catch (Exception ex) { result["Message"] = "关泵命令保存出错!"; myLogger.Error(ex.Message); } return(result); }
private void button3_Click(object sender, EventArgs e) { this.label9.Text = ""; try { DeviceModule.LoadDevices(); this.label6.Text = DeviceModule.GetAllDevice().Count.ToString(); this.label9.ForeColor = Color.Green; this.label9.Text = "更新成功"; } catch { this.label9.ForeColor = Color.Red; this.label9.Text = "更新失败"; } }
void LoadDevice() { dgDevice.Rows.Clear(); int i = 1; using (DeviceModule _maintain = new DeviceModule()) { _maintain.GetRFIDDevice().OrderBy(y => y.DeviceName).ToList().ForEach(x => { dgDevice.Rows.Add(x.ID, i, x.DeviceName, x.Port, x.BaundRate, x.DataBit, x.Parity, x.StopBit, x.Active); i++; }); } ObjEnable(false); dgDevice.Enabled = true; }
void SaveRoomDevice() { T_RoomDevie RD = new T_RoomDevie(); RD.RoomCode = txtRoomCode.Text; RD.RoomType = txtDescription.Text; RD.DeviceCode = txtDeviceDescription.Text; RD.DeviceName = DeviceName; RD.SerialPort = COMSerial; using (DeviceModule device = new DeviceModule()) { if (device.Save(RD, ref MsgReturned)) { SystemProperties.ShowMessage.MessageError(MsgReturned, "Room and device"); } } }
void LoadDeviceAvailable() { dgDeviceRecord.Rows.Clear(); int i = 1; using (DeviceModule device = new DeviceModule()) { device.GetRFIDDevice().ForEach(x => { var yy = device.GetDeviceAvailable().Where(A => A.SerialPort == x.Port).FirstOrDefault(); if (yy == null) { dgDeviceRecord.Rows.Add(i, x.DeviceName, x.Port); i++; } }); } }
//启动时,设备全部显示离线 #region 2015-8-7 每次启动时,将登陆状态置为0 void installDeviceState() { try { BaseModule.LoadBaseInfo(); CardUserModule.LoadCardUsers(); DistrictModule.UpdateLevelInfo(); DistrictModule.UpdateDistrictInfo(); //将在线状态置为0 DeviceModule.SetOnline0(); DeviceModule.LoadDevices(); /* * IList<Device> deviceList = DeviceModule.GetAllDevice(); * * foreach (Device d in deviceList) * { * if (d.Online == 1) * { * d.Online = 0; * DeviceModule.ModifyDevice(d); * } * } * */ AlarmService.Init(); int alarmCount = AlarmService.GetCount(); //logHelper.Info("程序启动报警数量为:" + alarmCount); ShowLogData.add("程序启动报警数量为:" + alarmCount); } catch (Exception e) { if (showErrorLog) { string error = string.Format("在将设备登陆状态置为0时,读取数据库时出错,错误信息{0}", e.Message); logHelper.Error(error); } } finally { } }
void Delete() { if (SystemProperties.ShowMessage.MessageQuestion(SystemProperties.MessageNotification.YouWantToDelete, "Device Config") == DialogResult.Yes) { if (!string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtComPort.Text) && !string.IsNullOrWhiteSpace(txtBaundRate.Text) && !string.IsNullOrWhiteSpace(txtDataBits.Text) && !string.IsNullOrWhiteSpace(cmbParity.Text) && !string.IsNullOrWhiteSpace(cmbStopBits.Text)) { using (DeviceModule device = new DeviceModule()) { device.Delete(SetDeviceConfig(true), ref MsgReturned); SystemProperties.ShowMessage.MessageInformation(MsgReturned, "Device Config"); } } else { SystemProperties.ShowMessage.MessageError(SystemProperties.MessageNotification.SelectFirst + " delete", "Device Config"); } } LoadDevice(); }
private void Refresh() { int i = 0; while (!isClose) { i++; if (i == 2 * 10) { WaterUserModule.LoadWaterUsers(); CardUserModule.LoadCardUsers(); i = 0; } DeviceModule.LoadDevices(); //间隔30秒 Thread.Sleep(30 * 1000); } }
void dgDevice_CellClick(object sender, DataGridViewCellEventArgs e) { using (DeviceModule device = new DeviceModule()) { var value = device.GetRFIDDevice().Where(x => x.ID == Convert.ToInt64(dgDevice.SelectedRows[0].Cells[0].Value)).FirstOrDefault(); if (value != null) { txtName.Text = value.DeviceName; txtBaundRate.Text = value.BaundRate.ToString(); txtComPort.Text = value.Port; txtDataBits.Text = value.DataBit.ToString(); cmbParity.Text = value.Parity; cmbStopBits.Text = value.StopBit; cbActive.Checked = value.Active.Value; btnEdit = SystemProperties.BtnProperties(btnEdit, true, Imagename.Edit.ToString(), Imagename._edit.ToString()); btnDelete = SystemProperties.BtnProperties(btnDelete, true, Imagename.Delete.ToString(), Imagename._delete.ToString()); } } }
private JavaScriptObject DeviceNodeToJson(Device device) { JavaScriptObject obj = new JavaScriptObject(); obj["Id"] = device.Id; obj["SimNo"] = device.SimNo; obj["Name"] = device.DeviceName; obj["SDate"] = device.SetupDate.ToString("yyyy-MM-dd HH:mm"); obj["Add"] = device.SetupAddress; obj["LON"] = device.LON / 1000000.0; obj["LAT"] = device.LAT / 1000000.0; string districtName = DistrictModule.GetDistrictName(device.DistrictId); if (districtName != null) { obj.Add("Dist", districtName); } else { obj.Add("Dist", "未知"); } obj["DevNo"] = device.DeviceNo; obj["DevNoF"] = DeviceModule.GetFullDeviceNoByID(device.Id); obj["OL"] = device.Online; obj["OLT"] = device.OnlineTime.ToString("yyyy-MM-dd HH:mm:ss"); switch (device.StationType) { case 0: obj["STT"] = "单站"; break; case 1: obj["STT"] = "主站"; break; case 2: obj["STT"] = "从站"; break; default: obj["STT"] = "单站"; break; } obj["DevT"] = device.DeviceType; obj["RSN"] = device.RemoteStation; return(obj); }
private JavaScriptObject getAllDeviceNo(HttpRequest request) { JavaScriptObject result = new JavaScriptObject(); result.Add("Result", false); result.Add("Message", ""); try { List <string> list = DeviceModule.GetAllDeviceNo(); result["Result"] = true; result["Message"] = string.Join(",", list.ToArray()); } catch (Exception exception) { result["Message"] = exception.Message; myLogger.Error(exception.Message); } return(result); }
private void init() { SafeSetLabel(this.label6, "", false); SafeSetLabel(this.label7, "", false); this.comboBox1.Items.Clear(); this.comboBox1.Items.Add("-请选择-"); if (DeviceModule.GetAllDevice() == null || DeviceModule.GetAllDevice().Count == 0) { DistrictModule.UpdateLevelInfo(); DistrictModule.UpdateDistrictInfo(); DeviceModule.LoadDevices(); } List <string> list = Module.DeviceModule.GetAllDeviceNo(); foreach (string deviceNo in list) { this.comboBox1.Items.Add(deviceNo); } this.comboBox1.SelectedIndex = 0; }
public string DeleteMangeNode(string loginIdentifer, string managerId) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if (loginUser == null) { obj2["Message"] = "未登录"; return(JavaScriptConvert.SerializeObject(obj2)); } if (loginUser.LoginTimeout) { obj2["Message"] = "登录超时"; return(JavaScriptConvert.SerializeObject(obj2)); } loginUser.LastOperateTime = DateTime.Now; CommonUtil.WaitMainLibInit(); District district = DistrictModule.ReturnDistrictInfo(long.Parse(managerId)); if (district == null) { obj2["Message"] = "传入的区域ID不存在"; return(JavaScriptConvert.SerializeObject(obj2)); } if (district.ParentId == 0) { obj2["Message"] = "根节点不允许删除"; return(JavaScriptConvert.SerializeObject(obj2)); } //有设备的节点不能删除 if (DeviceModule.GetDevicesForManageID(district.Id).Count > 0) { obj2["Message"] = "此区域下有设备,无法删除"; return(JavaScriptConvert.SerializeObject(obj2)); } string msg = DistrictModule.DeleteDistrictNode(long.Parse(managerId)); //ResMsg msg = DevicesManager.DeleteManageNode(managerId); if (msg == "删除成功")//msg.Result { GlobalAppModule.IsInitMainLib = true; DistrictModule.UpdateDistrictInfo(); GlobalAppModule.IsInitMainLib = false; Thread parameterThread = new Thread(new ParameterizedThreadStart(TcpRunThread.ParameterRun)); parameterThread.Start(ProtocolConst.WebToGateUpdateCache + ProtocolConst.UpdateCache_District + "01" + "0".PadLeft(16, '0')); obj2["Result"] = true; obj2["Message"] = "成功"; } else { //obj2["Message"] = msg.Message; obj2["Message"] = msg; } try { SysLog log = new SysLog(); log.LogUserId = loginUser.UserId; log.LogUserName = loginUser.LoginName; log.LogAddress = ToolsWeb.GetIP(context.Request); log.LogTime = DateTime.Now; log.LogType = "删除区域"; log.LogContent = msg + "|" + ModelHandler <District> .ToString(district); SysLogModule.Add(log); } catch { } return(JavaScriptConvert.SerializeObject(obj2)); }
public void LoadModules() { foreach (string directory in Directory.GetDirectories("Modules")) { foreach (string file in Directory.GetFiles(directory, "*.dll")) { FileInfo fileInfo = new FileInfo(file); if (fileInfo.Name.IndexOf("ChromaWave.Module") == 0) { Assembly module = Assembly.LoadFile(fileInfo.FullName); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler((a, b) => { string dllName = b.Name.Split(',')[0].Trim(); dllName += ".dll"; dllName = Path.Combine(fileInfo.DirectoryName, dllName); if (File.Exists(dllName)) { return(Assembly.LoadFile(dllName)); } else { return(null); } }); string moduleControllerName = $"{Path.GetFileNameWithoutExtension(fileInfo.Name)}.ChromaWaveModule"; Type deviceControllerType = module.GetType(moduleControllerName); if (deviceControllerType == null) { throw new Exception($"{moduleControllerName} was not found inside {file}"); } object deviceController = Activator.CreateInstance(deviceControllerType); MethodInfo method = deviceControllerType.GetMethod("Setup"); if (method == null) { throw new Exception("Module needs to have a Setup method"); } dynamic result = method.Invoke(deviceController, new object[] { }); DeviceModule devicesModule = new DeviceModule() { Name = result.Name, DeviceController = deviceController, Assembly = module }; List <Device> devices = new List <Device>(); foreach (dynamic dynamicResult in result.Devices) { devicesModule.Devices.Add(new Device() { Id = dynamicResult.Id, Title = dynamicResult.Title, Module = devicesModule, Map = new DeviceMap() { BackgroundImage = dynamicResult.Map.BackgroundImage, Size = dynamicResult.Map.Size, Leds = dynamicResult.Map.Leds, } }); } DeviceModules.Add(devicesModule); } } } }
private JavaScriptObject send(HttpRequest request) { string DeviceNo = request["DeviceNo"] ?? ""; string k = request["k"] ?? ""; string content = request["content"] ?? ""; string DeviceTime = request["DeviceTime"] ?? ""; string YearExploitation = request["YearExploitation"] ?? ""; string SerialNumber = request["SerialNumber"] ?? ""; string Range = request["Range"] ?? ""; string LineLength = request["LineLength"] ?? ""; JavaScriptObject result = new JavaScriptObject(); result.Add("Result", false); result.Add("Message", ""); if (DeviceNo.Length != 15) { result["Message"] = "设备编号格式不对!"; return(result); } Device device = DeviceModule.GetDeviceByFullDeviceNo(DeviceNo); if (device == null) { result["Message"] = "设备编号不存在!" + DeviceNo; return(result); } try { bool waitRsp = false; TcpCommunication tcpService = new TcpCommunication(); int timeDelay = 0; //待socket准备好 while (timeDelay < tcpService.TcpWait) { if ((tcpService.SOCKET_STATE == TcpCommunication.TCP_SocketState.SOCKET_CONNECTED) || (tcpService.SOCKET_STATE == TcpCommunication.TCP_SocketState.SOCKET_CLOSED)) { break; } Thread.Sleep(100); timeDelay = timeDelay + 1; } if (tcpService.SOCKET_STATE != TcpCommunication.TCP_SocketState.SOCKET_CONNECTED) { result["Message"] = "与网关通讯失败!"; return(result); } byte[] cmd_send = null; if (k == "1") { CmdToDtuSetDateTime cmd = new CmdToDtuSetDateTime(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.DateTimeNew = DateTime.Parse(DeviceTime); cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "2") { CmdToDtuQueryDateTime cmd = new CmdToDtuQueryDateTime(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "3") { CmdToDtuSetYearExploitation cmd = new CmdToDtuSetYearExploitation(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.YearExploitation = decimal.Parse(YearExploitation); cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "4") { CmdToDtuQueryYearExploitation cmd = new CmdToDtuQueryYearExploitation(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "5") { CmdToDtuOpenPump cmd = new CmdToDtuOpenPump(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "6") { CmdToDtuClosePump cmd = new CmdToDtuClosePump(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "7") { CmdToDtuSetStationCode cmd = new CmdToDtuSetStationCode(); if (device.StationType == 0) { result["Message"] = "非主从站无法设置分站射频地址!"; return(result); } else if (device.StationType == 1) { cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; List <Device> DeviceSubList = DeviceModule.GetAllDeviceSubList(device.Id); List <int> list = new List <int>(); foreach (Device DeviceSub in DeviceSubList) { list.Add(DeviceSub.StationCode); } cmd.StationCodeList = list; } else if (device.StationType == 2) { Device DeviceMain = DeviceModule.GetDeviceByID(device.MainId); string DeviceMainNo = DeviceModule.GetFullDeviceNoByID(device.MainId); cmd.AddressField = DeviceMainNo.Substring(0, 12) + Convert.ToInt32(DeviceMainNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)DeviceMain.StationType; cmd.StationCode = DeviceMain.StationType == 2 ? DeviceMain.StationCode : 0; List <Device> DeviceSubList = DeviceModule.GetAllDeviceSubList(device.MainId); List <int> list = new List <int>(); foreach (Device DeviceSub in DeviceSubList) { list.Add(DeviceSub.StationCode); } cmd.StationCodeList = list; } cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "8") { if (SerialNumber.Length != 8) { result["Message"] = "卡号长度只能为8位!"; return(result); } if (!Regex.IsMatch(SerialNumber, "^[0-9A-Fa-f]+$")) { result["Message"] = "卡号只能为0-9A-Fa-f!"; return(result); } CmdToDtuShieldSerialNumber cmd = new CmdToDtuShieldSerialNumber(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.SerialNumber = SerialNumber; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "9") { if (SerialNumber.Length != 8) { result["Message"] = "卡号长度只能为8位!"; return(result); } if (!Regex.IsMatch(SerialNumber, "^[0-9A-Fa-f]+$")) { result["Message"] = "卡号只能为0-9A-Fa-f!"; return(result); } CmdToDtuShieldSerialNumberCancel cmd = new CmdToDtuShieldSerialNumberCancel(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.SerialNumber = SerialNumber; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "10") { CmdToDtuSetGroundWaterParam cmd = new CmdToDtuSetGroundWaterParam(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.Range = byte.Parse(Range); cmd.LineLength = double.Parse(LineLength); cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "11") { CmdToDtuQueryGroundWaterParam cmd = new CmdToDtuQueryGroundWaterParam(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "12") { CmdToDtuQueryGroundWater cmd = new CmdToDtuQueryGroundWater(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else if (k == "13") { CmdToDtuQueryState cmd = new CmdToDtuQueryState(); cmd.AddressField = DeviceNo.Substring(0, 12) + Convert.ToInt32(DeviceNo.Substring(12, 3)).ToString("X").PadLeft(2, '0'); cmd.StationType = (byte)device.StationType; cmd.StationCode = device.StationType == 2 ? device.StationCode : 0; cmd.RawDataChar = cmd.WriteMsg(); cmd.RawDataStr = HexStringUtility.ByteArrayToHexString(cmd.RawDataChar); myLogger.Info(cmd.RawDataStr); cmd_send = cmd.RawDataChar; } else { result["Message"] = "参数错误!"; return(result); } tcpService.SendData(cmd_send, 0, cmd_send.Length); timeDelay = 0; while (timeDelay < tcpService.TcpWait) { if (tcpService.socketData.Buffer.Length > 0) { myLogger.Info(HexStringUtility.ByteArrayToHexString(tcpService.socketData.Buffer.Buffer)); } if (tcpService.socketData.Buffer.Length >= CommandCommon.CMD_MIN_LENGTH) { byte[] re = tcpService.socketData.Buffer.Buffer; byte[] buffer_new = new byte[tcpService.socketData.Buffer.Length]; Array.Copy(re, buffer_new, tcpService.socketData.Buffer.Length); string receiveHex = HexStringUtility.ByteArrayToHexString(buffer_new); //string str = HexStringUtility.HexStringToStr(receiveHex); waitRsp = true; result["Result"] = true; if (receiveHex == BaseProtocol.DeviceOffline) { result["Message"] = "查询终端不在线"; } else { result["Message"] = "终端在线返回结果:" + receiveHex; } } if (waitRsp == true) { myLogger.Info("获取响应结束"); break; } if (tcpService.SOCKET_STATE == TcpCommunication.TCP_SocketState.SOCKET_CLOSED) { myLogger.Info("Socket关闭结束"); break; } Thread.Sleep(100); timeDelay = timeDelay + 1; } tcpService.Close(); if (waitRsp == false) { result["Message"] = "等待设备回复超时!"; } } catch (Exception exception) { result["Message"] = exception.Message; myLogger.Error(exception.Message); } return(result); }
public string GetGlobalAlarmInfos(string loginIdentifer) { if (strDisposeAlarmCookieName == "") { strDisposeAlarmCookieName = CommonUtil.GetCookieName(this.context.Request, "DisposeAlarmTime"); } JavaScriptObject obj2 = new JavaScriptObject(); JavaScriptArray array = new JavaScriptArray(); obj2.Add("CookieName", strDisposeAlarmCookieName); obj2.Add("AlarmRecords", array); LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if (loginUser == null) { return(JavaScriptConvert.SerializeObject(obj2)); } if (loginUser.LoginTimeout) { return(JavaScriptConvert.SerializeObject(obj2)); } string str = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss"); if (this.context.Session["QueryAlarmStartTime"] != null) { str = this.context.Session["QueryAlarmStartTime"].ToString(); } else { string str2 = this.context.Server.UrlEncode(strDisposeAlarmCookieName); if (this.context.Request.Cookies[str2] != null) { str = this.context.Server.UrlDecode(this.context.Request.Cookies[str2].Value); } this.context.Session["QueryAlarmStartTime"] = str; } DateTime now = DateTime.Now; if (!CommonUtil.CheckTableExiste("DeviceAlarm_" + now.Year.ToString())) { return(JavaScriptConvert.SerializeObject(obj2)); } string deviceNoFulls = ""; List <long> allDevicesForManageID = DeviceModule.GetAllDevicesForManageID(SysUserModule.GetUser(loginUser.UserId).DistrictId); for (int i = 0; i < allDevicesForManageID.Count; i++) { deviceNoFulls += "'" + DeviceModule.GetFullDeviceNoByID(allDevicesForManageID[i]) + "',"; } if (deviceNoFulls == "") { return(JavaScriptConvert.SerializeObject(obj2)); } string sqlstr = "select * from DeviceAlarm_" + now.Year.ToString() + " a " + " where a.DeviceNo in (" + deviceNoFulls.TrimEnd(',') + ") and a.State = 'New'" + " and a.StartTime > '" + str.ToString() + "' and a.StartTime <= '" + now.ToString("yyyy-MM-dd HH:mm:ss") + "'" + " order by a.id"; DataTable table = DbHelperSQL.QueryDataTable(sqlstr); if (table != null) { for (int i = 0; i < table.Rows.Count; i++) { string AlarmType = table.Rows[i]["AlarmType"].ToString(); string AlarmValue = table.Rows[i]["AlarmValue"].ToString(); string AlarmTypeDesc = ""; string AlarmValueDesc = ""; bool flag = false; if (AlarmType == "1" && AlarmValue == "1") { AlarmTypeDesc = "交流电充电状态"; AlarmValueDesc = "停电"; flag = true; } else if (AlarmType == "2" && AlarmValue == "1") { AlarmTypeDesc = "蓄电池电压状态"; AlarmValueDesc = "电压低"; flag = true; } else if (AlarmType == "3" && AlarmValue == "1") { AlarmTypeDesc = "水位超限报警状态"; AlarmValueDesc = "报警"; flag = true; } else if (AlarmType == "4" && AlarmValue == "1") { AlarmTypeDesc = "流量超限报警状态"; AlarmValueDesc = "报警"; flag = true; } else if (AlarmType == "5" && AlarmValue == "1") { AlarmTypeDesc = "电压状态"; AlarmValueDesc = "报警"; flag = true; } else if (AlarmType == "6" && AlarmValue == "1") { AlarmTypeDesc = "流量仪表状态"; AlarmValueDesc = "故障"; flag = true; } else if (AlarmType == "7" && AlarmValue == "1") { AlarmTypeDesc = "水位仪表状态"; AlarmValueDesc = "故障"; flag = true; } else if (AlarmType == "9" && AlarmValue == "1") { AlarmTypeDesc = "存储器状态"; AlarmValueDesc = "异常"; flag = true; } else if (AlarmType == "12" && AlarmValue == "1") { AlarmTypeDesc = "水量超采"; AlarmValueDesc = "异常"; flag = true; } else if (AlarmType == "13" && AlarmValue == "1") { AlarmTypeDesc = "回路报警"; AlarmValueDesc = "报警"; flag = true; } else if (AlarmType == "14" && AlarmValue == "1") { AlarmTypeDesc = "输入断相"; AlarmValueDesc = "断相"; flag = true; } else if (AlarmType == "15" && AlarmValue == "1") { AlarmTypeDesc = "输出断相"; AlarmValueDesc = "断相"; flag = true; } else if (AlarmType == "16" && AlarmValue == "1") { AlarmTypeDesc = "电表信号报警"; AlarmValueDesc = "故障"; flag = true; } else if (AlarmType == "17" && AlarmValue == "1") { AlarmTypeDesc = "过载报警"; AlarmValueDesc = "故障"; flag = true; } else if (AlarmType == "18" && AlarmValue == "1") { AlarmTypeDesc = "用户剩余水量"; AlarmValueDesc = "故障"; flag = true; } else if (AlarmType == "19" && AlarmValue == "1") { AlarmTypeDesc = "用户剩余电量"; AlarmValueDesc = "故障"; flag = true; } if (flag) { JavaScriptObject item = new JavaScriptObject(); item.Add("单位名称", table.Rows[i]["DeviceNo"].ToString()); item.Add("测点名称", table.Rows[i]["DeviceNo"].ToString()); item.Add("报警时间", table.Rows[i]["StartTime"].ToString()); item.Add("报警类型", AlarmTypeDesc); item.Add("报警描述", AlarmTypeDesc + ":" + AlarmValueDesc); array.Add(item); } } } this.context.Session["QueryAlarmStartTime"] = now.ToString("yyyy-MM-dd HH:mm:ss"); return(JavaScriptConvert.SerializeObject(obj2)); }
public void closeClientSocket(AsyncSocketUserToken token, bool isUpdate) { if (token.DeviceList != null) { if (token.isClose) { if (SysCache.ShowInfoLog) { string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,客户端{0}正在关闭", token.DeviceList.DeviceNo); ShowLogData.add(info); LogHelper.Info(info); } return; } token.isClose = true; if (SysCache.ShowInfoLog) { string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,客户端{0},断开连接", token.DeviceList.DeviceNo); ShowLogData.add(info); LogHelper.Info(info); } if (isUpdate) { token.DeviceList.Online = 0; token.DeviceList.LastUpdate = DateTime.Now; token.DeviceList.TerminalState = "设备断开连接"; token.InvokeElement.proxySendDeviceList(token.DeviceList, null); /*未完成 更新终端状态*/ token.InvokeElement.updateDeviceList(token.DeviceList); } List <string> list = OnlineDeviceService.GetDeviceNoSubList(token.DeviceList.Id); if (list != null && list.Count > 0) { foreach (string str in list) { Device device = OnlineDeviceService.GetOnline(str); if (device != null) { if (SysCache.ShowInfoLog) { string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,客户端{0},从站断开连接,主站{1}断开", device.DeviceNo, token.DeviceList.DeviceNo); ShowLogData.add(info); LogHelper.Info(info); } device.Online = 0; device.LastUpdate = DateTime.Now; device.TerminalState = "设备断开连接"; token.InvokeElement.proxySendDeviceList(device, null); token.InvokeElement.updateDeviceList(device); } } } string deviceNo = DeviceModule.GetFullDeviceNoByID(token.DeviceList.Id); OnlineDeviceService.RemoveOnline(deviceNo); } //修改于 2015-4-20 if (token.ConnectedSocket == null) { return; } try { token.ConnectedSocket.Shutdown(SocketShutdown.Both); } catch (SocketException) { } catch (NullReferenceException e) { if (SysCache.ShowErrorLog) { string error = string.Format("程序关闭连接时出错,错误信息{0}", e.Message); LogHelper.Error(error); } } /* * * if (showInfoLog) * { * string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,释放信号量资源"); * ShowLogData.add(info); * LogHelper.Info(info); * } */ //start update by kqz 2017-2-3修改,由之前的注释修改成不注释 //由于在关闭掉客户端的时候,没有将此连接上来的客户端从已经连接的客户端集合中删除掉,所以导致一个客户端成功连接上后,再次断开 //下次连接,如果IP地址不同则连接不成功现象。 //并将此客户端资源回收到池中 //释放信号量资源 this.maxConnection.Release();//update by kqz 2017-3-28 9:34 将原来的注释取消 this.asyncSocketUserTokenPool.push(token); if (showInfoLog) { string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,并将此客户端资源回收到池中,池中剩余数量{0}", asyncSocketUserTokenPool.Count); ShowLogData.add(info); LogHelper.Info(info); } //正在连接的集合中祛除此客户端信息 this.asyncSocketUserTokenList.remove(token); if (showInfoLog) { string info = string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":[" + token.ConnectedSocket.RemoteEndPoint.ToString() + "]:DTU通信服务,正在连接的集合中祛除此客户端信息,剩余连接数量{0}", asyncSocketUserTokenList.count()); ShowLogData.add(info); LogHelper.Info(info); } // end update by kqz 2017-2-3修改,由之前的注释修改成不注释 token.ConnectedSocket.Close(); token.ConnectedSocket = null; token.isClose = false; }
private DataGridViewRow DeviceViewRow(Device device) { DataGridViewRow viewRow = new DataGridViewRow(); DataGridViewTextBoxCell deviceStateCell = new DataGridViewTextBoxCell(); deviceStateCell.Value = (device.Online == 0 ? "离线" : "在线"); viewRow.Cells.Add(deviceStateCell); DataGridViewTextBoxCell deviceNoCell = new DataGridViewTextBoxCell(); deviceNoCell.Value = DeviceModule.GetFullDeviceNoByID(device.Id); viewRow.Cells.Add(deviceNoCell); DataGridViewTextBoxCell deviceDeviceNameCell = new DataGridViewTextBoxCell(); deviceDeviceNameCell.Value = device.DeviceName; viewRow.Cells.Add(deviceDeviceNameCell); DataGridViewTextBoxCell deviceDeviceTypeCell = new DataGridViewTextBoxCell(); deviceDeviceTypeCell.Value = device.DeviceType; viewRow.Cells.Add(deviceDeviceTypeCell); DataGridViewTextBoxCell deviceRemoteStationCell = new DataGridViewTextBoxCell(); deviceRemoteStationCell.Value = device.RemoteStation; viewRow.Cells.Add(deviceRemoteStationCell); DataGridViewTextBoxCell deviceDistrictNameCell = new DataGridViewTextBoxCell(); District district = DistrictModule.ReturnDistrictInfo(device.DistrictId); if (district != null) { deviceDistrictNameCell.Value = district.DistrictName; } else { deviceDistrictNameCell.Value = device.DistrictId; } viewRow.Cells.Add(deviceDistrictNameCell); if (device.StationType == 0) { DataGridViewTextBoxCell deviceMainCell = new DataGridViewTextBoxCell(); deviceMainCell.Value = "单站"; viewRow.Cells.Add(deviceMainCell); DataGridViewTextBoxCell deviceNameMainCell = new DataGridViewTextBoxCell(); deviceNameMainCell.Value = ""; viewRow.Cells.Add(deviceNameMainCell); } else if (device.StationType == 1) { DataGridViewTextBoxCell deviceMainCell = new DataGridViewTextBoxCell(); deviceMainCell.Value = "主站"; viewRow.Cells.Add(deviceMainCell); DataGridViewTextBoxCell deviceNameMainCell = new DataGridViewTextBoxCell(); deviceNameMainCell.Value = ""; viewRow.Cells.Add(deviceNameMainCell); } else if (device.StationType == 2) { Device deviceMain = DeviceModule.GetDeviceByID(device.MainId); if (deviceMain != null) { DataGridViewTextBoxCell deviceMainCell = new DataGridViewTextBoxCell(); deviceMainCell.Value = DeviceModule.GetFullDeviceNoByID(deviceMain.Id); viewRow.Cells.Add(deviceMainCell); DataGridViewTextBoxCell deviceNameMainCell = new DataGridViewTextBoxCell(); deviceNameMainCell.Value = deviceMain.DeviceName; viewRow.Cells.Add(deviceNameMainCell); } } DataGridViewTextBoxCell dataEventTimeCell = new DataGridViewTextBoxCell(); dataEventTimeCell.Value = ""; viewRow.Cells.Add(dataEventTimeCell); DataGridViewTextBoxCell deviceEventTypeCell = new DataGridViewTextBoxCell(); deviceEventTypeCell.Value = ""; viewRow.Cells.Add(deviceEventTypeCell); DataGridViewTextBoxCell deviceRawDataDescCell = new DataGridViewTextBoxCell(); deviceRawDataDescCell.Value = ""; viewRow.Cells.Add(deviceRawDataDescCell); DataGridViewTextBoxCell deviceRawDataCell = new DataGridViewTextBoxCell(); deviceRawDataCell.Value = ""; viewRow.Cells.Add(deviceRawDataCell); return(viewRow); }
/// <summary> /// 更新大数据表的显示 /// </summary> /// <param name="deviceList"></param> private void updateDeviceListInGridView(Device deviceList, DeviceEvent deviceEvent) { lock (this.deviceListsDataGridView) { int rows = this.deviceListsDataGridView.Rows.Count; for (int i = 0; i < rows; i++) { object obj = this.deviceListsDataGridView.Rows[i].Cells[1].Value; if (obj != null) { string val = obj.ToString(); if (val.Equals(DeviceModule.GetFullDeviceNoByID(deviceList.Id))) { //存在修改行 this.deviceListsDataGridView.Rows[i].Cells[0].Value = (deviceList.Online == 0 ? "离线" : "在线"); this.deviceListsDataGridView.Rows[i].Cells[2].Value = deviceList.DeviceName; this.deviceListsDataGridView.Rows[i].Cells[3].Value = deviceList.DeviceType; this.deviceListsDataGridView.Rows[i].Cells[4].Value = deviceList.RemoteStation; District district = DistrictModule.ReturnDistrictInfo(deviceList.DistrictId); if (district != null) { this.deviceListsDataGridView.Rows[i].Cells[5].Value = district.DistrictName; } else { this.deviceListsDataGridView.Rows[i].Cells[5].Value = deviceList.DistrictId; } if (deviceList.StationType == 0) { this.deviceListsDataGridView.Rows[i].Cells[6].Value = "单站"; this.deviceListsDataGridView.Rows[i].Cells[7].Value = ""; } else if (deviceList.StationType == 1) { this.deviceListsDataGridView.Rows[i].Cells[6].Value = "主站"; this.deviceListsDataGridView.Rows[i].Cells[7].Value = ""; } else if (deviceList.StationType == 2) { Device deviceMain = DeviceModule.GetDeviceByID(deviceList.MainId); if (deviceMain != null) { this.deviceListsDataGridView.Rows[i].Cells[6].Value = DeviceModule.GetFullDeviceNoByID(deviceMain.Id); this.deviceListsDataGridView.Rows[i].Cells[7].Value = deviceMain.DeviceName; } else { this.deviceListsDataGridView.Rows[i].Cells[6].Value = "从站"; this.deviceListsDataGridView.Rows[i].Cells[7].Value = ""; } } if (deviceList.Online == 1) { if (deviceEvent != null) { this.deviceListsDataGridView.Rows[i].Cells[8].Value = deviceEvent.EventTime.ToString("yyyy-MM-dd HH:mm:ss"); this.deviceListsDataGridView.Rows[i].Cells[9].Value = deviceEvent.EventType; this.deviceListsDataGridView.Rows[i].Cells[10].Value = deviceEvent.Remark; this.deviceListsDataGridView.Rows[i].Cells[11].Value = deviceEvent.RawData; } } else { this.deviceListsDataGridView.Rows[i].Cells[8].Value = deviceList.LastUpdate.ToString("yyyy-MM-dd HH:mm:ss"); this.deviceListsDataGridView.Rows[i].Cells[9].Value = ""; this.deviceListsDataGridView.Rows[i].Cells[10].Value = ""; this.deviceListsDataGridView.Rows[i].Cells[11].Value = ""; } return; } } } //不存在添加新行 this.deviceListsDataGridView.Rows.Add(DeviceViewRow(deviceList)); } }
//根据信息的种类 ,进行处理:1.数据信息,发送给DTU 2.控制命令,发送给WEB 3.设备列表,更新显示表格 private void proxyProcess(DataTransfer transfer) { switch (transfer.TransferType) { case DataTransferType.DataTransferDataInfo: { DataTransferInfo info = transfer.TransferDataInfo; DeviceInfo di = new DeviceInfo(); di.Parse(info.DeviceNo); string DeviceFullNo = DeviceModule.DeviceNo_Hex2Normal(di.SerialString); string DeviceFullNoMain = DeviceModule.GetDeviceNoMain(DeviceFullNo); bridge.sendToDtu(DeviceFullNo, DeviceFullNoMain, info.Data, info.Offset, info.Length); break; } case DataTransferType.DataTransferCommand: { DTU.GateWay.Protocol.Command command = transfer.TransferCommand; bridge.sendToWeb(command.DeviceInfo.SerialLong, command); break; } case DataTransferType.DataTransferDeviceList: { Device deviceList = transfer.DeviceList; DeviceEvent deviceEvent = transfer.DeviceEvent; updateDeviceListInGridView(deviceList, deviceEvent); break; } case DataTransferType.DataTransferLog: { break; } case DataTransferType.DataTransferUpdateDevice: { string kt = transfer.KeyType; string key = transfer.Key; if (SysCache.ShowInfoLog) { ShowLogData.add("更新设备缓存:" + kt + "," + key); logHelper.Info("更新设备缓存:" + kt + "," + key); } if (kt == "01") { Device device = DeviceModule.GetDeviceByFullDeviceNo_DB(key); if (device != null) { DeviceModule.UpdateDeviceInfo(device); if (dtuServer != null) { dtuServer.updateDevice(device); } updateDeviceListInGridView(device, null); } else { if (SysCache.ShowInfoLog) { ShowLogData.add("更新设备缓存:" + kt + "," + key + " 无法更新设备不存在"); logHelper.Info("更新设备缓存:" + kt + "," + key + " 无法更新设备不存在"); } } } else if (kt == "02") { DeviceModule.RemoveDeviceInfo(key); lock (this.deviceListsDataGridView) { int rows = this.deviceListsDataGridView.Rows.Count; for (int i = 0; i < rows; i++) { object obj = this.deviceListsDataGridView.Rows[i].Cells[1].Value; if (obj != null) { string val = obj.ToString(); if (val.Equals(key)) { this.deviceListsDataGridView.Rows.Remove(this.deviceListsDataGridView.Rows[i]); return; } } } } } break; } case DataTransferType.DataTransferUpdateCardUser: { string kt = transfer.KeyType; string key = transfer.Key; ShowLogData.add("更新用户卡缓存:" + kt + "," + key); if (kt == "01") { CardUser cardUser = CardUserModule.GetCardUserBySerialNumber_DB(key); if (cardUser != null) { CardUserModule.UpdateCardUserInfo(cardUser); } } else if (kt == "02") { CardUserModule.RemoveCardUserInfo(key); } break; } case DataTransferType.DataTransferUpdateDistrict: { ShowLogData.add("更新地区缓存"); initDistrictTree(); break; } } }