public void photoDeleteExecute(Object parameter) { Photo = ""; try { ServiceProxy.ServiceTestClient client = new ServiceProxy.ServiceTestClient("WSHttpBinding_IServiceTest"); client.PicDelete(this.Information.Photo); } catch (Exception) { System.Windows.MessageBox.Show("清除错误,请联系管理员!"); } }
public void photoChooseExecute(Object parameter) { Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); dialog.Filter = "图像文件|*.jpg;*.png;*.jpeg"; if (dialog.ShowDialog() == true) { // 根据文件名在本地读取文件,存为字节文件,调用上传服务上传文件转换为图片并返回 // 在服务器端的存储位置(http链接),存储到数据库中;获取数据库中路径,赋给Photo预览 Photo = dialog.FileName; Image image = Image.FromFile(dialog.FileName); try { string imgString = Utils.ImgToByteArray(image); ServiceProxy.ServiceTestClient client = new ServiceProxy.ServiceTestClient("WSHttpBinding_IServiceTest"); string imgName = client.PicUpload(imgString); this.Information.Photo = imgName; } catch (Exception e) { System.Windows.MessageBox.Show("上传错误,请联系管理员!"); } } }
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 }