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

1667 lines
71 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Stocktaking;
using QMAPP.FJC.Entity.ProcessParameter;
using System.Data;
using QMAPP.FJC.Web.Models.Stocktaking;
using System.Collections;
using QMFrameWork.Log;
using QMAPP.DAL;
using QMAPP.Entity;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.Operation;
namespace QMAPP.FJC.DAL.Stocktaking
{
/// <summary>
/// 盘点记录信息查询
/// 模块编号:M14-1
/// 作 者:崔法宝
/// 编写日期:2017年09月13日
/// </summary>
public class StocktakingDAL : BaseDAL
{
#region 获取列表(手持)
public List<CountingSheet> GetAllList(string planid)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT S.MATERIAL_CODE AS [MaterialCode] ");
sql.AppendLine(" ,M.MATERIAL_NAME [MaterialName] ");
sql.AppendLine(" ,SUM(S.QTY) AS [Count] ");
sql.AppendLine(" FROM T_PP_COUNTSHEET AS S ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
sql.AppendLine(" ON S.MATERIAL_CODE=M.MATERIAL_CODE ");
sql.AppendLine(" WHERE PLANID=@planid ");
sql.AppendLine(" GROUP BY S.MATERIAL_CODE,M.MATERIAL_NAME");
parameters.Add(new DataParameter("planid", planid));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<CountingSheet>(sql.ToString(), parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "盘点计划信息数据层-获取列表"
});
throw;
}
}
//#region 获取子页面详细列表
///// <summary>
///// 获取子页面详细列表
///// </summary>
///// <param name="condition">条件</param>
///// <param name="page">数据页</param>
///// <returns>数据页</returns>
//public DataPage GetSubList(CountingdetailInfo condition, DataPage page)
//{
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetSubQuerySql(condition, ref parameters);
// //分页关键字段及排序
// page.KeyName = "PID";
// page.SortExpression = "UPDATEDATE DESC";
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// page = session.GetDataPage<CountingdetailInfo>(sql, parameters.ToArray(), page);
// }
// return page;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//#endregion
//#region 获取详细信息根据PID(点击添加的时候)
///// <summary>
///// 获取详细信息根据PID
///// </summary>
///// <param name="condition">条件</param>
///// <param name="page">数据页</param>
///// <returns>数据页</returns>
//public DataTable GetModel(string PID)
//{
// DataTable table = null;
// StringBuilder sqlBuilder = new StringBuilder();
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sqlBuilder.Append(" select * from T_PP_COUNTINGPLAN where PID='" + PID + "'");
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// table = session.GetTable(sqlBuilder.ToString(), parameters.ToArray());
// }
// return table;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//#endregion
//#region 获取详细信息根据PLANID
///// <summary>
///// 获取详细信息根据PLANID
///// </summary>
///// <param name="condition">条件</param>
///// <param name="page">数据页</param>
///// <returns>数据页</returns>
//public DataTable GetSubModel(string PLANID)
//{
// DataTable table = null;
// StringBuilder sqlBuilder = new StringBuilder();
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sqlBuilder.Append(" select * from T_PP_COUNTINGDETAIL where PLANID='" + PLANID + "'");
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// table = session.GetTable(sqlBuilder.ToString(), parameters.ToArray());
// }
// return table;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//#endregion
#region 返回登记数量
/// <summary>
/// 返回登记数量
/// </summary>
/// <param name="PID"></param>
/// <returns></returns>
public string ReturnREGISTNUMBER(string PID)
{
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.Append(@"select
count(1) as num
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID
inner join
dbo.T_AW_PRODUCT Pt
on D.MATERIAL_Code=Pt.MATERIAL_Code ");
sqlBuilder.Append(" where P.PID='" + PID + "' ");
return sqlBuilder.ToString();
}
#endregion
#region 返回实际数量
/// <summary>
/// 返回实际数量
/// </summary>
/// <param name="PID"></param>
/// <returns></returns>
public string ReturnACTUALNUMBER(string PID)
{
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.Append(@"select count(1) from T_PP_COUNTSHEET ");
sqlBuilder.Append("where PLANID='" + PID + "'");
return sqlBuilder.ToString();
}
#endregion
#region 盘点比对处理
/// <summary>
/// 盘点比对处理
/// </summary>
/// <param name="PID"></param>
/// <returns></returns>
public int detailCompareResult(string PID, string CREATEUSER)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sqlBuilder2 = new StringBuilder();
StringBuilder sqlBuilder3 = new StringBuilder();
StringBuilder sqlBuilder4 = new StringBuilder();
StringBuilder sqlBuilder5 = new StringBuilder();
StringBuilder sqlBuilder6 = new StringBuilder();
StringBuilder sqlBuilder7 = new StringBuilder();
StringBuilder sqlBuilder8 = new StringBuilder();
StringBuilder sqlBuilder9 = new StringBuilder();
StringBuilder sqlBuilder10 = new StringBuilder();
object result = null;
object result2 = null;
object result3 = null;
List<DataParameter> parameters = new List<DataParameter>();
string[] list = PID.Split(":".ToCharArray());
int resultData = 0;
foreach (string id in list)
{
sqlBuilder.Append(@"
select
sum(PT.CAPACITY-PT.USingCount) AS num
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID
INNER join
dbo.T_AW_PRODUCT Pt
on D.MATERIAL_Code=Pt.MATERIAL_Code
");
sqlBuilder.Append(@" where P.PID='" + id + "'");
sqlBuilder2.Append(@"
select sum(QTY) from T_PP_COUNTSHEET ");
sqlBuilder2.Append("where PLANID='" + id + "' ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray());
result2 = session.ExecuteSqlScalar(sqlBuilder2.ToString(), parameters.ToArray());
if (string.IsNullOrEmpty(result.ToString()))
{
result = "0";
}
if (string.IsNullOrEmpty(result2.ToString()))
{
result2 = "0";
}
sqlBuilder3.Append(@" update T_PP_COUNTINGPLAN set REGISTNUMBER='" + result.ToString() + "' ,UPDATEdATE='" + DateTime.Now.ToString() + "',PLAN_STATE='2', ACTUALNUMBER='" + result2.ToString() + "' where PID='" + id + "'");
session.ExecuteSql(sqlBuilder3.ToString(), parameters.ToArray());
int QTY = 0;
//int COMPARERESULT = 0;
List<CountingdetailInfo> listresult = new List<CountingdetailInfo>();
//删除对比结果表数据
sqlBuilder9.Append(@" delete from T_PP_COUNTRESULT where PLANID='" + id + "'");
session.ExecuteSql(sqlBuilder9.ToString(), parameters.ToArray());
if (Convert.ToInt32(result) - Convert.ToInt32(result2) < 0)
{
sqlBuilder4.Append(@" update T_PP_COUNTINGPLAN set ERROWSTATUS='异常' where PID='" + id + "' ");
session.ExecuteSqlScalar(sqlBuilder4.ToString(), parameters.ToArray());
}
if (Convert.ToInt32(result) - Convert.ToInt32(result2) > 0)
{
sqlBuilder4.Append(@" update T_PP_COUNTINGPLAN set ERROWSTATUS='异常' where PID='" + id + "' ");
session.ExecuteSqlScalar(sqlBuilder4.ToString(), parameters.ToArray());
}
if (Convert.ToInt32(result) - Convert.ToInt32(result2) == 0)
{
sqlBuilder4.Append(@" update T_PP_COUNTINGPLAN set ERROWSTATUS='异常' where PID='" + id + "' ");
session.ExecuteSqlScalar(sqlBuilder4.ToString(), parameters.ToArray());
}
//处理计划表没有数据
sqlBuilder5.Append(@"select
sum(PT.CAPACITY-PT.USingCount) AS num,
pt.MATERIAL_Code,
D.MATERIAL_TYPE_CODE,
D.MATERIAL_CODE
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID
INNER join
dbo.T_AW_PRODUCT Pt
on D.MATERIAL_Code=Pt.MATERIAL_Code ");
sqlBuilder5.Append("where P.PID='" + id + "' and D.MATERIAL_cODE ");
sqlBuilder5.Append(@" not in
(
select
C.MATERIAL_CODE
from T_PP_COUNTSHEET C where C.PlanID='" + id + "'");
sqlBuilder5.Append(@" )
GROUP BY D.MATERIAL_TYPE_CODE,D.MATERIAL_CODE,
pt.MATERIAL_Code ");
IList<CountingdetailInfo> listresult1 = session.GetList<CountingdetailInfo>(sqlBuilder5.ToString(), parameters.ToArray());
foreach (CountingdetailInfo item in listresult1)
{
//item.COMPARERESULT = "实物亏";
item.COMPARERESULT = "0";
//if (Convert.ToInt32(item.num) < 0)
//{
// item.num = item.num.Substring(1);
// item.COMPARERESULT = "0";
//}
//else
//{
// item.COMPARERESULT = "1";
//}
listresult.Add(item);
}
//处理计划实际相同数据
sqlBuilder6.Append(@" select
C.MATERIAL_CODE,
isnull(C.QTY-AA.num,0) AS num ,
C.MATERIAL_TYPE_CODE,
C.MATERIAL_SN
from T_PP_COUNTSHEET C
left join
(
select
sum(PT.CAPACITY-PT.USingCount) AS num,
pt.MATERIAL_Code
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID
INNER join
dbo.T_AW_PRODUCT Pt
on D.MATERIAL_Code=Pt.MATERIAL_Code
where P.PID='" + id + "' ");
sqlBuilder6.Append(@" GROUP BY D.MATERIAL_TYPE_CODE,D.MATERIAL_CODE,
pt.MATERIAL_Code
) AA on C.MATERIAL_CODE=AA.MATERIAL_Code
where C.MATERIAL_CODE in
(
select
D.MATERIAL_Code
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID ");
sqlBuilder6.Append(@" where P.PID='" + id + "' ");
sqlBuilder6.Append(@" ) and C.PlanID='" + id + "' ");
IList<CountingdetailInfo> listresult2 = session.GetList<CountingdetailInfo>(sqlBuilder6.ToString(), parameters.ToArray());
foreach (CountingdetailInfo item in listresult2)
{
//item.COMPARERESULT = "实物赢";
// item.COMPARERESULT = "1";
if (item.num != "0")
{
if (Convert.ToInt32(item.num) < 0)
{
item.num = item.num.Substring(1);
item.COMPARERESULT = "0";
}
else
{
item.COMPARERESULT = "1";
}
listresult.Add(item);
}
}
// 处理实际表没有数据
sqlBuilder8.Append(@"select
C.MATERIAL_CODE,
C.QTY AS num ,
C.MATERIAL_TYPE_CODE,
C.MATERIAL_SN
from T_PP_COUNTSHEET C
where C.MATERIAL_CODE not in
(
select
pt.MATERIAL_Code
from T_PP_COUNTINGPLAN P
inner join T_PP_COUNTINGDETAIL D
ON p.PID= D.PLANID
INNER join
dbo.T_AW_PRODUCT Pt
on D.MATERIAL_Code=Pt.MATERIAL_Code ");
sqlBuilder8.Append("where P.PID='" + id + "' ");
sqlBuilder8.Append(@"GROUP BY D.MATERIAL_TYPE_CODE,D.MATERIAL_CODE,
pt.MATERIAL_Code
) and C.PLanID='" + id + "' ");
IList<CountingdetailInfo> listresult3 = session.GetList<CountingdetailInfo>(sqlBuilder8.ToString(), parameters.ToArray());
foreach (CountingdetailInfo item in listresult3)
{
int num1 = Convert.ToInt32(item.num);
if (num1 != 0)
{
if (num1 > 0)
{
// item.COMPARERESULT = "实物赢";
item.COMPARERESULT = "1";
}
else
{
// item.COMPARERESULT = "实物亏";
item.COMPARERESULT = "0";
}
listresult.Add(item);
}
}
//往数据库中插入数据
foreach (CountingdetailInfo item in listresult)
{
sqlBuilder7 = new StringBuilder();
sqlBuilder7.Append("insert into T_PP_COUNTRESULT ");
sqlBuilder7.Append(" ( ");
sqlBuilder7.Append(" PID,PLANID,PLAN_NO,MATERIAL_TYPE_CODE,");
sqlBuilder7.Append(" MATERIAL_CODE,MATERIAL_SN,QTY,COMPARERESULT,");
sqlBuilder7.Append(" CREATEUSER,CREATEDATE");
sqlBuilder7.Append(" ) ");
sqlBuilder7.Append(" values");
sqlBuilder7.Append(" (");
sqlBuilder7.Append(" '" + Guid.NewGuid().ToString() + "',");
sqlBuilder7.Append(" '" + id + "',");
sqlBuilder7.Append(" '" + item.PLAN_NO + "',");
sqlBuilder7.Append(" '" + item.MATERIAL_TYPE_CODE + "',");
sqlBuilder7.Append(" '" + item.MATERIAL_CODE + "',");
//if (item.COMPARERESULT == "0")
//{
// sqlBuilder7.Append(" '" + "''" + "',");
//}
//else
//{
sqlBuilder7.Append(" '" + item.MATERIAL_SN + "',");
// }
sqlBuilder7.Append("" + item.num + ",");
sqlBuilder7.Append("" + Convert.ToInt32(item.COMPARERESULT) + ",");
sqlBuilder7.Append(" '" + CREATEUSER + "',");
sqlBuilder7.Append("'" + Convert.ToDateTime(DateTime.Now.ToString()) + "'");
sqlBuilder7.Append(" )");
session.ExecuteSql(sqlBuilder7.ToString(), parameters.ToArray());
}
if (listresult.Count == 0)//如果没有差异
{
sqlBuilder10.Append(@" update T_PP_COUNTINGPLAN set ERROWSTATUS='正常' where PID='" + id + "' ");
session.ExecuteSqlScalar(sqlBuilder10.ToString(), parameters.ToArray());
}
else
{
sqlBuilder10.Append(@" update T_PP_COUNTINGPLAN set ERROWSTATUS='异常' where PID='" + id + "' ");
session.ExecuteSqlScalar(sqlBuilder10.ToString(), parameters.ToArray());
}
}
resultData++;
}
return resultData;
}
#endregion
#endregion
#region 获取实体T_PP_COUNTINGPLAN
public Countingplaninfo Get(Countingplaninfo condition)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_PP_COUNTINGPLAN WHERE '1'='1'";
if (string.IsNullOrEmpty(condition.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", condition.PID));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
condition = session.Get<Countingplaninfo>(sqlChange, parameters.ToArray());
}
return condition;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "用户设备数据层-获取信息");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Countingplaninfo 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 = "UPDATEDATE DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<Countingplaninfo>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表(手持)
/// <summary>
/// 获取列表(手持)
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<Countingplaninfo> GetAllList(Countingplaninfo condition)
{
List<Countingplaninfo> list = new List<Countingplaninfo>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<Countingplaninfo>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "盘点计划信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句T_PP_COUNTINGPLAN主界面
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(Countingplaninfo condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT P.PID ");
sqlBuilder.AppendLine(" ,P.ERROWSTATUS ");
sqlBuilder.AppendLine(" ,P.FACTORY_CODE ");
sqlBuilder.AppendLine(" ,P.PLAN_NO ");
sqlBuilder.AppendLine(" ,P.PLAN_STATE ");
sqlBuilder.AppendLine(" ,P.REMARK ");
sqlBuilder.AppendLine(" ,P.PLAN_DATE ");
sqlBuilder.AppendLine(" ,P.REGISTNUMBER ");
sqlBuilder.AppendLine(" ,P.ACTUALNUMBER ");
sqlBuilder.AppendLine(" ,P.COUNTTYPE ");
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
sqlBuilder.AppendLine(" ,P.UPDATEUSER ");
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_PP_COUNTINGPLAN P ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=P.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=P.UPDATEUSER ");
//sqlBuilder.Append(" select PID,ERROWSTATUS,FACTORY_CODE,PLAN_NO,PLAN_STATE,REMARK,substring(convert(varchar(20),PLAN_DATE,23),0,11)as PLAN_DATE, ");
//sqlBuilder.Append(" REGISTNUMBER,ACTUALNUMBER,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE,COUNTTYPE ");
//sqlBuilder.Append(" from T_PP_COUNTINGPLAN ");
if (!string.IsNullOrEmpty(condition.PLAN_NO))
{
whereBuilder.Append(" AND P.PLAN_NO ='" + condition.PLAN_NO + "'");
}
if (!string.IsNullOrEmpty(condition.PLAN_STATE))
{
whereBuilder.Append(" AND P.PLAN_STATE ='" + condition.PLAN_STATE + "'");
}
//计划时间
if (condition.PLANTIMESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND P.PLAN_DATE >= @PLANTIMESTART");
parameters.Add(new DataParameter { ParameterName = "PLANTIMESTART", DataType = DbType.String, Value = condition.PLANTIMESTART });
}
if (condition.PLANTIMEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND P.PLAN_DATE <= @PLANTIMEEND");
parameters.Add(new DataParameter { ParameterName = "PLANTIMEEND", DataType = DbType.String, Value = condition.PLANTIMEEND });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE 1=1 " + whereBuilder.ToString());
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句T_PP_COUNTINGDETAIL
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetSubQuerySql(CountingdetailInfo condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT P.PID ");
sqlBuilder.AppendLine(" ,P.PLANID ");
sqlBuilder.AppendLine(" ,P.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" ,P.MATERIAL_CODE ");
sqlBuilder.AppendLine(" ,P.CREATEUSER ");
sqlBuilder.AppendLine(" ,P.CREATEDATE ");
sqlBuilder.AppendLine(" ,P.UPDATEUSER ");
sqlBuilder.AppendLine(" ,P.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" FROM T_PP_COUNTINGDETAIL P ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=P.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=P.UPDATEUSER ");
if (!string.IsNullOrEmpty(condition.PLANID))
{
whereBuilder.Append(" AND PLANID =@PLANID");
parameters.Add(new DataParameter { ParameterName = "PLANID", DataType = DbType.String, Value = condition.PLANID });
}
if (!string.IsNullOrEmpty(condition.MATERIAL_CODE))
{
whereBuilder.Append(" AND MATERIAL_CODE =@MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
if (!string.IsNullOrEmpty(condition.MATERIAL_TYPE_CODE))
{
whereBuilder.Append(" AND MATERIAL_TYPE_CODE =@MATERIAL_TYPE_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE 1=1 " + whereBuilder.ToString());
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息(T_PP_COUNTINGPLAN)
/// <summary>
/// 插入信息(T_PP_COUNTINGPLAN)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(Countingplaninfo model)
{
object count = 0;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//sqlBuilder.Append(" insert T_PP_COUNTINGPLAN( PID,FACTORY_CODE,PLAN_NO,PLAN_STATE,REMARK,PLAN_DATE, ");
//sqlBuilder.Append(" REGISTNUMBER,ACTUALNUMBER,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE,ERROWSTATUS ) ");
//sqlBuilder.Append(" values ( ");
//sqlBuilder.Append("'" + model.PID + "',");
//sqlBuilder.Append("'" + model.FACTORY_CODE + "',");
//sqlBuilder.Append("'" + model.PLAN_NO + "',");
//sqlBuilder.Append("'" + model.PLAN_STATE + "',");
//sqlBuilder.Append("'" + model.REMARK + "',");
//sqlBuilder.Append("'" + Convert.ToDateTime(model.PLAN_DATE) + "',");
//sqlBuilder.Append("" + Convert.ToInt32(model.REGISTNUMBER) + ",");
//sqlBuilder.Append("" + Convert.ToInt32(model.ACTUALNUMBER) + ",");
//sqlBuilder.Append("'" + model.CREATEUSER + "',");
//sqlBuilder.Append("'" + Convert.ToDateTime(model.CREATEDATE) + "',");
//sqlBuilder.Append("'" + model.UPDATEUSER + "',");
//sqlBuilder.Append("'" + Convert.ToDateTime(model.UPDATEDATE) + "',");
//sqlBuilder.Append("'正常'");
//sqlBuilder.Append(" ) ");
//插入基本信息
//count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
count = session.Insert<Countingplaninfo>(model);
}
return Convert.ToInt32(count);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息 T_PP_COUNTINGDETAIL表
/// <summary>
/// 插入信息 T_PP_COUNTINGDETAIL表
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public int InsertStocktakingPlan(List<CountingdetailInfo> list)
{
ImportMessage em = new ImportMessage();
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//设置祖先对象数据会话
session.OpenTs();
foreach (CountingdetailInfo info in list)
{
count = session.Insert<CountingdetailInfo>(info);
}
session.CommitTs();
}
}
catch (Exception ex)
{
throw ex;
}
return count;
}
#endregion
#region 获取列表(物料信息)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetMaterialGridList(CountingdetailInfo condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
sql = this.GetSubQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<CountingdetailInfo>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 修改更新信息(单表(T_PP_COUNTINGPLAN))
/// <summary>
/// 修改信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>修改行数</returns>
public int Update(Countingplaninfo model)
{
object count = 0;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sqlBuilder.Append(" update T_PP_COUNTINGPLAN set ");
sqlBuilder.Append("FACTORY_CODE='" + model.FACTORY_CODE + "',");
//if (model.PLAN_STATE.Trim() == "0")
//{
// model.PLAN_STATE = "1";
//}
sqlBuilder.Append("PLAN_STATE='" + model.PLAN_STATE + "',");
sqlBuilder.Append("COUNTTYPE='" + model.COUNTTYPE + "',");
sqlBuilder.Append("REMARK='" + model.REMARK + "',");
sqlBuilder.Append("PLAN_DATE='" + Convert.ToDateTime(model.PLAN_DATE) + "',");
sqlBuilder.Append("UPDATEUSER='" + model.UPDATEUSER + "',");
sqlBuilder.Append("UPDATEDATE='" + Convert.ToDateTime(model.UPDATEDATE) + "'");
sqlBuilder.Append(" where PID='" + model.PID + "'");
//插入基本信息
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return Convert.ToInt32(count);
}
catch (Exception ex)
{
throw ex;
}
}
public void UpdatePlan(Countingplaninfo model)
{
if (this.BaseSession != null)
{
BaseSession.Update<Countingplaninfo>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.Update<Countingplaninfo>(model);
}
}
}
#endregion
#region 编辑时删除信息
/// <summary>
/// 编辑时删除信息
/// </summary>
/// <param name="model">逻辑矩</param>
/// <returns>删除个数</returns>
public int EditDeleteUserWithMachine(CountingdetailInfo model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_PP_COUNTINGDETAIL ");
//设备
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 });
}
//用户id
if (string.IsNullOrEmpty(model.PLANID) == false)
{
whereBuilder.Append(" AND PLANID = @PLANID ");
parameters.Add(new DataParameter { ParameterName = "PLANID", DataType = DbType.String, Value = model.PLANID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
string sqlChange = ChangeSqlByDB(sqlBuilder.ToString(), session);
count = session.ExecuteSql(sqlChange, parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "逻辑矩阵数据层-删除信息");
throw ex;
}
}
#endregion
#region 编辑时保存识别是否已存在
/// <summary>
/// 编辑时保存识别是否已存在
/// 存在则更新,不存在插入
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int GetDetailInfo(CountingdetailInfo model)
{
string sql = null;
int count = 0;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetSubQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.GetTable(sql, parameters.ToArray()).Rows.Count);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "信息数据层-获取信息"
});
throw;
}
}
#endregion
#region 删除父表数据根据ID T_PP_COUNTINGPLAN
/// <summary>
/// 删除父表数据根据ID
/// </summary>
/// <param name="">信息</param>
/// <returns>计划单号</returns>
public object Delete(string PID)
{
object result;
try
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
string[] list = PID.Split(":".ToCharArray());
foreach (string id in list)
{
sqlBuilder.Append(" DELETE FROM T_PP_COUNTINGPLAN WHERE PID='" + id + "'");
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除子表的数据根据PLANID T_PP_COUNTINGDETAIL
/// <summary>
/// 删除子表的数据根据PLANID
/// </summary>
/// <param name="">信息</param>
/// <returns>计划单号</returns>
public object SubDelete(string PLANID)
{
object result;
try
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
string[] list = PLANID.Split(":".ToCharArray());
foreach (string id in list)
{
sqlBuilder.Append(" DELETE FROM T_PP_COUNTINGDETAIL WHERE PLANID='" + id + "'");
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取盘点明细查询
/// <summary>
/// 获取盘点明细查询
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetPanDetail(string PID, DataPage page)
{
DataTable table = null;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sqlBuilder.Append(@"
SELECT
CS.PID ,CS.MATERIAL_CODE,
M.MATERIAL_NAME as MATERIALNAME ,
isnull(CS.MAINCODE,'') as MAINCODE,
isnull(CS.PRODUCTCODE,'') as PRODUCTCODE,
CS.QTY,
CS.CREATEUSER,
C.USERNAME AS CREATEUSERNAME,
CS.CREATEDATE
from T_PP_COUNTSHEET CS
LEFT JOIN T_MD_MATERIAL M on CS.MATERIAL_Code=M.MATERIAL_CODE
LEFT JOIN T_QM_USER C ON C.USERID=CS.CREATEUSER
");
sqlBuilder.Append(" where CS.PlanID='" + PID + "'");
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "CREATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<CountSheetInfo>(sqlBuilder.ToString(), parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 手持获取物料信息
/// <summary>
/// 手持获取物料信息
/// </summary>
/// <param name="PLANID"></param>
/// <returns></returns>
public List<Entity.MD.Material> GetMaterialOfPlan(string PLANID)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT M.* ");
sql.AppendLine(" FROM T_PP_COUNTINGDETAIL AS P ");
sql.AppendLine(" JOIN T_MD_MATERIAL AS M ");
sql.AppendLine(" ON P.MATERIAL_CODE=M.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.PLANID=@planid ");
parameters.Add(new DataParameter("planid", PLANID));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql.ToString(), session);
//获取信息
return session.GetList<QMAPP.FJC.Entity.MD.Material>(sqlChange, parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
RecordExceptionLog(ex, "盘点信息数据层-获取信息");
throw ex;
}
}
#endregion
#region 获取符合条件的产品信息
/// <summary>
/// 获取符合条件的产品信息
/// </summary>
/// <param name="countingplaninfo"></param>
/// <returns></returns>
public List<CountResultInfo> GetListIn(Countingplaninfo countingplaninfo)
{
List<CountResultInfo> listIn = new List<CountResultInfo>();
StringBuilder sql = new StringBuilder();
sql.AppendFormat(@"select '{0}' AS PLANID,P.MATERIAL_TYPE AS MATERIAL_TYPE_CODE, P.MATERIAL_CODE,1 AS QTY,PRODUCTCODE,M.MAINCODE
from T_AW_PRODUCT p LEFT JOIN T_AW_MAIN M ON M.EPIDERMISCODE=P.PRODUCTCODE
where p.USINGSTATE='0' and p.OUTFLAG='0'
and exists(select 1 from T_PP_COUNTINGDETAIL pd where pd.PLANID='{0}'
and pd.MATERIAL_CODE=p.MATERIAL_CODE)", countingplaninfo.PID);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
listIn = session.GetList<CountResultInfo>(sql.ToString(), new List<DataParameter>().ToArray())
.ToList<CountResultInfo>();
}
return listIn;
}
#endregion
#region 盘点比对用到的方法
/// <summary>
/// 盘点比对用到的方法
/// </summary>
/// <param name="countingplaninfo"></param>
/// <returns></returns>
public DataTable GetResult(Countingplaninfo countingplaninfo)
{
DataTable dt = new DataTable();
//将库内数量与盘点数量整合到一起,然后将库内数量与盘点数量做差
//库内数量的统计方法
//注塑件:CFAA开头的产品记录
string sql = string.Format(@"
select sum(QTY) as QTY,MATERIAL_TYPE_CODE,MATERIAL_CODE,sum(CAPACITY) as CAPACITY,(sum(qty)- sum(CAPACITY)) as QC,(sum(CAPACITY)-sum(qty)) as CQ
from
(
select 0 AS QTY, p.MATERIAL_TYPE as MATERIAL_TYPE_CODE, p.MATERIAL_CODE ,SUM(p.CAPACITY) AS CAPACITY
from T_AW_PRODUCT p inner join t_md_material_class c on c.MATERIAL_TYPE_CODE=p.MATERIAL_TYPE
inner join T_MD_MATERIAL m on m.MATERIAL_CODE=p.MATERIAL_CODE
where exists(select 1 from T_PP_COUNTINGDETAIL pd where pd.PLANID='{0}' and pd.MATERIAL_CODE=m.MATERIAL_CODE)
and c.MATERIAL_ATTRIBUTE='2' and p.outflag='0' and p.status in ('0','1')
group by p.MATERIAL_TYPE,p.MATERIAL_CODE
union
select 0 as QTY,mc1.MATERIAL_TYPE_CODE, pc.MATERIAL_CODE,pc.COUNTVALUE as CAPACITY from T_AW_PRODUCTCOUNT pc
inner join T_MD_MATERIAL m1 on pc.MATERIAL_CODE=m1.MATERIAL_CODE
inner join T_MD_MATERIAL_CLASS mc1 on mc1.MATERIAL_TYPE_CODE=m1.MATERIAL_TYPE_CODE
where pc.PROTYPE=0
and exists(select 1 from T_PP_COUNTINGDETAIL pd2 where pd2.PLANID='{0}' and pd2.MATERIAL_CODE=m1.MATERIAL_CODE)
union
select pc.COUNTVALUE as QTY,mc1.MATERIAL_TYPE_CODE, pc.MATERIAL_CODE,0 as CAPACITY from T_AW_PRODUCTCOUNT pc
inner join T_MD_MATERIAL m1 on pc.MATERIAL_CODE=m1.MATERIAL_CODE
inner join T_MD_MATERIAL_CLASS mc1 on mc1.MATERIAL_TYPE_CODE=m1.MATERIAL_TYPE_CODE
and pc.PROTYPE=1
and exists(select 1 from T_PP_COUNTINGDETAIL pd2 where pd2.PLANID='{0}' and pd2.MATERIAL_CODE=m1.MATERIAL_CODE)
union
select sum(isnull(mr.mendnumber,0)) as QTY, mc3.MATERIAL_TYPE_CODE, m2.MATERIAL_CODE ,0 AS CAPACITY
from T_AW_MENDRECORDER mr INNER join t_md_material m2 on mr.MATERIAL_CODE=m2.MATERIAL_CODE
inner join T_MD_MATERIAL_CLASS mc3 on mc3.MATERIAL_TYPE_CODE=m2.MATERIAL_TYPE_CODE
where exists(select 1 from T_PP_COUNTINGDETAIL pd where pd.PLANID='{0}' and pd.MATERIAL_CODE=m2.MATERIAL_CODE)
and mc3.MATERIAL_ATTRIBUTE='1'
group by mc3.MATERIAL_TYPE_CODE, m2.MATERIAL_CODE
union
select sum(qty) as QTY, MATERIAL_TYPE_CODE,MATERIAL_CODE ,0 as CAPACITY
from T_PP_COUNTSHEET WHERE PLANID='{0}'
group by MATERIAL_TYPE_CODE,MATERIAL_CODE,PLANID
)
temp
group by MATERIAL_CODE,MATERIAL_TYPE_CODE "
, countingplaninfo.PID);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, new List<DataParameter>().ToArray());
}
return dt;
}
#endregion
#region 获取每日计划单号
/// <summary>
/// 获取每日计划单号
/// </summary>
/// <param name="">信息</param>
/// <returns>计划单号</returns>
public object GetPlanNoByDate(string NowDate)
{
object result;
try
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
sqlBuilder.Append(" select PLAN_NO from T_PP_COUNTINGPLAN where PLAN_NO like '" + NowDate.Replace("-", "") + "%' order by CreateDate desc ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 是否是服务盘点计划的物料
/// <summary>
/// 是否是服务盘点计划的物料
/// </summary>
/// <param name="planid"></param>
/// <param name="materialcode"></param>
/// <returns></returns>
public QMAPP.MD.Entity.Material IsPlanMaterial(string planid, string materialcode)
{
StringBuilder sql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql.AppendLine("SELECT M.* ");
sql.AppendLine(" FROM T_PP_COUNTINGDETAIL AS P ");
sql.AppendLine(" JOIN T_MD_MATERIAL AS M ");
sql.AppendLine(" ON P.MATERIAL_CODE=M.MATERIAL_CODE ");
sql.AppendLine(" WHERE P.MATERIAL_CODE=@materialcode ");
sql.AppendLine(" AND P.PLANID=@planid ");
parameters.Add(new DataParameter("materialcode", materialcode));
parameters.Add(new DataParameter("planid", planid));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql.ToString(), session);
//获取信息
return session.Get<QMAPP.MD.Entity.Material>(sqlChange, parameters.ToArray());
}
}
catch (Exception ex)
{
RecordExceptionLog(ex, "盘点信息数据层-获取信息");
throw ex;
}
}
#endregion
#region 删除盘点计划下的对比结果
/// <summary>
/// 删除盘点计划下的对比结果
/// </summary>
/// <param name="PID"></param>
public void DeletResultInfo(string PID)
{
string sql = string.Format("delete from T_PP_COUNTRESULT where PLANID='{0}'", PID);
this.BaseSession.ExecuteSql(sql, new List<DataParameter>().ToArray());
}
#endregion
#region 插入信息T_PP_COUNTSHEET
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int InsertCountSheet(CountSheetInfo model)
{
int count = 0;
try
{
if (this.BaseSession != null)
{
count = BaseSession.Insert<CountSheetInfo>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<CountSheetInfo>(model);
}
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取盘点计划ID
/// <summary>
/// 获取盘点计划ID
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public Countingplaninfo GetPlanId(Countingplaninfo model)
{
try
{
if (this.BaseSession != null)
{
model = BaseSession.Get<Countingplaninfo>(model);
}
else
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_PP_COUNTINGPLAN 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));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<Countingplaninfo>(sqlChange, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
return model;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取校验是否存在信息(查验此产品条码是否已经盘点)
/// <summary>
/// 获取校验是否存在信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public CountSheetInfo GetStocktaking(CountSheetInfo model)
{
try
{
if (this.BaseSession != null)
{
model = BaseSession.Get<CountSheetInfo>(model);
}
else
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = "SELECT * FROM T_PP_COUNTSHEET WHERE '1'='1'";
if (string.IsNullOrEmpty(model.PID) == false)
{
sql += " AND PID = @PID";
parameters.Add(new DataParameter("PID", model.PID));
}
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.PRODUCTCODE) == false)
{
sql += " AND PRODUCTCODE = @PRODUCTCODE";
parameters.Add(new DataParameter("PRODUCTCODE", model.PRODUCTCODE));
}
if (!string.IsNullOrEmpty(model.PLAN_NO))
{
sql += " AND PLAN_NO = @PLAN_NO";
parameters.Add(new DataParameter("PLAN_NO", model.PLAN_NO));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
string sqlChange = this.ChangeSqlByDB(sql, session);
//获取信息
model = session.Get<CountSheetInfo>(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>
/// <returns></returns>
public List<CountResultInfo> GetCountSheetInfoList(CountSheetInfo condition)
{
List<CountResultInfo> sheetList = new List<CountResultInfo>();
StringBuilder sql = new StringBuilder();
sql.Append("select PLANID, MATERIAL_TYPE_CODE,MATERIAL_CODE,QTY ,PRODUCTCODE,MAINCODE from T_PP_COUNTSHEET where 1=1 ");
if (string.IsNullOrEmpty(condition.PLANID) == false)
{
sql.AppendFormat(" and PLANID='{0}' ", condition.PLANID);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sheetList = session.GetList<CountResultInfo>(sql.ToString(), new List<DataParameter>().ToArray())
.ToList<CountResultInfo>();
}
return sheetList;
}
#endregion
#region 获取盘点对比结果查询
/// <summary>
/// 获取盘点对比结果查询
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetPanResultDetail(string PID, DataPage page)
{
DataTable table = null;
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
try
{
sqlBuilder.Append(" select P.MATERIAL_CODE ,p.CREATEDATE, M.MATERIAL_NAME as MATERIALNAME ,P.QTY ,cASE P.COMPARERESULT when '1' then '实物盈' else '实物亏' end as COMPARERESULT ,P.PRODUCTCODE,P.MAINCODE from T_PP_COUNTRESULT P ");
sqlBuilder.Append(" LEFT JOIN ");
sqlBuilder.Append(" T_MD_MATERIAL M on P.MATERIAL_cODE=M.MATERIAL_cODE where P.PLANID='" + PID + "' ");
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "CREATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<CountResultInfo>(sqlBuilder.ToString(), parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
public List<CountResultInfo> GetResultInfoList(string PID)
{
List<CountResultInfo> list = new List<CountResultInfo>();
string sql = string.Format("select * from T_PP_COUNTRESULT where PLANID='{0}'", PID);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<CountResultInfo>(sql, new List<DataParameter>().ToArray()).ToList<CountResultInfo>();
}
return list;
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(string PID)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sqlBuilder = new StringBuilder();
try
{
sqlBuilder.Append(@" select
CSheet.PID ,
CSheet.MATERIAL_Code,
TM.MATERIAL_NAME as MATERIALNAME ,
isnull(CSheet.MATERIAL_SN,'') as MATERIAL_SN,
CSheet.QTY,
CSheet.CREATEUSER,
CSheet.CREATEDATE
from
T_PP_COUNTSHEET CSheet
left join
T_MD_MATERIAL TM on
CSheet.MATERIAL_Code=TM.MATERIAL_Code ");
sqlBuilder.Append(" where CSheet.PLanID='" + PID + "'");
////构成查询语句
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sqlBuilder.ToString(), parameters.ToArray());
dt.TableName = "T_PP_COUNTSHEET";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/// <summary>
/// 获取盘点计划下的
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<CountingdetailInfo> GetCountDetailList(CountingdetailInfo condition)
{
List<DataParameter> parameters = new List<DataParameter>();
string sql = null;
sql = this.GetSubQuerySql(condition, ref parameters);
List<CountingdetailInfo> list = new List<CountingdetailInfo>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<CountingdetailInfo>(sql, parameters.ToArray()).ToList<CountingdetailInfo>();
}
return list;
}
/// <summary>
/// 出入库处理
/// </summary>
/// <param name="plan"></param>
public void ProductInOutDeal(Countingplaninfo plan)
{
try
{
#region
//更新产品入库
string updateGainSql = string.Format(@"update T_AW_PRODUCT set outflag='0'
where exists(select 1 from T_PP_COUNTRESULT where PLANID='{0}'
and COMPARERESULT='1' and T_PP_COUNTRESULT.PRODUCTCODE=T_AW_PRODUCT.PRODUCTCODE
and T_AW_PRODUCT.MATERIAL_CODE=T_PP_COUNTRESULT.MATERIAL_CODE)
", plan.PID);
//更新产品出库
string updateLossSql = string.Format(@"update T_AW_PRODUCT set outflag='1'
where exists(select 1 from T_PP_COUNTRESULT where PLANID='{0}'
and COMPARERESULT='0' and T_PP_COUNTRESULT.PRODUCTCODE=T_AW_PRODUCT.PRODUCTCODE
and T_AW_PRODUCT.MATERIAL_CODE=T_PP_COUNTRESULT.MATERIAL_CODE)
", plan.PID);
//插入入库信息
string insertProductIn = string.Format("insert into T_AW_PRODUCTIN select NEWID() as PID, '0' AS INTYPE, PRODUCTCODE, MATERIAL_CODE,'{0}' AS INUSER,GETDATE() AS INDATE from T_PP_COUNTRESULT where PLANID='{1}' and COMPARERESULT='1'", plan.CREATEUSER, plan.PID);
////插出入库信息
string insertProductOut = string.Format(@"insert into T_AW_PRODUCTOUT select NEWID() as PID, PRODUCTCODE, MATERIAL_CODE,'' as WORKCENTER_CODE,'' AS WORKCELL_CODE,'0' AS OUTREASON,
'' AS SHIFT_CODE,'{0}' AS CREATEUSER ,GETDATE() AS CREATEDATE,'{0}' AS UPDATEUSER , GETDATE() AS UPDATEDATE
from T_PP_COUNTRESULT where PLANID='{1}' and COMPARERESULT='0'", plan.CREATEUSER, plan.PID);
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
try
{
//更新入库件
session.ExecuteSql(updateGainSql, new List<DataParameter>().ToArray());
LogManager.LogHelper.Info(new LogInfo() { Info = updateGainSql });
//更新出库件
session.ExecuteSql(updateLossSql, new List<DataParameter>().ToArray());
LogManager.LogHelper.Info(new LogInfo() { Info = updateLossSql });
//插入入库记录
session.ExecuteSql(insertProductIn, new List<DataParameter>().ToArray());
LogManager.LogHelper.Info(new LogInfo() { Info = insertProductIn });
//插入出库记录
session.ExecuteSql(insertProductOut, new List<DataParameter>().ToArray());
LogManager.LogHelper.Info(new LogInfo() { Info = insertProductOut });
session.CommitTs();
}
catch (Exception ex)
{
session.RollbackTs();
LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex });
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex });
}
}
}
}