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.
319 lines
12 KiB
319 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using System.Data.Linq;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
|
|
public class ICSMO2UserDAL
|
|
{
|
|
|
|
#region 增加修改
|
|
public static void AddAndEdit(List<FormICSMO2UserUIModel> MO2UserInfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSMO2UserUIModel MO2UserInfo in MO2UserInfoList)
|
|
{
|
|
|
|
bool isNew = false;
|
|
var line = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == MO2UserInfo.LOTNO && a.OPCODE == MO2UserInfo.OPCODE);
|
|
//var line = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == MO2UserInfo.LOTNO );
|
|
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSMO2User();
|
|
line.ID = AppConfig.GetGuid();
|
|
}
|
|
line.MOCODE = MO2UserInfo.MOCODE;
|
|
line.MOSEQ = MO2UserInfo.MOSEQ;
|
|
line.LOTNO = MO2UserInfo.LOTNO;
|
|
line.SEGCODE = MO2UserInfo.SEGCODE;
|
|
line.RouteCode = MO2UserInfo.RouteCode;
|
|
line.OPCODE = MO2UserInfo.OPCODE;
|
|
line.USERCODE = MO2UserInfo.USERCODE;
|
|
line.USERName = MO2UserInfo.USERName;
|
|
line.EQPCode = MO2UserInfo.EQPCode;
|
|
line.EQPName = MO2UserInfo.EQPName;
|
|
line.MUSER = MO2UserInfo.MUSER;
|
|
line.MUSERName = MO2UserInfo.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(MO2UserInfo.MTIME);
|
|
line.WorkPoint = MO2UserInfo.WorkPoint;
|
|
line.EATTRIBUTE1 = MO2UserInfo.EATTRIBUTE1;
|
|
line.StartPlanDate = MO2UserInfo.StartPlanDate;
|
|
line.EndPlanDate = MO2UserInfo.EndPlanDate;
|
|
if (MO2UserInfo.PRLineID == "False" || MO2UserInfo.PRLineID == "0" || string.IsNullOrWhiteSpace(MO2UserInfo.PRLineID))
|
|
{
|
|
line.PRLineID = null;
|
|
}
|
|
else
|
|
{
|
|
line.PRLineID = MO2UserInfo.PRLineID;
|
|
}
|
|
|
|
if (isNew)
|
|
db.ICSMO2User.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#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.ICSMO2User.Where(a => codeList.Contains(a.ID));
|
|
db.ICSMO2User.DeleteAllOnSubmit(lines);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 取消下发
|
|
public static void cancelSend(List<string> codeList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lotonwip = db.ICSLOTONWIP.Where(a => codeList.Contains(a.LOTNO));
|
|
if (lotonwip != null && lotonwip.ToList().Count > 0)
|
|
{
|
|
throw new Exception("批次已经采集,不可取消派工");
|
|
}
|
|
var lines = db.ICSMO2User.Where(a => codeList.Contains(a.LOTNO));
|
|
db.ICSMO2User.DeleteAllOnSubmit(lines);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void cancelSend(List<string> lotno1, List<string> opcode1, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
|
|
var lotonwip1 = (from a in db.ICSLOTONWIP
|
|
where lotno1.Contains(a.LOTNO)
|
|
select a).ToList();
|
|
var lotonwip = lotonwip1.Where(a => opcode1.Contains(a.OPCODE));
|
|
if (lotonwip != null && lotonwip.ToList().Count > 0)
|
|
{
|
|
throw new Exception("批次已经采集,不可取消派工");
|
|
}
|
|
List<ICSMO2User> list = new List<ICSMO2User>();
|
|
for (int i = 0; i < lotno1.Count(); i++)
|
|
{
|
|
ICSMO2User[] b = (from a in db.ICSMO2User
|
|
where a.LOTNO.Equals(lotno1[i]) && a.OPCODE.Equals(opcode1[i])
|
|
select a).ToArray();
|
|
list.Add(b[0]);
|
|
}
|
|
|
|
db.ICSMO2User.DeleteAllOnSubmit(list);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void cancelSendWW(List<string> lotno1, List<string> opcode1, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
|
|
|
|
List<ICSMO2User> list = new List<ICSMO2User>();
|
|
for (int i = 0; i < lotno1.Count(); i++)
|
|
{
|
|
ICSMO2User[] b = (from a in db.ICSMO2User
|
|
where a.LOTNO.Equals(lotno1[i]) && a.OPCODE.Equals(opcode1[i])
|
|
select a).ToArray();
|
|
list.Add(b[0]);
|
|
|
|
if (db.ICSLOTONWIP.Where(a => a.MOCODE == b[0].MOCODE && a.OPCODE == b[0].OPCODE).FirstOrDefault() != null)
|
|
{
|
|
throw new Exception("批次:" + b[0].LOTNO + ",工序:" + b[0].OPCODE + "已经采集,不可取消派工");
|
|
}
|
|
}
|
|
var pos = list.Where(a => string.IsNullOrEmpty(a.PRLineID) && a.PRLineID.Contains("-")).Select(a => a.PRLineID.Substring(0, a.PRLineID.LastIndexOf('-'))).Distinct().ToList();//去重后的po单
|
|
|
|
foreach (var po in pos)
|
|
{
|
|
var mo2users = db.ICSMO2User.Where(a => a.PRLineID.Contains(po)).ToList();
|
|
|
|
foreach (var mo2user in mo2users)
|
|
{
|
|
|
|
var lotonwip = db.ICSLOTONWIP.Where(a => a.LOTNO == mo2user.LOTNO && a.OPCODE == mo2user.OPCODE).FirstOrDefault();
|
|
if (lotonwip != null)
|
|
{
|
|
throw new Exception("批次:" + lotonwip.LOTNO + ",工序:" + lotonwip.OPCODE + "已经采集,不可取消派工");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
db.ICSPO_PoMain.DeleteAllOnSubmit(db.ICSPO_PoMain.Where(a => pos.Contains(a.POCode)));//删除mes采购单
|
|
db.ICSMO2User.DeleteAllOnSubmit(list);//删除派工记录
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 写入日志
|
|
public static void WriteLogFile(string input, string txtName)
|
|
{
|
|
try
|
|
{
|
|
string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString() + "\\Log\\";
|
|
if (!System.IO.Directory.Exists(logAdress))
|
|
{
|
|
System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
|
|
}
|
|
|
|
string adress = logAdress + txtName;
|
|
if (!System.IO.Directory.Exists(adress))
|
|
{
|
|
System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
|
|
}
|
|
|
|
|
|
// string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
|
|
/**/
|
|
///指定日志文件的目录
|
|
string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
|
|
/**/
|
|
///定义文件信息对象
|
|
|
|
FileInfo finfo = new FileInfo(fname);
|
|
|
|
if (!finfo.Exists)
|
|
{
|
|
FileStream fs;
|
|
fs = File.Create(fname);
|
|
fs.Close();
|
|
finfo = new FileInfo(fname);
|
|
}
|
|
|
|
/**/
|
|
///判断文件是否存在以及是否大于2K
|
|
if (finfo.Length > 1024 * 1024 * 10)
|
|
{
|
|
/**/
|
|
///文件超过10MB则重命名
|
|
File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
|
|
/**/
|
|
///删除该文件
|
|
//finfo.Delete();
|
|
}
|
|
//finfo.AppendText();
|
|
/**/
|
|
///创建只写文件流
|
|
|
|
using (FileStream fs = finfo.OpenWrite())
|
|
{
|
|
/**/
|
|
///根据上面创建的文件流创建写数据流
|
|
StreamWriter w = new StreamWriter(fs);
|
|
|
|
/**/
|
|
///设置写数据流的起始位置为文件流的末尾
|
|
w.BaseStream.Seek(0, SeekOrigin.End);
|
|
|
|
w.WriteLine("*****************Start*****************");
|
|
w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
/**/
|
|
///写入当前系统时间并换行
|
|
|
|
/**/
|
|
///写入日志内容并换行
|
|
w.WriteLine(input);
|
|
|
|
/**/
|
|
///写入------------------------------------“并换行
|
|
w.WriteLine("------------------END------------------------");
|
|
|
|
/**/
|
|
///清空缓冲区内容,并把缓冲区内容写入基础流
|
|
w.Flush();
|
|
|
|
/**/
|
|
///关闭写数据流
|
|
w.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{ throw ex; }
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|