Beispiel #1
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);
        }
Beispiel #2
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);
     }
 }
Beispiel #3
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);
     }
 }
Beispiel #4
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;
                    }
                }
            }
        }