public static bool AreSame(VolunteerResult a, VolunteerResult b)
 {
     if (a == null && b == null)
     {
         return(true);
     }
     if ((a == null && b != null) || (a != null && b == null))
     {
         return(false);
     }
     else if (a.ErrorString == b.ErrorString && a.Succeeded == b.Succeeded)
     {
         if (a.ErrorVolunteerNum == b.ErrorVolunteerNum)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
        public VolunteerResult EditVolunteer(Volunteer a, int num, string name = DEFAULTSTRING, string c = DEFAULTSTRING, string mobile = DEFAULTSTRING, string room = DEFAULTSTRING, string email = DEFAULTSTRING)
        {
            if (num == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.EmptyId));
            }
            var v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);

            if (v != null)
            {
                v.StudentNum = num;
                v.Name       = (name == DEFAULTSTRING) ? v.Name : name;
                v.Class      = (c == DEFAULTSTRING) ? v.Class : c;
                v.Mobile     = (mobile == DEFAULTSTRING) ? v.Mobile : mobile;
                v.Room       = (room == DEFAULTSTRING) ? v.Room : room;
                v.Email      = (email == DEFAULTSTRING) ? v.Email : email;
                Save();
                Volunteer target = a;
                Volunteer edited = FindVolunteer(num);
                if (edited.Mobile != target.Mobile || edited.Email != target.Email || edited.Room != target.Room)
                {
                    bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1} (现学号:{2},姓名:{3}) 的志愿者基本信息.", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditContact, true);
                }
                else
                {
                    bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1} (现学号:{2},姓名:{3}) 的志愿者基本信息.", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditVolunteer, true);
                }
                return(VolunteerResult.Success());
            }
            else
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.NonExistingVolunteer));
            }
        }
Exemple #3
0
        public VolunteerResult EditVolunteer(Volunteer a, Volunteer b)
        {
            if (a == null || a.StudentNum == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.NonExistingVolunteer));
            }
            var v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);

            v.StudentNum = b.StudentNum;
            v.Name       = b.Name;
            v.Class      = b.Class;
            v.Mobile     = b.Mobile;
            v.Room       = b.Room;
            v.Email      = b.Email;
            Save();
            v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);
            Volunteer target = v;
            Volunteer edited = v;

            //Volunteer edited = FindVolunteer(b.StudentNum);
            if (edited.Mobile != target.Mobile || edited.Email != target.Email || edited.Room != target.Room)//日志字符串改成“修改联系方式”,现在联系方式:手机 电子邮件 寝室
            {
                bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1}的志愿者基本信息.现学号:{2},姓名:{3}", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditContact, true);
            }
            else
            {
                bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1}的志愿者基本信息.现学号:{2},姓名:{3}", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditVolunteer, true);
            }
            return(VolunteerResult.Success());
        }
Exemple #4
0
        public VolunteerResult AddVolunteer(int num, string name = DEFAULTSTRING, string c = DEFAULTSTRING, string mobile = DEFAULTSTRING, string room = DEFAULTSTRING, string email = DEFAULTSTRING, string skill = DEFAULTSTRING)
        {
            if (num == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.EmptyId));
            }
            var v = new Volunteer
            {
                StudentNum       = num,
                Name             = name,
                Class            = c,
                Mobile           = mobile,
                Room             = room,
                Email            = email,
                BlackListRecords = new List <BlackListRecord>(),
                CreditRecords    = new List <CreditRecord>(),
                ProjectCount     = 0,
                Project          = new List <Project>(),
                Skill            = skill,
                Score            = new Volunteer.VScore(),
                TargetedBy       = new List <LogRecord>()
            };

            return(AddVolunteer(v));
        }
        public static VolunteerResult Success()
        {
            var result = new VolunteerResult
            {
                _succeeded         = true,
                _errors            = { },
                _errorstring       = "",
                _errorvolunteernum = 0
            };

            return(result);
        }
        public static VolunteerResult Error(string errors, int num = 0)
        {
            if (errors.Count() == 0)
            {
                errors = "未提供错误信息";
            }
            var result = new VolunteerResult
            {
                _succeeded         = false,
                _errors            = new string[] { errors },
                _errorvolunteernum = num,
                _errorstring       = string.Join(",", errors)
            };

            return(result);
        }
        /// <summary>
        /// 使用字符串数组作为错误信息的方法
        /// </summary>
        /// <param name="errors"></param>
        /// <returns></returns>
        public static VolunteerResult Error(params string[] errors)
        {
            if (errors.Count() == 0)
            {
                errors = new string[] { "未提供错误信息" };
            }
            var result = new VolunteerResult
            {
                _succeeded         = false,
                _errors            = errors,
                _errorstring       = string.Join(",", errors),
                _errorvolunteernum = 0
            };

            return(result);
        }
Exemple #8
0
 public void ConfirmAddInBatch(List <Volunteer> temp, Project pro)
 {
     foreach (var item in temp)
     {
         var vol = database.Volunteers.SingleOrDefault(o => o.StudentNum == item.StudentNum);
         if (vol.Name == item.Name && vol.Class == item.Class && vol.Email == item.Email && vol.Mobile == item.Mobile)
         {
             vol.Project.Add(pro);
             continue;
         }
         else
         if (vol == null)
         {
             if (item.StudentNum > 205000000 || item.StudentNum < 201100000)
             {
                 errorList.Add("下面这些学号是不合法的,未予以导入,确认没有输错吗:" + item.StudentNum);
             }
             else
             {
                 VolunteerResult result = vhelper.AddVolunteer(item);
                 if (result.Succeeded == false)
                 {
                     informingMessage.Add("出现错误,错误信息[:" + result.ErrorString + "] 错误相关志愿者学号:[" + result.ErrorVolunteerNum + "]");
                 }
             }
         }
         else//重复且信息冲突
         {
             string inform = String.Format(@"个人信息更改的志愿者 - 学号:{0}
                                             原姓名:{1}                            现姓名{2}
                                             原电话:{3}                            现电话{4}
                                             原邮箱:{5}                            现邮箱{6}
                                             原宿舍:{7}                            现宿舍{8}
                                             原班级:{9}                            现班级{10}",
                                           item.StudentNum, vol.Name, item.Name, vol.Mobile, item.Mobile, vol.Email, item.Email, vol.Room, item.Room, vol.Class, item.Class);
             informingMessage.Add(inform);
             ChangedVols.Add(item);//冲突的话 只是给一个提示
         }
     }
     informingMessage.Add("导入成功");
 }
Exemple #9
0
 public void determChanges(params int[] StuNums)
 {
     foreach (var item in StuNums)
     {
         var nv = ChangedVols.SingleOrDefault(o => o.StudentNum == item);
         if (nv != null)
         {
             Volunteer       ov     = vhelper.FindVolunteer(item);
             VolunteerResult result = vhelper.EditVolunteer(ov, nv);
             if (result.Succeeded == false)
             {
                 errorList.Add("出现错误,错误信息:[" + result.ErrorString + "] 错误相关志愿者学号:[" + result.ErrorVolunteerNum + "]");
             }
         }
         else
         {
             errorList.Add("学号:" + item + "的志愿者不存在于信息变动的志愿者列表中");
         }
     }
     ChangedVols.Clear();
 }
Exemple #10
0
 public VolunteerResult AddVolunteer(Volunteer v)
 {
     if (v == null)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.NullVolunteerObject));
     }
     if (v.StudentNum == 0)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.EmptyId));
     }
     if (database.Volunteers.Where(o => o.StudentNum == v.StudentNum).Count() != 0)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.SameIdVolunteerExisted, v.StudentNum));
     }
     else
     {
         int stunum = v.StudentNum;
         v.Mobile           = v.Mobile == DEFAULTSTRING ? DEFAULTSTRING : v.Mobile;
         v.Room             = v.Room == DEFAULTSTRING ? DEFAULTSTRING : v.Room;
         v.Name             = v.Name == DEFAULTSTRING ? DEFAULTSTRING : v.Name;
         v.Class            = v.Class == DEFAULTSTRING ? DEFAULTSTRING : v.Class;
         v.Email            = v.Email == DEFAULTSTRING ? DEFAULTSTRING : v.Email; //加入几个列表的初始化.
         v.BlackListRecords = new List <BlackListRecord>();
         v.CreditRecords    = new List <CreditRecord>();
         v.ProjectCount     = 0;
         v.Project          = new List <Project>();
         v.Skill            = v.Skill;
         v.Score            = new Volunteer.VScore();
         v.TargetedBy       = new List <LogRecord>();
         database.Volunteers.Add(v);
         Save();
         Volunteer target    = FindVolunteer(stunum);
         bool      logresult = VolunteerOperationSucceeded(string.Format("已添加学号:[{0}],姓名:[{1}] 的志愿者条目进入数据库.", target.StudentNum, target.Name), target, LogType.EditContact, true);
         return(VolunteerResult.Success());
     }
 }
Exemple #11
0
 public VolunteerResult DeleteVolunteer(Volunteer a)
 {
     if (a != null)
     {
         int                    deletedVolunteerStuNum = a.StudentNum;
         string                 deletedVolunteerName   = a.Name;
         var                    volunteer = FindVolunteer(a.StudentNum);
         List <LogRecord>       loglist   = logger.FindLogRecordByTargetVolunteer(volunteer).ToList();
         List <BlackListRecord> blacklist = database.BlackListRecords.Where(b => b.Volunteer.UID == volunteer.UID).ToList();
         //foreach (var log in loglist)
         //{
         //    log.TargetVolunteer = null;
         //}
         //Save();//等待被注释
         database.Volunteers.Remove(volunteer);
         Save();
         bool logresult = VolunteerOperationSucceeded(string.Format("删除学号:{0},姓名:{1}的志愿者条目.", deletedVolunteerStuNum, deletedVolunteerName), null, LogType.DeleteVolunteer);
         return(VolunteerResult.Success());
     }
     else
     {
         return(VolunteerResult.Error(VolunteerResult.DeleteVolunteerErrorEnum.NonExistingVolunteer));
     }
 }