Example #1
0
        public InformationEditViewModel()
        {
            this.closeCommand       = new DelegateCommand(new Action <object>(closeExecute), new Func <Object, bool>(closeCanExecute));
            this.getCityCommand     = new DelegateCommand(new Action <object>(getCityExecute));
            this.photoChooseCommand = new DelegateCommand(new Action <object>(photoChooseExecute));
            this.photoDeleteCommand = new DelegateCommand(new Action <object>(photoDeleteExecute));
            this.editCommand        = new DelegateCommand(new Action <object>(editExecute));
            #region 初始化INformation属性
            var database   = client.GetDatabase("hrms");
            var collection = database.GetCollection <BsonDocument>("informations");
            var filter     = Builders <BsonDocument> .Filter.Eq("Id", "5436");

            var projection = Builders <BsonDocument> .Projection.Exclude("_id");

            var    doc     = collection.Find(filter).Project(projection).First();
            string jsonStr = doc.ToJson();
            this.Information = JsonUtils.DeserializeJsonToObject <Information>(jsonStr);
            #endregion

            #region 初始化照片
            ServiceProxy.ServiceTestClient serviceTestClient = new ServiceProxy.ServiceTestClient("WSHttpBinding_IServiceTest");
            string imgStr = serviceTestClient.PicDownload(Information.Photo);
            Image  img    = Utils.ByteArrayToImg(imgStr);
            string path   = "C:/Users/victo/Desktop/Csharp/HRMS_MVVM/HRMS_MVVM/images/" + Information.Photo + ".jpg";
            img.Save(path);
            Photo = path;
            #endregion

            #region 初始化民族
            Nations = new ObservableCollection <string>();
            Nations.Add("请选择");
            Nations.Add("土家族");
            Nations.Add("汉族");
            Nations.Add("苗族");
            #endregion
            #region 性别
            Genders = new ObservableCollection <string>();
            Genders.Add("请选择");
            Genders.Add("男");
            Genders.Add("女");
            #endregion
            #region 婚姻
            Marriages = new ObservableCollection <string>();
            Marriages.Add("请选择");
            Marriages.Add("已婚");
            Marriages.Add("未婚");
            #endregion
            #region 学历
            Educations = new ObservableCollection <string>();
            Educations.Add("请选择");
            Educations.Add("初中及以下");
            Educations.Add("高中");
            Educations.Add("本科");
            Educations.Add("硕士");
            Educations.Add("博士");
            #endregion
            #region 政治面貌
            Politics = new ObservableCollection <string>();
            Politics.Add("请选择");
            Politics.Add("群众");
            Politics.Add("共青团员");
            Politics.Add("中共党员");
            Politics.Add("其他");
            #endregion
            #region 籍贯
            Provinces = new ObservableCollection <string>();
            Provinces.Add("请选择");
            Provinces.Add("湖北");
            Provinces.Add("四川");

            Cities = new ObservableCollection <string>();
            if (Information.Province == "湖北")
            {
                Cities.Add("武汉");
                Cities.Add("恩施");
                Cities.Add("宜昌");
                City = Information.City;
            }
            else if (Information.Province == "四川")
            {
                Cities.Add("成都");
                Cities.Add("德阳");
                Cities.Add("绵阳");
                City = Information.City;
            }
            #endregion
        }