Пример #1
0
        private void buttonok_Click(object sender, EventArgs e)
        {
            m_tblpou              = new tblPou();
            m_tblpou.pouName      = textBoxName.Text;
            m_tblpou.Description  = textBoxDescription.Text;
            m_tblpou.Type         = (POUTYPE )comboBoxPOUtype.SelectedValue;
            m_tblpou.Language     = (PouLanguageType)comboBoxProgrammingLanguage.SelectedValue;
            m_tblpou.ControllerID = controller.ControllerID;
            m_tblpou.m_ControllerID_tblController = controller;
            int ret = m_tblpou.Insert();

            if (ret == 0)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                controller.m_tblPouCollection.Add(m_tblpou);
                Close();
            }
            else
            {
                if (ret == 2627)
                {
                    MessageBox.Show("POU Name exits in this controller select another name", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Database Error", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        private void AddPOU(EWSTreeNode node, PROGRAM_IMAGELIST program_imagelist, int imageindex)
        {
            long   ID     = ((EWSTreeNode)node).NodeID;
            tblPou tblpou = new tblPou();

            tblpou.pouName      = Global.EWS.m_tblSolution.GetControllerFromID(ID).GetNewPOUName();
            tblpou.Language     = (PouLanguageType)program_imagelist;
            tblpou.ControllerID = ID;
            tblpou.oIndex       = 0xffffff;
            tblpou.Insert();
            EWSTreeNode newnode = new EWSTreeNode(tblpou.pouName);

            newnode.NodeID             = tblpou.pouID;
            newnode.ImageIndex         = imageindex;
            newnode.SelectedImageIndex = imageindex;
            newnode.ContextMenuStrip   = contextMenuStripPOU;
            node.Nodes.Add(newnode);
            Global.EWS.m_tblSolution.GetControllerFromID(ID).ResetCollection();
            Global.EWS.m_tblSolution.GetControllerFromID(ID).m_tblPouCollection = null;
            Global.EWS.m_tblSolution.GetControllerFromID(ID).ReindexPOUs();
        }
Пример #3
0
        public void AddPOU(string filename, string controllername)
        {
            if (MainForm.Instance().CurrentUser.LogicExplorer != (int)EXPLORER_ACCESS.Full)
            {
                System.Windows.Forms.MessageBox.Show("current user cannot add any Contrller");
            }
            if (!File.Exists(filename))
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("File " + filename + " does not exist");
                return;
            }
            int           ret = 0;
            string        str;
            string        _log = "";
            int           ControllerNameCol = -1;
            bool          headerline        = true;
            tblPou        tblpou            = new tblPou();
            tblController tblcontroller     = tblSolution.m_tblSolution().GetControllerFromName(controllername);

            if (tblcontroller == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import POU Error controller " + controllername + " does not exist in database");
                return;
            }
            using (StreamReader reader = new StreamReader(filename))
            {
                while ((str = reader.ReadLine()) != null)
                {
                    str.Replace(",,", ", ,");
                    if (str.StartsWith("!"))
                    {
                        continue;
                    }
                    if (headerline)
                    {
                        tblpou.headerString = str;
                        headerline          = false;
                        ControllerNameCol   = tblpou.ColumnExistInHeader("ControllerName");
                        if (ControllerNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("POU add error: ControllerName column does not exist in " + filename);
                            break;
                        }
                    }
                    else
                    {
                        tblpou = new tblPou();
                        string[] _strs = str.Split(new Char[] { ',' });
                        if (_strs[ControllerNameCol].ToLower() == controllername)
                        {
                            tblpou.AddFromString(_strs, _strs[ControllerNameCol], ref _log);
                            tblpou.ControllerID = tblcontroller.ControllerID;
                            if ((ret = tblpou.Insert()) != 0)
                            {
                                if (ret == 19)
                                {
                                    DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database");
                                }
                            }
                            else
                            {
                                tblcontroller.m_tblPouCollection.Add(tblpou);
                            }
                        }
                    }
                }
                reader.Close();
            }
        }
Пример #4
0
        private void addUD(bool _isfunction, POUTYPE _poutype, POUEXECUTIONTYPE _pouexecutiontype, string _nodetreename)
        {
            AddUDPouForm addudpouform = new AddUDPouForm();

            if (DialogResult.OK == addudpouform.ShowDialog())
            {
                int _type = 0;
                if (_isfunction)
                {
                    _type = 0;
                }
                else
                {
                    _type = (int)VarType.USERDEFUNED;
                }
                foreach (tblFunction tblfunction in tblSolution.m_tblSolution().m_tblFunctionCollection)
                {
                    if (tblfunction.IsFunction == _isfunction)
                    {
                        if (tblfunction.Type > _type)
                        {
                            _type = tblfunction.Type;
                        }
                    }
                }

                if (CheckUDNameIsValid(addudpouform.pouname))
                {
                    tblPou tblpou = new tblPou();
                    tblpou.pouName       = addudpouform.pouname;
                    tblpou.Description   = addudpouform.poudescription;
                    tblpou.Type          = _poutype;
                    tblpou.Language      = addudpouform.pouLanguageType;
                    tblpou.executiontype = _pouexecutiontype;
                    tblpou.ControllerID  = tblSolution.m_tblSolution().Dummytblcontroller.ControllerID;
                    tblpou.Insert();
                    tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromID(tblpou.ControllerID);
                    tblcontroller.m_tblPouCollection.Add(tblpou);
                    tblcontroller.SavePouDB();
                    tblFunction _tblfunction = new tblFunction();
                    _tblfunction.FunctionName  = addudpouform.pouname;
                    _tblfunction.Description   = addudpouform.poudescription;
                    _tblfunction.Language      = (int)addudpouform.pouLanguageType;
                    _tblfunction.SolutionID    = tblSolution.m_tblSolution().SolutionID;
                    _tblfunction.FunctionGroup = (int)FunctionGroup.USER_DEFINED;
                    _tblfunction.IsFunction    = _isfunction;
                    _tblfunction.IsStandard    = false;
                    _tblfunction.Extensible    = false;
                    _tblfunction.Overloaded    = false;
                    _tblfunction.Width         = 4;
                    _tblfunction.Mode          = 3;
                    _tblfunction.Type          = _type + 1;
                    int ret = _tblfunction.Insert();
                    if (ret == 0)
                    {
                        //tblSolution.m_tblSolution().functionbyType.Add(_tblfunction.Type, _tblfunction);
                        //tblSolution.m_tblSolution().functionbyName.Add(_tblfunction.FunctionName, _tblfunction);
                        //EWSTreeNode _node;
                        foreach (TreeNode rootnode in treeViewControl.Nodes)
                        {
                            foreach (TreeNode _node in rootnode.Nodes)
                            {
                                //_node = (EWSTreeNode)node;
                                //while (_node.NextNode != null)
                                {
                                    if (_node.Text == _nodetreename)
                                    {
                                        EWSTreeNode node4 = new EWSTreeNode(tblpou.pouName);
                                        node4.NodeID = tblpou.pouID;
                                        if (_isfunction)
                                        {
                                            node4.Nodetype         = TREE_NODE_TYPE.FUNCTION;
                                            node4.ContextMenuStrip = contextMenuStripUDF;
                                        }
                                        else
                                        {
                                            node4.Nodetype         = TREE_NODE_TYPE.FUNCTIONBLOCK;
                                            node4.ContextMenuStrip = contextMenuStripUDFB;
                                        }
                                        switch ((PROGRAM_LANGUAGE)tblpou.Language)
                                        {
                                        case PROGRAM_LANGUAGE.ENUM_PROGRAM_LANGUAGE_FBD:
                                            node4.ImageIndex         = 4;
                                            node4.SelectedImageIndex = 5;
                                            break;

                                        case PROGRAM_LANGUAGE.ENUM_PROGRAM_LANGUAGE_ST:
                                            node4.ImageIndex         = 12;
                                            node4.SelectedImageIndex = 13;
                                            break;
                                        }


                                        _node.Nodes.Add(node4);
                                        return;
                                    }
                                    //   _node = (EWSTreeNode)_node.NextNode;
                                }
                            }
                        }
                    }
                }
            }
        }