private void OnButtonOKClick(object sender, RoutedEventArgs e) { if (current != null) { // try { var sel = cboDepart.SelectedItem as DepartmentUI; if (null != sel) { current.Deparment = sel.Department; } var selRule = cboRule.SelectedItem as AttendanceRule; if (null != selRule) { current.AttendanceRule = selRule; } current.Cameras.Clear(); foreach (var c in cameras) { if (c.IsChecked) { var r = new EmployeeCameraRelation() { CameraID = c.Camera.ID, EmployeeID = current.ID, }; current.Cameras.Add(r); } } // var service = new Service.EmployeeService(); service.OnSaveCompleted += (depart) => { this.Dispatcher.BeginInvoke(new Action(() => { if (null != OnClose) { OnClose(); } }), null); }; EnableUI(false); service.Save(current, (exp) => { this.Dispatcher.BeginInvoke(new Action <string>((msg) => { EnableUI(true); MetroUIExtender.Alert(msg); }), new object[] { exp.Message }); }); } catch (Exception exp) { MetroUIExtender.Alert(exp.Message); } } }
async Task <PhotoImageQueryItem[]> CreatePersonToCamera(Employee entity, EmployeeCameraRelation c) { List <PhotoImageQueryItem> list = new List <PhotoImageQueryItem>(); var ret = await service.personCreate(c.Camera, new Person() { id = entity.Code, idcardnum = entity.IDCard, name = entity.Name }); if (ret.success) { try { c.PersonID = ret.data == null ? null : ret.data.id; c.FirstPhotoID = null; c.SecondPhotoID = null; c.ThirdPhotoID = null; if (entity.FirstPhoto != null) { var fi = new faceinfo() { faceid = entity.FirstPhoto.ID.ToString().Replace("-", ""), personid = c.PersonID, imagebase64 = Utils.Base64Converter.File2String(entity.FirstPhoto.FilePath) }; var photo = await service.FaceCreate(c.Camera, fi); if (photo.success) { c.FirstPhotoID = fi.faceid; var item = new PhotoImageQueryItem() { Camera = c.Camera, PersonID = c.PersonID, FaceID = c.FirstPhotoID, PhotoImageID = entity.FirstPhoto.ID, }; list.Add(item); } else { throw new Exception(string.Format("上传第一张照片到设备({0})失败", c.Camera.IP)); } } if (entity.SecondPhoto != null) { var fi = new faceinfo() { faceid = entity.SecondPhoto.ID.ToString().Replace("-", ""), personid = c.PersonID, imagebase64 = Utils.Base64Converter.File2String(entity.SecondPhoto.FilePath) }; var photo = await service.FaceCreate(c.Camera, fi); if (photo.success) { c.SecondPhotoID = fi.faceid; var item = new PhotoImageQueryItem() { Camera = c.Camera, PersonID = c.PersonID, FaceID = c.SecondPhotoID, PhotoImageID = entity.SecondPhoto.ID, }; list.Add(item); } else { throw new Exception(string.Format("上传第二张照片到设备({0})失败", c.Camera.IP)); } } if (entity.ThirdPhoto != null) { var fi = new faceinfo() { faceid = entity.ThirdPhoto.ID.ToString().Replace("-", ""), personid = c.PersonID, imagebase64 = Utils.Base64Converter.File2String(entity.ThirdPhoto.FilePath) }; var photo = await service.FaceCreate(c.Camera, fi); if (photo.success) { c.ThirdPhotoID = fi.faceid; var item = new PhotoImageQueryItem() { Camera = c.Camera, PersonID = c.PersonID, FaceID = c.ThirdPhotoID, PhotoImageID = entity.ThirdPhoto.ID, }; list.Add(item); } else { throw new Exception(string.Format("上传第三张照片到设备({0})失败", c.Camera.IP)); } } c.Status = 1; } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(exp); throw exp; } // } return(list.ToArray()); }