Exemple #1
0
        /// <summary>
        ///		Update a DatapointNode in the database
        /// </summary>
        /// <param name="Node">
        ///		DatapointNode that should be updated
        /// </param>
        /// <returns>
        ///		true, if the node is updated
        ///		false, if no node is updated
        /// </returns>
        public Boolean UpdateNode(DatapointNode Node)
        {
            // Command that will be send to the databse
            MySqlCommand Command = this.Connection.CreateCommand();

            // Update a row in the databse with the given node id
            // UPDATE						> Update rows of a table
            // SET	[colum name] = [value],	> Set a column to the given value
            //		[colum name] = [value]	> Set a column to the given value
            // WHERE object_id = {0}		> Update all rows where the column object_id matches the given id
            Command.CommandText = String.Format(
                "UPDATE object_tree SET object_parent_id={0}, object_name='{1}', object_description='{2}', object_last_updated='{3}', datapoint_type={4}, datapoint_unit='{5}', datapoint_last_value='{6}', datapoint_last_updated='{7}' WHERE object_id={8}",
                Node.GetParentID(), Node.GetName(), Node.GetDescription(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Node.GetDatapointType(), Node.GetUnit(), Node.GetLastValue(), Node.GetLastValueUpdate().ToString("yyyy-MM-dd HH:mm:ss"), Node.GetID()
                );
            Command.Connection = this.Connection;

            // Execute the command and get the number of rows that are affected by the command
            Int32 AffectedRows = Command.ExecuteNonQuery();

            // If no rows where affected return false
            if (AffectedRows == 0)
            {
                return(false);
            }

            // Row successfully updated
            return(true);
        }
Exemple #2
0
        /// <summary>
        ///		Insert a DatapointNode into the database
        /// </summary>
        /// <param name="Node">
        ///		DatapointNode that should be insert
        /// </param>
        /// <returns>
        ///		true, if a row was inserted
        ///		false, if no row was inserted
        /// </returns>
        public Boolean InsertNode(DatapointNode Node)
        {
            // Command that will be send to the databse
            MySqlCommand Command = this.Connection.CreateCommand();

            // Update a row in the databse with the given node id
            // UPDATE						> Update rows of a table
            // SET	[colum name] = [value],	> Set a column to the given value
            //		[colum name] = [value]	> Set a column to the given value
            // WHERE object_id = {0}		> Update all rows where the column object_id matches the given id
            Command.CommandText = String.Format(
                "INSERT INTO object_tree ( object_parent_id , object_type ,  object_name , object_description , object_last_updated , datapoint_type , datapoint_unit , datapoint_last_value , datapoint_last_updated ) Values( {0} , {1} , '{2}' , '{3}' , '{4}' , '{5}' , '{6}' , '{7}' , '{8}' )",
                Node.GetParentID(), DatapointNode.NODE_TYPE, Node.GetName(), Node.GetDescription(), Node.GetLastUpdated().ToString("yyyy-MM-dd HH:mm:ss"), Node.GetDatapointType().ToString(), Node.GetUnit(), Node.GetLastValue(), Node.GetLastValueUpdate().ToString("yyyy-MM-dd HH:mm:ss")
                );
            Command.Connection = this.Connection;

            // Execute the command and get the number of rows that are affected by the command
            Int32 AffectedRows = Command.ExecuteNonQuery();

            // Set the ID of the node to the ID that was provided by the database
            Node.SetID(Command.LastInsertedId);

            // If no rows where affected return false
            if (AffectedRows == 0)
            {
                return(false);
            }

            // Row successfully insert
            return(true);
        }
Exemple #3
0
        public void LoadDatapointByID(Int64 nodeID, DatabaseFacade database)
        {
            this.Database = database;
            this.Database.OpenConnection();
            DatapointNode datapoint = this.Database.GetDatapointNodeByID(nodeID);
            FolderNode    parent    = this.Database.GetFolderNodeByID(datapoint.GetParentID());

            this.Database.CloseConnection();

            this.DatapointID                      = datapoint.GetID();
            this.LabelDatapointName.Text          = datapoint.GetName();
            this.AnalyseDatapointName.Text        = datapoint.GetName();
            this.AnalyseDatapointDescription.Text = datapoint.GetDescription();
            this.LabelDatapointDescription.Text   = datapoint.GetDescription();
            this.LabelDatapointID.Text            = datapoint.GetID().ToString();
            this.LabelDatapointParent.Text        = parent.GetName();
            if (datapoint.GetDatapointType() == DatapointNode.TYPE_BOOL)
            {
                this.LabelDatapointType.Text = "Bool (Wahr/Falsch)";
            }
            if (datapoint.GetDatapointType() == DatapointNode.TYPE_FLOATING_POINT)
            {
                this.LabelDatapointType.Text = "Fließkommazahl";
            }
            if (datapoint.GetDatapointType() == DatapointNode.TYPE_INTEGER)
            {
                this.LabelDatapointType.Text = "Ganzzahl";
            }
            if (datapoint.GetDatapointType() == DatapointNode.TYPE_TEXT)
            {
                this.LabelDatapointType.Text = "Text";
            }
            this.LabelDatapointUnit.Text       = datapoint.GetUnit();
            this.LabelDatapointLastValue.Text  = datapoint.GetLastValue() + " (" + datapoint.GetLastValueUpdate() + ")";
            this.LabelDatapointLastUpdate.Text = datapoint.GetLastUpdated().ToString();

            DateTime From     = DateTime.Now;
            TimeSpan FromTime = new TimeSpan(0, 0, 0);

            From = From.Date + FromTime;

            DateTime To     = DateTime.Now;
            TimeSpan ToTime = new TimeSpan(23, 59, 59);

            To = To.Date + ToTime;

            DrawDatapointChart(ChartDatapoint, From, To);
        }
Exemple #4
0
 static void GetSubnodes(Int64 ParentID, String Indent)
 {
     try {
         if (ParentIdDictionary.ContainsKey(ParentID.ToString()))
         {
             List <AbstractObjectNode> subNodes = ParentIdDictionary[ParentID.ToString()];
             foreach (AbstractObjectNode currentSubNode in subNodes)
             {
                 if (currentSubNode.GetType() == FolderNode.NODE_TYPE)
                 {
                     FolderNode Node = Database.GetFolderNodeByID(currentSubNode.GetID());
                     Console.ForegroundColor = ConsoleColor.Magenta;
                     Console.WriteLine("> " + Indent + Node.ToString());
                     Console.ForegroundColor = ConsoleColor.White;
                 }
                 if (currentSubNode.GetType() == DeviceNode.NODE_TYPE)
                 {
                     DeviceNode Node = Database.GetDeviceNodeByID(currentSubNode.GetID());
                     Console.ForegroundColor = ConsoleColor.Green;
                     Console.WriteLine("> " + Indent + Node.ToString());
                     Console.ForegroundColor = ConsoleColor.White;
                 }
                 if (currentSubNode.GetType() == DatapointNode.NODE_TYPE)
                 {
                     DatapointNode Node = Database.GetDatapointNodeByID(currentSubNode.GetID());
                     Console.ForegroundColor = ConsoleColor.Yellow;
                     Console.WriteLine("> " + Indent + Node.ToString());
                     Console.ForegroundColor = ConsoleColor.White;
                 }
                 GetSubnodes(currentSubNode.GetID(), Indent + "   ");
             }
         }
     } catch (Exception ex) {
         ConsoleWriteError(ex.Message);
     }
 }
Exemple #5
0
 public Boolean UpdateNode(DatapointNode Node)
 {
     return(this.DatabaseConnector.UpdateNode(Node));
 }
Exemple #6
0
 public Boolean InsertNode(DatapointNode Node)
 {
     return(this.DatabaseConnector.InsertNode(Node));
 }
Exemple #7
0
 public Boolean DeleteNode(DatapointNode Node)
 {
     return(this.DatabaseConnector.DeleteNodeByID(Node.GetID()));
 }
Exemple #8
0
        static void InsertExampleDatapointNodes(Int64 ParentID)
        {
            try {
                Console.Write("> Insert datapoint node...");
                Random        random        = new Random();
                DatapointNode datapointNode = new DatapointNode();
                datapointNode.SetName("Sauerstoff");
                datapointNode.SetParentID(ParentID);
                datapointNode.SetDescription("CO2Concentration");
                datapointNode.SetLastUpdated(DateTime.Now);
                datapointNode.SetDatapointType(DatapointNode.TYPE_INTEGER);
                datapointNode.SetUnit("PPM");
                datapointNode.SetLastValue(random.Next(300, 3000).ToString());
                datapointNode.SetLastValueUpdate(DateTime.Now);
                Boolean inserted = Database.InsertNode(datapointNode);
                if (inserted)
                {
                    ConsoleWriteSuccess(datapointNode.ToString());
                }
                else
                {
                    ConsoleWriteError("Could not insert datapoint node");
                }
            } catch (Exception ex) {
                ConsoleWriteError(ex.Message);
            }

            try {
                Console.Write("> Insert datapoint node...");
                Random        random        = new Random();
                DatapointNode datapointNode = new DatapointNode();
                datapointNode.SetName("Lautstärke");
                datapointNode.SetParentID(ParentID);
                datapointNode.SetDescription("Loudness");
                datapointNode.SetLastUpdated(DateTime.Now);
                datapointNode.SetDatapointType(DatapointNode.TYPE_INTEGER);
                datapointNode.SetUnit("DB");
                datapointNode.SetLastValue(random.Next(20, 130).ToString());
                datapointNode.SetLastValueUpdate(DateTime.Now);
                Boolean inserted = Database.InsertNode(datapointNode);
                if (inserted)
                {
                    ConsoleWriteSuccess(datapointNode.ToString());
                }
                else
                {
                    ConsoleWriteError("Could not insert root node");
                }
            } catch (Exception ex) {
                ConsoleWriteError(ex.Message);
            }

            try {
                Console.Write("> Insert datapoint node...");
                Random        random        = new Random();
                DatapointNode datapointNode = new DatapointNode();
                datapointNode.SetName("Temperatur");
                datapointNode.SetParentID(ParentID);
                datapointNode.SetDescription("Temperature");
                datapointNode.SetLastUpdated(DateTime.Now);
                datapointNode.SetDatapointType(DatapointNode.TYPE_FLOATING_POINT);
                datapointNode.SetUnit("°C");
                datapointNode.SetLastValue(random.NextDouble().ToString("0.00"));
                datapointNode.SetLastValueUpdate(DateTime.Now);
                Boolean inserted = Database.InsertNode(datapointNode);
                if (inserted)
                {
                    ConsoleWriteSuccess(datapointNode.ToString());
                }
                else
                {
                    ConsoleWriteError("Could not insert root node");
                }
            } catch (Exception ex) {
                ConsoleWriteError(ex.Message);
            }
        }