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.BLL.Dict;
using QMAPP.FJC.BLL.Basic;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity.Basic;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using QMAPP.FJC.DAL.FileCopy;
using QMFrameWork.Common.Serialization;
using System.Threading;
using QMAPP.FJC.Entity.ProcessParameter;
//using QMAPP.FJC.DAL.ProcessParameter;
using QMAPP.FJC.DAL;
using QMFrameWork.Common.Task;
using QMAPP.MD.Entity;
namespace QMAPP.FJC.BLL.Operation
{
///
/// 模块编号:M13-2
/// 作 用:加工记录
/// 作 者:单雨春
/// 编写日期:2015年06月04日
///
public class MainOperationBLL : BaseBLL
{
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetListWithParameter(MainOperation condition, DataPage page)
{
DataResult dataResult = new DataResult();
try
{
#region 获得加工参数标准值
var conditionPParameter = new ProcessParameter
{
//MACHINECODDE = condition.MACHINECODDE,
WORKCELL_CODE=condition.WORKCELL_CODE,
};
var listPParameter = new ProcessParameterDAL().GetList(conditionPParameter);
if (listPParameter == null || listPParameter.Count == 0)
{
dataResult.IsSuccess = false;
dataResult.Msg = QMAPP.FJC.Entity.Resource.NotSetProcessParameter;
dataResult.Result = new DataPage();
dataResult.Result.Result = new DataTable();
return dataResult;
}
#endregion
#region 获得加工记录及加工参数
condition.SelectCollumns = String.Join(",", listPParameter.Select(o => o.PARANAME));
condition.PARATABLENAME = listPParameter.FirstOrDefault().PARATABLENAME;
dataResult.Result = new MainOperationDAL().GetListWithParameter(condition, page);
if (dataResult.Result.Result == null)
{
dataResult.IsSuccess = false;
dataResult.Msg = QMAPP.FJC.Entity.Resource.NothingData;
dataResult.Result.Result = new DataTable();
return dataResult;
}
DataTable dtResult = dataResult.Result.Result as DataTable;
DictManageBLL dictColumnName = new DictManageBLL(DictKind.MAINOPERATIONSEARCHFORM);
DictManageBLL dictProcessType = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictProductType = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictLJStatus = new DictManageBLL(DictKind.LJSTATUS);
DictManageBLL dictOperateState = new DictManageBLL(DictKind.OPERATESTATE);
IList listDelColumn = new List();
//转换枚举描述
foreach (DataRow item in dtResult.Rows)
{
item["PROCESSTYPE"] = dictProcessType.GetDictValue(item["PROCESSTYPE"].ToString());
item["PRODUCTTYPE"] = dictProductType.GetDictValue(item["PRODUCTTYPE"].ToString());
item["STATUS"] = dictLJStatus.GetDictValue(item["STATUS"].ToString());
item["OPERATESTATE"] = dictOperateState.GetDictValue(item["OPERATESTATE"].ToString());
}
//设置标题
foreach (var item in dtResult.Columns.Cast())
{
if (item.ColumnName == "OPERATEDDATESTR" || item.ColumnName == "CREATEDATESTR")
{
//移除原来datetime类型的OPERATEDDATE、CREATEDATE
listDelColumn.Add(item);
}
else
{
var strColumnName = dictColumnName.GetDictValue(item.ColumnName);
if (string.IsNullOrEmpty(strColumnName))
{
var entityParam = listPParameter.FirstOrDefault(o => o.PARANAME == item.ColumnName);
if (entityParam != null)
{
strColumnName = entityParam.PARADESCRIBE;
}
}
if (!string.IsNullOrEmpty(strColumnName))
{
item.ColumnName = strColumnName;
}
else
{
listDelColumn.Add(item);
}
}
}
//移除
foreach (var item in listDelColumn)
{
dtResult.Columns.Remove(item);
}
dataResult.IsSuccess = true;
#endregion
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "加工记录-获取列表"
});
dataResult.IsSuccess = false;
dataResult.Msg = Resource.SystemException;
}
return dataResult;
}
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(MainOperation condition, DataPage page)
{
try
{
//获取信息列表
DataPage dataPage = new MainOperationDAL().GetList(condition, page);
#region 转换状态
List list = dataPage.Result as List;
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.OPERATESTATE);
foreach (MainOperation item in list)
{
//工序类别
item.OPERATESTATETEXT = operationStatusBll.GetDictValue(item.OPERATESTATE);
}
#endregion
return dataPage;
}
catch (Exception ex)
{
throw ex;
}
}
public DataPage GetOperationList(MainOperation condition, DataPage page)
{
try
{
//获取信息列表
DataPage dataPage = new MainOperationDAL().GetOperationList(condition, page);
#region 转换状态
List list = dataPage.Result as List;
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.OPERATESTATE);
foreach (MainOperation item in list)
{
//工序类别
item.OPERATESTATETEXT = operationStatusBll.GetDictValue(item.OPERATESTATE);
}
#endregion
return dataPage;
}
catch (Exception ex)
{
throw ex;
}
}
public DataPage GetOperationListNew(MainOperation condition, DataPage page)
{
try
{
//获取信息列表
DataPage dataPage = new MainOperationDAL().GetOperationListNew(condition, page);
#region 转换状态
List list = dataPage.Result as List;
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.OPERATESTATE);
foreach (MainOperation item in list)
{
//工序类别
item.OPERATESTATETEXT = operationStatusBll.GetDictValue(item.OPERATESTATE);
}
#endregion
return dataPage;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取列表
///
/// 条件
/// 全部数据
public List GetAllList(MainOperation condition)
{
try
{
List list = new MainOperationDAL().GetList(condition);
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.OPERATESTATE);
DictManageBLL processTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
foreach (MainOperation item in list)
{
//工序类别
item.OPERATESTATETEXT = operationStatusBll.GetDictValue(item.OPERATESTATE);
item.PROCESSTYPETEXT = processTypeBll.GetDictValue(item.PROCESSTYPE);
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取列表
///
/// 条件
/// 全部数据
public List GetOperationRecords(string productcode)
{
try
{
List list = new MainOperationDAL().GetOperationRecords(productcode);
ProcessParameterDAL dal = new ProcessParameterDAL();
var allparms = dal.GetList(new ProcessParameter { });
foreach (var rd in list)
{
rd.ParamColumns = allparms.Where(p => p.MACHINECODDE == rd.MACHINECODDE).ToList();
rd.PARATABLENAME = string.Join(",", rd.ParamColumns.GroupBy(p => p.PARATABLENAME).Select(p => p.Key).ToArray());
rd.SelectCollumns = string.Join(",", rd.ParamColumns.Select(p => p.PARANAME).ToArray());
if (rd.ParamColumns.Count > 0)
{
rd.ViewName = rd.ParamColumns.FirstOrDefault().MEMO;
}
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取列表(用于服务)
///
/// 条件
/// 全部数据
public List GetListUsedByCell(MainOperation condition)
{
try
{
List list = new MainOperationDAL().GetList(condition);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据扫描条码获取之前工序下拉列表(返修winform)
///
/// 条件
/// 全部数据
public List GetMainOperationWorkCell(string ProductCode, bool isINJECTION)
{
try
{
List list = new MainOperationDAL().GetMainOperationWorkCell(ProductCode, isINJECTION);
return list;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取统计列表
///
/// 条件
/// 全部数据
public DataResult GetListForstatistic(MainOperation condition)
{ DataResult dr = new DataResult();
try
{
DataTable dt = new MainOperationDAL().GetListForstatistic(condition);
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.PRODUCTTYPE);
foreach (DataRow row in dt.Rows)
{
//工序类别
row["产品类别"] = operationStatusBll.GetDictValue(row["产品类别"].ToString());
}
dr.IsSuccess = true;
dr.Result = dt;
}
catch (Exception ex)
{
dr.IsSuccess = false;
dr.Msg = ex.Message;
}
return dr;
}
public DataResult GetListForstatisticWithColor(MainOperation condition)
{
DataResult dr = new DataResult();
try
{
DataTable dt = new MainOperationDAL().GetListForStatisticWithColor(condition);
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.PRODUCTTYPE);
foreach (DataRow row in dt.Rows)
{
//工序类别
//row["产品类别"] = operationStatusBll.GetDictValue(row["产品类别"].ToString());
}
dr.IsSuccess = true;
dr.Result = dt;
}
catch (Exception ex)
{
dr.IsSuccess = false;
dr.Msg = ex.Message;
}
return dr;
}
public DataResult GetListForstatisticWithColor2(MainOperation condition)
{
DataResult dr = new DataResult();
try
{
DataTable dt = new MainOperationDAL().GetListForStatisticWithColor2(condition);
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.PRODUCTTYPE);
foreach (DataRow row in dt.Rows)
{
//工序类别
//row["产品类别"] = operationStatusBll.GetDictValue(row["产品类别"].ToString());
}
dr.IsSuccess = true;
dr.Result = dt;
}
catch (Exception ex)
{
dr.IsSuccess = false;
dr.Msg = ex.Message;
}
return dr;
}
///
/// 获取列表
///
/// 条件
/// 全部数据
public MainOperation GetByCondition(MainOperation condition)
{
try
{
List list = new MainOperationDAL().GetList(condition);
if (list.Count > 0)
{
DictManageBLL operationStatusBll = new DictManageBLL(DictKind.OPERATESTATE);
//工序类别
list[0].OPERATESTATETEXT = operationStatusBll.GetDictValue(list[0].OPERATESTATE);
return list[0];
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 产品加工追溯
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetMainOperationReviewList(MainOperation condition, DataPage page)
{
DataResult result = new DataResult();
DataPage dataPage = null;
try
{
if (string.IsNullOrEmpty(condition.PRODUCTCODE)
&& string.IsNullOrEmpty(condition.MAINCODE)
)
{
dataPage = new DataPage();
dataPage.Result = new List();
result.Result = dataPage;
return result;
}
dataPage = new MainOperationDAL().GetMainOperationReviewList(condition, page);
#region 转换零件类别、物料类别显示类型
List machineInfoList = dataPage.Result as List;
DictManageBLL dictProductStatusBll = new DictManageBLL(DictKind.PRODUCTSTATUS);
DictManageBLL dictProcessStatusBll = new DictManageBLL(DictKind.PROCESSSTATUS);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
foreach (MainOperation m in machineInfoList)
{
//产品状态
m.STATUS = dictProductStatusBll.GetDictValue(m.STATUS);
//加工状态
m.OPERATESTATE = dictProcessStatusBll.GetDictValue(m.OPERATESTATE);
//工序类别
m.CURRENTPROCESS = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
}
#endregion
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;
}
public List GetMainOperations(Product condition)
{
//DataPage dataPage = new DataPage();
//var desult = new List();
//DataResult result = new DataResult();
MainBLL mb = new MainBLL();
try
{
if (string.IsNullOrEmpty(condition.PRODUCTCODE))
{
if (string.IsNullOrEmpty(condition.MAINCODE))
{
return null;
}
var m = mb.GetByCondition(new Main { publicCode = condition.MAINCODE });
if (m == null)
{
return null;
}
condition.PRODUCTCODE = m.EPIDERMISCODE;
}
List machineInfoList = new MainOperationDAL().GetMainOperations(condition);
#region 转换零件类别、物料类别显示类型
DictManageBLL dictProductStatusBll = new DictManageBLL(DictKind.PRODUCTSTATUS);
DictManageBLL dictProcessStatusBll = new DictManageBLL(DictKind.PROCESSSTATUS);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
//foreach (Product m in machineInfoList)
//{
// //产品条码
// m.PRODUCTCODE = condition.PRODUCTCODE;
// //总成条码
// var main = mb.GetByCondition(new Main { publicCode = condition.PRODUCTCODE });
// if (main != null)
// {
// m.MAINCODE = condition.MAINCODE;
// }
// m.CREATEDATESTR = m.OPERATEDDATE.ToString("yyyy-MM-dd HH:mm:ss");
// //产品状态
// m.STATUS = dictProductStatusBll.GetDictValue(m.STATUS);
// //加工状态
// m.OPERATESTATE = dictProcessStatusBll.GetDictValue(m.OPERATESTATE);
// //工序类别
// m.CURRENTPROCESS = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
//}
#endregion
//result.Result = dataPage;
//result.IsSuccess = true;
return machineInfoList;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataResult GetExportDataForMOR(MainOperation model)
{
DataResult result = new DataResult();
try
{
DataTable dt = new MainOperationDAL().GetExportDataForMOR(model);
#region 转换零件类别、物料类别显示类型
DictManageBLL dictProductStatusBll = new DictManageBLL(DictKind.PRODUCTSTATUS);
DictManageBLL dictProcessStatusBll = new DictManageBLL(DictKind.PROCESSSTATUS);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
foreach (DataRow item in dt.Rows)
{
//产品状态
item["STATUS"] = dictProductStatusBll.GetDictValue(item["STATUS"].ToString());
//加工状态
item["OPERATESTATE"] = dictProcessStatusBll.GetDictValue(item["OPERATESTATE"].ToString());
//工序类别
item["CURRENTPROCESS"] = dictProcessTypeBll.GetDictValue(item["CURRENTPROCESS"].ToString());
}
#endregion
result.Result = dt;
}
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;
}
public DataResult GetExportDataForMORNew(MainOperation model)
{
DataResult result = new DataResult();
try
{
MainBLL mb = new MainBLL();
if (string.IsNullOrEmpty(model.PRODUCTCODE))
{
if (string.IsNullOrEmpty(model.MAINCODE))
{
return null;
}
var m = mb.GetByCondition(new Main { publicCode = model.MAINCODE });
if (m == null)
{
return null;
}
model.PRODUCTCODE = m.EPIDERMISCODE;
}
//List machineInfoList = new MainOperationDAL().GetMainOperations(condition);
DataTable dt = new MainOperationDAL().GetExportDataForMORNew(model);
#region 转换零件类别、物料类别显示类型
DictManageBLL dictProductStatusBll = new DictManageBLL(DictKind.PRODUCTSTATUS);
DictManageBLL dictProcessStatusBll = new DictManageBLL(DictKind.PROCESSSTATUS);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
foreach (DataRow item in dt.Rows)
{
//产品条码
item["PRODUCTCODE"] = model.PRODUCTCODE;
//总成条码
//var main = mb.GetByCondition(new Main { publicCode = model.PRODUCTCODE });
//if (main != null)
//{
// item["MAINCODE"] = model.MAINCODE;
//}
//item["CREATEDATESTR"] = item["OPERATEDDATE"].ToString("yyyy-MM-dd HH:mm:ss");
//产品状态
item["STATUS"] = dictProductStatusBll.GetDictValue(item["STATUS"].ToString());
//加工状态
item["OPERATESTATE"] = dictProcessStatusBll.GetDictValue(item["OPERATESTATE"].ToString());
//工序类别
item["CURRENTPROCESS"] = dictProcessTypeBll.GetDictValue(item["CURRENTPROCESS"].ToString());
}
#endregion
result.Result = dt;
}
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
#endregion
#region 设备加工
///
/// 判断是否符合设备模具的加工条件
///
///
///
public DataResult GetMashineStatus(OperationServiceParam operationServiceParam)
{
DataResult result = new DataResult();
string modelStation = "1";//默认第一个模具
//设置当前设备的当前模具
if (string.IsNullOrEmpty(operationServiceParam.machineInfo.MOLDNUMBER))
{
operationServiceParam.machineInfo.MOLDNUMBER = modelStation;
}
//如果设备存在位置扫描标示
if (operationServiceParam.machineInfo.ISSTATION.Equals(EnumGeter.HAVEORNOT.HAVE.GetHashCode()))
{
#region 调用接口------获取当前的模具位置
List models = operationServiceParam.machineInfo.MODELS;//设备模具列表
if (models != null && models.Count > 0)//证明有多模具,而且需要获取模具
{
//modelStation = "";//调用接口获取当前模具位置
//算出当前放零件的位置
modelStation = ((Convert.ToInt32(modelStation) + operationServiceParam.machineInfo.MODELSTATIONS) % models.Count).ToString();
operationServiceParam.model = models.Find(m => m.MODELSTATION == modelStation);
}
#endregion
}
result.IsSuccess = true;
return result;
}
///
/// 处理零件条码返回零件实体
///
/// 零件条码
/// 传递参数
/// Product--result.IsMain=true当前零件为本体 result.IsMain==false为零件
public DataResult ExplainProduct(string productCode, OperationServiceParam operationServiceParam)
{
DataResult result = new DataResult();
Product product = new Product();
try
{
#region 1.判断是否重复扫描,重复扫描不做任何操作
int exsitCount = operationServiceParam.productList.FindAll(m => m.PRODUCTCODE == productCode).Count;
if (exsitCount > 0)
{
result.IsSuccess = false;
return result;
}
#endregion
#region 2.获取当前零件信息
Product proSearchModel = new Product();
proSearchModel.PRODUCTCODE = productCode;
//获取产品信息
List products = new ProductBLL().GetListAndAttrByCondition(proSearchModel).OrderBy(o => o.USINGSTATE).ToList();
//如果产品数量大于1,那么一定风道信息
if (products.Count > 1)
{
//这里需要额外处理一下
//正常先获取处于本工位的条码信息
product = products.Find(m => m.CURRENTPROCESS == operationServiceParam.processSet.PROCESSTYPE);
//红外焊接工位处理
if (operationServiceParam.processSet.PROCESSTYPE == EnumGeter.ProcessType.hongwaihanjie.GetHashCode().ToString())
{
//获取红外焊接工位未使用的风道
product = products.Find(m =>
m.USINGSTATE == EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString()
&& m.CURRENTPROCESS == operationServiceParam.processSet.PROCESSTYPE);
//获取铆接工位未使用的风道
if (product == null)
{
product = products.Find(m =>
m.USINGSTATE == EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString());
}
}
//如果前面的条件过滤了所有的条码信息,表示在铆接和红外焊接的工序两个风道都使用完成
if (product == null)
{
product = products[0];
}
}
else if (products.Count == 1)
{
product = products[0];
if (operationServiceParam.machineInfo.PROCESSTYPE
== EnumGeter.ProcessType.maojie.GetHashCode().ToString()
&& product.CURRENTPROCESS != EnumGeter.ProcessType.maojie.GetHashCode().ToString()
&& productCode.IndexOf("B9B") == 0)
{
//20160612不全注塑丢失的条码信息
//闫永刚
product = InsertProductBack(productCode, operationServiceParam);
}
//2016-7-3 当红外焊接设备扫描了风道时,并且该风道已经使用,这时不能提升该风道已经使用
//因为两个风道使用同一个码,应提提示该风道没有进行铆接操作
//闫永刚
if (operationServiceParam.machineInfo.PROCESSTYPE
== EnumGeter.ProcessType.hongwaihanjie.GetHashCode().ToString()
&& product.USINGSTATE == EnumGeter.USINGSTATE.USED.GetHashCode().ToString()
&& productCode.IndexOf("B9B") == 0)
{
result.IsSuccess = false;
result.Msg = string.Format("{0}未进行铆接操作!", product.PRODUCTCODE);
return result;
}
}
else
{
product = null;
//20160612不全注塑丢失的条码信息
//闫永刚
product = InsertProductBack(productCode, operationServiceParam);
}
#endregion
if (product != null)
{
product.productBasic = new ProductBasicBLL().GetByCode(new ProductBasic { PRODUCTTYPE = product.PRODUCTTYPE });
}
#region 2.1 如果不存在当前零件信息,那么判断是否为外购件,并添加外购件信息
if (product == null)
{
//如果未外购件则添加
//根据条码调取服务获得该条码对应的类别
/////////服务
ProductBasic proBasic = new ProductBasic();
proBasic.PRODUCTTYPE = "";
if (productCode.IndexOf("B9H") == 0)//左格栅
{
proBasic.PRODUCTTYPE = "6";
if (productCode.Length != 18)
{
result.IsSuccess = false;
result.Msg = productCode + "左格栅条码格式错误!\r\n请扫描正确的左格栅条码!";
return result;
}
string colorCode=productCode.Substring(12,3);
if (colorCode != "24A" && colorCode != "6PS"
&& colorCode != "RK1" && colorCode != "AY2")
{
result.IsSuccess = false;
result.Msg = productCode + "左格栅条码颜色信息错误!\r\n请扫描正确的左格栅条码!";
return result;
}
}
else if (productCode.IndexOf("B9I") == 0)//右格栅
{
proBasic.PRODUCTTYPE = "10";
if (productCode.Length != 18)
{
result.IsSuccess = false;
result.Msg = productCode + "右格栅条码格式错误!\r\n请扫描正确的右格栅条码!";
return result;
}
string colorCode = productCode.Substring(12, 3);
if (colorCode != "24A" && colorCode != "6PS"
&& colorCode != "RK1" && colorCode != "AY2")
{
result.IsSuccess = false;
result.Msg = productCode + "右格栅条码颜色信息错误!\r\n请扫描正确的右格栅条码!";
return result;
}
}
else if (productCode.IndexOf("B9J") == 0)//中控支架
{
proBasic.PRODUCTTYPE = "7";
}
else if (productCode.IndexOf("B9K") == 0)//HUD支架
{
proBasic.PRODUCTTYPE = "11";
if (productCode.Length != 18)
{
result.IsSuccess = false;
result.Msg = productCode + "HUD支架条码格式错误!\r\n请扫描正确的HUD支架式条码!";
return result;
}
}
else
{
result.IsSuccess = false;
result.Msg = Resource.OperationProNotFound;
return result;
}
proBasic = new ProductBasicBLL().GetByCode(proBasic);
//获取类别出错
if (proBasic == null)
{
result.Msg = Resource.OperationProTypeError;
result.IsSuccess = false;
return result;
}
//获取判断出该条码属于哪个类别
#region 自制件
if (proBasic.PRODUCTSOURCE.Equals(EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString()))//属于自制
{
//判断当前设备是否接受和发送指令
if (!operationServiceParam.machineInfo.ISCONTROL.Equals(EnumGeter.ISCONTROL.NOSENDNOREAD.GetHashCode().ToString()))
{
result.Msg = Resource.OperationProNotFound;
result.IsSuccess = false;
return result;
}
//只有设备既不接受指令也不发送指令才需要添加
//获取当前零件类别的工序设置的第一道工序
ProcessSet processSet = new ProcessSetBLL().GetByModel(new ProcessSet { PRODUCTTYPE = proBasic.PRODUCTTYPE, PROCESSINDEX = 1 }).Result;
//将当前零件插入零件条码表生成原始记录
Product recorder = new Product();
recorder.PRODUCTCODE = productCode;
recorder.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString();
recorder.PRODUCTTYPE = proBasic.PRODUCTTYPE;
recorder.STATUS = EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString();
recorder.CURRENTPROCESS = processSet.PROCESSTYPE;
recorder.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
recorder.OUTFLAG = EnumGeter.PRODUCTOUTFLAG.INLIBRARY.GetHashCode().ToString();
recorder.USINGSTATE = EnumGeter.PRODUCTUSESTATE.UNUSED.GetHashCode().ToString();
recorder.CAPACITY = 1;
recorder.USINGCOUNT = 0;
//如果为表皮的话需要拆解表皮属性
if (recorder.PRODUCTTYPE.Equals(EnumGeter.ProductType.biaopi.GetHashCode().ToString()))
{
//解析条码
ProductAttribute productAttribute = new ProductAttribute();
//搪塑机编号
productAttribute.VAL1 = productCode.Substring(10, 7);
//产品类型
productAttribute.VAL2 = productCode.Substring(17, 2);
//高低配
productAttribute.VAL3 = productCode.Substring(19, 1);
//颜色
productAttribute.VAL4 = productCode.Substring(20, 1);
//腔
productAttribute.VAL5 = productCode.Substring(21, 1);
//模腔
productAttribute.VAL6 = productCode.Substring(22);
//加工日期
productAttribute.VAL7 = DateTime.ParseExact(productCode.Substring(0, 10), "yyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd");
DataResult resultInsert = new ProductBLL().InsertEpidermis(recorder);
if (resultInsert.IsSuccess == false)
{
result.Msg = Resource.OperationProNotFound;
result.IsSuccess = false;
return result;
}
}
else
{
DataResult resultInsert = new ProductBLL().Insert(recorder);
if (resultInsert.IsSuccess == false)
{
result.Msg = Resource.OperationProNotFound;
result.IsSuccess = false;
return result;
}
}
product = new ProductBLL().GetAndAttrByCondition(proSearchModel);
result.Result = product;
result.IsSuccess = true;
}
#endregion
#region 采购件
if (proBasic.PRODUCTSOURCE.Equals(EnumGeter.PRODUCTSOURCE.OUTSOURCING.GetHashCode().ToString()))//属于采购
{
Product pAdd = new Product();
pAdd.PRODUCTTYPE = proBasic.PRODUCTTYPE;
pAdd.PRODUCTCODE = productCode;
pAdd.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.OUTSOURCING.GetHashCode().ToString();
pAdd.MACHINENAME = operationServiceParam.machineInfo.MACHINENAME;
pAdd.MACHINECODDE = operationServiceParam.machineInfo.MACHINECODDE;
pAdd.STATUS = EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString();
pAdd.CURRENTPROCESS = operationServiceParam.processSet.PROCESSTYPE;
pAdd.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
pAdd.PRODUCESHIFTTCODE = "";
pAdd.PRODUCESHIFTNAME = "";
pAdd.OUTFLAG = EnumGeter.PRODUCTOUTFLAG.INLIBRARY.GetHashCode().ToString();
pAdd.USINGSTATE = EnumGeter.PRODUCTUSESTATE.USING.GetHashCode().ToString();
pAdd.CAPACITY = proBasic.CAPATITY;
pAdd.USINGCOUNT = 0;
//调用保存接口
DataResult resultInsert = new ProductBLL().InsertAndReturn(pAdd);
//保存成功
if (!resultInsert.IsSuccess)
{
result.Msg = resultInsert.Msg;
result.IsSuccess = false;
return result;
}
product = resultInsert.Result;
product.productBasic = proBasic;
}
#endregion
}
#endregion
#region 2.2 设置零件是哪种类别本体还是零件
if (product.PRODUCTTYPE.Equals(EnumGeter.ProductType.biaopi.GetHashCode().ToString())
&& product.USINGSTATE.Equals(EnumGeter.USINGSTATE.USED.GetHashCode().ToString())
&& operationServiceParam.machineInfo.PROCESSTYPE!=EnumGeter.ProcessType.lengdaoruohua.GetHashCode().ToString()
)
{
product.IsMain = true; //该零件为本体
}
else
{
product.IsMain = false;//该零件为零件
}
#region
result.Result = product;
result.IsSuccess = true;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = ex.Message;
throw;
}
return result;
}
///
/// 插入注塑产品信息
///
///
///
///
public Product InsertProductBack(string productCode,OperationServiceParam operationServiceParam)
{
Product product = null;
if (productCode.IndexOf("B9A") == 0 || productCode.IndexOf("B9B") == 0
|| productCode.IndexOf("B9C") == 0 || productCode.IndexOf("FJC") == 0
|| productCode.IndexOf("AAA") == 0)
{
Product newRecorder = new Product();
newRecorder.PID = Guid.NewGuid().ToString();
newRecorder.PRODUCTCODE = productCode;
newRecorder.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString();
newRecorder.STATUS = EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString();
newRecorder.CURRENTPROCESS = "";
newRecorder.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
newRecorder.OUTFLAG = EnumGeter.PRODUCTOUTFLAG.INLIBRARY.GetHashCode().ToString();
newRecorder.USINGSTATE = EnumGeter.PRODUCTUSESTATE.UNUSED.GetHashCode().ToString();
newRecorder.CAPACITY = 1;
newRecorder.USINGCOUNT = 0;
newRecorder.CURRENTPROCESS = operationServiceParam.processSet.PROCESSTYPE;
#region 初始化零件号
//获取产品零件号
List initList = new MaterialCodeInitDAL().GetList(new MaterialCodeInit() { PRODUCT_TYPES = productCode.Substring(0,3) });
if (initList.Count > 0)
{
MaterialCodeInit init = initList[0];
newRecorder.WORKCELL_CODE = init.WORKCELL_CODE;
newRecorder.WORKCENTER_CODE = init.WORKCENTER_CODE;
newRecorder.MATERIAL_CODE = init.MATERIAL_CODE;
newRecorder.WORKLOC_CODE = init.WORKLOC_CODE;
newRecorder.MATERIAL_TYPE = init.MATERIAL_TYPE;
}
#endregion
InsertInjectProduct(newRecorder);
List proList = new ProductBLL().GetListAndAttrByCondition(newRecorder);
product = proList[0];
#endregion
}
return product;
}
#region 插入注塑产品信息及加工记录
//插入产品记录
//插入注塑加工记录
private void InsertInjectProduct(Product newRecorder)
{
try
{
DateTime dt = Convert.ToDateTime("20" + newRecorder.PRODUCTCODE.Substring(3, 2) + "-" + newRecorder.PRODUCTCODE.Substring(5, 2) + "-" + newRecorder.PRODUCTCODE.Substring(7, 2) + " " + newRecorder.PRODUCTCODE.Substring(9, 2) + ":" + newRecorder.PRODUCTCODE.Substring(11, 2) + ":00");
newRecorder.CREATEDATE = dt;
MainOperation main = new MainOperation();
main.PID = Guid.NewGuid().ToString();
main.PDID = newRecorder.PID;
main.PRODUCTCODE = newRecorder.PRODUCTCODE;
if (newRecorder.PRODUCTCODE.IndexOf("B9A") == 0)
{
main.PROCESSTYPE = EnumGeter.ProcessType.gujiazhusu.GetHashCode().ToString();
main.CURRENTPROCESS = EnumGeter.ProcessType.gujiazhusu.GetHashCode().ToString();
newRecorder.PRODUCTTYPE = EnumGeter.ProductType.gujia.GetHashCode().ToString();
}
if (newRecorder.PRODUCTCODE.IndexOf("B9B") == 0)
{
main.PROCESSTYPE = EnumGeter.ProcessType.fengdaozhusu.GetHashCode().ToString();
main.CURRENTPROCESS = EnumGeter.ProcessType.fengdaozhusu.GetHashCode().ToString();
newRecorder.PRODUCTTYPE = EnumGeter.ProductType.fengdao.GetHashCode().ToString();
}
if (newRecorder.PRODUCTCODE.IndexOf("B9C") == 0)
{
main.PROCESSTYPE = EnumGeter.ProcessType.HUDfengdaozhusu.GetHashCode().ToString();
main.CURRENTPROCESS = EnumGeter.ProcessType.HUDfengdaozhusu.GetHashCode().ToString();
newRecorder.PRODUCTTYPE = EnumGeter.ProductType.HUDfengdao.GetHashCode().ToString();
}
if (newRecorder.PRODUCTCODE.IndexOf("FJC") == 0)
{
main.PROCESSTYPE = EnumGeter.ProcessType.qinangzhijiazhusu.GetHashCode().ToString();
main.CURRENTPROCESS = EnumGeter.ProcessType.qinangzhijiazhusu.GetHashCode().ToString();
newRecorder.PRODUCTTYPE = EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString();
}
if (newRecorder.PRODUCTCODE.IndexOf("AAA") == 0)
{
main.PROCESSTYPE = EnumGeter.ProcessType.qinangzhijiazhusu.GetHashCode().ToString();
main.CURRENTPROCESS = EnumGeter.ProcessType.qinangzhijiazhusu.GetHashCode().ToString();
newRecorder.PRODUCTTYPE = EnumGeter.ProductType.qinangzhijia.GetHashCode().ToString();
}
main.PRODUCTTYPE = newRecorder.PRODUCTTYPE;
main.STATUS = "0";
main.OPERATESTATE = EnumGeter.OPERATESTATE.COMPLETED.GetHashCode().ToString();
main.OPERATEDDATE = dt;
main.PRODUCELINE = "B9";
main.CREATEDATE = dt;
//InjectionParameterSampleDAL sampleDal = new InjectionParameterSampleDAL();
InJectionParameter para = new InJectionParameter();
//para = sampleDal.GetInJectionParameterSample(newRecorder);
para.PID = Guid.NewGuid().ToString();
para.PDID = newRecorder.PID;
para.MOID = main.PID;
para.PRODUCTCODE = newRecorder.PRODUCTCODE;
para.CREATEDATE = dt;
para.OPERATEDATE = dt;
//para.EDATE = dt.ToString("yyyy-MM-dd HH:mm:ss");
newRecorder.MACHINECODDE = para.MACHINECODDE;
newRecorder.MACHINENAME = para.MACHINENAME;
main.MACHINECODDE = para.MACHINECODDE;
main.MACHINENAME = para.MACHINENAME;
MainOperationDAL modal = new MainOperationDAL();
ProductDAL prodal = new ProductDAL();
////InjectionParameterDAL ipdal = new InjectionParameterDAL();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//ipdal.BaseSession = session;
prodal.BaseSession = session;
modal.BaseSession = session;
session.OpenTs();
prodal.Insert(newRecorder);
modal.Insert(main);
//ipdal.Insert(para);
session.CommitTs();
}
}
catch (Exception ex)
{
throw;
}
}
#endregion
///
/// 校验零件
///
///
/// BackStatus=true 代表 Main、 BackStatus=false 代表 Product
public DataResult