You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
399 lines
14 KiB
399 lines
14 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.CheckTime;
|
|
using QMFrameWork.Data;
|
|
using System.Data;
|
|
using QMAPP.Entity;
|
|
|
|
namespace QMAPP.FJC.DAL.CheckTime
|
|
{
|
|
/// </summary>
|
|
/// 模块名称:本地库无记录的 时间验证
|
|
/// 作 者:张松男
|
|
/// 编写日期:2020年03月00日
|
|
/// </summary>
|
|
public class ProductTimeDAL
|
|
{
|
|
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public ProductTime Get(ProductTime info)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
info = session.Get<ProductTime>(info);
|
|
}
|
|
return info;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(ProductTime condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
//if (string.IsNullOrEmpty(page.SortExpression))
|
|
// page.SortExpression = "CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
// 对应多种数据库
|
|
//string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
page = session.GetDataPage<ProductTime>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取全部规则
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ProductTime> GetAllList()
|
|
{
|
|
try
|
|
{
|
|
string sql = "SELECT * FROM [T_MD_PRODUCT_TIMECHECK]";
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<ProductTime>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(ProductTime condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT [PID],[CWorkLoc_Code],[PWorkLoc_Code],[PWorkLoc_Column],[Product_Column],[Check],[Operator],[Check_Type],[Check_Value],[Check_Table],[Check_Column],[Pwhere],[Remark],[CREATEDATE],[CREATEUSER],[UPDATEDATE],[UPDATEUSER]");
|
|
sqlBuilder.Append("FROM [T_MD_PRODUCT_TIMECHECK] ");
|
|
//whereBuilder.Append(" AND FLGDEL<> '1' ");
|
|
//查询条件
|
|
|
|
////查询条件
|
|
//if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND FACTORY_CODE = @FACTORY_CODE ");
|
|
// parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
|
//}
|
|
//if (string.IsNullOrEmpty(condition.REGEX) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND REGEX LIKE @REGEX ");
|
|
// parameters.Add(new DataParameter { ParameterName = "REGEX", DataType = DbType.String, Value = "%" + condition.REGEX + "%" });
|
|
//}
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 信息是否重复
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool Exists(ProductTime info)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(0) FROM T_MD_PRODUCT_TIMECHECK");
|
|
if (info.PID == null)
|
|
{
|
|
info.PID = "";
|
|
}
|
|
whereBuilder.Append(" AND PID <> @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
|
|
|
|
//添加进行无重复字段判断代码
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
|
|
}
|
|
return count > 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(ProductTime info)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<ProductTime>(info);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(ProductTime info)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<ProductTime>(info);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 逻辑删除
|
|
/// <summary>
|
|
/// 逻辑删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(ProductTime info)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("delete T_MD_PRODUCT_TIMECHECK ");
|
|
sqlBuilder.Append("WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = info.PID });
|
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public DateTime GetServiceDateTime()
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
try
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sqlScript = @"select GetDATE() as time ";
|
|
DataTable datatable = new DataTable();
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
datatable = session.GetTable(sqlScript, parameters.ToArray());
|
|
}
|
|
|
|
if (datatable.Rows.Count > 0)
|
|
{
|
|
string datetimestr = datatable.Rows[0]["time"].ToString();
|
|
return DateTime.Parse(datetimestr);
|
|
}
|
|
|
|
return DateTime.Now;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据工位查询出配置
|
|
/// </summary>
|
|
/// <param name="locCode"></param>
|
|
/// <returns></returns>
|
|
public ProductTime GetTimeCheckCfg(string locCode, string DAI_Code)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
DateTime dateTime = DateTime.MinValue;
|
|
DataTable dataTable = new DataTable();
|
|
ProductTime timeCheck = new ProductTime();
|
|
string sqlScript = $" select * from T_MD_PRODUCT_TIMECHECK where CWorkLoc_Code ='{locCode}' and DAI_Code = '{DAI_Code}' and [Check]='1' order by UPDATEDATE desc,CREATEDATE desc ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
dataTable = session.GetTable(sqlScript, parameters.ToArray());
|
|
}
|
|
|
|
|
|
if (dataTable.Rows.Count == 0)
|
|
{
|
|
return null; ;
|
|
}
|
|
else
|
|
{
|
|
DataRow row = dataTable.Rows[0];
|
|
|
|
timeCheck.PID = row["PID"].ToString();
|
|
timeCheck.CWorkLoc_Code = row["CWorkLoc_Code"].ToString();
|
|
timeCheck.PWorkLoc_Code = row["PWorkLoc_Code"].ToString();
|
|
timeCheck.PWorkLoc_Column = row["PWorkLoc_Column"].ToString();
|
|
timeCheck.Product_Column = row["Product_Column"].ToString();
|
|
timeCheck.Check = row["Check"].ToString();
|
|
timeCheck.Operator = row["Operator"].ToString();
|
|
timeCheck.Check_Type = row["Check_Type"].ToString();
|
|
timeCheck.Check_Value = row["Check_Value"].ToString();
|
|
timeCheck.Check_Table = row["Check_Table"].ToString();
|
|
timeCheck.Check_Column = row["Check_Column"].ToString();
|
|
timeCheck.Remark = row["Remark"].ToString();
|
|
if (DateTime.TryParse(row["CREATEDATE"].ToString(), out dateTime))
|
|
{
|
|
timeCheck.CREATEDATE = dateTime;
|
|
}
|
|
timeCheck.CREATEUSER = row["CREATEUSER"].ToString();
|
|
timeCheck.UPDATEUSER = row["UPDATEUSER"].ToString();
|
|
if (DateTime.TryParse(row["CREATEDATE"].ToString(), out dateTime))
|
|
{
|
|
timeCheck.UPDATEDATE = dateTime;
|
|
}
|
|
timeCheck.Column1 = row["Column1"].ToString();
|
|
timeCheck.Column2 = row["Column2"].ToString();
|
|
timeCheck.PWhere = row["PWhere"].ToString();
|
|
timeCheck.DAI_Code = row["DAI_Code"].ToString();
|
|
timeCheck.Check_ValueTo = row["Check_ValueTo"].ToString();
|
|
}
|
|
return timeCheck;
|
|
}
|
|
|
|
public DataTable GetConfigValue(ProductTime timeCheckModel, string productCode)
|
|
{
|
|
DataTable dataTable = new DataTable();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sqlScript = $" select {timeCheckModel.Check_Column} as CheckColumnValue from {timeCheckModel.Check_Table} where {timeCheckModel.PWorkLoc_Column} ='{timeCheckModel.PWorkLoc_Code}' and {timeCheckModel.Product_Column}='{productCode}' ";
|
|
if (!string.IsNullOrEmpty(timeCheckModel.PWhere))
|
|
{
|
|
sqlScript = sqlScript + " and " + timeCheckModel.PWhere;
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
dataTable = session.GetTable(sqlScript, parameters.ToArray());
|
|
}
|
|
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
return dataTable;
|
|
|
|
}
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(ProductTime model)
|
|
{
|
|
DataTable dt = null;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sql = this.GetQuerySql(model, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
dt = session.GetTable(sql, parameters.ToArray());
|
|
dt.TableName = "T_MD_PRODUCT_TIMECHECK";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|