Exemple #1
0
        /// <summary>
        /// 将当前所选页的工站配置更新到界面上
        /// </summary>
        void UpdateCurrPage(bool isReload, bool enabled = false)
        {
            TabPage currTP = tabControlCF1.SelectedTab;

            if (null == currTP)
            {
                return;
            }
            TableLayoutPanel currPanel = currTP.Controls[0] as TableLayoutPanel;

            if (isReload)
            {
                string category = currTP.Text;
                currPanel.Controls.Clear();
                string[] itemNames = _cfg.ItemNamesInTag(category);
                if (null == itemNames)
                {
                    return;
                }
                foreach (string itemName in itemNames)
                {
                    UcJFParamEdit ucParam = new UcJFParamEdit();
                    ucParam.IsHelpVisible = false;
                    ucParam.Height        = 50;
                    ucParam.Width         = 600;
                    ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, _cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null));
                    currPanel.Controls.Add(ucParam);
                }
            }
            foreach (UcJFParamEdit ucParam in currPanel.Controls)
            {
                //object paramVal = _station.GetCfgParamValue(ucParam.GetParamDesribe().DisplayName);
                object paramVal = _cfg.GetItemValue(ucParam.GetParamDesribe().DisplayName);
                ucParam.SetParamValue(paramVal);
                ucParam.IsValueReadOnly = !enabled;
            }
        }
        /// <summary>
        /// 写入按钮,将所有变量值写入数据池
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btWrite_Click(object sender, EventArgs e)
        {
            StringBuilder sbErrorInfo = new StringBuilder();
            bool          isOK        = true;

            ///先写入所有单值 项
            for (int i = 0; i < _lstUcSingleItems.Count; i++)
            {
                object        val = null;
                UcJFParamEdit pe  = _lstUcSingleItems[i];
                if (!pe.GetParamValue(out val))
                {
                    isOK = false;
                    sbErrorInfo.AppendLine(pe.GetParamDesribe().DisplayName + " 参数格式错误");
                }
                else
                {
                    if (!_dataPool.SetItemValue(pe.GetParamDesribe().DisplayName, val))
                    {
                        isOK = false;
                        sbErrorInfo.AppendLine(pe.GetParamDesribe().DisplayName + " 写入失败");
                    }
                }
            }

            ///再写入所有集合项
            //待添加代码


            if (!isOK)
            {
                JFTipsDelayClose.Show(sbErrorInfo.ToString(), -1);
                return;
            }
            JFTipsDelayClose.Show("写入成功", 1);
        }
Exemple #3
0
        void AdjustStationView()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(AdjustStationView));
                return;
            }
            tabControlCF1.TabPages.Clear();
            isEditting       = false;
            btEditSave.Text  = "编辑";
            btCancel.Enabled = false;
            if (null == _cfg)
            {
                lbInfo.Text        = "无配置项!";
                btEditSave.Enabled = false;
                return;
            }
            lbInfo.Text = "文件路径:" + _cfg.FilePath;
            string[] namedCategorys = _cfg.AllTags;
            //if(null == categorys || categorys.Length < 2) //只有一个无名称Tag,由于保存私有配置
            //{
            //    lbInfo.Text += " 无定制化参数";
            //    btEditSave.Enabled = false;
            //    return;
            //}
            List <string> categorys = new List <string>();

            if (!AllowedShowUnnameTag)
            {
                if (null == categorys || categorys.Count < 2) //只有一个无名称Tag,由于保存私有配置
                {
                    lbInfo.Text       += " 无定制化参数";
                    btEditSave.Enabled = false;
                    return;
                }
            }
            else
            {
                categorys.Add("");
            }
            if (namedCategorys != null)
            {
                categorys.AddRange(namedCategorys);
            }
            btEditSave.Enabled = true;
            foreach (string category in categorys)
            {
                if (string.IsNullOrEmpty(category))
                {
                    continue;
                }
                TabPage tp = new TabPage(category);
                tabControlCF1.TabPages.Add(tp);
                string[] itemNames = _cfg.ItemNamesInTag(category);
                if (null == itemNames)
                {
                    continue;
                }
                TableLayoutPanel panel = new TableLayoutPanel();
                //panel.RowStyles[0] = new RowStyle(SizeType.Absolute, 55);
                panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 55));
                panel.ColumnCount = 1;
                panel.AutoScroll  = true;
                panel.Dock        = DockStyle.Fill;
                tp.Controls.Add(panel);
                for (int i = 0; i < itemNames.Length; i++)//foreach (string itemName in itemNames)
                {
                    string        itemName = itemNames[i];
                    UcJFParamEdit ucParam  = new UcJFParamEdit();
                    ucParam.IsHelpVisible = false;
                    ucParam.Height        = 50;
                    ucParam.Width         = 600;//panel.Width*2/3;
                    //ucParam.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right ;
                    //ucParam.SetParamType(_cfg.GetItemValue(itemName).GetType());//ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName));
                    ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, _cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null));
                    ucParam.SetParamValue(_cfg.GetItemValue(itemName));
                    ucParam.IsValueReadOnly = false;
                    panel.Controls.Add(ucParam);
                    ucParam.IsValueReadOnly = true;
                    //panel.RowStyles[i].SizeType = SizeType.Absolute;
                    //panel.RowStyles[i].Height = 55;
                }
            }
            //if (tabControlCF1.TabCount > 0)
            //    tabControlCF1.SelectedIndex = 0;
        }
Exemple #4
0
        void AdjustUI()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(AdjustUI));
                return;
            }

            while (tabControlCF1.TabCount > 1)
            {
                tabControlCF1.TabPages.RemoveAt(tabControlCF1.TabCount - 1);
            }

            gbInitParams.Controls.Clear();

            if (null == _dev)
            {
                lbModel.Text        = "空";
                lbID.Text           = "空";
                lbOpend.Text        = "空";
                btOpenClose.Enabled = false;
                btOpenClose.Text    = "空设备";
                return;
            }
            else //更新设备信息
            {
                lbModel.Text = _dev.DeviceModel;
                lbID.Text    = _id;
                //UpdateDevice();

                int   locY      = 20;
                int   locX      = 5;
                Label lbDevInit = new Label();
                lbDevInit.Text     = _dev.IsInitOK?"初始化完成":"初始化失败";
                lbDevInit.Location = new Point(locX, locY);
                gbInitParams.Controls.Add(lbDevInit);
                locY += 28;
                for (int i = 0; i < _dev.InitParamNames.Length; i++)
                {
                    UcJFParamEdit ucParam = new UcJFParamEdit();
                    ucParam.SetParamDesribe(_dev.GetInitParamDescribe(_dev.InitParamNames[i]));
                    ucParam.SetParamValue(_dev.GetInitParamValue(_dev.InitParamNames[i]));
                    ucParam.Enabled  = false;
                    ucParam.Location = new Point(locX, locY);
                    gbInitParams.Controls.Add(ucParam);
                    ucParam.Width = gbInitParams.Width - 20;
                    locY          = ucParam.Bottom + 2;
                }

                if (_dev.DioCount > 0)
                {
                    ///fmDios = new FormDios();
                    for (int i = 0; i < _dev.DioCount; i++)
                    {
                        fmDios.AddModule(_dev.GetDio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "DIO模块";
                    tabPage.Name      = "DioModules";
                    tabPage.BackColor = fmDios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmDios.TopLevel        = false;
                    fmDios.FormBorderStyle = FormBorderStyle.None;
                    fmDios.Dock            = DockStyle.Fill;
                    fmDios.Parent          = tabPage;
                    fmDios.Visible         = true;
                    tabPage.Controls.Add(fmDios);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.McCount > 0)
                {
                    //fmMotions = new FormMotions();
                    for (int i = 0; i < _dev.McCount; i++)
                    {
                        fmMotions.AddModule(_dev.GetMc(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "Motion模块";
                    tabPage.Name      = "MotionModules";
                    tabPage.BackColor = fmMotions.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmMotions.TopLevel        = false;
                    fmMotions.FormBorderStyle = FormBorderStyle.None;
                    fmMotions.Dock            = DockStyle.Fill;
                    fmMotions.Parent          = tabPage;
                    fmMotions.Visible         = true;
                    tabPage.Controls.Add(fmMotions);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.CompareTriggerCount > 0)
                {
                    for (int i = 0; i < _dev.CompareTriggerCount; i++)
                    {
                        fmCmprTrigs.AddModule(_dev.GetCompareTrigger(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "CmprTrig模块";
                    tabPage.Name      = "CmprTrigModule";
                    tabPage.BackColor = fmCmprTrigs.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmCmprTrigs.TopLevel        = false;
                    fmCmprTrigs.FormBorderStyle = FormBorderStyle.None;
                    fmCmprTrigs.Dock            = DockStyle.Fill;
                    fmCmprTrigs.Parent          = tabPage;
                    fmCmprTrigs.Visible         = true;
                    tabPage.Controls.Add(fmCmprTrigs);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.AioCount > 0)
                {
                    for (int i = 0; i < _dev.AioCount; i++)
                    {
                        fmAios.AddModule(_dev.GetAio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "AIO模块";
                    tabPage.Name      = "AioModules";
                    tabPage.BackColor = fmAios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmAios.TopLevel        = false;
                    fmAios.FormBorderStyle = FormBorderStyle.None;
                    fmAios.Dock            = DockStyle.Fill;
                    fmAios.Parent          = tabPage;
                    fmAios.Visible         = true;
                    tabPage.Controls.Add(fmAios);  //tabPage选项卡添加一个窗体对象
                }
            }

            tabControlCF1.SelectedIndex = 0;
            UpdateModuleStatus();
        }
        /// <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;
            }
        }