public bool CanDo(SheetOperation operation) { switch (operation) { case SheetOperation.Modify: return(State == SheetState.Add); case SheetOperation.Approve: return(State == SheetState.Add); case SheetOperation.UndoApprove: return(State == SheetState.Approved); case SheetOperation.Nullify: return(State != SheetState.Canceled && State != SheetState.Inventory); case SheetOperation.StackIn: return(State == SheetState.Add || State == SheetState.Approved); case SheetOperation.StackOut: return(State == SheetState.Add || State == SheetState.Approved); default: return(false); } }
public static string GetDescription(SheetOperation state) { switch (state) { case SheetOperation.Create: return("新建"); case SheetOperation.Modify: return("修改"); case SheetOperation.Approve: return("审核"); case SheetOperation.UndoApprove: return("取消审核"); case SheetOperation.Nullify: return("作废"); case SheetOperation.StackIn: return("收货"); case SheetOperation.StackOut: return("发货"); default: return(string.Empty); } }
private void PerformSave <T>(SheetProcessorBase <T> processor, SheetOperation operation) where T : class, ISheet <string> { if (CheckInput()) { T sheet = GetItemFromInput() as T; CommandResult ret = processor.ProcessSheet(sheet, operation, Operator.Current.Name, Operator.Current.ID); if (ret.Result == ResultCode.Successful) { UpdatingItem = sheet; IsAdding = false; ItemShowing(); ShowButtonState(); if (operation == SheetOperation.Create) { this.OnItemAdded(new ItemAddedEventArgs(sheet)); } if (operation != SheetOperation.Create) { this.OnItemUpdated(new ItemUpdatedEventArgs(sheet)); } MessageBox.Show(string.Format("{0} 成功", SheetOperationDescription.GetDescription(operation)), "确定"); } else { MessageBox.Show(ret.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 保存单据操作日志 /// </summary> /// <param name="id"></param> /// <param name="docType"></param> /// <param name="operation"></param> /// <param name="opt"></param> /// <param name="unitWork"></param> /// <param name="dt"></param> protected virtual void AddOperationLog(string id, string docType, SheetOperation operation, IUnitWork unitWork, DateTime dt, string opt, string logID = null) { DocumentOperation doc = new DocumentOperation() { ID = Guid.NewGuid(), DocumentID = id, DocumentType = docType, OperatDate = dt, Operation = SheetOperationDescription.GetDescription(operation), Operator = opt, LogID = logID, }; ProviderFactory.Create <IProvider <DocumentOperation, Guid> >(RepoUri).Insert(doc, unitWork); }
/// <summary> /// 单据处理 /// </summary> /// <param name="sheet"></param> /// <param name="operation"></param> /// <param name="opt"></param> /// <returns></returns> public CommandResult ProcessSheet(TEntity sheet, SheetOperation operation, string opt, string logID) { try { IUnitWork unitWork = ProviderFactory.Create <IUnitWork>(RepoUri); DateTime? dt = GetServerDateTime(); //从数据库获取时间 if (dt == null) { return(new CommandResult(ResultCode.Fail, "从数据库服务器获取时间失败")); } if (operation == SheetOperation.Create) { sheet.LastActiveDate = dt.Value; DoAdd(sheet, unitWork, dt.Value, opt); } else { if (!sheet.CanDo(operation)) { return(new CommandResult(ResultCode.Fail, string.Format("单据不能进行 {0} 操作", SheetOperationDescription.GetDescription(operation)))); } DateTime?lastActiveDate = GetLastActiveDate(sheet); if (lastActiveDate == null) { return(new CommandResult(ResultCode.Fail, "获取单据最后操作时间失败,请重试")); } //单据的最后活动时间与当前值不相同,说明其它操作员在此次修改之前修改过单据 if (sheet.LastActiveDate != lastActiveDate.Value) { return(new CommandResult(ResultCode.Fail, "其它操作员已经修改了数据,请先获取到最新数据后再做修改")); } switch (operation) { case SheetOperation.Modify: DoUpdate(sheet, unitWork, dt.Value, opt); break; case SheetOperation.Approve: DoApprove(sheet, unitWork, dt.Value, opt); break; case SheetOperation.UndoApprove: UndoApprove(sheet, unitWork, dt.Value, opt); break; case SheetOperation.Nullify: DoNullify(sheet, unitWork, dt.Value, opt); break; case SheetOperation.StackIn: DoInventory(sheet, unitWork, dt.Value, opt); break; case SheetOperation.StackOut: DoShip(sheet, unitWork, dt.Value, opt); break; default: return(new CommandResult(ResultCode.Fail, string.Format("没有实现 {0} 处理", SheetOperationDescription.GetDescription(operation)))); } } AddOperationLog(sheet.ID, sheet.DocumentType, operation, unitWork, dt.Value, opt, logID); return(unitWork.Commit()); } catch (Exception ex) { return(new CommandResult(ResultCode.Fail, ex.Message)); } }
protected virtual void PerformOperation <T>(SheetProcessorBase <T> processor, SheetOperation operation) where T : class, ISheet <string> { if (operation == SheetOperation.Create || operation == SheetOperation.Modify) { PerformSave <T>(processor, operation); } else { if (UpdatingItem != null) { T sheet = null; if (operation == SheetOperation.Create || operation == SheetOperation.Modify) { MessageBox.Show("保存请调用 " + "PerformCreateOrModify()"); return; } else { sheet = UpdatingItem as T; if (MessageBox.Show(string.Format("是否要进行 {0}?", SheetOperationDescription.GetDescription(operation)), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } } CommandResult ret = processor.ProcessSheet(sheet, operation, Operator.Current.Name, Operator.Current.ID); if (ret.Result == ResultCode.Successful) { ItemShowing(); ShowButtonState(); if (operation != SheetOperation.Create) { this.OnItemUpdated(new ItemUpdatedEventArgs(sheet)); } MessageBox.Show(string.Format("{0} 成功", SheetOperationDescription.GetDescription(operation)), "确定"); } else { MessageBox.Show(ret.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }