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

413 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.Entity.Basic;
using QMFrameWork.Log;
using QMAPP.FJC.DAL.Basic;
using QMFrameWork.Data;
using System.Data;
using QMAPP.MD.BLL;
using QMAPP.MD.Entity;
using Resource = QMAPP.FJC.Entity.Resource;
namespace QMAPP.FJC.BLL.Basic
{
public class ProductInfoBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<ProductInfo> Get(ProductInfo model)
{
DataResult<ProductInfo> result = new DataResult<ProductInfo>();
try
{
result.Result = new ProductInfoDAL().Get(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件号逻辑层-获取信息!"
});
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 DataResult<DataPage> GetList(ProductInfo condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
DataPage dataPage = new ProductInfoDAL().GetList(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件号逻辑层-获取列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断区域编号是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsProductInfo(ProductInfo model)
{
try
{
return new ProductInfoDAL().ExistsProductInfo(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(ProductInfo model)
{
DataResult<int> result = new DataResult<int>();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
ProductInfoDAL cmdDAL = new ProductInfoDAL();
try
{
if (ExistsProductInfo(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.MaterielCodeIsHave;
return result;
}
result.Result = new ProductInfoDAL().Insert(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件号逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> Update(ProductInfo model)
{
DataResult<int> result = new DataResult<int>();
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsProductInfo(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.MaterielCodeIsHave;
return result;
}
result.Result = new ProductInfoDAL().Update(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件号逻辑层-更新信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public DataResult<int> Delete(string strs)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
DataResult<int> result = new DataResult<int>();
try
{
foreach (string str in list)
{
count += this.DeleteProductInfo(new ProductInfo { PID = str });
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteProductInfo(ProductInfo model)
{
int count = 0;
try
{
count = new ProductInfoDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(ProductInfo model)
{
try
{
return new ProductInfoDAL().GetExportData(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导入数据
/// <summary>
/// 导入Excel表数据
/// </summary>
/// <param name="list">Excel列表</param>
/// <param name="aramodel">区域信息</param>
/// <param name="plantmodel">工厂信息</param>
/// <param name="productbasicmodel">零件类别信息</param>
/// <returns>结果</returns>
public DataResult<ImportMessage> GetImportData(List<ProductInfo> list, Factory factorymodel, ProductBasic productbasicmodel)
{
DataResult<ImportMessage> result = new DataResult<ImportMessage>();
ProductInfoDAL cmDal = new ProductInfoDAL();
List<ProductInfo> List = new List<ProductInfo>();
int index = 0;
try
{
result.Result = new ImportMessage();
result.Result.Errors = new List<RowError>();
//List<Area> areainfo = null;
List<Factory> plantinfo = null;
List<ProductBasic> productbasicinfo = null;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取区域信息
//areainfo = new QMAPP.FJC.BLL.Basic.AreaBLL().GetAllList(aramodel);
//获取工厂信息
plantinfo = new FactoryBLL().GetAllList(factorymodel);
//获取零件类别信息
productbasicinfo = new QMAPP.FJC.BLL.Basic.ProductBasicBLL().GetAllList(productbasicmodel);
//状态判断
foreach (ProductInfo ma in list)
{
index++;
//转换区域
//Area areaMes = areainfo.Find(a => a.AREANAME == ma.AREANAME);
//if (areaMes != null)
//{
// ma.AREAID = areaMes.PID;
//}
//else
//{
// ma.PID = null;
// result.Result.Errors.Add(new RowError(index, "区域信息不存在"));
// result.Result.failureNum += 1;
// continue;
//}
//转换工厂
Factory plantMes = plantinfo.Find(p => p.FACTORY_NAME == ma.FACTORY_NAME);
if (plantMes != null)
{
ma.FACTORYID = plantMes.PID;
}
else
{
ma.PID = null;
result.Result.Errors.Add(new RowError(index, "工厂信息不存在"));
result.Result.failureNum += 1;
continue;
}
//校验工厂和区域信息是否匹配
//if (areaMes != null && plantMes != null)
//{
// int number = new ProductInfoDAL().ImportCheck(plantMes, areaMes);
// if (number == 0)
// {
// result.Result.Errors.Add(new RowError(index, "工厂和区域信息不匹配"));
// result.Result.failureNum += 1;
// continue;
// }
//}
//转换零件类别
ProductBasic productbasicMes = productbasicinfo.Find(pc => pc.PRODUCTNAME == ma.PRODUCTNAME);
if (productbasicMes != null)
{
ma.PRODUCTBASICID = productbasicMes.PID;
}
else
{
ma.PID = null;
result.Result.Errors.Add(new RowError(index, "零件类别不存在"));
result.Result.failureNum += 1;
continue;
}
if (string.IsNullOrEmpty(ma.InfoError) == false)
{
ma.PID = null;
result.Result.failureNum += 1;
continue;
}
//修改改时根据主键等信息获取详细内容信息
ProductInfo oldInfo = cmDal.Get(ma);
if (oldInfo != null)
{
//更新
ma.PID = oldInfo.PID;
ma.CREATEUSER = oldInfo.CREATEUSER;
ma.CREATEDATE = oldInfo.CREATEDATE;
ma.UPDATEUSER = this.LoginUser.UserID;
ma.UPDATEDATE = oldInfo.UPDATEDATE;
ma.IsNewInfo = false;
result.Result.updateNum += 1;
}
else
{
//新增
oldInfo = new ProductInfo();
ma.PID = Guid.NewGuid().ToString();
ma.CREATEUSER = this.LoginUser.UserID;
ma.CREATEDATE = DateTime.Now;
ma.UPDATEUSER = ma.CREATEUSER;
ma.UPDATEDATE = ma.CREATEDATE;
ma.IsNewInfo = true;
result.Result.insertNum += 1;
}
List.Add(ma);
}
}
//导入
cmDal.GetImportData(List);
result.Msg = "导入成功";
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Ex = ex;
return result;
}
}
#endregion
#region 获取零件列表(绑定下拉列表使用)王丹丹 2017.03.13
/// <summary>
/// 获取零件列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public DataResult<List<ProductInfo>> GetProductInfoList(ProductInfo condition)
{
DataResult<List<ProductInfo>> result = new DataResult<List<ProductInfo>>();
try
{
result.Result = new ProductInfoDAL().GetProductInfoList(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件信息逻辑层-获取零件列表(绑定下拉列表使用)!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
}
}