Esempio n. 1
0
 public int ReportForRepair(string DormNum, string goods, string why, DateTime date)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Repair repair = new Repair();
                 repair.DormNum    = DormNum;
                 repair.CommitDate = date;
                 repair.Goods      = goods;
                 db.Repair.Add(repair);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(1);//添加成功
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 2
0
 public int DeleteStudent(string Id)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Student dbstudent = db.Student.Find(Id);
                 if (dbstudent != null)
                 {
                     Dorm dorm = db.Dorm.Find(dbstudent.DormNum);
                     dorm.UsedNum--;
                     dorm.AllowNum++;
                     db.Student.Remove(dbstudent);
                     db.SaveChanges();
                     return(1); //完成
                 }
                 return(0);     //用户不存在
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 3
0
 public int ChangeDorm(string StudentId, string newDormNum, string why)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Student    student = db.Student.Find(StudentId);
                 ChangeDorm dorm    = new ChangeDorm();
                 if (db.Dorm.Find(newDormNum).UsedNum != 0)
                 {
                     dorm.OldDormNum = student.DormNum;
                     dorm.StudentId  = StudentId;
                     dorm.Begindate  = DateTime.Now;
                     dorm.Why        = why;
                     dorm.NewDormNum = newDormNum;
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(1); //申请成功
                 }
                 return(0);     //当前寝室床位不足,请更换寝室
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 4
0
 public int DealRepair(int Id, decimal money, string ReasonsForUncompletion)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Repair repair = db.Repair.Find(Id);
                 if (repair != null && repair.ResolutionDate == null)
                 {
                     repair.ResolutionDate         = DateTime.Now;
                     repair.Money                  = money;
                     repair.ReasonsForUncompletion = ReasonsForUncompletion;
                     return(1); //维修完成
                 }
                 return(0);     //该维修已处理
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 5
0
 public int DeleteStaff(string Id)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Staff dbstaff = db.Staff.Find(Id);
                 if (dbstaff != null)
                 {
                     db.Staff.Remove(dbstaff);
                     db.SaveChanges();
                     return(1); //完成
                 }
                 return(0);     //用户不存在
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 6
0
 public int DeleteDorm(String Id)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Dorm dorm = db.Dorm.Find(Id);
                 if (dorm != null)
                 {
                     if (dorm.UsedNum == 0)
                     {
                         db.Dorm.Remove(dorm);
                         db.SaveChanges();
                         return(1);//完成
                     }
                     else
                     {
                         return(3);//寝室有学生使用,请更换学生寝室
                     }
                 }
                 return(0);//寝室号不存在
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 7
0
 public int EditDorm(Dorm dorm)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Dorm dbdorm = db.Dorm.Find(dorm.DormNum);
                 if (dbdorm == null)
                 {
                     db.Dorm.Add(dorm);
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(1);//寝室不存在 新增
                 }
                 else
                 {
                     dbdorm.DormNum  = dorm.DormNum;
                     dbdorm.AllowNum = dorm.AllowNum;
                     dbdorm.LouNum   = dorm.LouNum;
                     dbdorm.UsedNum  = dorm.UsedNum;
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(0);//寝室号已存在,修改
                 }
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 8
0
 public int DealChangeDorm(int Id, bool flag, string why)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 ChangeDorm changeDorm = db.ChangeDorm.Find(Id);
                 if (changeDorm.AdminOpinion != null)
                 {
                     return(0);                                //管理员已处理,无需处理
                 }
                 changeDorm.AgreeDate    = DateTime.Now;
                 changeDorm.AdminOpinion = flag;
                 changeDorm.Why          = why;
                 return(1);//处理完成
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 9
0
 public int EditStaff(Staff staff)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Staff dbstaff = db.Staff.Find(staff.Code);
                 if (dbstaff == null)
                 {
                     db.Staff.Add(staff);
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(1);//用户不存在 添加
                 }
                 else
                 {
                     dbstaff.Name        = staff.Name;
                     dbstaff.Birth       = staff.Birth;
                     dbstaff.Managenment = staff.Managenment;
                     dbstaff.Password    = staff.Password;
                     dbstaff.Phone       = staff.Phone;
                     dbstaff.Position    = staff.Position;
                     dbstaff.Sex         = staff.Sex;
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(0);//用户已存在 修改
                 }
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }
Esempio n. 10
0
 public int EditStudent(Student student)
 {
     using (var db = new SDMSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Student dbstudent = db.Student.Find(student.Code);
                 if (dbstudent == null)
                 {
                     db.Student.Add(student);
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(1);//用户不存在 新增成功
                 }
                 else
                 {
                     dbstudent.Class    = student.Class;
                     dbstudent.DormNum  = student.DormNum;
                     dbstudent.Name     = student.Name;
                     dbstudent.Password = student.Password;
                     dbstudent.Phone    = student.Phone;
                     dbstudent.Sex      = student.Sex;
                     db.SaveChanges();
                     dbContextTransaction.Commit();
                     return(0);//学生以存在,修改
                 }
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(2);//数据库添加异常
             }
         }
     }
 }