Exemplo n.º 1
0
        public override Response Execute(Command wrapper)
        {
            var result = new Response()
            {
                IsSuccess = true, Entities = new List <EntityBase>()
            };

            try
            {
                var db = CreateDatabase();
                using (var conn = db.CreateConnection())
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    var cmd = CommandConvert.ToSelectSelfCommand(db, conn, null, wrapper.Text, wrapper.Params, Type.GetType(wrapper.EntityType), wrapper);
                    var ds  = db.ExecuteDataSet(cmd);
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        result.Entities = new List <EntityBase>();
                        MapConverter.ToList(ds.Tables[0], Type.GetType(wrapper.EntityType), result.Entities);
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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;
         }
     }
 }
Exemplo n.º 4
0
 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;
         }
     }
 }
Exemplo n.º 5
0
        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);
        }