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

478 lines
17 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.DAL.Basic;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using QMAPP.FJC.BLL.Dict;
namespace QMAPP.FJC.BLL.Basic
{
public class BomHdrBLL : BaseBLL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(BomHdr condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取Bom信息列表
DataPage dataPage = new BomHdrDAL().GetList(condition, page);
#region 转换有效性、类型显示
DictManageBLL dictPSBll = new DictManageBLL(DictKind.USINGSTATE);
List<BomHdr> bomhdrInfoList = dataPage.Result as List<BomHdr>;
foreach (BomHdr b in bomhdrInfoList)
{
b.DEL_FLG = dictPSBll.GetDictValue(b.DEL_FLG);
b.NODE_TYPE = dictPSBll.GetDictValue(b.NODE_TYPE);
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-获取列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断编号是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsBomHdr(BomHdr model)
{
try
{
return new BomHdrDAL().ExistsBomHdr(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(BomHdr model)
{
DataResult<int> result = new DataResult<int>();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.FLAGDEL = "0";
model.CREATEUSR = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSR = model.CREATEUSR;
model.UPDATEDATE = model.CREATEDATE;
MaterielDAL cmdDAL = new MaterielDAL();
try
{
if (ExistsBomHdr(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.BomHdrCodeIsHave;
return result;
}
result.Result = new BomHdrDAL().Insert(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public DataResult<int> Delete(string strs)
{
DataResult<int> result = new DataResult<int>();
BomHdrDAL BomHdrDal = new BomHdrDAL();
string[] list = strs.Split(":".ToCharArray());
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
session.OpenTs();
BomHdrDal.BaseSession = session;
foreach (string str in list)
{
//删除Bom
result.Result += BomHdrDal.DeleteBomHdr(new BomHdr { PID = str });
//删除Bom明细
//result.Result += BomHdrDal.DeleteBomDetail(new BomDetail() { BOM_HDR_PID = str });
}
session.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
throw e;
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-删除!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteBomHdr(BomHdr model)
{
int count = 0;
try
{
count = new BomHdrDAL().DeleteBomHdr(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取BOM下拉列表
/// <summary>
/// 获取BOM下拉列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public DataResult<List<BomHdr>> GetBomHdrList(BomHdr condition)
{
DataResult<List<BomHdr>> result = new DataResult<List<BomHdr>>();
try
{
result.Result = new BomHdrDAL().GetBomHdrList(condition);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "BOM信息逻辑层-获取BOM下拉列表"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
}
#endregion
#region 获取BOM明细(分页)
/// <summary>
/// 获取BOM明细(分页)
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> BomHdrConfigList(BomDetail condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取Bom信息列表
DataPage dataPage = new BomHdrDAL().BomHdrConfigList(condition, page);
#region 转换有效性、类型、计量单位显示
List<BomDetail> bomdetailInfoList = dataPage.Result as List<BomDetail>;
foreach (BomDetail bd in bomdetailInfoList)
{
if (bd.IS_ASSY == "0")
{ bd.IS_ASSY = "是"; }
if (bd.IS_ASSY == "1")
{ bd.IS_ASSY = "否"; }
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-获取BOM明细列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取BOM明细列表
/// <summary>
/// 获取BOM明细列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<List<BomDetail>> BomDetailList(BomDetail condition)
{
DataResult<List<BomDetail>> result = new DataResult<List<BomDetail>>();
List<BomDetail> list = new List<BomDetail>();
try
{
//获取Bom明细列表
list = new BomHdrDAL().BomDetailList(condition);
result.Result = list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-获取BOM明细列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 配置Bom明细
/// <summary>
/// Bom明细保存
/// </summary>
/// <param name="model">Bom明细信息</param>
/// <returns></returns>
public DataResult<int> BomHdrConfigSave(BomDetail model)
{
DataResult<int> result = new DataResult<int>();
BomHdrDAL bomGroupDal = new BomHdrDAL();
List<BomDetail> listBomDetail = new List<BomDetail>();
//Bom明细信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSR = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSR = model.CREATEUSR;
model.UPDATEDATE = model.CREATEDATE;
try
{
#region 校验
////获取Bom明细列表
//listBomDetail = bomGroupDal.BomDetailList(model);
//if (string.IsNullOrEmpty(model.PARENTID))
//{
// List<BomDetail> listParent = listBomDetail.FindAll(o => !string.IsNullOrEmpty(model.PRODUCTINFOID) && string.IsNullOrEmpty(model.PARENTID));
// if (listParent.Count >= 1)
// {
// result.Msg = "只能添加一个一级零件!";
// result.IsSuccess = false;
// return result;
// }
//}
//if (!string.IsNullOrEmpty(model.PARENTID))
//{
// List<BomDetail> listParent = listBomDetail.FindAll(o => o.PRODUCTINFOID == model.PARENTID);
// if (listParent.Count <= 0)
// {
// result.Msg = "该父零件号不存在!";
// result.IsSuccess = false;
// return result;
// }
//}
//List<BomDetail> listMat = listBomDetail.FindAll(o => o.PRODUCTINFOID == model.PRODUCTINFOID || o.PARENTID == model.PRODUCTINFOID);
//if (listMat.Count > 0)
//{
// result.Msg = "该零件号已存在!";
// result.IsSuccess = false;
// return result;
//}
#endregion
result.Result = new BomHdrDAL().InsertBomDetail(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-Bom明细保存!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除Bom明细
/// <summary>
/// 删除Bom明细
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public DataResult<int> DeleteBomConfig(string str)
{
BomHdrDAL bomGroupDal = new BomHdrDAL();
List<BomDetail> listBomDetail = new List<BomDetail>();
BomDetail entity = new BomDetail();
DataResult<int> result = new DataResult<int>();
try
{
//#region 校验先删除最低层级明细
////获取BOM明细
//entity = bomGroupDal.GetBomDetail(new BomDetail() { PID = str });
//int bomlayer = entity.BOMMARK.Length / 2;//bom明细层级
////获取Bom明细列表
//listBomDetail = bomGroupDal.BomDetailList(new BomDetail() { BOM_HDR_PID = entity.BOM_HDR_PID });
////如果父零件存在,查询该父零件号下级的零件号的数量
//List<string> parentMarkList = new List<string>();
//for (int i = 0; i <= entity.BOMMARK.Length - 1; i += 2)
//{
// parentMarkList.Add(entity.BOMMARK.Substring(i, 2));
//}
//int index = parentMarkList.FindIndex(o => o.Equals("00"));
//if (index != -1)
//{
// string startStr = entity.BOMMARK.Substring(0, index * 2);
// var startMarklist = from item in listBomDetail
// where item.BOMMARK.StartsWith(startStr)
// && item.BOMMARK.Length == bomlayer * 2
// select new { bommark = item.BOMMARK };
// if (startMarklist.Count() > 1)
// {
// result.Msg = "请先删除最低层级明细!";
// result.IsSuccess = false;
// return result;
// }
//}
//#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
session.OpenTs();
bomGroupDal.BaseSession = session;
//删除Bom明细
result.Result += bomGroupDal.DeleteBomDetail(new BomDetail() { PID = str });
//删除Bom解析数据
//result.Result += bomGroupDal.DeleteBomAnalyze(new BomAnalyze() { BOMDETAILPID = str });
session.CommitTs();
}
catch (Exception ex)
{
session.RollbackTs();
throw ex;
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "Bom信息维护逻辑层-删除Bom明细!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteBomDetail(BomDetail model)
{
int count = 0;
try
{
count = new BomHdrDAL().DeleteBomDetail(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}