private SqlCommand CommandBuilder(DbActionType type) { SqlCommand command = new SqlCommand(type.ToString(), GetSqlConnection()) { CommandType = CommandType.StoredProcedure }; if (Entity == null && (type == DbActionType.EditarProductos || type == DbActionType.InsertarProductos || type == DbActionType.EliminarProducto)) { throw new ArgumentNullException(); } if (type == DbActionType.EditarProductos || type == DbActionType.InsertarProductos) { command.Parameters.AddWithValue("@nombre", Entity.Name); command.Parameters.AddWithValue("@descrip", Entity.Descripcion); command.Parameters.AddWithValue("@marca", Entity.Marca); command.Parameters.AddWithValue("@precio", Entity.Precio); command.Parameters.AddWithValue("@stock", Entity.Stock); } if (type == DbActionType.EditarProductos || type == DbActionType.EliminarProducto) { command.Parameters.AddWithValue("@stock", Entity.Id); } return(command); }
private void AddAudit(string message, string objectType = "", int? objectKey = null, int recordCount = 0, DbActionType action = DbActionType.NullAction) { Audit audit = new Audit(); audit.DateStamp = DateTime.Now; audit.Message = message; audit.ObjectKey = objectKey; audit.ObjectType = objectType; audit.UserName = UserName; audit.RecordCount = recordCount; audit.Action = action.ToString(); Debug.WriteLine("[AUDIT] " + message); DB.Audits.Add(audit); }
/// <summary> /// /// </summary> public Sql(OntologyDescriptor ontology, string clientId, string commandId, DbActionType actionType, string localEntityId, InfoItem[] infoValue, Func <DbParameter> createParameter) { this._ontology = ontology; this._localEntityId = localEntityId; this._infoValue = infoValue; this._clientId = clientId; this._commandId = commandId; this._createParameter = createParameter; if (ontology == null || string.IsNullOrEmpty(localEntityId)) { this.IsValid = false; this.Description = "命令信息标识或信息值为空或本体为空或本地标识为空"; throw new ArgumentNullException("command"); } // 无需把switch流程选择逻辑重构掉,因为actionType枚举不存在变化 switch (actionType) { case DbActionType.Insert: if (infoValue == null || infoValue.Length == 0) { this.Description = "命令信息值为空"; break; } BuildInsertSql(); break; case DbActionType.Update: if (infoValue == null || infoValue.Length == 0) { this.Description = "命令信息值为空"; break; } BuildUpdateSql(); break; case DbActionType.Delete: BuildDeleteSql(); break; default: this.IsValid = false; this.Description = "意外的不能执行的动作码" + actionType.ToString(); break; } }
/// <summary> /// /// </summary> public Sql(OntologyDescriptor ontology, string clientId, string commandId, DbActionType actionType, string localEntityId, InfoItem[] infoValue, Func<DbParameter> createParameter) { this._ontology = ontology; this._localEntityId = localEntityId; this._infoValue = infoValue; this._clientId = clientId; this._commandId = commandId; this._createParameter = createParameter; if (ontology == null || string.IsNullOrEmpty(localEntityId)) { this.IsValid = false; this.Description = "命令信息标识或信息值为空或本体为空或本地标识为空"; throw new ArgumentNullException("command"); } // 无需把switch流程选择逻辑重构掉,因为actionType枚举不存在变化 switch (actionType) { case DbActionType.Insert: if (infoValue == null || infoValue.Length == 0) { this.Description = "命令信息值为空"; break; } BuildInsertSql(); break; case DbActionType.Update: if (infoValue == null || infoValue.Length == 0) { this.Description = "命令信息值为空"; break; } BuildUpdateSql(); break; case DbActionType.Delete: BuildDeleteSql(); break; default: this.IsValid = false; this.Description = "意外的不能执行的动作码" + actionType.ToString(); break; } }