Exemple #1
0
        protected override bool ActionGenuine(out string errorInfo)
        {
            string      itemName    = GetInitParamValue(PN_SysPoolItemName) as string;
            IJFDataPool sysDataPool = JFHubCenter.Instance.DataPool;

            if (!sysDataPool.ContainItem(itemName))
            {
                errorInfo = "系统数据池不包含数据项名:" + itemName;
                return(false);
            }

            object val;

            if (!sysDataPool.GetItemValue(itemName, out val))
            {
                errorInfo = "获取系统数据项失败:名称:\"" + itemName + "\"";
                return(false);
            }

            SetOutputParamValue(ON_CurrVal, val);
            errorInfo = "Success";
            return(true);
        }
        /// <summary>
        /// 将数据池项更新到界面上
        /// </summary>
        void AdjustPoolItem()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(AdjustPoolItem));
                return;
            }
            bool isTimerFlushEnabled = timerFlush.Enabled;

            timerFlush.Enabled    = false;
            chkAutoUpdate.Checked = false;
            panelSingleItems.Controls.Clear();
            panelCollectionItems.Controls.Clear();
            _lstUcSingleItems.Clear();
            _lstChkSingleDisableUpdates.Clear();
            _lstBtSingleWrites.Clear();

            _lstUcCollectItems.Clear();
            _lstChkCollectDisableUpdates.Clear();
            _lstBtCollectWrites.Clear();

            if (null == _dataPool)
            {
                lbInfo.Text           = "数据池未设置";
                btAdjust.Enabled      = false;
                btRead.Enabled        = false;
                btAdjust.Enabled      = false;
                chkAutoUpdate.Enabled = false;
                return;
            }
            lbInfo.Text           = "";
            btAdjust.Enabled      = true;
            btRead.Enabled        = true;
            btAdjust.Enabled      = true;
            chkAutoUpdate.Enabled = true;

            string[] singleItemNames = _dataPool.AllItemKeys;
            if (null != singleItemNames)
            {
                foreach (string itemName in singleItemNames)
                {
                    Type   t = _dataPool.GetItemType(itemName);
                    object val;
                    bool   isOK = _dataPool.GetItemValue(itemName, out val);
                    if (!isOK) //测试中才会用到
                    {
                        MessageBox.Show("获取SingleItem值失败,ItemName = " + itemName);
                    }
                    UcJFParamEdit uc = new UcJFParamEdit();
                    uc.Height        = 23;
                    uc.IsHelpVisible = false;
                    uc.SetParamDesribe(JFParamDescribe.Create(itemName, t, JFValueLimit.NonLimit, null));
                    uc.SetParamValue(val);
                    CheckBox chkDisableUpdate = new CheckBox();
                    chkDisableUpdate.Text = "停更";
                    Button btSingleWrite = new Button();
                    btSingleWrite.Text   = "写入";
                    btSingleWrite.Click += OnSingleItemWriteButtonClick;
                    _lstUcSingleItems.Add(uc);
                    _lstChkSingleDisableUpdates.Add(chkDisableUpdate);
                    _lstBtSingleWrites.Add(btSingleWrite);
                    panelSingleItems.Controls.Add(uc);
                    panelSingleItems.Controls.Add(chkDisableUpdate);
                    panelSingleItems.Controls.Add(btSingleWrite);
                }
                TableLayoutRowStyleCollection styles = panelSingleItems.RowStyles;
                foreach (RowStyle style in styles)
                {
                    // Set the row height to 20 pixels.
                    style.SizeType = SizeType.Absolute;
                    style.Height   = 25;
                }
            }


            string[] collectItemNames = _dataPool.AllListKeys;
            if (null != collectItemNames)
            {
                foreach (string itemName in collectItemNames)
                {
                    Type elementType = _dataPool.GetListElementType(itemName);
                    Type lstType     = typeof(List <>).MakeGenericType(elementType); //动态获取数组类型
                    /*List<object>*/ object itemVal = _dataPool.LockList(itemName);
                    _dataPool.UnlockList(itemName);
                    //var itemValRealy = JFConvertExt.ChangeType(itemVal, lstType);


                    UcJFParamEdit uc = new UcJFParamEdit();
                    uc.Height        = 50;
                    uc.IsHelpVisible = false;
                    uc.SetParamDesribe(JFParamDescribe.Create(itemName, lstType, JFValueLimit.NonLimit, null));
                    uc.SetParamValue(itemVal);
                    uc.SetParamValue(null);
                    CheckBox chkDisableUpdate = new CheckBox();
                    chkDisableUpdate.Text = "停更";
                    Button btCollectWrite = new Button();
                    btCollectWrite.Text   = "写入";
                    btCollectWrite.Click += OnCollectItemWriteButtonClick;
                    _lstUcCollectItems.Add(uc);
                    _lstChkCollectDisableUpdates.Add(chkDisableUpdate);
                    _lstBtCollectWrites.Add(btCollectWrite);
                    panelCollectionItems.Controls.Add(uc);
                    panelCollectionItems.Controls.Add(chkDisableUpdate);
                    panelCollectionItems.Controls.Add(btCollectWrite);
                }
                TableLayoutRowStyleCollection styles = panelCollectionItems.RowStyles;
                foreach (RowStyle style in styles)
                {
                    // Set the row height to 20 pixels.
                    style.SizeType = SizeType.Absolute;
                    style.Height   = 55;
                }
            }

            chkAutoUpdate.Checked = false;


            if (isTimerFlushEnabled)
            {
                chkAutoUpdate.Checked = true;
                timerFlush.Enabled    = true;
            }
            else
            {
                chkAutoUpdate.Checked = false;
            }
        }