锐腾搅拌上料功能
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.

224 lines
8.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Base.Config.AppConfig;
using System.Data;
using ICSSoft.Base.Config.DBHelper;
using ICSSoft.Frame.Helper;
using System.Collections;
namespace ICSSoft.Frame.Data.DAL
{
public class ICSOPBOMDAL
{
public static readonly string OPBOMITEMTYPE_DEFAULT = "lot";
public static readonly string OPBOMVERSION_DEFAULT = "1";
public static readonly string OPBOMISItemCheckValue_DEFAULT = "0";
public static readonly string OPBOMItemCheckValue_DEFAULT = "0000000";
public static readonly string OPBOMItemUOM_DEFAULT = "OPBOMItemUOM";
private FramDataContext _domainDataProvider = null;
public ICSOPBOMDAL(FramDataContext domainDataProvider)
{
this._domainDataProvider = domainDataProvider;
}
#region 新增和修改
public static void Add(List<ICSOPBOM> tbInfoList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (ICSOPBOM tbinfo in tbInfoList)
{
bool isNew = false;
var line = db.ICSOPBOM.SingleOrDefault(a => a.ITEMCODE == tbinfo.ITEMCODE && a.OBCODE == tbinfo.OBCODE && a.OPBOMVER == tbinfo.OPBOMVER );
if (line == null)
{
isNew = true;
line = new ICSOPBOM();
line.ITEMCODE = tbinfo.ITEMCODE;
line.OBCODE = tbinfo.OBCODE;
line.OPBOMVER = tbinfo.OPBOMVER;
}
line.WorkPoint = tbinfo.WorkPoint;
line.ITEMID = tbinfo.ITEMID;
line.OBROUTE = tbinfo.OBROUTE;
line.OPDESC = tbinfo.OPDESC;
line.MUSER = tbinfo.MUSER;
line.MUSERName = tbinfo.MUSERName;
line.MTIME = tbinfo.MTIME;
line.EATTRIBUTE1 = tbinfo.EATTRIBUTE1;
line.AVIALABLE = tbinfo.AVIALABLE;
if (isNew)
db.ICSOPBOM.InsertOnSubmit(line);
db.SubmitChanges();
}
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
public ICSOPBOM GetOPBOMByRouteCode(string itemCode, string routeCode, string bomVersion)
{
string sql = "select * from ICSOPBOM where 1=1 {0}";
string tmpString = string.Empty;
if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
{
tmpString += " and itemcode ='" + itemCode.Trim() + "'";
}
if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
{
tmpString += " and obroute ='" + routeCode.Trim() + "'";
}
if ((bomVersion != string.Empty) && (bomVersion.Trim() != string.Empty))
{
tmpString += " and opbomver ='" + bomVersion.Trim() + "'";
}
tmpString += " and WorkPoint='"+AppConfig.WorkPointCode+"'" ;
//工单途程是否有上料工序
bool IsComponetLoading = this.CheckItemRouteIsContainComponetLoading(itemCode, routeCode);
List<ICSITEMROUTE2OP> objsOp = this.GetItemRouteIsContainComponetLoading(itemCode, routeCode);
List<ICSOPBOM> objs = this._domainDataProvider.ExecuteQuery<ICSOPBOM>(String.Format(sql, tmpString)).ToList();
//检查工单途程是否有上料工序,如果有则OPBOM不允许为空并抛出异常,否则则新增一个OPBOM插入数据库,并返回这个OPBOM,不再抛出异常
if (objs == null)
{
if (IsComponetLoading)
{
throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}']", itemCode, routeCode));
}
else
{
ICSOPBOM opBOM = CreateNewOPBOM();
opBOM.ITEMCODE = itemCode;
opBOM.OBROUTE = routeCode;
opBOM.MUSER = AppConfig.UserCode;
opBOM.MUSERName = AppConfig.UserName;
opBOM.OBCODE = routeCode;
opBOM.WorkPoint = AppConfig.WorkPointCode;
opBOM.OPBOMVER = bomVersion;
this.AddOPBOM(opBOM);
return opBOM;
}
}
else
{
if (IsComponetLoading)
{
foreach (ICSITEMROUTE2OP opbom in objsOp)
{
string selectSql = "select count(*) from ICSopbomdetail where 1= 1 {0} and WorkPoint='" +AppConfig.WorkPointCode+ "'";
string tmpString2 = " and itemcode ='" + itemCode.Trim() + "' ";
tmpString2 += " and opcode='" + opbom.OPCODE.Trim() + "'";
string opcodesSelect = string.Format(" AND obcode = '" + ((ICSOPBOM)objs[0]).OBCODE.Trim() + "' ");
tmpString2 += opcodesSelect;
int result = _domainDataProvider.ExecuteQuery<int>(String.Format(selectSql, tmpString2)).First<int>();
if (!(result > 0))
{
throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}',$OpCode='{2}']", itemCode, routeCode, opbom.OPCODE), null);
}
}
}
}
return objs[0];
}
#region 检查产品途程是否包含上料工序
public bool CheckItemRouteIsContainComponetLoading(string itemcode, string routecode)
{
bool returnbool = false;
string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
if (itemroute2ops != null)
{
foreach (object _item2op in itemroute2ops)
{
if (IsComponentLoadingOperation(((ICSITEMROUTE2OP)_item2op).OPCONTROL))
{
returnbool = true;
break;
}
}
}
return returnbool;
}
public List<ICSITEMROUTE2OP> GetItemRouteIsContainComponetLoading(string itemcode, string routecode)
{
List<ICSITEMROUTE2OP> objList = new List<ICSITEMROUTE2OP>();
string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
if (itemroute2ops != null && itemroute2ops.Count>0)
{
foreach (ICSITEMROUTE2OP _item2op in itemroute2ops)
{
if (IsComponentLoadingOperation((_item2op).OPCONTROL))
{
objList.Add(_item2op);
}
}
}
if (objList.Count > 0)
{
return objList;
}
return null;
}
private bool IsComponentLoadingOperation(string opControl)
{
return FormatHelper.StringToBoolean(opControl, 0);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public ICSOPBOM CreateNewOPBOM()
{
return new ICSOPBOM();
}
/// <summary>
/// item下BOMCode,暂时不考虑版本版本为1
/// 不考虑版本的升级
/// </summary>
/// <param name="opBOM"></param>
public void AddOPBOM(ICSOPBOM opBOM)
{
if (opBOM.OPBOMVER.Trim().Length == 0)
opBOM.OPBOMVER = OPBOMVERSION_DEFAULT;
this._domainDataProvider.ICSOPBOM.InsertOnSubmit(opBOM);
}
#endregion
}
}