using Dapper;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using Siger.Middlelayer.Dapper.Data;
using System.Text;
using Siger.Middlelayer.Redis;

namespace Siger.Middlelayer.Dapper
{
    public class CNCRetrospectRepository : DapperRepositoryBase
    {
        public CNCRetrospectRepository(int companyId, int projectId) : base(companyId, projectId)
        {
        }

        public IEnumerable<CNCRetrospect> GetCNCRetrospect(int machineId, string sn)
        {
            using (var conn = GetDbConnection())
            {
                var sql = string.Format("SELECT id,MachineID,CycleCounter,Pn,Spn,Fro,Sro,Sn,SpindleID,ToolNum,DataTime,UpdateTime from RET_Retrospect where MachineID={0} and Sn='{1}'", machineId, sn);

                var list = conn.Query<CNCRetrospect>(sql);
                return list;
            }
        }
        /// <summary>
        /// 取最新一条
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Complate> GetlastRecord()
        {
            using (var conn = GetDbConnection())
            {
                var sql = string.Format("SELECT  id,t,barcode FROM complete ORDER BY id DESC LIMIT 1");

                var list = conn.Query<Complate>(sql);
                return list;
            }
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
