using DatabaseClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SlMesDbIterface
{
    public class solveUploadData { 

        public static DataTable GetUpLoadData(int dataType, string tableName, out string erorrMessage)
        {
            erorrMessage = "";
            DataTable dt = new DataTable();
            var dbClient = new DBClientFactory("mysql").Create();
            dbClient.Connect(Program.MySqlConnectString);
            try
            {
                string sql = "select * from " + tableName + " WHERE S001 = '" + dataType.ToString() + "' AND S028 = '0' order by S029 DESC limit 10";
                dt = dbClient.ExecQuery(sql);
            }
            catch (Exception err)
            {
                erorrMessage = err.Message;
            }
            return dt;
        }
    
        public static void UpDateUpLoadData(int id, string tableName, string resCode, string resMsg)
        {
     
            var dbClient = new DBClientFactory("mysql").Create();
            dbClient.Connect(Program.MySqlConnectString);
            try
            {
                string sql = "update " + tableName + " set S028 = '" + resCode
                    + "', S029 = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "', S030 = '" + resMsg + "'" 
                    + " WHERE id = '" + id.ToString() + "'";
                dbClient.ExecNonQuery(sql);
            }
            catch (Exception err)
            {
            }
        }

    }
}
