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.
1836 lines
68 KiB
1836 lines
68 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.Operation;
|
|
using QMAPP.FJC.Entity.ProduceManage;
|
|
using QMAPP.DAL;
|
|
using QMFrameWork.Log;
|
|
using QMAPP.FJC.Entity.Stocktaking;
|
|
|
|
namespace QMAPP.FJC.DAL.Operation
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M13-1
|
|
/// 作 用:零件条码表
|
|
/// 作 者:王庆男
|
|
/// 编写日期:2015年05月29日
|
|
///</summary>
|
|
public class ProductDAL : BaseDAL
|
|
{
|
|
|
|
/// <summary>
|
|
/// 数据会话
|
|
/// </summary>
|
|
//public IDataSession BaseSession = null;
|
|
|
|
#region 获取信息
|
|
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Product Get(Product model)
|
|
{
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
model = BaseSession.Get<Product>(model);
|
|
}
|
|
else
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_AW_PRODUCT WHERE 1=1 ";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.PRODUCTCODE) == false)
|
|
{
|
|
sql += " AND PRODUCTCODE = @PRODUCTCODE";
|
|
parameters.Add(new DataParameter("PRODUCTCODE", model.PRODUCTCODE));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false)
|
|
{
|
|
sql += " AND MATERIAL_CODE = @MATERIAL_CODE";
|
|
parameters.Add(new DataParameter("MATERIAL_CODE", model.MATERIAL_CODE));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<Product>(sqlChange, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "物料号信息数据层-获取信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取T_AW_PACKAGE信息
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public Entity.Operation.Package GetPackage(Entity.Operation.Package model)
|
|
{
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
model = BaseSession.Get<Entity.Operation.Package>(model);
|
|
}
|
|
else
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "SELECT * FROM T_AW_PACKAGE WHERE '1'='1'";
|
|
if (string.IsNullOrEmpty(model.PID) == false)
|
|
{
|
|
sql += " AND PID = @PID";
|
|
parameters.Add(new DataParameter("PID", model.PID));
|
|
}
|
|
if (string.IsNullOrEmpty(model.PACKAGECODE) == false)
|
|
{
|
|
sql += " AND PACKAGECODE = @PACKAGECODE";
|
|
parameters.Add(new DataParameter("PACKAGECODE", model.PACKAGECODE));
|
|
}
|
|
sql += " ORDER BY CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = this.ChangeSqlByDB(sql, session);
|
|
//获取信息
|
|
model = session.Get<Entity.Operation.Package>(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(Product condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Product>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetListAndAttribute(Product condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetAttributeQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "A.PID";
|
|
page.SortExpression = "CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Product>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取替换列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetProductReplaceList(ProductReplace condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySqlProductReplace(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
page.SortExpression = "CREATEDATE DESC";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<ProductReplace>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#region 替换件获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExpProductReplaceList(ProductReplace model)
|
|
{
|
|
DataTable dt = null;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sql = this.GetQuerySqlProductReplace(model, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
dt = session.GetTable(sql, parameters.ToArray());
|
|
dt.TableName = "ProductReplaceExp";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "导出获取数据错误!"
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public List<Product> GetListAndAttribute(Product condition)
|
|
{
|
|
string sql = null;
|
|
List<Product> list = new List<Product>();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetAttributeQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<Product>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>数据页</returns>
|
|
public List<Product> GetList(Product condition)
|
|
{
|
|
List<Product> list = new List<Product>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<Product>(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(Product condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT A.PID,A.CREATEDATE,");
|
|
sqlBuilder.Append("A.PRODUCTTYPE,A.PRODUCTCODE,A.PRODUCTSOURCE,");
|
|
sqlBuilder.Append("A.MACHINENAME,A.MACHINECODDE,A.STATUS,");
|
|
sqlBuilder.Append("A.CURRENTPROCESS,A.PRODUCELINE,A.PRODUCESHIFTNAME,");
|
|
sqlBuilder.Append("A.PRODUCESHIFTTCODE,A.OUTFLAG,A.USINGSTATE, ");
|
|
sqlBuilder.Append("A.CAPACITY,A.USINGCOUNT,A.CREATEUSER, ");
|
|
sqlBuilder.Append("A.UPDATEUSER,A.UPDATEDATE, ");
|
|
sqlBuilder.Append("A.MATERIAL_TYPE, ");
|
|
sqlBuilder.Append("A.MATERIAL_CODE, ");
|
|
sqlBuilder.Append("A.ENDOFLINE, ");
|
|
sqlBuilder.Append("A.WORKCELL_CODE, ");
|
|
sqlBuilder.Append("A.WORKLOC_CODE, ");
|
|
sqlBuilder.Append("A.WORKCENTER_CODE,");
|
|
sqlBuilder.Append("A.PLAN_NO, ");
|
|
sqlBuilder.Append("A.PLAN_ID, ");
|
|
sqlBuilder.Append("M.MATERIAL_NAME, ");
|
|
sqlBuilder.Append("M.PROJECTCODE, ");
|
|
sqlBuilder.Append("C.USERNAME AS CREATEUSERNAME,B.PRODUCTNAME as PRODUCTTYPENAME, ");
|
|
sqlBuilder.Append("E.MFGCODE AS ERP_WORKLINE ");
|
|
sqlBuilder.Append("FROM T_AW_PRODUCT A ");
|
|
sqlBuilder.Append("LEFT JOIN T_QM_USER C ON C.USERID=A.CREATEUSER ");
|
|
sqlBuilder.Append("LEFT JOIN T_BD_PRODUCTBASIC B ON A.PRODUCTTYPE=B.PRODUCTTYPE ");
|
|
sqlBuilder.Append("LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=A.MATERIAL_CODE ");
|
|
sqlBuilder.Append("LEFT JOIN T_AW_MENDRECORDERERP E ON E.TYPE_CODE=A.WORKCENTER_CODE AND MFGCODETYPE='WORKLINE' ");
|
|
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATESTARTDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.CREATEDATE >@CREATESTARTDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATESTARTDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATESTARTDATE
|
|
});
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATEENDDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.CREATEDATE < @CREATEENDDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEENDDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEENDDATE
|
|
});
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.MACHINECODDE = " + "@MACHINECODDE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "MACHINECODDE",
|
|
DataType = DbType.String,
|
|
Value = condition.MACHINECODDE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_TYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.MATERIAL_TYPE = " + "@MATERIAL_TYPE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "MATERIAL_TYPE",
|
|
DataType = DbType.String,
|
|
Value = condition.MATERIAL_TYPE
|
|
});
|
|
}
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.MATERIAL_CODE = " + "@MATERIAL_CODE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "MATERIAL_CODE",
|
|
DataType = DbType.String,
|
|
Value = condition.MATERIAL_CODE
|
|
});
|
|
}
|
|
//if (string.IsNullOrEmpty(condition.PRODUCTCODELIKE) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND A.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'");
|
|
// parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODELIKE });
|
|
//}
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODELIKE) == false)
|
|
{
|
|
whereBuilder.Append(" AND (A.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" +
|
|
"+'%' OR M.MAINCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%')");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTCODELIKE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PID = @PID");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PID",
|
|
DataType = DbType.String,
|
|
Value = condition.PID
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTCODE = @PRODUCTCODE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTCODE
|
|
});
|
|
}
|
|
|
|
if (condition.CREATEDATE != null && condition.CREATEDATE != DateTime.MinValue)
|
|
{
|
|
whereBuilder.Append(" AND (CONVERT(varchar(100), A.CREATEDATE, 23)) = " + "@CREATEDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEDATE.ToString("yyyy-MM-dd")
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTTYPE = " + "@PRODUCTTYPE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTTYPE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTTYPE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPES) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTTYPE IN ('" + condition.PRODUCTTYPES.Replace(",", "','") + "')");
|
|
//parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCELINE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCELINE = " + "@PRODUCELINE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCELINE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCELINE
|
|
});
|
|
}
|
|
if (string.IsNullOrEmpty(condition.PRODUCTSOURCE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTSOURCE = " + "@PRODUCTSOURCE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTSOURCE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTSOURCE
|
|
});
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(condition.USINGSTATE) == false)
|
|
{
|
|
if (condition.USINGSTATE.Equals("3"))
|
|
{
|
|
whereBuilder.Append(" AND A.USINGSTATE != '2'");
|
|
}
|
|
else
|
|
{
|
|
whereBuilder.Append(" AND A.USINGSTATE = " + "@USINGSTATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "USINGSTATE",
|
|
DataType = DbType.String,
|
|
Value = condition.USINGSTATE
|
|
});
|
|
}
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
sqlBuilder.Append(" order by A.CREATEDATE desc ");
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取替换查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySqlProductReplace(ProductReplace condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT * ");
|
|
sqlBuilder.Append(",(select USERNAME from T_QM_USER where USERID=CREATEUSER) as CREATEUSERNAME");
|
|
sqlBuilder.Append(" FROM T_AW_PRODUCT_REPLACE");
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false)
|
|
{
|
|
whereBuilder.Append(" AND CREATEDATE >@CREATEDATESTART");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEDATESTART",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEDATESTART
|
|
});
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false)
|
|
{
|
|
whereBuilder.Append(" AND CREATEDATE < @CREATEDATEEND");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEDATEEND",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEDATEEND
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (string.IsNullOrEmpty(condition.PID) == false)
|
|
//{
|
|
// whereBuilder.Append(" AND A.PID = @PID");
|
|
// parameters.Add(new DataParameter
|
|
// {
|
|
// ParameterName = "PID",
|
|
// DataType = DbType.String,
|
|
// Value = condition.PID
|
|
// });
|
|
//}
|
|
|
|
if (string.IsNullOrEmpty(condition.MAIN_PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND (MAIN_PRODUCTCODE like @MAIN_PRODUCTCODE or CHILD_PRODUCTCODE like @MAIN_PRODUCTCODE or REPLACE_PRODUCTCODE like @MAIN_PRODUCTCODE)");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "MAIN_PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = "%"+ condition.MAIN_PRODUCTCODE + "%"
|
|
});
|
|
}
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
//sqlBuilder.Append(" order by CREATEDATE desc ");
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
private string GetQuerySqlByAssemble(string code)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append("SELECT A.PID,A.CREATEDATE,");
|
|
sqlBuilder.Append("A.PRODUCTTYPE,A.PRODUCTCODE,A.PRODUCTSOURCE, ");
|
|
sqlBuilder.Append("A.MACHINENAME,A.MACHINECODDE,A.STATUS, ");
|
|
sqlBuilder.Append("A.CURRENTPROCESS,A.PRODUCELINE,A.PRODUCESHIFTNAME, ");
|
|
sqlBuilder.Append("A.PRODUCESHIFTTCODE,A.OUTFLAG,A.USINGSTATE, ");
|
|
sqlBuilder.Append("A.CAPACITY,A.USINGCOUNT,A.CREATEUSER, ");
|
|
sqlBuilder.Append("A.UPDATEUSER,A.UPDATEDATE, ");
|
|
sqlBuilder.Append("A.MATERIAL_TYPE, ");
|
|
sqlBuilder.Append("A.MATERIAL_CODE, ");
|
|
sqlBuilder.Append("A.PLAN_NO, ");
|
|
sqlBuilder.Append("A.PLAN_ID, ");
|
|
sqlBuilder.Append("A.WORKCELL_CODE, ");
|
|
sqlBuilder.Append("A.WORKLOC_CODE, ");
|
|
sqlBuilder.Append("A.WORKCENTER_CODE, ");
|
|
sqlBuilder.Append("A.ENDOFLINE, ");
|
|
sqlBuilder.Append("M.MAINCODE, ");
|
|
sqlBuilder.Append("C.USERNAME AS CREATEUSERNAME,");
|
|
sqlBuilder.Append("'' as PRODUCTTYPENAME ");
|
|
sqlBuilder.Append("FROM T_AW_PRODUCT A ");
|
|
sqlBuilder.Append("LEFT JOIN T_QM_USER C ON C.USERID=A.CREATEUSER ");
|
|
sqlBuilder.Append(
|
|
"LEFT JOIN T_AW_MAIN M ON M.EPIDERMISCODE=A.PRODUCTCODE AND A.MATERIAL_CODE=M.MATERIAL_CODE ");
|
|
whereBuilder.AppendFormat("AND A.WORKCENTER_CODE IS NOT NULL ");
|
|
if (code.StartsWith("052 "))
|
|
{
|
|
whereBuilder.AppendFormat("AND M.MAINCODE='{0}'", code);
|
|
}
|
|
//else if(System.Text.RegularExpressions.Regex.IsMatch(code,"^D\\d{2}\\w+[RF][LR]\\d{2}(10|11|12|0[1-9])(30|31|2\\d|1\\d|0[1-9])\\w\\d{5}$"))
|
|
//{
|
|
// whereBuilder.AppendFormat("AND A.PLAN_NO = '{0}'", code);
|
|
//}
|
|
else if (code.StartsWith("D01") || code.StartsWith("DP2"))
|
|
{
|
|
whereBuilder.AppendFormat("AND A.PLAN_NO = '{0}'", code);
|
|
}
|
|
else
|
|
{
|
|
whereBuilder.AppendFormat("AND A.PRODUCTCODE = '{0}'", code);
|
|
}
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
sqlBuilder.Append(" ORDER BY CREATEDATE DESC");
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
private string GetQuerySqlNew(Product condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
//sqlBuilder.Append("SELECT T.MID, M.MAINCODE, ");
|
|
//sqlBuilder.Append("P.PRODUCTTYPE, P.PRODUCTCODE, P.PRODUCTSOURCE, ");
|
|
//sqlBuilder.Append("P.CURRENTPROCESS, P.PRODUCELINE, P.STATUS, ");
|
|
//sqlBuilder.Append("P.MATERIAL_CODE, P.MATERIAL_TYPE, ");
|
|
//sqlBuilder.Append("P.PRODUCESHIFTTCODE, P.USINGSTATE, P.PID ");
|
|
//sqlBuilder.Append("FROM dbo.T_AW_MAINPRODUCT T ");
|
|
//sqlBuilder.Append("LEFT OUTER JOIN dbo.T_AW_MAIN M ON T.MID = M.PID ");
|
|
//sqlBuilder.Append("LEFT OUTER JOIN dbo.T_AW_PRODUCT P ON T.PDID = P.PID ");
|
|
sqlBuilder.Append(
|
|
"SELECT M.PID AS MID, M.MAINCODE, P.PRODUCTTYPE, P.PRODUCTCODE, P.PRODUCTSOURCE, P.CURRENTPROCESS, P.PRODUCELINE, P.STATUS, P.MATERIAL_CODE, P.MATERIAL_TYPE, P.PRODUCESHIFTTCODE,P.USINGSTATE, P.PID, MD.PROJECTCODE,E.MFGCODE AS ERP_WORKLINE ");
|
|
sqlBuilder.Append(
|
|
"FROM T_AW_MAIN M LEFT JOIN T_AW_PRODUCT P ON P.PRODUCTCODE=M.EPIDERMISCODE AND P.MATERIAL_CODE=M.MATERIAL_CODE ");
|
|
sqlBuilder.Append("LEFT JOIN T_MD_MATERIAL MD ON MD.MATERIAL_CODE=P.MATERIAL_CODE ");
|
|
sqlBuilder.Append("LEFT JOIN T_AW_MENDRECORDERERP E ON E.TYPE_CODE=P.WORKCENTER_CODE AND MFGCODETYPE='WORKLINE' ");
|
|
|
|
//查询条件
|
|
//if (string.IsNullOrEmpty(condition.UserName) == false)
|
|
//{
|
|
//whereBuilder.Append(" AND USERNAME LIKE '%'+" + "@USERNAME" + "+'%'");
|
|
//parameters.Add(new DataParameter { ParameterName = "USERNAME", DataType = DbType.String, Value = condition.UserName});
|
|
//}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.MAINCODE=@PRODUCTCODE ");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTCODE
|
|
});
|
|
}
|
|
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
sqlBuilder.Append(" order by M.CREATEDATE desc ");
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetAttributeQuerySql(Product condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(
|
|
"SELECT A.PID,PRODUCTTYPE,PRODUCTCODE,C.MATERIAL_NAME,A.MATERIAL_CODE,A.PLAN_NO,A.PLAN_ID,PRODUCTSOURCE,MACHINENAME,MACHINECODDE,STATUS,CURRENTPROCESS,PRODUCELINE,PRODUCESHIFTNAME,PRODUCESHIFTTCODE,OUTFLAG,USINGSTATE,A.CAPACITY,USINGCOUNT,A.CREATEUSER,A.CREATEDATE,A.UPDATEUSER,A.UPDATEDATE,O.USERNAME as CREATEUSERNAME ");
|
|
sqlBuilder.Append(
|
|
",B.PID as PAPID,VAL1,VAL2,VAL3,VAL4,VAL5,VAL6,VAL7,VAL8,VAL9,VAL10,VAL11,VAL12,VAL13,VAL14,VAL15 ");
|
|
sqlBuilder.Append(
|
|
"FROM T_AW_PRODUCT A LEFT JOIN T_AW_PRODUCTATTRIBUTE B ON A.PID = B.MPPID LEFT JOIN T_QM_USER O ON O.USERID=A.CREATEUSER");
|
|
//20171010 zxd 添加
|
|
sqlBuilder.Append(" LEFT JOIN T_MD_MATERIAL C ON C.MATERIAL_CODE=A.MATERIAL_CODE");
|
|
//查询条件
|
|
|
|
if (string.IsNullOrEmpty(condition.PID) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PID = " + "@PID");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PID",
|
|
DataType = DbType.String,
|
|
Value = condition.PID
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATESTARTDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.CREATEDATE >@CREATESTARTDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATESTARTDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATESTARTDATE
|
|
});
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CREATEENDDATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.CREATEDATE < @CREATEENDDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEENDDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEENDDATE
|
|
});
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTTYPE = @PRODUCTTYPE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTTYPE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTTYPE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
|
{
|
|
whereBuilder.Append(" AND MACHINECODDE = " + "@MACHINECODDE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "MACHINECODDE",
|
|
DataType = DbType.String,
|
|
Value = condition.MACHINECODDE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODELIKE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTCODELIKE
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.CURRENTPROCESS = @CURRENTPROCESS");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CURRENTPROCESS",
|
|
DataType = DbType.String,
|
|
Value = condition.CURRENTPROCESS
|
|
});
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND A.PRODUCTCODE = @PRODUCTCODE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCTCODE
|
|
});
|
|
}
|
|
if (string.IsNullOrEmpty(condition.VAL4) == false)
|
|
{
|
|
whereBuilder.Append(" AND VAL4 = " + "@VAL4");
|
|
parameters.Add(new DataParameter { ParameterName = "VAL4", DataType = DbType.String, Value = condition.VAL4 });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.PRODUCELINE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCELINE = " + "@PRODUCELINE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCELINE",
|
|
DataType = DbType.String,
|
|
Value = condition.PRODUCELINE
|
|
});
|
|
}
|
|
|
|
if (condition.CREATEDATE != null && condition.CREATEDATE != DateTime.MinValue)
|
|
{
|
|
whereBuilder.Append(" AND (CONVERT(varchar(100), A.CREATEDATE, 23)) = " + "@CREATEDATE");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "CREATEDATE",
|
|
DataType = DbType.String,
|
|
Value = condition.CREATEDATE.ToString("yyyy-MM-dd")
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
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(Product 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_PRODUCT";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 信息是否重复
|
|
|
|
/// <summary>
|
|
/// 判断名称是否存在
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
|
public bool ExistsProduct(Product model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(1) FROM T_AW_PRODUCT");
|
|
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.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTCODE =@PRODUCTCODE ");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "PRODUCTCODE",
|
|
DataType = DbType.String,
|
|
Value = model.PRODUCTCODE
|
|
});
|
|
}
|
|
//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>true:已存在;fasel:不存在。</returns>
|
|
public bool IsUsedProduct(Product model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
sqlBuilder.Append("SELECT COUNT(1) FROM T_AW_PRODUCT");
|
|
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.USINGSTATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND USINGSTATE = @USINGSTATE ");
|
|
parameters.Add(new DataParameter
|
|
{
|
|
ParameterName = "USINGSTATE",
|
|
DataType = DbType.String,
|
|
Value = model.USINGSTATE
|
|
});
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Product model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = this.BaseSession.Insert<Product>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Product>(model);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 插入信息(俩表包括Attribute)
|
|
/// </summary>
|
|
/// <param name="model">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int InsertMainAndAttribute(Product model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (BaseSession != null)
|
|
{
|
|
count = BaseSession.Insert<Product>(model);
|
|
if (count > 0 && model.PRODUCTATTRIBUTE != null && !string.IsNullOrEmpty(model.PID))
|
|
{
|
|
count = BaseSession.Insert<ProductAttribute>(model.PRODUCTATTRIBUTE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
try
|
|
{
|
|
session.OpenTs();
|
|
//插入基本信息
|
|
count = session.Insert<Product>(model);
|
|
if (count > 0 && model.PRODUCTATTRIBUTE != null && !string.IsNullOrEmpty(model.PID))
|
|
{
|
|
count = session.Insert<ProductAttribute>(model.PRODUCTATTRIBUTE);
|
|
}
|
|
session.CommitTs();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
session.RollbackTs();
|
|
throw;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 插入T_AW_PACKAGE信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int InsertPackage(Entity.Operation.Package model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = this.BaseSession.Insert<Entity.Operation.Package>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//插入基本信息
|
|
count = session.Insert<Entity.Operation.Package>(model);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Product model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = this.BaseSession.Update<Product>(model);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Product>(model);
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(List<Product> models)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (BaseSession != null)
|
|
{
|
|
//更新基本信息
|
|
count = BaseSession.Update<Product>(models);
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.Update<Product>(models);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(Product model, MendRecorder recorder)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
try
|
|
{
|
|
session.OpenTs();
|
|
count = session.Update<Product>(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(Product model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
if (this.BaseSession != null)
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("DELETE T_AW_PRODUCT ");
|
|
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_PRODUCT ");
|
|
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<Product> list)
|
|
{
|
|
ImportMessage em = new ImportMessage();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//设置祖先对象数据会话
|
|
session.OpenTs();
|
|
foreach (Product info in list)
|
|
{
|
|
if (info.IsNewInfo == true)
|
|
{
|
|
//插入信息
|
|
int count = session.Insert<Product>(info);
|
|
em.insertNum++;
|
|
}
|
|
else
|
|
{
|
|
//更新信息
|
|
int count = session.Update<Product>(info);
|
|
em.updateNum++;
|
|
}
|
|
}
|
|
session.CommitTs();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return em;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取信息
|
|
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Product GetProductInfo(Product model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(model, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<Product>(sql, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public Product GetProductInfoNew(Product model)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySqlNew(model, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<Product>(sql, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取流水号信息
|
|
|
|
/// <summary>
|
|
/// 获取流水号信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public int GetNum(Product model)
|
|
{
|
|
int num = 0;
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
sqlBuilder.AppendLine("SELECT count(*) FROM T_AW_PRODUCT ");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取数量信息
|
|
num = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString())) + 1;
|
|
}
|
|
return num;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "零件条码信息数据层-获取信息"
|
|
});
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public int ExistsCheck(string barCode)
|
|
{
|
|
int productSum = 0;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = string.Format("select count(1) from t_aw_product where productcode='{0}'", barCode);
|
|
|
|
LogManager.LogHelper.Info(new LogInfo() {Info = sql});
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
productSum = Convert.ToInt32(session.ExecuteSqlScalar(sql, new List<DataParameter>().ToArray()));
|
|
}
|
|
return productSum;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public Product GetProductByAssembleCode(string code)
|
|
{
|
|
string sql = null;
|
|
Product model = new Product();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySqlByAssemble(code);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<Product>(sql, parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#region 获取主体条码下的零件列表
|
|
|
|
public List<Product> GetMainProductMaterialCodeList(string productcode)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
var sql =
|
|
"SELECT * FROM T_AW_PRODUCT T where T.PID in (select PART_PID from T_QT_PRODUCT_STRUCTURE where PROCESS_CODE='" +
|
|
productcode + "') ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Product>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 替换并添加临时表
|
|
|
|
public int ReplaceProductMaterialCode(Product mainProduct, Product childProduct, Product replaceProduct,
|
|
string UserID)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
try
|
|
{
|
|
// 开始事务
|
|
session.OpenTs();
|
|
if (string.IsNullOrWhiteSpace(replaceProduct.PID)
|
|
&& !string.IsNullOrWhiteSpace(replaceProduct.PRODUCTCODE))
|
|
{
|
|
replaceProduct.PID = Guid.NewGuid().ToString();
|
|
replaceProduct.USINGSTATE = "2";
|
|
replaceProduct.USINGCOUNT = replaceProduct.USINGCOUNT + 1;
|
|
session.Insert(replaceProduct);
|
|
}
|
|
else
|
|
{
|
|
//修改替换条码的状态和使用数量
|
|
replaceProduct.USINGSTATE = "2";
|
|
replaceProduct.USINGCOUNT = replaceProduct.USINGCOUNT + 1;
|
|
session.Update(replaceProduct);
|
|
}
|
|
string sql = "";
|
|
if (childProduct != null&&!string.IsNullOrWhiteSpace(childProduct.PID))
|
|
{
|
|
//替换T_QT_PRODUCT_STRUCTURE表里的PART_PID
|
|
sql = "update T_QT_PRODUCT_STRUCTURE set PART_PID='" + replaceProduct.PID +
|
|
"' where PART_PID='" + childProduct.PID + "'";
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
childProduct.USINGCOUNT = childProduct.USINGCOUNT - 1;
|
|
childProduct.USINGSTATE = "0";
|
|
//childProduct.UPDATEDATE = DateTime.Now;
|
|
session.Update(childProduct);
|
|
}
|
|
else
|
|
{
|
|
sql = "INSERT INTO [T_QT_PRODUCT_STRUCTURE] VALUES(NEWID(),'" + mainProduct.PRODUCTCODE + "','" + mainProduct.PID + "','" + replaceProduct.PID + "')";
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
|
|
//添加临时表
|
|
var pid = Guid.NewGuid().ToString();
|
|
sql =
|
|
"INSERT INTO T_AW_PRODUCT_REPLACE (PID,MAIN_PID,MAIN_PRODUCTCODE,MAIN_MATERIAL_CODE,MAIN_STATUS,CHILD_PID,CHILD_PRODUCTCODE,CHILD_MATERIAL_CODE,CHILD_STATUS,REPLACE_PID,REPLACE_PRODUCTCODE,REPLACE_STATUS,CREATEUSER,CREATEDATE) ";
|
|
sql += "VALUES('" + pid + "','" + mainProduct.PID + "','" + mainProduct.PRODUCTCODE + "','" +
|
|
mainProduct.MATERIAL_CODE + "','0','" + (childProduct != null ? childProduct.PID : "") + "','" + (childProduct != null ? childProduct.PRODUCTCODE : "") + "','" +
|
|
(childProduct != null ? childProduct.MATERIAL_CODE : "") + "','0','" + replaceProduct.PID + "','" + replaceProduct.PRODUCTCODE +
|
|
"','0','" + UserID + "','" + DateTime.Now + "')";
|
|
session.ExecuteSql(sql, parameters.ToArray());
|
|
|
|
// 事务提交
|
|
session.CommitTs();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
session.RollbackTs();
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 获取T_MD_PACKAGESET信息
|
|
/// <summary>
|
|
/// 获取T_MD_PACKAGESET信息
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public PackageSet GetPackageSetInfo(PackageSet model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
sqlBuilder.Append(" SELECT * ");
|
|
sqlBuilder.Append(" FROM T_MD_MATERIAL ");
|
|
//sqlBuilder.Append(" FROM T_MD_PACKAGESET ");
|
|
|
|
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.MATERIAL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND MATERIAL_CODE= @MATERIAL_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = model.MATERIAL_CODE });
|
|
}
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
|
|
try
|
|
{
|
|
if (null != BaseSession)
|
|
{
|
|
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), BaseSession);
|
|
model = BaseSession.Get<PackageSet>(sqlChange, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
|
|
//获取信息
|
|
model = session.Get<PackageSet>(sqlChange, parameters.ToArray());
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RecordExceptionLog(ex, "数据层-获取信息");
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 通过零件号获取产品信息数量
|
|
|
|
public int GetCountByMaterialCode(string materialCode)
|
|
{
|
|
int count = 0;
|
|
|
|
string sql = string.Format("select isnull(sum(CAPACITY),0) from T_AW_PRODUCT p inner join t_md_material_class c on c.MATERIAL_TYPE_CODE= MATERIAL_TYPE where (PRODUCTCODE like 'CFAA%' AND MATERIAL_CODE='{0}' and MATERIAL_ATTRIBUTE='1' ) or (MATERIAL_CODE='{0}' and MATERIAL_ATTRIBUTE='2' and p.outflag='0' and p.status in ('0','1'))", materialCode);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new List<DataParameter>().ToArray()));
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 通过零件号获取使用数量
|
|
|
|
public int GetUsedCountByMaterialCode(string materialCode)
|
|
{
|
|
int count = 0;
|
|
|
|
string sql = string.Format("select isnull(sum(USINGCOUNT),0) from T_AW_PRODUCT where USINGSTATE<>'0' AND MATERIAL_CODE='{0}'", materialCode);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sql, new List<DataParameter>().ToArray()));
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public int ReplaceBarcode(string oldcode, string newcode)
|
|
{
|
|
try
|
|
{
|
|
int count = 0;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = "UPDATE T_AW_PRODUCT SET PRODUCTCODE=@newcode WHERE PRODUCTCODE=@oldcode";
|
|
parameters.Add(new DataParameter("newcode", newcode));
|
|
parameters.Add(new DataParameter("oldcode", oldcode));
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = this.BaseSession.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public int ReplacePlanNo(string productcode, string planno,string planid)
|
|
{
|
|
try
|
|
{
|
|
int count = 0;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = "UPDATE T_AW_PRODUCT SET PLAN_NO=@planno,PLAN_NO_REV=@plannorev,PLAN_ID=@planid WHERE PRODUCTCODE=@productcode";
|
|
parameters.Add(new DataParameter("planno", planno));
|
|
parameters.Add(new DataParameter("plannorev", new string(planno.Reverse().ToArray())));
|
|
parameters.Add(new DataParameter("planid", planid));
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
if (this.BaseSession != null)
|
|
{
|
|
count = this.BaseSession.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
else
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//更新基本信息
|
|
count = session.ExecuteSql(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public Product GetProductByPartID(string partid)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
Product model = new Product();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.AppendLine("SELECT * ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCT ");
|
|
sql.AppendLine(" WHERE PRODUCTCODE=(SELECT PROCESS_CODE ");
|
|
sql.AppendLine(" FROM T_QT_PRODUCT_STRUCTURE ");
|
|
sql.AppendLine(" WHERE PART_PID=@partid) ");
|
|
sql.AppendLine(" ORDER BY CREATEDATE DESC ");
|
|
parameters.Add(new DataParameter("partid", partid));
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get<Product>(sql.ToString(), parameters.ToArray());
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
public List<Product> GetPartList(string productcode)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT P.* ");
|
|
sql.AppendLine(" ,M.MATERIAL_NAME ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCT AS P ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
|
|
sql.AppendLine(" ON P.MATERIAL_CODE=M.MATERIAL_CODE ");
|
|
sql.AppendLine(" WHERE P.PID IN (SELECT PART_PID ");
|
|
sql.AppendLine(" FROM T_QT_PRODUCT_STRUCTURE ");
|
|
sql.AppendLine(" WHERE PROCESS_CODE=@productcode) ");
|
|
sql.AppendLine(" ORDER BY UPDATEDATE DESC ");
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Product>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
public ShipmentInfo GetShipmentInfo(string productcode)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT F.VWSEQ ");
|
|
sql.AppendLine(" ,F.VIN ");
|
|
sql.AppendLine(" ,F.KIN ");
|
|
sql.AppendLine(" ,D.SANBARCODE ");
|
|
sql.AppendLine(" ,D.SCANDATE ");
|
|
sql.AppendLine(" FROM T_PP_PASCARDDETAILS AS D ");
|
|
sql.AppendLine(" LEFT JOIN T_PP_FISORDER AS F ");
|
|
sql.AppendLine(" ON D.FISDETAILID=F.PID ");
|
|
sql.AppendLine(" WHERE D.SANBARCODE=@productcode ");
|
|
sql.AppendLine(" ORDER BY SCANDATE DESC ");
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.Get<ShipmentInfo>(sql.ToString(), parameters.ToArray());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|