Beispiel #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");
        }