Esempio n. 1
0
        public static void ButtonClick(string tag, bool logic, string eventText = null)
        {
            if (Static.Link)
            {
                try
                {
                    bool err;
                    OpcServer.GetInstance().GetOpc(OpcServer.OpcList.Rbu).cl.WriteBool(tag, logic, out err);
                    if (eventText != null)
                    {
                        EventsBase.GetInstance().GetControlEvents(OpcServer.OpcList.Rbu).AddEvent(eventText, SystemEventType.UserDoing);
                    }
                    if (err)
                    {
                        MessageBox.Show("Возможно запись не прошла.\nПроверьте OPC-сервер или соответствующий тег",
                                        "Предупреждение");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Запись не прошла. Повторите ввод", "Ошибка");
                }
            }
            else

            {
                MessageBox.Show("Нет связи с ПЛК", "Ошибка");
            }
        }
Esempio n. 2
0
        //public string GetConnectionStringEvents(OpcServer.OpcList opcName)
        //{
        //    if (ServiceData.GetInstance().GetSqlName() == "PostgreSQL")
        //    {
        //        return "server=" + ServiceData.GetInstance().GetSqlAddress() + ";user id=AS_Library;password=asuasu123;database=" +
        //               OpcServer.GetInstance().GetObjectData(opcName).EventBaseName;

        //    }

        //    return "Data Source=" + ServiceData.GetInstance().GetSqlAddress() +
        //           "\\" + ServiceData.GetInstance().GetSqlName() + ";Initial Catalog=" +
        //           OpcServer.GetInstance().GetObjectData(opcName).EventBaseName +
        //           "; User ID=AS_Library;Password=asuasu123;";
        //}

        public void CreateControlEvents(OpcServer.OpcList objectName)
        {
            if (!_eventsDict.ContainsKey(objectName))
            {
                _eventsDict.Add(objectName,
                                new ControlEventsEntity(OpcServer.GetInstance().GetOpc(OpcServer.OpcList.Rbu), new EventsEntityCoreService(), false, false, false, false));
            }
        }
Esempio n. 3
0
        private void CreateSubscription()
        {
            _opc = OpcServer.GetInstance().GetOpc(_opcName);
            var value = new OpcMonitoredItem(_opc.cl.GetNode(_opcTag), OpcAttribute.Value);

            value.DataChangeReceived += HandleValueChanged;
            OpcServer.GetInstance().GetSubscription(_opcName).AddMonitoredItem(value);
        }
Esempio n. 4
0
 public static OpcServer GetInstance()
 {
     if (_instance == null)
     {
         _instance = new OpcServer();
     }
     return(_instance);
 }
Esempio n. 5
0
 public static void Archive_OnClick(OpcServer.OpcList opcName, string nameStation = "")
 {
     try
     {
         bool          postgresql = ServiceData.GetInstance().GetSqlName() == "PostgreSQL";
         WindowArchive window     = new WindowArchive(OpcServer.GetInstance().GetConnectionStringData(opcName), null,
                                                      0, true, OpcServer.GetInstance().GetOpc(opcName).AnalogTags, OpcServer.GetInstance().GetOpc(opcName).DiscreteTags,
                                                      postgresql, OpcServer.GetInstance().GetObjectData(opcName).SqlTableName, nameStation, new DataNewArchiverReader());
         window.SaveGraphLeg += OnSaveGraphLeg;
         window.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка:" + ex.Message);
     }
 }
Esempio n. 6
0
 public static void Archive_OnClick()
 {
     try
     {
         //var connectionString = "server=localhost; user id=AS_Library;password=asuasu123;database=DbRbuDatabaseNew";
         //var opc = new OPC_client("opc.tcp://localhost:49320", "server=localhost;user id=AS_Library;password=asuasu123;database=DbOpcTables", "Rbu");
         //opc.cl.Connect("localhost", "", 100);0
         WindowArchive window = new WindowArchive(OpcServer.GetInstance().GetConnectionStringData(OpcServer.OpcList.Rbu), null,
                                                  0, true, OpcServer.GetInstance().GetOpc(OpcServer.OpcList.Rbu).AnalogTags, OpcServer.GetInstance().GetOpc(OpcServer.OpcList.Rbu).DiscreteTags,
                                                  true, OpcServer.GetInstance().GetObjectData(OpcServer.OpcList.Rbu).SqlTableName, "", new DataNewArchiverReader());
         window.SaveGraphLeg += OnSaveGraphLeg;
         window.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка:" + ex.Message);
     }
 }
Esempio n. 7
0
        private static void OnSaveGraphLeg(Tag tag, string nameBase)
        {
            bool postgresql = ServiceData.GetInstance().GetSqlName() == "PostgreSQL";

            if (!postgresql)
            {
                using (SqlConnection connection = new SqlConnection(ServiceData.GetInstance().GetOpcTablesBase()))
                {
                    try
                    {
                        connection.Open();

                        // Create an instance of a DataAdapter.
                        SqlDataAdapter adapter
                            = new SqlDataAdapter(
                                  "SELECT Id, Legend, Koef, Color, ChangeVal, SaveByTime, RarelyChanging FROM " + nameBase + " WHERE NumTag = " + tag.NumTag,
                                  connection);

                        // Create an instance of a DataSet, and retrieve data from the Authors table.
                        DataSet dbOpcTables = new DataSet("DbOpcTables");
                        adapter.FillSchema(dbOpcTables, SchemaType.Source, nameBase);
                        adapter.Fill(dbOpcTables, nameBase);

                        DataColumn[] myKey = new DataColumn[1];
                        myKey[0] = dbOpcTables.Tables[0].Columns[0];
                        dbOpcTables.Tables[0].PrimaryKey = myKey;

                        var tblAuthors = dbOpcTables.Tables[nameBase];
                        var dataRow    = tblAuthors.Rows[0];
                        dataRow.BeginEdit();
                        dataRow["Legend"]         = tag.NameTag;
                        dataRow["Color"]          = tag.Color;
                        dataRow["Koef"]           = Convert.ToDouble(tag.Koef);
                        dataRow["ChangeVal"]      = Convert.ToDouble(tag.ChangeVal);
                        dataRow["SaveByTime"]     = tag.SaveByTime;
                        dataRow["RarelyChanging"] = tag.RarelyChanging;
                        dataRow.EndEdit();

                        SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(adapter);
                        adapter.Update(dbOpcTables, nameBase);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Что-то пошло не так!" + "\n" + ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            else
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(ServiceData.GetInstance().GetOpcTablesBase()))
                {
                    try
                    {
                        connection.Open();

                        // Create an instance of a DataAdapter.
                        NpgsqlDataAdapter adapter
                            = new NpgsqlDataAdapter(
                                  "SELECT \"Id\", \"Legend\", \"Koef\", \"Color\", \"ChangeVal\", \"SaveByTime\", \"RarelyChanging\" FROM dbo." + "\"" + nameBase + "\"" + " WHERE \"NumTag\" = " + tag.NumTag,
                                  connection);

                        // Create an instance of a DataSet, and retrieve data from the Authors table.
                        DataSet dbOpcTables = new DataSet("DbOpcTables");
                        adapter.FillSchema(dbOpcTables, SchemaType.Source, nameBase);
                        adapter.Fill(dbOpcTables, nameBase);

                        DataColumn[] myKey = new DataColumn[1];
                        myKey[0] = dbOpcTables.Tables[0].Columns[0];
                        dbOpcTables.Tables[0].PrimaryKey = myKey;

                        var tblAuthors = dbOpcTables.Tables[nameBase];
                        var dataRow    = tblAuthors.Rows[0];
                        dataRow.BeginEdit();
                        dataRow["Legend"]         = tag.NameTag;
                        dataRow["Color"]          = tag.Color;
                        dataRow["Koef"]           = Convert.ToDouble(tag.Koef);
                        dataRow["ChangeVal"]      = Convert.ToDouble(tag.ChangeVal);
                        dataRow["SaveByTime"]     = tag.SaveByTime;
                        dataRow["RarelyChanging"] = tag.RarelyChanging;
                        dataRow.EndEdit();

                        NpgsqlCommandBuilder objCommandBuilder = new NpgsqlCommandBuilder(adapter);
                        adapter.Update(dbOpcTables, nameBase);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Что-то пошло не так!" + "\n" + ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

            foreach (var item in OpcServer.GetInstance().GetObjects())
            {
                if (item.Value.SqlTableName == nameBase)
                {
                    var tagD = OpcServer.GetInstance().GetOpc(item.Key).DiscreteTags
                               .SingleOrDefault(x => x.NumTag == tag.NumTag);
                    if (tagD != null)
                    {
                        tagD.Legend         = tag.NameTag;
                        tagD.Color          = tag.Color;
                        tagD.Koef           = tag.Koef;
                        tagD.ChangeVal      = tag.ChangeVal;
                        tagD.SaveByTime     = tag.SaveByTime;
                        tagD.RarelyChanging = tag.RarelyChanging;
                        break;
                    }

                    var tagA = OpcServer.GetInstance().GetOpc(item.Key).AnalogTags
                               .SingleOrDefault(x => x.NumTag == tag.NumTag);
                    if (tagA != null)
                    {
                        tagA.Legend         = tag.NameTag;
                        tagA.Color          = tag.Color;
                        tagA.Koef           = tag.Koef;
                        tagA.ChangeVal      = tag.ChangeVal;
                        tagA.SaveByTime     = tag.SaveByTime;
                        tagA.RarelyChanging = tag.RarelyChanging;
                        break;
                    }
                }
            }
        }