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 获取抽检记录表信息
///
/// 获取抽检记录表信息(主要是PID)
///
///
///
public ProductCheck Get(ProductCheck model)
{
ProductCheck result = new ProductCheck();
try
{
result = new ProductCheckDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetWinformList(ProductCheck condition, DataPage page)
{
try
{
page = new ProductCheckDAL().GetList(condition, page);
List list = page.Result as List;
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;
}
}
///
/// 获取分页列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(ProductCheck condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取物料信息列表
DataPage dataPage = new ProductCheckDAL().GetList(condition, page);
#region 外购件标识
List list = dataPage.Result as List;
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 获取配置表列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
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
///
/// 获取设备信息,填充Grid
///
///
///
public List GetCheckWithMaterialInfo(CheckWithMaterial condition)
{
List materialList = new List();
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 确认保存
///
/// 确认保存
///
///
///
public DataResult EditInsertCheckValueItem(DataTable Dt, CheckValueItem checkValueInfo)
{
int count = 0;
ProductCheckDAL cmdDAL = new ProductCheckDAL();
cmdDAL.BaseSession = AppDataFactory.CreateMainSession();
DataResult result = new DataResult();
try
{
//存在的抽检值信息(更新)
List updateCheckValue = new List();
//新加的抽检值信息(增加)
List addCheckValue = new List();
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)
///
/// 插入信息(T_PP_COUNTINGPLAN)
///
/// 信息
/// 插入行数
public DataResult InsertProductCheck(ProductCheck model)
{
DataResult result = new DataResult();
try
{
result.Result = new ProductCheckDAL().InsertProductCheck(model);
}
catch (Exception ex)
{
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息(T_AW_PRODUCTCHECK)
///
/// 插入信息(T_PP_COUNTINGPLAN)
///
/// 信息
/// 插入行数
public DataResult UpdateProductCheck(ProductCheck model)
{
DataResult result = new DataResult();
try
{
result.Result = new ProductCheckDAL().UpdateProductCheck(model);
}
catch (Exception ex)
{
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
///
/// 删除
///
///
///
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使用)
///
/// 获取输入值列表(winform使用)
///
///
///
public List GetInputValueList(InputValue condition)
{
List result = new List();
try
{
List list = new ProductCheckDAL().GetInputValueList(condition);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 加载详细信息
///
/// 加载详细信息
///
/// 条件
/// 数据页
public DataResult> GetProductCheckItemList(CheckWithMaterial condition)
{
DataResult> result = new DataResult>();
result.IsSuccess = true;
try
{
result.Result = new ProductCheckDAL().GetProductCheckItemList(condition);
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
public DataResult GetExportData(string[] idArray)
{
DataResult result=new DataResult();
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;
}
}
}
}