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

414 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.DAL.Operation;
using QMFrameWork.Log;
using QMAPP.Entity;
using System.Data;
using QMAPP.FJC.BLL.Dict;
using QMAPP.MD.BLL;
namespace QMAPP.FJC.BLL.Operation
{
public class ProductCheckBLL : BaseBLL
{
#region 获取抽检记录表信息
/// <summary>
/// 获取抽检记录表信息(主要是PID)
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public ProductCheck Get(ProductCheck model)
{
ProductCheck result = new ProductCheck();
try
{
result = new ProductCheckDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWinformList(ProductCheck condition, DataPage page)
{
try
{
page = new ProductCheckDAL().GetList(condition, page);
List<ProductCheck> list = page.Result as List<ProductCheck>;
DictManageBLL dictCheckResult = new DictManageBLL(DictKind.CHECKRESULT);
DictManageBLL dictCheckType = new DictManageBLL(DictKind.PRODUCTCHECKTYPE);
foreach (ProductCheck o in list)
{
o.CHECKRESULT = dictCheckResult.GetDictValue(o.CHECKRESULT);
o.PRODUCTCHECKTYPE = dictCheckType.GetDictValue(o.PRODUCTCHECKTYPE);
}
page.Result = list;
return page;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(ProductCheck condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取物料信息列表
DataPage dataPage = new ProductCheckDAL().GetList(condition, page);
#region 外购件标识
List<ProductCheck> list = dataPage.Result as List<ProductCheck>;
DictManageBLL dictCheckResult = new DictManageBLL(DictKind.CHECKRESULT);
DictManageBLL dictCheckType = new DictManageBLL(DictKind.PRODUCTCHECKTYPE);
foreach (ProductCheck o in list)
{
o.CHECKRESULT = dictCheckResult.GetDictValue(o.CHECKRESULT);
o.PRODUCTCHECKTYPE = dictCheckType.GetDictValue(o.PRODUCTCHECKTYPE);
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取配置表列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public CheckWithMaterial GetCheckWithMaterial(CheckWithMaterial condition)
{
try
{
return new ProductCheckDAL().GetCheckWithMaterial(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "-获取信息"
});
throw ex;
}
}
#endregion
#region 获取设备信息,填充Grid
/// <summary>
/// 获取设备信息,填充Grid
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<CheckWithMaterial> GetCheckWithMaterialInfo(CheckWithMaterial condition)
{
List<CheckWithMaterial> materialList = new List<CheckWithMaterial>();
try
{
materialList = new ProductCheckDAL().GetCheckWithMaterialInfo(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "逻辑层-获取本体信息!"
});
throw ex;
}
return materialList;
}
#endregion
#region 确认保存
/// <summary>
/// 确认保存
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public DataResult<int> EditInsertCheckValueItem(DataTable Dt, CheckValueItem checkValueInfo)
{
int count = 0;
ProductCheckDAL cmdDAL = new ProductCheckDAL();
cmdDAL.BaseSession = AppDataFactory.CreateMainSession();
DataResult<int> result = new DataResult<int>();
try
{
//存在的抽检值信息(更新)
List<CheckValueItem> updateCheckValue = new List<CheckValueItem>();
//新加的抽检值信息(增加)
List<CheckValueItem> addCheckValue = new List<CheckValueItem>();
for (int i = 0; i < Dt.Rows.Count; i++)
{
//检测值
string InputValue = Dt.Rows[i]["INPUTVALUE"].ToString();
string InputType = Dt.Rows[i]["INPUTTYPE"].ToString();
//if (string.IsNullOrEmpty(InputValue))
//{
// if (InputType == "1")
// {
// InputValue = "OK";
// }
// else
// {
// InputValue = "0";
// }
//}
//抽检项编码
string CheckItemCode = Dt.Rows[i]["CHECKITEMCODE"].ToString();
CheckValueItem item = cmdDAL.GetDetailInfo(new CheckValueItem() { CHECKITEMCODE = CheckItemCode, PRODUCTCHECK_PID = checkValueInfo.PRODUCTCHECK_PID });
CheckValueItem detailInfo = new CheckValueItem();
//如果T_AW_CHECKVALUEITEM表存在数据,则更新
if (item != null)
{
detailInfo.PID = item.PID;
detailInfo.PRODUCTCHECK_PID = checkValueInfo.PRODUCTCHECK_PID;
detailInfo.CHECKITEMCODE = CheckItemCode;
detailInfo.INPUTVALUE = InputValue;
detailInfo.CREATEUSER = checkValueInfo.CREATEUSER;
detailInfo.CREATEDATE = DateTime.Now;
updateCheckValue.Add(detailInfo);
}
else
{
detailInfo.PID = Guid.NewGuid().ToString();
detailInfo.PRODUCTCHECK_PID = checkValueInfo.PRODUCTCHECK_PID;
detailInfo.CHECKITEMCODE = CheckItemCode;
detailInfo.INPUTVALUE = InputValue;
detailInfo.CREATEUSER = checkValueInfo.CREATEUSER;
detailInfo.CREATEDATE = DateTime.Now;
addCheckValue.Add(detailInfo);
}
}
//插入
if (addCheckValue.Count > 0)
{
result.Result = cmdDAL.InsertCheckValue(addCheckValue);
}
//更新
else if (updateCheckValue.Count > 0)
{
result.Result = cmdDAL.UpdateCheckValue(updateCheckValue);
}
}
catch (Exception ex)
{
throw ex;
}
result.Result = count;
result.Msg = "成功!";
result.IsSuccess = true;
return result;
}
#endregion
#region 插入信息(T_AW_PRODUCTCHECK)
/// <summary>
/// 插入信息(T_PP_COUNTINGPLAN)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> InsertProductCheck(ProductCheck model)
{
DataResult<int> result = new DataResult<int>();
try
{
result.Result = new ProductCheckDAL().InsertProductCheck(model);
}
catch (Exception ex)
{
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息(T_AW_PRODUCTCHECK)
/// <summary>
/// 插入信息(T_PP_COUNTINGPLAN)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> UpdateProductCheck(ProductCheck model)
{
DataResult<int> result = new DataResult<int>();
try
{
result.Result = new ProductCheckDAL().UpdateProductCheck(model);
}
catch (Exception ex)
{
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="pid"></param>
/// <returns></returns>
public DataResult Delete(string pid)
{
DataResult result = new DataResult();
result.IsSuccess = true;
try
{
int i = new ProductCheckDAL().Delete(pid);
if (i == 0)
{
result.IsSuccess = false;
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取输入值列表(winform使用)
/// <summary>
/// 获取输入值列表(winform使用)
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<InputValue> GetInputValueList(InputValue condition)
{
List<InputValue> result = new List<InputValue>();
try
{
List<InputValue> list = new ProductCheckDAL().GetInputValueList(condition);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 加载详细信息
/// <summary>
/// 加载详细信息
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public DataResult<List<CheckWithMaterial>> GetProductCheckItemList(CheckWithMaterial condition)
{
DataResult<List<CheckWithMaterial>> result = new DataResult<List<CheckWithMaterial>>();
result.IsSuccess = true;
try
{
result.Result = new ProductCheckDAL().GetProductCheckItemList(condition);
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
public DataResult<ProductCheckExport> GetExportData(string[] idArray)
{
DataResult<ProductCheckExport> result=new DataResult<ProductCheckExport>();
try
{
if (idArray.Length < 1 || idArray.Length > 8)
{
result.IsSuccess = false;
result.Msg = "请选择1至8条抽检记录进行导出操作!";
return result;
}
DAL.Operation.ProductCheckDAL dal = new ProductCheckDAL();
result.Result = new ProductCheckExport();
result.Result.CheckRecords = dal.GetList(idArray);
if (result.Result.CheckRecords.Count == 0)
{
result.IsSuccess = false;
result.Msg = "未查到抽检数据!";
return result;
}
if (result.Result.CheckRecords.GroupBy(p => p.MATERIAL_CODE).Count() > 1)
{
result.IsSuccess = false;
result.Msg = "只能选择同一种物料的抽检记录进行导出操作!";
return result;
}
result.Result.MaterialInfo = new DAL.MD.MaterialDAL().Get(result.Result.CheckRecords.FirstOrDefault().MATERIAL_CODE);
result.Result.CheckItems = dal.GetCheckItems(result.Result.MaterialInfo.MATERIAL_TYPE_CODE);
result.Result.CheckValueItems = dal.GetCheckValueItems(idArray);
result.IsSuccess = true;
return result;
}
catch(Exception e)
{
result.IsSuccess = false;
result.Msg = e.Message;
return result;
}
}
}
}