Ejemplo n.º 1
0
        public static List<OPCField_ex> ProcessDataQuery(OPCStationInfo Station, string ToolServer)
        {
            OleDbCommand mCommand = new OleDbCommand("ProcessDataQuery");
            mCommand.CommandType = CommandType.StoredProcedure;
            OleDbConnection mConnection = new OleDbConnection(ToolServer);
            OleDbParameter IdIn = new OleDbParameter("@station", OleDbType.Integer);
            IdIn.Value = Station.StationID;
            mCommand.Parameters.Add(IdIn);
            mConnection.Open();
            mCommand.Connection = mConnection;
            OleDbDataReader mReader;
            mReader = mCommand.ExecuteReader();
            List<OPCField_ex> fields = new List<OPCField_ex>();

            while (mReader.Read())
            {
                OPCField_ex f = new OPCField_ex();
                f.StationInfo = Station;
                f.ScaleFactor = mReader.GetFloat(11);
                f.ClientTopicID = mReader.GetString(2);
                f.ClientItemID = mReader.GetString(1);
                f.DeviceType = (short)mReader.GetInt32(0);
                f.OPCItemID = mReader.GetString(3);
                f.RequestFromOPC = false;
                f.OPCprefix = mReader.GetString(4);
                f.OPCTopicID = mReader.GetString(5);
                //f.Type = (Int32)mReader["DataType"];********************************
                try
                {
                  //  f.DataType = GetTypeFromNum((Int32)mReader["DataType"]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message+"  "+mReader.GetString(9));
                }
               // if (f.DataType != typeof(float))
               // {

               // }
                fields.Add(f);
            }

            mReader.Close();
            mConnection.Close();
            return fields;
        }
Ejemplo n.º 2
0
 public void InsertnewOPCField(OPCField_ex F, MySqlConnection conn)
 {
     MySqlCommand c = new MySqlCommand("INSERT into fields ( Name ) VALUES (  ) ", conn);
 }
Ejemplo n.º 3
0
        public static void GetFromItemTable(List<OPCField_ex> OPCFields, string ToolServer)
        {
            Dictionary<int,string> UnitLookup = new Dictionary<int,string>();
            Dictionary<int, string> TypeLookup = new Dictionary<int, string>();

            OleDbCommand mCommand = new OleDbCommand("SELECT * FROM Items WHERE 1");
            mCommand.CommandType = CommandType.Text;
            OleDbConnection mConnection = new OleDbConnection(ToolServer);
            mConnection.Open();
            mCommand.Connection = mConnection;

            OleDbCommand FillDictionary = new OleDbCommand("SELECT UnitType,UnitTypeName FROM UnitType WHERE 1");
            FillDictionary.CommandType = CommandType.Text;
            FillDictionary.Connection = mConnection;
            OleDbDataReader FillReader = FillDictionary.ExecuteReader();

            while(FillReader.Read())
            {
                UnitLookup.Add((int)FillReader[0],(string)FillReader[1]);
            }

            FillReader.Close();

            OleDbCommand FillDictionaryType = new OleDbCommand("SELECT DataType,DataTypeName FROM DataType WHERE 1");
            FillDictionaryType.CommandType = CommandType.Text;
            FillDictionaryType.Connection = mConnection;
            OleDbDataReader FillReaderType = FillDictionaryType.ExecuteReader();

            while (FillReaderType.Read())
            {
                TypeLookup.Add((int)FillReaderType[0], (string)FillReaderType[1]);
            }

            FillReaderType.Close();

            OleDbDataReader mReader;
            mReader = mCommand.ExecuteReader();
            List<OPCField_ex> fields = new List<OPCField_ex>();
            int allreadyhave = 0;

            Console.Write("enumerating all opc items to pull OPC Scale Factor");

            try
            {
                while (mReader.Read())
                {
                    OPCField_ex f = new OPCField_ex();

                    f.ClientTopicID = (string)mReader["ClientTopicID"];

                    string test = f.ClientTopicID;
                    Debug.WriteLine(test);
                    if (!test.Contains("STATION"))
                    {
                        continue;
                    }

                   // f.DataType =
                    f.Type = TypeLookup[(int)mReader["DataType"]];
                    // Console.Write(".");
                    f.ScaleFactor = (float)mReader["OPCScaleFactor"];

                    if(  mReader["UnitType"].GetType() == typeof(System.DBNull) )
                    {

                    }
                    else
                    {
                        int lookup_unit = (int)mReader["UnitType"];

                        f.units = UnitLookup[lookup_unit];
                    }

                    string number = f.ClientTopicID.Substring(f.ClientTopicID.IndexOf("STATION") + 7, 2);
                    int n = int.Parse(number);

                    if (n < 99 && n < 0)
                    {
                        throw new Exception();
                    }

                    f.StationInfo = GetStationFromNumber(n);

                    f.ClientItemID = (string)mReader["ClientItemID"];
                    try
                    {
                        f.OPCItemID = (string)mReader["OPCItemID"];
                    }
                    catch
                    {
                        continue;
                    }
                    try
                    {
                        f.OPCprefix = (string)mReader["OPCPrefix"];
                    }
                    catch
                    {

                    }
                    try
                    {
                        f.OPCTopicID = (string)mReader["OPCTopicID"];
                    }
                    catch
                    {

                    }
                   // OPCField_ex AlreadExist = OPCFields.Where(b => b.OPC_Lookup == f.OPC_Lookup).First();
                   // if (AlreadExist == null)
                  //  {
                        OPCFields.Add(f);
                        string stationT = "NULL";
                        if(f.StationInfo != null)
                        {
                            stationT = f.StationInfo.StationID.ToString();
                        }
                        Console.WriteLine(string.Format("Added field: {0} scale {1} station {2}",f.OPC_Lookup,f.ScaleFactor,stationT));
                  //  }
                   // else
                  //  {
                   //     allreadyhave++;
                   //     if (AlreadExist.ScaleFactor != f.ScaleFactor)
                   //     {

                    //    }
                   // }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                mReader.Close();
                mConnection.Close();
            }
        }