コード例 #1
0
ファイル: DormBusiness.cs プロジェクト: happybai/DormManage
        public String DormInfoSimpleExchange(String firstDormNum, String firstBedNum, String secondDormNum, String secondBedNum)
        {
            int firstBedNumber = Convert.ToInt16(firstBedNum);
            int secondBedNumber = Convert.ToInt16(secondBedNum);
            var list =
                Db.DormInfoSimples.Where(
                    u =>
                        (u.Dorm.Num == firstDormNum && u.BedNum == firstBedNumber) ||
                        (u.Dorm.Num == secondDormNum && u.BedNum == secondBedNumber)).ToList();
            //List<DormInfoSimple> list = diso.Find("from DormInfoSimple where (Dorm.Num=? and BedNum=?) or (Dorm.Num=? and BedNum=?)", new object[] { firstDormNum, firstBedNum, secondDormNum, secondBedNum });
            if (list.Count > 1)
            {
                var temp = new DormInfoSimple();
                temp.ClassInfo = list[0].ClassInfo;
                temp.IsDormLeader = list[0].IsDormLeader;
                temp.IsPartyMember = list[0].IsPartyMember;
                temp.Post = list[0].Post;
                temp.StudentName = list[0].StudentName;
                temp.StudentSex = list[0].StudentSex;
                temp.TeacherName = list[0].TeacherName;

                list[0].ClassInfo = list[1].ClassInfo;
                list[0].IsDormLeader = list[1].IsDormLeader;
                list[0].IsPartyMember = list[1].IsPartyMember;
                list[0].Post = list[1].Post;
                list[0].StudentName = list[1].StudentName;
                list[0].StudentSex = list[1].StudentSex;
                list[0].TeacherName = list[1].TeacherName;

                list[1].ClassInfo = temp.ClassInfo;
                list[1].IsDormLeader = temp.IsDormLeader;
                list[1].IsPartyMember = temp.IsPartyMember;
                list[1].Post = temp.Post;
                list[1].StudentName = temp.StudentName;
                list[1].StudentSex = temp.StudentSex;
                list[1].TeacherName = temp.TeacherName;
                //int tempId = list[0].Id;
                //int tempBedId = list[0].BedNum;
                //DormInfo tempDormInfo = list[0].Dorm;
                //list[0].Id = list[1].Id;
                //list[0].BedNum = list[1].BedNum;
                //list[0].Dorm = list[1].Dorm;
                //list[1].Id = tempId;
                //list[1].BedNum = tempBedId;
                //list[1].Dorm = tempDormInfo;

                Db.SaveChanges();
                return "修改成功";
            }
            else
            {
                return "交换寝室失败,请检查寝室和床号是否正确";
            }
        }
コード例 #2
0
ファイル: AnalysisExcel.cs プロジェクト: happybai/DormManage
 public virtual List<DormInfoSimple> AnalysisExcelToDormInfoSimple(string filePath, ref string errorInfo)
 {
     var dataTable = NPOIHelper.Import(filePath);
     var resultList = new List<DormInfoSimple>();
     for (var i = 0; i < dataTable.Rows.Count; i++)
     {
         var classInfo = dataTable.Rows[i][0].ToString();
         var name = dataTable.Rows[i][1].ToString();
         var sex = dataTable.Rows[i][2].ToString();
         var bedNum = dataTable.Rows[i][3].ToString();
         var dormNum = dataTable.Rows[i][4].ToString();
         var teacher = dataTable.Rows[i][5].ToString();
         var isLeader = dataTable.Rows[i][6].ToString();
         var post = dataTable.Rows[i][7].ToString();
         var isParty = dataTable.Rows[i][8].ToString();
         var dormInfo = DormInfoDao.GetDormInfoByNum(dormNum);
         DormInfoSimple dormInfoSimple;
         if (dormInfo == null)
         {
             errorInfo += "第" + (i + 1) + "条数据寝室不存在";
             return null;
         }
         if (!String.IsNullOrEmpty(classInfo))
         {
             var teacherNum = TeacherDao.GetTeacherNumByName(teacher);
             if (ClassInfoDao.AddClass(classInfo, teacherNum))
             {
                 dormInfoSimple = new DormInfoSimple
                 {
                     ClassInfo = ClassInfoDao.GetClassInfoByAbbreviation(classInfo),
                     StudentName = name,
                     StudentSex = sex,
                     BedNum = Convert.ToInt16(bedNum),
                     Dorm = dormInfo,
                     TeacherName = teacher,
                     IsDormLeader = isLeader,
                     Post = post,
                     IsPartyMember = isParty
                 };
             }
             else
             {
                 errorInfo += "第" + (i + 1) + "条数据班级不存在";
                 return null;
             }
         }
         else
         {
             dormInfoSimple = new DormInfoSimple
             {
                 ClassInfo = null,
                 StudentName = "",
                 StudentSex = "",
                 BedNum = Convert.ToInt16(bedNum),
                 Dorm = dormInfo,
                 TeacherName = "",
                 IsDormLeader = "",
                 Post = "",
                 IsPartyMember = ""
             };
         }
         resultList.Add(dormInfoSimple);
     }
     return resultList;
 }
コード例 #3
0
ファイル: DormBusiness.cs プロジェクト: happybai/DormManage
        public String WholeDormExchange(String firstDormNum, String secondDormNum)
        {
            var first = Db.DormInfoSimples.Where(u => u.Dorm.Num == firstDormNum).ToList();
            var second = Db.DormInfoSimples.Where(u => u.Dorm.Num == secondDormNum).ToList();

            //List<DormInfoSimple> firstList = diso.Find("from DormInfoSimple where Dorm.Num=?", new object[] { FirstDormNum });
            //List<DormInfoSimple> secondList = diso.Find("from DormInfoSimple where Dorm.Num=?", new object[] { SecondDormNum });
            if (first.Count == second.Count)
            {
                for (int i = 0; i < first.Count; i++)
                {
                    Db.Entry(first[i]).State = EntityState.Modified;
                    Db.Entry(second[i]).State = EntityState.Modified;
                    var temp = new DormInfoSimple();
                    temp.ClassInfo = first[i].ClassInfo;
                    temp.IsDormLeader = first[i].IsDormLeader;
                    temp.IsPartyMember = first[i].IsPartyMember;
                    temp.Post = first[i].Post;
                    temp.StudentName = first[i].StudentName;
                    temp.StudentSex = first[i].StudentSex;
                    temp.TeacherName = first[i].TeacherName;

                    first[i].ClassInfo = second[i].ClassInfo;
                    first[i].IsDormLeader = second[i].IsDormLeader;
                    first[i].IsPartyMember = second[i].IsPartyMember;
                    first[i].Post = second[i].Post;
                    first[i].StudentName = second[i].StudentName;
                    first[i].StudentSex = second[i].StudentSex;
                    first[i].TeacherName = second[i].TeacherName;

                    second[i].ClassInfo = temp.ClassInfo;
                    second[i].IsDormLeader = temp.IsDormLeader;
                    second[i].IsPartyMember = temp.IsPartyMember;
                    second[i].Post = temp.Post;
                    second[i].StudentName = temp.StudentName;
                    second[i].StudentSex = temp.StudentSex;
                    second[i].TeacherName = temp.TeacherName;

                    //int tempId = first[i].Id;
                    //int tempBedId = first[i].BedNum;
                    //DormInfo tempDormInfo = first[i].Dorm;
                    //first[i].Id = second[i].Id;
                    //first[i].BedNum = second[i].BedNum;
                    //first[i].Dorm = second[i].Dorm;

                    //second[i].Id = tempId;
                    //second[i].BedNum = tempBedId;
                    //second[i].Dorm = tempDormInfo;
                }
            }
            else
            {
                return "寝室人数不等,不能交换";
            }

            Db.SaveChanges();
            //List<DormInfoSimple> list = new List<DormInfoSimple>();
            //list.AddRange(firstList);
            //list.AddRange(secondList);
            //diso.SaveOrUpdateAll(list);
            return "修改成功";
        }