using System;
//using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;
using System.Net.Sockets;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Data.OleDb;
//using SystemFramework;
namespace DataLinkMesWork
{
public partial class DataAccess
{
///
/// 创建增加数据用表
///
///
///
public static DataTable GetInsertTable(DataTable dt)
{
DataTable dt1;
DataRow row;
dt1 = dt.Clone();
for (int i = 0; i < dt.Rows.Count; i++)
{
row = dt1.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
row[j] = dt.Rows[i][j];
}
dt1.Rows.Add(row);
}
return dt1;
}
///
///
///
///
///
///
public static bool ExecuteDataTable_OleDb_Access1(string sql,out DataSet ds)
{
string ErrorMessage ;
return SQLCommon.ExecuteDataTable_OleDb(sql, ApplicationConfig.dbConnectionString_Access, out ds, out ErrorMessage);
}
///
/// 获取EXCEL的表 表名字列
///
/// Excel文件
/// 数据表
public static DataTable GetExcelTableName(string p_ExcelFile)
{
try
{
if (System.IO.File.Exists(p_ExcelFile))
{
OleDbConnection _ExcelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + p_ExcelFile);
_ExcelConn.Open();
DataTable _Table = _ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
_ExcelConn.Close();
return _Table;
}
return null;
}
catch
{
return null;
}
}
///
///
///
///
///
public static SqlConnection getConn(string strConnectionstring)
{
SqlConnection conn = new SqlConnection(strConnectionstring);
conn.Open();
return conn;
}
///
///
///
///
///
///
public static void TranExecuteNonQuery(SqlConnection conn, SqlTransaction mTrans, string sql)
{
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Transaction = mTrans;
cmd.ExecuteNonQuery();
}
///
/// 执行指定Sql 语句,返回所影响的行数。
///
/// 拼接出来的SQL语句。
///
/// 返回所影响的记录条数
/// ErrorMessage
/// True / False
public static bool ExecuteSql_count(string sql,string strConnectionstring, out int count,out string ErrorMessage)
{
SqlParameter[] thisParms = new SqlParameter[2];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@sql", sql);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@count", SqlDbType.Int, 32);
thisParms[1].Direction = ParameterDirection.Output;
count = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_executesql_count", strConnectionstring, ref thisParms, out ErrorMessage))
{
count = Convert.ToInt32(thisParms[1].Value.ToString());
return true;
}
return false;
}
///
/// 执行指定插入 Sql 语句,返回当前记录的新ID。
///
/// 拼接出来的SQL语句。
///
///
/// 返回当前记录的新ID
///
///
public static bool ExecuteSql_newID(string sql,string strConnectionstring, string tablename, out long newID, out string ErrorMessage)
{
SqlParameter[] thisParms = new SqlParameter[3];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@sql", sql);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@newID", SqlDbType.BigInt, 64);
thisParms[1].Direction = ParameterDirection.Output;
thisParms[2] = new System.Data.SqlClient.SqlParameter("@tablename", tablename);
thisParms[2].Direction = ParameterDirection.Input;
newID = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_insertRecord_newID", strConnectionstring, ref thisParms, out ErrorMessage))
{
newID = Convert.ToInt32(thisParms[1].Value.ToString());
return true;
}
return false;
}
///
///
///
///
///
///
///
///
///
public static bool ExecuteSql_newID(string sql,string strConnectionstring,string tablename, out int newID,out string ErrorMessage)
{
SqlParameter[] thisParms = new SqlParameter[3];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@sql", sql);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@newID", SqlDbType.Int, 32);
thisParms[1].Direction = ParameterDirection.Output;
thisParms[2] = new System.Data.SqlClient.SqlParameter("@tablename", tablename);
thisParms[2].Direction = ParameterDirection.Input;
newID = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_insertRecord_newID", strConnectionstring, ref thisParms, out ErrorMessage))
{
newID = Convert.ToInt32(thisParms[1].Value.ToString());
return true;
}
return false;
}
///
/// 根据输入参数,对指定表进行分页显示
///
/// 要进行分页的表/视图的名称
///
/// 表或者视图的主键
/// 进行过滤的条件
/// 需要显示的字段名称
/// 排序的条件,直接输入字段名 +desc/asc,例如id desc,name asc
/// 当前页的页码
/// 每一页的显示的数据量
/// 返回页码总数
/// 返回数据总数
///
/// 返回错误
/// True / False
public static bool ExecPageQuery(string tbname,string strConnectionstring, string fieldkey, string where, string fieldshow, string fieldorder, int pagecurrent, int pagesize, out int pagecount, out int itemcount,out DataSet ds, out string ErrorMessage)
{
SqlParameter[] thisParms = new SqlParameter[9];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@tbname", tbname);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@fieldkey", fieldkey);
thisParms[1].Direction = ParameterDirection.Input;
thisParms[2] = new System.Data.SqlClient.SqlParameter("@where", where);
thisParms[2].Direction = ParameterDirection.Input;
thisParms[3] = new System.Data.SqlClient.SqlParameter("@fieldshow",fieldshow);
thisParms[3].Direction = ParameterDirection.Input;
thisParms[4] = new System.Data.SqlClient.SqlParameter("@fieldorder", fieldorder);
thisParms[4].Direction = ParameterDirection.Input;
thisParms[5] = new System.Data.SqlClient.SqlParameter("@pagecurrent", pagecurrent);
thisParms[5].Direction = ParameterDirection.Input;
thisParms[6] = new System.Data.SqlClient.SqlParameter("@pagesize", pagesize);
thisParms[6].Direction = ParameterDirection.Input;
thisParms[7] = new System.Data.SqlClient.SqlParameter("@pagecount", SqlDbType.Int,32);
thisParms[7].Direction = ParameterDirection.Output;
thisParms[8] = new System.Data.SqlClient.SqlParameter("@itemcount", SqlDbType.Int,32);
thisParms[8].Direction = ParameterDirection.Output;
pagecount = 0;
itemcount = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_pagesplit", strConnectionstring, ref thisParms, out ds, out ErrorMessage))
{
pagecount = Convert.ToInt32(thisParms[7].Value.ToString());
itemcount = Convert.ToInt32(thisParms[8].Value.ToString());
return true;
}
return false;
}
public static bool ExecPageQueryMesWork(string tbname, string strConnectionstring, string fieldkey, string where, string fieldshow, string fieldorder, string filedgroup,int pagecurrent, int pagesize, out int pagecount, out int itemcount, out DataTable dt, out string ErrorMessage)
{
DataSet ds;
dt = new DataTable();
SqlParameter[] thisParms = new SqlParameter[9];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@tbname", tbname);
thisParms[1] = new System.Data.SqlClient.SqlParameter("@fieldkey", fieldkey);
thisParms[2] = new System.Data.SqlClient.SqlParameter("@where", where);
thisParms[3] = new System.Data.SqlClient.SqlParameter("@fieldshow", fieldshow);
thisParms[4] = new System.Data.SqlClient.SqlParameter("@fieldOrder", fieldorder);
thisParms[5] = new System.Data.SqlClient.SqlParameter("@PageCurrent", pagecurrent);
thisParms[6] = new System.Data.SqlClient.SqlParameter("@PageSize", pagesize);
thisParms[7] = new System.Data.SqlClient.SqlParameter("@PageCount", SqlDbType.Int, 32);
thisParms[8] = new System.Data.SqlClient.SqlParameter("@ItemCount", SqlDbType.Int, 32);
thisParms[7].Direction = ParameterDirection.Output;
thisParms[8].Direction = ParameterDirection.Output;
pagecount = 0;
itemcount = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_pagesplit", strConnectionstring, ref thisParms, out ds, out ErrorMessage))
{
dt = ds.Tables[0];
pagecount = Convert.ToInt32(thisParms[7].Value.ToString());
itemcount = Convert.ToInt32(thisParms[8].Value.ToString());
return true;
}
return false;
}
///
/// 根据输入参数,对指定表进行分页显示
///
/// 要进行分页的表/视图的名称
/// 表或者视图的主键
/// 表或者视图的主键
/// 进行过滤的条件
/// 需要显示的字段名称
/// 排序的条件,直接输入字段名 +desc/asc,例如id desc,name asc
/// 排序的条件,直接输入字段名 +desc/asc,例如id desc,name asc
/// 当前页的页码
/// 每一页的显示的数据量
/// 返回页码总数
/// 返回数据总数
///
/// 返回错误
/// True / False
public static bool ExecPageQuery_GroupBy(string tbname, string strConnectionstring, string fieldkey, string where, string fieldshow, string fieldorder,string filedgroup ,int pagecurrent, int pagesize, out int pagecount, out int itemcount, out DataSet ds, out string ErrorMessage)
{
SqlParameter[] thisParms = new SqlParameter[10];
thisParms[0] = new System.Data.SqlClient.SqlParameter("@tbname", tbname);
thisParms[0].Direction = ParameterDirection.Input;
thisParms[1] = new System.Data.SqlClient.SqlParameter("@fieldkey", fieldkey);
thisParms[1].Direction = ParameterDirection.Input;
thisParms[2] = new System.Data.SqlClient.SqlParameter("@where", where);
thisParms[2].Direction = ParameterDirection.Input;
thisParms[3] = new System.Data.SqlClient.SqlParameter("@fieldshow", fieldshow);
thisParms[3].Direction = ParameterDirection.Input;
thisParms[4] = new System.Data.SqlClient.SqlParameter("@fieldorder", fieldorder);
thisParms[4].Direction = ParameterDirection.Input;
thisParms[5] = new System.Data.SqlClient.SqlParameter("@filedgroup", filedgroup);
thisParms[5].Direction = ParameterDirection.Input;
thisParms[6] = new System.Data.SqlClient.SqlParameter("@pagecurrent", pagecurrent);
thisParms[6].Direction = ParameterDirection.Input;
thisParms[7] = new System.Data.SqlClient.SqlParameter("@pagesize", pagesize);
thisParms[7].Direction = ParameterDirection.Input;
thisParms[8] = new System.Data.SqlClient.SqlParameter("@pagecount", SqlDbType.Int, 32);
thisParms[8].Direction = ParameterDirection.Output;
thisParms[9] = new System.Data.SqlClient.SqlParameter("@itemcount", SqlDbType.Int, 32);
thisParms[9].Direction = ParameterDirection.Output;
pagecount = 0;
itemcount = 0;
ErrorMessage = "";
if (SQLCommon.ExecuteStoredProcedure("sp_xt_pagesplit_GroupBy", strConnectionstring, ref thisParms, out ds, out ErrorMessage))
{
pagecount = Convert.ToInt32(thisParms[8].Value.ToString());
itemcount = Convert.ToInt32(thisParms[9].Value.ToString());
return true;
}
return false;
}
///
///
///
///
///
///
///
///
///
///
public static bool addGrants(int intGrantee, int intGranteeType, int intObjectId, int intOjbectType,string strConnectionString,out string strErrmessage)
{
string sql = "insert into grants (grantee,granteetype,objectid,objecttype,createtime,creator,creatorid) values("
+intGrantee + ","
+intGranteeType + ","
+intObjectId + ","
+ intOjbectType + ",getdate(),'SYSTEM',0)";
if (ExecuteSQL(sql, strConnectionString, out strErrmessage))
{
return true;
}
return false;
}
///
///
///
///
///
///
///
///
///
///
public static bool delGrants(int intGrantee, int intGranteeType, int intObjectId, int intOjbectType, string strConnectionString, out string strErrmessage)
{
string sql = "update grants set deleted=1 where grantee=" + intGrantee + " and granteetype=" + intGranteeType + " and objectid=" + intObjectId + " and objecttype=" + intOjbectType;
if (ExecuteSQL(sql, strConnectionString, out strErrmessage))
{
return true;
}
return false;
}
///
/// 提供通用的调用存储过程的方法(增加数据的数据表的到数据库的调用)
///
/// 存储过程名称
/// 存储过程参数数组
/// 增加数据的数据表
///
public static bool ExecuteStoredProcedure(string procedureName, ref SqlParameter[] sqlParameters, DataTable dt)
{
string errorMessage;
return SQLCommon.ExecuteStoredProcedure( procedureName, ApplicationConfig.ConnectionString_MES, ref sqlParameters, dt, out errorMessage);
}
///
/// 提供通用的调用存储过程的方法(增加数据的数据表的到数据库的调用)
///
/// 存储过程名称
/// 存储过程参数数组
/// 布尔值,true表示该执行成功,false表示执行失败
public static bool ExecuteStoredProcedure(string procedureName, ref SqlParameter[] sqlParameters)
{
string errorMessage;
return SQLCommon.ExecuteStoredProcedure(procedureName, ApplicationConfig.ConnectionString_MES, ref sqlParameters, out errorMessage);
}
///
/// 提供通用的调用存储过程的方法(增加数据的数据表的到数据库的调用)
///
///
///
///
public static bool ExecuteStoredProcedure(string procedureName, out DataTable dt)
{
string errorMessage;
return SQLCommon.ExecuteStoredProcedure(procedureName, ApplicationConfig.ConnectionString_MES, out dt, out errorMessage);
}
///
/// 执行带参数的存储过程
///
///
///
///
///
public static bool ExecuteStoredProcedure(string procedureName, ref SqlParameter[] sqlParameters, out DataTable dt)
{
string errorMessage;
DataSet ds;
SQLCommon.ExecuteStoredProcedure(procedureName, ApplicationConfig.ConnectionString_MES, ref sqlParameters,out ds, out errorMessage);
try
{
dt = ds.Tables[0];
return true;
}
catch
{
dt = null;
return false;
}
}
}
}