public override void AddLinkedVariables() { try { string name; bool exist = false; tblvariable.LoadLinkedVariable(); if (!tblfunction.IsStandard) { foreach (tblFormalParameter tblformalparameter in tblfunction.m_tblFormalParameterCollection) { if ((tblformalparameter.Class == (int)VarClass.Output) || //(tblformalparameter.Class == (int)VarClass.Internal) || (tblformalparameter.Class == (int)VarClass.Local)) { name = tblvariable.VarName + "_" + tblformalparameter.PinName; exist = false; foreach (tblVariable tv in tblvariable.m_tblFInstanceVariableList) { if (tv.VarName == name) { exist = true; break; } } if (!exist) { tblVariable temp = new tblVariable(); temp.VarName = tblvariable.VarName + "_" + tblformalparameter.PinName; //temp.Class = (int)VarClass.Child; temp.Class = (int)tblformalparameter.Class | (int)VarClass.FunctionInstanse; temp.Option = tblformalparameter.Option; temp.Type = tblformalparameter.Type; temp.ParentVarID = tblvariable.VarNameID; temp.ParentVarLinkName = tblformalparameter.PinName; temp.ParentVarLinkID = tblformalparameter.PinID; temp.pouID = tblvariable.pouID; //temp.oIndex = tblformalparameter.oIndex; temp.InitialVal = tblformalparameter.InitializeValue; temp.PlantStructureID = tblSolution.m_tblSolution().AreaLongList[tblSolution.m_tblSolution().GetControllerobjectofPOUID(tblvariable.pouID).ControllerName]; temp.Insert(); tblSolution.m_tblSolution().GetPouFromID(tblvariable.pouID).VariablesByName.Add(temp.VarName.ToLower(), temp); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); DCS.Forms.MainForm.Instance().WriteToOutputWindows("Output variable linked to function " + tblvariable.VarName + " cannot be inserted"); } }
public void AddVariable(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 ret = 0; string str; string _log = ""; bool headerline = true; tblVariable tblvariable = new tblVariable(); tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(controllername); if (tblcontroller == null) { DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import Variable Error: controller " + controllername + " does not exist in database"); return; } tblPou tblpou = tblcontroller.GetPouFromName(pouname); if (tblpou == null) { DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import Variable 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) { tblvariable.headerString = str; headerline = false; ControllerNameCol = tblvariable.ColumnExistInHeader("ControllerName"); if (ControllerNameCol == -1) { DCS.Forms.MainForm.Instance().WriteToOutputWindows("Variable add error: ControllerName column does not exist in " + filename); break; } pouNameCol = tblvariable.ColumnExistInHeader("pouName"); if (pouNameCol == -1) { DCS.Forms.MainForm.Instance().WriteToOutputWindows("Variable add error: pouName column does not exist in " + filename); break; } } else { tblvariable = new tblVariable(); string[] _strs = str.Split(new Char[] { ',' }); //if (_strs[ControllerNameCol].ToLower() != controllername) //{ // continue; //} if ((_strs[ControllerNameCol].ToLower() == controllername) && (_strs[pouNameCol].ToLower() == pouname)) { tblvariable.AddFromString(_strs, _strs[pouNameCol], ref _log); tblvariable.pouID = tblpou.pouID; if ((ret = tblvariable.Insert()) != 0) { if (ret == 19) { DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database"); } } else { tblpou.m_tblVariableCollection.Add(tblvariable); } } } } reader.Close(); } // transaction.Commit(); }
void RowExistIntblVariable(string pinname, string pindescription, string pintype, string pinclass, string pininitialvalue, ref int oIndex) { foreach (tblVariable tblvariable in _tblpou.m_tblVariableCollection) { if (tblvariable.VarName.ToUpper() == pinname.ToUpper()) { tblvariable.Description = pindescription; tblvariable.Type = (int)tblSolution.m_tblSolution().functionbyName[pintype.ToUpper()].Type; if (pinclass == "Input") { tblvariable.Class = (int)VarClass.Input; } if (pinclass == "InOut") { tblvariable.Class = (int)VarClass.InOut; } if (pinclass == "Reference") { tblvariable.Class = (int)VarClass.Input; } if (pinclass == "Output") { tblvariable.Class = (int)VarClass.Output; } if (pinclass == "Local") { tblvariable.Class = (int)VarClass.Local; } tblvariable.InitialVal = pininitialvalue; tblvariable.PlantStructureID = tblSolution.m_tblSolution().Dummytblcontroller.PlantStructureID; tblvariable.Update(); return; } } { tblVariable tblvariable = new tblVariable(); tblvariable.pouID = _tblpou.pouID; tblvariable.VarName = pinname.ToUpper(); tblvariable.Description = pindescription; tblvariable.Type = (int)tblSolution.m_tblSolution().functionbyName[pintype.ToUpper()].Type; if (pinclass == "Input") { tblvariable.Class = (int)VarClass.Input; } if (pinclass == "InOut") { tblvariable.Class = (int)VarClass.InOut; } if (pinclass == "Reference") { tblvariable.Class = (int)VarClass.Input; } if (pinclass == "Output") { tblvariable.Class = (int)VarClass.Output; } if (pinclass == "Local") { tblvariable.Class = (int)VarClass.Local; } tblvariable.InitialVal = pininitialvalue; tblvariable.PlantStructureID = tblSolution.m_tblSolution().Dummytblcontroller.PlantStructureID; tblvariable.Insert(); _tblpou.VariablesByName.Add(tblvariable.VarName.ToLower(), tblvariable); _tblpou.VariablesByName.Remove(tblvariable.VarName); } _tblpou.m_tblVariableCollection = null; }