using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Common
{
    public sealed class AppUtils
    {
        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <returns></returns>
        private static string GetConnectingString()
        {
            var databaseSettings = ConfigurationManager.GetSection("databaseSettings") as NameValueCollection;
            return databaseSettings["connectionString"];
        }
        /// <summary>
        /// 重置回路当天开启时长
        /// </summary>
        public static void ResetHostModalTime()
        {
            Task.Factory.StartNew(() =>
            {
                using (IDbConnection connection = new SqlConnection(GetConnectingString()))
                {
                    using (IDbCommand command = connection.CreateCommand())
                    {
                        connection.Open();
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "UpdateHostModalRecords";
                        command.ExecuteNonQuery();
                    }
                }
            });
        }
        /// <summary>
        /// 统计回路能耗
        /// </summary>
        public static void StatisticHostModalEnergy()
        {
            using (IDbConnection connection = new SqlConnection(GetConnectingString()))
            {
                using (IDbCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "QueryRoomTypeModal_Power";
                    command.ExecuteNonQuery();
                }
            }
        }
    }
}
