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

648 lines
22 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMFrameWork.Common.Encrypt;
using QMFrameWork.Data;
using QMAPP.FJC.DAL.Operation;
using QMAPP.FJC.Entity.Operation;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.ProduceManage;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.BLL.Basic;
using QMAPP.Entity;
using QMAPP.FJC.Entity;
using QMFrameWork.Log;
using QMAPP.FJC.Entity.Injection;
using QMAPP.FJC.DAL.FeedInManage;
namespace QMAPP.FJC.BLL.Operation
{
/// <summary>
/// 模块编号:M13-1
/// 作 用:加工本体
/// 作 者:王庆男
/// 编写日期:2015年06月04日
///</summary>
public class MainBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public Main Get(Main model)
{
try
{
return new MainDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public Main GetByCondition(Main model)
{
try
{
List<Main> list = new MainDAL().GetList(model);
if (list.Count > 0)
{
return list[0];
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
public MaterialCodeInit GetMaterialSetByCondition(MaterialCodeInit condition)
{
return new QMAPP.FJC.DAL.Basic.MaterialCodeInitDAL().GetByCondition(condition);
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(Main condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
result.IsSuccess = true;
page = new MainDAL().GetList(condition, page);
List<Main> list = page.Result as List<Main>;
//处理字典信息
DictManageBLL dictPROCESSTYPE = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictColor = new DictManageBLL(DictKind.COLOR);
DictManageBLL dictSTATUS = new DictManageBLL(DictKind.LJSTATUS);
DictManageBLL dictOUTFLAG = new DictManageBLL(DictKind.OUTFLAG);
DictManageBLL dictHL = new DictManageBLL(DictKind.HAndL);
DictManageBLL dictYN = new DictManageBLL(DictKind.ValidFlg);
foreach (var info in list)
{
//替换工序类别显示值
info.CURRENTPROCESS = dictPROCESSTYPE.GetDictValue(info.CURRENTPROCESS);
//替换零件类别显示值
info.COLOR = dictColor.GetDictValue(info.COLOR);
//替换零件类别显示值
info.STATUS = dictSTATUS.GetDictValue(info.STATUS);
//替换出库标记显示值
info.OUTFLAG = dictOUTFLAG.GetDictValue(info.OUTFLAG);
//替换使用状态显示值
info.HB = dictHL.GetDictValue(info.HB);
info.COMPLETEFLAG = dictYN.GetDictValue(info.COMPLETEFLAG);
//info.COMPLETETIMESTR = dictColor.GetDictValue(info.COLOR);
info.COMPLETEDATE = (info.COMPLETETIME == System.DateTime.MinValue) ? ""
: info.COMPLETETIME.ToString("yyyy-MM-dd HH:mm:ss");
}
page.Result = list;
result.Result = page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "本体信息获取列表错误!"
});
result.IsSuccess = false;
result.Msg = "本体信息获取列表错误!";
}
return result;
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部数据</returns>
public List<Main> GetAllList(Main condition)
{
try
{
return new MainDAL().GetList(condition);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsMain(Main model)
{
try
{
return new MainDAL().ExistsMain(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(Main model)
{
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
MainDAL cmdDAL = new MainDAL();
if (ExistsMain(model) == true)
return -1;
return new MainDAL().Insert(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(Main model)
{
try
{
//if (ExistsT_AW_MAIN(Model) == true)
//return -1;
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
return new MainDAL().Update(model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> UpdateStatus(Main model, MendRecorder recorder)
{
DataResult<int> result = new DataResult<int>();
try
{
model.UPDATEUSER = this.LoginUser.UserID;
recorder.PID = Guid.NewGuid().ToString();
recorder.CREATEUSER = this.LoginUser.UserID;
recorder.CREATEDATE = DateTime.Now;
recorder.UPDATEUSER = model.CREATEUSER;
recorder.UPDATEDATE = model.CREATEDATE;
result.Result = new MainDAL().Update(model, recorder);
result.IsSuccess = true;
result.Msg = Resource.MsgSuccess;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "零件条码--更新零件状态返修或报废"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(string strs)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.DeleteMain(new Main { PID = str });
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteMain(Main model)
{
int count = 0;
try
{
count = new MainDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataResult<DataTable> GetExportData(Main model)
{
DataResult<DataTable> result = new DataResult<DataTable>();
result.IsSuccess = true;
try
{
result.Result = new MainDAL().GetExportData(model);
//处理字典信息
DictManageBLL dictPROCESSTYPE = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictColor = new DictManageBLL(DictKind.COLOR);
DictManageBLL dictSTATUS = new DictManageBLL(DictKind.LJSTATUS);
DictManageBLL dictOUTFLAG = new DictManageBLL(DictKind.OUTFLAG);
DictManageBLL dictHL = new DictManageBLL(DictKind.HAndL);
DictManageBLL dictYN = new DictManageBLL(DictKind.ValidFlg);
foreach (DataRow dr in result.Result.Rows)
{
//替换工序类别显示值
dr["CURRENTPROCESS"] = dictPROCESSTYPE.GetDictValue(dr["CURRENTPROCESS"].ToString());
//替换零件类别显示值
dr["COLOR"] = dictColor.GetDictValue(dr["COLOR"].ToString());
//替换零件类别显示值
dr["STATUS"] = dictSTATUS.GetDictValue(dr["STATUS"].ToString());
//替换出库标记显示值
dr["OUTFLAG"] = dictOUTFLAG.GetDictValue(dr["OUTFLAG"].ToString());
//替换使用状态显示值
dr["HB"] = dictHL.GetDictValue(dr["HB"].ToString());
dr["COMPLETEFLAG"] = dictYN.GetDictValue(dr["COMPLETEFLAG"].ToString());
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
#region 导入数据
public DataResult<ImportMessage> GetImportData(List<Main> list)
{
DataResult<ImportMessage> result = new DataResult<ImportMessage>();
MainDAL cmDal = new MainDAL();
List<Main> List = new List<Main>();
int index = 0;
try
{
result.Result = new ImportMessage();
result.Result.Errors = new List<RowError>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//状态判断
foreach (Main ma in list)
{
index++;
if (string.IsNullOrEmpty(ma.InfoError) == false)
{
ma.PID = null;
result.Result.failureNum += 1;
continue;
}
//修改改时根据主键等信息获取详细内容信息
Main 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 Main();
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 获取投料信息列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<List<InjectionRecorder>> GetProductInfectionList(string id)
{
DataResult<List<InjectionRecorder>> result = new DataResult<List<InjectionRecorder>>();
try
{
List<InjectionRecorder> list = new List<InjectionRecorder>();
result.IsSuccess = true;
list = new MainDAL().GetProductInfectionList(id);
//处理字典信息
DictManageBLL dictMATERIALTYPE = new DictManageBLL(DictKind.MATERIALTYPE);
foreach (var info in list)
{
//替换物料类别显示值
info.MATERIALTYPE = dictMATERIALTYPE.GetDictValue(info.MATERIALTYPE);
}
result.Result = list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "获取投料信息错误!"
});
result.IsSuccess = false;
result.Msg = "获取投料信息错误!";
}
return result;
}
#endregion
#region 更新表皮相关物料信息
/// <summary>
/// 更新表皮相关物料信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult UpdateMaterial(InjectionRecorder model)
{
DataResult result = new DataResult();
try
{
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
int count = new EpidermisDAL().UpdateMaterial(model);
if (count > 0)
{
result.IsSuccess = true;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "表皮信息更新批次号错误!"
});
result.IsSuccess = false;
result.Msg = "表皮信息更新批次号错误!";
throw ex;
}
return result;
}
#endregion
/// <summary>
/// 创建仪表板本体信息
/// </summary>
/// <param name="productcode"></param>
/// <param name="materialcode"></param>
/// <returns></returns>
public Main CreateMain(string productcode, string materialcode)
{
var materialdal = new QMAPP.FJC.DAL.MD.MaterialDAL();
var material = materialdal.Get(new QMAPP.FJC.Entity.MD.Material { MATERIAL_CODE = materialcode });
var matinitdal = new FJC.DAL.Basic.MaterialCodeInitDAL();
var mcinit = matinitdal.GetByCondition(new MaterialCodeInit { MATERIAL_TYPE = material.MATERIAL_TYPE_CODE, MATERIAL_CODE=material.MATERIAL_CODE });
using (IDataSession session = AppDataFactory.CreateMainSession())
{
try
{
session.OpenTs();
ProductDAL prodal = new ProductDAL();
prodal.BaseSession = session;
prodal.Insert(new Product
{
CAPACITY = 1,
CREATEDATE = DateTime.Now,
CREATEUSER = base.LoginUser.UserID,
CURRENTPROCESS = "",
ENDOFLINE = "1",
MACHINECODDE = "",
MACHINENAME = "",
MATERIAL_CODE = materialcode,
MATERIAL_TYPE = material.MATERIAL_TYPE_CODE,
OUTFLAG = "0",
PID = Guid.NewGuid().ToString(),
PRODUCELINE = "",
PRODUCESHIFTNAME = "A",
PRODUCESHIFTTCODE = "A",
PRODUCTCODE = productcode,
PRODUCTSOURCE = "0",
PRODUCTTYPE = "",
STATUS = "0",
TEAM_CODE = "",
UPDATEDATE = DateTime.Now,
UPDATEUSER = base.LoginUser.UserID,
USINGCOUNT = 0,
USINGSTATE = "0",
WORKCELL_CODE = mcinit == null ? "" : mcinit.WORKCELL_CODE_INIT,
WORKCENTER_CODE = mcinit == null ? "" : mcinit.WORKCENTER_CODE_INIT,
WORKLOC_CODE = ""
});
Main main = new Main()
{
COMPLETEFLAG = "1",
COMPLETETIME = DateTime.Now,
CREATEDATE = DateTime.Now,
CREATEUSER = base.LoginUser.UserID,
CURRENTPROCESS = "15",
MACHINECODDE = "",
OUTFLAG = "0",
PID = Guid.NewGuid().ToString(),
PROCESSSTATE = "1",
PRODUCELINE = mcinit == null ? "" : mcinit.WORKCENTER_CODE_INIT,
STATUS = "0",
UPDATEDATE = DateTime.Now,
UPDATEUSER = base.LoginUser.UserID,
IsNewInfo = true,
MATERIAL_CODE = materialcode,
MAINCODE = GenerateAssyCode(materialcode, DateTime.Now), //data.WorkLocState.CurrentState.PROCESS_CODE,
SKID = "",
SKELETONCODE = "",
EID = "",
EPIDERMISCODE = productcode,
WORKCELL_CODE = mcinit == null ? "" : mcinit.WORKCELL_CODE_INIT,
WORKCENTER_CODE = mcinit == null ? "" : mcinit.WORKCENTER_CODE_INIT,
WORKLOC_CODE = ""
};
DAL.Operation.MainDAL maindal = new MainDAL();
maindal.BaseSession = session;
maindal.Insert(main);
session.CommitTs();
return main;
}
catch(Exception e)
{
session.RollbackTs();
throw e;
}
}
}
public string GenerateAssyCode(string materialcode, DateTime time)
{
DAL.Operation.MainDAL maindal = new DAL.Operation.MainDAL();
//0到100000的总成号作为手工打印的总成号段
PrintCode printcode = maindal.GetMaxANDMinMainCode(materialcode);
//string maxcode = maindal.GetMaxMainCode(0, 1000000);
string maxcode = maindal.GetMaxMainCode(printcode.MINVALUE, printcode.MAXVALUE);
string newcode = "1";
if (!string.IsNullOrEmpty(maxcode))
{
newcode = (Convert.ToInt32(maxcode) + 1) + "";
}
if (Convert.ToInt32(newcode) > printcode.MAXVALUE)
{
throw new Exception("该配置零件条码流水号溢出,请重新设置!");
}
newcode = "052 4XR" + newcode.PadLeft(7, '0');
string finalcode = newcode + CalculateChecksum(newcode);
printcode.MAINCODE = finalcode;
printcode.ISCOMPLETE = 0;
printcode.SERIAL_NUM = 0;
PrintCodeDAL dal = new PrintCodeDAL();
dal.Update(printcode);
return finalcode;
}
/// <summary>
/// 计算验证码
/// </summary>
/// <returns></returns>
public static string CalculateChecksum(string barcode)
{
string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
int sum = 0;
foreach (var c in barcode)
{
sum += chars.IndexOf(c);
}
int rem = sum % chars.Length;
return chars[rem].ToString();
}
}
}