Example #1
0
        public BlockTraineeListViewModel(BlockTraineeBussiness bussiness)
        {
            _bussiness = bussiness;
            _bussiness.LoadTraineesEvnet += trainees =>
            {
                Trainees.Clear();
                if (trainees != null)
                {
                    trainees.ForEach(t =>
                    {
                        Trainees.Add(new TraineeViewModel(t, false));
                        Trainees.Last().OperateTraineeEvent += OnOperateTrainee;
                    });
                }
            };

            _bussiness.TraineeChangedEvent += (operation, trainee, newIndex) =>
            {
                switch (operation)
                {
                case OperationType.Add:
                    Trainees.Add(new TraineeViewModel(trainee, false));
                    Trainees.Last().OperateTraineeEvent += OnOperateTrainee;
                    break;

                case OperationType.Update:
                    Trainees.Where(t => t.TraineeID == trainee.TraineeIDForShown).First().TraineeName = trainee.TraineeName;
                    break;

                case OperationType.Delete:
                    Trainees.Remove(Trainees.Where(t => t.TraineeID == trainee.TraineeIDForShown).First());
                    break;
                }
            };
        }
Example #2
0
        public IEnumerable <Trainee> GetAllTrainees(Func <Trainee, bool> predicat = null)
        {
            IEnumerable <Trainee> Trainees;

            try
            {
                Trainees = from p in TraineeRoot.Elements()
                           select new Trainee()
                {
                    ID          = Convert.ToInt32(p.Element("TraineeID").Value),
                    FirstName   = p.Element("FamilyName").Value,
                    FamilyName  = p.Element("FamilyName").Value,
                    Gender      = p.Element("Gender").Value,
                    PhoneNum    = Convert.ToInt32(p.Element("PhoneNum").Value),
                    Address     = p.Element("Address").Value,
                    Birthday    = DateTime.Parse(p.Element("Birthday").Value),
                    Model       = p.Element("Model").Value,
                    GearType    = p.Element("Geartype").Value,
                    School      = p.Element("School").Value,
                    TeacherName = p.Element("TeacherName").Value,
                    LessonAMT   = Convert.ToInt32(p.Element("LessonAmt").Value),
                };

                if (predicat != null)
                {
                    Trainees = Trainees.Where(predicat);
                }
            }
            catch
            {
                Trainees = null;
            }
            return(Trainees);
        }
Example #3
0
        public IEnumerable <Trainee> getAllTrainees(Func <Trainee, bool> predicat = null)
        {
            IEnumerable <Trainee> Trainees;

            try
            {
                Trainees = from p in TraineeRoot.Elements()
                           // where predicat
                           select new Trainee()
                {
                    id           = Convert.ToInt32(p.Element("branchNumber").Value),
                    firstName    = p.Element("First Name").Value,
                    lastName     = p.Element("last Name").Value,
                    phoneNum     = p.Element("PhoneNumber").Value,
                    Adress       = p.Element("Address").Value,
                    birthday     = Convert.ToDateTime(p.Element("Birthday").Value),
                    school       = p.Element("School name").Value,
                    teacher      = p.Element("Teacher name").Value,
                    numOfLessons = Convert.ToInt32(p.Element("number of lessons").Value),
                    transmission = (BE.Transmission)Enum.Parse(typeof(Transmission), p.Element("Transmission").Value),
                    Gender       = (BE.gender)Enum.Parse(typeof(gender), p.Element("Gender").Value)
                };
                if (predicat != null)
                {
                    Trainees = Trainees.Where(predicat);
                }
            }
            catch
            {
                Trainees = null;
            }
            return(Trainees);
        }
Example #4
0
 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);
 }
Example #5
0
        public RegularTraineeListViewModel(RegularTraineeBussiness bussiness) : base()
        {
            _bussiness = bussiness;
            _bussiness.LoadTraineesEvent += trainees =>
            {
                Trainees.Clear();
                if (trainees != null)
                {
                    trainees.ForEach(t =>
                    {
                        Trainees.Add(new TraineeViewModel(t, true));
                        Trainees.Last().OperateTraineeEvent += OnOperateTrainee;
                    });
                }
            };
            _bussiness.TraineeChangedEvent += (operation, trainee, newIndex) =>
            {
                switch (operation)
                {
                case OperationType.Add:
                    Trainees.Add(new TraineeViewModel(trainee, true));
                    Trainees.Last().OperateTraineeEvent += OnOperateTrainee;
                    break;

                case OperationType.Update:
                    if (newIndex == -1)
                    {    //只是更新信息
                        Trainees.Where(t => t.TraineeID == trainee.TraineeIDForShown).First().TraineeName = trainee.TraineeName;
                    }
                    else
                    {    //删除或者恢复
                        Trainees.Remove(Trainees.Where(t => t.TraineeID == trainee.TraineeIDForShown).First());
                        Trainees.Insert(newIndex, new TraineeViewModel(trainee, true));
                        Trainees[newIndex].OperateTraineeEvent += OnOperateTrainee;
                    }
                    break;

                case OperationType.Delete:
                    Trainees.Remove(Trainees.Where(t => t.TraineeID == trainee.TraineeIDForShown).First());
                    break;
                }
            };
        }