//把操作的状态改变的操作后单据的状态。 private int convertToDocState(Database db, DocStateTraceInfo stateInfo) { MB.Util.Model.DocOperateType operateType = stateInfo.OP_STATE; switch (operateType) { case DocOperateType.Approved: return((int)MB.Util.Model.DocState.Approved); case DocOperateType.Completed: return((int)MB.Util.Model.DocState.Completed); case DocOperateType.Withdraw: return((int)MB.Util.Model.DocState.Withdraw); case DocOperateType.Suspended: return((int)MB.Util.Model.DocState.Suspended); case DocOperateType.CancelSuspended: int orgDocState = getSuspendDocState(db, stateInfo.DOC_TYPE, stateInfo.DOC_ID); return(orgDocState); default: throw new MB.Util.APPException(string.Format("当前单据的操作类型{0} 还没有进行相应的处理,请检查", operateType.ToString()), MB.Util.APPMessageType.SysErrInfo); } }
/// <summary> /// 存储单据操作的状态改变操作记录。 /// 这里有很多特殊的约束:要求主表必须有一个ID、DOC_STATE和LAST_MODIFIED_DATE,同时键值必须是Int32类型。 /// </summary> /// <param name="db">连接的数据库</param> /// <param name="stateInfo">状态改变的记录信息</param> /// <returns>1表示成功,-1表示不成功</returns> public int SaveDocState(Database db, string docType, MB.Orm.Common.BaseModel docEntity, string remark, DocOperateType operateType) { DocStateTraceInfo stateInfo = new DocStateTraceInfo(docType, docEntity, remark, operateType); var databaseType = MB.Orm.Persistence.DatabaseHelper.GetDatabaseType(db); //在提交之前先检查服务器日期 MB.Orm.Persistence.EntityDistributedHelper.NewInstance.CheckEntityCanSave(docEntity); string sql = databaseType == MB.Orm.Enums.DatabaseType.Oracle ? SQL_INSERT_DOC_TRACE.Replace('@', ':') : SQL_INSERT_DOC_TRACE; DbCommand dbCmd = db.GetSqlStringCommand(sql); if (stateInfo.ID <= 0) { stateInfo.ID = MB.Orm.Persistence.EntityIdentityHelper.NewInstance.GetEntityIdentity("SYS_DOC_STATE_CHANGED_TRACE"); } //@ID,@DOC_TYPE,@DOC_ID,@DOC_ORG_SATE,@OP_USER_CODE,@OP_DATE,@OP_STATE,@REMARK db.AddInParameter(dbCmd, "ID", System.Data.DbType.Int32, stateInfo.ID); db.AddInParameter(dbCmd, "DOC_TYPE", System.Data.DbType.String, stateInfo.DOC_TYPE); db.AddInParameter(dbCmd, "DOC_ID", System.Data.DbType.Int32, stateInfo.DOC_ID); db.AddInParameter(dbCmd, "DOC_ORG_SATE", System.Data.DbType.Int32, (int)stateInfo.DOC_ORG_SATE); db.AddInParameter(dbCmd, "OP_STATE", System.Data.DbType.Int32, (int)stateInfo.OP_STATE); db.AddInParameter(dbCmd, "OP_USER_CODE", System.Data.DbType.String, stateInfo.OP_USER_CODE); db.AddInParameter(dbCmd, "REMARK", System.Data.DbType.String, stateInfo.REMARK); //更改原表的单据状态 string orgObjectSql = string.Format(SQL_UPDATE_DOC_STATE, stateInfo.OBJECT_TABLE_NAME); orgObjectSql = databaseType == MB.Orm.Enums.DatabaseType.Oracle ? orgObjectSql.Replace('@', ':') : orgObjectSql; DbCommand orgCmd = db.GetSqlStringCommand(orgObjectSql); db.AddInParameter(orgCmd, "DOC_STATE", System.Data.DbType.Int32, convertToDocState(db, stateInfo)); db.AddInParameter(orgCmd, "DOC_ID", System.Data.DbType.Int32, stateInfo.DOC_ID); return(MB.RuleBase.Common.DatabaseExecuteHelper.NewInstance.ExecuteNonQuery(db, new DbCommand[] { dbCmd, orgCmd })); }