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 ICSOPHoursDAL { #region 新增和修改List public static string AddList(List InfoList, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { string str = ""; string ID = ""; foreach (ICSHoursCost info in InfoList) { if (ID != info.Organization + info.CostCenter + info.Month) { ID = info.Organization + info.CostCenter + info.Month; var lines = db.ICSHoursCost.Where(a => a.Organization + a.CostCenter + a.Month == ID); ICSHoursCost first = lines.FirstOrDefault(); if (first != null && first.Status) { throw new Exception("已审核不能修改!"); } db.ICSHoursCost.DeleteAllOnSubmit(lines); } ICSHoursCost line = new ICSHoursCost(); line.ID = AppConfig.GetGuid(); line.Status = false; line.Organization = info.Organization; line.CostCenter = info.CostCenter; line.Month = info.Month; line.Hours = info.Hours; line.Type = info.Type; line.Cost = info.Cost; line.MUSER = info.MUSER; line.MUSERNAME = info.MUSERNAME; line.MTIME = info.MTIME; line.WorkPoint = info.WorkPoint; line.EATTRIBUTE1 = info.EATTRIBUTE1; db.ICSHoursCost.InsertOnSubmit(line); db.SubmitChanges(); } db.Transaction.Commit(); return str; } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion #region 审核 public static void checkInfo(List codeList,bool status, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var lines = db.ICSHoursCost.Where(a => codeList.Contains(a.Organization + a.CostCenter+a.Month)); foreach (var line in lines) { if (line.Status && status) throw new Exception("选中行已审核,不能再次审核!"); else if (!line.Status && !status) throw new Exception("选中行未审核,不能弃审!"); line.Status = status; } db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion } }