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.
340 lines
12 KiB
340 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.DAL;
|
|
using QMAPP.Entity.Sys;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Log;
|
|
|
|
namespace QMAPP.FJC.DAL.ProductIn
|
|
{
|
|
public class ProductInDAL : BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public Entity.ProductIn.ProductIn Get(Entity.ProductIn.ProductIn model)
|
|
{
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
model = session.Get(model);
|
|
}
|
|
return model;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取入库记录
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public Entity.ProductIn.ProductIn GetInRecord(string productcode)
|
|
{
|
|
try
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = "SELECT * FROM T_AW_PRODUCTIN WHERE PRODUCTCODE=@productcode";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
return session.Get<Entity.ProductIn.ProductIn>(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取入库记录
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public Entity.ProductIn.ProductIn GetInRecordmp4(string productcode)
|
|
{
|
|
try
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = "SELECT * FROM T_AW_PRODUCTIN WHERE PRODUCTCODE=@productcode";
|
|
using (IDataSession session = AppDataFactory.CreateSession("maindbBC316_MP4"))
|
|
{
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
return session.Get<Entity.ProductIn.ProductIn>(sql, parameters.ToArray());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public DataPage GetList(Entity.ProductIn.ProductIn 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 = "INDATE DESC";
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Entity.ProductIn.ProductIn>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public List<Entity.ProductIn.ProductIn> GetAllList(Entity.ProductIn.ProductIn condition)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = this.GetQuerySql(condition, ref parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Entity.ProductIn.ProductIn>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
|
|
|
|
public List<Entity.ProductIn.ProductIn> GetInRecords(string productcode)
|
|
{
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT I.* ");
|
|
sql.AppendLine(" ,U.USERNAME AS INUSER_NAME ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCTIN AS I ");
|
|
sql.AppendLine(" LEFT JOIN T_QM_USER AS U ");
|
|
sql.AppendLine(" ON I.INUSER=U.USERID ");
|
|
sql.AppendLine(" WHERE I.PRODUCTCODE=@productcode");
|
|
sql.AppendLine(" ORDER BY INDATE");
|
|
|
|
parameters.Add(new DataParameter("productcode", productcode));
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Entity.ProductIn.ProductIn>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
|
|
#region 查询语句
|
|
/// <summary>
|
|
/// 查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(Entity.ProductIn.ProductIn condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
// ,(case when INTTYPE='0' then '退货入库' else '其它入库' end) as INTTYPE_NAME
|
|
sqlBuilder.Append(@"SELECT [PID]
|
|
,[INTTYPE]
|
|
|
|
,[PRODUCTCODE]
|
|
,[MATERIAL_CODE]
|
|
,(select MATERIAL_NAME from T_MD_MATERIAL where MATERIAL_CODE=t.MATERIAL_CODE) as MATERIAL_NAME
|
|
,(select USERNAME from T_QM_USER where USERID=INUSER) as INUSER_NAME
|
|
,[INUSER]
|
|
,CONVERT(VARCHAR(19),[INDATE],120) AS [INDATE]
|
|
FROM T_AW_PRODUCTIN t");
|
|
|
|
//查询条件
|
|
if (string.IsNullOrEmpty(condition.INTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND INTTYPE =@INTTYPE");
|
|
parameters.Add(new DataParameter { ParameterName = "INTTYPE", DataType = DbType.String, Value = condition.INTTYPE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%' ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
|
|
}
|
|
|
|
if (condition.CREATEDATESTART != DateTime.MinValue)
|
|
{
|
|
whereBuilder.Append(" AND INDATE >= @CREATEDATESTART");
|
|
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "CREATEDATESTART", Value = condition.CREATEDATESTART.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
}
|
|
|
|
if (condition.CREATEDATEEND != DateTime.MinValue)
|
|
{
|
|
whereBuilder.Append(" AND INDATE < @CREATEDATEEND");
|
|
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "CREATEDATEEND", Value = condition.CREATEDATEEND.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
public int Update(Entity.ProductIn.ProductIn model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = session.Update(model);
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Entity.ProductIn.ProductIn model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var productCode = "";
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
string sql = "SELECT EPIDERMISCODE as PRODUCTCODE FROM T_AW_MAIN where MAINCODE='" + model.PRODUCTCODE + "' order by CREATEDATE desc";
|
|
var main = session.Get<Product>(sql, parameters.ToArray());
|
|
if (main != null)
|
|
{
|
|
productCode = main.PRODUCTCODE;
|
|
}
|
|
else
|
|
{
|
|
productCode = model.PRODUCTCODE;
|
|
}
|
|
sql = "SELECT * FROM T_AW_PRODUCT where PRODUCTCODE='" + productCode + "' and OUTFLAG='1' order by CREATEDATE desc";
|
|
var p = session.Get<Product>(sql, parameters.ToArray());
|
|
if (p != null)
|
|
{
|
|
//更新出库状态
|
|
p.OUTFLAG = "0";
|
|
session.Update(p);
|
|
model.MATERIAL_CODE = p.MATERIAL_CODE;
|
|
//插入基本信息
|
|
count = session.Insert<Entity.ProductIn.ProductIn>(model);
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(Entity.ProductIn.ProductIn model)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//删除基本信息
|
|
sqlBuilder.Append("DELETE T_AW_PRODUCTIN ");
|
|
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 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(Entity.ProductIn.ProductIn 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 = "ProductInExp";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "导出获取数据错误!"
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|