using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
namespace Hynix.Core
{
/// <summary>
/// Sql Command 실행을 도와주는 클래스
/// </summary>
public class SqlHelper
{
public static void ExcuteCommand(string strConn, string strCmd)
{
ExcuteCommand(strConn, strCmd, false, null);
}
public static void ExcuteCommand(SqlTransaction tran, string strCmd)
{
ExcuteCommand(tran, strCmd, false, null);
}
public static void ExcuteCommand(SqlTransaction tran, string strCmd, bool IsSP, SqlParameter[] oParams)
{
SqlCommand oCmd = new SqlCommand(strCmd, tran.Connection, tran);
oCmd.CommandTimeout = int.Parse(Config.Instance.GetValue("TIMEOUT"));
if (IsSP == true) { oCmd.CommandType = CommandType.StoredProcedure; }
if (oParams != null)
{
for (int i = 0; i < oParams.Length; i++)
{
oCmd.Parameters.Add(oParams[i]);
}
}
oCmd.ExecuteNonQuery();
}
public static void ExcuteCommand(string strConn, string strCmd, bool IsSP, SqlParameter[] oParams)
{
if (strConn.IndexOf("Connect Timeout") < 0)
{
strConn += ";Connect Timeout=" + Config.Instance.GetValue("TIMEOUT") + ";";
}
SqlConnection oConn = new SqlConnection(strConn);
SqlCommand oCmd = new SqlCommand(strCmd, oConn);
oCmd.CommandTimeout = int.Parse(Config.Instance.GetValue("TIMEOUT"));
if (IsSP==true)
{
oCmd.CommandType = CommandType.StoredProcedure;
if (oParams != null)
{
for (int i = 0; i < oParams.Length; i++)
{
oCmd.Parameters.Add(oParams[i]);
}
}
}
oConn.Open();
oCmd.ExecuteNonQuery();
oConn.Close();
}
public static DataSet ExcuteDataSet(string strConn, string strCmd)
{
return ExcuteDataSet(strConn, strCmd, false, null);
}
public static DataSet ExcuteDataSet(string strConn, string strCmd, bool IsSP, SqlParameter[] oParams)
{
if (strConn.IndexOf("Connect Timeout") < 0)
{
strConn += ";Connect Timeout=" + Config.Instance.GetValue("TIMEOUT") + ";";
}
SqlConnection oConn = new SqlConnection(strConn);
SqlCommand oCmd = new SqlCommand(strCmd, oConn);
oCmd.CommandTimeout = int.Parse(Config.Instance.GetValue("TIMEOUT"));
if (IsSP==true)
{
oCmd.CommandType = CommandType.StoredProcedure;
if (oParams != null)
{
for (int i = 0; i < oParams.Length; i++)
{
oCmd.Parameters.Add(oParams[i]);
}
}
}
SqlDataAdapter da = new SqlDataAdapter(oCmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}