private void OnTraineeChanged(OperationType operation, TraineeModel trainee) { switch (operation) { case OperationType.Add: if (trainee.IsNew) //新建学员 { string traineeID; _dal.Add(trainee, out traineeID); trainee.TraineeID = traineeID; } _dal.AddTraineeForBlock(trainee.CurrentBlockID, trainee.TraineeID); OverdueChangedEvent?.Invoke(); break; case OperationType.Update: _dal.UpdateForBlock(trainee, _currentClassID); if (trainee.CurrentBlockID != _currentClassID) { operation = OperationType.Delete; } break; } TraineeChangedEvent?.Invoke(operation, trainee); }
public FuzzyTraineeViewModel(TraineeModel trainee, ClassType classType) { TraineeClassName = classType == ClassType.Regular ? string.Empty : trainee.RegularClassName; TraineeName = trainee.TraineeName; _trainee = trainee; ChangeColor(false); }
public int AddTrainee(TraineeModel m, string userId) { var t = new Trainee { Firstname = m.Firstname, Surname = m.Surname, DateOfBirth = m.DateOfBirth, BeNumber = m.BeNumber, Avatar = m.Avatar }; var ret = _dbContext.Trainees.Add(t); //middle table var exist = from x in _dbContext.UserTrainees where x.UserId == userId && x.TraineeId == ret.Id select x; if (!exist.Any()) { var ut = new UserTrainee { UserId = userId, TraineeId = ret.Id }; _dbContext.UserTrainees.Add(ut); } _dbContext.SaveChanges(); return(ret.Id); }
/// <summary> /// 学员信息已更改,更新界面,更新数据库 /// </summary> /// <param name="operation"></param> /// <param name="trainee"></param> public void OnTraineeChanged(OperationType operation, TraineeModel trainee) { if (operation == OperationType.Update) { _dal.Update(trainee); if (trainee.RegularClassID != _currentClassID) { operation = OperationType.Delete; } OverdueChangedEvent?.Invoke(); } else if (operation == OperationType.Add) { if (trainee.IsNew) { string traineeID; _dal.Add(trainee, out traineeID); trainee.TraineeID = traineeID; } else { _dal.AddTraineeForRegular(trainee.RegularClassID, trainee.TraineeID); } _trainees.Add(trainee); OverdueChangedEvent?.Invoke(); } TraineeChangedEvent?.Invoke(operation, trainee); }
protected virtual void OnTraineeSelected(TraineeModel trainee) { TraineeName = trainee.TraineeName; Trainee.TraineeName = TraineeName; Trainee.TraineeID = trainee.TraineeID; Trainee.InitialRemainRegularCount = trainee.InitialRemainRegularCount; }
public TraineeForCallingViewModel(TraineeModel trainee, int callingState = -1) { TraineeID = trainee.TraineeIDForShown; TraineeName = trainee.TraineeName; CallingState = callingState; _trainee = trainee; }
public ActionResult TraineeCreate(int id = 0) { TarineeList tarineeList = new TarineeList(); if (id > 0) { tarineeList = traineeRepository.GetTarineeListById(id); } TraineeModel traineeModel = new TraineeModel { ID = tarineeList.ID, AverageInspection = tarineeList.AverageInspection, InspectionFirst = tarineeList.InspectionFirst, InspectionSecond = tarineeList.InspectionSecond, InspectionThird = tarineeList.InspectionThird, TraineesThird = tarineeList.TraineesThird, TraineesSecond = tarineeList.TraineesSecond, Trade = tarineeList.Trade, TraineesFirst = tarineeList.TraineesFirst, UnitFirst = tarineeList.UnitFirst, UnitSecond = tarineeList.UnitSecond, UnitThird = tarineeList.UnitThird }; return(View(traineeModel)); }
public ActionResult Edit(int id, TraineeModel model) { var result = _traineeService.Update(id, model); SetUserUpdate(id, DateTime.MinValue.Utc()); //The return status check is performed in trainee script return(Json(result)); }
public ActionResult Add(TraineeModel m) { using (var repo = new Repository()) { repo.AddTrainee(m, User.Identity.GetUserId()); } return(RedirectToAction("Index")); }
/// <summary> /// 在列表中添加学员 /// </summary> /// <param name="trainee"></param> public void AddTrainee(TraineeModel trainee) { _trinees.Add(trainee); if (!string.IsNullOrEmpty(trainee.CurrentBlockID)) { _blockTrainnesCannotBeChosen.Add(trainee.TraineeID); } TraineeChangedEvent?.Invoke(); }
public ActionResult TDelete(int id = 0) { TraineeModel traineeModel = new TraineeModel(); if (id > 0) { traineeRepository.DeleteTarineeLists(id); } return(RedirectToAction("Index")); }
//public void Change(TraineeModel trainee) //{ // Render(trainee, isRegular); //} private void Render(TraineeModel trainee, bool isRegular) { _trainee = trainee; TraineeID = trainee.TraineeIDForShown; TraineeName = trainee.TraineeName; VisRemain = isRegular ? Visibility.Visible : Visibility.Hidden; RemainClass = trainee.RemainRegularCount.ToString(); RemainColor = trainee.RemainRegularCount > 0 ? GlobalVariables.IncomeColor : GlobalVariables.ExpenseColor; ChangeButtons(trainee.State); }
public ActionResult Create(TraineeModel model) { if (CurrentUser.UserRole == UserRole.Rackaz) { model.User.Area = CurrentUser.Area; } var result = _traineeService.Add(model); //The return status check is performed in Trainee Script.. return(Json(result)); }
private void OnOperateTrainee(OperationType operation, TraineeModel trainee) { if (operation == OperationType.Select) { foreach (TraineeViewModel item in Trainees.Where(t => t.TraineeID != trainee.TraineeIDForShown)) { item.ConvertToUnselected(); } return; } _bussiness.OperateTrainee(operation, trainee); }
public ActionResult AddTrainee(FormCollection model) { TraineeModel trainee = new TraineeModel { TraineeId = Convert.ToInt32(model["TraineeId"]), Name = model["Name"], Email = model["Email"], DateOfJoining = Convert.ToDateTime(model["DateOfJoining"]) }; traineeList.Add(trainee); return(View("ListTrainee")); }
public void GetRegularPresence(string traineeName, bool isCurrentTerm) { //get trainee info TraineeModel trainee = _currentTrainees.Where(t => t.TraineeName == traineeName).First(); List <NameCallingModel> callings = isCurrentTerm ? _calling.GetListForCurrentTerm(trainee.TraineeID) : _calling.GetListForPreviousTerm(trainee.TraineeID); _currentPresenceInfo = new PresenceInfo(); _currentPresenceInfo.FillPresence(callings, _regular, trainee.TraineeID); PresenceInfoChangedEvent?.Invoke(_currentPresenceInfo); }
public virtual void Enable(OperationType operation, TraineeModel trainee) { Trainee = trainee; Operation = operation; Title = (operation == OperationType.Add ? "增加" : "修改") + "学员"; IsClassEditable = operation == OperationType.Add ? false : true; TraineeName = trainee.TraineeName; IsPopupOpen = false; InitialRemain = operation == OperationType.Add ? "0" : trainee.InitialRemainRegularCount.ToString(); HideErr(); Vis = Visibility.Visible; }
public StatusModel TutorTraineeAdd(TutorModel tutor, TraineeModel trainee) { var status = new StatusModel(false, String.Empty); try { using (var unitOfWork = new UnitOfWork <BelibaHomaDBEntities>()) { //Retrieving Related Entities by using the repositories and GetById function (all but User which was not yet created) var traineeRepository = unitOfWork.GetRepository <ITraineeRepository>(); var _trainee = traineeRepository.GetByKey(trainee.UserId); var tutorRepository = unitOfWork.GetRepository <ITutorRepository>(); var _tutor = tutorRepository.GetByKey(tutor.UserId); TutorTraineeModel newModel = new TutorTraineeModel(); newModel.Status = TTStatus.UnApproved; //Mapping the model into TutorTrainee Entity var tutortraineeRepository = unitOfWork.GetRepository <ITutorTraineeRepository>(); var entity = newModel.MapTo <TutorTrainee>(); //Linking the Complexed entities to the retrieved ones entity.Tutor = _tutor; entity.TutorId = tutor.UserId; entity.Trainee = _trainee; entity.TraineeId = _trainee.UserId; //Finally Adding the entity to DB tutortraineeRepository.Add(entity); unitOfWork.SaveChanges(); //If we got here - Yay! :) status.Success = true; } } catch (Exception ex) { status.Message = String.Format("שגיאה במהלך הוספת קשר החונכות למסד"); LogService.Logger.Error(status.Message, ex); } return(status); }
/// <summary> /// 界面请求对学员进行编辑 /// </summary> /// <param name="operation"></param> /// <param name="trainee"></param> public void OperateTrainee(OperationType operation, TraineeModel trainee) { trainee = trainee ?? new TraineeModel(); trainee.CurrentBlockID = _currentClassID; if (operation == OperationType.Delete) { _dal.DeleteTraineeForBlock(trainee.CurrentBlockID, trainee.TraineeID); TraineeChangedEvent?.Invoke(OperationType.Delete, trainee); return; } if (operation == OperationType.Add) { if (string.IsNullOrEmpty(_currentClassID)) { return; } } TraineeOperation.Enable(operation, trainee); }
public bool UpdateForBlock(TraineeModel model, string oldBlockID) { int rowsAffected; SqlParameter[] parameters = { new SqlParameter("@TraineeID", SqlDbType.VarChar, 50), new SqlParameter("@TraineeName", SqlDbType.VarChar, 50), new SqlParameter("@NewBlockID", SqlDbType.VarChar, 50), new SqlParameter("@OldBlockID", SqlDbType.VarChar, 50), }; parameters[0].Value = model.TraineeID; parameters[1].Value = model.TraineeName; parameters[2].Value = model.CurrentBlockID; parameters[3].Value = oldBlockID; DbHelperSQL.RunProcedure("TraineeInfo_Update_Block_LK", parameters, out rowsAffected); return(true); }
public ActionResult TraineeCreate(TraineeModel traineeModel) { try { TarineeList tarineeList = new TarineeList { ID = traineeModel.ID, AverageInspection = traineeModel.AverageInspection, InspectionFirst = traineeModel.InspectionFirst, InspectionSecond = traineeModel.InspectionSecond, InspectionThird = traineeModel.InspectionThird, TraineesThird = traineeModel.TraineesThird, TraineesSecond = traineeModel.TraineesSecond, Trade = traineeModel.Trade, TraineesFirst = traineeModel.TraineesFirst, UnitFirst = traineeModel.UnitFirst, UnitSecond = traineeModel.UnitSecond, UnitThird = traineeModel.UnitThird }; if (ModelState.IsValid) { if (tarineeList.ID > 0) { traineeRepository.UpdateTarineeList(tarineeList); } else { traineeRepository.InsertTarineeList(tarineeList); } } else { return(View(tarineeList)); } return(RedirectToAction("Index")); } catch (Exception) { return(View(traineeModel)); } }
//public void GetTraineeNames() /// <summary> /// 界面请求对学员进行编辑 /// </summary> /// <param name="operation"></param> /// <param name="trainee"></param> public void OperateTrainee(OperationType operation, TraineeModel trainee) { if (operation == OperationType.Delete || operation == OperationType.Reverse) { DeleteOrReverseTrainee(operation, trainee); OverdueChangedEvent?.Invoke(); return; } if (operation == OperationType.Add) { if (string.IsNullOrEmpty(_currentClassID)) { return; } trainee = new TraineeModel(); trainee.RegularClassID = _currentClassID; } TraineeOperation.Enable(operation, trainee); }
public bool Update(TraineeModel model) { int rowsAffected; SqlParameter[] parameters = { new SqlParameter("@TraineeID", SqlDbType.VarChar, 50), new SqlParameter("@TraineeName", SqlDbType.VarChar, 50), new SqlParameter("@RegularClassID", SqlDbType.VarChar, 50), new SqlParameter("@InitialRemainRegularCount", SqlDbType.Int), new SqlParameter("@State", SqlDbType.Int) }; parameters[0].Value = model.TraineeID; parameters[1].Value = model.TraineeName; parameters[2].Value = model.RegularClassID; parameters[3].Value = model.InitialRemainRegularCount; parameters[4].Value = model.State; DbHelperSQL.RunProcedure("TraineeInfo_Update_Regular_LK", parameters, out rowsAffected); return(true); }
/// <summary> /// 删除学员 /// </summary> /// <param name="trainee"></param> private void DeleteOrReverseTrainee(OperationType operation, TraineeModel trainee) { if (operation == OperationType.Delete) { trainee.State++; } else if (operation == OperationType.Reverse) { trainee.State--; } _dal.Update(trainee); if (trainee.State == 2) {//彻底删除 TraineeChangedEvent?.Invoke(OperationType.Delete, trainee); } else {//暂时删除或者恢复正常 _trainees[_trainees.IndexOf(_trainees.Where(t => t.TraineeID == trainee.TraineeID).First())] = trainee; _trainees.Sort(); int newIndex = _trainees.IndexOf(trainee); TraineeChangedEvent?.Invoke(OperationType.Update, trainee, newIndex); } }
public bool Add(TraineeModel model, out string traineeID) { int rowsAffected; SqlParameter[] parameters = { new SqlParameter("@TraineeName", SqlDbType.VarChar, 20), new SqlParameter("@RegularClassID", SqlDbType.VarChar, 50), new SqlParameter("@RemainRegularCount", SqlDbType.Int), new SqlParameter("@InitialRemainRegularCount", SqlDbType.Int), new SqlParameter("@ID", SqlDbType.VarChar, 50) }; parameters[0].Value = model.TraineeName; parameters[1].Value = model.RegularClassID; parameters[2].Value = model.RemainRegularCount; parameters[3].Value = model.InitialRemainRegularCount; parameters[4].Direction = ParameterDirection.Output; DbHelperSQL.RunProcedure("TraineeInfo_ADD_LK", parameters, out rowsAffected); traineeID = parameters[4].Value.ToString(); return(true); }
public override void Enable(OperationType operation, TraineeModel trainee) { base.Enable(operation, trainee); SelectedClass = _regularClasses.RegularClassCollection.Where(c => c.ClassID == trainee.RegularClassID).First().ClassName; }
/// <summary> /// Add new Trainee /// </summary> /// <param name="model"></param> /// <returns></returns> public StatusModel Add(TraineeModel model) { var status = new StatusModel(false, String.Empty); try { using (var unitOfWork = new UnitOfWork <BelibaHomaDBEntities>()) { //Updating the User Role in the model model.User.UserRole = UserRole.Trainee; //Retrieving Related Entities by using the repositories and GetById function (all but User which was not yet created) var academicInstitutionRepository = unitOfWork.GetRepository <IAcademicInstitutionRepository>(); var academicInstitution = academicInstitutionRepository.GetByKey(model.AcademicInstitution.Id); var academicMajorRepository = unitOfWork.GetRepository <IAcademicMajorRepository>(); var academicMajor = academicMajorRepository.GetByKey(model.AcademicMajor.Id); //academic major 1 & 2 can be null var academicMajor1 = new AcademicMajor(); academicMajor1 = model.AcademicMajor1.Id != 0 ? academicMajorRepository.GetByKey(model.AcademicMajor1.Id) : null; var academicMajor2 = new AcademicMajor(); academicMajor2 = model.AcademicMajor2.Id != 0 ? academicMajorRepository.GetByKey(model.AcademicMajor2.Id) : null; var userRepository = unitOfWork.GetRepository <IUserRepository>(); //Running some server side validations if (model.User.IdNumber.Length != 9) { status.Message = "מספר תעודת הזהות צריך להכיל בדיוק 9 ספרות"; throw new System.ArgumentException(status.Message, "model"); } if (model.Birthday > DateTime.Now.AddYears(-15)) { status.Message = "תאריך הלידה של החניך צריך להיות לפחות לפני 15 שנים"; throw new System.ArgumentException(status.Message, "model"); } if (academicInstitution.InstitutionType == (int)InstitutionType.Mechina && model.AcademicYear != 0 && model.SemesterNumber != 0) { status.Message = "החניך במכינה, שנת הלימודים ומספר הסמסטר צריכים להיות 0"; throw new System.ArgumentException(status.Message, "model"); } if (academicInstitution.InstitutionType != (int)InstitutionType.Mechina && (model.AcademicYear == 0 || model.SemesterNumber == 0)) { status.Message = "אם החניך איננו ממוסד מסוג מכינה, על מספר הסמסטר והשנה האקדמית להיות שונים מ-0"; throw new System.ArgumentException(status.Message, "model"); } if (model.User.Area != null && academicInstitution.Area != (int)model.User.Area) { status.Message = "המוסד האקדמי של החונך נמצא באזור פעילות שונה מהאזור שהוזן לחונך"; throw new System.ArgumentException(status.Message, "model"); } //Adding the User Model to the DB (By using the Add function in UserService) var userStatus = _userService.Add(model.User); if (userStatus.Success) { //Get the new user entity from DB (also linked to Trainee) var user = userRepository.GetByKey(userStatus.Data); model.Pasam = 0; model.LastPasamCalculation = user.CreationTime; //Updating "not input" fields in Trainee model model.TutorHours = 0; model.TutorHoursBonding = 0; model.DroppedOut = false; //Mapping the model into Trainee Entity var traineeRepository = unitOfWork.GetRepository <ITraineeRepository>(); var entity = model.MapTo <Trainee>(); //Linking the Complexed entities to the retrieved ones entity.AcademicInstitution = academicInstitution; entity.AcademicMajor = academicMajor; entity.AcademicMajor1 = academicMajor1; entity.AcademicMajor2 = academicMajor2; entity.User = user; entity.AcademicInstitutionId = academicInstitution.Id; entity.AcademicMajorId = academicMajor.Id; if (model.AcademicMajor1.Id != 0) { entity.AcademicMinorId = academicMajor1.Id; } if (model.AcademicMajor2.Id != 0) { entity.AcademicMajorNeededHelpId = academicMajor2.Id; } entity.UserId = user.Id; //Finally Adding the entity to DB traineeRepository.Add(entity); unitOfWork.SaveChanges(); //If we got here - Yay! :) status.Success = true; status.Message = String.Format("חניך {0} הוזן בהצלחה", model.User.FullName); } else { status.Message = userStatus.Message; } } } catch (Exception ex) { if (status.Message == string.Empty) { status.Message = String.Format("שגיאה במהלך הוספת חניך"); } LogService.Logger.Error(status.Message, ex); } return(status); }
public StatusModel RunAlgorithm(AlgorithmModel model) { var status = new StatusModel(false, String.Empty); int numTrainees = model.TraineeList.Count; int numTutors = model.TutorList.Count; int[,] utilityMat = new int[numTrainees, numTutors]; int maxUtil = 0; for (int traineeIdx = 0; traineeIdx < numTrainees; traineeIdx++) { for (int tutorIdx = 0; tutorIdx < numTutors; tutorIdx++) { TraineeModel trainee = model.TraineeList[traineeIdx]; TutorModel tutor = model.TutorList[tutorIdx]; int libaWeight = 200; int majorWeight = 2000; int minorWeight = 1000; int clusterWeight = 20; int institutionWeight = 50; bool isMechina = (trainee.EnglishLevel > 0 || trainee.MathLevel > 0 || trainee.PhysicsLevel > 0); if (isMechina) { majorWeight = majorWeight / 5; institutionWeight = institutionWeight / 4; minorWeight = minorWeight / 5; clusterWeight = clusterWeight / 4; } //Gender must match if (trainee.Gender != tutor.Gender) { utilityMat[traineeIdx, tutorIdx] = -1; continue; } //TODO: Check with or if required AcademicYear instead of SemesterNumber //tutor has senority over trainee if (trainee.SemesterNumber > tutor.SemesterNumber) { utilityMat[traineeIdx, tutorIdx] = -1; continue; } //Liba matching if ((int)trainee.MathLevel > (int)tutor.MathLevel || (int)trainee.EnglishLevel > (int)tutor.EnglishLevel || (int)trainee.PhysicsLevel > (int)tutor.PhysicsLevel) { utilityMat[traineeIdx, tutorIdx] = -1; continue; } else if (isMechina) { utilityMat[traineeIdx, tutorIdx] += libaWeight; } //Trainee Major match int calc1 = 0; if (trainee.AcademicMajor.Id == tutor.AcademicMajor.Id) { calc1 += majorWeight; } else if (tutor.AcademicMajor1 != null && trainee.AcademicMajor.Id == tutor.AcademicMajor1.Id) { calc1 += majorWeight - (int)(0.1 * majorWeight); } //Trainee minor match int calc2 = 0; if (trainee.AcademicMajor1 != null) { if (tutor.AcademicMajor1 != null && trainee.AcademicMajor1.Id == tutor.AcademicMajor1.Id) { calc2 += minorWeight; } else if (trainee.AcademicMajor1.Id == tutor.AcademicMajor.Id) { calc2 += minorWeight - (int)(0.1 * minorWeight); } } else { calc1 = (int)(1.5 * calc1); } //Trainee needed help exsists if (trainee.AcademicMajor2 != null) { if (trainee.AcademicMajor2.Id == tutor.AcademicMajor.Id) { calc1 += (int)(majorWeight * 0.5); } else if (tutor.AcademicMajor1 != null && trainee.AcademicMajor2.Id == tutor.AcademicMajor1.Id) { calc1 += (int)(majorWeight * 0.5); } } else { if (calc1 > 0) { calc1 += (int)(majorWeight * 0.5); } if (calc2 > 0) { calc2 += (int)(minorWeight * 0.5); } } //adding calc to matrix utilityMat[traineeIdx, tutorIdx] += (calc1 + calc2); //Academic Clusters //Trainee major cluster calc1 = 0; if (trainee.AcademicMajor.AcademicCluster == tutor.AcademicMajor.AcademicCluster) { calc1 += clusterWeight; } else if (tutor.AcademicMajor1 != null && trainee.AcademicMajor.AcademicCluster == tutor.AcademicMajor1.AcademicCluster) { calc1 += clusterWeight - (int)(0.1 * clusterWeight); } //Trainee minor cluster calc2 = 0; if (trainee.AcademicMajor1 != null) { if (tutor.AcademicMajor1 != null && trainee.AcademicMajor1.AcademicCluster == tutor.AcademicMajor1.AcademicCluster) { calc2 += clusterWeight; } else if (trainee.AcademicMajor1.AcademicCluster == tutor.AcademicMajor.AcademicCluster) { calc2 += clusterWeight - (int)(0.1 * clusterWeight); } } else { calc1 = (int)(1.5 * calc1); } //Trainee needed help exsists - consider cluster if (trainee.AcademicMajor2 != null) { if (trainee.AcademicMajor2.AcademicCluster == tutor.AcademicMajor.AcademicCluster) { calc1 += (int)(clusterWeight * 0.5); } else if (tutor.AcademicMajor1 != null && trainee.AcademicMajor2.AcademicCluster == tutor.AcademicMajor1.AcademicCluster) { calc1 += (int)(clusterWeight * 0.35); } } else { if (calc1 > 0) { calc1 += (int)(clusterWeight * 0.5); } if (calc2 > 0) { calc2 += (int)(clusterWeight * 0.5); } } //adding calc to matrix utilityMat[traineeIdx, tutorIdx] += (calc1 + calc2); //AcademicInstitution needs to be alike.. or similar //Academic institution does not disqualify matches if (trainee.AcademicInstitution.InstitutionType == tutor.AcademicInstitution.InstitutionType) { utilityMat[traineeIdx, tutorIdx] += institutionWeight; } else if (trainee.AcademicInstitution.InstitutionType < tutor.AcademicInstitution.InstitutionType) { utilityMat[traineeIdx, tutorIdx] += institutionWeight / 2; } //If they have the same Academic Institution if (trainee.AcademicInstitution.Name == tutor.AcademicInstitution.Name) { utilityMat[traineeIdx, tutorIdx] += institutionWeight; } //check what is max util if (utilityMat[traineeIdx, tutorIdx] > maxUtil) { maxUtil = utilityMat[traineeIdx, tutorIdx]; } } } //Generate cost matrix //Create a balanced matrix for the algorithm NXN int matSize = 0; matSize = numTrainees >= numTutors ? numTrainees : numTutors; int[,] costMatrix = new int[matSize, matSize]; int bigM = maxUtil * 1000; for (int traineeIdx = 0; traineeIdx < numTrainees; traineeIdx++) { for (int tutorIdx = 0; tutorIdx < numTutors; tutorIdx++) { //replace -1 (forbidden) with M if (utilityMat[traineeIdx, tutorIdx] == -1) { costMatrix[traineeIdx, tutorIdx] = bigM; } //Convert utility to cost else { costMatrix[traineeIdx, tutorIdx] = maxUtil - utilityMat[traineeIdx, tutorIdx]; } } } // Send Matrix to Algorithm MatchingAlgorithm alg = new MatchingAlgorithm(costMatrix); int[,] finalmatch = alg.Run(); //Translate Matrix to actual matches var unmatchedTrainees = new List <int>(); var isMatchedTrainees = new int[numTrainees]; var unmatchedTutors = new List <int>(); var isMatchedTutors = new int[numTutors]; try { for (int traineeIdx = 0; traineeIdx < numTrainees; traineeIdx++) { for (int tutorIdx = 0; tutorIdx < numTutors; tutorIdx++) { if (finalmatch[traineeIdx, tutorIdx] == 5) { if (utilityMat[traineeIdx, tutorIdx] > 100) { //Create Match var result = TutorTraineeAdd(model.TutorList[tutorIdx], model.TraineeList[traineeIdx]); isMatchedTutors[tutorIdx] = 1; isMatchedTrainees[traineeIdx] = 1; if (!result.Success) { throw new Exception(result.Message); } } } } } for (int i = 0; i < numTrainees; i++) { if (isMatchedTrainees[i] == 0) { unmatchedTrainees.Add(i); } } for (int i = 0; i < numTutors; i++) { if (isMatchedTutors[i] == 0) { unmatchedTutors.Add(i); } } if (unmatchedTutors.Count < unmatchedTrainees.Count) { foreach (var tutor in unmatchedTutors) { var maxValue = -1; int loc = -1; foreach (var trainee in unmatchedTrainees) { if (utilityMat[trainee, tutor] > maxValue) { maxValue = utilityMat[trainee, tutor]; loc = trainee; } } if (maxValue > 100 && loc > -1) { TutorTraineeAdd(model.TutorList[tutor], model.TraineeList[loc]); unmatchedTrainees.Remove(loc); } } } else { foreach (var trainee in unmatchedTrainees) { var maxValue = -1; int loc = -1; foreach (var tutor in unmatchedTutors) { if (utilityMat[trainee, tutor] > maxValue) { maxValue = utilityMat[trainee, tutor]; loc = tutor; } } if (maxValue > 100 && loc > -1) { TutorTraineeAdd(model.TutorList[loc], model.TraineeList[trainee]); unmatchedTrainees.Remove(loc); } } } status.Success = true; } catch (Exception ex) { status.Message = String.Format("שגיאה במהלך הרצת האלגוריתם"); LogService.Logger.Error(status.Message, ex); } return(status); }
public override void Enable(OperationType operation, TraineeModel trainee) { base.Enable(operation, trainee); TraineeCollection.LoadBlockTraineesCannotBeChosen(trainee.CurrentBlockID); SelectedClass = _blockClasses.BlockClassCollection.Where(c => c.ClassID == trainee.CurrentBlockID).First().ClassName; }
/// <summary> /// 在列表中修改学员 /// </summary> /// <param name="trainee"></param> public void UpdateTrainee(TraineeModel trainee) { _trinees[_trinees.IndexOf(_trinees.Where(t => t.TraineeID == trainee.TraineeID).First())] = trainee; TraineeChangedEvent?.Invoke(); }