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.
1099 lines
42 KiB
1099 lines
42 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.Entity;
|
|
using QMAPP.FJC.Entity.ProduceManage;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMFrameWork.Log;
|
|
using QMAPP.DAL;
|
|
using QMAPP.FJC.Entity.Injection;
|
|
namespace QMAPP.FJC.DAL.Operation
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M13-1
|
|
/// 作 用:加工本体
|
|
/// 作 者:王庆男
|
|
/// 编写日期:2015年06月04日
|
|
///</summary>
|
|
public class MainDAL : BaseDAL
|
|
{
|
|
|
|
/// <summary>
|
|
/// 数据会话
|
|
/// </summary>
|
|
//public IDataSession BaseSession = null;
|
|
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Main Get(Main model)
|
|
{
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
model = BaseSession.Get<Main>(model);
|
|
}
|
|
else
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_AW_MAIN WHERE '1'='1'";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.MAINCODE) == false)
|
|
{
|
|
sql += " AND MAINCODE = @MAINCODE";
|
|
parameters.Add(new DataParameter("MAINCODE", model.MAINCODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<Main>(sqlChange, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Main condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "UPDATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Main>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部</returns>
|
|
public List<Main> GetList(Main condition)
|
|
{
|
|
string sql = null;
|
|
List<Main> list = new List<Main>();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<Main>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Main condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT M.PID ");
|
|
sqlBuilder.AppendLine(" ,M.MAINCODE ");
|
|
sqlBuilder.AppendLine(" ,M.SKID ");
|
|
sqlBuilder.AppendLine(" ,M.SKELETONCODE ");
|
|
sqlBuilder.AppendLine(" ,M.EID ");
|
|
sqlBuilder.AppendLine(" ,M.EPIDERMISCODE ");
|
|
sqlBuilder.AppendLine(" ,MA.HBTYPE AS HB ");
|
|
sqlBuilder.AppendLine(" ,MA.COLOR ");
|
|
sqlBuilder.AppendLine(" ,M.MACHINECODDE ");
|
|
sqlBuilder.AppendLine(" ,M.PROCESSSTATE ");
|
|
sqlBuilder.AppendLine(" ,M.STATUS ");
|
|
sqlBuilder.AppendLine(" ,M.CURRENTPROCESS ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCELINE ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTNAME ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTTCODE ");
|
|
sqlBuilder.AppendLine(" ,M.OUTFLAG ");
|
|
sqlBuilder.AppendLine(" ,M.SPID ");
|
|
sqlBuilder.AppendLine(" ,M.SENDCODE ");
|
|
sqlBuilder.AppendLine(" ,M.COMPLETETIME ");
|
|
sqlBuilder.AppendLine(" ,M.COMPLETEFLAG ");
|
|
sqlBuilder.AppendLine(" ,M.MATERIAL_CODE ");
|
|
sqlBuilder.AppendLine(" ,MA.MATERIAL_NAME ");
|
|
sqlBuilder.AppendLine(" ,MC.MATERIAL_TYPE_CODE AS MATERIAL_TYPE ");
|
|
sqlBuilder.AppendLine(" ,MC.MATERIAL_TYPE_NAME ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
|
|
|
|
|
|
|
sqlBuilder.Append("FROM T_AW_MAIN M");
|
|
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
|
|
sqlBuilder.Append(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL MA ON MA.MATERIAL_CODE=M.MATERIAL_CODE ");
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL_CLASS MC ON MC.MATERIAL_TYPE_CODE=MA.MATERIAL_TYPE_CODE ");
|
|
//查询条件
|
|
|
|
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.MAINCODE = @MAINCODE");
|
|
parameters.Add(new DataParameter { ParameterName = "MAINCODE", DataType = DbType.String, Value = condition.MAINCODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.MATERIAL_CODE = @MATERIAL_CODE");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.EPIDERMISCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND EPIDERMISCODE = @EPIDERMISCODE");
|
|
parameters.Add(new DataParameter { ParameterName = "EPIDERMISCODE", DataType = DbType.String, Value = condition.EPIDERMISCODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCELINE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCELINE = @PRODUCELINE");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCELINE", DataType = DbType.String, Value = condition.PRODUCELINE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.SPID) == false)
|
|
{
|
|
whereBuilder.Append(" AND SPID =@SPID");
|
|
parameters.Add(new DataParameter { ParameterName = "SPID", DataType = DbType.String, Value = condition.SPID });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false)
|
|
{
|
|
whereBuilder.Append(" AND CURRENTPROCESS =@CURRENTPROCESS");
|
|
parameters.Add(new DataParameter { ParameterName = "CURRENTPROCESS", DataType = DbType.String, Value = condition.CURRENTPROCESS });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.SENDCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND SENDCODE =@SENDCODE");
|
|
parameters.Add(new DataParameter { ParameterName = "SENDCODE", DataType = DbType.String, Value = condition.SENDCODE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.publicCode) == false)
|
|
{
|
|
whereBuilder.Append(" AND (EPIDERMISCODE =@publicCode OR SKELETONCODE =@publicCode OR MAINCODE = @publicCode)");
|
|
parameters.Add(new DataParameter { ParameterName = "publicCode", DataType = DbType.String, Value = condition.publicCode });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.COLOR) == false)
|
|
{
|
|
whereBuilder.Append(" AND MA.COLOR =@COLOR");
|
|
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.HB) == false)
|
|
{
|
|
whereBuilder.Append(" AND MA.HBTYPE =@HB");
|
|
parameters.Add(new DataParameter { ParameterName = "HB", DataType = DbType.String, Value = condition.HB });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.STATUS) == false)
|
|
{
|
|
whereBuilder.Append(" AND STATUS =@STATUS");
|
|
parameters.Add(new DataParameter { ParameterName = "STATUS", DataType = DbType.String, Value = condition.STATUS });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PROCESSSTATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PROCESSSTATE =@PROCESSSTATE");
|
|
parameters.Add(new DataParameter { ParameterName = "PROCESSSTATE", DataType = DbType.String, Value = condition.PROCESSSTATE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.COMPLETEFLAG) == false)
|
|
{
|
|
whereBuilder.Append(" AND COMPLETEFLAG =@COMPLETEFLAG");
|
|
parameters.Add(new DataParameter { ParameterName = "COMPLETEFLAG", DataType = DbType.String, Value = condition.COMPLETEFLAG });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.CREATEDATE >= @STARTCREATEDATE");
|
|
parameters.Add(new DataParameter { ParameterName = "STARTCREATEDATE", DataType = DbType.String, Value = condition.STARTCREATEDATE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.CREATEDATE <= @ENDCREATEDATE");
|
|
parameters.Add(new DataParameter { ParameterName = "ENDCREATEDATE", DataType = DbType.String, Value = condition.ENDCREATEDATE });
|
|
}
|
|
|
|
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="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(Main 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_AW_MAIN";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 信息是否重复
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsMain(Main model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_MAIN");
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND PID =@PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
}
|
|
//if (string.IsNullOrEmpty(model.) == false)
|
|
//{
|
|
//whereBuilder.Append(" AND AREACODE=@AREACODE");
|
|
//parameters.Add(new DataParameter { ParameterName = "AREACODE", DataType = DbType.String, Value = ""model.AREACODE + "" });
|
|
//}
|
|
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()));
|
|
}
|
|
if (count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最大编码
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
public PrintCode GetMaxMainCode(string materialCode)
|
|
{
|
|
//StringBuilder sqlBuilder = new StringBuilder();
|
|
//StringBuilder whereBuilder = new StringBuilder();
|
|
//string result = "";
|
|
//StringBuilder printeBuilder = new StringBuilder();
|
|
//try
|
|
//{
|
|
// sqlBuilder.Append("select isnull(max(substring(maincode,8,7)),0) from t_aw_main");
|
|
// printeBuilder.Append("select isnull(max(substring(maincode,8,7)),0) from T_AW_PRINTCODE");
|
|
// object o;
|
|
// object b;
|
|
// using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
// {
|
|
// o = (session.ExecuteSqlScalar(sqlBuilder.ToString()));
|
|
|
|
// b = (session.ExecuteSqlScalar(printeBuilder.ToString()));
|
|
// }
|
|
// if (Convert.ToInt32(o.ToString()) > Convert.ToInt32(b.ToString()))
|
|
// {
|
|
// result = o.ToString();
|
|
// }
|
|
// else
|
|
// {
|
|
// result = b.ToString();
|
|
// }
|
|
|
|
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw ex;
|
|
//}
|
|
//return result;
|
|
|
|
PrintCode printcode = new PrintCode();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
StringBuilder printeBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
printeBuilder.Append(" select PID,");
|
|
printeBuilder.Append(" substring(maincode,8,7) AS MAINCODE,");
|
|
printeBuilder.Append(" ISCOMPLETE,");
|
|
printeBuilder.Append(" PRODUCTCODE,");
|
|
printeBuilder.Append(" CREATETIME");
|
|
printeBuilder.Append(" from T_AW_PRINTCODE");
|
|
|
|
if (string.IsNullOrEmpty(materialCode) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTCODE = '" + materialCode + "'"); ;
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
printeBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
printcode = session.Get<PrintCode>(printeBuilder.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return printcode;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最大编码
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
public string GetMaxMainCode(int rangeMin,int rangeMax)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
string result = "";
|
|
StringBuilder printeBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sqlBuilder.Append("select isnull(max(substring(maincode,8,7)),0) from t_aw_main WHERE substring(maincode,8,7) between @min and @max ");
|
|
printeBuilder.Append("select isnull(max(substring(maincode,8,7)),0) from T_AW_PRINTCODE WHERE substring(maincode,8,7) between @min and @max ");
|
|
|
|
parameters.Add(new DataParameter("min", rangeMin.ToString().PadLeft(7, '0')));
|
|
parameters.Add(new DataParameter("max", rangeMax.ToString().PadLeft(7, '0')));
|
|
object o;
|
|
object b;
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
o = (session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
|
|
|
|
b = (session.ExecuteSqlScalar(printeBuilder.ToString(), parameters.ToArray()));
|
|
}
|
|
if (Convert.ToInt32(o.ToString()) > Convert.ToInt32(b.ToString()))
|
|
{
|
|
result = o.ToString();
|
|
}
|
|
else
|
|
{
|
|
result = b.ToString();
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Main model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (BaseSession != null)
|
|
{
|
|
//插入基本信息
|
|
count = BaseSession.Insert<Main>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Main>(model);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Main model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = BaseSession.Update<Main>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Main>(model);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Main model, MendRecorder recorder)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
try
|
|
{
|
|
session.OpenTs();
|
|
count = session.Update<Main>(model);
|
|
count = session.Insert<MendRecorder>(recorder);
|
|
session.CommitTs();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
session.RollbackTs();
|
|
throw;
|
|
}
|
|
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 逻辑删除
|
|
/// <summary>
|
|
/// 逻辑删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(Main model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
|
|
//删除基本信息
|
|
sqlBuilder.Append("DELETE T_AW_MAIN ");
|
|
sqlBuilder.Append("WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("DELETE T_AW_MAIN ");
|
|
sqlBuilder.Append("WHERE PID = @PID ");
|
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 导入
|
|
public ImportMessage GetImportData(List<Main> list)
|
|
{
|
|
ImportMessage em = new ImportMessage();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//设置祖先对象数据会话
|
|
session.OpenTs();
|
|
foreach (Main info in list)
|
|
{
|
|
if (info.IsNewInfo == true)
|
|
{
|
|
//插入信息
|
|
int count = session.Insert<Main>(info);
|
|
em.insertNum++;
|
|
}
|
|
else
|
|
{
|
|
//更新信息
|
|
int count = session.Update<Main>(info);
|
|
em.updateNum++;
|
|
}
|
|
}
|
|
session.CommitTs();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return em;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 获取信息(产品档案)
|
|
/// <summary>
|
|
/// 获取信息(产品档案)
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Main GetMain(Main condition)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetMainQuerySql(condition, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
condition = session.Get<Main>(sql, parameters.ToArray());
|
|
}
|
|
return condition;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "加工本体-获取信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句(产品档案)
|
|
/// <summary>
|
|
/// 获取查询语句(产品档案)
|
|
/// </summary>
|
|
/// <param name="condition">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetMainQuerySql(Main condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.AppendLine(" SELECT M.PID ");
|
|
sqlBuilder.AppendLine(" ,M.MAINCODE ");
|
|
sqlBuilder.AppendLine(" ,M.SKID ");
|
|
sqlBuilder.AppendLine(" ,M.SKELETONCODE ");
|
|
sqlBuilder.AppendLine(" ,M.EID ");
|
|
sqlBuilder.AppendLine(" ,M.EPIDERMISCODE ");
|
|
sqlBuilder.AppendLine(" ,M.HB ");
|
|
sqlBuilder.AppendLine(" ,M.COLOR ");
|
|
sqlBuilder.AppendLine(" ,M.MACHINECODDE ");
|
|
sqlBuilder.AppendLine(" ,M.PROCESSSTATE ");
|
|
sqlBuilder.AppendLine(" ,M.STATUS ");
|
|
sqlBuilder.AppendLine(" ,M.CURRENTPROCESS ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCELINE ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTNAME ");
|
|
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTTCODE ");
|
|
sqlBuilder.AppendLine(" ,M.OUTFLAG ");
|
|
sqlBuilder.AppendLine(" ,M.SPID ");
|
|
sqlBuilder.AppendLine(" ,M.SENDCODE ");
|
|
sqlBuilder.AppendLine(" ,M.COMPLETETIME ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
|
|
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
|
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
|
sqlBuilder.AppendLine(" FROM T_AW_MAIN M");
|
|
sqlBuilder.AppendLine("LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
|
|
|
|
//查询条件
|
|
//表皮条码
|
|
if (string.IsNullOrEmpty(condition.EPIDERMISCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.EPIDERMISCODE =@EPIDERMISCODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "EPIDERMISCODE", DataType = DbType.String, Value = condition.EPIDERMISCODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MAINCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.MAINCODE =@MAINCODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MAINCODE", DataType = DbType.String, Value = condition.MAINCODE });
|
|
}
|
|
|
|
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="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Main GetMainForOutwarehouse(Main condition)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetMainQuerySql(condition, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
condition = session.Get<Main>(sql, parameters.ToArray());
|
|
}
|
|
return condition;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "加工本体-获取信息(工控机出库)"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public List<InjectionRecorder> GetProductInfectionList(string id)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
List<InjectionRecorder> list = new List<InjectionRecorder>();
|
|
try
|
|
{
|
|
sql = this.GetProductInfectionQuerySqlNew(id, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<InjectionRecorder>(sql, parameters.ToArray()).ToList<InjectionRecorder>();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "表皮信息投料信息查询错误!"
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetProductInfectionQuerySql(string id, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(string.Format(@"SELECT
|
|
PI.PID,
|
|
PI.MPPID,
|
|
PI.MATERIALNAME,
|
|
PI.MATERIALCODE,
|
|
PI.MATERIALTYPE,
|
|
PI.MATERIALBATCH,
|
|
PI.PROCESSTYPE,
|
|
PI.INJECTIONINDEX,
|
|
PI.INJECTIONTERMINAL,
|
|
PI.USEDWEIGHT,
|
|
'' as MACHINENAME,
|
|
'' as MACHINECODDE,
|
|
'' as PRODUCESHIFTNAME,
|
|
'' as PRODUCESHIFTTCODE,
|
|
'' as PRODUCELINE,
|
|
PI.CREATEUSER,
|
|
PI.CREATEDATE,
|
|
PI.UPDATEUSER,
|
|
PI.UPDATEDATE
|
|
FROM T_AW_PRODUCTINJECTION PI
|
|
where MPPID in (
|
|
select PDID as mppid from T_AW_MAINPRODUCT mp where mp.MID = '{0}'
|
|
union
|
|
select pid as mppid from t_aw_main where pid='{0}')
|
|
", id));
|
|
|
|
#region 查询条件
|
|
|
|
//if (string.IsNullOrEmpty(id) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND PI.MPPID = @id");
|
|
// parameters.Add(new DataParameter { ParameterName = "id", DataType = DbType.String, Value = id });
|
|
//}
|
|
|
|
//if (whereBuilder.Length > 0)
|
|
//{
|
|
// sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
//}
|
|
#endregion
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
private string GetProductInfectionQuerySqlNew(string id, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(string.Format(@"SELECT
|
|
PI.PID,
|
|
PI.MPPID,
|
|
PI.MATERIALNAME,
|
|
PI.MATERIALCODE,
|
|
PI.MATERIALTYPE,
|
|
PI.MATERIALBATCH,
|
|
PI.PROCESSTYPE,
|
|
PI.INJECTIONINDEX,
|
|
PI.INJECTIONTERMINAL,
|
|
PI.USEDWEIGHT,
|
|
'' as MACHINENAME,
|
|
'' as MACHINECODDE,
|
|
'' as PRODUCESHIFTNAME,
|
|
'' as PRODUCESHIFTTCODE,
|
|
'' as PRODUCELINE,
|
|
PI.CREATEUSER,
|
|
PI.CREATEDATE,
|
|
PI.UPDATEUSER,
|
|
PI.UPDATEDATE
|
|
FROM T_AW_PRODUCTINJECTION PI
|
|
where IPID in (select PRODUCT_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE=(SELECT EPIDERMISCODE FROM [T_AW_MAIN] where maincode='{0}'))
|
|
", id));
|
|
|
|
#region 查询条件
|
|
|
|
//if (string.IsNullOrEmpty(id) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND PI.MPPID = @id");
|
|
// parameters.Add(new DataParameter { ParameterName = "id", DataType = DbType.String, Value = id });
|
|
//}
|
|
|
|
//if (whereBuilder.Length > 0)
|
|
//{
|
|
// sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
//}
|
|
#endregion
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 成都扫描颜色配置打码
|
|
/// 20181104
|
|
/// </summary>
|
|
/// <param name="barcode"></param>
|
|
/// <returns></returns>
|
|
public PrintCode GetFinalMaxMainCodePrint(string material)
|
|
{
|
|
PrintCode printcode = new PrintCode();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
StringBuilder printeBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
printeBuilder.Append(" select PID,");
|
|
printeBuilder.Append(" MAINCODE,");
|
|
printeBuilder.Append(" ISCOMPLETE,");
|
|
printeBuilder.Append(" COLOR_CODE,");
|
|
printeBuilder.Append(" PRODUCTCODE,");
|
|
printeBuilder.Append(" CREATETIME");
|
|
printeBuilder.Append(" from T_AW_PRINTCODE");
|
|
|
|
if (string.IsNullOrEmpty(material) == false)
|
|
{
|
|
whereBuilder.Append(" AND COLOR_CODE = '" + material + "'"); ;
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
printeBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
printcode = session.Get<PrintCode>(printeBuilder.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return printcode;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 成都临时打印
|
|
/// </summary>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public PrintCode NewGetMaxMainCode(string materialcode)
|
|
{
|
|
PrintCode printcode = new PrintCode();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
StringBuilder printeBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
printeBuilder.Append(" select PID,");
|
|
printeBuilder.Append(" substring(maincode,8,7) AS MAINCODE,");
|
|
printeBuilder.Append(" ISCOMPLETE,");
|
|
printeBuilder.Append(" PRODUCTCODE,");
|
|
printeBuilder.Append(" CREATETIME");
|
|
printeBuilder.Append(" from T_AW_PRINTCODE");
|
|
|
|
if (string.IsNullOrEmpty(materialcode) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTCODE = '" + materialcode + "'"); ;
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
printeBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
printcode = session.Get<PrintCode>(printeBuilder.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return printcode;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 成都获取最大值最小值
|
|
/// </summary>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public PrintCode GetMaxANDMinMainCode(string materialcode)
|
|
{
|
|
PrintCode printcode = new PrintCode();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
StringBuilder printeBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
printeBuilder.Append(" select PID,");
|
|
printeBuilder.Append(" substring(maincode,8,7) AS MAINCODE,");
|
|
printeBuilder.Append(" MINVALUE,");
|
|
printeBuilder.Append(" MAXVALUE,");
|
|
printeBuilder.Append(" ISCOMPLETE,");
|
|
printeBuilder.Append(" PRODUCTCODE,");
|
|
printeBuilder.Append(" MATERIAL_NAME,");
|
|
printeBuilder.Append(" COLOR_CODE,");
|
|
printeBuilder.Append(" PRINT_TEMPALTE_TEM,");
|
|
printeBuilder.Append(" PRINT_TEMPALTE_DATA,");
|
|
printeBuilder.Append(" PRECODE,");
|
|
printeBuilder.Append(" SERIAL_NUM,");
|
|
printeBuilder.Append(" CREATETIME,");
|
|
printeBuilder.Append(" UPDATETIME");
|
|
printeBuilder.Append(" from T_AW_PRINTCODE");
|
|
if (string.IsNullOrEmpty(materialcode) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTCODE = '" + materialcode + "'"); ;
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
printeBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
printcode = session.Get<PrintCode>(printeBuilder.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return printcode;
|
|
}
|
|
}
|
|
|
|
}
|
|
|