using System;
using System.Runtime.Remoting;
using System.Collections;
using System.Reflection;
using System.Runtime.Remoting;
using System.Text.RegularExpressions;
using System.Linq;
using System.Data.Linq;
using System.Xml;
using System.IO;
using ICSSoft.Base.Config.AppConfig;
using System.Collections.Specialized;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Frame.DataConnect.Action;
using System.Data;
using ICSSoft.Frame.Helper;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Base.Config.DBHelper;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace ICSSoft.Frame.DataConnect
{
///
/// BaseModel 的摘要说明。
/// 文件名: BaseModel.cs
/// 描 述: 基本模型维护后台
/// 版 本:
///
public class ICSBaseModel
{
FramDataContext domainDataProvider = new Data.Entity.FramDataContext();
private FramDataContext _domainDataProvider = null;
private const string TS_Operation = "TS";
public ICSBaseModel(FramDataContext domainDataProvider)
{
this._domainDataProvider = domainDataProvider;
}
public ICSBaseModel()
{
}
public FramDataContext DataProvider
{
get
{
return _domainDataProvider;
}
}
#region Segment
///
/// ** 功能描述: 由SegmentCode获得Segment
/// ** 修 改:
/// ** 日 期:
/// ** 版本
///
///
///
public object GetSegment(string segmentCode)
{
return this.DataProvider.ICSSEG.SingleOrDefault(a => a.SEGCODE == segmentCode && a.WorkPoint == AppConfig.WorkPointCode);
}
#endregion
#region ICSSS
public object GetStepSequence(string stepSequenceCode)
{
return this.DataProvider.ICSSS.SingleOrDefault(a => a.SSCODE == stepSequenceCode && a.WorkPoint == AppConfig.WorkPointCode);
}
///
/// ** 功能描述: 查询ICSSS的总行数
///
///
/// StepSequenceCode,模糊查询
/// SegmentCode,模糊查询
/// ICSSS的总记录数
public int QueryStepSequenceCount(string stepSequenceCode, string segmentCode, string BigStepSequenceCode)
{
var ssline = from a in DataProvider.ICSSS
join b in DataProvider.ICSSEG on a.SEGID equals b.ID
where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
select new
{
a,
b
};
if (stepSequenceCode != null && stepSequenceCode.Length != 0)
{
ssline = ssline.Where(p=>p.a.SSCODE==stepSequenceCode);
}
if (segmentCode != null && segmentCode.Length != 0)
{
if (segmentCode.IndexOf(",") >= 0)
{
ssline = ssline.Where(p => segmentCode.Contains(p.b.SEGCODE));
}
else
{
ssline = ssline.Where(p=>p.b.SEGCODE.StartsWith(segmentCode));
}
}
if (ssline != null)
{
return ssline.ToList().Count;
}
else
{
return 0;
}
}
///
/// ** 功能描述: 分页查询ICSSS
///
/// StepSequenceCode,模糊查询
/// SegmentCode,模糊查询
/// 开始行数
/// 结束行数
///
public object[] QueryStepSequence(string stepSequenceCode, string segmentCode)
{
try
{
var ssline = from a in DataProvider.ICSSS
join b in DataProvider.ICSSEG on a.SEGID equals b.ID
where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
orderby a.SSCODE
select new
{
a,
b
};
if (stepSequenceCode != null && stepSequenceCode.Length != 0)
{
ssline = ssline.Where(p=>p.a.SSCODE.StartsWith(stepSequenceCode));
}
if (segmentCode != null && segmentCode.Length != 0)
{
if (segmentCode.IndexOf(",") >= 0)
{
ssline = ssline.Where(p => segmentCode.Contains(p.b.SEGCODE));
}
else
{
ssline = ssline.Where(p => p.b.SEGCODE.StartsWith(segmentCode));
}
}
return ssline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format( "select * from TBLSS where 1=1 {0} order by SSSEQ", condition )));
//return this.DataProvider.CustomQuery(typeof(ICSSS), new PagerCondition(string.Format(, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), condition), "SEGCODE"));
}
///
/// ** 功能描述: 获得所有的ICSSS
///
/// 所有的ICSSS
public object[] GetAllStepSequence()
{
try
{
var line = DataProvider.ICSSS.Where(p => p.WorkPoint == AppConfig.WorkPointCode);
return line.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format("select {0} from TBLSS where 1=1 " + " and WorkPoint ='"+AppConfig.WorkPointCode+"'" + " order by SSCODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)))));
}
///
/// ** 功能描述: 获得Segment下所有的ICSSS
///
/// Segment下所有的ICSSS
public object[] GetStepSequenceBySegmentCode(string segmentCode)
{
try
{
var ssline = from a in DataProvider.ICSSS
join b in DataProvider.ICSSEG on a.SEGID equals b.ID
where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode && b.SEGCODE==segmentCode
orderby a.SSCODE
select new
{
a,
b
};
return ssline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format("select {0} from TBLSS where 1=1 " + " and WorkPoint ='"+AppConfig.WorkPointCode+"'" + " and SEGCODE='{1}' order by SSCODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), segmentCode)));
}
#endregion
#region ICSRES
//检查资源对应工序是返工途程的第一个工序
private void CheckResource(ICSRES resource)
{
var resline = from a in DataProvider.ICSOP2RES
join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
join c in DataProvider.ICSROUTE on b.ROUTECODE equals c.ROUTECODE
where a.RESCODE == resource.RESCODE && c.ROUTETYPE == "Rework" && a.WorkPoint == AppConfig.WorkPointCode && b.WORKPOINT == AppConfig.WorkPointCode && c.WorkPoint == AppConfig.WorkPointCode
select new {
b.ROUTECODE
};
if (resource.ID != null && resline != null)
{
ICSOP2RES op = this.GetOperationByResource(resource.RESCODE);
if (op == null)
{
throw new Exception("$Error_Res_not_belong_To_Op");
}
object op2 = GetFirstOperationOfRoute(resline.ToList()[0].ToString()) as ICSOP;
if (op2 == null)
{
throw new Exception("$error_route_no_op");
}
if (((ICSOP)op2).OPCODE != op.OPCODE)
{
throw new Exception("$error_res_not_first_op");
}
}
}
public object GetResource(string resourceCode)
{
try
{
var line = DataProvider.ICSRES.SingleOrDefault(a => a.RESCODE == resourceCode);
return line;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// ** 功能描述: 查询ICSRES的总行数
///
/// ResourceCode,模糊查询
/// ICSRES的总记录数
public int QueryResourceCount(string resourceCode, string stepSequenceCode, string crewCode)
{
var resline = from a in DataProvider.ICSRES
join b in DataProvider.ICSSS on a.SSID equals b.ID
where a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode && b.WorkPoint==AppConfig.WorkPointCode
select new
{
a,
b
};
if (stepSequenceCode != "")
{
if (stepSequenceCode.IndexOf(",") >= 0)
{
resline= resline.Where(p=>stepSequenceCode.Contains(p.b.SSCODE));
}
else
{
resline = resline.Where(p => p.b.SSCODE.StartsWith(stepSequenceCode));
}
}
if (crewCode != "")
{
resline = resline.Where(p => p.a.CREWCODE.StartsWith(crewCode));
}
return resline.ToList().Count;
}
public object[] CheckResource(string ssCode)
{
try
{
var resline = from a in DataProvider.ICSSS
where ssCode.ToUpper().StartsWith(a.SSCODE) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), ssCode)));
}
///
/// ** 功能描述: 分页查询ICSRES
///
/// ResourceCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSRES数组
public object[] QueryResource(string resourceCode, string stepSequenceCode, string crewCode)
{
try
{
var resline = from a in DataProvider.ICSRES
join b in DataProvider.ICSSS on a.SSID equals b.ID
where a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode && b.WorkPoint==AppConfig.WorkPointCode
select new
{
a,
b
};
if (stepSequenceCode != "")
{
if (stepSequenceCode.IndexOf(",") >= 0)
{
resline = resline.Where(p => stepSequenceCode.Contains(p.b.SSCODE));
}
else
{
resline = resline.Where(p => p.b.SSCODE.StartsWith(stepSequenceCode));
}
} //stepSequenceCode在数据库中允许为空,
if (crewCode != "")
{
resline = resline.Where(p => p.a.CREWCODE.StartsWith(crewCode));
}
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES), new PagerCondition(qSql, "RESCODE", inclusive, exclusive));
}
///
/// ** 功能描述: 获得所有的ICSRES
///
/// ICSRES的总记录数
public object[] GetAllResource()
{
try
{
var resline = from a in DataProvider.ICSRES
where a.WorkPoint == AppConfig.WorkPointCode
orderby a.RESCODE
select a;
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)))));
}
///
/// ** 功能描述: 根据ShiftTypeCode得到ICSRES实体
///
/// SegmentCode
/// ICSRES数组
public object[] QueryResourceBySegmentCode(string segmentCode)
{
try
{
var resline = from a in DataProvider.ICSRES
join b in DataProvider.ICSSEG on a.SEGID equals b.ID
where b.SEGCODE == segmentCode && a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
select new {
a,
b
};
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// End Added
// return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), segmentCode)));
}
#endregion
#region ICSOP
public object GetOperation(string opCode)
{
try
{
var opline = from a in DataProvider.ICSOP
where a.OPCODE == opCode && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomSearch(typeof(ICSOP), new object[] { opCode });
}
///
/// ** 功能描述: 查询ICSOP的总行数
///
/// OPCODE,模糊查询
/// ICSOP的总记录数
public int QueryOperationCount(string oPCode)
{
var resline = from a in DataProvider.ICSOP
where oPCode.StartsWith(oPCode) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return resline.ToList().Count;
//return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLOP where 1=1 and OPCODE like '{0}%'", oPCode)));
}
///
/// ** 功能描述: 查询ICSOP
///
/// OPCODE,模糊查询
/// 开始行数
/// 结束行数
/// ICSOP数组
public object[] QueryOperation(string oPCode)
{
try
{
var resline = from a in DataProvider.ICSOP
where a.OPCODE.StartsWith(oPCode) && a.WorkPoint==AppConfig.WorkPointCode
select a;
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSOP), new PagerCondition(string.Format("select {0} from TBLOP where 1=1 and OPCODE like '{1}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), oPCode), "OPCODE", inclusive, exclusive));
}
public object[] QueryOperation()
{
try
{
var resline = DataProvider.ICSOP.Where(p => p.WorkPoint == AppConfig.WorkPointCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition("select distinct opcode from TBLOP ORDER BY opcode"));
}
///
/// ** 功能描述: 获得所有的ICSOP
///
/// ICSOP的总记录数
public object[] GetAllOperation()
{
try
{
var resline = from a in DataProvider.ICSOP
where a.WorkPoint == AppConfig.WorkPointCode
select a;
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP order by OPCODE ", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)))));
}
public bool IsOperationInRoute(string routeCode, string opCode)
{
var resline = DataProvider.ICSROUTE2OP.Where(p=>p.ROUTECODE==routeCode&&p.OPCODE==opCode&&p.WORKPOINT==AppConfig.WorkPointCode);
if (resline != null)
{
return true;
}
else
{
return false;
}
}
#endregion
#region ICSROUTE
///
/// ** 功能描述: 查询ICSROUTE的总行数
///
/// RouteCode,模糊查询
/// ICSROUTE的总记录数
public int QueryRouteCount(string routeCode)
{
var resline = DataProvider.ICSROUTE.Where(p=>p.ROUTECODE.StartsWith(routeCode));
return resline.ToList().Count;
//return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLROUTE where 1=1 and ROUTECODE like '{0}%' ", routeCode)));
}
///
/// ** 功能描述: 分页查询ICSROUTE
///
/// RouteCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSROUTE数组
public object[] QueryRoute(string routeCode)
{
try
{
var resline = DataProvider.ICSROUTE.Where(p => p.ROUTECODE.StartsWith(routeCode)&&p.WorkPoint==AppConfig.WorkPointCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSROUTE), new PagerCondition(string.Format("select {0} from TBLROUTE where 1=1 and ROUTECODE like '{1}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)), routeCode), "ROUTECODE ", inclusive, exclusive));
}
///
/// ** 功能描述: 分页查询ICSROUTE
///
/// RouteCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSROUTE数组
public object[] QueryICSITEM2ROUTE(string itemCode)
{
try
{
var resline = DataProvider.ICSITEM2ROUTE.Where(p=>p.ITEMCODE==itemCode && p.WorkPoint==AppConfig.WorkPointCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSITEM2ROUTE),
// new PagerCondition(string.Format("select {0} from TBLICSITEM2ROUTE where ITEMCODE = '{1}'"
// + " and WorkPoint ='"+AppConfig.WorkPointCode+"'",
// DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSITEM2ROUTE)), itemCode),
// "ITEMCODE ", inclusive, exclusive));
}
///
/// ** 功能描述: 分页查询ICSROUTE
///
/// RouteCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSROUTE数组
public int GetICSITEM2ROUTECount(string itemCode)
{
try
{
var resline = DataProvider.ICSITEM2ROUTE.Where(p => p.ITEMCODE == itemCode && p.WorkPoint == AppConfig.WorkPointCode);
return resline.ToList().Count;
}
catch (Exception)
{
throw;
}
}
///
/// ** 功能描述: 获得所有的ICSROUTE
///
/// ICSROUTE的总记录数
public object[] GetAllRoute()
{
try
{
var resline = DataProvider.ICSROUTE.Where(p=>p.WorkPoint==AppConfig.WorkPointCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSROUTE), new SQLCondition(string.Format("select {0} from TBLROUTE order by ROUTECODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)))));
}
///
/// ** 功能描述: 获得所有的ICSROUTE
///
/// ICSROUTE的总记录数
public object[] GetAllRouteEnabled()
{
try
{
var resline = DataProvider.ICSROUTE.Where(p=>p.WorkPoint==AppConfig.WorkPointCode&&p.ENABLED=="生效"&&p.WorkPoint==AppConfig.WorkPointCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSROUTE), new SQLCondition(string.Format("select {0} from TBLROUTE where enabled='1' order by ROUTECODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)))));
}
public object GetOPFromRoute2OP(string routeCode, string resourceCode)
{
try
{
var resline = from a in DataProvider.ICSROUTE2OP
join b in DataProvider.ICSOP2RES on a.OPCODE equals b.OPCODE
select new {
a,
b
};
if (routeCode.Trim() != string.Empty)
{
resline = resline.Where(p=>p.a.ROUTECODE==routeCode.Trim().ToUpper());
}
if (resourceCode.Trim() != string.Empty)
{
resline = resline.Where(p => p.b.RESCODE == resourceCode.Trim().ToUpper());
}
return resline.ToArray() ;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//object[] returnObjects = this.DataProvider.CustomQuery(typeof(ICSROUTE2OP), new SQLCondition(sql));
//if (returnObjects != null)
//{
// return returnObjects[0];
//}
//return null;
}
///
/// ** 功能描述: 获得所有的ICSROUTE
///
///
///
public bool IsRouteRef(string routeCode)
{
var resline = DataProvider.ICSITEM2ROUTE.Where(p=>p.ISREF=="是" && p.ROUTECODE==routeCode && p.WorkPoint==AppConfig.WorkPointCode);
if (resline!=null)
{
return true;
}
else
{
return false;
}
//return (this.DataProvider.GetCount(new SQLCondition(string.Format(" select count(*) from ICSITEM2ROUTE where ISREF='是' AND ROUTECODE='{0}' ", routeCode))) > 0);
}
#endregion
public void AddOrEdit(string Type)
{
System.Type type = System.Type.GetType(Type);
}
#region ICSROUTE2OP
public ICSROUTE2OP CreateNewRoute2Operation()
{
return new ICSROUTE2OP();
}
public void AddAndUpdateRoute2Operation(ICSROUTE2OP route2Operation)
{
try
{
bool isNew = false;
var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == route2Operation.ROUTEID && a.OPID == route2Operation.OPID);
if (line == null)
{
isNew = true;
line = new ICSROUTE2OP();
line.OPID = route2Operation.OPID;
line.ROUTEID = route2Operation.ROUTEID;
}
line.ROUTECODE = route2Operation.ROUTECODE;
line.OPCODE = route2Operation.OPCODE;
line.OPSEQ = route2Operation.OPSEQ;
line.OPCONTROL = route2Operation.OPCONTROL;
line.MUSER = route2Operation.MUSER;
line.MUSERName = route2Operation.MUSERName;
line.MTIME = route2Operation.MTIME;
line.WORKPOINT = route2Operation.WORKPOINT;
line.EATTRIBUTE1 = route2Operation.EATTRIBUTE1;
if (isNew) DataProvider.ICSROUTE2OP.InsertOnSubmit(line);
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void AddRoute2Operation(ICSROUTE2OP[] route2Operations)
{
try
{
foreach (ICSROUTE2OP route2Operation in route2Operations)
{
bool isNew = false;
var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == route2Operation.ROUTEID && a.OPID == route2Operation.OPID);
if (line == null)
{
isNew = true;
line = new ICSROUTE2OP();
line.OPID = route2Operation.OPID;
line.ROUTEID = route2Operation.ROUTEID;
}
line.ROUTECODE = route2Operation.ROUTECODE;
line.OPCODE = route2Operation.OPCODE;
line.OPSEQ = route2Operation.OPSEQ;
line.OPCONTROL = route2Operation.OPCONTROL;
line.MUSER = route2Operation.MUSER;
line.MUSERName = route2Operation.MUSERName;
line.MTIME = route2Operation.MTIME;
line.WORKPOINT = route2Operation.WORKPOINT;
line.EATTRIBUTE1 = route2Operation.EATTRIBUTE1;
if (isNew) DataProvider.ICSROUTE2OP.InsertOnSubmit(line);
}
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public void UpdateRoute2Operation(ICSROUTE2OP route2Operation)
{
UpdateRoute2Operation(route2Operation, true);
}
public void UpdateRoute2Operation(ICSROUTE2OP route2Operation, bool checkSeq)
{
if (checkSeq)
{
var resline = DataProvider.ICSROUTE2OP.Where(p => p.ROUTECODE == route2Operation.ROUTECODE);
//object[] route2Ops = this.DataProvider.CustomQuery(typeof(ICSROUTE2OP),
// new SQLCondition(string.Format("select {0} from tblroute2op where routecode = '{1}'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE2OP)), route2Operation.RouteCode)));
if (resline != null)
{
foreach (ICSROUTE2OP route2Op in resline)
{
if (route2Op.OPSEQ== route2Operation.OPSEQ
&& route2Op.OPCODE != route2Operation.OPCODE)
{
throw new Exception("$Error_Route2Operation_Sequence_Cannot_Repeat");
}
}
}
}
AddAndUpdateRoute2Operation(route2Operation);
}
///
/// sammer kong 2005/05/21 route in usage
///
///
public void DeleteRoute2Operation(ICSROUTE2OP route2Operation)
{
try
{
var lines = DataProvider.ICSROUTE2OP.Where(a => a.OPID == route2Operation.OPID && a.ROUTEID == route2Operation.ROUTEID);
DataProvider.ICSROUTE2OP.DeleteAllOnSubmit(lines);
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
}
public void DeleteRoute2Operation(ICSROUTE2OP[] route2Operations)
{
try
{
foreach (ICSROUTE2OP route2Operation in route2Operations)
{
var lines = DataProvider.ICSROUTE2OP.Where(a => a.OPID == route2Operation.OPID && a.ROUTEID == route2Operation.ROUTEID);
DataProvider.ICSROUTE2OP.DeleteAllOnSubmit(lines);
}
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
}
public bool IsRouteOperationInUsage(string routeCode, string opCode)
{
object obj = this.GetRoute2Operation(routeCode, opCode);
if (obj != null && obj is ICSROUTE2OP)
{
//_standardRouteInUsage usageCheck = new _standardRouteInUsage(obj as ICSROUTE2OP, this.DataProvider);
//return !usageCheck.Check();
}
else
{
//ExceptionManager.Raise(this.GetType(), "Error_Argument_Null");
}
return false;
}
public object GetRoute2Operation(string routeCode, string opCode)
{
try
{
var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.OPID == opCode && a.ROUTEID == routeCode);
return line;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomSearch(typeof(ICSROUTE2OP), new object[] { routeCode, opCode });
}
//根据产品途程工序代码获取工序
public object[] QueryCurrentRoute2Operation(string itemCode, string routeCode, string opCode)
{
try
{
var resline = DataProvider.ICSITEMROUTE2OP.Where(p=>p.ITEMCODE==itemCode&&p.ROUTECODE==routeCode&&p.OPCODE==opCode);
return resline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(
// typeof(ICSITEM2ROUTE),
// new SQLCondition(
// string.Format(" select {0} from TBLITEMROUTE2OP where itemcode = '{1}' and routecode = '{2}' and opcode = '{3}'" + " and WorkPoint ='" + AppConfig.WorkPointCode + "'",
// DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSITEM2ROUTE)), itemCode, routeCode, opCode)));
}
#region ICSROUTE --> ICSOP
///
/// ** 功能描述: 由RouteCode获得ICSOP
///
/// RouteCode,精确查询
/// ICSOP数组
public object[] GetOperationByRouteCode(string routeCode)
{
string sql = string.Format("select * from ICSOP where OPCODE in ( select OPCODE from ICSROUTE2OP where ROUTECODE='{0}')", routeCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
ICSOP[] entity = new ICSOP[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["ID"].ToString() );
entity[i] = line;
i++;
}
return entity;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP where OPCODE in ( select OPCODE from TBLROUTE2OP where ROUTECODE='{1}')", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode)));
}
///
/// ** 功能描述: 由RouteCode获得属于ICSROUTE的ICSOP的数量
///
/// RouteCode,精确查询
/// OPCODE,模糊查询
/// ICSOP的数量
public int GetSelectedOperationByRouteCodeCount(string routeCode, string oPCode)
{
string sql = string.Format("select * from ICSROUTE2OP where ROUTECODE ='{0}' and OPCODE like '{1}%'", routeCode, oPCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
ICSROUTE2OP[] entity = new ICSROUTE2OP[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == dr["ROUTEID"].ToString() && a.OPID == dr["OPID"].ToString());
entity[i] = line;
i++;
}
return entity.Length;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLROUTE2OP where ROUTECODE ='{0}' and OPCODE like '{1}%'", routeCode, oPCode)));
}
///
/// ** 功能描述: 由RouteCode获得属于ICSROUTE的ICSOP,分页
///
/// RouteCode,精确查询
/// OPCODE,模糊查询
/// 开始行数
/// 结束行数
/// ICSOP数组
public object[] GetSelectedOperationByRouteCode(string routeCode, string oPCode)
{
string sql = string.Format("select * from ICSOP where OPCODE in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
ICSOP[] entity = new ICSOP[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
entity[i] = line;
i++;
}
return entity;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSOP),
// new PagerCondition(string.Format("select {0} from TBLOP where OPCODE in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{1}') and OPCODE like '{2}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode, oPCode), "OPCODE", inclusive, exclusive));
}
///
/// ** 功能描述: 由RouteCode获得不属于ICSROUTE的ICSOP的数量
///
/// RouteCode,精确查询
/// OPCODE,模糊查询
/// ICSOP的数量
public int GetUnselectedOperationByRouteCodeCount(string routeCode, string oPCode)
{
string sql = string.Format("select * from ICSOP where OPCODE not in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
ICSOP[] entity = new ICSOP[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
entity[i] = line;
i++;
}
return entity.Length;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLOP where OPCODE not in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode)));
}
///
/// ** 功能描述: 由RouteCode获得不属于ICSROUTE的ICSOP,分页
///
/// RouteCode,精确查询
/// OPCODE,模糊查询
/// 开始行数
/// 结束行数
/// ICSOP数组
public object[] GetUnselectedOperationByRouteCode(string routeCode, string oPCode, int inclusive, int exclusive)
{
string sql = string.Format("select * from ICSOP where OPCODE not in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
ICSOP[] entity = new ICSOP[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
entity[i] = line;
i++;
}
return entity;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSOP),
//new PagerCondition(string.Format("select {0} from TBLOP where OPCODE not in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{1}') and OPCODE like '{2}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode, oPCode), "OPCODE", inclusive, exclusive));
}
///
/// ** 功能描述: 由RouteCode获得属于ICSROUTE的OperationOfRoute,分页
///
/// RouteCode,精确查询
/// OPCODE,模糊查询
/// 开始行数
/// 结束行数
/// OperationOfRoute数组
public object[] GetSelectedOperationOfRouteByRouteCode(string routeCode, string opCode)
{
string sql = string.Format("select {0}, ICSROUTE2OP.OPSEQ, ICSROUTE2OP.ROUTECODE from ICSOP a,ICSROUTE2OP b where ICSOP.OPCODE = ICSROUTE2OP.OPCODE and ICSROUTE2OP.ROUTECODE='{1}' and a.WORKPOINT='" + AppConfig.WorkPointCode + "' and b.WORKPOINT='" + AppConfig.WorkPointCode + "' and ICSROUTE2OP.OPCODE like '{2}%'", "ICSROUTE2OP.OPCODE,ICSOP.OPDESC,ICSOP.OPCOLLECTION,ICSROUTE2OP.OPCONTROL,ICSROUTE2OP.MUSERName,ICSROUTE2OP.MTIME,ICSROUTE2OP.EAttribute1", routeCode, opCode);
DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
Object[] entity = new Object[dt.Rows.Count];
try
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
Object[] obj = new Object[dt.Columns.Count];
for (int m = 0; m < dt.Columns.Count; m++)
{
obj[m] = dr[m];
}
entity[i]=obj;
i++;
}
return entity;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(FormOperationOfRouteModel), new PagerCondition(string.Format("select {0}, TBLROUTE2OP.OPSEQ, TBLROUTE2OP.ROUTECODE from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLROUTE2OP.OPCODE like '{2}%'", "TBLROUTE2OP.OPCODE,TBLOP.OPDESC,TBLOP.OPCOLLECTION,TBLROUTE2OP.OPCONTROL,TBLROUTE2OP.MUSER,TBLROUTE2OP.MDATE,TBLROUTE2OP.MTIME,TBLROUTE2OP.EAttribute1", routeCode, opCode), "TBLROUTE2OP.OPSEQ", inclusive, exclusive));
}
#endregion
#endregion
#region ICSOP2RES
public ICSOP2RES CreateNewOperation2Resource()
{
return new ICSOP2RES();
}
public void AddAndUpdateOperation2Resource(ICSOP2RES operation2Resource)
{
try
{
bool isNew = false;
var line = DataProvider.ICSOP2RES.SingleOrDefault(a => a.RESID == operation2Resource.RESID && a.OPID == operation2Resource.OPID);
if (line == null)
{
isNew = true;
line = new ICSOP2RES();
line.OPID = operation2Resource.OPID;
line.RESID = operation2Resource.RESID;
}
line.RESCODE = operation2Resource.RESCODE;
line.OPCODE = operation2Resource.OPCODE;
line.RESSEQ = operation2Resource.RESSEQ;
line.MUSER = operation2Resource.MUSER;
line.MUSERName = operation2Resource.MUSERName;
line.MTIME = operation2Resource.MTIME;
line.WorkPoint = operation2Resource.WorkPoint;
line.EATTRIBUTE1 = operation2Resource.EATTRIBUTE1;
if (isNew) DataProvider.ICSOP2RES.InsertOnSubmit(line);
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//this._helper.AddDomainObject(operation2Resource);
}
public void AddOperation2Resource(ICSOP2RES[] operation2Resources)
{
try
{
foreach (ICSOP2RES operation2Res in operation2Resources)
{
bool isNew = false;
var line = DataProvider.ICSOP2RES.SingleOrDefault(a => a.RESID == operation2Res.RESID && a.OPID == operation2Res.OPID);
if (line == null)
{
isNew = true;
line = new ICSOP2RES();
line.OPID = operation2Res.OPID;
line.RESID = operation2Res.RESID;
}
line.RESCODE = operation2Res.RESCODE;
line.OPCODE = operation2Res.OPCODE;
line.RESSEQ = operation2Res.RESSEQ;
line.MUSER = operation2Res.MUSER;
line.MUSERName = operation2Res.MUSERName;
line.MTIME = operation2Res.MTIME;
line.WorkPoint = operation2Res.WorkPoint;
line.EATTRIBUTE1 = operation2Res.EATTRIBUTE1;
if (isNew) DataProvider.ICSOP2RES.InsertOnSubmit(line);
}
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//this._helper.AddDomainObject(operation2Resources);
}
//public void UpdateOperation2Resource(ICSOP2RES operation2Resource)
//{
// this._helper.UpdateDomainObject(operation2Resource);
//}
public void DeleteOperation2Resource(ICSOP2RES operation2Resource)
{
try
{
var lines = DataProvider.ICSOP2RES.Where(a => a.OPID == operation2Resource.OPID && a.RESID == operation2Resource.RESID);
DataProvider.ICSOP2RES.DeleteAllOnSubmit(lines);
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
//this._helper.DeleteDomainObject(operation2Resource);
}
public void DeleteOperation2Resource(ICSOP2RES[] operation2Resources)
{
try
{
for (int i = 0; i < operation2Resources.Length;i++ )
{
var lines = DataProvider.ICSOP2RES.Where(a => a.OPID == operation2Resources[i].OPID && a.RESID == operation2Resources[i].RESID);
DataProvider.ICSOP2RES.DeleteAllOnSubmit(lines);
}
DataProvider.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
}
public object GetOperation2Resource(string operationCode, string resourceCode)
{
try
{
var resline = DataProvider.ICSOP2RES.SingleOrDefault(p => p.OPCODE == operationCode && p.RESCODE == resourceCode && p.WorkPoint == AppConfig.WorkPointCode);
return resline;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
#region ICSOP --> ICSRES
///
/// ** 功能描述: 由OPCODE获得ICSRES
///
/// OPCODE,精确查询
/// ICSRES数组
public object[] GetResourceByOperationCode(string oPCode)
{
try
{
var opline=from a in DataProvider.ICSRES
where (from b in DataProvider.ICSOP2RES
where b.OPCODE==oPCode && b.WorkPoint==AppConfig.WorkPointCode
select b.RESCODE).Contains(a.RESCODE) && a.WorkPoint==AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode)));
}
public ICSOP2RES GetOperationByResource(string rescode)
{
try
{
var opline = from a in DataProvider.ICSOP2RES
where a.RESCODE == rescode && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToList()[0];
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// ** 功能描述:由ICSSS获得ICSRES
///
/// ICSSS,精确查询
/// ICSRES 数组
public object[] GetResourceByStepSequenceCode(string StepSequenceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where (from b in DataProvider.ICSSS
where b.SSCODE == StepSequenceCode && b.WorkPoint == AppConfig.WorkPointCode
select b.ID).Contains(a.SSID) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), StepSequenceCode)));
}
///
/// ** 功能描述: 由OPCODE获得属于ICSOP的ICSRES的数量
///
/// OPCODE,精确查询
/// ResourceCode,模糊查询
/// ICSRES的数量
public int GetSelectedResourceByOperationCodeCount(string oPCode, string resourceCode)
{
var opline = from a in DataProvider.ICSOP2RES
join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
where a.OPCODE == oPCode && b.RESCODE.StartsWith(resourceCode)
&& a.WorkPoint == AppConfig.WorkPointCode
select new { a, b };
return opline.ToList().Count;
//return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, resourceCode)));
}
public int GetResourceByOpCodeAndDctCodeCount(string oPCode, string dctCode)
{
var opline = from a in DataProvider.ICSOP2RES
join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
where a.OPCODE == oPCode && b.DCTCODE.StartsWith(dctCode) && a.WorkPoint == AppConfig.WorkPointCode
select new { a, b };
return opline.ToList().Count;
//return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, dctCode)));
}
///
/// ** 功能描述: 由OPCODE获得属于ICSOP的ICSRES,分页
///
/// OPCODE,精确查询
/// ResourceCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSRES数组
public object[] GetSelectedResourceByOperationCode(string oPCode, string resourceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where (from b in DataProvider.ICSOP2RES
where b.OPCODE == oPCode && b.WorkPoint == AppConfig.WorkPointCode
select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES),
// new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode, resourceCode), "RESCODE", inclusive, exclusive));
}
public object[] GetResourceByDCTCode(string dctCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where a.DCTCODE==dctCode && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES),
//new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), dctCode), "dctcode", inclusive, exclusive));
}
///
/// ** 功能描述: 由OPCODE获得不属于ICSOP的ICSRES的数量
///
/// OPCODE,精确查询
/// ResourceCode,模糊查询
/// ICSRES的数量
public int GetUnselectedResourceByOperationCodeCount(string oPCode, string resourceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where !(from b in DataProvider.ICSOP2RES
where 1 == 1 && b.WorkPoint == AppConfig.WorkPointCode
select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(oPCode) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToList().Count;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, resourceCode)));
}
public int GetUnselectedResourceByDCTCodeCount(string dctCode, string resourceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where !a.DCTCODE.ToUpper().StartsWith(dctCode) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToList().Count;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, dctCode, resourceCode)));
}
public int GetResourceByresAndDCTCodeCount(string resourceCode, string dctCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where a.DCTCODE == resourceCode && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
select a;
return opline.ToList().Count;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, dctCode, resourceCode)));
}
///
/// ** 功能描述: 由OPCODE获得不属于ICSOP的ICSRES,分页
///
/// OPCODE,精确查询
/// ResourceCode,模糊查询
/// 开始行数
/// 结束行数
/// ICSRES数组
public object[] GetUnselectedResourceByOperationCode(string oPCode, string resourceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where !(from b in DataProvider.ICSOP2RES
where b.RESCODE.ToUpper().StartsWith(resourceCode)&& b.OPCODE==oPCode && b.WorkPoint==AppConfig.WorkPointCode
select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ICSRES),
// new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode, resourceCode), "RESCODE", inclusive, exclusive));
}
public object[] GetUnselectedResourceByDCTCode(string dctCode, string resourceCode)
{
try
{
var opline = from a in DataProvider.ICSRES
where !(from b in DataProvider.ICSRES
where b.DCTCODE.ToUpper().StartsWith(dctCode) && b.WorkPoint==AppConfig.WorkPointCode
select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode
select a;
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//return this.DataProvider.CustomQuery(typeof(ICSRES),
// new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), dctCode, resourceCode), "RESCODE", inclusive, exclusive));
}
///
/// ** 功能描述: 由OPCODE获得属于ICSOP的ResourceOfOperation,分页
///
/// OPCODE,精确查询
/// ResourceCode,模糊查询
/// 开始行数
/// 结束行数
/// ResourceOfOperation数组
public object[] GetSelectedResourceOfOperationByOperationCode(string opCode, string resCode, int inclusive, int exclusive)
{
try
{
var opline = from a in DataProvider.ICSOP2RES
join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
where a.OPCODE == opCode && b.RESCODE.StartsWith(resCode) //&& a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
select new {b};
DataProvider.Connection.Close();
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// return this.DataProvider.CustomQuery(typeof(ResourceOfOperation), new PagerCondition(string.Format(sql,
// DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSRES)), opCode, resCode), "TBLOP2RES.RESSEQ", inclusive, exclusive));
}
///
/// ** 功能描述:由moCode获得ICSRES
///
/// moCode,精确查询
/// ICSRES 数组
public object[] GetResourceByMoCode(string MOCode)
{
try
{
var opline = from a in DataProvider.ICSRES
join b in DataProvider.ICSOP2RES on a.RESCODE equals b.RESCODE
join c in DataProvider.ICSOP on b.OPCODE equals c.OPCODE
join d in DataProvider.ICSROUTE2OP on c.OPCODE equals d.OPCODE
join e in DataProvider.ICSROUTE on d.ROUTECODE equals e.ROUTECODE
join f in DataProvider.ICSMO2ROUTE on e.ROUTECODE equals f.ROUTECODE
join g in DataProvider.ICSMO on f.MOCODE equals g.MOCODE
where g.MOCODE == MOCode && a.WorkPoint == AppConfig.WorkPointCode &&
b.WorkPoint == AppConfig.WorkPointCode && c.WorkPoint == AppConfig.WorkPointCode &&
d.WORKPOINT == AppConfig.WorkPointCode && f.WorkPoint == AppConfig.WorkPointCode && g.WorkPoint == AppConfig.WorkPointCode
orderby a.RESCODE
select new { a,b,c,d,e,f,g};
return opline.ToArray();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//if (GlobalVariables.CurrentOrganizations.GetSQLConditionWithoutColumnName().Length > 0)
//{
// sql += " and TBLRES.ORGID in (" + GlobalVariables.CurrentOrganizations.GetSQLConditionWithoutColumnName() + ")";
//}
//return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, MOCode)));
}
///
/// ** 功能描述:由moCode获得SMTResource
///
/// moCode,精确查询
/// ICSRES 数组
//public object[] GetSMTResourceByMoCode(string MOCode)
//{
//
// string sql = "";
// sql += "select ICSRES.* from ICSRES where RESCODE IN (select RESCODE from ICSSMTRESBOM where MOCODE = '{0}') ";
// sql += " and WorkPoint ='" + AppConfig.WorkPointCode + "'";
// sql += " ORDER BY TBLRES.rescode ";
// // End Added
// return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, MOCode)));
//}
#endregion
#endregion
#region ICSROUTE --> ICSOP --> ICSRES
///
/// ** 功能描述: 由ICSROUTE和ICSRES获得ICSOP
///
/// RouteCode
/// ResourceCode
///
public object GetOperationByRouteAndResource(string routeCode, string resourceCode)
{
try
{
var resline = from a in DataProvider.ICSOP
join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
join c in DataProvider.ICSOP2RES on a.OPCODE equals c.OPCODE
where b.ROUTECODE == routeCode && c.RESCODE == resourceCode
select a;
return resline.ToList()[0] ;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
// object[] objs = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format(@"select {0} from TBLOP,TBLROUTE2OP,TBLOP2RES where TBLOP.OPCODE = TBLOP2RES.OPCODE and
// TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLOP2RES.RESCODE='{2}'",
// DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode, resourceCode)));
//if (objs != null && objs.Length > 0)
//{
// return objs[0];
//}
//return null;
}
///
/// ** 功能描述: 获得ICSROUTE的第一个ICSOP
///
/// RouteCode
///
public object GetFirstOperationOfRoute(string routeCode)
{
var resline = from a in DataProvider.ICSOP
join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
where b.ROUTECODE == routeCode && a.WorkPoint == AppConfig.WorkPointCode && b.WORKPOINT == AppConfig.WorkPointCode
orderby b.OPSEQ
select a.OPCODE;
try
{
if (resline != null && resline.ToList().Count > 0)
{
return resline.ToList()[0];
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//object[] objs = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format(@"select routeCode from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' order by TBLROUTE2OP.OPSEQ",
// DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode)));
}
///
/// ** 功能描述: 获得ICSROUTE的下一个ICSOP
///
/// RouteCode
/// 当前OP
///
public object GetNextOperationOfRoute(string routeCode, string currentOperationCode)
{
try
{
var opline = from a in DataProvider.ICSOP
join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
where b.ROUTECODE == routeCode && (from c in DataProvider.ICSROUTE2OP
where c.ROUTECODE == routeCode && c.OPCODE == currentOperationCode && c.WORKPOINT == AppConfig.WorkPointCode
select c.OPSEQ).Equals(b.OPSEQ-1) && a.OPCODE == currentOperationCode && a.WorkPoint == AppConfig.WorkPointCode
select new {
a
};
if (opline != null && opline.ToList().Count > 0)
{
return opline.ToList()[0];
}
else
{
return null;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//operations = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLROUTE2OP.OPSEQ > {2} order by TBLROUTE2OP.OPSEQ",
// DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode, ((ICSROUTE2OP)relation).OPSEQ)));
}
#region this is for cs
public ICSITEMROUTE2OP GetMORouteFirstOperation(string moCode, string routeCode)
{
ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode );
string selectSql = " select * "
+ " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and "
+ " opseq = (select min(opseq) from ICSITEMROUTE2OP"
+ " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '" + AppConfig.WorkPointCode + "')";
List list = this.DataProvider.ExecuteQuery(selectSql).ToList();
if (list == null || list.Count ==1)
{
throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, routeCode));
}
return (ICSITEMROUTE2OP)list[0];
}
public ICSITEMROUTE2OP GetMORouteNextOperation(string moCode, string routeCode, string opCode)
{
ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode);
if (mo == null)
{
throw new Exception("$Error_MONotExisted");
}
string selectSql = " select * "
+ " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' "
+ " and workpoint = '"+AppConfig.WorkPointCode+"'"
+ " and opseq > (select opseq from ICSITEMROUTE2OP"
+ " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and opcode='" + opCode + "' and workpoint = '" + AppConfig.WorkPointCode + "' order by opseq";
List list = this.DataProvider.ExecuteQuery(selectSql).ToList();
if (list == null || list.Count == 1)
{
throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, routeCode));
}
return (ICSITEMROUTE2OP)list[0];
}
public bool OperationIsRouteLastOperation(string moCode, string routeCode, string OpCode)
{
ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode);
if (mo == null)
{
throw new Exception("$Error_MONotExisted");
}
string selectSql = " select count(*) "
+ " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '"+AppConfig.WorkPointCode+"'"
+ " and opseq = (select max(opseq) from ICSITEMROUTE2OP"
+ " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '" + AppConfig.WorkPointCode + "') and opcode='" + OpCode + "'";
var query = this.DataProvider.ExecuteQuery(selectSql);
int iCount = query.First();
if (iCount > 0)
{
return true;
}
return false;
}
#endregion
#endregion
#region Time Period
///
/// ** 功能描述: 获得Shift下所有的TimePeriod
/// ** 修 改:
/// ** 日 期:
///
/// ShiftCode
/// TimePeriod数组
public List GetTimePeriodByShiftCode(string shiftCode)
{
string sqlStr = "select * from ICSLTP where SHIFTCODE='"+shiftCode+"' order by TPSEQ";
return this.DataProvider.ExecuteQuery(sqlStr).ToList();
}
public object GetTimePeriod(string timePeriodCode)
{
return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode);
}
///
/// 获取TimePeriod开始时间
///
///
///
public int GetTimePeriodBeginTime(string timePeriodCode)
{
return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode).TPBTIME;
}
///
/// 获取TimePeriod结束时间
///
///
///
public int GetTimePeriodEndTime(string timePeriodCode)
{
return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode).TPETIME;
}
public int GetShiftDay(ICSTP currentTimePeriod, DateTime currentDateTime)
{
int shiftDay = FormatHelper.TODateInt(currentDateTime);
if (currentTimePeriod != null)
{
if (currentTimePeriod.ISOVERDATE == FormatHelper.TRUE_STRING)
{
if (currentTimePeriod.TPBTIME < currentTimePeriod.TPETIME)
{
shiftDay = FormatHelper.TODateInt(currentDateTime.AddDays(-1));
}
else if (FormatHelper.TOTimeInt(currentDateTime) < currentTimePeriod.TPBTIME)
{
shiftDay = FormatHelper.TODateInt(currentDateTime.AddDays(-1));
}
}
}
return shiftDay;
}
public int GetShiftDayBySS(ICSSS stepSequence, DateTime currentDateTime)
{
int returnValue = FormatHelper.TODateInt(currentDateTime);
if (stepSequence != null)
{
ICSTP tp = (ICSTP)GetTimePeriod(stepSequence.SHIFTTYPEID, FormatHelper.TOTimeInt(currentDateTime));
if (tp != null)
{
returnValue = GetShiftDay(tp, currentDateTime);
}
}
return returnValue;
}
public ICSSHIFT GetShift(string shiftTypeId, int time)
{
ICSSHIFT returnValue = null;
ICSTP tp = (ICSTP)GetTimePeriod(shiftTypeId, time);
if (tp != null)
{
returnValue = this.DataProvider.ICSSHIFT.SingleOrDefault(a => a.ID == tp.SHIFTID);
}
return returnValue;
}
///
/// ** 功能描述: 根据给定时间及ShiftType 获得唯一的 TimePeriod
/// ** 作 者: Jane Shu
/// ** 日 期: 2005-03-08
/// ** 修 改: Jane Shu
/// ** 日 期: 2005-07-25
///
///
///
///
public object GetTimePeriod(string shiftTypeId, int time)
{
string sqlStr = @"select * from icstp where shifttypeid= '"+shiftTypeId+@"' and (
(tpbtime < tpetime and " +time+@" between tpbtime and tpetime )
or (tpbtime > tpetime and " + time + @" < tpbtime and " + time + @" + 240000 between tpbtime and tpetime + 240000)
or (tpbtime > tpetime and " + time + @" > tpbtime and " + time + @" between tpbtime and tpetime + 240000) )";
List < ICSTP > list = this.DataProvider.ExecuteQuery(sqlStr).ToList();
if (list != null && list.Count > 0)
{
return list[0];
}
return null;
}
#endregion
}
}