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 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(BomHdr condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取Bom信息列表
DataPage dataPage = new BomHdrDAL().GetList(condition, page);
#region 转换有效性、类型显示
DictManageBLL dictPSBll = new DictManageBLL(DictKind.USINGSTATE);
List bomhdrInfoList = dataPage.Result as List;
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 信息是否重复
///
/// 判断编号是否存在
///
///
/// true:已存在;fasel:不存在。
public bool ExistsBomHdr(BomHdr model)
{
try
{
return new BomHdrDAL().ExistsBomHdr(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(BomHdr model)
{
DataResult result = new DataResult();
//基本信息
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 删除
///
/// 删除信息
///
///
/// 删除个数
public DataResult Delete(string strs)
{
DataResult result = new DataResult();
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;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteBomHdr(BomHdr model)
{
int count = 0;
try
{
count = new BomHdrDAL().DeleteBomHdr(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取BOM下拉列表
///
/// 获取BOM下拉列表
///
/// 条件
/// 数据页
public DataResult> GetBomHdrList(BomHdr condition)
{
DataResult> result = new DataResult>();
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明细(分页)
///
/// 获取BOM明细(分页)
///
/// 条件
/// 数据页
/// 数据页
public DataResult BomHdrConfigList(BomDetail condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取Bom信息列表
DataPage dataPage = new BomHdrDAL().BomHdrConfigList(condition, page);
#region 转换有效性、类型、计量单位显示
List bomdetailInfoList = dataPage.Result as List;
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明细列表
///
/// 获取BOM明细列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult> BomDetailList(BomDetail condition)
{
DataResult> result = new DataResult>();
List list = new List();
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明细
///
/// Bom明细保存
///
/// Bom明细信息
///
public DataResult BomHdrConfigSave(BomDetail model)
{
DataResult result = new DataResult();
BomHdrDAL bomGroupDal = new BomHdrDAL();
List listBomDetail = new List();
//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 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 listParent = listBomDetail.FindAll(o => o.PRODUCTINFOID == model.PARENTID);
// if (listParent.Count <= 0)
// {
// result.Msg = "该父零件号不存在!";
// result.IsSuccess = false;
// return result;
// }
//}
//List 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明细
///
/// 删除Bom明细
///
/// 信息
/// 删除个数
public DataResult DeleteBomConfig(string str)
{
BomHdrDAL bomGroupDal = new BomHdrDAL();
List listBomDetail = new List();
BomDetail entity = new BomDetail();
DataResult result = new DataResult();
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 parentMarkList = new List();
//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;
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int DeleteBomDetail(BomDetail model)
{
int count = 0;
try
{
count = new BomHdrDAL().DeleteBomDetail(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}