| | |
| | | using Yw; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraLayout; |
| | | using Yw; |
| | | using Yw.WinFrmUI; |
| | | |
| | | |
| | | namespace IBox.WinFrmUI |
| | | { |
| | | public partial class IBoxFormLog : DocumentPage |
| | | { |
| | | |
| | | private string startCode = "[&start&]"; |
| | | private string endCode = "[&end&]"; |
| | | private string paramCode = "[¶m&]"; |
| | | private string getlogCode = "getlog"; |
| | | private string clearlogCode = "clearlog"; |
| | | public IBoxFormLog() |
| | | { |
| | | this.PageTitle.Caption = "日志管理"; |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | public void HideButton() |
| | | { |
| | | //simpleButton1.Visible = simpleButton2.Visible = false; |
| | | /*layoutControlItem2.Visibility =*/ |
| | | layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | |
| | | private void EboxFormLog_Load(object sender, EventArgs e) |
| | | { |
| | | //BluetoothHelper.GetInstance().SMR -= null; |
| | | //BluetoothHelper.GetInstance().SMR += new BluetoothHelper.ShowMessReturn(GetReceive); |
| | | //BluetoothHelper.GetInstance().ListenerData(); |
| | | this.dateEditStartDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | this.dateEditEndDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | SetData(); |
| | |
| | | LogResult = "" |
| | | }; |
| | | |
| | | SendText(startCode + getlogCode + paramCode + JsonHelper.Object2Json(m) + endCode); |
| | | SendText(IBoxHelper.startCode + IBoxHelper.getlogCode + IBoxHelper.paramCode + JsonHelper.Object2Json(m) + IBoxHelper.endCode); |
| | | } |
| | | |
| | | private void SetData() |
| | | public void SetData() |
| | | { |
| | | var dic = GetDic(); |
| | | imageComboBoxEdit1.Properties.Items.Add("全部", "", -1); |
| | |
| | | |
| | | imageComboBoxEdit1.SelectedIndex = 0; |
| | | imageComboBoxEdit2.SelectedIndex = 0; |
| | | |
| | | } |
| | | |
| | | public void GetReceive(string msg) |
| | | { |
| | | if (!this.IsHandleCreated || this.IsDisposed || string.IsNullOrEmpty(msg)) return; |
| | | if (msg.StartsWith("error:") && msg.Contains("目标主机坏了")) |
| | | { |
| | | MessageBoxHelper.ShowWarning("l 蓝牙设备连接失败,请重试!"); return; |
| | | } |
| | | if (!string.IsNullOrEmpty(msg) && msg.Contains(startCode)) |
| | | { |
| | | var order = msg.Replace(endCode, "").Replace(startCode, "").Trim(); |
| | | SetOrder(order); |
| | | } |
| | | else MessageBoxHelper.ShowWarning("l 蓝牙设备连接失败"); |
| | | } |
| | | |
| | | public event EventHandler<string> SendData; |
| | | |
| | | private void SendText(string content) |
| | | { |
| | | //BluetoothHelper.GetInstance().SendData(content); |
| | | SendData?.Invoke(null, content); |
| | | } |
| | | |
| | | private void SetOrder(string order) |
| | | { |
| | | var smsg = order.Split(new string[] { paramCode }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (smsg.Length < 2) |
| | | if (SendData != null) |
| | | { |
| | | return; |
| | | SendData?.Invoke(null, content); |
| | | } |
| | | |
| | | switch (smsg[0].Trim()) |
| | | else |
| | | { |
| | | case "getlog": |
| | | var getloglist = JsonHelper.Json2Object<List<IBoxLogViewModel>>(smsg[1].Trim()); |
| | | BindData(getloglist); |
| | | break; |
| | | if (IBoxHelper.Ping()) |
| | | { |
| | | var smsg = content.Split(new string[] { IBoxHelper.paramCode, IBoxHelper.startCode }, StringSplitOptions.RemoveEmptyEntries); |
| | | if (smsg.Length < 2) |
| | | { |
| | | return; |
| | | } |
| | | switch (smsg[0].Trim()) |
| | | { |
| | | case IBoxHelper.getlogCode: |
| | | { |
| | | var order = IBoxHelper.HttpGet(content); |
| | | var result = IBoxHelper.GetContent(order); |
| | | if (!string.IsNullOrEmpty(result)) |
| | | { |
| | | var model = JsonHelper.Json2Object<List<IBoxLogViewModel>>(result); |
| | | BindData(model, false); |
| | | } |
| | | break; |
| | | } |
| | | default: |
| | | IBoxHelper.HttpGet(content); |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MessageBoxHelper.ShowWarning("网络连接失败,请检查网络"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void simpleButton1_Click(object sender, EventArgs e) |
| | | { |
| | | Search(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询 |
| | | /// </summary> |
| | | public void Search() |
| | | { |
| | | //查询 |
| | | //SendText(startCode + getlogCode + paramCode + endCode); |
| | | //this.dateEditStartDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | //this.dateEditEndDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | var m = new GetCalcValueModel() |
| | | { |
| | | StartDate = DateTime.Parse(this.dateEditStartDate.EditValue.ToString()), |
| | |
| | | LogEvent = imageComboBoxEdit1.EditValue?.ToString() |
| | | }; |
| | | |
| | | SendText(startCode + getlogCode + paramCode + JsonHelper.Object2Json(m) + endCode); |
| | | SendText(IBoxHelper.startCode + IBoxHelper.getlogCode + IBoxHelper.paramCode + JsonHelper.Object2Json(m) + IBoxHelper.endCode); |
| | | } |
| | | |
| | | private void simpleButton2_Click(object sender, EventArgs e) |
| | | { |
| | | Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空 |
| | | /// </summary> |
| | | public void Clear() |
| | | { |
| | | //清空 |
| | | this.Invoke(new Action(() => |
| | |
| | | eboxLogViewModelBindingSource.DataSource = null; |
| | | this.gridView1.RefreshData(); |
| | | })); |
| | | SendText(startCode + clearlogCode + paramCode + endCode); |
| | | SendText(IBoxHelper.startCode + IBoxHelper.clearlogCode + IBoxHelper.paramCode + IBoxHelper.endCode); |
| | | } |
| | | |
| | | private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) |
| | | { |
| | | |
| | | if (e.Column.FieldName == "LogResult") |
| | | { |
| | | var celValue = e.CellValue.ToString(); |
| | |
| | | celNewValue = "提示"; |
| | | e.Appearance.ForeColor = Color.Blue; |
| | | break; |
| | | |
| | | case "fail": |
| | | celNewValue = "失败"; |
| | | e.Appearance.ForeColor = Color.Coral; |
| | | break; |
| | | |
| | | case "error": |
| | | celNewValue = "异常"; |
| | | e.Appearance.ForeColor = Color.Red; |
| | | break; |
| | | |
| | | default: |
| | | celNewValue = "成功"; |
| | | e.Appearance.ForeColor = Color.Green; |
| | |
| | | |
| | | private Dictionary<string, string> GetDic() |
| | | { |
| | | |
| | | return new Dictionary<string, string> |
| | | { |
| | | //{ "heartbeat", "心跳" }, |
| | | //{ "getbase", "获取基础信息" }, |
| | | //{ "getrules", "获取规则信息" }, |
| | | //{ "saverules", "保存规则信息" }, |
| | | //{ "getprotocol", "获取协议配置" }, |
| | | //{ "saveprotocol", "保存协议配置" }, |
| | | //{ "getalarmbysignalid", "获取单个信号报警信息" }, |
| | | //{ "getalarmbyday", "按天查询报警信息" }, |
| | | //{ "getbysignalidofdayrange", "根据日期范围查询报警信息" }, |
| | | //{ "getrealrecord", "查询实时数据" }, |
| | | //{ "datadownload", "数据下发" }, |
| | | //{ "gethistoryrecord", "查询单个信号历史数据" }, |
| | | //{ "getlog", "获取日志" }, |
| | | //{ "clearlog", "清空日志" }, |
| | | //{ "getparams", "获取参数配置" }, |
| | | //{ "saveparams", "保存参数配置" }, |
| | | { "controll", "智能控制" }, |
| | | { "postdata", "数据推送" }, |
| | | { "default", "常规" }, |
| | | { "datadocking", "数据采集" }, |
| | | //{ "getcalvalue", "获取智能控制数据" }, |
| | | //{ "execcalvalue", "执行智能控制" } |
| | | }; |
| | | } |
| | | |
| | | private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) |
| | | { |
| | | if (e.Column.FieldName == "LogEvent") |
| | |
| | | case "info": |
| | | celNewValue = "提示"; |
| | | break; |
| | | |
| | | case "fail": |
| | | celNewValue = "失败"; |
| | | break; |
| | | |
| | | case "error": |
| | | celNewValue = "异常"; |
| | | break; |
| | | |
| | | default: |
| | | celNewValue = "成功"; |
| | | break; |
| | | } |
| | | e.DisplayText = celNewValue; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | /// <param name="eboxLogs"></param> |
| | | /// <param name="isBlue"></param> |
| | | public void BindData(List<IBoxLogViewModel> eboxLogs, bool isBlue = true) |
| | | { |
| | | if (isBlue) |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |