///// <summary>
        ///// Sets the status value. Language-KeyValue is the combination of "MES-CON OS TPM.Status.[item][itemStatus]".
        ///// </summary>
        ///// <param name="item">The item to update.</param>
        ///// <param name="itemStatus">The status of the item to update.</param>
        ///// <param name="titelStandardText">The title standard text.</param>
        ///// <param name="textStandardText">The text standard text.</param>
        ///// <param name="color">The color.</param>
        ///// <param name="millisecondsToExpire">The milliseconds to expire.</param>
        ///// <param name="parameter">Parameter to be inserted in the TextReference.Text. Will be inserted for %P in oder of appearance.</param>
        ///// <returns>
        ///// True if successful, else false.
        ///// </returns>
        ///// <exception cref="System.Exception">Item must not be Empty
        ///// or
        ///// Item must start with \MES-CON OS TPM.Status.\.</exception>
        //public static bool SetStatusValue(
        //                                  string item,
        //                                  string itemStatus,
        //                                  string titelStandardText,
        //                                  string textStandardText,
        //                                  System.Drawing.Color color,
        //                                  int millisecondsToExpire,
        //                                  params string[] parameter)
        //{
        //    if (item == string.Empty)
        //    {
        //        throw new Exception("Item must not be Empty");
        //    }
        //    else if (!item.StartsWith("MES-CON OS TPM.Status."))
        //    {
        //        throw new Exception("Item must start with \"MES-CON OS TPM.Status.\"");
        //    }
        //    else
        //    {
        //        lock (LockStatusCache)
        //        {
        //            bool titleOkay = false;
        //            bool textOkay = false;
        //            string keyValue = string.Concat(item, itemStatus);

        //            titleOkay = statusCache.ContainsKey(keyValue + ".Title") && statusCache[keyValue + ".Title"].Equals(titelStandardText);
        //            if (!titleOkay)
        //            {
        //                if (BuildLanguageObject(keyValue + ".Title", titelStandardText))
        //                {
        //                    statusCache.Add(keyValue + ".Title", titelStandardText);
        //                    titleOkay = true;
        //                }
        //            }

        //            string textStandard = textStandardText.Substring(0, textStandardText.Length > 4000 ? 4000 : textStandardText.Length);
        //            textOkay = statusCache.ContainsKey(keyValue + ".Text") && statusCache[keyValue + ".Text"].Equals(textStandard);
        //            if (!textOkay)
        //            {
        //                if (BuildLanguageObject(keyValue + ".Text", textStandard))
        //                {
        //                    statusCache.Add(keyValue + ".Text", textStandard);
        //                    textOkay = true;
        //                }
        //            }

        //            if (titleOkay && textOkay)
        //            {
        //                DataTable parameters = new DataTable();
        //                parameters.Columns.Add("Item", typeof(string));
        //                parameters.Columns.Add("ParameterNumber", typeof(int));
        //                parameters.Columns.Add("ParameterValue", typeof(string));

        //                for (int i = 0; i < parameter.Length; i++)
        //                {
        //                    parameters.Rows.Add(item, i, parameter[i].Substring(0, parameter[i].Length > 4000 ? 4000 : parameter[i].Length));
        //                }

        //                SqlCommand sqlCommand = new SqlCommand("P_TPM_InsertOrUpdateT_TPM_Status");
        //                sqlCommand.CommandType = CommandType.StoredProcedure;
        //                sqlCommand.Parameters.Add("Item", SqlDbType.NVarChar, 128);
        //                sqlCommand.Parameters.Add("ItemStatus", SqlDbType.NVarChar, 50);
        //                sqlCommand.Parameters.Add("TitelStandardText", SqlDbType.NVarChar, 256);
        //                sqlCommand.Parameters.Add("TextStandardText", SqlDbType.NVarChar, 512);
        //                sqlCommand.Parameters.Add("DisplayColorAlpha", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("DisplayColorRed", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("DisplayColorGreen", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("DisplayColorBlue", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("Description", SqlDbType.NVarChar, 256);
        //                sqlCommand.Parameters.Add("MSToStatusExpires", SqlDbType.Int);
        //                sqlCommand.Parameters.Add("StandardValue", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("AllowPush", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("Show", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("Position", SqlDbType.TinyInt);
        //                sqlCommand.Parameters.Add("ParameterTable", SqlDbType.Structured);

        //                sqlCommand.Parameters["Item"].Value = item;
        //                sqlCommand.Parameters["ItemStatus"].Value = itemStatus;
        //                sqlCommand.Parameters["TitelStandardText"].Value = titelStandardText;
        //                sqlCommand.Parameters["TextStandardText"].Value = textStandardText;
        //                sqlCommand.Parameters["DisplayColorAlpha"].Value = color.A;
        //                sqlCommand.Parameters["DisplayColorRed"].Value = color.R;
        //                sqlCommand.Parameters["DisplayColorGreen"].Value = color.G;
        //                sqlCommand.Parameters["DisplayColorBlue"].Value = color.B;
        //                sqlCommand.Parameters["Description"].Value = "Status " + item;
        //                sqlCommand.Parameters["MSToStatusExpires"].Value = millisecondsToExpire;
        //                sqlCommand.Parameters["StandardValue"].Value = 0;
        //                sqlCommand.Parameters["AllowPush"].Value = 1;
        //                sqlCommand.Parameters["Show"].Value = 1;
        //                sqlCommand.Parameters["Position"].Value = 0;
        //                sqlCommand.Parameters["ParameterTable"].Value = parameters;

        //                DataBaseFunctions.NonQuery(sqlCommand);

        //                return true;
        //            }
        //        }
        //    }

        //    return false;
        //}

        /// <summary>
        /// Sets the config value.
        /// </summary>
        /// <param name="userId">
        /// The user Id.
        /// </param>
        /// <param name="item">
        /// The item to update.
        /// </param>
        /// <param name="value">
        /// The value to update.
        /// </param>
        /// <returns>
        /// True if successful, else false.
        /// </returns>
        public static bool SetVisUserConfigValue(int userId, string item, string value)
        {
            if (item == string.Empty)
            {
                return(false);
            }

            if (
                DataBaseFunctions.NonQuery(
                    "UPDATE [dbo].[T_VIS_UserConfig] SET [ItemValue] = '" + value + "' WHERE [UserID] = " + userId
                    + " AND [Item] = '" + item + "'") == 0)
            {
                if (
                    DataBaseFunctions.NonQuery(
                        "INSERT INTO [dbo].[T_VIS_UserConfig] ([UserID], [Item], [ItemValue]) VALUES (" + userId + ", '"
                        + item + "', '" + value + "')") == 1)
                {
                    return(true);
                }

                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Does the action.
        /// </summary>
        /// <param name="actionName">
        /// Name of the action.
        /// </param>
        /// <param name="parameter1">
        /// The parameter1.
        /// </param>
        /// <param name="parameter2">
        /// The parameter2.
        /// </param>
        /// <param name="parameter3">
        /// The parameter3.
        /// </param>
        /// <param name="parameter4">
        /// The parameter4.
        /// </param>
        /// <param name="parameter5">
        /// The parameter5.
        /// </param>
        /// <param name="parameter6">
        /// The parameter6.
        /// </param>
        /// <param name="parameter7">
        /// The parameter7.
        /// </param>
        /// <param name="parameter8">
        /// The parameter8.
        /// </param>
        /// <param name="who">
        /// The who value.
        /// </param>
        /// <param name="timeoutInMs">
        /// The timeout in milliseconds.
        /// </param>
        /// <param name="reply">
        /// The reply.
        /// </param>
        /// <returns>
        /// 0 success (reply is valid)
        /// -1 action insert in DB failed
        /// -2 DataRow with reply not found in DB
        /// -3 Timeout.
        /// </returns>
        public static int DoAction(
            string actionName,
            string parameter1,
            string parameter2,
            string parameter3,
            string parameter4,
            string parameter5,
            string parameter6,
            string parameter7,
            string parameter8,
            string who,
            int timeoutInMs,
            out string reply)
        {
            DateTime now = DateTime.Now;
            string   sql = "INSERT INTO T_TPM_VIS_Action " + "([ActionName]" + ", [Parameter1]" + ", [Parameter2]"
                           + ", [Parameter3]" + ", [Parameter4]" + ", [Parameter5]" + ", [Parameter6]" + ", [Parameter7]"
                           + ", [Parameter8]" + ", [Who]" + ", [Time]" + ", [Reply])" + " VALUES " + "('" + actionName
                           + "'," + " '" + parameter1 + "'," + " '" + parameter2 + "'," + " '" + parameter3 + "'," + " '"
                           + parameter4 + "'," + " '" + parameter5 + "'," + " '" + parameter6 + "'," + " '" + parameter7
                           + "'," + " '" + parameter8 + "'," + " '" + who + "'," + " '" + now.ToString("s") + "','')";

            if (DataBaseFunctions.NonQuery(sql) > 0)
            {
                if (timeoutInMs > 0)
                {
                    while (now.AddMilliseconds(timeoutInMs) > DateTime.Now)
                    {
                        System.Threading.Thread.Sleep(100);
                        DataSet result =
                            DataBaseFunctions.Query("SELECT Reply FROM T_TPM_VIS_Action WHERE ActionName = '" + actionName + "' AND Time = '" + now.ToString("s") + "'");
                        if (DataBaseFunctions.TestDataSet(result, 1))
                        {
                            reply = result.Tables[0].Rows[0]["Reply"].ToString();
                            if (reply != string.Empty)
                            {
                                DataBaseFunctions.NonQuery("DELETE FROM T_TPM_VIS_Action WHERE ActionName = '" + actionName + "' AND Time = '" + now.ToString("s") + "'");
                                return(0);
                            }
                        }
                        else
                        {
                            DataBaseFunctions.NonQuery("DELETE FROM T_TPM_VIS_Action WHERE ActionName = '" + actionName + "' AND Time = '" + now.ToString("s") + "'");
                            reply = string.Empty;
                            return(-2);
                        }
                    }

                    DataBaseFunctions.NonQuery("DELETE FROM T_TPM_VIS_Action WHERE ActionName = '" + actionName + "' AND Time = '" + now.ToString("s") + "'");
                    reply = string.Empty;
                    return(-3);
                }

                reply = string.Empty;
                return(0);
            }

            reply = string.Empty;
            return(-1);
        }
        /// <summary>
        /// Builds the language object.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="standardText">
        /// The standard text.
        /// </param>
        /// <returns>
        /// If method was executed successfully.
        /// </returns>
        public static bool BuildLanguageObject(string item, string standardText)
        {
            DataBaseFunctions.NonQuery(
                "EXEC P_TPM_InsertOrUpdateAllLanguagesForLanguageObject @Object = '" + item + "', @StandardText = '"
                + standardText + "'");

            return(true);
        }
 /// <summary>
 /// Sets the action reply.
 /// </summary>
 /// <param name="actionName">
 /// Name of the action.
 /// </param>
 /// <param name="requestTime">
 /// The request time.
 /// </param>
 /// <param name="reply">
 /// The reply.
 /// </param>
 public static void SetActionReply(string actionName, DateTime requestTime, string reply)
 {
     DataBaseFunctions.NonQuery(
         "UPDATE T_TPM_VIS_Action SET Reply = '" + reply + "' WHERE ActionName = '" + actionName
         + "' AND Time = '" + requestTime.ToString("s") + "'");
 }