天津投入产出系统后端
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.

285 lines
11 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Operation;
using System.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.Operation
{
public class ProductOutDAL : BaseDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(ProductOut 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())
{
page = session.GetDataPage<ProductOut>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
public List<ProductOut> GetList(string productcode)
{
//string sql = "SELECT * FROM [T_AW_PRODUCTOUT] AS O WHERE [PRODUCT_CODE] =@productcode ORDER BY [CREATEDATE]";
List<DataParameter> parameters = new List<DataParameter>();
try
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT O.* ");
sql.AppendLine(" ,R.OUTREASON_NAME");
sql.AppendLine(" ,U.USERNAME AS CREATEUSERNAME ");
sql.AppendLine(" FROM T_AW_PRODUCTOUT AS O ");
sql.AppendLine(" LEFT JOIN T_QM_USER AS U ");
sql.AppendLine(" ON O.CREATEUSER=U.USERID ");
sql.AppendLine(" LEFT JOIN T_MD_OUTREASON AS R ");
sql.AppendLine(" ON R.OUTREASON_CODE=O.OUTREASON ");
sql.AppendLine(" WHERE O.[PRODUCT_CODE] =@productcode");
sql.AppendLine(" ORDER BY [CREATEDATE]");
parameters.Add(new DataParameter("productcode", productcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<ProductOut>(sql.ToString(), 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(ProductOut condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT A.PID,");
sqlBuilder.Append("A.PRODUCT_CODE,");
sqlBuilder.Append("A.MATERIAL_CODE,");
sqlBuilder.Append("A.WORKCENTER_CODE,");
sqlBuilder.Append("WC.WORKCENTER_NAME,");
sqlBuilder.Append("A.WORKCELL_CODE,");
sqlBuilder.Append("W.WORKCELL_NAME,");
sqlBuilder.Append("A.OUTREASON,");
sqlBuilder.Append("A.SHIFT_CODE,");
sqlBuilder.Append("A.CREATEUSER,");
sqlBuilder.Append("CONVERT(VARCHAR(19),A.CREATEDATE,120) AS CREATEDATE,");
sqlBuilder.Append("A.UPDATEUSER,");
sqlBuilder.Append("CONVERT(VARCHAR(19),A.UPDATEDATE,120) AS UPDATEDATE,");
sqlBuilder.Append("M.MATERIAL_NAME,");
sqlBuilder.Append("S.PRODUCESHIFTNAME AS SHIFT_NAME,");
sqlBuilder.Append("MC.MATERIAL_TYPE_CODE,");
sqlBuilder.Append("MC.MATERIAL_TYPE_NAME,");
sqlBuilder.Append("C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.Append("FROM T_AW_PRODUCTOUT A ");
sqlBuilder.Append("LEFT JOIN T_QM_USER C ON C.USERID=A.CREATEUSER ");
sqlBuilder.Append("LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=A.MATERIAL_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_MATERIAL_CLASS MC on MC.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE ");
sqlBuilder.Append("LEFT JOIN T_BD_PRODUCESHIFT S ON S.PRODUCESHIFTTCODE=A.SHIFT_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_WORKCENTER WC ON WC.WORKCENTER_CODE=A.WORKCENTER_CODE ");
sqlBuilder.Append("LEFT JOIN T_MD_WORKCELL W ON W.WORKCELL_CODE=A.WORKCELL_CODE ");
//查询条件
if (condition.CREATEDATESTART != null && condition.CREATEDATESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND A.CREATEDATE>@CREATEDATESTART ");
parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.String, Value = condition.CREATEDATESTART.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.CREATEDATEEND != null && condition.CREATEDATEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND A.CREATEDATE<@CREATEDATEEND ");
parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (string.IsNullOrEmpty(condition.PRODUCT_CODE) == false)
{
whereBuilder.Append(" AND A.PRODUCT_CODE LIKE '%'+" + "@PRODUCT_CODE" + "+'%' ");
parameters.Add(new DataParameter { ParameterName = "PRODUCT_CODE", DataType = DbType.String, Value = condition.PRODUCT_CODE });
}
if (string.IsNullOrEmpty(condition.MATERIAL_TYPE_CODE) == false)
{
whereBuilder.Append(" AND MC.MATERIAL_TYPE_CODE =@MATERIAL_TYPE_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE });
}
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 (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 int InsertProductOut(ProductOut model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
session.OpenTs();
//插入出库表
count = session.Insert<ProductOut>(model);
if (count > 0)
{
//更新本体表
count = session.Update<Product>(model.productList);
}
session.CommitTs();
}
catch (Exception)
{
session.RollbackTs();
throw;
}
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(ProductOut 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 = "ProductOutExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
#region 获取列表出库原因
/// <summary>
/// 获取列表出库原因
/// </summary>
/// <param name="condition">条件</param>
/// <returns>列表</returns>
public List<OutReason> GetOutReasonList(OutReason condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<OutReason> listProcessInfo = new List<OutReason>();
try
{
sql = "SELECT * FROM T_MD_OUTREASON";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
string sqlChange = this.ChangeSqlByDB(sql, session);
listProcessInfo = session.GetList<OutReason>(sqlChange, parameters.ToArray()).ToList();
}
return listProcessInfo;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "出库信息-获取列表");
throw ex;
}
}
#endregion
}
}