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.
108 lines
3.4 KiB
108 lines
3.4 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 IcsAGVLocationDAL
|
|
{
|
|
#region 新增和修改
|
|
public static void Add(List<IcsAGVLocation> InfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (IcsAGVLocation info in InfoList)
|
|
{
|
|
bool isNew = false;
|
|
var line = db.IcsAGVLocation.SingleOrDefault(a => a.ID == info.ID);
|
|
var exists = db.IcsAGVLocation.Where(a => a.ID != info.ID && a.LocationCode == info.LocationCode).FirstOrDefault();
|
|
if (exists != null)
|
|
throw new Exception("点位编码:"+info.LocationCode+"已存在!");
|
|
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new IcsAGVLocation();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.LocationCode = info.LocationCode;
|
|
}
|
|
|
|
|
|
line.LocationName = info.LocationName;
|
|
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.IcsAGVLocation.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 通过ID查询
|
|
public static IcsAGVLocation searchInfoByID(string ID, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
try {
|
|
var rtn=db.IcsAGVLocation.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.IcsAGVLocation.Where(a => codeList.Contains(a.ID));
|
|
db.IcsAGVLocation.DeleteAllOnSubmit(lines);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|