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

685 lines
21 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.MD.DAL;
using QMAPP.MD.Entity;
using QMAPP.BLL;
using QMAPP.MD.BLL.Dict;
namespace QMAPP.MD.BLL
{
/// <summary>
/// 模块名称:Bom信息
/// 作 者:郭兆福
/// 编写日期:2017年05月10日
/// </summary>
public class PbomBLL : BaseBLL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(Pbom condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取Bom信息列表
DataPage dataPage = new PbomDAL().GetList(condition, page);
#region 转换有效性、类型显示
DictManageBLL dictBomStatusBLL = new DictManageBLL(DictKind.BomStatus);
List<Pbom> pbomInfoList = dataPage.Result as List<Pbom>;
foreach (Pbom b in pbomInfoList)
{
b.STATUS_NAME = dictBomStatusBLL.GetDictValue(b.STATUS);
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
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(Pbom model)
{
try
{
return new PbomDAL().ExistsBomHdr(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(Pbom model)
{
DataResult<int> result = new DataResult<int>();
//PBOM信息
model.PID = Guid.NewGuid().ToString();
model.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
//物料加工工艺
MaterialRoute materialRoute = new MaterialRoute();
materialRoute.PID = Guid.NewGuid().ToString();
// 工艺路线编码
materialRoute.ROUTE_CODE = model.ROUTE_CODE;
// PBOM物料编码
materialRoute.MATERIAL_CODE = model.MATERIAL_CODE;
materialRoute.FLGDEL = "0";
materialRoute.CREATEUSER = this.LoginUser.UserID;
materialRoute.UPDATEUSER = model.CREATEUSER;
try
{
if (ExistsBomHdr(model) == true)
{
result.IsSuccess = false;
result.Msg = "PBOM编号或者物料号信息已经存在!";
return result;
}
// 取得工艺路线
ProcessRoute route = new ProcessRoute();
route.ROUTE_CODE = model.ROUTE_CODE;
route = new ProcessRouteDAL().Get(route);
// 工艺路线版本
materialRoute.ROUTE_VER_NUM = route.ROUTE_VER;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
PbomDAL pbomDAL = new PbomDAL();
MaterialRouteDAL materialRouteDAL = new MaterialRouteDAL();
// 开始事务
session.OpenTs();
pbomDAL.BaseSession = session;
// 增加PBOM
result.Result = pbomDAL.Insert(model);
materialRouteDAL.BaseSession = session;
// 物料加工工艺
materialRouteDAL.Insert(materialRoute);
// 事务提交
session.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
throw e;
}
}
}
catch (Exception ex)
{
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>();
PbomDAL pbomDal = new PbomDAL();
MaterialRouteDAL materialRouteDal = new MaterialRouteDAL();
string[] list = strs.Split(":".ToCharArray());
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
pbomDal.BaseSession = session;
materialRouteDal.BaseSession = session;
foreach (string str in list)
{
//删除物料工艺信息
result.Result += materialRouteDal.DeleteMaterialRouteByPbomId(str);
//删除Bom明细
result.Result += pbomDal.DeleteBomDetailByPbomId(str);
//删除Bom
result.Result += pbomDal.DeleteBomHdr(new Pbom { PID = str });
}
session.CommitTs();
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteBomHdr(Pbom model)
{
int count = 0;
try
{
PbomDAL pbomDAL = new PbomDAL();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
pbomDAL.BaseSession = session;
try
{
session.OpenTs();
count = pbomDAL.DeleteBomHdr(model);
PbomItem modelItem = new PbomItem();
modelItem.PBOM_CODE = model.PBOM_CODE;
pbomDAL.DeleteBomDetail(modelItem);
session.CommitTs();
}
catch (Exception ex)
{
session.RollbackTs();
}
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取BOM下拉列表
/// <summary>
/// 获取BOM下拉列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public DataResult<List<Pbom>> GetBomHdrList(Pbom condition)
{
DataResult<List<Pbom>> result = new DataResult<List<Pbom>>();
try
{
result.Result = new PbomDAL().GetBomHdrList(condition);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
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> GetPbomItemList(PbomItem condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取Bom信息列表
DataPage dataPage = new PbomDAL().BomHdrConfigList(condition, page);
List<PbomItem> pbomItemList = dataPage.Result as List<PbomItem>;
// 客供标识符
DictManageBLL dictCspFlag = new DictManageBLL(DictKind.CspFlag);
foreach (PbomItem m in pbomItemList)
{
//客供标识符
m.FLAG_CSP_NAME = dictCspFlag.GetDictValue(m.FLAG_CSP);
}
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取BOM明细列表
/// <summary>
/// 获取BOM明细列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public DataResult<List<PbomItem>> PbomItemList(PbomItem condition)
{
DataResult<List<PbomItem>> result = new DataResult<List<PbomItem>>();
List<PbomItem> list = new List<PbomItem>();
try
{
//获取Bom明细列表
list = new PbomDAL().BomDetailList(condition);
result.Result = list;
}
catch (Exception ex)
{
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> PbomItemSave(PbomItem model)
{
DataResult<int> result = new DataResult<int>();
if (model.SEQ_NUM<=0)
{
result.IsSuccess = false;
result.Msg = "序号输入1以上的数值!";
return result;
}
if (model.SEQ_NUM <= model.UP_SQ_NUM)
{
result.IsSuccess = false;
result.Msg = "序号应大于前置序号!";
return result;
}
if (model.UNIT_SUM <= 0)
{
result.IsSuccess = false;
result.Msg = "数量输入1以上的数值!";
return result;
}
if (IsPbomHdrMaterial(model) == true)
{
result.IsSuccess = false;
result.Msg = "BOM项目物料不能结合BOM物料相同!";
return result;
}
if (IsPbomDetailMaterial(model.PBOM_CODE,model.MATERIAL_CODE) == true)
{
result.IsSuccess = false;
result.Msg = "相同的BOM项目物料已经存在!";
return result;
}
PbomDAL pbomDal = new PbomDAL();
//Bom明细信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
model.FLGDEL = "0";
try
{
result.Result = new PbomDAL().InsertBomDetail(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 判断bom头物料和bom物料是否相同
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
private Boolean IsPbomHdrMaterial(PbomItem model)
{
PbomDAL pbomDal = new PbomDAL();
Pbom pbom = new Pbom();
pbom.PBOM_CODE = model.PBOM_CODE;
pbom = pbomDal.Get(pbom);
if (pbom.MATERIAL_CODE == model.MATERIAL_CODE)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断bom头物料和bom物料是否相同
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
private Boolean IsPbomDetailMaterial(string pbomCode,string materialCode)
{
PbomDAL pbomDal = new PbomDAL();
PbomItem pbomItem = new PbomItem();
pbomItem.PBOM_CODE = pbomCode;
pbomItem.MATERIAL_CODE = materialCode;
pbomItem = pbomDal.GetBomDetail(pbomItem);
if (null != pbomItem)
{
return true;
}
else
{
return false;
}
}
#endregion
#region 删除Bom明细
/// <summary>
/// 删除Bom明细
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public DataResult<int> DeletePbomItem(string str)
{
PbomDAL bomGroupDal = new PbomDAL();
List<PbomItem> listBomDetail = new List<PbomItem>();
PbomItem entity = new PbomItem();
DataResult<int> result = new DataResult<int>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
bomGroupDal.BaseSession = session;
//删除Bom明细
result.Result += bomGroupDal.DeleteBomDetail(new PbomItem() { PID = str });
session.CommitTs();
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteBomDetail(PbomItem model)
{
int count = 0;
try
{
count = new PbomDAL().DeleteBomDetail(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取物料对应工艺路线
/// <summary>
/// 获取物料对应工艺路线
/// </summary>
/// <param name="materialCode"></param>
/// <returns></returns>
public DataResult<MaterialRoute> GetRouteByMaterialCode(MaterialRoute model)
{
DataResult<MaterialRoute> result = new DataResult<MaterialRoute>();
try
{
// 物料加工工艺
result.Result = new MaterialRouteDAL().Get(model);
return result;
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region 获取BOM明细列表
/// <summary>
/// 获取BOM明细列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>数据页</returns>
public List<PbomItem> GetPbomItemAllList(PbomItem model)
{
try
{
//获取Bom明细列表
return new PbomDAL().GetPbomItemList(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取BOMItem信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public PbomItem GetPbomItemOne(PbomItem model)
{
try
{
return new PbomDAL().GetPbomItemOne(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "PBOM管理--获取信息"
});
throw ex;
}
}
#endregion
#region 获取SEQ_NUM最大号
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public int GetMaxSeqNum(PbomItem model)
{
try
{
var pi = new PbomDAL().GetMaxSeqNum(model);
return pi.SEQ_NUM;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "PBOM管理--获取SEQ_NUM最大号"
});
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int InsertPbomItem(PbomItem model)
{
//PBOM信息
model.PID = Guid.NewGuid().ToString();
model.FLGDEL = "0";
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
model.CREATEDATE = DateTime.Now;
model.UPDATEDATE = model.CREATEDATE;
try
{
return new PbomDAL().InsertPbomItem(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int UpdatePbomItem(PbomItem model)
{
model.UPDATEUSER = this.LoginUser.UserID;
model.UPDATEDATE = DateTime.Now;
try
{
return new PbomDAL().UpdatePbomItem(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> DelPbomItem(string pid)
{
//try
//{
// return new PbomDAL().DelPbomItem(pid);
//}
//catch (Exception ex)
//{
// throw ex;
//}
DataResult<int> result = new DataResult<int>();
try
{
result.Result = new PbomDAL().DelPbomItem(pid);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
public List<Pbom> GetBomBySubMaterial(string material)
{
DAL.PbomDAL dal = new PbomDAL();
return dal.GetPbomByMaterialCode(material);
}
public List<Pbom> GetFinalPbom(string material)
{
DAL.PbomDAL dal = new PbomDAL();
return dal.GetFinalPbom(material);
}
public List<PbomItem> GetWorkingBom(string WorklocCode, string OrderNo)
{
return new DAL.PbomDAL().GetWorkingBom(WorklocCode, OrderNo);
}
public List<PbomItem> GetSubItem(string upmaterial)
{
return new DAL.PbomDAL().GetSubItem(upmaterial);
}
}
}