using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.DAL
{
///
/// InspectRecordDetail
///
public partial class InspectRecordDetail : BaseDAL
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get
{
return ConfigHelper.RecordConnectionConfig;
}
}
///
///
///
///
///
public static string GetTableName(int Year)
{
return string.Format("inspect_record_detail{0}", Year);
}
///
///
///
///
///
public static string GetTableName(DateTime dt)
{
return string.Format("inspect_record_detail{0}", dt.ToString("yyyy"));
}
///
///
///
///
///
public static string GetTableName(string dt)
{
if (string.IsNullOrEmpty(dt))
return string.Format("inspect_record_detail{0}", DateTime.Today.ToString("yyyy"));
return string.Format("inspect_record_detail{0}", dt.Substring(0, 4));
}
///
///
///
///
///
///
public List GetByRecordID(int RecordYear, long RecordID)
{
var strSql = string.Format("select * FROM {0} WHERE recordid={1} ", InspectRecordDetail.GetTableName(RecordYear), RecordID);
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Ado.SqlQuery(strSql);
}
//using (var db = new SqlSugarClient(ConnectionConfig))
//{
// return db.Queryable()
// .Where(x => x.RecordID == RecordID) .ToList();
//}
}
///
///
///
///
///
///
public List GetDetailsByRecordID(long RecordID, DateTime recordDay)
{
if (RecordID <= 0)
return null;
var strSql = string.Format("select * FROM {0} WHERE recordid={1} ", InspectRecordDetail.GetTableName(recordDay), RecordID);
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Ado.SqlQuery(strSql);
}
//using (var db = new SqlSugarClient(ConnectionConfig))
//{
// return db.Queryable()
// .Where(x => x.RecordID == RecordID).ToList();
//}
}
///
/// 仅仅获取
///
///
///
///
public List GetDetailByContentID(long ContentID, int RecordYear)
{
var strSql = string.Format("select * FROM {0} WHERE contentid={1} ", InspectRecordDetail.GetTableName(RecordYear), ContentID);
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Ado.SqlQuery(strSql);
}
//using (var db = new SqlSugarClient(ConnectionConfig))
//{
// return db.Queryable()
// .Where(x => x.ContentID == ContentID).ToList();
//}
}
///
/// 仅仅获取
///
///
///
///
///
public List GetDetailByContentID(long ContentID, DateTime StartDay, DateTime EndDay)
{
if (ContentID <= 0)
return null;
var strSql = string.Format("select * FROM {0} WHERE contentid={1} and time>'{2}' and time<'{3}' ",
InspectRecordDetail.GetTableName(StartDay), ContentID, StartDay, EndDay);
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Ado.SqlQuery(strSql);
}
//using (var db = new SqlSugarClient(ConnectionConfig))
//{
// return db.Queryable()
// .Where(x => x.ContentID == ContentID && x.Time > StartDay && x.Time < EndDay).ToList();
//}
}
///
///
///
///
///
///
public bool SaveDetails(DateTime RecordDay, List Details)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
StringBuilder strSql4Detail = new StringBuilder();
strSql4Detail.AppendFormat("update {0} set ", InspectRecordDetail.GetTableName(RecordDay));
strSql4Detail.Append(" value=@value,");
strSql4Detail.Append(" status=@status,");
strSql4Detail.Append(" time=@time ");
strSql4Detail.Append(" where id=@id ");
foreach (var detail in Details)
{
if(detail.ID > 0)
{
db.Ado.ExecuteCommand(strSql4Detail.ToString(), new List(){
new SugarParameter("@value",detail.Value),
new SugarParameter("@status",detail.Status) ,
new SugarParameter("@time",DateTime.Now),
new SugarParameter("@id",detail.ID)});
}
}
}
return true;
}
}
}