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.
1203 lines
48 KiB
1203 lines
48 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using QMAPP.FJC.Entity.FIS;
|
||
|
using QMFrameWork.Data;
|
||
|
using QMFrameWork.Log;
|
||
|
using System.Data;
|
||
|
using QMAPP.Entity;
|
||
|
using QMAPP.DAL;
|
||
|
using QMAPP.FJC.Entity.FileCopy.FIS;
|
||
|
|
||
|
namespace QMAPP.FJC.DAL.FIS
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 注塑计划管理
|
||
|
///
|
||
|
///
|
||
|
/// </summary>
|
||
|
public class OrderPlanDAL : BaseDAL
|
||
|
{
|
||
|
#region 获取信息
|
||
|
/// <summary>
|
||
|
/// 获取信息
|
||
|
/// </summary>
|
||
|
/// <param name="">条件</param>
|
||
|
/// <returns>信息</returns>
|
||
|
public OrderPlan Get(OrderPlan model)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_PP_ORDERPLAN WHERE 1=1 ";
|
||
|
if (string.IsNullOrEmpty(model.PID) == false)
|
||
|
{
|
||
|
sql += " AND PID = @PID";
|
||
|
parameters.Add(new DataParameter("PID", model.PID));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.PLAN_NO) == false)
|
||
|
{
|
||
|
sql += " AND PLAN_NO = @PLAN_NO";
|
||
|
parameters.Add(new DataParameter("PLAN_NO", model.PLAN_NO));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.MACHINECODDE) == false)
|
||
|
{
|
||
|
sql += " AND MACHINECODDE = @MACHINECODDE";
|
||
|
parameters.Add(new DataParameter("MACHINECODDE", model.MACHINECODDE));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false)
|
||
|
{
|
||
|
sql += " AND MATERIAL_CODE = @MATERIAL_CODE";
|
||
|
parameters.Add(new DataParameter("MATERIAL_CODE", model.MATERIAL_CODE));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.PLAN_STATES) == false)
|
||
|
{
|
||
|
sql += " AND PLAN_STATE IN ('" + model.PLAN_STATES.Replace(",", "','") + "')";
|
||
|
|
||
|
}
|
||
|
if (BaseSession != null)
|
||
|
{
|
||
|
//获取信息
|
||
|
model = BaseSession.Get<OrderPlan>(sql, parameters.ToArray());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//获取信息
|
||
|
model = session.Get<OrderPlan>(sql, parameters.ToArray());
|
||
|
}
|
||
|
}
|
||
|
return model;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "信息数据层-获取信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public OrderPlan GetOne(OrderPlan model)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_PP_ORDERPLAN WHERE PLAN_STATE IN ('1','2') ";
|
||
|
if (string.IsNullOrEmpty(model.PID) == false)
|
||
|
{
|
||
|
sql += " AND PID = @PID";
|
||
|
parameters.Add(new DataParameter("PID", model.PID));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.PLAN_NO) == false)
|
||
|
{
|
||
|
sql += " AND PLAN_NO = @PLAN_NO";
|
||
|
parameters.Add(new DataParameter("PLAN_NO", model.PLAN_NO));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.MACHINECODDE) == false)
|
||
|
{
|
||
|
sql += " AND MACHINECODDE = @MACHINECODDE";
|
||
|
parameters.Add(new DataParameter("MACHINECODDE", model.MACHINECODDE));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.MATERIAL_CODE) == false)
|
||
|
{
|
||
|
sql += " AND MATERIAL_CODE = @MATERIAL_CODE";
|
||
|
parameters.Add(new DataParameter("MATERIAL_CODE", model.MATERIAL_CODE));
|
||
|
}
|
||
|
|
||
|
sql += " order by CREATEDATE desc ";
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//获取信息
|
||
|
model = session.Get<OrderPlan>(sql, parameters.ToArray());
|
||
|
}
|
||
|
return model;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "信息数据层-获取信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public OrderPlan GetInfo(OrderPlan model)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_PP_ORDERPLAN WHERE PLAN_NO = @PLAN_NO";
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//获取信息
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLAN_NO", DataType = DbType.String, Value = model.PLAN_NO });
|
||
|
model = session.Get<OrderPlan>(sql, parameters.ToArray());
|
||
|
}
|
||
|
return model;
|
||
|
}
|
||
|
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 DataPage GetList(OrderPlan 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<OrderPlan>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "注塑信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取查询语句
|
||
|
/// <summary>
|
||
|
/// 获取查询语句
|
||
|
/// </summary>
|
||
|
/// <param name="user">查询条件</param>
|
||
|
/// <param name="parameters">参数</param>
|
||
|
/// <returns>查询语句</returns>
|
||
|
private string GetQuerySql(OrderPlan condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.AppendLine(" SELECT DISTINCT O.PID ");
|
||
|
sqlBuilder.AppendLine(" ,O.FACTORY_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_NO ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_SEQ ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_STATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.MATERIAL_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.MACHINECODDE ");
|
||
|
sqlBuilder.AppendLine(" ,O.PBOM_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.ROUTE_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.REMARK ");
|
||
|
sqlBuilder.AppendLine(" ,O.QTY ");
|
||
|
sqlBuilder.AppendLine(" ,O.COMPLETE_QTY ");
|
||
|
sqlBuilder.AppendLine(" ,CONVERT(VARCHAR(19),O.PLAN_DATE,120) AS PLAN_DATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.SHIFT_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,P.PRODUCESHIFTNAME AS SHIFT_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLANSOURCE ");
|
||
|
sqlBuilder.AppendLine(" ,O.PRODUCEREQUIRE ");
|
||
|
//sqlBuilder.AppendLine(" ,WC.WORKCENTER_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,O.CREATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.UPDATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,O.UPDATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.IGNORE_FISBREAK ");
|
||
|
sqlBuilder.AppendLine(" ,O.FIS_ASMSETCODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.STARTTIME AS STARTTIMEVIEW ");
|
||
|
sqlBuilder.AppendLine(" ,O.ENDTIME AS ENDTIMEVIEW");
|
||
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" FROM T_PP_ORDERPLAN O ");
|
||
|
//注塑所需要的表T_PP_WORKORDER
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PRODUCESHIFT P ON P.PRODUCESHIFTTCODE=O.SHIFT_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=O.FACTORY_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_PP_WORKORDER W ON W.ORDERPLANID=O.PID ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=O.MATERIAL_CODE ");
|
||
|
//sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCELL WC ON WC.WORKCELL_CODE=PRW.WORKCELL_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=O.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=O.UPDATEUSER ");
|
||
|
|
||
|
whereBuilder.AppendFormat(" AND O.WORKCENTER_CODE in (select distinct WORKCENTER from T_PP_ORDERINDENTITY where ORDER_TYPE='{0}')", condition.ORDER_TYPE);
|
||
|
//查询条件
|
||
|
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.FACTORY_CODE = @FACTORY_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(condition.PLAN_NO) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_NO = @PLAN_NO ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLAN_NO", DataType = DbType.String, Value = condition.PLAN_NO });
|
||
|
}
|
||
|
//物料号
|
||
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.MATERIAL_CODE = @MATERIAL_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
||
|
}
|
||
|
//工艺路线
|
||
|
if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.ROUTE_CODE = @ROUTE_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE });
|
||
|
}
|
||
|
//班次编码
|
||
|
if (string.IsNullOrEmpty(condition.SHIFT_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.SHIFT_CODE = @SHIFT_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "SHIFT_CODE", DataType = DbType.String, Value = condition.SHIFT_CODE });
|
||
|
}
|
||
|
//设备
|
||
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.MACHINECODDE = @MACHINECODDE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
|
||
|
}
|
||
|
//计划时间
|
||
|
if (condition.PLANTIMESTART != DateTime.MinValue)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_DATE >= @PLANTIMESTART");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLANTIMESTART", DataType = DbType.String, Value = condition.PLANTIMESTART });
|
||
|
}
|
||
|
if (condition.PLANTIMEEND != DateTime.MinValue)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_DATE <= @PLANTIMEEND");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLANTIMEEND", DataType = DbType.String, Value = condition.PLANTIMEEND });
|
||
|
}
|
||
|
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 信息是否重复
|
||
|
/// <summary>
|
||
|
/// 判断计划单号是否存在
|
||
|
/// </summary>
|
||
|
/// <param name="info"></param>
|
||
|
/// <returns>true:已存在;fasel:不存在。</returns>
|
||
|
public int ExistsOrderPlan(OrderPlan model)
|
||
|
{
|
||
|
string PID = "";
|
||
|
int count = 0;
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(model.PID) == false)
|
||
|
{
|
||
|
PID = model.PID;
|
||
|
}
|
||
|
sqlBuilder.AppendLine("SELECT COUNT(*) FROM T_PP_ORDERPLAN ");
|
||
|
sqlBuilder.AppendLine(" WHERE PID <> @PID AND PLAN_NO=@PLAN_NO");
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
|
||
|
new DataParameter("PID", PID),
|
||
|
new DataParameter { ParameterName = "PLAN_NO", Value = model.PLAN_NO }));
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 插入信息
|
||
|
/// <summary>
|
||
|
/// 插入信息(单表)
|
||
|
/// </summary>
|
||
|
/// <param name="">信息</param>
|
||
|
/// <returns>插入行数</returns>
|
||
|
public int Insert(OrderPlan model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
if (BaseSession != null)
|
||
|
{
|
||
|
//插入基本信息
|
||
|
count = BaseSession.Insert<OrderPlan>(model);
|
||
|
InsertOrderPlanTrace(BaseSession, model, "新增");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//插入基本信息
|
||
|
count = session.Insert<OrderPlan>(model);
|
||
|
InsertOrderPlanTrace(session, model, "新增");
|
||
|
}
|
||
|
}
|
||
|
//using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
//{
|
||
|
// //插入基本信息
|
||
|
// count = session.Insert<OrderPlan>(model);
|
||
|
//}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 更新信息
|
||
|
/// <summary>
|
||
|
/// 更新信息
|
||
|
/// </summary>
|
||
|
/// <param name=""></param>
|
||
|
/// <returns>更新行数</returns>
|
||
|
public int Update(OrderPlan model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
if (this.BaseSession != null)
|
||
|
{
|
||
|
count = BaseSession.Update<OrderPlan>(model);
|
||
|
InsertOrderPlanTrace(BaseSession, model, "修改");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//更新基本信息
|
||
|
count = session.Update<OrderPlan>(model);
|
||
|
InsertOrderPlanTrace(session, model, "修改");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 删除
|
||
|
/// <summary>
|
||
|
/// 删除信息
|
||
|
/// </summary>
|
||
|
/// <param name=""></param>
|
||
|
/// <returns>删除个数</returns>
|
||
|
//提交事务
|
||
|
public int Delete(OrderPlan model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//删除基本信息
|
||
|
count = session.Delete<OrderPlan>(model);
|
||
|
InsertOrderPlanTrace(session, model, "删除");
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 删除校验
|
||
|
/// <summary>
|
||
|
/// 删除校验
|
||
|
/// </summary>
|
||
|
/// <param name="model"></param>
|
||
|
/// <returns></returns>
|
||
|
public int DelCheck(OrderPlan model)
|
||
|
{
|
||
|
int num = 0;
|
||
|
int state;
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
||
|
|
||
|
sqlBuilder.AppendLine(" SELECT COMPLETE_QTY ");
|
||
|
sqlBuilder.AppendLine(" FROM T_PP_ORDERPLAN ");
|
||
|
sqlBuilder.AppendLine(" WHERE PID = @PID ");
|
||
|
sqlBuilder2.AppendLine(" SELECT PLAN_STATE ");
|
||
|
sqlBuilder2.AppendLine(" FROM T_PP_ORDERPLAN ");
|
||
|
sqlBuilder2.AppendLine(" WHERE PID = @PID ");
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
num = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("PID", model.PID)));
|
||
|
state = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder2.ToString(), new DataParameter("PID", model.PID)));
|
||
|
}
|
||
|
return num+state;
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 发布
|
||
|
/// <summary>
|
||
|
/// 发布信息
|
||
|
/// </summary>
|
||
|
/// <param name=""></param>
|
||
|
/// <returns>发布个数</returns>
|
||
|
public int PutOut(OrderPlan model, DataTable workOrderDt)
|
||
|
{
|
||
|
|
||
|
BaseSession = AppDataFactory.CreateMainSession();
|
||
|
IDbConnection dbConn = DbManager.MainConnectionInfo.Connection;
|
||
|
IDbTransaction ids = dbConn.BeginTransaction();
|
||
|
try
|
||
|
{
|
||
|
if (workOrderDt.Rows != null)
|
||
|
{
|
||
|
BaseSession.DbHelper.BulkCopyData(workOrderDt, "T_PP_WORKORDER", dbConn, ids);
|
||
|
ids.Commit();
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ids.Rollback();
|
||
|
throw ex;
|
||
|
}
|
||
|
int count = 0;
|
||
|
int count2 = 0;
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
sqlBuilder.AppendLine(" UPDATE T_PP_ORDERPLAN ");
|
||
|
sqlBuilder.AppendLine(" SET PLAN_STATE='1' ");
|
||
|
sqlBuilder.AppendLine(" WHERE PID = @PID ");
|
||
|
|
||
|
sqlBuilder2.AppendLine(" UPDATE T_PP_WORKORDER ");
|
||
|
sqlBuilder2.AppendLine(" SET STATE='1' ");
|
||
|
sqlBuilder2.AppendLine(" WHERE ORDERPLANID = @PID ");
|
||
|
|
||
|
//发布更新基本信息
|
||
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
||
|
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
||
|
count2 = session.ExecuteSql(sqlBuilder2.ToString(), parameters.ToArray());
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 发布 新
|
||
|
/// <summary>
|
||
|
/// 发布信息
|
||
|
/// 为了事物传递新的session zxd20171101
|
||
|
/// </summary>
|
||
|
/// <param name=""></param>
|
||
|
/// <returns>发布个数</returns>
|
||
|
public int PutOutBaseSession(OrderPlan model, DataTable workOrderDt)
|
||
|
{
|
||
|
if (BaseSession==null)
|
||
|
{
|
||
|
BaseSession = AppDataFactory.CreateMainSession();
|
||
|
}
|
||
|
|
||
|
//IDbConnection dbConn = DbManager.MainConnectionInfo.Connection;
|
||
|
//IDbTransaction ids = dbConn.BeginTransaction();
|
||
|
//try
|
||
|
//{
|
||
|
// if (workOrderDt.Rows != null)
|
||
|
// {
|
||
|
// BaseSession.DbHelper.BulkCopyData(workOrderDt, "T_PP_WORKORDER", dbConn, ids);
|
||
|
// ids.Commit();
|
||
|
// }
|
||
|
//}
|
||
|
//catch (Exception ex)
|
||
|
//{
|
||
|
// ids.Rollback();
|
||
|
// throw ex;
|
||
|
//}
|
||
|
int count = 0;
|
||
|
int count2 = 0;
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
|
||
|
sqlBuilder.AppendLine(" UPDATE T_PP_ORDERPLAN ");
|
||
|
sqlBuilder.AppendLine(" SET PLAN_STATE='1' ");
|
||
|
sqlBuilder.AppendLine(" WHERE PID = @PID ");
|
||
|
|
||
|
sqlBuilder2.AppendLine(" UPDATE T_PP_WORKORDER ");
|
||
|
sqlBuilder2.AppendLine(" SET STATE='1' ");
|
||
|
sqlBuilder2.AppendLine(" WHERE ORDERPLANID = @PID ");
|
||
|
|
||
|
//发布更新基本信息
|
||
|
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
|
||
|
//string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
|
||
|
count = BaseSession.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
|
||
|
count2 = BaseSession.ExecuteSql(sqlBuilder2.ToString(), parameters.ToArray());
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 发布校验
|
||
|
/// <summary>
|
||
|
/// 发布校验
|
||
|
/// </summary>
|
||
|
/// <param name="model"></param>
|
||
|
/// <returns></returns>
|
||
|
public int PutOutCheck(OrderPlan model)
|
||
|
{
|
||
|
int num = 0;
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
|
||
|
sqlBuilder.AppendLine(" SELECT PLAN_STATE ");
|
||
|
sqlBuilder.AppendLine(" FROM T_PP_ORDERPLAN ");
|
||
|
sqlBuilder.AppendLine(" WHERE PID = @PID ");
|
||
|
|
||
|
if (BaseSession != null)
|
||
|
{
|
||
|
num = Convert.ToInt32(BaseSession.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("PID", model.PID)));
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
num = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), new DataParameter("PID", model.PID)));
|
||
|
|
||
|
}
|
||
|
}
|
||
|
return num;
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 导入
|
||
|
public ImportMessage GetImportData(List<OrderPlan> list)
|
||
|
{
|
||
|
ImportMessage em = new ImportMessage();
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//设置祖先对象数据会话
|
||
|
session.OpenTs();
|
||
|
foreach (OrderPlan info in list)
|
||
|
{
|
||
|
if (info.IsNewInfo == true)
|
||
|
{
|
||
|
//插入信息
|
||
|
int count = session.Insert<OrderPlan>(info);
|
||
|
InsertOrderPlanTrace(session, info, "新增");
|
||
|
|
||
|
|
||
|
//痕迹表
|
||
|
FISPlanRecord record = new FISPlanRecord();
|
||
|
|
||
|
record.PID = Guid.NewGuid().ToString();
|
||
|
record.MID = info.PID;
|
||
|
record.PLAN_NO = info.PLAN_NO;
|
||
|
record.MATERIAL_CODE = info.MATERIAL_CODE;
|
||
|
record.PLAN_QTY = info.QTY;
|
||
|
record.OPERATION_TYPE = "0";
|
||
|
record.CREATEUSER = info.CREATEUSER;
|
||
|
record.CREATEDATE = info.CREATEDATE;
|
||
|
|
||
|
int no = new OrderPlanDAL().InsertRecord(record);
|
||
|
|
||
|
em.insertNum++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//更新信息
|
||
|
int count = session.Update<OrderPlan>(info);
|
||
|
InsertOrderPlanTrace(session, info, "修改");
|
||
|
|
||
|
#region 插入修改信息痕迹表
|
||
|
//插入修改信息痕迹表
|
||
|
FISPlanRecord record = new FISPlanRecord();
|
||
|
|
||
|
record.PID = Guid.NewGuid().ToString();
|
||
|
record.MID = info.PID;
|
||
|
record.PLAN_NO = info.PLAN_NO;
|
||
|
record.MATERIAL_CODE = info.MATERIAL_CODE;
|
||
|
record.PLAN_QTY = info.QTY;
|
||
|
record.OPERATION_TYPE = "1";
|
||
|
record.CREATEUSER = info.CREATEUSER;
|
||
|
record.CREATEDATE = info.CREATEDATE;
|
||
|
|
||
|
int no = new OrderPlanDAL().InsertRecord(record);
|
||
|
#endregion
|
||
|
|
||
|
em.updateNum++;
|
||
|
}
|
||
|
}
|
||
|
session.CommitTs();
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
return em;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取导出的数据
|
||
|
/// <summary>
|
||
|
/// 获取导出的数据
|
||
|
/// </summary>
|
||
|
/// <param name="user">查询条件</param>
|
||
|
/// <returns>数据</returns>
|
||
|
public DataTable GetExportData(OrderPlan 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 = "OrderPlanExp";
|
||
|
}
|
||
|
return dt;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 删除订单
|
||
|
|
||
|
public void DeleteOrderPlan(OrderPlan entity)
|
||
|
{
|
||
|
if (this.BaseSession != null)
|
||
|
{
|
||
|
BaseSession.Delete<OrderPlan>(entity);
|
||
|
InsertOrderPlanTrace(BaseSession,entity, "删除");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using(IDataSession session=AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
session.Delete<OrderPlan>(entity);
|
||
|
InsertOrderPlanTrace(session,entity, "删除");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 改变更新订单
|
||
|
/// <summary>
|
||
|
/// 改变更新订单
|
||
|
/// </summary>
|
||
|
/// <param name="entity"></param>
|
||
|
public void ChangeOrderPlan(OrderPlan entity)
|
||
|
{
|
||
|
if (this.BaseSession != null)
|
||
|
{
|
||
|
|
||
|
this.BaseSession.Update<OrderPlan>(entity);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
|
||
|
session.Update<OrderPlan>(entity);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取流水号
|
||
|
/// <summary>
|
||
|
/// 获取流水号
|
||
|
/// </summary>
|
||
|
/// <param name="">条件</param>
|
||
|
/// <returns>*信息</returns>
|
||
|
public FISPlan GetOrderPlanSeq(FISPlan model)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "SELECT * FROM T_AW_FISPLAN WHERE 1=1 ";
|
||
|
if (string.IsNullOrEmpty(model.PREFIX) == false)
|
||
|
{
|
||
|
sql += " AND PREFIX = @PREFIX";
|
||
|
parameters.Add(new DataParameter("PREFIX", model.PREFIX));
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(model.DATASTR) == false)
|
||
|
{
|
||
|
sql += " AND DATASTR = @DATASTR";
|
||
|
parameters.Add(new DataParameter("DATASTR", model.DATASTR));
|
||
|
}
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//获取信息
|
||
|
model = session.Get<FISPlan>(sql, parameters.ToArray());
|
||
|
}
|
||
|
return model;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "流水号本体-获取信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 更新流水号信息
|
||
|
/// <summary>
|
||
|
/// 更新流水号信息
|
||
|
/// </summary>
|
||
|
/// <param name=""></param>
|
||
|
/// <returns>更新行数</returns>
|
||
|
public int UpdateFisPlan(FISPlan model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
if (this.BaseSession != null)
|
||
|
{
|
||
|
count = BaseSession.Update<FISPlan>(model);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//更新基本信息
|
||
|
count = session.Update<FISPlan>(model);
|
||
|
}
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 插入流水号信息
|
||
|
/// <summary>
|
||
|
/// 插入信息(单表)
|
||
|
/// </summary>
|
||
|
/// <param name=model"">物料号信息</param>
|
||
|
/// <returns>插入行数</returns>
|
||
|
public int InsertFisPlan(FISPlan model)
|
||
|
{
|
||
|
int count = 0;
|
||
|
try
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//插入基本信息
|
||
|
count = session.Insert<FISPlan>(model);
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "物料号信息数据层-插入信息"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 插入信息
|
||
|
/// <summary>
|
||
|
/// 插入信息(单表)
|
||
|
/// </summary>
|
||
|
/// <param name="">信息</param>
|
||
|
/// <returns>插入行数</returns>
|
||
|
public int InsertRecord(FISPlanRecord record)
|
||
|
{
|
||
|
int no = 0;
|
||
|
try
|
||
|
{
|
||
|
if (BaseSession != null)
|
||
|
{
|
||
|
//插入基本信息
|
||
|
no = BaseSession.Insert<FISPlanRecord>(record);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
//插入基本信息
|
||
|
no = session.Insert<FISPlanRecord>(record);
|
||
|
}
|
||
|
}
|
||
|
return no;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 配置设备人员
|
||
|
|
||
|
#region 配置设备人员
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <param name="page">数据页</param>
|
||
|
/// <returns>数据页</returns>
|
||
|
public DataPage FisPlanRecordList(FISPlanRecord condition, DataPage page)
|
||
|
{
|
||
|
string sql = "";
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetFisPlanRecordSql(condition, ref parameters);
|
||
|
|
||
|
//分页关键字段及排序
|
||
|
page.KeyName = "PID";
|
||
|
if (string.IsNullOrEmpty(page.SortExpression))
|
||
|
{
|
||
|
page.SortExpression = "CREATEDATE DESC";
|
||
|
}
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
page = session.GetDataPage<FISPlanRecord>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "订单信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取查询语句
|
||
|
/// <summary>
|
||
|
/// 获取查询语句
|
||
|
/// </summary>
|
||
|
/// <param name="user">查询条件</param>
|
||
|
/// <param name="parameters">参数</param>
|
||
|
/// <returns>查询语句</returns>
|
||
|
private string GetFisPlanRecordSql(FISPlanRecord condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.AppendLine(" SELECT P.PID ");
|
||
|
sqlBuilder.AppendLine(" ,P.MID ");
|
||
|
sqlBuilder.AppendLine(" ,P.PLAN_NO ");
|
||
|
sqlBuilder.AppendLine(" ,P.MATERIAL_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,P.PLAN_QTY ");
|
||
|
sqlBuilder.AppendLine(" ,P.OPERATION_TYPE ");
|
||
|
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,P.CREATEDATE ");;
|
||
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" FROM T_AW_FISPLANRECORD P ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=P.CREATEUSER ");
|
||
|
|
||
|
//查询条件
|
||
|
if (string.IsNullOrEmpty(condition.MID) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND P.MID= @MID ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MID", DataType = DbType.String, Value = condition.PLAN_NO });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 计划管理操作记录
|
||
|
/// <summary>
|
||
|
/// 插入计划管理操作记录
|
||
|
/// </summary>
|
||
|
public int InsertOrderPlanTrace(IDataSession Bsession,OrderPlan model,string operatType)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var opt=new OrderPlanTrace
|
||
|
{
|
||
|
PID = Guid.NewGuid().ToString(),
|
||
|
FACTORY_CODE = model.FACTORY_CODE,
|
||
|
PLAN_NO = model.PLAN_NO ,
|
||
|
PLAN_SEQ = model.PLAN_SEQ ,
|
||
|
PLAN_STATE = model.PLAN_STATE ,
|
||
|
MATERIAL_CODE = model.MATERIAL_CODE ,
|
||
|
MACHINECODDE = model.MACHINECODDE ,
|
||
|
PBOM_CODE = model.PBOM_CODE ,
|
||
|
ROUTE_CODE = model.ROUTE_CODE ,
|
||
|
REMARK = model.REMARK ,
|
||
|
QTY = model.QTY ,
|
||
|
COMPLETE_QTY = model.COMPLETE_QTY ,
|
||
|
PLAN_DATE = model.PLAN_DATE ,
|
||
|
SHIFT_CODE = model.SHIFT_CODE ,
|
||
|
PLANSOURCE = model.PLANSOURCE ,
|
||
|
PRODUCEREQUIRE = model.PRODUCEREQUIRE ,
|
||
|
CREATEDATE = model.UPDATEDATE ,
|
||
|
CREATEUSER = model.UPDATEUSER ,
|
||
|
UPDATEDATE = model.UPDATEDATE ,
|
||
|
UPDATEUSER = model.UPDATEUSER ,
|
||
|
WORKCENTER_CODE = model.WORKCENTER_CODE ,
|
||
|
IGNORE_FISBREAK = model.IGNORE_FISBREAK ,
|
||
|
OPERATE_TYPE = operatType
|
||
|
};
|
||
|
return Bsession.Insert<OrderPlanTrace>(opt);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public DataPage GetTraceList(OrderPlanTrace condition, DataPage page)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySqlTrace(condition, ref parameters);
|
||
|
//分页关键字段及排序
|
||
|
page.KeyName = "PID";
|
||
|
if (string.IsNullOrEmpty(page.SortExpression))
|
||
|
{
|
||
|
page.SortExpression = "UPDATEDATE DESC";
|
||
|
}
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
page = session.GetDataPage<OrderPlanTrace>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "注塑信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
private string GetQuerySqlTrace(OrderPlanTrace condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.AppendLine(" SELECT DISTINCT O.PID ");
|
||
|
sqlBuilder.AppendLine(" ,O.FACTORY_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,F.FACTORY_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_NO ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_SEQ ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLAN_STATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.MATERIAL_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,M.MATERIAL_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.MACHINECODDE ");
|
||
|
sqlBuilder.AppendLine(" ,O.PBOM_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.ROUTE_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,O.REMARK ");
|
||
|
sqlBuilder.AppendLine(" ,O.QTY ");
|
||
|
sqlBuilder.AppendLine(" ,O.COMPLETE_QTY ");
|
||
|
sqlBuilder.AppendLine(" ,CONVERT(VARCHAR(19),O.PLAN_DATE,120) AS PLAN_DATE");
|
||
|
sqlBuilder.AppendLine(" ,O.SHIFT_CODE ");
|
||
|
sqlBuilder.AppendLine(" ,P.PRODUCESHIFTNAME AS SHIFT_NAME ");
|
||
|
sqlBuilder.AppendLine(" ,O.PLANSOURCE ");
|
||
|
sqlBuilder.AppendLine(" ,O.PRODUCEREQUIRE ");
|
||
|
sqlBuilder.AppendLine(" ,O.OPERATE_TYPE ");
|
||
|
sqlBuilder.AppendLine(" ,O.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,CONVERT(VARCHAR(19),O.CREATEDATE,120) as CREATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.UPDATEUSER ");
|
||
|
sqlBuilder.AppendLine(" ,CONVERT(VARCHAR(19),O.UPDATEDATE,120) as UPDATEDATE ");
|
||
|
sqlBuilder.AppendLine(" ,O.IGNORE_FISBREAK ");
|
||
|
sqlBuilder.AppendLine(" ,O.FIS_ASMSETCODE ");
|
||
|
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
|
||
|
sqlBuilder.AppendLine(" FROM T_PP_ORDERPLANTRACE O ");
|
||
|
//注塑所需要的表T_PP_WORKORDER
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PRODUCESHIFT P ON P.PRODUCESHIFTTCODE=O.SHIFT_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY F ON F.FACTORY_CODE=O.FACTORY_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_PP_WORKORDER W ON W.ORDERPLANID=O.PID ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=O.MATERIAL_CODE ");
|
||
|
//sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCELL WC ON WC.WORKCELL_CODE=PRW.WORKCELL_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=O.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=O.UPDATEUSER ");
|
||
|
|
||
|
//whereBuilder.AppendFormat(" AND O.WORKCENTER_CODE in (select distinct WORKCENTER from T_PP_ORDERINDENTITY where ORDER_TYPE='{0}')", condition.ORDER_TYPE);
|
||
|
//查询条件
|
||
|
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.FACTORY_CODE = @FACTORY_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.WORKCENTER_CODE = @WORKCENTER_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(condition.PLAN_NO) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_NO like '%'+@PLAN_NO+'%' ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLAN_NO", DataType = DbType.String, Value = condition.PLAN_NO });
|
||
|
}
|
||
|
//物料号
|
||
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.MATERIAL_CODE = @MATERIAL_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
||
|
}
|
||
|
//工艺路线
|
||
|
if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.ROUTE_CODE = @ROUTE_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE });
|
||
|
}
|
||
|
//班次编码
|
||
|
if (string.IsNullOrEmpty(condition.SHIFT_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.SHIFT_CODE = @SHIFT_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "SHIFT_CODE", DataType = DbType.String, Value = condition.SHIFT_CODE });
|
||
|
}
|
||
|
//设备
|
||
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.MACHINECODDE = @MACHINECODDE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
|
||
|
}
|
||
|
//计划时间
|
||
|
if (condition.PLANTIMESTART != DateTime.MinValue)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_DATE >= @PLANTIMESTART");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLANTIMESTART", DataType = DbType.String, Value = condition.PLANTIMESTART });
|
||
|
}
|
||
|
if (condition.PLANTIMEEND != DateTime.MinValue)
|
||
|
{
|
||
|
whereBuilder.Append(" AND O.PLAN_DATE <= @PLANTIMEEND");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PLANTIMEEND", DataType = DbType.String, Value = condition.PLANTIMEEND });
|
||
|
}
|
||
|
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
public DataTable GetExportDataTrace(OrderPlanTrace model)
|
||
|
{
|
||
|
DataTable dt = null;
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sql = this.GetQuerySqlTrace(model, ref parameters);
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
dt = session.GetTable(sql, parameters.ToArray());
|
||
|
dt.TableName = "OrderPlanExp";
|
||
|
}
|
||
|
return dt;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
}
|