Пример #1
0
 private void toolStripComboBoxDomain_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (tbldomain != null)
     {
         tbldomain.m_tblControllerCollection.ControllerChanged -= new ControllerChangedEventHandler(updateControllerComboventhandler);
     }
     tbldomain  = (tblDomain)toolStripComboBoxDomain.SelectedItem;
     domainname = tbldomain.DomainName;
     domainid   = tbldomain.DomainID;
     tbldomain.m_tblControllerCollection.ControllerChanged += new ControllerChangedEventHandler(updateControllerComboventhandler);
     if (tbldomain.m_tblControllerCollection.Count > 0)
     {
         updateControllerCombo();
         toolStripComboBoxController.Enabled = true;
     }
     else
     {
         toolStripComboBoxController.Items.Clear();
         toolStripComboBoxProgram.Items.Clear();
         toolStripComboBoxController.Enabled = false;
         toolStripComboBoxProgram.Enabled    = false;
         tblcontroller = null;
         tblpou        = null;
         SelectVariable();
     }
 }
Пример #2
0
 private void updatePOUCombo()
 {
     toolStripComboBoxProgram.Items.Clear();
     for (int i = 0; i < tblcontroller.m_tblPOUCollection.Count; i++)
     {
         //if (tblcontroller.m_tblPOUCollection[i].pouName != "GLOBAL")
         {
             toolStripComboBoxProgram.Items.Add(tblcontroller.m_tblPOUCollection[i]);
         }
     }
     toolStripComboBoxProgram.ComboBox.DisplayMember = "pouName";
     if (toolStripComboBoxProgram.Items.Count > 0)
     {
         if (toolStripComboBoxProgram.SelectedIndex == -1)
         {
             toolStripComboBoxProgram.SelectedIndex = 0;
         }
         tblpou = tblcontroller.m_tblPOUCollection[toolStripComboBoxProgram.SelectedIndex];
         SelectVariable();
     }
     if (tblpou == null)
     {
         toolStripButtonAdd.Enabled    = false;
         toolStripButtonDelete.Enabled = false;
         toolStripButtonEdit.Enabled   = false;
     }
     else
     {
         toolStripButtonAdd.Enabled    = true;
         toolStripButtonDelete.Enabled = true;
         toolStripButtonEdit.Enabled   = true;
     }
 }
Пример #3
0
 private void compilePOUToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         EWSTreeNode node  = (EWSTreeNode)treeViewControl.SelectedNode;
         long        pouid = ((EWSTreeNode)node).NodeID;
         //bool ret = false;
         Compiler compiler = new Compiler(/*mainform*/);
         tblPou   tblpou   = tblSolution.m_tblSolution().GetPouFromID(pouid);
         string   filename;
         if (tblpou.Language == PouLanguageType.ST)
         {
             filename  = Common.ProjectPath + "\\LOGIC";
             filename += "\\";
             filename += tblSolution.m_tblSolution().GetControllerobjectofPOUID(tblpou.pouID).ControllerName;
             filename += "\\";
             filename += tblpou.pouName + ".st";
             using (StreamWriter writer = new StreamWriter(filename))
             {
                 writer.WriteLine(tblpou.STText);
                 writer.Close();
             }
         }
         compiler.CompilePOU(tblSolution.m_tblSolution().GetPouFromID(pouid));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #4
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);
                }
            }
        }
        public override bool SaveTabPage()
        {
            tblVariable tblvariable;
            bool        ret    = true;
            tblPou      tblpou = null;

            foreach (VariableGrid variablegrid in tempList)
            {
                if (variablegrid.Modified)
                {
                    if ((tblpou == null) || (tblpou.pouID != variablegrid.pouID))
                    {
                        tblpou = Global.EWS.m_tblSolution.GetPouFromID(variablegrid.pouID);
                    }
                    tblvariable = tblpou.GetVariableFromID(variablegrid.VarNameID);
                    if (tblvariable != null)
                    {
                        tblvariable.CopyVariableGrid(variablegrid);
                        if (tblvariable.Update() != 0)
                        {
                            ret = false;
                            break;
                        }
                        variablegrid.Modified = false;
                    }
                }
            }
            if (ret)
            {
                base.SaveTabPage();
            }

            return(ret);
        }
Пример #6
0
 public POUObject(tblPou tocopy)
 {
     pouName         = tocopy.pouName;
     Description     = tocopy.Description;
     Type            = tocopy.Type;
     triggerSignalID = tocopy.triggerSignalID;
     executiontype   = tocopy.executiontype;
     Language        = tocopy.Language;
 }
Пример #7
0
        private void DeletePOU_Click(object sender, EventArgs e)
        {
            EWSTreeNode node = (EWSTreeNode)treeViewControl.SelectedNode;

            if (node != null)
            {
                if (node.Nodetype == TREE_NODE_TYPE.PROGRAM)
                {
                    tblPou tblpou = new tblPou();
                    tblpou.pouID = node.NodeID;
                    tblpou.Delete();
                }
            }
        }
Пример #8
0
        //private long _DomainID;
        //public long DomainID
        //{
        //    get
        //    {
        //        return _DomainID;
        //    }
        //    set
        //    {
        //        _DomainID = value;
        //    }
        //}



        public TabSFCPageControl(long id)
            : base(id)
        {
            InitializeComponent();
            //_drawarea = new DrawArea(this);
            TabPageType = TABPAGETYPE.SFC;
            _tblpou     = tblSolution.m_tblSolution().GetPouFromID(ID);
#if EWSAPP
            _pouobject = new POUObject(_tblpou);
#endif
            tblcontroller       = tblSolution.m_tblSolution().GetControllerobjectofPOUID(ID);
            drawarea.Size       = new System.Drawing.Size(1280, 830);
            drawarea.SnapX      = 8;
            drawarea.SnapY      = 8;
            drawarea.SnapEnable = true;
            UpdateToolstripNavigation();
        }
Пример #9
0
        public Variable(long _pouid)
        {
            InitializeComponent();
            tblvariable.VarNameID = -1;
            localPOU = Global.Instance.m_tblSolution.GetPouFromID(_pouid);
            globalPOU = Global.Instance.m_tblSolution.GetGlobaltblPouObjectFromID(_pouid);
            radioButtonGlobal.Checked = true;

            _dataTable = new DataTable();
            _dataSet = new DataSet();

            //initialize bindingsource
            bindingSource_main.DataSource = _dataSet;

            ScanAvailableTypesinPOU();

            SetTestData();

            // set the delegate that the tree uses to know if a node is expandable
            this.treeListView1.CanExpandGetter = x => (x as Node).Children.Count > 0;
            // set the delegate that the tree uses to know the children of a node
            this.treeListView1.ChildrenGetter = x => (x as Node).Children;

            // create the tree columns and set the delegates to print the desired object proerty
            var NameCol = new BrightIdeasSoftware.OLVColumn("Name", "Name");
            NameCol.AspectGetter = x => (x as Node).Name;

            var Descriptioncol = new BrightIdeasSoftware.OLVColumn("Description", "Description");
            Descriptioncol.AspectGetter = x => (x as Node).Column1;

            var Typecol = new BrightIdeasSoftware.OLVColumn("Type", "Type");
            Typecol.AspectGetter = x => (x as Node).Column2;

            var IDcol = new BrightIdeasSoftware.OLVColumn("ID", "ID");
            IDcol.AspectGetter = x => (x as Node).Column3;

            // add the columns to the tree
            this.treeListView1.Columns.Add(NameCol);
            this.treeListView1.Columns.Add(Descriptioncol);
            this.treeListView1.Columns.Add(Typecol);
            this.treeListView1.Columns.Add(IDcol);
            
        }
Пример #10
0
        private void DeleteUD(TREE_NODE_TYPE _tree_node_type)
        {
            EWSTreeNode node         = (EWSTreeNode)treeViewControl.SelectedNode;
            string      name         = node.Text.ToUpper();
            tblFunction _tblfunction = null;
            tblPou      _tblpou      = null;

            if (node != null)
            {
                if (node.Nodetype == _tree_node_type)
                {
                    foreach (tblFunction tblfunction in tblSolution.m_tblSolution().m_tblFunctionCollection)
                    {
                        if (tblfunction.FunctionName.ToUpper() == name)
                        {
                            _tblfunction = tblfunction;
                            tblSolution.m_tblSolution().functionbyType.Remove(_tblfunction.Type);
                            tblSolution.m_tblSolution().functionbyName.Remove(_tblfunction.FunctionName);
                            break;
                        }
                    }
                    if (_tblfunction != null)
                    {
                        tblSolution.m_tblSolution().m_tblFunctionCollection.Remove(_tblfunction);
                        _tblfunction.Delete();
                    }
                    foreach (tblPou tblpou in tblSolution.m_tblSolution().Dummytblcontroller.m_tblPouCollection)
                    {
                        if (tblpou.pouName.ToUpper() == name)
                        {
                            _tblpou = tblpou;
                            break;
                        }
                    }
                    if (_tblpou != null)
                    {
                        //tblSolution.m_tblSolution().Dummytblcontroller.m_tblPouCollection.Remove(_tblpou);
                        _tblpou.Delete();
                    }
                }
                treeViewControl.Nodes.Remove(treeViewControl.SelectedNode);
            }
        }
Пример #11
0
 public UDFPinForm(bool _isfunction, string _pouname)
 {
     InitializeComponent();
     foreach (tblPou tblpou in tblSolution.m_tblSolution().Dummytblcontroller.m_tblPouCollection)
     {
         if (tblpou.pouName.ToUpper() == _pouname.ToUpper())
         {
             _tblpou = tblpou;
             break;
         }
     }
     foreach (tblFunction tblfunction in tblSolution.m_tblSolution().m_tblFunctionCollection)
     {
         if (tblfunction.FunctionName.ToUpper() == _pouname.ToUpper())
         {
             _tblfunction = tblfunction;
             break;
         }
     }
 }
Пример #12
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();
        }
Пример #13
0
        private void moveUpPOU_Click(object sender, EventArgs e)
        {
            EWSTreeNode node         = (EWSTreeNode)treeViewControl.SelectedNode;
            long        pouid        = ((EWSTreeNode)node).NodeID;
            long        controllerid = ((EWSTreeNode)node.Parent).NodeID;
            tblPou      tblpou       = tblSolution.m_tblSolution().GetControllerFromID(controllerid).GetPouFromID(pouid);

            if (tblpou.oIndex > 1)
            {
                tblSolution.m_tblSolution().GetControllerFromID(controllerid).MoveUpPOU(tblpou.oIndex);
                TreeNode parent = node.Parent;
                if (parent != null)
                {
                    int index = parent.Nodes.IndexOf(node);
                    if (index > 0)
                    {
                        parent.Nodes.RemoveAt(index);
                        parent.Nodes.Insert(index - 1, node);
                    }
                }
            }
        }
Пример #14
0
        private void moveDownPOU_Click(object sender, EventArgs e)
        {
            EWSTreeNode node         = (EWSTreeNode)treeViewControl.SelectedNode;
            long        pouid        = ((EWSTreeNode)node).NodeID;
            long        controllerid = ((EWSTreeNode)node.Parent).NodeID;
            tblPou      tblpou       = Global.EWS.m_tblSolution.GetControllerFromID(controllerid).GetPouFromID(pouid);

            if (tblpou.oIndex != (Global.EWS.m_tblSolution.GetControllerFromID(controllerid).m_tblPouCollection.Count - 1))
            {
                Global.EWS.m_tblSolution.GetControllerFromID(controllerid).MoveDownPOU(tblpou.oIndex);
                TreeNode parent = node.Parent;
                if (parent != null)
                {
                    int index = parent.Nodes.IndexOf(node);
                    if (index < parent.Nodes.Count - 1)
                    {
                        parent.Nodes.RemoveAt(index);
                        parent.Nodes.Insert(index + 1, node);
                    }
                }
            }
        }
Пример #15
0
        private void treeViewControl_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (e.Label != null)
            {
                if (e.Label.Length > 0)
                {
                    if (e.Label.IndexOfAny(new char[] { '@', '.', ',', '!' }) == -1)
                    {
                        long ID = ((EWSTreeNode)e.Node.Parent).NodeID;
                        if (!Global.EWS.m_tblSolution.GetControllerFromID(ID).CheckPOUNameExist(e.Label))
                        {
                            tblPou tblpou = Global.EWS.m_tblSolution.GetControllerFromID(ID).GetPouFromID(((EWSTreeNode)e.Node).NodeID);
                            tblpou.pouName = e.Label;
                            tblpou.Update();
                        }
                        e.Node.EndEdit(false);
                    }
                    else
                    {
                        /* Cancel the label edit action, inform the user, and
                         * place the node in edit mode again. */
                        e.CancelEdit = true;

                        e.Node.BeginEdit();
                    }
                }
                else
                {
                    /* Cancel the label edit action, inform the user, and
                     * place the node in edit mode again. */
                    e.CancelEdit = true;
                    MessageBox.Show("Invalid tree node label.\nThe label cannot be blank",
                                    "Node Label Edit");
                    e.Node.BeginEdit();
                }
                treeViewControl.LabelEdit = false;
            }
        }
Пример #16
0
        public VariableForm()
        {
            try
            {
                //mainewsform = _mainewsform;
                InitializeComponent();
                tblvariable.VarNameID = -1;
                localPOU  = null;
                globalPOU = null;
                //radioButtonGlobal.Checked = true;

                radioButtonGlobal.Checked = !Common.Variable_LocalSelected;
                radioButtonLocal.Checked  = Common.Variable_LocalSelected;

                //SetTestData();

                // set the delegate that the tree uses to know if a node is expandable
                this.treeListView1.CanExpandGetter = x => (x as Node).Children.Count > 0;
                // set the delegate that the tree uses to know the children of a node
                this.treeListView1.ChildrenGetter = x => (x as Node).Children;

                // create the tree columns and set the delegates to print the desired object proerty
                var NameCol = new BrightIdeasSoftware.OLVColumn("Name", "Name");
                NameCol.AspectGetter = x => (x as Node).Name;

                var Descriptioncol = new BrightIdeasSoftware.OLVColumn("Description", "Description");
                Descriptioncol.AspectGetter = x => (x as Node).Description;

                var Typecol = new BrightIdeasSoftware.OLVColumn("Type", "Type");
                Typecol.AspectGetter = x => (x as Node).Type;

                var Areacol = new BrightIdeasSoftware.OLVColumn("Area", "Area");
                Areacol.AspectGetter = x => (x as Node).Area;

                // add the columns to the tree
                this.treeListView1.Columns.Add(NameCol);
                this.treeListView1.Columns.Add(Descriptioncol);
                this.treeListView1.Columns.Add(Typecol);
                this.treeListView1.Columns.Add(Areacol);

                if (Common.Variable_NameColWidth > 0)
                {
                    this.treeListView1.Columns[0].Width = Common.Variable_NameColWidth;
                }
                if (Common.Variable_DescriptionColWidth > 0)
                {
                    this.treeListView1.Columns[1].Width = Common.Variable_DescriptionColWidth;
                }
                if (Common.Variable_TypeColWidth > 0)
                {
                    this.treeListView1.Columns[2].Width = Common.Variable_TypeColWidth;
                }
                if (Common.Variable_IDColWidth > 0)
                {
                    this.treeListView1.Columns[3].Width = Common.Variable_IDColWidth;
                }

                //this.button1.Width = this.treeListView1.Columns[0].Width;
                //button1.Height = treeListView1.TopItem.Bounds.Top;
                //listView.Items[0].Bounds.Top
                // int ggg = treeListView1.TopItem.Bounds.Top;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #17
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;
                                }
                            }
                        }
                    }
                }
            }
        }
 public tblProgramBodyCollection(tblPou parent)
 {
     m_pouID_tblPou = parent;
 }
Пример #19
0
 private void toolStripComboBoxProgram_SelectedIndexChanged(object sender, EventArgs e)
 {
     tblpou = (tblPou)toolStripComboBoxProgram.SelectedItem;
 }
Пример #20
0
        public void AddREAL(string filename, string controllername, string pouname)
        {
            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 ControllerNameCol = -1;
            int pouNameCol        = -1;
            int VarNameCol        = -1;

            int           ret = 0;
            string        str;
            string        _log          = "";
            bool          headerline    = true;
            tblREAL       tblreal       = new tblREAL();
            tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(controllername);

            if (tblcontroller == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import REAL Error: controller " + controllername + " does not exist in database");
                return;
            }
            tblPou tblpou = tblcontroller.GetPouFromName(pouname);

            if (tblpou == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import REAL Error: pou " + pouname + " does not exist in " + controllername);
                return;
            }
            //var transaction = Common.Conn.BeginTransaction();
            using (StreamReader reader = new StreamReader(filename))
            {
                while ((str = reader.ReadLine()) != null)
                {
                    str.Replace(",,", ", ,");
                    if (str.StartsWith("!"))
                    {
                        continue;
                    }
                    if (headerline)
                    {
                        tblreal.headerString = str;
                        headerline           = false;
                        ControllerNameCol    = tblreal.ColumnExistInHeader("ControllerName");
                        if (ControllerNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: ControllerName column does not exist in " + filename);
                            break;
                        }
                        pouNameCol = tblreal.ColumnExistInHeader("pouName");
                        if (pouNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: pouName column does not exist in " + filename);
                            break;
                        }
                        VarNameCol = tblreal.ColumnExistInHeader("VarName");
                        if (VarNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: VarName column does not exist in " + filename);
                            break;
                        }
                    }
                    else
                    {
                        tblreal = new tblREAL();
                        string[] _strs = str.Split(new Char[] { ',' });
                        if ((_strs[ControllerNameCol].ToLower() == controllername) && (_strs[pouNameCol].ToLower() == pouname))
                        {
                            if (tblpou.VariablesByName.ContainsKey(_strs[VarNameCol].ToLower()))
                            {
                                tblVariable tblvariable = tblpou.VariablesByName[_strs[VarNameCol].ToLower()];
                                tblreal.AddFromString(_strs, _strs[pouNameCol], ref _log);

                                tblreal.VarNameID = tblvariable.VarNameID;
                                if ((ret = tblreal.Insert()) != 0)
                                {
                                    if (ret == 19)
                                    {
                                        DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database");
                                    }
                                }
                            }
                            else
                            {
                                DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add Error: Varaible " + _strs[VarNameCol] + " does not exist in database");
                            }
                        }
                    }
                }
                reader.Close();
            }
        }
Пример #21
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();
            }
        }