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.
107 lines
3.8 KiB
107 lines
3.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Frame.APP.Entity;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class IcsEqpWithLocationDAL
|
|
{
|
|
#region 新增和修改
|
|
public static void Add(List<IcsEqpWithLocation> InfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (IcsEqpWithLocation info in InfoList)
|
|
{
|
|
bool isNew = false;
|
|
var line = db.IcsEqpWithLocation.SingleOrDefault(a => a.ID == info.ID);
|
|
var exists = db.IcsEqpWithLocation.Where(a => a.ID != info.ID && a.LocationCode == info.LocationCode&&a.EqpCode==info.EqpCode).FirstOrDefault();
|
|
if (exists != null)
|
|
throw new Exception("设备:"+info.EqpCode+"已和点位:"+info.LocationCode+"关联!");
|
|
//var LocatonExists = db.IcsEqpWithLocation.Where(a => a.ID != info.ID && a.LocationCode == info.LocationCode).FirstOrDefault();
|
|
//if (LocatonExists != null)
|
|
// throw new Exception("点位:" + info.LocationCode + "已被设备:"+ LocatonExists.EqpCode+"关联!");
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new IcsEqpWithLocation();
|
|
line.ID = AppConfig.GetGuid();
|
|
}
|
|
line.LocationCode = info.LocationCode;
|
|
line.EqpCode = info.EqpCode;
|
|
line.Workpoint = AppConfig.WorkPointCode;
|
|
line.Muser = AppConfig.UserCode;
|
|
line.MuserName = AppConfig.UserName;
|
|
line.Mtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
if (isNew)
|
|
db.IcsEqpWithLocation.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 通过ID查询
|
|
public static IcsEqpWithLocation searchInfoByID(string ID, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
try {
|
|
var rtn=db.IcsEqpWithLocation.FirstOrDefault(a => a.ID == ID);
|
|
if (rtn == null)
|
|
throw new Exception("获取信息失败!");
|
|
else
|
|
return rtn;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 删除
|
|
public static void deleteInfo(List<string> codeList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.IcsEqpWithLocation.Where(a => codeList.Contains(a.ID));
|
|
db.IcsEqpWithLocation.DeleteAllOnSubmit(lines);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|