using Maticsoft.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pms.UserEvent.Model
{
    public class TaskDatasDAL
    {
        public static bool Add(TaskDatas task)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append($"insert into PLCCallTask([TaskID],[TaskType],[TaskStatus],[CallTime],[Materials],CarType) VALUES ('{task.TaskID}',{task.TaskType},'{task.TaskStatus}','{task.CallTime}','{task.Materials}',{task.CarType})");
            return DbHelperSQL.ExecuteSql(sql.ToString()) > 0 ? true : false;
        }

        public static DataTable GetList(string strWhere)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append($"select * from [PLCCallTask]");
            if (strWhere != "")
            {
                sql.Append($" where {strWhere}");
            }
            return DbHelperSQL.Query(sql.ToString()).Tables[0];
        }
        public static bool UpdateStatus(string status, string TaskID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append($"update [PLCCallTask] set TaskStatus='{status}' where TaskID='{TaskID}'");
            return DbHelperSQL.ExecuteSql(sql.ToString()) > 0 ? true : false;
        }

        /// <summary>
        /// TaskData 数据 转存到 HistoryTaskData
        /// </summary>
        /// <param name="TaskID"></param>
        public static void Datatransform(string TaskID)
        {
            string strSql = " insert into HisPLCCallTask select * from PLCCallTask where TaskID = '" + TaskID + "'";
            if (DbHelperSQL.ExecuteSql(strSql) > 0)
            {
                strSql = " delete from PLCCallTask where TaskID = '" + TaskID + "'";
                DbHelperSQL.ExecuteSql(strSql);
            }
        }
    }
}
