private void DoSave(bool isupload = false) { if (dgvSelected.Rows.Count == 0) { if (_inprivateStaffInfos.Count == 0) { WinInfoHelper.ShowInfoWindow(this, "请至少选一个授权的人员!"); return; } } var hasPrivates = _inprivateStaffInfos.ToList(); List <Maticsoft.Model.SMT_STAFF_INFO> staffInfos = new List <Maticsoft.Model.SMT_STAFF_INFO>(); foreach (DataGridViewRow item in dgvSelected.Rows) { staffInfos.Add((Maticsoft.Model.SMT_STAFF_INFO)item.Tag); } CtrlWaiting waiting = new CtrlWaiting(() => { Maticsoft.BLL.SMT_STAFF_FACEDEV sfbll = new Maticsoft.BLL.SMT_STAFF_FACEDEV(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> addmodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> updatemodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> deletemodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); try { foreach (var staff in staffInfos) { foreach (var dev in _selectDevices) { var model = sfbll.GetModel(staff.ID, dev.ID); if (model == null) { model = new Maticsoft.Model.SMT_STAFF_FACEDEV(); model.ADD_TIME = DateTime.Now; model.END_VALID_TIME = dtpEnd.Value.Date + new TimeSpan(23, 59, 59); model.FACEDEV_ID = dev.ID; model.IS_UPLOAD = false; model.STAFF_DEV_ID = Guid.NewGuid().ToString("N"); model.STAFF_ID = staff.ID; model.START_VALID_TIME = dtpStart.Value.Date; model.UPLOAD_TIME = DateTime.Now; sfbll.Add(model); } else { hasPrivates.RemoveAll(m => m.ID == model.STAFF_ID); model.START_VALID_TIME = dtpStart.Value.Date; model.END_VALID_TIME = dtpEnd.Value.Date + new TimeSpan(23, 59, 59); if (string.IsNullOrWhiteSpace(model.STAFF_DEV_ID)) { model.STAFF_DEV_ID = Guid.NewGuid().ToString("N"); } sfbll.Update(model); } model.STAFF_INFO = staff; model.FACERECG_DEVICE = dev; if (!model.IS_UPLOAD) { addmodels.Add(model); } } } foreach (var item in hasPrivates) { foreach (var dev in _selectDevices) { var model = sfbll.GetModel(item.ID, dev.ID); if (model != null) { deletemodels.Add(model); } } } } catch (Exception ex) { WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message); log.Error("保存异常:", ex); return; } if (deletemodels.Count > 0) { string errMsg = ""; var delre = UploadPrivate.DeleteFace(deletemodels, out errMsg); if (delre != null && delre.Count > 0) { foreach (var item in delre) { sfbll.Delete(item.STAFF_ID, item.FACEDEV_ID); } } } if (isupload) { string errMsg = ""; SmartAccess.Common.Datas.UploadPrivate.CancelObject cancelObject = new UploadPrivate.CancelObject(); bool ret = UploadPrivate.UploadFace(cancelObject, addmodels, updatemodels, out errMsg); if (!ret || !string.IsNullOrWhiteSpace(errMsg)) { WinInfoHelper.ShowInfoWindow(this, "保存成功,部分权限上传异常:" + errMsg); } } this.Invoke(new Action(() => { this.DialogResult = DialogResult.OK; this.Close(); })); }); waiting.Show(this); }
private void DoUpload(List <Maticsoft.Model.SMT_STAFF_FACEDEV> list, bool bforce, bool bcancel, params DataGridViewRow[] rows) { List <Maticsoft.Model.SMT_STAFF_FACEDEV> addmodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> updatemodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> deletemodels = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); foreach (var item in list) { if (bcancel && item.IS_UPLOAD) { deletemodels.Add(item); } else { if (item.IS_UPLOAD) { updatemodels.Add(item); } else { addmodels.Add(item); } } } CtrlWaiting waiting = new CtrlWaiting(() => { string errMsg = ""; bool ret = false; List <Maticsoft.Model.SMT_STAFF_FACEDEV> dels = null; if (bcancel && deletemodels.Count > 0) { dels = UploadPrivate.DeleteFace(deletemodels, out errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { WinInfoHelper.ShowInfoWindow(this, "权限删除存在异常:" + errMsg); } } else { SmartAccess.Common.Datas.UploadPrivate.CancelObject cancelObject = new UploadPrivate.CancelObject(); if (bforce) { ret = UploadPrivate.UploadFace(cancelObject, list, null, out errMsg); } else { ret = UploadPrivate.UploadFace(cancelObject, addmodels, updatemodels, out errMsg); } if (!ret || !string.IsNullOrWhiteSpace(errMsg)) { WinInfoHelper.ShowInfoWindow(this, "权限上传存在异常:" + errMsg); } } if (rows != null && rows.Length > 0) { this.Invoke(new Action(() => { foreach (var row in rows) { Maticsoft.Model.SMT_STAFF_FACEDEV item = (Maticsoft.Model.SMT_STAFF_FACEDEV)row.Tag; string state = ""; if (item.IS_FORBIDDEN) { state = "已禁用"; } else if (item.IS_UPLOAD) { state = "已上传"; } else { if (item.PHOTO == null || item.PHOTO.Length == 0) { state = "未上传(无照片)"; } else { state = "未上传"; } } row.Cells[4].Value = state; row.Cells[8].Value = item.IS_UPLOAD ? "重上传" : "上传"; } })); } else { DoSearch(null, null, null); } }); waiting.Show(this); }
private void DoSaveDevices(List <Maticsoft.Model.SMT_FACERECG_DEVICE> devices, bool upload = false) { if (dtpStart.Value.Date > dtpEnd.Value.Date) { WinInfoHelper.ShowInfoWindow(this, "起始时间不能小于结束时间!"); return; } CtrlWaiting ctrlWaiting = new CtrlWaiting("正在保存...", () => { try { Maticsoft.BLL.SMT_STAFF_FACEDEV sfBLL = new Maticsoft.BLL.SMT_STAFF_FACEDEV(); var sfList = sfBLL.GetModelList("STAFF_ID=" + _staffInfo.ID); List <Maticsoft.Model.SMT_FACERECG_DEVICE> tempDevs = new List <Maticsoft.Model.SMT_FACERECG_DEVICE>(); tempDevs.AddRange(devices); List <Maticsoft.Model.SMT_STAFF_FACEDEV> addPrivates = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> updatePrivates = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); List <Maticsoft.Model.SMT_STAFF_FACEDEV> delPrivates = new List <Maticsoft.Model.SMT_STAFF_FACEDEV>(); foreach (var item in sfList) { var sc = devices.Find(m => m.ID == item.FACEDEV_ID); if (sc == null)//不存在,则权限删除 { delPrivates.Add(item); // sfBLL.Delete(item.STAFF_ID, item.FACEDEV_ID);//删除权限 } else { item.START_VALID_TIME = dtpStart.Value.Date; item.END_VALID_TIME = dtpEnd.Value.Date + new TimeSpan(23, 59, 59); if (_staffInfo.VALID_STARTTIME.Date > item.START_VALID_TIME.Date) { item.START_VALID_TIME = _staffInfo.VALID_STARTTIME.Date; } if (_staffInfo.VALID_ENDTIME.Date < item.END_VALID_TIME.Date) { item.END_VALID_TIME = _staffInfo.VALID_ENDTIME.Date + new TimeSpan(23, 59, 59); } sfBLL.Update(item); tempDevs.Remove(sc); if (!item.IS_UPLOAD) { addPrivates.Add(item); } else { if (_imageChanged) { addPrivates.Add(item); } else { updatePrivates.Add(item); } } } } foreach (var item in tempDevs)//添加的权限 { Maticsoft.Model.SMT_STAFF_FACEDEV newSd = new Maticsoft.Model.SMT_STAFF_FACEDEV(); newSd.ADD_TIME = DateTime.Now; newSd.FACEDEV_ID = item.ID; newSd.IS_UPLOAD = false; newSd.UPLOAD_TIME = DateTime.Now; newSd.STAFF_ID = _staffInfo.ID; newSd.STAFF_DEV_ID = Guid.NewGuid().ToString("N"); newSd.START_VALID_TIME = dtpStart.Value.Date; newSd.END_VALID_TIME = dtpEnd.Value.Date + new TimeSpan(23, 59, 59); if (_staffInfo.VALID_STARTTIME.Date > newSd.START_VALID_TIME.Date) { newSd.START_VALID_TIME = _staffInfo.VALID_STARTTIME.Date; } if (_staffInfo.VALID_ENDTIME.Date < newSd.END_VALID_TIME.Date) { newSd.END_VALID_TIME = _staffInfo.VALID_ENDTIME.Date + new TimeSpan(23, 59, 59); } sfBLL.Add(newSd); addPrivates.Add(newSd); } if (upload) { string errMsg; if (delPrivates.Count > 0) { var delResults = UploadPrivate.DeleteFace(delPrivates, out errMsg); if (delResults != null && delResults.Count > 0) { foreach (var item in delResults) { Maticsoft.BLL.SMT_STAFF_FACEDEV bll = new Maticsoft.BLL.SMT_STAFF_FACEDEV(); bll.Delete(item.STAFF_ID, item.FACEDEV_ID); } } } errMsg = ""; if (addPrivates.Count > 0 || updatePrivates.Count > 0) { SmartAccess.Common.Datas.UploadPrivate.CancelObject cancelObject = new UploadPrivate.CancelObject(); bool ret = UploadPrivate.UploadFace(cancelObject, addPrivates, updatePrivates, out errMsg); if (ret && errMsg != "") { WinInfoHelper.ShowInfoWindow(this, "上传权限存在异常:" + errMsg); log.Warn("上传权限存在异常:" + errMsg); return; } } WinInfoHelper.ShowInfoWindow(null, "上传权限结束!"); } this.Invoke(new Action(() => { this.DialogResult = DialogResult.OK; this.Close(); })); } catch (System.Exception ex) { log.Error("保存异常:", ex); WinInfoHelper.ShowInfoWindow(this, "保存异常:" + ex.Message); } }); ctrlWaiting.Show(this); }