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.
|
|
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 ICSItemOPPriceDAL { #region 新增和修改
public static void Add(List<ICSItemOPPrice> InfoList, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { foreach (ICSItemOPPrice info in InfoList) { bool isNew = false; var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ID == info.ID); if (line == null) { isNew = true; line = new ICSItemOPPrice(); } //var codes = db.ICSItemOPPrice.Where(a => a.ITEMCODE == info.ITEMCODE && a.OPCODE == info.OPCODE && a.ID != info.ID);
//if (codes.ToList().Count > 0)
//{
// throw new Exception("已存在相同产品工序的价格");
//}
line.ID = info.ID; //var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ITEMCODE == info.ITEMCODE && a.OPCODE == info.OPCODE);
//if (line == null)
//{
// isNew = true;
// line = new ICSItemOPPrice();
// line.ID = AppConfig.GetGuid();
//}
line.ITEMCODE = info.ITEMCODE; line.OPCODE = info.OPCODE; line.Price = Convert.ToDecimal(info.Price); line.MUSER = AppConfig.UserId; line.MUSERName = AppConfig.UserName; line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss") ; line.WorkPoint = AppConfig.WorkPointCode; line.EATTRIBUTE1 = info.EATTRIBUTE1;
if (isNew) db.ICSItemOPPrice.InsertOnSubmit(line); db.SubmitChanges(); }
db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion
#region 通过ID查询
public static DataTable searchInfoByID(string ID, string dsconn) {
string sql = @"SELECT
b.INVNAME AS ItemName, c.OPDESC, a.ID, a.ITEMCODE, a.OPCODE, a.Price, a.WorkPoint, a.MUSER, a.MUSERName, a.MTIME, a.EATTRIBUTE1
FROM ICSItemOPPrice a left join ICSINVENTORY b on a.ITEMCODE=b.INVCODE left join ICSOP c on a.OPCODE=C.OPCODE where a.ID='{0}'";
sql = string.Format(sql, ID); DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
return dt; } #endregion
#region 是否存在
public static bool IsIncluding(string ItemCode, string OPCode, string eqptype, string dsconn) {
FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ITEMCODE == ItemCode && a.OPCODE == OPCode); if (line == null) return true; else return false; } catch (Exception ex) { db.Transaction.Rollback(); 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.ICSItemOPPrice.Where(a => codeList.Contains(a.ID)); db.ICSItemOPPrice.DeleteAllOnSubmit(lines); db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw ex; }
} #endregion
} }
|