public override Response Execute(Command wrapper) { var result = new Response() { IsSuccess = true, OutParams = new List <OutParam>() }; var db = CreateDatabase(); using (var conn = db.CreateConnection()) { try { if (conn.State != ConnectionState.Open) { conn.Open(); } /* * if (wrapper.AfterCommands.IsNotNullOrEmpty()) * { * var tran = conn.BeginTransaction(); * try * { * TryExcuteCommands(db, wrapper, result, conn, tran); * if (string.IsNullOrEmpty(result.Message)) * { * tran.Commit(); * } * else * { * tran.Rollback(); * } * } * catch (Exception ex) * { * tran.Rollback(); * * result.IsSuccess = false; * result.Message = ex.Message; * } * * }*/ if (result.IsSuccess) { var cmd = CommandConvert.ToSelectCommand(db, conn, null, wrapper.CmdType, wrapper.Text, wrapper.Params); result.Tag = cmd.ExecuteScalar(); Tool.SetListOutParam(cmd, result.OutParams); } conn.Close(); } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } } return(result); }
private static void TryExcuteCommands(Database db, Command wrapper, Response result, DbConnection conn, DbTransaction tran) { foreach (var proc in wrapper.AfterCommands) { var cmd = CommandConvert.ToSelectCommand(db, conn, tran, proc.CmdType, proc.Text, proc.Params); var message = cmd.GetProcMsgParam(); result.RowCount = cmd.ExecuteNonQuery(); if (message != null && !string.IsNullOrEmpty(message.Value as string)) { result.Message = message.Value as string; result.IsSuccess = false; break; } } }
private static void ExcuteCommands(Database db, List <Command> cmdList, Response result, DbConnection conn, DbTransaction tran) { foreach (var proc in cmdList) { var cmdProc = CommandConvert.ToSelectCommand(db, conn, tran, proc.CmdType, proc.Text, proc.Params); var message = cmdProc.GetProcMsgParam(); cmdProc.ExecuteNonQuery(); if (message != null && !string.IsNullOrEmpty(message.Value as string)) { result.Message = message.Value as string; result.IsSuccess = false; break; } } }
private static DataSet GetListData(Database db, Command wrapper, Response result, DbConnection conn, DbTransaction tran) { DbCommand cmd = CommandConvert.ToSelectCommand(db, conn, tran, wrapper.CmdType, wrapper.Text, wrapper.Params); if (cmd.CommandType == CommandType.StoredProcedure && (cmd.CommandText == Tool.Proc_PageData || cmd.CommandText.EndsWith(Tool.ProcPage_Suffix))) { db.AddOutParameter(cmd, Tool.Proc_Param_Count, DbType.Int32, 4); } var ds = db.ExecuteDataSet(cmd); if (cmd.Parameters.Contains(Tool.Proc_Param_Count)) { result.Tag = cmd.Parameters[Tool.Proc_Param_Count].Value; } Tool.SetListOutParam(cmd, result.OutParams); return(ds); }