示例#1
0
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="regs"></param>
        /// <param name="site"></param>
        /// <param name="macs"></param>
        /// <param name="sens"></param>
        /// <param name="date"></param>
        /// <param name="conclusion"></param>
        /// <param name="inserted"></param>
        /// <returns></returns>
        public string AddRecordDAL(string regs, string site, string macs, string sens, string date, string conclusion, List <Guid> gList)
        {
            DateTime        inserted = DateTime.Now;          //获取当前系统的时间
            List <Pictures> picList  = new List <Pictures>(); //存放图片信息

            using (var db = new MachineFailureEntities())
            {
                using (var tran = db.Database.BeginTransaction()) //开启事物
                {
                    try
                    {
                        //查询记录
                        var record = db.Records.FirstOrDefault(e => sens.Equals(e.FaultTypeID.ToString()) && date.Equals(e.Timestamp) && conclusion.Equals(e.Conclusion));
                        if (record != null)  //判断插入的记录是否已经存在
                        {
                            return("exsit");
                        }
                        //插入记录
                        var recordID = Guid.NewGuid();  //生成记录的ID
                        db.Records.Add(new Records()
                        {
                            RecordID    = recordID,
                            FaultTypeID = Guid.Parse(sens),
                            Conclusion  = conclusion,
                            Timestamp   = date,
                            Inserted    = inserted
                        });

                        //插入图片
                        foreach (var g in gList)
                        {
                            picList.Add(new Pictures()
                            {
                                PictureID = g, RecordID = recordID
                            });
                        }
                        db.Pictures.AddRange(picList);

                        //更新故障类型的时间
                        UpdateTime.UpdateFaultTypes(db, Guid.Parse(sens), inserted);
                        //更新机组时间
                        UpdateTime.UpdateMachines(db, Guid.Parse(macs), inserted);
                        //更新站点时间
                        UpdateTime.UpdateSites(db, Guid.Parse(site), inserted);
                        //更新大区的时间
                        UpdateTime.UpdateRegionals(db, Guid.Parse(regs), inserted);

                        db.SaveChanges();
                        tran.Commit();
                    }
                    catch (Exception e)
                    {
                        tran.Rollback();
                        Debug.WriteLine(e);
                        return("false");
                    }
                }
            }
            return("true");
        }
示例#2
0
 /// <summary>
 /// 插入故障类型
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="addr"></param>
 /// <returns></returns>
 public string AddFaultTypeDAL(Guid macID, Guid siteID, Guid regsID, string name)
 {
     using (var db = new MachineFailureEntities())
     {
         using (var tran = db.Database.BeginTransaction())
         {
             try
             {
                 //插入之前先查询是否存在
                 var ft = db.FaultTypes.FirstOrDefault(e => name.Equals(e.Name) && macID.Equals(e.MachineID));
                 if (ft != null)
                 {
                     return("This name already exsit");
                 }
                 //开始插入
                 var date = DateTime.Now;
                 db.FaultTypes.Add(new FaultTypes()
                 {
                     FaultTypeID = Guid.NewGuid(), Name = name, MachineID = macID, Updated = date
                 });
                 UpdateTime.UpdateMachines(db, macID, date);
                 UpdateTime.UpdateSites(db, siteID, date);
                 UpdateTime.UpdateRegionals(db, regsID, date);
                 db.SaveChanges();
                 tran.Commit();
             }
             catch
             {
                 tran.Rollback();
                 return("Add failed");
             }
         }
     }
     return("Add success");
 }