Exemplo n.º 1
0
        /// <summary>
        /// 显示结果
        /// </summary>
        private void ShowResult()
        {
            DateTime errTime = DateTime.Now;

            while (true)
            {
                Thread.Sleep(1000);
                try
                {
                    this.UpdateAllStatus();
                    int uiCnt = NCSys.UIResult.Count;
                    for (int i = 0; i < uiCnt; i++)
                    {
                        if (i % 200 == 0)
                        {
                            Thread.Sleep(200);
                        }
                        else
                        {
                            Thread.Sleep(80);
                        }
                        CmdResult command = null;
                        if (NCSys.UIResult.TryDequeue(out command) == false)
                        {
                            continue;
                        }
                        if (command == null)
                        {
                            continue;
                        }
                        if (NCSys.IsRun == true)
                        {
                            this.Invoke(new ShowUI(UpdateList), command);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FileLog.WriteLog("错误信息:" + ex.Message + ex.StackTrace);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新内存的数据
        /// </summary>
        /// <param name="index"></param>
        /// <param name="command"></param>
        /// <param name="msg"></param>
        private void UpdateList(CmdResult command)
        {
            if (command == null)
            {
                return;
            }
            DataRow curDr = null;

            #region 表头
            try
            {
                this.UpdateAllStatus();
                curDr = this.dtModule.Rows.Find(new object[] { command.Ledger, command.Module_id });
                if (curDr != null)
                {
                    string status    = command.FunName; //"抄表";
                    int    viewTimes = (CommFunc.ConvertDBNullToInt32(curDr["ViewTimes"]) + 1);
                    int    sueTimes  = (CommFunc.ConvertDBNullToInt32(curDr["SueTimes"]) + (command.ErrCode == 1 ? 1 : 0));

                    if (command.FunType.Equals(V0Fun.EventWpf.ToString()))
                    {
                        status             = "恶性负载";
                        curDr["Update_dt"] = DateTime.Now;
                        curDr["Value"]     = "";
                    }
                    else
                    {
                        status             = command.FunType.Equals(V0Fun.E.ToString()) ? "抄表" : command.FunType.Equals(V0Fun.Ssr.ToString()) ? "拉合闸状态" : status;
                        status             = string.IsNullOrEmpty(status) ? "抄表" : status;
                        curDr["Update_dt"] = command.Update;
                        curDr["Value"]     = command.Value;
                    }
                    curDr["Status"]    = status;
                    curDr["ViewTimes"] = viewTimes;
                    curDr["SueTimes"]  = sueTimes;
                    curDr["ErrCode"]   = command.ErrCode;
                    if (viewTimes == 0)
                    {
                        curDr["SuePer"] = "--";
                    }
                    else
                    {
                        curDr["SuePer"] = (((decimal)sueTimes / (decimal)viewTimes) * 100).ToString("f2");
                    }
                }
            }
            catch
            { /*重载时的错误,不处理*/
            }
            #endregion
            #region 明细
            if (this.isShowList == true && command != null)
            {
                try
                {/*清除时错误,不处理*/
                    if (this.listViewLog.Items.Count > 3000)
                    {
                        int rmCC = 2000;
                        while (rmCC > 0)
                        {
                            this.listViewLog.Items.RemoveAt(0);
                            rmCC = --rmCC;
                        }
                    }
                    //
                    if (!string.IsNullOrEmpty(this.txtModuleAddr.Text.Trim()))
                    {
                        if (!command.ModuleAddr.Trim().Equals(this.txtModuleAddr.Text.Trim()))
                        {
                            return;
                        }
                    }
                    else
                    {
                        #region 防止生产过快,消费过慢
                        if (NCSys.UIResult.Count > 5000)
                        {/*防止生产过快,消费过慢*/
                            this.checkBox1.Checked = true;
                        }
                        #endregion
                    }

                    if (command.Result.Count == 0)
                    {
                        this.listViewLog.Items.Add(new ListViewItem(new string[] { "电表", command.ModuleAddr, "", command.BiludBY, command.Update.ToString("yyyy-MM-dd HH:mm:ss fff"), command.ErrTxt }));
                    }
                    foreach (string s in command.Result)
                    {
                        this.listViewLog.Items.Add(new ListViewItem(s.Split(';').ToArray()));
                        Thread.Sleep(5);
                    }
                    //
                    int allCC = this.listViewLog.Items.Count;
                    if (allCC - 1 > 1)
                    {
                        this.listViewLog.EnsureVisible(allCC - 1);
                    }
                }
                catch
                { }
            }
            #endregion
        }