public static T Exec<T>(string CmdStr, Dg<T> Ex, string ConStr = null, string CmdType = null, params object[] Ps)
{
T Tmp = default(T);
ConStr = string.IsNullOrEmpty(ConStr) ? Db.Ds : ConStr;
using (SqlConnection Con = new SqlConnection(ConStr))
{
SqlCommand Cmd = new SqlCommand(CmdStr, Con);
Cmd.CommandType = string.IsNullOrEmpty(CmdType) ? CommandType.StoredProcedure : CommandType.Text;
if (Con.State == ConnectionState.Closed)
{
Con.Open();
}
if (Ps.Length > 0)
{
if (Ps[0] is Array)
{
object o = null;
for (int i = 0; i < Ps.Length; i++)
{
object[] p = Ps[i] as object[];
bool tz = i > 0;
int n = p.Length - 2;
object[] pa = new object[tz ? n + 1 : n];
if (p.Length > 2)
{
Array.Copy(p, 2, pa, 0, n);
}
if (i > 0)
{
pa[pa.Length - 1] = o;
}
if (i != Ps.Length - 1)
{
Cmd.CommandText = p[0] as string;
Db.Ps(Cmd, pa);
o = (p[1] as Dg<object>)(Cmd);
}
else
{
Cmd.CommandText = CmdStr;
Cmd.Parameters.Clear();
Db.Ps(Cmd, p);
Cmd.Parameters.Add("o", o);
}
}
}
else
{
Db.Ps(Cmd, Ps);
}
}
Tmp = Ex(Cmd);
}
return Tmp;
}
{
T Tmp = default(T);
ConStr = string.IsNullOrEmpty(ConStr) ? Db.Ds : ConStr;
using (SqlConnection Con = new SqlConnection(ConStr))
{
SqlCommand Cmd = new SqlCommand(CmdStr, Con);
Cmd.CommandType = string.IsNullOrEmpty(CmdType) ? CommandType.StoredProcedure : CommandType.Text;
if (Con.State == ConnectionState.Closed)
{
Con.Open();
}
if (Ps.Length > 0)
{
if (Ps[0] is Array)
{
object o = null;
for (int i = 0; i < Ps.Length; i++)
{
object[] p = Ps[i] as object[];
bool tz = i > 0;
int n = p.Length - 2;
object[] pa = new object[tz ? n + 1 : n];
if (p.Length > 2)
{
Array.Copy(p, 2, pa, 0, n);
}
if (i > 0)
{
pa[pa.Length - 1] = o;
}
if (i != Ps.Length - 1)
{
Cmd.CommandText = p[0] as string;
Db.Ps(Cmd, pa);
o = (p[1] as Dg<object>)(Cmd);
}
else
{
Cmd.CommandText = CmdStr;
Cmd.Parameters.Clear();
Db.Ps(Cmd, p);
Cmd.Parameters.Add("o", o);
}
}
}
else
{
Db.Ps(Cmd, Ps);
}
}
Tmp = Ex(Cmd);
}
return Tmp;
}