diff --git a/Application/Code/CommonClass.cs.orig b/Application/Code/CommonClass.cs.orig new file mode 100644 index 0000000..e1ec63c --- /dev/null +++ b/Application/Code/CommonClass.cs.orig @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WorkStation +{ + public class CommonClass + { + } + public class BoxItem + { + private string _text = null; + private object _value = null; + public string Text { get { return this._text; } set { this._text = value; } } + public object Value { get { return this._value; } set { this._value = value; } } + public override string ToString() + { + return this._text; + } + } +} diff --git a/Application/Code/SqlHelper.cs b/Application/Code/SqlHelper.cs index 29c068f..b9bd1ba 100644 --- a/Application/Code/SqlHelper.cs +++ b/Application/Code/SqlHelper.cs @@ -175,7 +175,7 @@ private static void PrepareCommand(SqlCommand command, SqlConnection connection, /// public static int ExecuteNonQuery(string commandText) { - return ExecuteNonQuery(sqlConnectionStr,CommandType.Text,commandText); + return ExecuteNonQuery(sqlConnectionStr,CommandType.Text,commandText,(SqlParameter[])null); } /// /// 执行但参数的sql数据 @@ -187,21 +187,19 @@ public static int ExecuteNonQuery(string commandText, params SqlParameter[] comm { return ExecuteNonQuery(sqlConnectionStr, CommandType.Text, commandText,commandParameters); } + /// - /// 执行指定连接字符串,类型的SqlCommand. + /// 执行存储过程 /// - /// - /// 示例: - /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders"); - /// - /// 一个有效的数据库连接字符串 - /// 命令类型 (存储过程,命令文本, 其它.) - /// 存储过程名称或SQL语句 - /// 返回命令影响的行数 - public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText) + /// + /// + /// + /// + public static int ExecuteNonQuery(string spName, CommandType commandType, params SqlParameter[] parameterValues) { - return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null); - } + return ExecuteNonQuery(sqlConnectionStr, CommandType.StoredProcedure, spName, parameterValues); + } + /// /// 执行指定连接字符串,类型的SqlCommand.如果没有提供参数,不返回结果. @@ -225,16 +223,13 @@ public static int ExecuteNonQuery(string connectionString, CommandType commandTy } } + + /// - /// 执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数, + ///执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数, /// 此方法需要在参数缓存方法中探索参数并生成参数. /// - /// - /// 这个方法没有提供访问输出参数和返回值. - /// 示例: - /// int result = ExecuteNonQuery(connString, "PublishOrders", 24, 36); - /// - /// 一个有效的数据库连接字符串/param> + /// 一个有效的数据库连接字符串 /// 存储过程名称 /// 分配到存储过程输入参数的对象数组 /// 返回受影响的行数 @@ -338,14 +333,10 @@ public static int ExecuteNonQuery(SqlConnection connection, string spName, param /// /// 执行带事务的SqlCommand. /// - /// - /// 示例.: - /// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders"); - /// /// 一个有效的数据库连接对象 /// 命令类型(存储过程,命令文本或其它.) /// 存储过程名称或T-SQL语句 - /// 返回影响的行数/returns> + /// 返回影响的行数 public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText) { return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null); diff --git a/Application/Code/SqlHelper.cs.orig b/Application/Code/SqlHelper.cs.orig new file mode 100644 index 0000000..c0cf624 --- /dev/null +++ b/Application/Code/SqlHelper.cs.orig @@ -0,0 +1,4772 @@ +<<<<<<< HEAD +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Data; +using System.Data.SqlClient; +using System.Collections; +using System.Xml; + +namespace WorkStation +{ + /// + /// SqlServer数据访问帮助类 + /// + public sealed class SqlHelper + { + private static string sqlConnectionStr = "Data Source=192.168.1.221;Initial Catalog=Patrol;User Id=sa;Password=sa123"; + + #region 私有构造函数和方法 + private SqlHelper() + { + WorkStation.Properties.Settings wset = new Properties.Settings(); + sqlConnectionStr = wset.ConnectionString; + } + + /// + /// 将SqlParameter参数数组(参数值)分配给SqlCommand命令. + /// 这个方法将给任何一个参数分配DBNull.Value; + /// 该操作将阻止默认值的使用. + /// + /// 命令名 + /// SqlParameters数组 + private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters) + { + if (command == null) throw new ArgumentNullException("command"); + if (commandParameters != null) + { + foreach (SqlParameter p in commandParameters) + { + if (p != null) + { + // 检查未分配值的输出参数,将其分配以DBNull.Value. + if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) && + (p.Value == null)) + { + p.Value = DBNull.Value; + } + command.Parameters.Add(p); + } + } + } + } + + /// + /// 将DataRow类型的列值分配到SqlParameter参数数组. + /// + /// 要分配值的SqlParameter参数数组 + /// 将要分配给存储过程参数的DataRow + private static void AssignParameterValues(SqlParameter[] commandParameters, DataRow dataRow) + { + if ((commandParameters == null) || (dataRow == null)) + { + return; + } + int i = 0; + // 设置参数值 + foreach (SqlParameter commandParameter in commandParameters) + { + // 创建参数名称,如果不存在,只抛出一个异常. + if (commandParameter.ParameterName == null || + commandParameter.ParameterName.Length <= 1) + throw new Exception( + string.Format("请提供参数{0}一个有效的名称{1}.", i, commandParameter.ParameterName)); + // 从dataRow的表中获取为参数数组中数组名称的列的索引. + // 如果存在和参数名称相同的列,则将列值赋给当前名称的参数. + if (dataRow.Table.Columns.IndexOf(commandParameter.ParameterName.Substring(1)) != -1) + commandParameter.Value = dataRow[commandParameter.ParameterName.Substring(1)]; + i++; + } + } + + /// + /// 将一个对象数组分配给SqlParameter参数数组. + /// + /// 要分配值的SqlParameter参数数组 + /// 将要分配给存储过程参数的对象数组 + private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues) + { + if ((commandParameters == null) || (parameterValues == null)) + { + return; + } + // 确保对象数组个数与参数个数匹配,如果不匹配,抛出一个异常. + if (commandParameters.Length != parameterValues.Length) + { + throw new ArgumentException("参数值个数与参数不匹配."); + } + // 给参数赋值 + for (int i = 0, j = commandParameters.Length; i < j; i++) + { + // If the current array value derives from IDbDataParameter, then assign its Value property + if (parameterValues[i] is IDbDataParameter) + { + IDbDataParameter paramInstance = (IDbDataParameter)parameterValues[i]; + if (paramInstance.Value == null) + { + commandParameters[i].Value = DBNull.Value; + } + else + { + commandParameters[i].Value = paramInstance.Value; + } + } + else if (parameterValues[i] == null) + { + commandParameters[i].Value = DBNull.Value; + } + else + { + commandParameters[i].Value = parameterValues[i]; + } + } + } + + /// + /// 预处理用户提供的命令,数据库连接/事务/命令类型/参数 + /// + /// 要处理的SqlCommand + /// 数据库连接 + /// 一个有效的事务或者是null值 + /// 命令类型 (存储过程,命令文本, 其它.) + /// 存储过程名或都T-SQL命令文本 + /// 和命令相关联的SqlParameter参数数组,如果没有参数为'null' + /// true 如果连接是打开的,则为true,其它情况下为false. + private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection) + { + if (command == null) throw new ArgumentNullException("command"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + // If the provided connection is not open, we will open it + if (connection.State != ConnectionState.Open) + { + mustCloseConnection = true; + connection.Open(); + } + else + { + mustCloseConnection = false; + } + // 给命令分配一个数据库连接. + command.Connection = connection; + // 设置命令文本(存储过程名或SQL语句) + command.CommandText = commandText; + // 分配事务 + if (transaction != null) + { + if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + command.Transaction = transaction; + } + // 设置命令类型. + command.CommandType = commandType; + // 分配命令参数 + if (commandParameters != null) + { + AttachParameters(command, commandParameters); + } + return; + } + #endregion 私有构造函数和方法结束 + + #region ExecuteNonQuery命令 + /// + /// 执行SQL语句,返回受影响的行数 + /// + /// Sql语句 + /// + public static int ExecuteNonQuery(string commandText) + { + return ExecuteNonQuery(sqlConnectionStr,CommandType.Text,commandText); + } + /// + /// 执行但参数的sql数据 + /// + /// sql语句 + /// 参数 + /// + public static int ExecuteNonQuery(string commandText, params SqlParameter[] commandParameters) + { + return ExecuteNonQuery(sqlConnectionStr, CommandType.Text, commandText,commandParameters); + } + /// + /// 执行指定连接字符串,类型的SqlCommand. + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本, 其它.) + /// 存储过程名称或SQL语句 + /// 返回命令影响的行数 + public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText) + { + return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定连接字符串,类型的SqlCommand.如果没有提供参数,不返回结果. + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本, 其它.) + /// 存储过程名称或SQL语句 + /// SqlParameter参数数组 + /// 返回命令影响的行数 + public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + return ExecuteNonQuery(connection, commandType, commandText, commandParameters); + } + } + + /// + /// 执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数, + /// 此方法需要在参数缓存方法中探索参数并生成参数. + /// + /// + /// 这个方法没有提供访问输出参数和返回值. + /// 示例: + /// int result = ExecuteNonQuery(connString, "PublishOrders", 24, 36); + /// + /// 一个有效的数据库连接字符串/param> + /// 存储过程名称 + /// 分配到存储过程输入参数的对象数组 + /// 返回受影响的行数 + public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果存在参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从探索存储过程参数(加载到缓存)并分配给存储过程参数数组. + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数情况下 + return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令 + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteNonQuery(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令 + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// T存储过程名称或T-SQL语句 + /// SqlParamter参数数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // Finally, execute the command + int retval = cmd.ExecuteNonQuery(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return retval; + } + + /// + /// 执行指定数据库连接对象的命令,将对象数组的值赋给存储过程参数. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值 + /// 示例: + /// int result = ExecuteNonQuery(conn, "PublishOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程分配参数值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行带事务的SqlCommand. + /// + /// + /// 示例.: + /// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// 返回影响的行数/returns> + public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行带事务的SqlCommand(指定参数). + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// SqlParamter参数数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行 + int retval = cmd.ExecuteNonQuery(); + + // 清除参数集,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行带事务的SqlCommand(指定参数值). + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值 + /// 示例: + /// int result = ExecuteNonQuery(conn, trans, "PublishOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回受影响的行数 + public static int ExecuteNonQuery(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteNonQuery方法结束 + + #region ExecuteSqls + /// + /// 执行Sql语句数组 + /// + /// Sql数组 + /// + public static int ExecuteSqls(string[] strs) + { + int count = 0; + SqlConnection conn = new SqlConnection(sqlConnectionStr); + conn.Open(); + SqlTransaction tran = conn.BeginTransaction(); + SqlCommand command = new SqlCommand(); + command.Connection = conn; + try + { + foreach (string s in strs) + { + command.CommandType = CommandType.Text; + command.CommandText = s; + count = count + command.ExecuteNonQuery(); + } + tran.Commit(); + } + catch(Exception ex) + { + tran.Rollback(); + count = 0; + throw new ArgumentNullException(ex.Message); + } + finally + { + conn.Close(); + } + return count; + } + #endregion + + #region ExecuteDataset方法 + /// + /// 执行Sql语句,返回DataSet + /// + /// + /// + public static DataSet ExecuteDataset(string commandText) + { + return ExecuteDataset(sqlConnectionStr, CommandType.Text, commandText); + } + /// + /// 执行指定数据库连接字符串的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText) + { + return ExecuteDataset(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接字符串的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// SqlParamters参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + return ExecuteDataset(connection, commandType, commandText, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,直接提供参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值. + /// 示例: + /// DataSet ds = ExecuteDataset(connString, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中检索存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteDataset(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建SqlDataAdapter和DataSet. + using (SqlDataAdapter da = new SqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + // 填充DataSet. + da.Fill(ds); + + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return ds; + } + } + + /// + /// 执行指定数据库连接对象的命令,指定参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输入参数和返回值. + /// 示例.: + /// DataSet ds = ExecuteDataset(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 比缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定事务的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定事务的命令,指定参数,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建 DataAdapter & DataSet + using (SqlDataAdapter da = new SqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + da.Fill(ds); + cmd.Parameters.Clear(); + return ds; + } + } + + /// + /// 执行指定事务的命令,指定参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输入参数和返回值. + /// 示例.: + /// DataSet ds = ExecuteDataset(trans, "GetOrders", 24, 36); + /// + /// 事务 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteDataset数据集命令结束 + + #region ExecuteReader 数据阅读器 + /// + /// 枚举,标识数据库连接是由SqlHelper提供还是由调用者提供 + /// + private enum SqlConnectionOwnership + { + /// 由SqlHelper提供连接 + Internal, + /// 由调用者提供连接 + External + } + + /// + /// 执行Sql语句,返回数据阅读器 + /// + /// Sql语句 + /// + public static SqlDataReader ExecuteReader(string commandText) + { + return ExecuteReader(sqlConnectionStr,CommandType.Text,commandText); + } + /// + /// 执行指定数据库连接字符串的数据阅读器. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText) + { + return ExecuteReader(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的数据阅读器. + /// + /// + /// 如果是SqlHelper打开连接,当连接关闭DataReader也将关闭. + /// 如果是调用都打开连接,DataReader由调用都管理. + /// + /// 一个有效的数据库连接对象 + /// 一个有效的事务,或者为 'null' + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParameters参数数组,如果没有参数则为'null' + /// 标识数据库连接对象是由调用者提供还是由SqlHelper提供 + /// 返回包含结果集的SqlDataReader + private static SqlDataReader ExecuteReader(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, SqlConnectionOwnership connectionOwnership) + { + if (connection == null) throw new ArgumentNullException("connection"); + bool mustCloseConnection = false; + // 创建命令 + SqlCommand cmd = new SqlCommand(); + try + { + PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建数据阅读器 + SqlDataReader dataReader; + if (connectionOwnership == SqlConnectionOwnership.External) + { + dataReader = cmd.ExecuteReader(); + } + else + { + dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); + } + + // 清除参数,以便再次使用.. + // HACK: There is a problem here, the output parameter values are fletched + // when the reader is closed, so if the parameters are detached from the command + // then the SqlReader can磘 set its values. + // When this happen, the parameters can磘 be used again in other command. + bool canClear = true; + foreach (SqlParameter commandParameter in cmd.Parameters) + { + if (commandParameter.Direction != ParameterDirection.Input) + canClear = false; + } + + if (canClear) + { + cmd.Parameters.Clear(); + } + return dataReader; + } + catch + { + if (mustCloseConnection) + connection.Close(); + throw; + } + } + + /// + /// 执行指定数据库连接字符串的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组(new SqlParameter("@prodid", 24)) + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + SqlConnection connection = null; + try + { + connection = new SqlConnection(connectionString); + connection.Open(); + return ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal); + } + catch + { + // If we fail to return the SqlDatReader, we need to close the connection ourselves + if (connection != null) connection.Close(); + throw; + } + + } + + /// + /// 执行指定数据库连接字符串的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteReader(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的数据阅读器. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteReader(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 命令类型 (存储过程,命令文本或其它) + /// SqlParamter参数数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + return ExecuteReader(connection, (SqlTransaction)null, commandType, commandText, commandParameters, SqlConnectionOwnership.External); + } + + /// + /// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// T存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteReader(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + return ExecuteReader(transaction.Connection, transaction, commandType, commandText, commandParameters, SqlConnectionOwnership.External); + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, "GetOrders", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteReader数据阅读器 + + #region ExecuteScalar 返回结果集中的第一行第一列 + /// + /// 执行Sql语句,返回结果集的第一行第一列 + /// + /// Sql语句 + /// + public static object ExecuteScalar(string commandText) + { + return ExecuteScalar(sqlConnectionStr,CommandType.Text,commandText); + } + /// + /// 执行指定数据库连接字符串的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接字符串的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + return ExecuteScalar(connection, commandType, commandText, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, "GetOrderCount", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行SqlCommand命令,并返回结果. + object retval = cmd.ExecuteScalar(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return retval; + } + + /// + /// 执行指定数据库连接对象的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, "GetOrderCount", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库事务的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库事务的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行SqlCommand命令,并返回结果. + object retval = cmd.ExecuteScalar(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行指定数据库事务的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, "GetOrderCount", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // PPull the parameters for this stored procedure from the parameter cache () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteScalar + + #region ExecuteXmlReader XML阅读器 + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteXmlReader(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 分配给命令的SqlParamter参数数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + bool mustCloseConnection = false; + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + try + { + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + XmlReader retval = cmd.ExecuteXmlReader(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + catch + { + if (mustCloseConnection) + connection.Close(); + throw; + } + } + + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 using "FOR XML AUTO" + /// 分配给存储过程输入参数的对象数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteXmlReader(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 分配给命令的SqlParamter参数数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + XmlReader retval = cmd.ExecuteXmlReader(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, "GetOrders", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteXmlReader 阅读器结束 + + #region FillDataset 填充数据集 + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + public static void FillDataset(string connectionString, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, commandType, commandText, dataSet, tableNames); + } + } + + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集.指定命令参数. + /// + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(string connectionString, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, commandType, commandText, dataSet, tableNames, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, 24); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(string connectionString, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, spName, dataSet, tableNames, parameterValues); + } + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(SqlConnection connection, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames) + { + FillDataset(connection, commandType, commandText, dataSet, tableNames, null); + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定参数. + /// + /// + /// 示例: + /// FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + public static void FillDataset(SqlConnection connection, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + FillDataset(connection, null, commandType, commandText, dataSet, tableNames, commandParameters); + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(conn, "GetOrders", ds, new string[] {"orders"}, 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(SqlConnection connection, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); + } + else + { + // 没有参数值 + FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames); + } + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(SqlTransaction transaction, CommandType commandType, + string commandText, + DataSet dataSet, string[] tableNames) + { + FillDataset(transaction, commandType, commandText, dataSet, tableNames, null); + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集,指定参数. + /// + /// + /// 示例: + /// FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + public static void FillDataset(SqlTransaction transaction, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + FillDataset(transaction.Connection, transaction, commandType, commandText, dataSet, tableNames, commandParameters); + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(trans, "GetOrders", ds, new string[]{"orders"}, 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(SqlTransaction transaction, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); + } + else + { + // 没有参数值 + FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames); + } + } + + /// + /// [私有方法][内部调用]执行指定数据库连接对象/事务的命令,映射数据表并填充数据集,DataSet/TableNames/SqlParameters. + /// + /// + /// 示例: + /// FillDataset(conn, trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand command = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command)) + { + + // 追加表映射 + if (tableNames != null && tableNames.Length > 0) + { + string tableName = "Table"; + for (int index = 0; index < tableNames.Length; index++) + { + if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames"); + dataAdapter.TableMappings.Add(tableName, tableNames[index]); + tableName += (index + 1).ToString(); + } + } + + // 填充数据集使用默认表名称 + dataAdapter.Fill(dataSet); + // 清除参数,以便再次使用. + command.Parameters.Clear(); + } + if (mustCloseConnection) + connection.Close(); + } + #endregion + + #region UpdateDataset 更新数据集 + /// + /// 执行数据集更新到数据库,指定inserted, updated, or deleted命令. + /// + /// + /// 示例: + /// UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order"); + /// + /// [追加记录]一个有效的T-SQL语句或存储过程 + /// [删除记录]一个有效的T-SQL语句或存储过程 + /// [更新记录]一个有效的T-SQL语句或存储过程 + /// 要更新到数据库的DataSet + /// 要更新到数据库的DataTable + public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName) + { + if (insertCommand == null) throw new ArgumentNullException("insertCommand"); + if (deleteCommand == null) throw new ArgumentNullException("deleteCommand"); + if (updateCommand == null) throw new ArgumentNullException("updateCommand"); + if (tableName == null || tableName.Length == 0) throw new ArgumentNullException("tableName"); + // 创建SqlDataAdapter,当操作完成后释放. + using (SqlDataAdapter dataAdapter = new SqlDataAdapter()) + { + // 设置数据适配器命令 + dataAdapter.UpdateCommand = updateCommand; + dataAdapter.InsertCommand = insertCommand; + dataAdapter.DeleteCommand = deleteCommand; + // 更新数据集改变到数据库 + dataAdapter.Update(dataSet, tableName); + // 提交所有改变到数据集. + dataSet.AcceptChanges(); + } + } + #endregion + + #region CreateCommand 创建一条SqlCommand命令 + /// + /// 创建SqlCommand命令,指定数据库连接对象,存储过程名和参数. + /// + /// + /// 示例: + /// SqlCommand command = CreateCommand(conn, "AddCustomer", "CustomerID", "CustomerName"); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 源表的列名称数组 + /// 返回SqlCommand命令 + public static SqlCommand CreateCommand(SqlConnection connection, string spName, params string[] sourceColumns) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 创建命令 + SqlCommand cmd = new SqlCommand(spName, connection); + cmd.CommandType = CommandType.StoredProcedure; + // 如果有参数值 + if ((sourceColumns != null) && (sourceColumns.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 将源表的列到映射到DataSet命令中. + for (int index = 0; index < sourceColumns.Length; index++) + commandParameters[index].SourceColumn = sourceColumns[index]; + // Attach the discovered parameters to the SqlCommand object + AttachParameters(cmd, commandParameters); + } + return cmd; + } + #endregion + + #region ExecuteNonQueryTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // Sf the row has values, the store procedure parameters must be initialized + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteDatasetTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + public static DataSet ExecuteDatasetTypedParams(string connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + //如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + /// + public static DataSet ExecuteDatasetTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + public static DataSet ExecuteDatasetTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteReaderTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteScalarTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteXmlReaderTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReaderTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteXmlReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReaderTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + } + + /// + /// SqlHelperParameterCache提供缓存存储过程参数,并能够在运行时从存储过程中探索参数. + /// + public sealed class SqlHelperParameterCache + { + #region 私有方法,字段,构造函数 + // 私有构造函数,妨止类被实例化. + private SqlHelperParameterCache() { } + // 这个方法要注意 + private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable()); + /// + /// 探索运行时的存储过程,返回SqlParameter参数数组. + /// 初始化参数值为 DBNull.Value. + /// + /// 一个有效的数据库连接 + /// 存储过程名称 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + private static SqlParameter[] DiscoverSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + SqlCommand cmd = new SqlCommand(spName, connection); + cmd.CommandType = CommandType.StoredProcedure; + connection.Open(); + // 检索cmd指定的存储过程的参数信息,并填充到cmd的Parameters参数集中. + SqlCommandBuilder.DeriveParameters(cmd); + connection.Close(); + // 如果不包含返回值参数,将参数集中的每一个参数删除. + if (!includeReturnValueParameter) + { + cmd.Parameters.RemoveAt(0); + } + + // 创建参数数组 + SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count]; + // 将cmd的Parameters参数集复制到discoveredParameters数组. + cmd.Parameters.CopyTo(discoveredParameters, 0); + // 初始化参数值为 DBNull.Value. + foreach (SqlParameter discoveredParameter in discoveredParameters) + { + discoveredParameter.Value = DBNull.Value; + } + return discoveredParameters; + } + + /// + /// SqlParameter参数数组的深层拷贝. + /// + /// 原始参数数组 + /// 返回一个同样的参数数组 + private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters) + { + SqlParameter[] clonedParameters = new SqlParameter[originalParameters.Length]; + for (int i = 0, j = originalParameters.Length; i < j; i++) + { + clonedParameters[i] = (SqlParameter)((ICloneable)originalParameters[i]).Clone(); + } + return clonedParameters; + } + #endregion 私有方法,字段,构造函数结束 + + #region 缓存方法 + /// + /// 追加参数数组到缓存. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名或SQL语句 + /// 要缓存的参数数组 + public static void CacheParameterSet(string connectionString, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + string hashKey = connectionString + ":" + commandText; + paramCache[hashKey] = commandParameters; + } + + /// + /// 从缓存中获取参数数组. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名或SQL语句 + /// 参数数组 + public static SqlParameter[] GetCachedParameterSet(string connectionString, string commandText) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + string hashKey = connectionString + ":" + commandText; + SqlParameter[] cachedParameters = paramCache[hashKey] as SqlParameter[]; + if (cachedParameters == null) + { + return null; + } + else + { + return CloneParameters(cachedParameters); + } + } + #endregion 缓存方法结束 + + #region 检索指定的存储过程的参数集 + /// + /// 返回指定的存储过程的参数集 + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名 + /// 返回SqlParameter参数数组 + public static SqlParameter[] GetSpParameterSet(string connectionString, string spName) + { + return GetSpParameterSet(connectionString, spName, false); + } + + /// + /// 返回指定的存储过程的参数集 + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符. + /// 存储过程名 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + public static SqlParameter[] GetSpParameterSet(string connectionString, string spName, bool includeReturnValueParameter) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + using (SqlConnection connection = new SqlConnection(connectionString)) + { + return GetSpParameterSetInternal(connection, spName, includeReturnValueParameter); + } + } + + /// + /// [内部]返回指定的存储过程的参数集(使用连接对象). + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名 + /// 返回SqlParameter参数数组 + internal static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName) + { + return GetSpParameterSet(connection, spName, false); + } + + /// + /// [内部]返回指定的存储过程的参数集(使用连接对象) + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// + /// 是否包含返回值参数 + /// + /// 返回SqlParameter参数数组 + internal static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + using (SqlConnection clonedConnection = (SqlConnection)((ICloneable)connection).Clone()) + { + return GetSpParameterSetInternal(clonedConnection, spName, includeReturnValueParameter); + } + } + + /// + /// [私有]返回指定的存储过程的参数集(使用连接对象) + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + private static SqlParameter[] GetSpParameterSetInternal(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + string hashKey = connection.ConnectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter" : ""); + SqlParameter[] cachedParameters; + + cachedParameters = paramCache[hashKey] as SqlParameter[]; + if (cachedParameters == null) + { + SqlParameter[] spParameters = DiscoverSpParameterSet(connection, spName, includeReturnValueParameter); + paramCache[hashKey] = spParameters; + cachedParameters = spParameters; + } + + return CloneParameters(cachedParameters); + } + + #endregion 参数集检索结束 + } +} +======= +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Data; +using System.Data.SqlClient; +using System.Collections; +using System.Xml; + +namespace WorkStation +{ + /// + /// SqlServer数据访问帮助类 + /// + public sealed class SqlHelper + { + private static string sqlConnectionStr = "Data Source=192.168.1.221;Initial Catalog=Patrol;User Id=sa;Password=sa123"; + + #region 私有构造函数和方法 + private SqlHelper() + { + WorkStation.Properties.Settings wset = new Properties.Settings(); + sqlConnectionStr = wset.ConnectionString; + } + + /// + /// 将SqlParameter参数数组(参数值)分配给SqlCommand命令. + /// 这个方法将给任何一个参数分配DBNull.Value; + /// 该操作将阻止默认值的使用. + /// + /// 命令名 + /// SqlParameters数组 + private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters) + { + if (command == null) throw new ArgumentNullException("command"); + if (commandParameters != null) + { + foreach (SqlParameter p in commandParameters) + { + if (p != null) + { + // 检查未分配值的输出参数,将其分配以DBNull.Value. + if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) && + (p.Value == null)) + { + p.Value = DBNull.Value; + } + command.Parameters.Add(p); + } + } + } + } + + /// + /// 将DataRow类型的列值分配到SqlParameter参数数组. + /// + /// 要分配值的SqlParameter参数数组 + /// 将要分配给存储过程参数的DataRow + private static void AssignParameterValues(SqlParameter[] commandParameters, DataRow dataRow) + { + if ((commandParameters == null) || (dataRow == null)) + { + return; + } + int i = 0; + // 设置参数值 + foreach (SqlParameter commandParameter in commandParameters) + { + // 创建参数名称,如果不存在,只抛出一个异常. + if (commandParameter.ParameterName == null || + commandParameter.ParameterName.Length <= 1) + throw new Exception( + string.Format("请提供参数{0}一个有效的名称{1}.", i, commandParameter.ParameterName)); + // 从dataRow的表中获取为参数数组中数组名称的列的索引. + // 如果存在和参数名称相同的列,则将列值赋给当前名称的参数. + if (dataRow.Table.Columns.IndexOf(commandParameter.ParameterName.Substring(1)) != -1) + commandParameter.Value = dataRow[commandParameter.ParameterName.Substring(1)]; + i++; + } + } + + /// + /// 将一个对象数组分配给SqlParameter参数数组. + /// + /// 要分配值的SqlParameter参数数组 + /// 将要分配给存储过程参数的对象数组 + private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues) + { + if ((commandParameters == null) || (parameterValues == null)) + { + return; + } + // 确保对象数组个数与参数个数匹配,如果不匹配,抛出一个异常. + if (commandParameters.Length != parameterValues.Length) + { + throw new ArgumentException("参数值个数与参数不匹配."); + } + // 给参数赋值 + for (int i = 0, j = commandParameters.Length; i < j; i++) + { + // If the current array value derives from IDbDataParameter, then assign its Value property + if (parameterValues[i] is IDbDataParameter) + { + IDbDataParameter paramInstance = (IDbDataParameter)parameterValues[i]; + if (paramInstance.Value == null) + { + commandParameters[i].Value = DBNull.Value; + } + else + { + commandParameters[i].Value = paramInstance.Value; + } + } + else if (parameterValues[i] == null) + { + commandParameters[i].Value = DBNull.Value; + } + else + { + commandParameters[i].Value = parameterValues[i]; + } + } + } + + /// + /// 预处理用户提供的命令,数据库连接/事务/命令类型/参数 + /// + /// 要处理的SqlCommand + /// 数据库连接 + /// 一个有效的事务或者是null值 + /// 命令类型 (存储过程,命令文本, 其它.) + /// 存储过程名或都T-SQL命令文本 + /// 和命令相关联的SqlParameter参数数组,如果没有参数为'null' + /// true 如果连接是打开的,则为true,其它情况下为false. + private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection) + { + if (command == null) throw new ArgumentNullException("command"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + // If the provided connection is not open, we will open it + if (connection.State != ConnectionState.Open) + { + mustCloseConnection = true; + connection.Open(); + } + else + { + mustCloseConnection = false; + } + // 给命令分配一个数据库连接. + command.Connection = connection; + // 设置命令文本(存储过程名或SQL语句) + command.CommandText = commandText; + // 分配事务 + if (transaction != null) + { + if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + command.Transaction = transaction; + } + // 设置命令类型. + command.CommandType = commandType; + // 分配命令参数 + if (commandParameters != null) + { + AttachParameters(command, commandParameters); + } + return; + } + #endregion 私有构造函数和方法结束 + + #region ExecuteNonQuery命令 + /// + /// 执行SQL语句,返回受影响的行数 + /// + /// Sql语句 + /// + public static int ExecuteNonQuery(string commandText) + { + return ExecuteNonQuery(sqlConnectionStr,CommandType.Text,commandText,(SqlParameter[])null); + } + /// + /// 执行但参数的sql数据 + /// + /// sql语句 + /// 参数 + /// + public static int ExecuteNonQuery(string commandText, params SqlParameter[] commandParameters) + { + return ExecuteNonQuery(sqlConnectionStr, CommandType.Text, commandText,commandParameters); + } + + /// + /// 执行存储过程 + /// + /// + /// + /// + /// + public static int ExecuteNonQuery(string spName, CommandType commandType, params SqlParameter[] parameterValues) + { + return ExecuteNonQuery(sqlConnectionStr, CommandType.StoredProcedure, spName, parameterValues); + } + + + /// + /// 执行指定连接字符串,类型的SqlCommand.如果没有提供参数,不返回结果. + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本, 其它.) + /// 存储过程名称或SQL语句 + /// SqlParameter参数数组 + /// 返回命令影响的行数 + public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + return ExecuteNonQuery(connection, commandType, commandText, commandParameters); + } + } + + + + /// + ///执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数, + /// 此方法需要在参数缓存方法中探索参数并生成参数. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 分配到存储过程输入参数的对象数组 + /// 返回受影响的行数 + public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果存在参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从探索存储过程参数(加载到缓存)并分配给存储过程参数数组. + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数情况下 + return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令 + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteNonQuery(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令 + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// T存储过程名称或T-SQL语句 + /// SqlParamter参数数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // Finally, execute the command + int retval = cmd.ExecuteNonQuery(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return retval; + } + + /// + /// 执行指定数据库连接对象的命令,将对象数组的值赋给存储过程参数. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值 + /// 示例: + /// int result = ExecuteNonQuery(conn, "PublishOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程分配参数值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行带事务的SqlCommand. + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行带事务的SqlCommand(指定参数). + /// + /// + /// 示例: + /// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型(存储过程,命令文本或其它.) + /// 存储过程名称或T-SQL语句 + /// SqlParamter参数数组 + /// 返回影响的行数 + public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行 + int retval = cmd.ExecuteNonQuery(); + + // 清除参数集,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行带事务的SqlCommand(指定参数值). + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值 + /// 示例: + /// int result = ExecuteNonQuery(conn, trans, "PublishOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回受影响的行数 + public static int ExecuteNonQuery(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteNonQuery方法结束 + + #region ExecuteSqls + /// + /// 执行Sql语句数组 + /// + /// Sql数组 + /// + public static int ExecuteSqls(string[] strs) + { + int count = 0; + SqlConnection conn = new SqlConnection(sqlConnectionStr); + conn.Open(); + SqlTransaction tran = conn.BeginTransaction(); + SqlCommand command = new SqlCommand(); + command.Connection = conn; + try + { + foreach (string s in strs) + { + command.CommandType = CommandType.Text; + command.CommandText = s; + count = count + command.ExecuteNonQuery(); + } + tran.Commit(); + } + catch(Exception ex) + { + tran.Rollback(); + count = 0; + throw new ArgumentNullException(ex.Message); + } + finally + { + conn.Close(); + } + return count; + } + #endregion + + #region ExecuteDataset方法 + /// + /// 执行Sql语句,返回DataSet + /// + /// + /// + public static DataSet ExecuteDataset(string commandText) + { + return ExecuteDataset(sqlConnectionStr, CommandType.Text, commandText); + } + /// + /// 执行指定数据库连接字符串的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText) + { + return ExecuteDataset(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接字符串的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// SqlParamters参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + return ExecuteDataset(connection, commandType, commandText, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,直接提供参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值. + /// 示例: + /// DataSet ds = ExecuteDataset(connString, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中检索存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteDataset(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建SqlDataAdapter和DataSet. + using (SqlDataAdapter da = new SqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + // 填充DataSet. + da.Fill(ds); + + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return ds; + } + } + + /// + /// 执行指定数据库连接对象的命令,指定参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输入参数和返回值. + /// 示例.: + /// DataSet ds = ExecuteDataset(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 比缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定事务的命令,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定事务的命令,指定参数,返回DataSet. + /// + /// + /// 示例: + /// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建 DataAdapter & DataSet + using (SqlDataAdapter da = new SqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + da.Fill(ds); + cmd.Parameters.Clear(); + return ds; + } + } + + /// + /// 执行指定事务的命令,指定参数值,返回DataSet. + /// + /// + /// 此方法不提供访问存储过程输入参数和返回值. + /// 示例.: + /// DataSet ds = ExecuteDataset(trans, "GetOrders", 24, 36); + /// + /// 事务 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet + public static DataSet ExecuteDataset(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数 + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数分配值 + AssignParameterValues(commandParameters, parameterValues); + return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteDataset(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteDataset数据集命令结束 + + #region ExecuteReader 数据阅读器 + /// + /// 枚举,标识数据库连接是由SqlHelper提供还是由调用者提供 + /// + private enum SqlConnectionOwnership + { + /// 由SqlHelper提供连接 + Internal, + /// 由调用者提供连接 + External + } + + /// + /// 执行Sql语句,返回数据阅读器 + /// + /// Sql语句 + /// + public static SqlDataReader ExecuteReader(string commandText) + { + return ExecuteReader(sqlConnectionStr,CommandType.Text,commandText); + } + /// + /// 执行指定数据库连接字符串的数据阅读器. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText) + { + return ExecuteReader(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的数据阅读器. + /// + /// + /// 如果是SqlHelper打开连接,当连接关闭DataReader也将关闭. + /// 如果是调用都打开连接,DataReader由调用都管理. + /// + /// 一个有效的数据库连接对象 + /// 一个有效的事务,或者为 'null' + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParameters参数数组,如果没有参数则为'null' + /// 标识数据库连接对象是由调用者提供还是由SqlHelper提供 + /// 返回包含结果集的SqlDataReader + private static SqlDataReader ExecuteReader(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, SqlConnectionOwnership connectionOwnership) + { + if (connection == null) throw new ArgumentNullException("connection"); + bool mustCloseConnection = false; + // 创建命令 + SqlCommand cmd = new SqlCommand(); + try + { + PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 创建数据阅读器 + SqlDataReader dataReader; + if (connectionOwnership == SqlConnectionOwnership.External) + { + dataReader = cmd.ExecuteReader(); + } + else + { + dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); + } + + // 清除参数,以便再次使用.. + // HACK: There is a problem here, the output parameter values are fletched + // when the reader is closed, so if the parameters are detached from the command + // then the SqlReader can磘 set its values. + // When this happen, the parameters can磘 be used again in other command. + bool canClear = true; + foreach (SqlParameter commandParameter in cmd.Parameters) + { + if (commandParameter.Direction != ParameterDirection.Input) + canClear = false; + } + + if (canClear) + { + cmd.Parameters.Clear(); + } + return dataReader; + } + catch + { + if (mustCloseConnection) + connection.Close(); + throw; + } + } + + /// + /// 执行指定数据库连接字符串的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// SqlParamter参数数组(new SqlParameter("@prodid", 24)) + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + SqlConnection connection = null; + try + { + connection = new SqlConnection(connectionString); + connection.Open(); + return ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal); + } + catch + { + // If we fail to return the SqlDatReader, we need to close the connection ourselves + if (connection != null) connection.Close(); + throw; + } + + } + + /// + /// 执行指定数据库连接字符串的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// 示例: + /// SqlDataReader dr = ExecuteReader(connString, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteReader(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的数据阅读器. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText) + { + return ExecuteReader(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 命令类型 (存储过程,命令文本或其它) + /// SqlParamter参数数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + return ExecuteReader(connection, (SqlTransaction)null, commandType, commandText, commandParameters, SqlConnectionOwnership.External); + } + + /// + /// [调用者方式]执行指定数据库连接对象的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// 示例: + /// SqlDataReader dr = ExecuteReader(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// T存储过程名 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return ExecuteReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText) + { + return ExecuteReader(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数. + /// + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + return ExecuteReader(transaction.Connection, transaction, commandType, commandText, commandParameters, SqlConnectionOwnership.External); + } + + /// + /// [调用者方式]执行指定数据库事务的数据阅读器,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// SqlDataReader dr = ExecuteReader(trans, "GetOrders", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReader(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + AssignParameterValues(commandParameters, parameterValues); + return ExecuteReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteReader数据阅读器 + + #region ExecuteScalar 返回结果集中的第一行第一列 + /// + /// 执行Sql语句,返回结果集的第一行第一列 + /// + /// Sql语句 + /// + public static object ExecuteScalar(string commandText) + { + return ExecuteScalar(sqlConnectionStr,CommandType.Text,commandText); + } + /// + /// 执行指定数据库连接字符串的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(connectionString, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接字符串的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + return ExecuteScalar(connection, commandType, commandText, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(connString, "GetOrderCount", 24, 36); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(string connectionString, string spName, params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库连接对象的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行SqlCommand命令,并返回结果. + object retval = cmd.ExecuteScalar(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + if (mustCloseConnection) + connection.Close(); + return retval; + } + + /// + /// 执行指定数据库连接对象的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(conn, "GetOrderCount", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库事务的命令,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteScalar(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库事务的命令,指定参数,返回结果集中的第一行第一列. + /// + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行SqlCommand命令,并返回结果. + object retval = cmd.ExecuteScalar(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行指定数据库事务的命令,指定参数值,返回结果集中的第一行第一列. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// int orderCount = (int)ExecuteScalar(trans, "GetOrderCount", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalar(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // PPull the parameters for this stored procedure from the parameter cache () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteScalar(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteScalar(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteScalar + + #region ExecuteXmlReader XML阅读器 + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteXmlReader(connection, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 分配给命令的SqlParamter参数数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + bool mustCloseConnection = false; + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + try + { + PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + XmlReader retval = cmd.ExecuteXmlReader(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + catch + { + if (mustCloseConnection) + connection.Close(); + throw; + } + } + + /// + /// 执行指定数据库连接对象的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(conn, "GetOrders", 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 using "FOR XML AUTO" + /// 分配给存储过程输入参数的对象数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlConnection connection, string spName, params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders"); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText) + { + // 执行参数为空的方法 + return ExecuteXmlReader(transaction, commandType, commandText, (SqlParameter[])null); + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数. + /// + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 using "FOR XML AUTO" + /// 分配给命令的SqlParamter参数数组 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand cmd = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + XmlReader retval = cmd.ExecuteXmlReader(); + + // 清除参数,以便再次使用. + cmd.Parameters.Clear(); + return retval; + } + + /// + /// 执行指定数据库事务的SqlCommand命令,并产生一个XmlReader对象做为结果集返回,指定参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// XmlReader r = ExecuteXmlReader(trans, "GetOrders", 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 分配给存储过程输入参数的对象数组 + /// 返回一个包含结果集的DataSet. + public static XmlReader ExecuteXmlReader(SqlTransaction transaction, string spName, params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + // 没有参数值 + return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion ExecuteXmlReader 阅读器结束 + + #region FillDataset 填充数据集 + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + public static void FillDataset(string connectionString, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, commandType, commandText, dataSet, tableNames); + } + } + + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集.指定命令参数. + /// + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接字符串 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 分配给命令的SqlParamter参数数组 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(string connectionString, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, commandType, commandText, dataSet, tableNames, commandParameters); + } + } + + /// + /// 执行指定数据库连接字符串的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(connString, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, 24); + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(string connectionString, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建并打开数据库连接对象,操作完成释放对象. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + // 调用指定数据库连接字符串重载方法. + FillDataset(connection, spName, dataSet, tableNames, parameterValues); + } + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(SqlConnection connection, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames) + { + FillDataset(connection, commandType, commandText, dataSet, tableNames, null); + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定参数. + /// + /// + /// 示例: + /// FillDataset(conn, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + public static void FillDataset(SqlConnection connection, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + FillDataset(connection, null, commandType, commandText, dataSet, tableNames, commandParameters); + } + + /// + /// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(conn, "GetOrders", ds, new string[] {"orders"}, 24, 36); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(SqlConnection connection, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); + } + else + { + // 没有参数值 + FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames); + } + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集. + /// + /// + /// 示例: + /// FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + public static void FillDataset(SqlTransaction transaction, CommandType commandType, + string commandText, + DataSet dataSet, string[] tableNames) + { + FillDataset(transaction, commandType, commandText, dataSet, tableNames, null); + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集,指定参数. + /// + /// + /// 示例: + /// FillDataset(trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + public static void FillDataset(SqlTransaction transaction, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + FillDataset(transaction.Connection, transaction, commandType, commandText, dataSet, tableNames, commandParameters); + } + + /// + /// 执行指定数据库事务的命令,映射数据表并填充数据集,指定存储过程参数值. + /// + /// + /// 此方法不提供访问存储过程输出参数和返回值参数. + /// + /// 示例: + /// FillDataset(trans, "GetOrders", ds, new string[]{"orders"}, 24, 36); + /// + /// 一个有效的连接事务 + /// 存储过程名称 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给存储过程输入参数的对象数组 + public static void FillDataset(SqlTransaction transaction, string spName, + DataSet dataSet, string[] tableNames, + params object[] parameterValues) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果有参数值 + if ((parameterValues != null) && (parameterValues.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + // 给存储过程参数赋值 + AssignParameterValues(commandParameters, parameterValues); + // 调用重载方法 + FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); + } + else + { + // 没有参数值 + FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames); + } + } + + /// + /// [私有方法][内部调用]执行指定数据库连接对象/事务的命令,映射数据表并填充数据集,DataSet/TableNames/SqlParameters. + /// + /// + /// 示例: + /// FillDataset(conn, trans, CommandType.StoredProcedure, "GetOrders", ds, new string[] {"orders"}, new SqlParameter("@prodid", 24)); + /// + /// 一个有效的数据库连接对象 + /// 一个有效的连接事务 + /// 命令类型 (存储过程,命令文本或其它) + /// 存储过程名称或T-SQL语句 + /// 要填充结果集的DataSet实例 + /// 表映射的数据表数组 + /// 用户定义的表名 (可有是实际的表名.) + /// + /// 分配给命令的SqlParamter参数数组 + private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, + string commandText, DataSet dataSet, string[] tableNames, + params SqlParameter[] commandParameters) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (dataSet == null) throw new ArgumentNullException("dataSet"); + // 创建SqlCommand命令,并进行预处理 + SqlCommand command = new SqlCommand(); + bool mustCloseConnection = false; + PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection); + + // 执行命令 + using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command)) + { + + // 追加表映射 + if (tableNames != null && tableNames.Length > 0) + { + string tableName = "Table"; + for (int index = 0; index < tableNames.Length; index++) + { + if (tableNames[index] == null || tableNames[index].Length == 0) throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames"); + dataAdapter.TableMappings.Add(tableName, tableNames[index]); + tableName += (index + 1).ToString(); + } + } + + // 填充数据集使用默认表名称 + dataAdapter.Fill(dataSet); + // 清除参数,以便再次使用. + command.Parameters.Clear(); + } + if (mustCloseConnection) + connection.Close(); + } + #endregion + + #region UpdateDataset 更新数据集 + /// + /// 执行数据集更新到数据库,指定inserted, updated, or deleted命令. + /// + /// + /// 示例: + /// UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order"); + /// + /// [追加记录]一个有效的T-SQL语句或存储过程 + /// [删除记录]一个有效的T-SQL语句或存储过程 + /// [更新记录]一个有效的T-SQL语句或存储过程 + /// 要更新到数据库的DataSet + /// 要更新到数据库的DataTable + public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName) + { + if (insertCommand == null) throw new ArgumentNullException("insertCommand"); + if (deleteCommand == null) throw new ArgumentNullException("deleteCommand"); + if (updateCommand == null) throw new ArgumentNullException("updateCommand"); + if (tableName == null || tableName.Length == 0) throw new ArgumentNullException("tableName"); + // 创建SqlDataAdapter,当操作完成后释放. + using (SqlDataAdapter dataAdapter = new SqlDataAdapter()) + { + // 设置数据适配器命令 + dataAdapter.UpdateCommand = updateCommand; + dataAdapter.InsertCommand = insertCommand; + dataAdapter.DeleteCommand = deleteCommand; + // 更新数据集改变到数据库 + dataAdapter.Update(dataSet, tableName); + // 提交所有改变到数据集. + dataSet.AcceptChanges(); + } + } + #endregion + + #region CreateCommand 创建一条SqlCommand命令 + /// + /// 创建SqlCommand命令,指定数据库连接对象,存储过程名和参数. + /// + /// + /// 示例: + /// SqlCommand command = CreateCommand(conn, "AddCustomer", "CustomerID", "CustomerName"); + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 源表的列名称数组 + /// 返回SqlCommand命令 + public static SqlCommand CreateCommand(SqlConnection connection, string spName, params string[] sourceColumns) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 创建命令 + SqlCommand cmd = new SqlCommand(spName, connection); + cmd.CommandType = CommandType.StoredProcedure; + // 如果有参数值 + if ((sourceColumns != null) && (sourceColumns.Length > 0)) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + // 将源表的列到映射到DataSet命令中. + for (int index = 0; index < sourceColumns.Length; index++) + commandParameters[index].SourceColumn = sourceColumns[index]; + // Attach the discovered parameters to the SqlCommand object + AttachParameters(cmd, commandParameters); + } + return cmd; + } + #endregion + + #region ExecuteNonQueryTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回受影响的行数. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回影响的行数 + public static int ExecuteNonQueryTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // Sf the row has values, the store procedure parameters must be initialized + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteDatasetTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + public static DataSet ExecuteDatasetTypedParams(string connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + //如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + /// + public static DataSet ExecuteDatasetTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回DataSet. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回一个包含结果集的DataSet. + public static DataSet ExecuteDatasetTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteDataset(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteReaderTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回DataReader. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回包含结果集的SqlDataReader + public static SqlDataReader ExecuteReaderTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteScalarTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(String connectionString, String spName, DataRow dataRow) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回结果集中的第一行第一列. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回结果集中的第一行第一列 + public static object ExecuteScalarTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteScalar(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteScalar(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + + #region ExecuteXmlReaderTypedParams 类型化参数(DataRow) + /// + /// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReaderTypedParams(SqlConnection connection, String spName, DataRow dataRow) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteXmlReader(connection, CommandType.StoredProcedure, spName); + } + } + + /// + /// 执行指定连接数据库事务的存储过程,使用DataRow做为参数值,返回XmlReader类型的结果集. + /// + /// 一个有效的连接事务 object + /// 存储过程名称 + /// 使用DataRow作为参数值 + /// 返回XmlReader结果集对象. + public static XmlReader ExecuteXmlReaderTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) + { + if (transaction == null) throw new ArgumentNullException("transaction"); + if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + // 如果row有值,存储过程必须初始化. + if (dataRow != null && dataRow.ItemArray.Length > 0) + { + // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. () + SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName); + + // 分配参数值 + AssignParameterValues(commandParameters, dataRow); + + return SqlHelper.ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, commandParameters); + } + else + { + return SqlHelper.ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName); + } + } + #endregion + } + + /// + /// SqlHelperParameterCache提供缓存存储过程参数,并能够在运行时从存储过程中探索参数. + /// + public sealed class SqlHelperParameterCache + { + #region 私有方法,字段,构造函数 + // 私有构造函数,妨止类被实例化. + private SqlHelperParameterCache() { } + // 这个方法要注意 + private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable()); + /// + /// 探索运行时的存储过程,返回SqlParameter参数数组. + /// 初始化参数值为 DBNull.Value. + /// + /// 一个有效的数据库连接 + /// 存储过程名称 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + private static SqlParameter[] DiscoverSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + SqlCommand cmd = new SqlCommand(spName, connection); + cmd.CommandType = CommandType.StoredProcedure; + connection.Open(); + // 检索cmd指定的存储过程的参数信息,并填充到cmd的Parameters参数集中. + SqlCommandBuilder.DeriveParameters(cmd); + connection.Close(); + // 如果不包含返回值参数,将参数集中的每一个参数删除. + if (!includeReturnValueParameter) + { + cmd.Parameters.RemoveAt(0); + } + + // 创建参数数组 + SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count]; + // 将cmd的Parameters参数集复制到discoveredParameters数组. + cmd.Parameters.CopyTo(discoveredParameters, 0); + // 初始化参数值为 DBNull.Value. + foreach (SqlParameter discoveredParameter in discoveredParameters) + { + discoveredParameter.Value = DBNull.Value; + } + return discoveredParameters; + } + + /// + /// SqlParameter参数数组的深层拷贝. + /// + /// 原始参数数组 + /// 返回一个同样的参数数组 + private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters) + { + SqlParameter[] clonedParameters = new SqlParameter[originalParameters.Length]; + for (int i = 0, j = originalParameters.Length; i < j; i++) + { + clonedParameters[i] = (SqlParameter)((ICloneable)originalParameters[i]).Clone(); + } + return clonedParameters; + } + #endregion 私有方法,字段,构造函数结束 + + #region 缓存方法 + /// + /// 追加参数数组到缓存. + /// + /// 一个有效的数据库连接字符串 + /// 存储过程名或SQL语句 + /// 要缓存的参数数组 + public static void CacheParameterSet(string connectionString, string commandText, params SqlParameter[] commandParameters) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + string hashKey = connectionString + ":" + commandText; + paramCache[hashKey] = commandParameters; + } + + /// + /// 从缓存中获取参数数组. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名或SQL语句 + /// 参数数组 + public static SqlParameter[] GetCachedParameterSet(string connectionString, string commandText) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); + string hashKey = connectionString + ":" + commandText; + SqlParameter[] cachedParameters = paramCache[hashKey] as SqlParameter[]; + if (cachedParameters == null) + { + return null; + } + else + { + return CloneParameters(cachedParameters); + } + } + #endregion 缓存方法结束 + + #region 检索指定的存储过程的参数集 + /// + /// 返回指定的存储过程的参数集 + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名 + /// 返回SqlParameter参数数组 + public static SqlParameter[] GetSpParameterSet(string connectionString, string spName) + { + return GetSpParameterSet(connectionString, spName, false); + } + + /// + /// 返回指定的存储过程的参数集 + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符. + /// 存储过程名 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + public static SqlParameter[] GetSpParameterSet(string connectionString, string spName, bool includeReturnValueParameter) + { + if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + using (SqlConnection connection = new SqlConnection(connectionString)) + { + return GetSpParameterSetInternal(connection, spName, includeReturnValueParameter); + } + } + + /// + /// [内部]返回指定的存储过程的参数集(使用连接对象). + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接字符 + /// 存储过程名 + /// 返回SqlParameter参数数组 + internal static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName) + { + return GetSpParameterSet(connection, spName, false); + } + + /// + /// [内部]返回指定的存储过程的参数集(使用连接对象) + /// + /// + /// 这个方法将查询数据库,并将信息存储到缓存. + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// + /// 是否包含返回值参数 + /// + /// 返回SqlParameter参数数组 + internal static SqlParameter[] GetSpParameterSet(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + using (SqlConnection clonedConnection = (SqlConnection)((ICloneable)connection).Clone()) + { + return GetSpParameterSetInternal(clonedConnection, spName, includeReturnValueParameter); + } + } + + /// + /// [私有]返回指定的存储过程的参数集(使用连接对象) + /// + /// 一个有效的数据库连接对象 + /// 存储过程名 + /// 是否包含返回值参数 + /// 返回SqlParameter参数数组 + private static SqlParameter[] GetSpParameterSetInternal(SqlConnection connection, string spName, bool includeReturnValueParameter) + { + if (connection == null) throw new ArgumentNullException("connection"); + if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName"); + string hashKey = connection.ConnectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter" : ""); + SqlParameter[] cachedParameters; + + cachedParameters = paramCache[hashKey] as SqlParameter[]; + if (cachedParameters == null) + { + SqlParameter[] spParameters = DiscoverSpParameterSet(connection, spName, includeReturnValueParameter); + paramCache[hashKey] = spParameters; + cachedParameters = spParameters; + } + + return CloneParameters(cachedParameters); + } + + #endregion 参数集检索结束 + } +} +>>>>>>> qicb/Develop diff --git a/Application/Main.Designer.cs b/Application/Main.Designer.cs deleted file mode 100644 index 06e6756..0000000 --- a/Application/Main.Designer.cs +++ /dev/null @@ -1,271 +0,0 @@ -namespace WorkStation -{ - partial class Main - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows 窗体设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main)); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.巡检项模板ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.任务管理ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.统计报表ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.巡检信息ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.基础信息ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.卡片管理ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.帮助ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); - this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); - this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); - this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); - this.toolStripButton4 = new System.Windows.Forms.ToolStripButton(); - this.treeView1 = new System.Windows.Forms.TreeView(); - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); - this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton(); - this.menuStrip1.SuspendLayout(); - this.toolStripContainer1.BottomToolStripPanel.SuspendLayout(); - this.toolStripContainer1.ContentPanel.SuspendLayout(); - this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); - this.toolStripContainer1.SuspendLayout(); - this.toolStrip1.SuspendLayout(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.巡检项模板ToolStripMenuItem, - this.任务管理ToolStripMenuItem, - this.统计报表ToolStripMenuItem, - this.巡检信息ToolStripMenuItem, - this.基础信息ToolStripMenuItem, - this.卡片管理ToolStripMenuItem, - this.帮助ToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1029, 25); - this.menuStrip1.TabIndex = 1; - this.menuStrip1.Text = "menuStrip1"; - // - // 巡检项模板ToolStripMenuItem - // - this.巡检项模板ToolStripMenuItem.Name = "巡检项模板ToolStripMenuItem"; - this.巡检项模板ToolStripMenuItem.Size = new System.Drawing.Size(95, 21); - this.巡检项模板ToolStripMenuItem.Text = "巡检项模板(&T)"; - // - // 任务管理ToolStripMenuItem - // - this.任务管理ToolStripMenuItem.Name = "任务管理ToolStripMenuItem"; - this.任务管理ToolStripMenuItem.Size = new System.Drawing.Size(84, 21); - this.任务管理ToolStripMenuItem.Text = "任务管理(&A)"; - // - // 统计报表ToolStripMenuItem - // - this.统计报表ToolStripMenuItem.Name = "统计报表ToolStripMenuItem"; - this.统计报表ToolStripMenuItem.Size = new System.Drawing.Size(84, 21); - this.统计报表ToolStripMenuItem.Text = "统计报表(&R)"; - // - // 巡检信息ToolStripMenuItem - // - this.巡检信息ToolStripMenuItem.Name = "巡检信息ToolStripMenuItem"; - this.巡检信息ToolStripMenuItem.Size = new System.Drawing.Size(80, 21); - this.巡检信息ToolStripMenuItem.Text = "巡检信息(&I)"; - // - // 基础信息ToolStripMenuItem - // - this.基础信息ToolStripMenuItem.Name = "基础信息ToolStripMenuItem"; - this.基础信息ToolStripMenuItem.Size = new System.Drawing.Size(84, 21); - this.基础信息ToolStripMenuItem.Text = "基础信息(&B)"; - // - // 卡片管理ToolStripMenuItem - // - this.卡片管理ToolStripMenuItem.Name = "卡片管理ToolStripMenuItem"; - this.卡片管理ToolStripMenuItem.Size = new System.Drawing.Size(84, 21); - this.卡片管理ToolStripMenuItem.Text = "卡片管理(&C)"; - // - // 帮助ToolStripMenuItem - // - this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem"; - this.帮助ToolStripMenuItem.Size = new System.Drawing.Size(61, 21); - this.帮助ToolStripMenuItem.Text = "帮助(&H)"; - // - // toolStripContainer1 - // - // - // toolStripContainer1.BottomToolStripPanel - // - this.toolStripContainer1.BottomToolStripPanel.Controls.Add(this.statusStrip1); - // - // toolStripContainer1.ContentPanel - // - this.toolStripContainer1.ContentPanel.Controls.Add(this.treeView1); - this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(1029, 353); - this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.toolStripContainer1.Location = new System.Drawing.Point(0, 25); - this.toolStripContainer1.Name = "toolStripContainer1"; - this.toolStripContainer1.Size = new System.Drawing.Size(1029, 400); - this.toolStripContainer1.TabIndex = 3; - this.toolStripContainer1.Text = "toolStripContainer1"; - // - // toolStripContainer1.TopToolStripPanel - // - this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.toolStrip1); - // - // toolStrip1 - // - this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; - this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripButton1, - this.toolStripButton2, - this.toolStripButton3, - this.toolStripButton4}); - this.toolStrip1.Location = new System.Drawing.Point(3, 0); - this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(204, 25); - this.toolStrip1.TabIndex = 0; - // - // toolStripButton1 - // - this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); - this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton1.Name = "toolStripButton1"; - this.toolStripButton1.Size = new System.Drawing.Size(23, 22); - this.toolStripButton1.Text = "toolStripButton1"; - // - // toolStripButton2 - // - this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image"))); - this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton2.Name = "toolStripButton2"; - this.toolStripButton2.Size = new System.Drawing.Size(23, 22); - this.toolStripButton2.Text = "toolStripButton2"; - // - // toolStripButton3 - // - this.toolStripButton3.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton3.Image"))); - this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton3.Name = "toolStripButton3"; - this.toolStripButton3.Size = new System.Drawing.Size(123, 22); - this.toolStripButton3.Text = "toolStripButton3"; - // - // toolStripButton4 - // - this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripButton4.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton4.Image"))); - this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton4.Name = "toolStripButton4"; - this.toolStripButton4.Size = new System.Drawing.Size(23, 22); - this.toolStripButton4.Text = "toolStripButton4"; - // - // treeView1 - // - this.treeView1.Location = new System.Drawing.Point(3, 3); - this.treeView1.Name = "treeView1"; - this.treeView1.Size = new System.Drawing.Size(121, 97); - this.treeView1.TabIndex = 0; - // - // statusStrip1 - // - this.statusStrip1.Dock = System.Windows.Forms.DockStyle.None; - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripProgressBar1, - this.toolStripDropDownButton1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 0); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(1029, 22); - this.statusStrip1.TabIndex = 0; - // - // toolStripProgressBar1 - // - this.toolStripProgressBar1.Name = "toolStripProgressBar1"; - this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16); - // - // toolStripDropDownButton1 - // - this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image"))); - this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 20); - this.toolStripDropDownButton1.Text = "toolStripDropDownButton1"; - // - // Main - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1029, 425); - this.Controls.Add(this.toolStripContainer1); - this.Controls.Add(this.menuStrip1); - this.IsMdiContainer = true; - this.MainMenuStrip = this.menuStrip1; - this.Name = "Main"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "RFID智能巡检系统"; - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.toolStripContainer1.BottomToolStripPanel.ResumeLayout(false); - this.toolStripContainer1.BottomToolStripPanel.PerformLayout(); - this.toolStripContainer1.ContentPanel.ResumeLayout(false); - this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false); - this.toolStripContainer1.TopToolStripPanel.PerformLayout(); - this.toolStripContainer1.ResumeLayout(false); - this.toolStripContainer1.PerformLayout(); - this.toolStrip1.ResumeLayout(false); - this.toolStrip1.PerformLayout(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.MenuStrip menuStrip1; - private System.Windows.Forms.ToolStripMenuItem 巡检项模板ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 任务管理ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 统计报表ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 巡检信息ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 基础信息ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 卡片管理ToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem 帮助ToolStripMenuItem; - private System.Windows.Forms.ToolStripContainer toolStripContainer1; - private System.Windows.Forms.ToolStrip toolStrip1; - private System.Windows.Forms.ToolStripButton toolStripButton1; - private System.Windows.Forms.ToolStripButton toolStripButton2; - private System.Windows.Forms.ToolStripButton toolStripButton3; - private System.Windows.Forms.ToolStripButton toolStripButton4; - private System.Windows.Forms.TreeView treeView1; - private System.Windows.Forms.StatusStrip statusStrip1; - private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1; - private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1; - } -} - diff --git a/Application/Main.cs b/Application/Main.cs deleted file mode 100644 index 8e74937..0000000 --- a/Application/Main.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; - -namespace WorkStation -{ - public partial class Main : Form - { - public Main() - { - InitializeComponent(); - } - - } -} diff --git a/Application/Main.resx b/Application/Main.resx deleted file mode 100644 index 93f8c4b..0000000 --- a/Application/Main.resx +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 18, -1 - - - 358, -1 - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - 138, -1 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - 28 - - \ No newline at end of file diff --git a/Application/Program.cs b/Application/Program.cs index 07ad871..1feae75 100644 --- a/Application/Program.cs +++ b/Application/Program.cs @@ -14,7 +14,7 @@ static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new frmain()); + Application.Run(new frmMain()); } } } diff --git a/Application/Program.cs.orig b/Application/Program.cs.orig index 2a90e35..c627450 100644 --- a/Application/Program.cs.orig +++ b/Application/Program.cs.orig @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; - namespace WorkStation { static class Program @@ -15,7 +14,7 @@ namespace WorkStation { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Main()); + Application.Run(new frmMain()); } } } diff --git a/Application/Properties/Settings.Designer.cs b/Application/Properties/Settings.Designer.cs index db260cc..7820368 100644 --- a/Application/Properties/Settings.Designer.cs +++ b/Application/Properties/Settings.Designer.cs @@ -13,7 +13,7 @@ namespace WorkStation.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -32,5 +32,41 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio return ((string)(this["ConnectionString"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvRoute { + get { + return ((bool)(this["tvRoute"])); + } + set { + this["tvRoute"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvLogicalPoint { + get { + return ((bool)(this["tvLogicalPoint"])); + } + set { + this["tvLogicalPoint"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvPhysicalPoint { + get { + return ((bool)(this["tvPhysicalPoint"])); + } + set { + this["tvPhysicalPoint"] = value; + } + } } } diff --git a/Application/Properties/Settings.Designer.cs.orig b/Application/Properties/Settings.Designer.cs.orig index 76bdc4b..8de931e 100644 --- a/Application/Properties/Settings.Designer.cs.orig +++ b/Application/Properties/Settings.Designer.cs.orig @@ -1,8 +1,7 @@ -<<<<<<< HEAD //------------------------------------------------------------------------------ // // 此代码由工具生成。 -// 运行时版本:4.0.30319.17929 +// 运行时版本:4.0.30319.269 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 @@ -14,7 +13,7 @@ namespace WorkStation.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -23,33 +22,54 @@ namespace WorkStation.Properties { return defaultInstance; } } - } -} + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] + [global::System.Configuration.DefaultSettingValueAttribute("Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123")] + public string ConnectionString { + get { + return ((string)(this["ConnectionString"])); + } + } +<<<<<<< HEAD ======= -//------------------------------------------------------------------------------ -// -// 此代码由工具生成。 -// 运行时版本:4.0.30319.269 -// -// 对此文件的更改可能会导致不正确的行为,并且如果 -// 重新生成代码,这些更改将会丢失。 -// -//------------------------------------------------------------------------------ - -namespace Application.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvRoute { + get { + return ((bool)(this["tvRoute"])); + } + set { + this["tvRoute"] = value; + } + } - public static Settings Default { + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvLogicalPoint { get { - return defaultInstance; + return ((bool)(this["tvLogicalPoint"])); + } + set { + this["tvLogicalPoint"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvPhysicalPoint { + get { + return ((bool)(this["tvPhysicalPoint"])); + } + set { + this["tvPhysicalPoint"] = value; } } +>>>>>>> qicb/Develop } } ->>>>>>> hefl diff --git a/Application/Properties/Settings.settings b/Application/Properties/Settings.settings index 54c7202..20856e7 100644 --- a/Application/Properties/Settings.settings +++ b/Application/Properties/Settings.settings @@ -1,5 +1,5 @@  - + @@ -9,5 +9,14 @@ </SerializableConnectionString> Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123 + + True + + + True + + + True + \ No newline at end of file diff --git a/Application/Properties/Settings.settings.orig b/Application/Properties/Settings.settings.orig new file mode 100644 index 0000000..bfee4c5 --- /dev/null +++ b/Application/Properties/Settings.settings.orig @@ -0,0 +1,37 @@ +<<<<<<< HEAD + + + + + + <?xml version="1.0" encoding="utf-16"?> +<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <ConnectionString>Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123</ConnectionString> +</SerializableConnectionString> + Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123 + + +======= + + + + + + <?xml version="1.0" encoding="utf-16"?> +<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <ConnectionString>Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123</ConnectionString> +</SerializableConnectionString> + Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123 + + + True + + + True + + + True + + +>>>>>>> qicb/Develop + \ No newline at end of file diff --git a/Application/WorkStation.csproj b/Application/WorkStation.csproj index 76a803f..d294d11 100644 --- a/Application/WorkStation.csproj +++ b/Application/WorkStation.csproj @@ -82,17 +82,23 @@ frmAddRoute.cs - + Form - - frmAddTask.cs + + frmAddRoutName.cs - + Form - - frmain.cs + + frmAddMachine.cs + + + Form + + + frmAddTask.cs Form @@ -160,20 +166,14 @@ frmIssueTask.cs - - - + Form - - SiteEditDelete.cs - - - Form - - - SiteNew.cs + + frmMain.cs + + frmAddCard.cs @@ -189,12 +189,15 @@ frmAddRoute.cs + + frmAddRoutName.cs + + + frmAddMachine.cs + frmAddTask.cs - - frmain.cs - frmAddItem.cs @@ -228,6 +231,9 @@ frmIssueTask.cs + + frmMain.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -238,21 +244,13 @@ Resources.resx True - - SiteEditDelete.cs - - - SiteNew.cs - - - SettingsSingleFileGenerator + PublicSettingsSingleFileGenerator Settings.Designer.cs - Designer True @@ -297,12 +295,6 @@ - - - {274882FC-F42C-4969-9BA1-EE5CBF5C37A0} - Model - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + \ No newline at end of file diff --git a/Application/frmAddMachine.Designer.cs b/Application/frmAddMachine.Designer.cs new file mode 100644 index 0000000..f3aba19 --- /dev/null +++ b/Application/frmAddMachine.Designer.cs @@ -0,0 +1,198 @@ +namespace WorkStation +{ + partial class frmAddMachine + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.tbName = new System.Windows.Forms.TextBox(); + this.tbAlias = new System.Windows.Forms.TextBox(); + this.cboArea = new System.Windows.Forms.ComboBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.dgvMachine = new System.Windows.Forms.DataGridView(); + this.chkColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.btnDel = new System.Windows.Forms.Button(); + this.labID = new System.Windows.Forms.Label(); + this.btnUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dgvMachine)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(27, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 12); + this.label1.TabIndex = 0; + this.label1.Text = "设备名称"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(360, 39); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 12); + this.label2.TabIndex = 1; + this.label2.Text = "设备别名"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(27, 82); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 2; + this.label3.Text = "所属厂区"; + // + // tbName + // + this.tbName.Location = new System.Drawing.Point(87, 36); + this.tbName.Name = "tbName"; + this.tbName.Size = new System.Drawing.Size(245, 21); + this.tbName.TabIndex = 3; + // + // tbAlias + // + this.tbAlias.Location = new System.Drawing.Point(419, 36); + this.tbAlias.Name = "tbAlias"; + this.tbAlias.Size = new System.Drawing.Size(211, 21); + this.tbAlias.TabIndex = 4; + // + // cboArea + // + this.cboArea.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboArea.FormattingEnabled = true; + this.cboArea.Location = new System.Drawing.Point(87, 82); + this.cboArea.Name = "cboArea"; + this.cboArea.Size = new System.Drawing.Size(244, 20); + this.cboArea.TabIndex = 5; + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(419, 77); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(61, 23); + this.btnSave.TabIndex = 6; + this.btnSave.Text = "保存"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // dgvMachine + // + this.dgvMachine.AllowUserToAddRows = false; + this.dgvMachine.AllowUserToDeleteRows = false; + this.dgvMachine.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvMachine.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.chkColumn}); + this.dgvMachine.Location = new System.Drawing.Point(26, 161); + this.dgvMachine.Name = "dgvMachine"; + this.dgvMachine.ReadOnly = true; + this.dgvMachine.RowTemplate.Height = 23; + this.dgvMachine.Size = new System.Drawing.Size(604, 236); + this.dgvMachine.TabIndex = 7; + this.dgvMachine.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMachine_CellClick); + // + // chkColumn + // + this.chkColumn.HeaderText = "选择"; + this.chkColumn.Name = "chkColumn"; + this.chkColumn.ReadOnly = true; + this.chkColumn.Width = 38; + // + // btnDel + // + this.btnDel.Location = new System.Drawing.Point(556, 77); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(59, 23); + this.btnDel.TabIndex = 8; + this.btnDel.Text = "删除"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // labID + // + this.labID.AutoSize = true; + this.labID.Location = new System.Drawing.Point(337, 82); + this.labID.Name = "labID"; + this.labID.Size = new System.Drawing.Size(17, 12); + this.labID.TabIndex = 9; + this.labID.Text = "ID"; + this.labID.Visible = false; + // + // btnUpdate + // + this.btnUpdate.Location = new System.Drawing.Point(486, 77); + this.btnUpdate.Name = "btnUpdate"; + this.btnUpdate.Size = new System.Drawing.Size(64, 23); + this.btnUpdate.TabIndex = 10; + this.btnUpdate.Text = "修改"; + this.btnUpdate.UseVisualStyleBackColor = true; + this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click); + // + // frmAddMachine + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(667, 460); + this.Controls.Add(this.btnUpdate); + this.Controls.Add(this.labID); + this.Controls.Add(this.btnDel); + this.Controls.Add(this.dgvMachine); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.cboArea); + this.Controls.Add(this.tbAlias); + this.Controls.Add(this.tbName); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "frmAddMachine"; + this.Text = "添加设备"; + this.Load += new System.EventHandler(this.frmAddSiteArea_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvMachine)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox tbName; + private System.Windows.Forms.TextBox tbAlias; + private System.Windows.Forms.ComboBox cboArea; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.DataGridView dgvMachine; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.DataGridViewCheckBoxColumn chkColumn; + private System.Windows.Forms.Label labID; + private System.Windows.Forms.Button btnUpdate; + } +} \ No newline at end of file diff --git a/Application/frmAddMachine.cs b/Application/frmAddMachine.cs new file mode 100644 index 0000000..c733f1d --- /dev/null +++ b/Application/frmAddMachine.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddMachine : Form + { + public frmAddMachine() + { + InitializeComponent(); + } + private void frmAddSiteArea_Load(object sender, EventArgs e) + { + getArea(); + bindDgvMachine(); + } + + private void btnSave_Click(object sender, EventArgs e) + { + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",this.tbName.Text.Trim().ToString()), + new SqlParameter("@alias",this.tbAlias.Text.Trim().ToString()), + new SqlParameter("@site_id",SqlDbType.BigInt) + }; + pars[2].Value = cboArea.SelectedValue; + + string strSql = "insert into machine([Name],Alias,Site_ID) values(@name,@alias,@site_id)"; + + if (SqlHelper.ExecuteNonQuery(strSql, pars) == 1) + { + MessageBox.Show("保存成功"); + bindDgvMachine(); + } + + } + + private void getArea() + { + DataSet ds = SqlHelper.ExecuteDataset("select ID,Name From Site"); + this.cboArea.DataSource = ds.Tables[0]; + this.cboArea.DisplayMember = "Name"; + this.cboArea.ValueMember = "ID"; + this.cboArea.SelectedIndex = cboArea.Items.Count > 0 ? 0 : -1; + } + + private void bindDgvMachine() + { + string str_select = @"select + m.id as 编号, + m.name as 设备名称, + m.alias as 别名, + s.name as 厂区 + from machine m,site s + where m.site_id=s.id"; + DataSet ds = SqlHelper.ExecuteDataset(str_select); + this.dgvMachine.DataSource=ds.Tables[0]; + } + + private void dgvMachine_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex == -1) return; + if (e.ColumnIndex == 0) + { + if ((bool)dgvMachine.Rows[e.RowIndex].Cells[0].EditedFormattedValue == false) + { + dgvMachine.Rows[e.RowIndex].Cells[0].Value = true; + } + else + { + dgvMachine.Rows[e.RowIndex].Cells[0].Value = false; + } + } + else + { + labID.Text = dgvMachine.Rows[e.RowIndex].Cells[1].Value.ToString(); + tbName.Text = dgvMachine.Rows[e.RowIndex].Cells[2].Value.ToString(); + tbAlias.Text = dgvMachine.Rows[e.RowIndex].Cells[3].Value.ToString(); + cboArea.Text = dgvMachine.Rows[e.RowIndex].Cells[4].Value.ToString(); + } + + } + + private void btnDel_Click(object sender, EventArgs e) + { + string Del = ""; + string strsql = "Delete From Machine Where ID in("; + for (int i = 0; i < dgvMachine.Rows.Count; i++) + { + try + { + if ((bool)dgvMachine.Rows[i].Cells[0].Value == true) + { + Del += dgvMachine.Rows[i].Cells[1].Value.ToString() + ","; + } + } + catch + { + continue; + } + } + if (Del != "") + { + Del = Del.Substring(0, Del.Length - 1); + strsql += Del + ")"; + SqlHelper.ExecuteNonQuery(strsql); + bindDgvMachine(); + } + + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",this.tbName.Text.Trim().ToString()), + new SqlParameter("@alias",this.tbAlias.Text.Trim().ToString()), + new SqlParameter("@site_id",SqlDbType.BigInt) + }; + pars[2].Value = cboArea.SelectedValue; + string strSql = "Update machine set [Name]=@name,Alias=@alias,Site_ID=@site_id where id=" + labID.Text; + if (SqlHelper.ExecuteNonQuery(strSql,pars) == 1) + { + MessageBox.Show("修改成功"); + bindDgvMachine(); + } + } + + + } +} diff --git a/Application/frmAddMachine.resx b/Application/frmAddMachine.resx new file mode 100644 index 0000000..64fa149 --- /dev/null +++ b/Application/frmAddMachine.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/Application/frmAddPoint.Designer.cs b/Application/frmAddPoint.Designer.cs index 1cd5a00..92fe175 100644 --- a/Application/frmAddPoint.Designer.cs +++ b/Application/frmAddPoint.Designer.cs @@ -36,36 +36,36 @@ private void InitializeComponent() this.txtRelation = new System.Windows.Forms.TextBox(); this.btnRead = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button(); - this.listView1 = new System.Windows.Forms.ListView(); - this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.btnUpdate = new System.Windows.Forms.Button(); + this.btnDel = new System.Windows.Forms.Button(); + this.dgvPoint = new System.Windows.Forms.DataGridView(); + this.chkColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.labID = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dgvPoint)).BeginInit(); this.SuspendLayout(); // // lblName // this.lblName.AutoSize = true; - this.lblName.Location = new System.Drawing.Point(135, 50); + this.lblName.Location = new System.Drawing.Point(74, 44); this.lblName.Name = "lblName"; - this.lblName.Size = new System.Drawing.Size(29, 12); + this.lblName.Size = new System.Drawing.Size(53, 12); this.lblName.TabIndex = 0; - this.lblName.Text = "名称"; + this.lblName.Text = "巡检名称"; // // lblAlias // this.lblAlias.AutoSize = true; - this.lblAlias.Location = new System.Drawing.Point(135, 93); + this.lblAlias.Location = new System.Drawing.Point(379, 44); this.lblAlias.Name = "lblAlias"; this.lblAlias.Size = new System.Drawing.Size(29, 12); this.lblAlias.TabIndex = 1; this.lblAlias.Text = "别名"; - this.lblAlias.Click += new System.EventHandler(this.label1_Click); // // lblRelated // this.lblRelated.AutoSize = true; - this.lblRelated.Location = new System.Drawing.Point(99, 135); + this.lblRelated.Location = new System.Drawing.Point(62, 90); this.lblRelated.Name = "lblRelated"; this.lblRelated.Size = new System.Drawing.Size(65, 12); this.lblRelated.TabIndex = 2; @@ -73,80 +73,107 @@ private void InitializeComponent() // // txtName // - this.txtName.Location = new System.Drawing.Point(198, 47); + this.txtName.Location = new System.Drawing.Point(137, 41); this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(237, 21); this.txtName.TabIndex = 3; // // txtAlias // - this.txtAlias.Location = new System.Drawing.Point(198, 90); + this.txtAlias.Location = new System.Drawing.Point(414, 41); this.txtAlias.Name = "txtAlias"; - this.txtAlias.Size = new System.Drawing.Size(237, 21); + this.txtAlias.Size = new System.Drawing.Size(262, 21); this.txtAlias.TabIndex = 4; // // txtRelation // - this.txtRelation.Location = new System.Drawing.Point(198, 126); + this.txtRelation.Location = new System.Drawing.Point(137, 81); this.txtRelation.Name = "txtRelation"; + this.txtRelation.ReadOnly = true; this.txtRelation.Size = new System.Drawing.Size(237, 21); this.txtRelation.TabIndex = 5; // // btnRead // - this.btnRead.Location = new System.Drawing.Point(460, 126); + this.btnRead.Location = new System.Drawing.Point(414, 79); this.btnRead.Name = "btnRead"; this.btnRead.Size = new System.Drawing.Size(75, 23); this.btnRead.TabIndex = 6; this.btnRead.Text = "读取"; this.btnRead.UseVisualStyleBackColor = true; + this.btnRead.Click += new System.EventHandler(this.btnRead_Click); // // btnSave // - this.btnSave.Location = new System.Drawing.Point(573, 126); + this.btnSave.Location = new System.Drawing.Point(414, 124); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 7; this.btnSave.Text = "保存"; this.btnSave.UseVisualStyleBackColor = true; - // - // listView1 - // - this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.columnHeader1, - this.columnHeader2, - this.columnHeader3, - this.columnHeader4}); - this.listView1.GridLines = true; - this.listView1.Location = new System.Drawing.Point(72, 218); - this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(587, 163); - this.listView1.TabIndex = 8; - this.listView1.UseCompatibleStateImageBehavior = false; - this.listView1.View = System.Windows.Forms.View.Details; - // - // columnHeader1 - // - this.columnHeader1.Text = "巡检点编号"; - // - // columnHeader2 - // - this.columnHeader2.Text = "名称"; - // - // columnHeader3 - // - this.columnHeader3.Text = "别名"; - // - // columnHeader4 - // - this.columnHeader4.Text = "关联标签卡"; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnUpdate + // + this.btnUpdate.Location = new System.Drawing.Point(509, 124); + this.btnUpdate.Name = "btnUpdate"; + this.btnUpdate.Size = new System.Drawing.Size(75, 23); + this.btnUpdate.TabIndex = 9; + this.btnUpdate.Text = "修改"; + this.btnUpdate.UseVisualStyleBackColor = true; + this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click); + // + // btnDel + // + this.btnDel.Location = new System.Drawing.Point(616, 124); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(75, 23); + this.btnDel.TabIndex = 10; + this.btnDel.Text = "删除"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // dgvPoint + // + this.dgvPoint.AllowUserToAddRows = false; + this.dgvPoint.AllowUserToDeleteRows = false; + this.dgvPoint.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvPoint.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.chkColumn}); + this.dgvPoint.Location = new System.Drawing.Point(27, 178); + this.dgvPoint.Name = "dgvPoint"; + this.dgvPoint.ReadOnly = true; + this.dgvPoint.RowTemplate.Height = 23; + this.dgvPoint.Size = new System.Drawing.Size(687, 329); + this.dgvPoint.TabIndex = 11; + this.dgvPoint.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvPoint_CellClick); + // + // chkColumn + // + this.chkColumn.HeaderText = "选择"; + this.chkColumn.Name = "chkColumn"; + this.chkColumn.ReadOnly = true; + this.chkColumn.Width = 38; + // + // labID + // + this.labID.AutoSize = true; + this.labID.Location = new System.Drawing.Point(507, 84); + this.labID.Name = "labID"; + this.labID.Size = new System.Drawing.Size(41, 12); + this.labID.TabIndex = 12; + this.labID.Text = "巡检ID"; + this.labID.Visible = false; // // frmAddPoint // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(751, 550); - this.Controls.Add(this.listView1); + this.Controls.Add(this.labID); + this.Controls.Add(this.dgvPoint); + this.Controls.Add(this.btnDel); + this.Controls.Add(this.btnUpdate); this.Controls.Add(this.btnSave); this.Controls.Add(this.btnRead); this.Controls.Add(this.txtRelation); @@ -158,6 +185,7 @@ private void InitializeComponent() this.Name = "frmAddPoint"; this.Text = "新建巡检点"; this.Load += new System.EventHandler(this.frmAddPoint_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvPoint)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -173,10 +201,10 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtRelation; private System.Windows.Forms.Button btnRead; private System.Windows.Forms.Button btnSave; - private System.Windows.Forms.ListView listView1; - private System.Windows.Forms.ColumnHeader columnHeader1; - private System.Windows.Forms.ColumnHeader columnHeader2; - private System.Windows.Forms.ColumnHeader columnHeader3; - private System.Windows.Forms.ColumnHeader columnHeader4; + private System.Windows.Forms.Button btnUpdate; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.DataGridView dgvPoint; + private System.Windows.Forms.DataGridViewCheckBoxColumn chkColumn; + private System.Windows.Forms.Label labID; } } \ No newline at end of file diff --git a/Application/frmAddPoint.Designer.cs.orig b/Application/frmAddPoint.Designer.cs.orig new file mode 100644 index 0000000..abacc63 --- /dev/null +++ b/Application/frmAddPoint.Designer.cs.orig @@ -0,0 +1,213 @@ +namespace WorkStation +{ + partial class frmAddPoint + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblName = new System.Windows.Forms.Label(); + this.lblAlias = new System.Windows.Forms.Label(); + this.lblRelated = new System.Windows.Forms.Label(); + this.txtName = new System.Windows.Forms.TextBox(); + this.txtAlias = new System.Windows.Forms.TextBox(); + this.txtRelation = new System.Windows.Forms.TextBox(); + this.btnRead = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnUpdate = new System.Windows.Forms.Button(); + this.btnDel = new System.Windows.Forms.Button(); + this.dgvPoint = new System.Windows.Forms.DataGridView(); + this.chkColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.labID = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dgvPoint)).BeginInit(); + this.SuspendLayout(); + // + // lblName + // + this.lblName.AutoSize = true; + this.lblName.Location = new System.Drawing.Point(74, 44); + this.lblName.Name = "lblName"; + this.lblName.Size = new System.Drawing.Size(53, 12); + this.lblName.TabIndex = 0; + this.lblName.Text = "巡检名称"; + // + // lblAlias + // + this.lblAlias.AutoSize = true; + this.lblAlias.Location = new System.Drawing.Point(379, 44); + this.lblAlias.Name = "lblAlias"; + this.lblAlias.Size = new System.Drawing.Size(29, 12); + this.lblAlias.TabIndex = 1; + this.lblAlias.Text = "别名"; + // + // lblRelated + // + this.lblRelated.AutoSize = true; + this.lblRelated.Location = new System.Drawing.Point(62, 90); + this.lblRelated.Name = "lblRelated"; + this.lblRelated.Size = new System.Drawing.Size(65, 12); + this.lblRelated.TabIndex = 2; + this.lblRelated.Text = "关联标签卡"; + // + // txtName + // + this.txtName.Location = new System.Drawing.Point(137, 41); + this.txtName.Name = "txtName"; + this.txtName.Size = new System.Drawing.Size(237, 21); + this.txtName.TabIndex = 3; + // + // txtAlias + // + this.txtAlias.Location = new System.Drawing.Point(414, 41); + this.txtAlias.Name = "txtAlias"; + this.txtAlias.Size = new System.Drawing.Size(262, 21); + this.txtAlias.TabIndex = 4; + // + // txtRelation + // + this.txtRelation.Location = new System.Drawing.Point(137, 81); + this.txtRelation.Name = "txtRelation"; + this.txtRelation.ReadOnly = true; + this.txtRelation.Size = new System.Drawing.Size(237, 21); + this.txtRelation.TabIndex = 5; + // + // btnRead + // + this.btnRead.Location = new System.Drawing.Point(414, 79); + this.btnRead.Name = "btnRead"; + this.btnRead.Size = new System.Drawing.Size(75, 23); + this.btnRead.TabIndex = 6; + this.btnRead.Text = "读取"; + this.btnRead.UseVisualStyleBackColor = true; + this.btnRead.Click += new System.EventHandler(this.btnRead_Click); + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(414, 124); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 7; + this.btnSave.Text = "保存"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnUpdate + // + this.btnUpdate.Location = new System.Drawing.Point(509, 124); + this.btnUpdate.Name = "btnUpdate"; + this.btnUpdate.Size = new System.Drawing.Size(75, 23); + this.btnUpdate.TabIndex = 9; + this.btnUpdate.Text = "修改"; + this.btnUpdate.UseVisualStyleBackColor = true; + this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click); + // + // btnDel + // + this.btnDel.Location = new System.Drawing.Point(616, 124); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(75, 23); + this.btnDel.TabIndex = 10; + this.btnDel.Text = "删除"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // dgvPoint + // + this.dgvPoint.AllowUserToAddRows = false; + this.dgvPoint.AllowUserToDeleteRows = false; + this.dgvPoint.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvPoint.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.chkColumn}); + this.dgvPoint.Location = new System.Drawing.Point(27, 178); + this.dgvPoint.Name = "dgvPoint"; + this.dgvPoint.ReadOnly = true; + this.dgvPoint.RowTemplate.Height = 23; + this.dgvPoint.Size = new System.Drawing.Size(687, 329); + this.dgvPoint.TabIndex = 11; + this.dgvPoint.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvPoint_CellClick); + // + // chkColumn + // + this.chkColumn.HeaderText = "选择"; + this.chkColumn.Name = "chkColumn"; + this.chkColumn.ReadOnly = true; + this.chkColumn.Width = 38; + // + // labID + // + this.labID.AutoSize = true; + this.labID.Location = new System.Drawing.Point(507, 84); + this.labID.Name = "labID"; + this.labID.Size = new System.Drawing.Size(41, 12); + this.labID.TabIndex = 12; + this.labID.Text = "巡检ID"; + this.labID.Visible = false; + // + // frmAddPoint + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(751, 550); + this.Controls.Add(this.labID); + this.Controls.Add(this.dgvPoint); + this.Controls.Add(this.btnDel); + this.Controls.Add(this.btnUpdate); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.btnRead); + this.Controls.Add(this.txtRelation); + this.Controls.Add(this.txtAlias); + this.Controls.Add(this.txtName); + this.Controls.Add(this.lblRelated); + this.Controls.Add(this.lblAlias); + this.Controls.Add(this.lblName); + this.Name = "frmAddPoint"; + this.Text = "新建巡检点"; + this.Load += new System.EventHandler(this.frmAddPoint_Load); +<<<<<<< HEAD +======= + ((System.ComponentModel.ISupportInitialize)(this.dgvPoint)).EndInit(); +>>>>>>> qicb/Develop + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblName; + private System.Windows.Forms.Label lblAlias; + private System.Windows.Forms.Label lblRelated; + private System.Windows.Forms.TextBox txtName; + private System.Windows.Forms.TextBox txtAlias; + private System.Windows.Forms.TextBox txtRelation; + private System.Windows.Forms.Button btnRead; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnUpdate; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.DataGridView dgvPoint; + private System.Windows.Forms.DataGridViewCheckBoxColumn chkColumn; + private System.Windows.Forms.Label labID; + } +} \ No newline at end of file diff --git a/Application/frmAddPoint.cs b/Application/frmAddPoint.cs index 5fbaf09..24f2861 100644 --- a/Application/frmAddPoint.cs +++ b/Application/frmAddPoint.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using System.Data.SqlClient; namespace WorkStation { @@ -16,14 +17,134 @@ public frmAddPoint() InitializeComponent(); } - private void label1_Click(object sender, EventArgs e) + private void frmAddPoint_Load(object sender, EventArgs e) + { + this.labID.Text = ""; + this.btnSave.Enabled = false; + getDgvPoint(); + } + + private void btnSave_Click(object sender, EventArgs e) { + if (SqlHelper.ExecuteNonQuery("Select Count(1) From PhysicalCheckPoint Where [Name]='" + this.txtName.Text.Trim() + "'") > 0) + { + MessageBox.Show("已存在巡检点名称,"); + this.txtName.Focus(); + return; + } + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",SqlDbType.NVarChar), + new SqlParameter("@alias",SqlDbType.NVarChar), + new SqlParameter("@rfid",SqlDbType.BigInt) + }; + pars[0].Value = this.txtName.Text.Trim(); + pars[1].Value = this.txtAlias.Text.Trim(); + + string str_select = "Select ID From Rrid Where Name='"+this.txtRelation.Text.Trim()+"'"; + string str_rfid = (SqlHelper.ExecuteScalar("connectionstring",CommandType.Text,str_select)).ToString(); + pars[2].Value = str_rfid; + + string str_insert = "Insert Into PhysicalCheckPoint([Name],Alias,Rfid_Id) values(@name,@alias,@rfid)"; + Object obj_ret = SqlHelper.ExecuteNonQuery(str_insert,pars); + if (obj_ret.ToString() == "1") + { + MessageBox.Show("保存成功"); + } + getDgvPoint(); } - private void frmAddPoint_Load(object sender, EventArgs e) + private void btnRead_Click(object sender, EventArgs e) + { + this.btnSave.Enabled = true; + } + + private void getDgvPoint() + { + DataSet ds = SqlHelper.ExecuteDataset("Select P.ID as 编号,P.Name as 巡检名称,P.Alias as 别名,R.RFID as 关联标签卡 from PhysicalCheckPoint as P left join Rfid as R on P.Rfid_ID=R.ID"); + dgvPoint.DataSource=ds.Tables[0]; + } + + private void dgvPoint_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex == -1) return; + if (e.ColumnIndex == 0) + { + if ((bool)dgvPoint.Rows[e.RowIndex].Cells[0].EditedFormattedValue == false) + { + dgvPoint.Rows[e.RowIndex].Cells[0].Value = true; + } + else + { + dgvPoint.Rows[e.RowIndex].Cells[0].Value = false; + } + } + else + { + labID.Text = dgvPoint.Rows[e.RowIndex].Cells[1].Value.ToString(); + txtName.Text = dgvPoint.Rows[e.RowIndex].Cells[2].Value.ToString(); + txtAlias.Text = dgvPoint.Rows[e.RowIndex].Cells[3].Value.ToString(); + txtRelation.Text = dgvPoint.Rows[e.RowIndex].Cells[4].Value.ToString(); + + } + } + + private void btnUpdate_Click(object sender, EventArgs e) { + if (labID.Text == "") + return; + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",SqlDbType.NVarChar), + new SqlParameter("@alias",SqlDbType.NVarChar), + new SqlParameter("@rfid",SqlDbType.BigInt) + }; + pars[0].Value = this.txtName.Text.Trim(); + pars[1].Value = this.txtAlias.Text.Trim(); + string str_select = "Select ID From Rrid Where Name='" + this.txtRelation.Text.Trim() + "'"; + string str_rfid = (SqlHelper.ExecuteScalar("connectionstring", CommandType.Text, str_select)).ToString(); + pars[2].Value = str_rfid; + + string str_insert = "Update PhysicalCheckPoint set [Name]=@name,Alias=@alias,Rfid_Id=@rfid where ID="+labID.Text.Trim(); + + Object obj_ret = SqlHelper.ExecuteNonQuery(str_insert,pars); + if (obj_ret.ToString() == "1") + { + MessageBox.Show("修改成功"); + } + getDgvPoint(); + } + + private void btnDel_Click(object sender, EventArgs e) + { + string Del = ""; + string strsql = "Delete From PhysicalCheckPoint Where ID in("; + for (int i = 0; i < dgvPoint.Rows.Count; i++) + { + try + { + if ((bool)dgvPoint.Rows[i].Cells[0].Value == true) + { + Del += dgvPoint.Rows[i].Cells[1].Value.ToString() + ","; + } + } + catch + { + continue; + } + } + if (Del != "") + { + Del = Del.Substring(0, Del.Length - 1); + strsql += Del + ")"; + SqlHelper.ExecuteNonQuery(strsql); + getDgvPoint(); + } + else + { + MessageBox.Show("请选择要删除的项。"); + } } + } } diff --git a/Application/frmAddPoint.cs.orig b/Application/frmAddPoint.cs.orig new file mode 100644 index 0000000..2120c74 --- /dev/null +++ b/Application/frmAddPoint.cs.orig @@ -0,0 +1,178 @@ +<<<<<<< HEAD +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace WorkStation +{ + public partial class frmAddPoint : Form + { + public frmAddPoint() + { + InitializeComponent(); + } + + + private void frmAddPoint_Load(object sender, EventArgs e) + { + + } + } +} +======= +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddPoint : Form + { + public frmAddPoint() + { + InitializeComponent(); + } + + private void frmAddPoint_Load(object sender, EventArgs e) + { + this.labID.Text = ""; + this.btnSave.Enabled = false; + getDgvPoint(); + } + + private void btnSave_Click(object sender, EventArgs e) + { + if (SqlHelper.ExecuteNonQuery("Select Count(1) From PhysicalCheckPoint Where [Name]='" + this.txtName.Text.Trim() + "'") > 0) + { + MessageBox.Show("已存在巡检点名称,"); + this.txtName.Focus(); + return; + } + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",SqlDbType.NVarChar), + new SqlParameter("@alias",SqlDbType.NVarChar), + new SqlParameter("@rfid",SqlDbType.BigInt) + }; + pars[0].Value = this.txtName.Text.Trim(); + pars[1].Value = this.txtAlias.Text.Trim(); + + string str_select = "Select ID From Rrid Where Name='"+this.txtRelation.Text.Trim()+"'"; + string str_rfid = (SqlHelper.ExecuteScalar("connectionstring",CommandType.Text,str_select)).ToString(); + pars[2].Value = str_rfid; + + string str_insert = "Insert Into PhysicalCheckPoint([Name],Alias,Rfid_Id) values(@name,@alias,@rfid)"; + + Object obj_ret = SqlHelper.ExecuteNonQuery(str_insert,pars); + if (obj_ret.ToString() == "1") + { + MessageBox.Show("保存成功"); + } + getDgvPoint(); + } + + private void btnRead_Click(object sender, EventArgs e) + { + this.btnSave.Enabled = true; + } + + private void getDgvPoint() + { + DataSet ds = SqlHelper.ExecuteDataset("Select P.ID as 编号,P.Name as 巡检名称,P.Alias as 别名,R.RFID as 关联标签卡 from PhysicalCheckPoint as P left join Rfid as R on P.Rfid_ID=R.ID"); + dgvPoint.DataSource=ds.Tables[0]; + } + + private void dgvPoint_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex == -1) return; + if (e.ColumnIndex == 0) + { + if ((bool)dgvPoint.Rows[e.RowIndex].Cells[0].EditedFormattedValue == false) + { + dgvPoint.Rows[e.RowIndex].Cells[0].Value = true; + } + else + { + dgvPoint.Rows[e.RowIndex].Cells[0].Value = false; + } + } + else + { + labID.Text = dgvPoint.Rows[e.RowIndex].Cells[1].Value.ToString(); + txtName.Text = dgvPoint.Rows[e.RowIndex].Cells[2].Value.ToString(); + txtAlias.Text = dgvPoint.Rows[e.RowIndex].Cells[3].Value.ToString(); + txtRelation.Text = dgvPoint.Rows[e.RowIndex].Cells[4].Value.ToString(); + + } + } + + private void btnUpdate_Click(object sender, EventArgs e) + { + if (labID.Text == "") + return; + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@name",SqlDbType.NVarChar), + new SqlParameter("@alias",SqlDbType.NVarChar), + new SqlParameter("@rfid",SqlDbType.BigInt) + }; + pars[0].Value = this.txtName.Text.Trim(); + pars[1].Value = this.txtAlias.Text.Trim(); + + string str_select = "Select ID From Rrid Where Name='" + this.txtRelation.Text.Trim() + "'"; + string str_rfid = (SqlHelper.ExecuteScalar("connectionstring", CommandType.Text, str_select)).ToString(); + pars[2].Value = str_rfid; + + string str_insert = "Update PhysicalCheckPoint set [Name]=@name,Alias=@alias,Rfid_Id=@rfid where ID="+labID.Text.Trim(); + + Object obj_ret = SqlHelper.ExecuteNonQuery(str_insert,pars); + if (obj_ret.ToString() == "1") + { + MessageBox.Show("修改成功"); + } + getDgvPoint(); + } + + private void btnDel_Click(object sender, EventArgs e) + { + string Del = ""; + string strsql = "Delete From PhysicalCheckPoint Where ID in("; + for (int i = 0; i < dgvPoint.Rows.Count; i++) + { + try + { + if ((bool)dgvPoint.Rows[i].Cells[0].Value == true) + { + Del += dgvPoint.Rows[i].Cells[1].Value.ToString() + ","; + } + } + catch + { + continue; + } + } + if (Del != "") + { + Del = Del.Substring(0, Del.Length - 1); + strsql += Del + ")"; + SqlHelper.ExecuteNonQuery(strsql); + getDgvPoint(); + } + else + { + MessageBox.Show("请选择要删除的项。"); + } + } + + } +} +>>>>>>> qicb/Develop diff --git a/Application/frmAddPoint.resx b/Application/frmAddPoint.resx index 1af7de1..ea347e6 100644 --- a/Application/frmAddPoint.resx +++ b/Application/frmAddPoint.resx @@ -1,120 +1,126 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + \ No newline at end of file diff --git a/Application/frmAddRoutName.Designer.cs b/Application/frmAddRoutName.Designer.cs new file mode 100644 index 0000000..0a4e0e6 --- /dev/null +++ b/Application/frmAddRoutName.Designer.cs @@ -0,0 +1,169 @@ +namespace WorkStation +{ + partial class frmAddRoutName + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.cboSiteArea = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.tbRouteName = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.tbRouteAlias = new System.Windows.Forms.TextBox(); + this.btnClose = new System.Windows.Forms.Button(); + this.btnTrue = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.cboInOrder = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // cboSiteArea + // + this.cboSiteArea.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboSiteArea.FormattingEnabled = true; + this.cboSiteArea.Location = new System.Drawing.Point(85, 21); + this.cboSiteArea.Name = "cboSiteArea"; + this.cboSiteArea.Size = new System.Drawing.Size(183, 20); + this.cboSiteArea.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 12); + this.label1.TabIndex = 1; + this.label1.Text = "所在厂区"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(28, 60); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 12); + this.label2.TabIndex = 2; + this.label2.Text = "路线名称"; + // + // tbRouteName + // + this.tbRouteName.Location = new System.Drawing.Point(85, 57); + this.tbRouteName.Name = "tbRouteName"; + this.tbRouteName.Size = new System.Drawing.Size(183, 21); + this.tbRouteName.TabIndex = 3; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(28, 89); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 4; + this.label3.Text = "路线别名"; + // + // tbRouteAlias + // + this.tbRouteAlias.Location = new System.Drawing.Point(85, 86); + this.tbRouteAlias.Name = "tbRouteAlias"; + this.tbRouteAlias.Size = new System.Drawing.Size(183, 21); + this.tbRouteAlias.TabIndex = 5; + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(180, 155); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 6; + this.btnClose.Text = "关闭"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // btnTrue + // + this.btnTrue.Location = new System.Drawing.Point(85, 155); + this.btnTrue.Name = "btnTrue"; + this.btnTrue.Size = new System.Drawing.Size(75, 23); + this.btnTrue.TabIndex = 7; + this.btnTrue.Text = "添加"; + this.btnTrue.UseVisualStyleBackColor = true; + this.btnTrue.Click += new System.EventHandler(this.btnTrue_Click); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(26, 118); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(53, 12); + this.label4.TabIndex = 8; + this.label4.Text = "顺序巡检"; + // + // cboInOrder + // + this.cboInOrder.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboInOrder.FormattingEnabled = true; + this.cboInOrder.Location = new System.Drawing.Point(85, 115); + this.cboInOrder.Name = "cboInOrder"; + this.cboInOrder.Size = new System.Drawing.Size(183, 20); + this.cboInOrder.TabIndex = 9; + // + // frmAddRoutName + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(313, 225); + this.Controls.Add(this.cboInOrder); + this.Controls.Add(this.label4); + this.Controls.Add(this.btnTrue); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.tbRouteAlias); + this.Controls.Add(this.label3); + this.Controls.Add(this.tbRouteName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.cboSiteArea); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.Name = "frmAddRoutName"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "路线详细信息"; + this.Load += new System.EventHandler(this.frmAddRoutName_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + public System.Windows.Forms.ComboBox cboSiteArea; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + public System.Windows.Forms.TextBox tbRouteName; + private System.Windows.Forms.Label label3; + public System.Windows.Forms.TextBox tbRouteAlias; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Button btnTrue; + private System.Windows.Forms.Label label4; + public System.Windows.Forms.ComboBox cboInOrder; + } +} \ No newline at end of file diff --git a/Application/frmAddRoutName.cs b/Application/frmAddRoutName.cs new file mode 100644 index 0000000..c5621fd --- /dev/null +++ b/Application/frmAddRoutName.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddRoutName : Form + { + public Boolean isEdit=false; + public object routeID; + public string routeName, routeAlias, routeArea; + public TreeView tView; + public frmAddRoutName() + { + InitializeComponent(); + } + + private void frmAddRoutName_Load(object sender, EventArgs e) + { + if (isEdit) + { + this.btnTrue.Text = "修改"; + this.Text = "修改巡检路线"; + SqlDataReader dr = SqlHelper.ExecuteReader("Select Site_ID,Name,Alias,Sequence From CheckRoute Where ID="+routeID.ToString()); + if (dr == null) return; + while (dr.Read()) + { + this.cboSiteArea.SelectedValue = dr["Site_ID"]; + this.tbRouteName.Text = dr["Name"].ToString(); + this.tbRouteAlias.Text = dr["Alias"].ToString(); + this.cboInOrder.SelectedValue = dr["Sequence"].ToString(); + } + dr.Dispose(); + } + this.cbo_init(); + } + + private void btnTrue_Click(object sender, EventArgs e) + { + int _ret=(int)SqlHelper.ExecuteScalar("Select Count(1) From CheckRoute Where Name='" + this.tbRouteName.Text.Trim() + "' and Site_ID=" + cboSiteArea.SelectedValue.ToString()); + if ( isEdit==false&&_ret!= 0) + { + MessageBox.Show("请确保路线名称的唯一性"); + return; + } + string strsql = ""; + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@id",SqlDbType.BigInt), + new SqlParameter("@name",this.tbRouteName.Text.Trim().ToString()), + new SqlParameter("@alias",this.tbRouteAlias.Text.Trim().ToString()), + new SqlParameter("@routeid",SqlDbType.BigInt), + new SqlParameter("@sequence",SqlDbType.Int) + }; + if (isEdit) + { + strsql = "Update CheckRoute Set Site_ID=@id,[Name]=@name,Alias=@alias,Sequence=@sequence Where ID=@routeid"; + } + else + { + strsql = "Insert Into CheckRoute(Site_ID,[Name],Alias,Sequence) Values(@id,@name,@alias,@sequence)"; + + } + pars[0].Value = cboSiteArea.SelectedValue.ToString(); + pars[3].Value = routeID; + pars[4].Value = this.cboInOrder.SelectedValue; + SqlHelper.ExecuteNonQuery(strsql, pars); + frmAddRoute.tvRouteInit(tView); + tView.ExpandAll(); + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void cbo_init() + { + DataSet ds = SqlHelper.ExecuteDataset("Select Code,Meaning From Codes where purpose='CheckSequence' "); + this.cboInOrder.DataSource = ds.Tables[0]; + this.cboInOrder.DisplayMember = "Meaning"; + this.cboInOrder.ValueMember = "Code"; + this.cboInOrder.SelectedIndex = this.cboInOrder.Items.Count > 0 ? 0 : -1; + ds.Dispose(); + + ds = SqlHelper.ExecuteDataset("Select Id,Name From Site"); + cboSiteArea.DataSource = ds.Tables[0]; + cboSiteArea.DisplayMember = "Name"; + cboSiteArea.ValueMember = "ID"; + this.cboSiteArea.SelectedIndex = this.cboSiteArea.Items.Count > 0 ? 0 : -1; + ds.Dispose(); + } + } +} diff --git a/Application/frmAddRoutName.cs.orig b/Application/frmAddRoutName.cs.orig new file mode 100644 index 0000000..bdcec20 --- /dev/null +++ b/Application/frmAddRoutName.cs.orig @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddRoutName : Form + { + public Boolean isEdit = false; + public object routeID; + public string routeName, routeAlias, routeArea; + public TreeView tView; + public frmAddRoutName() + { + InitializeComponent(); + } + + private void frmAddRoutName_Load(object sender, EventArgs e) + { + if (isEdit) + { + this.btnTrue.Text = "修改"; + this.Text = "修改巡检路线"; +<<<<<<< HEAD + SqlDataReader dr = SqlHelper.ExecuteReader("Select Site_ID,Name,Alias,Code From CheckRoute Where ID=" + routeID.ToString()); +======= + SqlDataReader dr = SqlHelper.ExecuteReader("Select Site_ID,Name,Alias,Sequence From CheckRoute Where ID="+routeID.ToString()); +>>>>>>> qicb/Develop + if (dr == null) return; + while (dr.Read()) + { + this.cboSiteArea.SelectedValue = dr["Site_ID"]; + this.tbRouteName.Text = dr["Name"].ToString(); + this.tbRouteAlias.Text = dr["Alias"].ToString(); + this.cboInOrder.SelectedValue = dr["Sequence"].ToString(); + } + dr.Dispose(); + } + this.cbo_init(); + } + + private void btnTrue_Click(object sender, EventArgs e) + { +<<<<<<< HEAD + int _ret = (int)SqlHelper.ExecuteScalar("Select Count(1) From CheckRoute Where Name='" + this.tbRouteName.Text.Trim() + "' and Site_ID=" + cboSiteArea.SelectedValue.ToString()); + if (_ret != 0) +======= + int _ret=(int)SqlHelper.ExecuteScalar("Select Count(1) From CheckRoute Where Name='" + this.tbRouteName.Text.Trim() + "' and Site_ID=" + cboSiteArea.SelectedValue.ToString()); + if ( isEdit==false&&_ret!= 0) +>>>>>>> qicb/Develop + { + MessageBox.Show("请确保路线名称的唯一性"); + return; + } + string strsql = ""; + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@id",SqlDbType.BigInt), + new SqlParameter("@name",this.tbRouteName.Text.Trim().ToString()), + new SqlParameter("@alias",this.tbRouteAlias.Text.Trim().ToString()), + new SqlParameter("@routeid",SqlDbType.BigInt), + new SqlParameter("@sequence",SqlDbType.Int) + }; + if (isEdit) + { +<<<<<<< HEAD + strsql = "Update CheckRoute Set Site_ID=@id,[Name]=@name,Alias=@alias,Code=@code Where ID=@routeid"; + } + else + { + strsql = "Insert Into CheckRoute(Site_ID,[Name],Alias,Code) Values(@id,@name,@alias,@code)"; + + } +======= + strsql = "Update CheckRoute Set Site_ID=@id,[Name]=@name,Alias=@alias,Sequence=@sequence Where ID=@routeid"; + } + else + { + strsql = "Insert Into CheckRoute(Site_ID,[Name],Alias,Sequence) Values(@id,@name,@alias,@sequence)"; + + } +>>>>>>> qicb/Develop + pars[0].Value = cboSiteArea.SelectedValue.ToString(); + pars[3].Value = routeID; + pars[4].Value = this.cboInOrder.SelectedValue; + SqlHelper.ExecuteNonQuery(strsql, pars); + frmAddRoute.tvRouteInit(tView); + tView.ExpandAll(); + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void cbo_init() + { +<<<<<<< HEAD + DataSet ds = SqlHelper.ExecuteDataset("Select Code,Meaning From Codes WHERE Purpose ='CheckSequence'"); +======= + DataSet ds = SqlHelper.ExecuteDataset("Select Code,Meaning From Codes where purpose='CheckSequence' "); +>>>>>>> qicb/Develop + this.cboInOrder.DataSource = ds.Tables[0]; + this.cboInOrder.DisplayMember = "Meaning"; + this.cboInOrder.ValueMember = "Code"; + this.cboInOrder.SelectedIndex = this.cboInOrder.Items.Count > 0 ? 0 : -1; + ds.Dispose(); + + ds = SqlHelper.ExecuteDataset("Select Id,Name From Site"); + cboSiteArea.DataSource = ds.Tables[0]; + cboSiteArea.DisplayMember = "Name"; + cboSiteArea.ValueMember = "ID"; + this.cboSiteArea.SelectedIndex = this.cboSiteArea.Items.Count > 0 ? 0 : -1; + ds.Dispose(); + } + } +} diff --git a/Application/frmAddRoutName.resx b/Application/frmAddRoutName.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/Application/frmAddRoutName.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Application/frmAddRoute.Designer.cs b/Application/frmAddRoute.Designer.cs index 3548b86..197d63c 100644 --- a/Application/frmAddRoute.Designer.cs +++ b/Application/frmAddRoute.Designer.cs @@ -28,153 +28,284 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.lblName = new System.Windows.Forms.Label(); - this.lblAlias = new System.Windows.Forms.Label(); - this.lblGenus = new System.Windows.Forms.Label(); - this.lblPoint = new System.Windows.Forms.Label(); - this.txtName = new System.Windows.Forms.TextBox(); - this.txtGenus = new System.Windows.Forms.TextBox(); - this.txtAlias = new System.Windows.Forms.TextBox(); - this.txtPoint = new System.Windows.Forms.TextBox(); - this.listView1 = new System.Windows.Forms.ListView(); - this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.新建路线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.删除路线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.chkRoute = new System.Windows.Forms.CheckBox(); + this.tvRoute = new System.Windows.Forms.TreeView(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.labRouteID = new System.Windows.Forms.Label(); + this.btnAddTemplate = new System.Windows.Forms.Button(); + this.chkPhysicalPoint = new System.Windows.Forms.CheckBox(); + this.chkLogicalPoint = new System.Windows.Forms.CheckBox(); + this.tvPhysicalPoint = new System.Windows.Forms.TreeView(); + this.label2 = new System.Windows.Forms.Label(); + this.tbRoute = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.tvLogicalPoint = new System.Windows.Forms.TreeView(); this.btnSave = new System.Windows.Forms.Button(); + this.btnMoveDown = new System.Windows.Forms.Button(); + this.btnMoveUp = new System.Windows.Forms.Button(); + this.btnDel = new System.Windows.Forms.Button(); + this.btnAdd = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // - // lblName - // - this.lblName.AutoSize = true; - this.lblName.Location = new System.Drawing.Point(206, 59); - this.lblName.Name = "lblName"; - this.lblName.Size = new System.Drawing.Size(29, 12); - this.lblName.TabIndex = 0; - this.lblName.Text = "名称"; - // - // lblAlias - // - this.lblAlias.AutoSize = true; - this.lblAlias.Location = new System.Drawing.Point(206, 99); - this.lblAlias.Name = "lblAlias"; - this.lblAlias.Size = new System.Drawing.Size(29, 12); - this.lblAlias.TabIndex = 1; - this.lblAlias.Text = "别名"; - // - // lblGenus - // - this.lblGenus.AutoSize = true; - this.lblGenus.Location = new System.Drawing.Point(182, 133); - this.lblGenus.Name = "lblGenus"; - this.lblGenus.Size = new System.Drawing.Size(53, 12); - this.lblGenus.TabIndex = 2; - this.lblGenus.Text = "所属厂区"; - // - // lblPoint - // - this.lblPoint.AutoSize = true; - this.lblPoint.Location = new System.Drawing.Point(158, 169); - this.lblPoint.Name = "lblPoint"; - this.lblPoint.Size = new System.Drawing.Size(77, 12); - this.lblPoint.TabIndex = 3; - this.lblPoint.Text = "包含的巡检点"; - // - // txtName - // - this.txtName.Location = new System.Drawing.Point(295, 56); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(224, 21); - this.txtName.TabIndex = 4; - // - // txtGenus - // - this.txtGenus.Location = new System.Drawing.Point(295, 124); - this.txtGenus.Name = "txtGenus"; - this.txtGenus.Size = new System.Drawing.Size(224, 21); - this.txtGenus.TabIndex = 5; - // - // txtAlias - // - this.txtAlias.Location = new System.Drawing.Point(295, 90); - this.txtAlias.Name = "txtAlias"; - this.txtAlias.Size = new System.Drawing.Size(224, 21); - this.txtAlias.TabIndex = 6; - // - // txtPoint - // - this.txtPoint.Location = new System.Drawing.Point(295, 160); - this.txtPoint.Name = "txtPoint"; - this.txtPoint.Size = new System.Drawing.Size(224, 21); - this.txtPoint.TabIndex = 8; - // - // listView1 - // - this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.columnHeader1, - this.columnHeader2, - this.columnHeader3, - this.columnHeader4, - this.columnHeader5}); - this.listView1.GridLines = true; - this.listView1.Location = new System.Drawing.Point(106, 220); - this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(586, 198); - this.listView1.TabIndex = 9; - this.listView1.UseCompatibleStateImageBehavior = false; - this.listView1.View = System.Windows.Forms.View.Details; - // - // columnHeader1 - // - this.columnHeader1.Text = "巡检路线编号"; - this.columnHeader1.Width = 116; - // - // columnHeader2 - // - this.columnHeader2.Text = "名称"; - this.columnHeader2.Width = 75; - // - // columnHeader3 - // - this.columnHeader3.Text = "别名"; - // - // columnHeader4 - // - this.columnHeader4.Text = "所属厂区"; - this.columnHeader4.Width = 85; - // - // columnHeader5 - // - this.columnHeader5.Text = "包含的巡检点"; - this.columnHeader5.Width = 111; + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.新建路线ToolStripMenuItem, + this.toolStripMenuItem1, + this.删除路线ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(751, 24); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // 新建路线ToolStripMenuItem + // + this.新建路线ToolStripMenuItem.Name = "新建路线ToolStripMenuItem"; + this.新建路线ToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.新建路线ToolStripMenuItem.Text = "新建路线"; + this.新建路线ToolStripMenuItem.Click += new System.EventHandler(this.新建路线ToolStripMenuItem_Click); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(65, 20); + this.toolStripMenuItem1.Text = "编辑路线"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // + // 删除路线ToolStripMenuItem + // + this.删除路线ToolStripMenuItem.Name = "删除路线ToolStripMenuItem"; + this.删除路线ToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.删除路线ToolStripMenuItem.Text = "删除路线"; + this.删除路线ToolStripMenuItem.Click += new System.EventHandler(this.删除路线ToolStripMenuItem_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.chkRoute); + this.groupBox1.Controls.Add(this.tvRoute); + this.groupBox1.Location = new System.Drawing.Point(13, 28); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(223, 486); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "巡检路线"; + // + // chkRoute + // + this.chkRoute.AutoSize = true; + this.chkRoute.Checked = true; + this.chkRoute.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkRoute.Location = new System.Drawing.Point(93, 458); + this.chkRoute.Name = "chkRoute"; + this.chkRoute.Size = new System.Drawing.Size(72, 16); + this.chkRoute.TabIndex = 1; + this.chkRoute.Text = "自动展开"; + this.chkRoute.UseVisualStyleBackColor = true; + this.chkRoute.CheckedChanged += new System.EventHandler(this.chkRoute_CheckedChanged); + // + // tvRoute + // + this.tvRoute.Location = new System.Drawing.Point(6, 20); + this.tvRoute.Name = "tvRoute"; + this.tvRoute.Size = new System.Drawing.Size(211, 432); + this.tvRoute.TabIndex = 0; + this.tvRoute.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvRoute_AfterSelect); + this.tvRoute.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvRoute_NodeMouseDoubleClick); + // + // groupBox2 + // + this.groupBox2.BackColor = System.Drawing.SystemColors.Control; + this.groupBox2.Controls.Add(this.labRouteID); + this.groupBox2.Controls.Add(this.btnAddTemplate); + this.groupBox2.Controls.Add(this.chkPhysicalPoint); + this.groupBox2.Controls.Add(this.chkLogicalPoint); + this.groupBox2.Controls.Add(this.tvPhysicalPoint); + this.groupBox2.Controls.Add(this.label2); + this.groupBox2.Controls.Add(this.tbRoute); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this.tvLogicalPoint); + this.groupBox2.Controls.Add(this.btnSave); + this.groupBox2.Controls.Add(this.btnMoveDown); + this.groupBox2.Controls.Add(this.btnMoveUp); + this.groupBox2.Controls.Add(this.btnDel); + this.groupBox2.Controls.Add(this.btnAdd); + this.groupBox2.Location = new System.Drawing.Point(254, 28); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(485, 486); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路线巡检点设置"; + // + // labRouteID + // + this.labRouteID.AutoSize = true; + this.labRouteID.Location = new System.Drawing.Point(273, 31); + this.labRouteID.Name = "labRouteID"; + this.labRouteID.Size = new System.Drawing.Size(41, 12); + this.labRouteID.TabIndex = 18; + this.labRouteID.Text = "路线ID"; + this.labRouteID.Visible = false; + // + // btnAddTemplate + // + this.btnAddTemplate.Location = new System.Drawing.Point(202, 82); + this.btnAddTemplate.Name = "btnAddTemplate"; + this.btnAddTemplate.Size = new System.Drawing.Size(75, 23); + this.btnAddTemplate.TabIndex = 17; + this.btnAddTemplate.Text = "添加模板"; + this.btnAddTemplate.UseVisualStyleBackColor = true; + // + // chkPhysicalPoint + // + this.chkPhysicalPoint.AutoSize = true; + this.chkPhysicalPoint.Checked = true; + this.chkPhysicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkPhysicalPoint.Location = new System.Drawing.Point(338, 458); + this.chkPhysicalPoint.Name = "chkPhysicalPoint"; + this.chkPhysicalPoint.Size = new System.Drawing.Size(72, 16); + this.chkPhysicalPoint.TabIndex = 16; + this.chkPhysicalPoint.Text = "自动展开"; + this.chkPhysicalPoint.UseVisualStyleBackColor = true; + this.chkPhysicalPoint.CheckedChanged += new System.EventHandler(this.chkPhysicalPoint_CheckedChanged); + // + // chkLogicalPoint + // + this.chkLogicalPoint.AutoSize = true; + this.chkLogicalPoint.Checked = true; + this.chkLogicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkLogicalPoint.Location = new System.Drawing.Point(50, 458); + this.chkLogicalPoint.Name = "chkLogicalPoint"; + this.chkLogicalPoint.Size = new System.Drawing.Size(72, 16); + this.chkLogicalPoint.TabIndex = 15; + this.chkLogicalPoint.Text = "自动展开"; + this.chkLogicalPoint.UseVisualStyleBackColor = true; + this.chkLogicalPoint.CheckedChanged += new System.EventHandler(this.chkLogicalPoint_CheckedChanged); + // + // tvPhysicalPoint + // + this.tvPhysicalPoint.Location = new System.Drawing.Point(282, 56); + this.tvPhysicalPoint.Name = "tvPhysicalPoint"; + this.tvPhysicalPoint.Size = new System.Drawing.Size(197, 396); + this.tvPhysicalPoint.TabIndex = 13; + this.tvPhysicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvPhysicalPoint_BeforeSelect); + this.tvPhysicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvPhysicalPoint_NodeMouseDoubleClick); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(336, 31); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 12; + this.label2.Text = "巡检点"; + // + // tbRoute + // + this.tbRoute.BackColor = System.Drawing.SystemColors.Control; + this.tbRoute.ForeColor = System.Drawing.SystemColors.WindowText; + this.tbRoute.Location = new System.Drawing.Point(75, 23); + this.tbRoute.Name = "tbRoute"; + this.tbRoute.ReadOnly = true; + this.tbRoute.Size = new System.Drawing.Size(191, 21); + this.tbRoute.TabIndex = 11; + this.tbRoute.Text = "shenm "; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(15, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(65, 12); + this.label1.TabIndex = 10; + this.label1.Text = "当前路线:"; + // + // tvLogicalPoint + // + this.tvLogicalPoint.Location = new System.Drawing.Point(6, 56); + this.tvLogicalPoint.Name = "tvLogicalPoint"; + this.tvLogicalPoint.Size = new System.Drawing.Size(189, 396); + this.tvLogicalPoint.TabIndex = 9; + this.tvLogicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvLogicalPoint_BeforeSelect); + this.tvLogicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvLogicalPoint_NodeMouseDoubleClick); // // btnSave // - this.btnSave.Location = new System.Drawing.Point(597, 169); + this.btnSave.Location = new System.Drawing.Point(201, 375); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); - this.btnSave.TabIndex = 10; + this.btnSave.TabIndex = 8; this.btnSave.Text = "保存"; this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnMoveDown + // + this.btnMoveDown.Location = new System.Drawing.Point(201, 207); + this.btnMoveDown.Name = "btnMoveDown"; + this.btnMoveDown.Size = new System.Drawing.Size(75, 23); + this.btnMoveDown.TabIndex = 6; + this.btnMoveDown.Text = "下移"; + this.btnMoveDown.UseVisualStyleBackColor = true; + this.btnMoveDown.Click += new System.EventHandler(this.btnMoveDown_Click); + // + // btnMoveUp + // + this.btnMoveUp.Location = new System.Drawing.Point(201, 171); + this.btnMoveUp.Name = "btnMoveUp"; + this.btnMoveUp.Size = new System.Drawing.Size(75, 23); + this.btnMoveUp.TabIndex = 5; + this.btnMoveUp.Text = "上移"; + this.btnMoveUp.UseVisualStyleBackColor = true; + this.btnMoveUp.Click += new System.EventHandler(this.btnMoveUp_Click); + // + // btnDel + // + this.btnDel.Location = new System.Drawing.Point(201, 140); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(75, 23); + this.btnDel.TabIndex = 2; + this.btnDel.Text = ">"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // btnAdd + // + this.btnAdd.Location = new System.Drawing.Point(201, 111); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(75, 23); + this.btnAdd.TabIndex = 1; + this.btnAdd.Text = "<"; + this.btnAdd.UseVisualStyleBackColor = true; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // // frmAddRoute // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(744, 470); - this.Controls.Add(this.btnSave); - this.Controls.Add(this.listView1); - this.Controls.Add(this.txtPoint); - this.Controls.Add(this.txtAlias); - this.Controls.Add(this.txtGenus); - this.Controls.Add(this.txtName); - this.Controls.Add(this.lblPoint); - this.Controls.Add(this.lblGenus); - this.Controls.Add(this.lblAlias); - this.Controls.Add(this.lblName); + this.ClientSize = new System.Drawing.Size(751, 526); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; this.Name = "frmAddRoute"; this.Text = "新建巡检路线"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmAddRoute_FormClosing); + this.Load += new System.EventHandler(this.frmAddRoute_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -182,20 +313,29 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.Label lblName; - private System.Windows.Forms.Label lblAlias; - private System.Windows.Forms.Label lblGenus; - private System.Windows.Forms.Label lblPoint; - private System.Windows.Forms.TextBox txtName; - private System.Windows.Forms.TextBox txtGenus; - private System.Windows.Forms.TextBox txtAlias; - private System.Windows.Forms.TextBox txtPoint; - private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem 新建路线ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 删除路线ToolStripMenuItem; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox chkRoute; + private System.Windows.Forms.TreeView tvRoute; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Button btnMoveDown; + private System.Windows.Forms.Button btnMoveUp; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.Button btnSave; - private System.Windows.Forms.ColumnHeader columnHeader1; - private System.Windows.Forms.ColumnHeader columnHeader2; - private System.Windows.Forms.ColumnHeader columnHeader3; - private System.Windows.Forms.ColumnHeader columnHeader4; - private System.Windows.Forms.ColumnHeader columnHeader5; + private System.Windows.Forms.Button btnAddTemplate; + private System.Windows.Forms.CheckBox chkPhysicalPoint; + private System.Windows.Forms.CheckBox chkLogicalPoint; + private System.Windows.Forms.TreeView tvPhysicalPoint; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox tbRoute; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TreeView tvLogicalPoint; + private System.Windows.Forms.Label labRouteID; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + + } } \ No newline at end of file diff --git a/Application/frmAddRoute.Designer.cs.orig b/Application/frmAddRoute.Designer.cs.orig new file mode 100644 index 0000000..9329751 --- /dev/null +++ b/Application/frmAddRoute.Designer.cs.orig @@ -0,0 +1,487 @@ +namespace WorkStation +{ + partial class frmAddRoute + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { +<<<<<<< HEAD + this.lblName = new System.Windows.Forms.Label(); + this.lblAlias = new System.Windows.Forms.Label(); + this.lblGenus = new System.Windows.Forms.Label(); + this.lblPoint = new System.Windows.Forms.Label(); + this.txtName = new System.Windows.Forms.TextBox(); + this.txtGenus = new System.Windows.Forms.TextBox(); + this.txtAlias = new System.Windows.Forms.TextBox(); + this.txtPoint = new System.Windows.Forms.TextBox(); + this.listView1 = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.btnSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lblName + // + this.lblName.AutoSize = true; + this.lblName.Location = new System.Drawing.Point(206, 59); + this.lblName.Name = "lblName"; + this.lblName.Size = new System.Drawing.Size(29, 12); + this.lblName.TabIndex = 0; + this.lblName.Text = "名称"; + // + // lblAlias + // + this.lblAlias.AutoSize = true; + this.lblAlias.Location = new System.Drawing.Point(206, 99); + this.lblAlias.Name = "lblAlias"; + this.lblAlias.Size = new System.Drawing.Size(29, 12); + this.lblAlias.TabIndex = 1; + this.lblAlias.Text = "别名"; + // + // lblGenus + // + this.lblGenus.AutoSize = true; + this.lblGenus.Location = new System.Drawing.Point(182, 133); + this.lblGenus.Name = "lblGenus"; + this.lblGenus.Size = new System.Drawing.Size(53, 12); + this.lblGenus.TabIndex = 2; + this.lblGenus.Text = "所属厂区"; + // + // lblPoint + // + this.lblPoint.AutoSize = true; + this.lblPoint.Location = new System.Drawing.Point(158, 169); + this.lblPoint.Name = "lblPoint"; + this.lblPoint.Size = new System.Drawing.Size(77, 12); + this.lblPoint.TabIndex = 3; + this.lblPoint.Text = "包含的巡检点"; + // + // txtName + // + this.txtName.Location = new System.Drawing.Point(295, 56); + this.txtName.Name = "txtName"; + this.txtName.Size = new System.Drawing.Size(224, 21); + this.txtName.TabIndex = 4; + // + // txtGenus + // + this.txtGenus.Location = new System.Drawing.Point(295, 124); + this.txtGenus.Name = "txtGenus"; + this.txtGenus.Size = new System.Drawing.Size(224, 21); + this.txtGenus.TabIndex = 5; + // + // txtAlias + // + this.txtAlias.Location = new System.Drawing.Point(295, 90); + this.txtAlias.Name = "txtAlias"; + this.txtAlias.Size = new System.Drawing.Size(224, 21); + this.txtAlias.TabIndex = 6; + // + // txtPoint + // + this.txtPoint.Location = new System.Drawing.Point(295, 160); + this.txtPoint.Name = "txtPoint"; + this.txtPoint.Size = new System.Drawing.Size(224, 21); + this.txtPoint.TabIndex = 8; + // + // listView1 + // + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1, + this.columnHeader2, + this.columnHeader3, + this.columnHeader4, + this.columnHeader5}); + this.listView1.GridLines = true; + this.listView1.Location = new System.Drawing.Point(106, 220); + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(586, 198); + this.listView1.TabIndex = 9; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + // + // columnHeader1 + // + this.columnHeader1.Text = "巡检路线编号"; + this.columnHeader1.Width = 116; + // + // columnHeader2 + // + this.columnHeader2.Text = "名称"; + this.columnHeader2.Width = 75; + // + // columnHeader3 + // + this.columnHeader3.Text = "别名"; + // + // columnHeader4 + // + this.columnHeader4.Text = "所属厂区"; + this.columnHeader4.Width = 85; + // + // columnHeader5 + // + this.columnHeader5.Text = "包含的巡检点"; + this.columnHeader5.Width = 111; +======= + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.新建路线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.删除路线ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.chkRoute = new System.Windows.Forms.CheckBox(); + this.tvRoute = new System.Windows.Forms.TreeView(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.labRouteID = new System.Windows.Forms.Label(); + this.btnAddTemplate = new System.Windows.Forms.Button(); + this.chkPhysicalPoint = new System.Windows.Forms.CheckBox(); + this.chkLogicalPoint = new System.Windows.Forms.CheckBox(); + this.tvPhysicalPoint = new System.Windows.Forms.TreeView(); + this.label2 = new System.Windows.Forms.Label(); + this.tbRoute = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.tvLogicalPoint = new System.Windows.Forms.TreeView(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnMoveDown = new System.Windows.Forms.Button(); + this.btnMoveUp = new System.Windows.Forms.Button(); + this.btnDel = new System.Windows.Forms.Button(); + this.btnAdd = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.新建路线ToolStripMenuItem, + this.toolStripMenuItem1, + this.删除路线ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(751, 24); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // 新建路线ToolStripMenuItem + // + this.新建路线ToolStripMenuItem.Name = "新建路线ToolStripMenuItem"; + this.新建路线ToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.新建路线ToolStripMenuItem.Text = "新建路线"; + this.新建路线ToolStripMenuItem.Click += new System.EventHandler(this.新建路线ToolStripMenuItem_Click); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(65, 20); + this.toolStripMenuItem1.Text = "编辑路线"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // + // 删除路线ToolStripMenuItem + // + this.删除路线ToolStripMenuItem.Name = "删除路线ToolStripMenuItem"; + this.删除路线ToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.删除路线ToolStripMenuItem.Text = "删除路线"; + this.删除路线ToolStripMenuItem.Click += new System.EventHandler(this.删除路线ToolStripMenuItem_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.chkRoute); + this.groupBox1.Controls.Add(this.tvRoute); + this.groupBox1.Location = new System.Drawing.Point(13, 28); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(223, 486); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "巡检路线"; + // + // chkRoute + // + this.chkRoute.AutoSize = true; + this.chkRoute.Checked = true; + this.chkRoute.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkRoute.Location = new System.Drawing.Point(93, 458); + this.chkRoute.Name = "chkRoute"; + this.chkRoute.Size = new System.Drawing.Size(72, 16); + this.chkRoute.TabIndex = 1; + this.chkRoute.Text = "自动展开"; + this.chkRoute.UseVisualStyleBackColor = true; + this.chkRoute.CheckedChanged += new System.EventHandler(this.chkRoute_CheckedChanged); + // + // tvRoute + // + this.tvRoute.Location = new System.Drawing.Point(6, 20); + this.tvRoute.Name = "tvRoute"; + this.tvRoute.Size = new System.Drawing.Size(211, 432); + this.tvRoute.TabIndex = 0; + this.tvRoute.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvRoute_AfterSelect); + this.tvRoute.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvRoute_NodeMouseDoubleClick); + // + // groupBox2 + // + this.groupBox2.BackColor = System.Drawing.SystemColors.Control; + this.groupBox2.Controls.Add(this.labRouteID); + this.groupBox2.Controls.Add(this.btnAddTemplate); + this.groupBox2.Controls.Add(this.chkPhysicalPoint); + this.groupBox2.Controls.Add(this.chkLogicalPoint); + this.groupBox2.Controls.Add(this.tvPhysicalPoint); + this.groupBox2.Controls.Add(this.label2); + this.groupBox2.Controls.Add(this.tbRoute); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this.tvLogicalPoint); + this.groupBox2.Controls.Add(this.btnSave); + this.groupBox2.Controls.Add(this.btnMoveDown); + this.groupBox2.Controls.Add(this.btnMoveUp); + this.groupBox2.Controls.Add(this.btnDel); + this.groupBox2.Controls.Add(this.btnAdd); + this.groupBox2.Location = new System.Drawing.Point(254, 28); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(485, 486); + this.groupBox2.TabIndex = 3; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "路线巡检点设置"; + // + // labRouteID + // + this.labRouteID.AutoSize = true; + this.labRouteID.Location = new System.Drawing.Point(273, 31); + this.labRouteID.Name = "labRouteID"; + this.labRouteID.Size = new System.Drawing.Size(41, 12); + this.labRouteID.TabIndex = 18; + this.labRouteID.Text = "路线ID"; + this.labRouteID.Visible = false; + // + // btnAddTemplate + // + this.btnAddTemplate.Location = new System.Drawing.Point(202, 82); + this.btnAddTemplate.Name = "btnAddTemplate"; + this.btnAddTemplate.Size = new System.Drawing.Size(75, 23); + this.btnAddTemplate.TabIndex = 17; + this.btnAddTemplate.Text = "添加模板"; + this.btnAddTemplate.UseVisualStyleBackColor = true; + // + // chkPhysicalPoint + // + this.chkPhysicalPoint.AutoSize = true; + this.chkPhysicalPoint.Checked = true; + this.chkPhysicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkPhysicalPoint.Location = new System.Drawing.Point(338, 458); + this.chkPhysicalPoint.Name = "chkPhysicalPoint"; + this.chkPhysicalPoint.Size = new System.Drawing.Size(72, 16); + this.chkPhysicalPoint.TabIndex = 16; + this.chkPhysicalPoint.Text = "自动展开"; + this.chkPhysicalPoint.UseVisualStyleBackColor = true; + this.chkPhysicalPoint.CheckedChanged += new System.EventHandler(this.chkPhysicalPoint_CheckedChanged); + // + // chkLogicalPoint + // + this.chkLogicalPoint.AutoSize = true; + this.chkLogicalPoint.Checked = true; + this.chkLogicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkLogicalPoint.Location = new System.Drawing.Point(50, 458); + this.chkLogicalPoint.Name = "chkLogicalPoint"; + this.chkLogicalPoint.Size = new System.Drawing.Size(72, 16); + this.chkLogicalPoint.TabIndex = 15; + this.chkLogicalPoint.Text = "自动展开"; + this.chkLogicalPoint.UseVisualStyleBackColor = true; + this.chkLogicalPoint.CheckedChanged += new System.EventHandler(this.chkLogicalPoint_CheckedChanged); + // + // tvPhysicalPoint + // + this.tvPhysicalPoint.Location = new System.Drawing.Point(282, 56); + this.tvPhysicalPoint.Name = "tvPhysicalPoint"; + this.tvPhysicalPoint.Size = new System.Drawing.Size(197, 396); + this.tvPhysicalPoint.TabIndex = 13; + this.tvPhysicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvPhysicalPoint_BeforeSelect); + this.tvPhysicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvPhysicalPoint_NodeMouseDoubleClick); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(336, 31); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 12; + this.label2.Text = "巡检点"; + // + // tbRoute + // + this.tbRoute.BackColor = System.Drawing.SystemColors.Control; + this.tbRoute.ForeColor = System.Drawing.SystemColors.WindowText; + this.tbRoute.Location = new System.Drawing.Point(75, 23); + this.tbRoute.Name = "tbRoute"; + this.tbRoute.ReadOnly = true; + this.tbRoute.Size = new System.Drawing.Size(191, 21); + this.tbRoute.TabIndex = 11; + this.tbRoute.Text = "shenm "; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(15, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(65, 12); + this.label1.TabIndex = 10; + this.label1.Text = "当前路线:"; + // + // tvLogicalPoint + // + this.tvLogicalPoint.Location = new System.Drawing.Point(6, 56); + this.tvLogicalPoint.Name = "tvLogicalPoint"; + this.tvLogicalPoint.Size = new System.Drawing.Size(189, 396); + this.tvLogicalPoint.TabIndex = 9; + this.tvLogicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvLogicalPoint_BeforeSelect); + this.tvLogicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvLogicalPoint_NodeMouseDoubleClick); + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(201, 375); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 8; + this.btnSave.Text = "保存"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnMoveDown + // + this.btnMoveDown.Location = new System.Drawing.Point(201, 207); + this.btnMoveDown.Name = "btnMoveDown"; + this.btnMoveDown.Size = new System.Drawing.Size(75, 23); + this.btnMoveDown.TabIndex = 6; + this.btnMoveDown.Text = "下移"; + this.btnMoveDown.UseVisualStyleBackColor = true; + this.btnMoveDown.Click += new System.EventHandler(this.btnMoveDown_Click); + // + // btnMoveUp + // + this.btnMoveUp.Location = new System.Drawing.Point(201, 171); + this.btnMoveUp.Name = "btnMoveUp"; + this.btnMoveUp.Size = new System.Drawing.Size(75, 23); + this.btnMoveUp.TabIndex = 5; + this.btnMoveUp.Text = "上移"; + this.btnMoveUp.UseVisualStyleBackColor = true; + this.btnMoveUp.Click += new System.EventHandler(this.btnMoveUp_Click); + // + // btnDel + // + this.btnDel.Location = new System.Drawing.Point(201, 140); + this.btnDel.Name = "btnDel"; + this.btnDel.Size = new System.Drawing.Size(75, 23); + this.btnDel.TabIndex = 2; + this.btnDel.Text = ">"; + this.btnDel.UseVisualStyleBackColor = true; + this.btnDel.Click += new System.EventHandler(this.btnDel_Click); + // + // btnAdd + // + this.btnAdd.Location = new System.Drawing.Point(201, 111); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(75, 23); + this.btnAdd.TabIndex = 1; + this.btnAdd.Text = "<"; + this.btnAdd.UseVisualStyleBackColor = true; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); +>>>>>>> qicb/Develop + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(597, 169); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 10; + this.btnSave.Text = "保存"; + this.btnSave.UseVisualStyleBackColor = true; + // + // frmAddRoute + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; +<<<<<<< HEAD + this.ClientSize = new System.Drawing.Size(744, 470); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.listView1); + this.Controls.Add(this.txtPoint); + this.Controls.Add(this.txtAlias); + this.Controls.Add(this.txtGenus); + this.Controls.Add(this.txtName); + this.Controls.Add(this.lblPoint); + this.Controls.Add(this.lblGenus); + this.Controls.Add(this.lblAlias); + this.Controls.Add(this.lblName); +======= + this.ClientSize = new System.Drawing.Size(751, 526); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; +>>>>>>> qicb/Develop + this.Name = "frmAddRoute"; + this.Text = "新建巡检路线"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmAddRoute_FormClosing); + this.Load += new System.EventHandler(this.frmAddRoute_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem 新建路线ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 删除路线ToolStripMenuItem; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox chkRoute; + private System.Windows.Forms.TreeView tvRoute; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Button btnMoveDown; + private System.Windows.Forms.Button btnMoveUp; + private System.Windows.Forms.Button btnDel; + private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnAddTemplate; + private System.Windows.Forms.CheckBox chkPhysicalPoint; + private System.Windows.Forms.CheckBox chkLogicalPoint; + private System.Windows.Forms.TreeView tvPhysicalPoint; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox tbRoute; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TreeView tvLogicalPoint; + private System.Windows.Forms.Label labRouteID; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + + + } +} \ No newline at end of file diff --git a/Application/frmAddRoute.cs b/Application/frmAddRoute.cs index 641f48f..0ced010 100644 --- a/Application/frmAddRoute.cs +++ b/Application/frmAddRoute.cs @@ -1,19 +1,486 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; - -namespace WorkStation -{ - public partial class frmAddRoute : Form - { - public frmAddRoute() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddRoute : Form + { + public frmAddRoute() + { + InitializeComponent(); + } + WorkStation.Properties.Settings wset = new Properties.Settings(); + + List listPhy = new List(); + List listLogical = new List(); + private void frmAddRoute_Load(object sender, EventArgs e) + { + tvRouteInit(tvRoute); + getTvPhysicalPoint(); + + chkRoute.Checked = wset.tvRoute; + chkLogicalPoint.Checked = wset.tvLogicalPoint; + chkPhysicalPoint.Checked = wset.tvPhysicalPoint; + + if (wset.tvRoute) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + if (wset.tvPhysicalPoint) tvPhysicalPoint.ExpandAll(); else tvPhysicalPoint.CollapseAll(); + if (wset.tvLogicalPoint) tvLogicalPoint.ExpandAll(); else tvLogicalPoint.CollapseAll(); + } + + private void tvRoute_AfterSelect(object sender, TreeViewEventArgs e) + { + if (tvRoute.SelectedNode.Nodes.Count == 0 && tvRoute.SelectedNode.Level == 2) + { + getTvLogicalPoint(tvRoute.SelectedNode.Tag.ToString()); + tbRoute.ForeColor = tvRoute.SelectedNode.ForeColor; + tbRoute.Text = tvRoute.SelectedNode.Text; + labRouteID.Text = tvRoute.SelectedNode.Tag.ToString(); + } + else + { + tbRoute.Text = ""; + labRouteID.Text = ""; + tvLogicalPoint.Nodes.Clear(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + listLogical = listPhy; + if (labRouteID.Text == "" && tbRoute.Text == "") + { + MessageBox.Show("请选择路线"); + return; + } + foreach (TreeNode node in listPhy) + { + if (node.Parent != null) //node有上级 + { + bool isExit = false; + foreach (TreeNode no in tvLogicalPoint.Nodes) + { + if (no.Parent == null && no.Tag.ToString() == node.Parent.Tag.ToString()) //如果存在node的上级 + { + bool isChild = false; + foreach (TreeNode t in no.Nodes) + { + if (t.Tag.ToString() == node.Tag.ToString() && t.Text == node.Text) + { + isChild = true; break; + } + } + if (isChild == false) + { + no.Nodes.Add((TreeNode)node.Clone()); + } + isExit = true; + break; + } + } + if (isExit == false)//不存在,则新建node的上级 + { + TreeNode tn = new TreeNode(); + tn.Text = node.Parent.Text; + tn.Tag = node.Parent.Tag; + tn.Nodes.Add((TreeNode)node.Clone()); + tvLogicalPoint.Nodes.Add(tn); + } + } + else //node没有上级 + { + bool isExitNode = false; + foreach (TreeNode no in tvLogicalPoint.Nodes) + { + if (no.Parent == null && no.Tag.ToString() == node.Tag.ToString()) + { + isExitNode = true; + break; + } + } + if (isExitNode == false) + { + TreeNode tn = new TreeNode(); + tn.Text = node.Text; + tn.Tag = node.Tag; + tvLogicalPoint.Nodes.Add(tn); + } + } + } + + } + + private void btnDel_Click(object sender, EventArgs e) + { + foreach (TreeNode node in listLogical) + { + if (node.Parent == null) + { + Object obj_ID = SqlHelper.ExecuteScalar("Select ID From LogicalCheckPoint Where Route_ID=" + labRouteID.Text + " and PhysicalPoint_ID=" + node.Tag); + SqlHelper.ExecuteNonQuery("Delete From LogicalCheckPoint where ID=" + obj_ID.ToString()); + if (node.Nodes.Count > 0) + { + foreach (TreeNode de in node.Nodes) + { + SqlHelper.ExecuteNonQuery("Delete From LogicalPoint_Item Where ID=" + obj_ID.ToString()); + } + } + } + tvLogicalPoint.Nodes.Remove(node); + } + } + + private void btnMoveUp_Click(object sender, EventArgs e) + { + if (listLogical.Count == 0) return; + TreeNode selnode = listLogical[0]; + TreeNode prenode = selnode.PrevNode; + TreeNode newnode = selnode.Clone() as TreeNode; + if (prenode != null) + { + if (selnode.Parent != null) + { + selnode.Parent.Nodes.Insert(prenode.Index, newnode); + } + else + { + tvLogicalPoint.Nodes.Insert(prenode.Index, newnode); + } + selnode.Remove(); + tvLogicalPoint.SelectedNode = newnode; + } + else + { + MessageBox.Show("已经到顶"); return; + } + } + + private void btnMoveDown_Click(object sender, EventArgs e) + { + TreeNode selnode = listLogical[0]; + TreeNode nextnode = selnode.NextNode; + TreeNode newnode = selnode.Clone() as TreeNode; + if (nextnode != null) + { + if (selnode.Parent != null) + { + selnode.Parent.Nodes.Insert(nextnode.Index + 1, newnode); + } + else + { + tvLogicalPoint.Nodes.Insert(nextnode.Index + 1, newnode); + } + selnode.Remove(); + tvLogicalPoint.SelectedNode = newnode; + } + else + { + MessageBox.Show("已经到底"); return; + } + } + + private void btnSave_Click(object sender, EventArgs e) + { + foreach (TreeNode node in tvLogicalPoint.Nodes) + { + if (node.Level == 0 && node.Nodes.Count == 0) + { + MessageBox.Show("请确保每个巡检点下有巡检项"); + return; + } + } + string route_id = ""; + if (labRouteID.Text != "") + { + route_id = tvRoute.SelectedNode.Tag.ToString(); + } + else + { + MessageBox.Show("请选择要保存的路线"); + return; + } + for (int i = 0; i < tvLogicalPoint.Nodes.Count; i++) + { + if (tvLogicalPoint.Nodes[i].Level == 0) + { + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@Route_ID",SqlDbType.BigInt), + new SqlParameter("@PhysicalPoint_ID",SqlDbType.BigInt), + new SqlParameter("@Name",SqlDbType.VarChar), + new SqlParameter("@Alias",SqlDbType.VarChar), + new SqlParameter("@ItemsID",SqlDbType.VarChar), + new SqlParameter("@ItemsIndex",SqlDbType.VarChar), + new SqlParameter("@CheckOrder",SqlDbType.Int) + }; + pars[0].Value = labRouteID.Text; + pars[1].Value = tvLogicalPoint.Nodes[i].Tag; + pars[2].Value = tvLogicalPoint.Nodes[i].Text; + pars[3].Value = ""; + + string parValue = "",parIndex=""; + foreach (TreeNode node in tvLogicalPoint.Nodes[i].Nodes) + { + parValue += node.Tag + ","; + parIndex += node.Index + ","; + } + pars[4].Value = parValue; + pars[5].Value = parIndex; + pars[6].Value = tvLogicalPoint.Nodes[i].Index; + + int _ret = SqlHelper.ExecuteNonQuery("LogicalPointItemControl",CommandType.StoredProcedure,pars); + } + + } + getTvLogicalPoint(labRouteID.Text.Trim()); + + } + + private void 新建路线ToolStripMenuItem_Click(object sender, EventArgs e) + { + frmAddRoutName rn = new frmAddRoutName(); + rn.tView = this.tvRoute; + rn.Show(); + } + + //获取路线上的逻辑巡检点 + private void getTvLogicalPoint(string route_id) + { + tvLogicalPoint.Nodes.Clear(); + SqlDataReader dr = SqlHelper.ExecuteReader("Select PhysicalPoint_ID,Name,ID From LogicalCheckPoint where route_ID=" + route_id +" order by checkorder"); + if (dr == null) return; + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["PhysicalPoint_ID"].ToString(); + tnode = tvNodeAdd(tnode, "select l.ID as LIID,c.[Name],c.ID ,'' as Sequence from LogicalPoint_Item l ,CheckItem c where l.Item_ID=c.ID and l.ID=" + dr["ID"].ToString().Trim() + " order by l.inorder"); + tvLogicalPoint.Nodes.Add(tnode); + } + if (chkLogicalPoint.Checked) + tvLogicalPoint.ExpandAll(); + } + //获取物理巡检点 + private void getTvPhysicalPoint() + { + SqlDataReader dr = SqlHelper.ExecuteReader("Select ID,Name From PhysicalCheckPoint"); + if (dr == null) { dr.Dispose(); return; } + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["ID"].ToString(); + tnode = tvNodeAdd(tnode, "Select ID,Name,'' AS Sequence From CheckItem Where Phy_ID=" + dr["ID"].ToString().Trim()); + tvPhysicalPoint.Nodes.Add(tnode); + } + dr.Close(); + } + + public static void tvRouteInit(TreeView tvRoute) + { + tvRoute.Nodes.Clear(); + SqlDataReader dr = SqlHelper.ExecuteReader("Select ID,Name From Company"); + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["ID"].ToString(); + tnode = tvNodeAdd(tnode, "select ID,Name,''AS Sequence from Site where Company_ID='" + dr["ID"].ToString() + "'"); + for (int i = 0; i < tnode.Nodes.Count; i++) + { + (tnode.Nodes)[i] = tvNodeAdd((tnode.Nodes)[i], "Select ID,Name,Sequence as Sequence from CheckRoute Where site_id=" + (tnode.Nodes)[i].Tag); + } + tvRoute.Nodes.Add(tnode); + } + //tvRoute.ExpandAll(); + dr.Close(); + + } + + private static TreeNode tvNodeAdd(TreeNode node, string comstr) + { + SqlDataReader dr = SqlHelper.ExecuteReader(comstr); + if (dr == null) + { + dr.Dispose(); + return null; + } + while (dr.Read()) + { + TreeNode tn = new TreeNode(); + tn.Text = dr["Name"].ToString(); + tn.Tag = dr["ID"]; + if (dr["Sequence"].ToString() == "1") + { + tn.ForeColor = Color.Red; + } + node.Nodes.Add(tn); + } + dr.Close(); + return node; + } + + private void tvPhysicalPoint_BeforeSelect(object sender, TreeViewCancelEventArgs e) + { + if (ModifierKeys == Keys.Control) + { + if (listPhy.Contains(e.Node)) + { + listPhy.Remove(e.Node); + } + else + { + listPhy.Add(e.Node); + } + } + else + { + listPhy.Clear(); + listPhy.Add(e.Node); + } + PaintSelectedNode(tvPhysicalPoint, listPhy); + e.Cancel = true; + } + + private void tvLogicalPoint_BeforeSelect(object sender, TreeViewCancelEventArgs e) + { + if (ModifierKeys == Keys.Control) + { + if (listLogical.Contains(e.Node)) + { + listLogical.Remove(e.Node); + } + else + { + listLogical.Add(e.Node); + } + } + else + { + listLogical.Clear(); + listLogical.Add(e.Node); + } + PaintSelectedNode(tvLogicalPoint, listLogical); + e.Cancel = true; + } + + public void PaintSelectedNode(TreeView tv, List listNodes) + { + foreach (TreeNode trNode in tv.Nodes) + { + trNode.BackColor = tv.BackColor; + trNode.ForeColor = tv.ForeColor; + ClearSelectedNode(tv, trNode); + } + foreach (TreeNode node in listNodes) + { + node.BackColor = SystemColors.Highlight; + node.ForeColor = SystemColors.HighlightText; + } + } + + public void ClearSelectedNode(TreeView tv, TreeNode tr) + { + foreach (TreeNode node in tr.Nodes) + { + node.BackColor = tv.BackColor; + node.ForeColor = tv.ForeColor; + ClearSelectedNode(tv, node); + } + } + + private void tvLogicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Index.ToString()); + listLogical.Clear(); + listLogical.Add(e.Node); + PaintSelectedNode(tvLogicalPoint, listLogical); + } + + private void tvPhysicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Text); + listPhy.Clear(); + listPhy.Add(e.Node); + PaintSelectedNode(tvPhysicalPoint, listPhy); + } + + private void 删除路线ToolStripMenuItem_Click(object sender, EventArgs e) + { + if (tvRoute.SelectedNode.Level != 2) + { + MessageBox.Show("请选择具体路线"); + return; + } + string strDel = "Delete From CheckRoute Where ID=" + tvRoute.SelectedNode.Tag; + if (SqlHelper.ExecuteNonQuery(strDel) != 1) + { + MessageBox.Show("删除失败"); + return; + } + else + { + tvRouteInit(tvRoute); + } + } + + private void chkRoute_CheckedChanged(object sender, EventArgs e) + { + if (chkRoute.Checked == true) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + } + + private void chkLogicalPoint_CheckedChanged(object sender, EventArgs e) + { + if (chkLogicalPoint.Checked) + tvLogicalPoint.ExpandAll(); + else + tvLogicalPoint.CollapseAll(); + } + + private void chkPhysicalPoint_CheckedChanged(object sender, EventArgs e) + { + if (chkPhysicalPoint.Checked) + tvPhysicalPoint.ExpandAll(); + else + tvPhysicalPoint.CollapseAll(); + } + + private void frmAddRoute_FormClosing(object sender, FormClosingEventArgs e) + { + wset.tvLogicalPoint = chkLogicalPoint.Checked; + wset.tvPhysicalPoint = chkPhysicalPoint.Checked; + wset.tvRoute = chkRoute.Checked; + wset.Save(); + } + + private void tvRoute_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + if (e.Node.Level == 2) + { + frmAddRoutName fn = new frmAddRoutName(); + fn.tView = tvRoute; + fn.isEdit = true; + fn.routeID = e.Node.Tag; + fn.Show(); + } + } + + private void toolStripMenuItem1_Click(object sender, EventArgs e) + { + if (tvRoute.SelectedNode.Level == 2) + { + frmAddRoutName fn = new frmAddRoutName(); + fn.tView = tvRoute; + fn.isEdit = true; + fn.routeID = tvRoute.SelectedNode.Tag; + fn.Show(); + } + } + + } +} diff --git a/Application/frmAddRoute.cs.orig b/Application/frmAddRoute.cs.orig new file mode 100644 index 0000000..8d5a4a3 --- /dev/null +++ b/Application/frmAddRoute.cs.orig @@ -0,0 +1,490 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; + +namespace WorkStation +{ + public partial class frmAddRoute : Form + { + public frmAddRoute() + { + InitializeComponent(); + } + WorkStation.Properties.Settings wset = new Properties.Settings(); + + List listPhy = new List(); + List listLogical = new List(); + private void frmAddRoute_Load(object sender, EventArgs e) + { + tvRouteInit(tvRoute); + getTvPhysicalPoint(); + + chkRoute.Checked = wset.tvRoute; + chkLogicalPoint.Checked = wset.tvLogicalPoint; + chkPhysicalPoint.Checked = wset.tvPhysicalPoint; + + if (wset.tvRoute) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + if (wset.tvPhysicalPoint) tvPhysicalPoint.ExpandAll(); else tvPhysicalPoint.CollapseAll(); + if (wset.tvLogicalPoint) tvLogicalPoint.ExpandAll(); else tvLogicalPoint.CollapseAll(); + } + + private void tvRoute_AfterSelect(object sender, TreeViewEventArgs e) + { + if (tvRoute.SelectedNode.Nodes.Count == 0 && tvRoute.SelectedNode.Level == 2) + { + getTvLogicalPoint(tvRoute.SelectedNode.Tag.ToString()); + tbRoute.ForeColor = tvRoute.SelectedNode.ForeColor; + tbRoute.Text = tvRoute.SelectedNode.Text; + labRouteID.Text = tvRoute.SelectedNode.Tag.ToString(); + } + else + { + tbRoute.Text = ""; + labRouteID.Text = ""; + tvLogicalPoint.Nodes.Clear(); + } + } + + private void btnAdd_Click(object sender, EventArgs e) + { + listLogical = listPhy; + if (labRouteID.Text == "" && tbRoute.Text == "") + { + MessageBox.Show("请选择路线"); + return; + } + foreach (TreeNode node in listPhy) + { + if (node.Parent != null) //node有上级 + { + bool isExit = false; + foreach (TreeNode no in tvLogicalPoint.Nodes) + { + if (no.Parent == null && no.Tag.ToString() == node.Parent.Tag.ToString()) //如果存在node的上级 + { + bool isChild = false; + foreach (TreeNode t in no.Nodes) + { + if (t.Tag.ToString() == node.Tag.ToString() && t.Text == node.Text) + { + isChild = true; break; + } + } + if (isChild == false) + { + no.Nodes.Add((TreeNode)node.Clone()); + } + isExit = true; + break; + } + } + if (isExit == false)//不存在,则新建node的上级 + { + TreeNode tn = new TreeNode(); + tn.Text = node.Parent.Text; + tn.Tag = node.Parent.Tag; + tn.Nodes.Add((TreeNode)node.Clone()); + tvLogicalPoint.Nodes.Add(tn); + } + } + else //node没有上级 + { + bool isExitNode = false; + foreach (TreeNode no in tvLogicalPoint.Nodes) + { + if (no.Parent == null && no.Tag.ToString() == node.Tag.ToString()) + { + isExitNode = true; + break; + } + } + if (isExitNode == false) + { + TreeNode tn = new TreeNode(); + tn.Text = node.Text; + tn.Tag = node.Tag; + tvLogicalPoint.Nodes.Add(tn); + } + } + } + + } + + private void btnDel_Click(object sender, EventArgs e) + { + foreach (TreeNode node in listLogical) + { + if (node.Parent == null) + { + Object obj_ID = SqlHelper.ExecuteScalar("Select ID From LogicalCheckPoint Where Route_ID=" + labRouteID.Text + " and PhysicalPoint_ID=" + node.Tag); + SqlHelper.ExecuteNonQuery("Delete From LogicalCheckPoint where ID=" + obj_ID.ToString()); + if (node.Nodes.Count > 0) + { + foreach (TreeNode de in node.Nodes) + { + SqlHelper.ExecuteNonQuery("Delete From LogicalPoint_Item Where ID=" + obj_ID.ToString()); + } + } + } + tvLogicalPoint.Nodes.Remove(node); + } + } + + private void btnMoveUp_Click(object sender, EventArgs e) + { + if (listLogical.Count == 0) return; + TreeNode selnode = listLogical[0]; + TreeNode prenode = selnode.PrevNode; + TreeNode newnode = selnode.Clone() as TreeNode; + if (prenode != null) + { + if (selnode.Parent != null) + { + selnode.Parent.Nodes.Insert(prenode.Index, newnode); + } + else + { + tvLogicalPoint.Nodes.Insert(prenode.Index, newnode); + } + selnode.Remove(); + tvLogicalPoint.SelectedNode = newnode; + } + else + { + MessageBox.Show("已经到顶"); return; + } + } + + private void btnMoveDown_Click(object sender, EventArgs e) + { + TreeNode selnode = listLogical[0]; + TreeNode nextnode = selnode.NextNode; + TreeNode newnode = selnode.Clone() as TreeNode; + if (nextnode != null) + { + if (selnode.Parent != null) + { + selnode.Parent.Nodes.Insert(nextnode.Index + 1, newnode); + } + else + { + tvLogicalPoint.Nodes.Insert(nextnode.Index + 1, newnode); + } + selnode.Remove(); + tvLogicalPoint.SelectedNode = newnode; + } + else + { + MessageBox.Show("已经到底"); return; + } + } + + private void btnSave_Click(object sender, EventArgs e) + { + foreach (TreeNode node in tvLogicalPoint.Nodes) + { + if (node.Level == 0 && node.Nodes.Count == 0) + { + MessageBox.Show("请确保每个巡检点下有巡检项"); + return; + } + } + string route_id = ""; + if (labRouteID.Text != "") + { + route_id = tvRoute.SelectedNode.Tag.ToString(); + } + else + { + MessageBox.Show("请选择要保存的路线"); + return; + } + for (int i = 0; i < tvLogicalPoint.Nodes.Count; i++) + { + if (tvLogicalPoint.Nodes[i].Level == 0) + { + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@Route_ID",SqlDbType.BigInt), + new SqlParameter("@PhysicalPoint_ID",SqlDbType.BigInt), + new SqlParameter("@Name",SqlDbType.VarChar), + new SqlParameter("@Alias",SqlDbType.VarChar), + new SqlParameter("@ItemsID",SqlDbType.VarChar), + new SqlParameter("@ItemsIndex",SqlDbType.VarChar), + new SqlParameter("@CheckOrder",SqlDbType.Int) + }; + pars[0].Value = labRouteID.Text; + pars[1].Value = tvLogicalPoint.Nodes[i].Tag; + pars[2].Value = tvLogicalPoint.Nodes[i].Text; + pars[3].Value = ""; + + string parValue = "", parIndex = ""; + foreach (TreeNode node in tvLogicalPoint.Nodes[i].Nodes) + { + parValue += node.Tag + ","; + parIndex += node.Index + ","; + } + pars[4].Value = parValue; + pars[5].Value = parIndex; + pars[6].Value = tvLogicalPoint.Nodes[i].Index; + +<<<<<<< HEAD + int _ret = SqlHelper.ExecuteNonQuery("LogicalPointItemControl", pars); +======= + int _ret = SqlHelper.ExecuteNonQuery("LogicalPointItemControl",CommandType.StoredProcedure,pars); +>>>>>>> qicb/Develop + } + + } + getTvLogicalPoint(labRouteID.Text.Trim()); + + } + + private void 新建路线ToolStripMenuItem_Click(object sender, EventArgs e) + { + frmAddRoutName rn = new frmAddRoutName(); + rn.tView = this.tvRoute; + rn.Show(); + } + + //获取路线上的逻辑巡检点 + private void getTvLogicalPoint(string route_id) + { + tvLogicalPoint.Nodes.Clear(); + SqlDataReader dr = SqlHelper.ExecuteReader("Select PhysicalPoint_ID,Name,ID From LogicalCheckPoint where route_ID=" + route_id + " order by checkorder"); + if (dr == null) return; + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["PhysicalPoint_ID"].ToString(); + tnode = tvNodeAdd(tnode, "select l.ID as LIID,c.[Name],c.ID ,'' as Sequence from LogicalPoint_Item l ,CheckItem c where l.Item_ID=c.ID and l.ID=" + dr["ID"].ToString().Trim() + " order by l.inorder"); + tvLogicalPoint.Nodes.Add(tnode); + } + if (chkLogicalPoint.Checked) + tvLogicalPoint.ExpandAll(); + } + //获取物理巡检点 + private void getTvPhysicalPoint() + { + SqlDataReader dr = SqlHelper.ExecuteReader("Select ID,Name From PhysicalCheckPoint"); + if (dr == null) { dr.Dispose(); return; } + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["ID"].ToString(); + tnode = tvNodeAdd(tnode, "Select ID,Name,'' AS Sequence From CheckItem Where Phy_ID=" + dr["ID"].ToString().Trim()); + tvPhysicalPoint.Nodes.Add(tnode); + } + dr.Close(); + } + + public static void tvRouteInit(TreeView tvRoute) + { + tvRoute.Nodes.Clear(); + SqlDataReader dr = SqlHelper.ExecuteReader("Select ID,Name From Company"); + while (dr.Read()) + { + TreeNode tnode = new TreeNode(); + tnode.Text = dr["Name"].ToString(); + tnode.Tag = dr["ID"].ToString(); + tnode = tvNodeAdd(tnode, "select ID,Name,''AS Sequence from Site where Company_ID='" + dr["ID"].ToString() + "'"); + for (int i = 0; i < tnode.Nodes.Count; i++) + { + (tnode.Nodes)[i] = tvNodeAdd((tnode.Nodes)[i], "Select ID,Name,Sequence as Sequence from CheckRoute Where site_id=" + (tnode.Nodes)[i].Tag); + } + tvRoute.Nodes.Add(tnode); + } + //tvRoute.ExpandAll(); + dr.Close(); + + } + + private static TreeNode tvNodeAdd(TreeNode node, string comstr) + { + SqlDataReader dr = SqlHelper.ExecuteReader(comstr); + if (dr == null) + { + dr.Dispose(); + return null; + } + while (dr.Read()) + { + TreeNode tn = new TreeNode(); + tn.Text = dr["Name"].ToString(); + tn.Tag = dr["ID"]; + if (dr["Sequence"].ToString() == "1") + { + tn.ForeColor = Color.Red; + } + node.Nodes.Add(tn); + } + dr.Close(); + return node; + } + + private void tvPhysicalPoint_BeforeSelect(object sender, TreeViewCancelEventArgs e) + { + if (ModifierKeys == Keys.Control) + { + if (listPhy.Contains(e.Node)) + { + listPhy.Remove(e.Node); + } + else + { + listPhy.Add(e.Node); + } + } + else + { + listPhy.Clear(); + listPhy.Add(e.Node); + } + PaintSelectedNode(tvPhysicalPoint, listPhy); + e.Cancel = true; + } + + private void tvLogicalPoint_BeforeSelect(object sender, TreeViewCancelEventArgs e) + { + if (ModifierKeys == Keys.Control) + { + if (listLogical.Contains(e.Node)) + { + listLogical.Remove(e.Node); + } + else + { + listLogical.Add(e.Node); + } + } + else + { + listLogical.Clear(); + listLogical.Add(e.Node); + } + PaintSelectedNode(tvLogicalPoint, listLogical); + e.Cancel = true; + } + + public void PaintSelectedNode(TreeView tv, List listNodes) + { + foreach (TreeNode trNode in tv.Nodes) + { + trNode.BackColor = tv.BackColor; + trNode.ForeColor = tv.ForeColor; + ClearSelectedNode(tv, trNode); + } + foreach (TreeNode node in listNodes) + { + node.BackColor = SystemColors.Highlight; + node.ForeColor = SystemColors.HighlightText; + } + } + + public void ClearSelectedNode(TreeView tv, TreeNode tr) + { + foreach (TreeNode node in tr.Nodes) + { + node.BackColor = tv.BackColor; + node.ForeColor = tv.ForeColor; + ClearSelectedNode(tv, node); + } + } + + private void tvLogicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Index.ToString()); + listLogical.Clear(); + listLogical.Add(e.Node); + PaintSelectedNode(tvLogicalPoint, listLogical); + } + + private void tvPhysicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Text); + listPhy.Clear(); + listPhy.Add(e.Node); + PaintSelectedNode(tvPhysicalPoint, listPhy); + } + + private void 删除路线ToolStripMenuItem_Click(object sender, EventArgs e) + { + if (tvRoute.SelectedNode.Level != 2) + { + MessageBox.Show("请选择具体路线"); + return; + } + string strDel = "Delete From CheckRoute Where ID=" + tvRoute.SelectedNode.Tag; + if (SqlHelper.ExecuteNonQuery(strDel) != 1) + { + MessageBox.Show("删除失败"); + return; + } + else + { + tvRouteInit(tvRoute); + } + } + + private void chkRoute_CheckedChanged(object sender, EventArgs e) + { + if (chkRoute.Checked == true) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + } + + private void chkLogicalPoint_CheckedChanged(object sender, EventArgs e) + { + if (chkLogicalPoint.Checked) + tvLogicalPoint.ExpandAll(); + else + tvLogicalPoint.CollapseAll(); + } + + private void chkPhysicalPoint_CheckedChanged(object sender, EventArgs e) + { + if (chkPhysicalPoint.Checked) + tvPhysicalPoint.ExpandAll(); + else + tvPhysicalPoint.CollapseAll(); + } + + private void frmAddRoute_FormClosing(object sender, FormClosingEventArgs e) + { + wset.tvLogicalPoint = chkLogicalPoint.Checked; + wset.tvPhysicalPoint = chkPhysicalPoint.Checked; + wset.tvRoute = chkRoute.Checked; + wset.Save(); + } + + private void tvRoute_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + if (e.Node.Level == 2) + { + frmAddRoutName fn = new frmAddRoutName(); + fn.tView = tvRoute; + fn.isEdit = true; + fn.routeID = e.Node.Tag; + fn.Show(); + } + } + + private void toolStripMenuItem1_Click(object sender, EventArgs e) + { + if (tvRoute.SelectedNode.Level == 2) + { + frmAddRoutName fn = new frmAddRoutName(); + fn.tView = tvRoute; + fn.isEdit = true; + fn.routeID = tvRoute.SelectedNode.Tag; + fn.Show(); + } + } + + } +} diff --git a/Application/frmAddRoute.resx b/Application/frmAddRoute.resx index 1af7de1..0f6d8eb 100644 --- a/Application/frmAddRoute.resx +++ b/Application/frmAddRoute.resx @@ -1,120 +1,123 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + \ No newline at end of file diff --git a/Application/frmAddTask.Designer.cs b/Application/frmAddTask.Designer.cs index bf3c786..615b915 100644 --- a/Application/frmAddTask.Designer.cs +++ b/Application/frmAddTask.Designer.cs @@ -66,7 +66,6 @@ private void InitializeComponent() this.lblName.Size = new System.Drawing.Size(29, 12); this.lblName.TabIndex = 0; this.lblName.Text = "名称"; - this.lblName.Click += new System.EventHandler(this.lblName_Click); // // lblAlias // @@ -76,7 +75,6 @@ private void InitializeComponent() this.lblAlias.Size = new System.Drawing.Size(29, 12); this.lblAlias.TabIndex = 1; this.lblAlias.Text = "别名"; - this.lblAlias.Click += new System.EventHandler(this.lblAlias_Click); // // lblRount // @@ -86,7 +84,6 @@ private void InitializeComponent() this.lblRount.Size = new System.Drawing.Size(53, 12); this.lblRount.TabIndex = 2; this.lblRount.Text = "巡检路线"; - this.lblRount.Click += new System.EventHandler(this.lblRount_Click); // // lblPost // @@ -96,7 +93,6 @@ private void InitializeComponent() this.lblPost.Size = new System.Drawing.Size(53, 12); this.lblPost.TabIndex = 3; this.lblPost.Text = "指派岗位"; - this.lblPost.Click += new System.EventHandler(this.lblPost_Click); // // lblTime // @@ -106,7 +102,6 @@ private void InitializeComponent() this.lblTime.Size = new System.Drawing.Size(53, 12); this.lblTime.TabIndex = 4; this.lblTime.Text = "巡检时间"; - this.lblTime.Click += new System.EventHandler(this.label5_Click); // // lblCycle // @@ -116,7 +111,6 @@ private void InitializeComponent() this.lblCycle.Size = new System.Drawing.Size(53, 12); this.lblCycle.TabIndex = 5; this.lblCycle.Text = "巡检周期"; - this.lblCycle.Click += new System.EventHandler(this.label6_Click); // // lblshengxiao // @@ -126,7 +120,6 @@ private void InitializeComponent() this.lblshengxiao.Size = new System.Drawing.Size(53, 12); this.lblshengxiao.TabIndex = 6; this.lblshengxiao.Text = "生效时间"; - this.lblshengxiao.Click += new System.EventHandler(this.lblshengxiao_Click); // // lblshixiao // @@ -136,7 +129,6 @@ private void InitializeComponent() this.lblshixiao.Size = new System.Drawing.Size(53, 12); this.lblshixiao.TabIndex = 7; this.lblshixiao.Text = "失效时间"; - this.lblshixiao.Click += new System.EventHandler(this.lblshixiao_Click); // // txtName // @@ -144,7 +136,6 @@ private void InitializeComponent() this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(183, 21); this.txtName.TabIndex = 8; - this.txtName.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // txtAlias // @@ -152,7 +143,6 @@ private void InitializeComponent() this.txtAlias.Name = "txtAlias"; this.txtAlias.Size = new System.Drawing.Size(183, 21); this.txtAlias.TabIndex = 9; - this.txtAlias.TextChanged += new System.EventHandler(this.txtAlias_TextChanged); // // txtgangwei // @@ -160,7 +150,6 @@ private void InitializeComponent() this.txtgangwei.Name = "txtgangwei"; this.txtgangwei.Size = new System.Drawing.Size(183, 21); this.txtgangwei.TabIndex = 11; - this.txtgangwei.TextChanged += new System.EventHandler(this.txtgangwei_TextChanged); // // listView1 // @@ -181,7 +170,6 @@ private void InitializeComponent() this.listView1.TabIndex = 16; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; - this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); // // ColumnHeader // @@ -243,7 +231,6 @@ private void InitializeComponent() this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(183, 20); this.comboBox1.TabIndex = 18; - this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // dateTimePicker1 // @@ -251,7 +238,6 @@ private void InitializeComponent() this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(183, 21); this.dateTimePicker1.TabIndex = 19; - this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged); // // textBox1 // @@ -259,7 +245,6 @@ private void InitializeComponent() this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(68, 21); this.textBox1.TabIndex = 20; - this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged_1); // // listBox1 // @@ -275,7 +260,6 @@ private void InitializeComponent() this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(99, 40); this.listBox1.TabIndex = 21; - this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); // // dateTimePicker2 // @@ -283,7 +267,6 @@ private void InitializeComponent() this.dateTimePicker2.Name = "dateTimePicker2"; this.dateTimePicker2.Size = new System.Drawing.Size(183, 21); this.dateTimePicker2.TabIndex = 22; - this.dateTimePicker2.ValueChanged += new System.EventHandler(this.dateTimePicker2_ValueChanged); // // dateTimePicker3 // @@ -291,7 +274,6 @@ private void InitializeComponent() this.dateTimePicker3.Name = "dateTimePicker3"; this.dateTimePicker3.Size = new System.Drawing.Size(183, 21); this.dateTimePicker3.TabIndex = 23; - this.dateTimePicker3.ValueChanged += new System.EventHandler(this.dateTimePicker3_ValueChanged); // // frmAddTask // @@ -319,7 +301,6 @@ private void InitializeComponent() this.Controls.Add(this.lblName); this.Name = "frmAddTask"; this.Text = "新建任务"; - this.Load += new System.EventHandler(this.frmAddTask_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Application/frmAddTask.cs b/Application/frmAddTask.cs index db9166e..66af44f 100644 --- a/Application/frmAddTask.cs +++ b/Application/frmAddTask.cs @@ -16,99 +16,6 @@ public frmAddTask() InitializeComponent(); } - private void label6_Click(object sender, EventArgs e) - { - - } - - private void label5_Click(object sender, EventArgs e) - { - - } - - private void textBox1_TextChanged(object sender, EventArgs e) - { - - } - - private void listView1_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void lblName_Click(object sender, EventArgs e) - { - - } - - private void lblAlias_Click(object sender, EventArgs e) - { - - } - - private void txtAlias_TextChanged(object sender, EventArgs e) - { - - } - - private void frmAddTask_Load(object sender, EventArgs e) - { - - } - - private void lblRount_Click(object sender, EventArgs e) - { - - } - - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void lblPost_Click(object sender, EventArgs e) - { - - } - - private void txtgangwei_TextChanged(object sender, EventArgs e) - { - - } - - private void dateTimePicker1_ValueChanged(object sender, EventArgs e) - { - - } - - private void textBox1_TextChanged_1(object sender, EventArgs e) - { - - } - - private void listBox1_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void lblshengxiao_Click(object sender, EventArgs e) - { - - } - - private void dateTimePicker2_ValueChanged(object sender, EventArgs e) - { - - } - - private void lblshixiao_Click(object sender, EventArgs e) - { - - } - - private void dateTimePicker3_ValueChanged(object sender, EventArgs e) - { - - } + } } diff --git a/Application/frmEditOrDeleteTask.Designer.cs b/Application/frmEditOrDeleteTask.Designer.cs index a216d68..8f3086b 100644 --- a/Application/frmEditOrDeleteTask.Designer.cs +++ b/Application/frmEditOrDeleteTask.Designer.cs @@ -240,7 +240,6 @@ private void InitializeComponent() this.lblshixiao.Size = new System.Drawing.Size(53, 12); this.lblshixiao.TabIndex = 29; this.lblshixiao.Text = "失效时间"; - this.lblshixiao.Click += new System.EventHandler(this.lblshixiao_Click); // // lblshengxiao // diff --git a/Application/frmEditOrDeleteTask.cs b/Application/frmEditOrDeleteTask.cs index 935be5e..f0cfdc0 100644 --- a/Application/frmEditOrDeleteTask.cs +++ b/Application/frmEditOrDeleteTask.cs @@ -16,9 +16,5 @@ public frmEditOrDeleteTask() InitializeComponent(); } - private void lblshixiao_Click(object sender, EventArgs e) - { - - } } } diff --git a/Application/frmain.Designer.cs b/Application/frmMain.Designer.cs similarity index 97% rename from Application/frmain.Designer.cs rename to Application/frmMain.Designer.cs index 86576f8..2bd0186 100644 --- a/Application/frmain.Designer.cs +++ b/Application/frmMain.Designer.cs @@ -1,6 +1,6 @@ namespace WorkStation { - partial class frmain + partial class frmMain { /// /// Required designer variable. @@ -28,7 +28,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmain)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain)); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.panel7 = new System.Windows.Forms.Panel(); @@ -794,24 +794,28 @@ private void InitializeComponent() this.tsmixunjianluxian.Name = "tsmixunjianluxian"; this.tsmixunjianluxian.Size = new System.Drawing.Size(154, 22); this.tsmixunjianluxian.Text = "巡检路线管理"; + this.tsmixunjianluxian.Click += new System.EventHandler(this.tsmixunjianluxian_Click); // // tsmixunjiandian // this.tsmixunjiandian.Name = "tsmixunjiandian"; this.tsmixunjiandian.Size = new System.Drawing.Size(154, 22); this.tsmixunjiandian.Text = "巡检点管理"; + this.tsmixunjiandian.Click += new System.EventHandler(this.tsmixunjiandian_Click); // // tsmixunjianxiangs // this.tsmixunjianxiangs.Name = "tsmixunjianxiangs"; this.tsmixunjianxiangs.Size = new System.Drawing.Size(154, 22); this.tsmixunjianxiangs.Text = "巡检项管理"; + this.tsmixunjianxiangs.Click += new System.EventHandler(this.tsmixunjianxiangs_Click); // // tsmishebeixunjianxiang // this.tsmishebeixunjianxiang.Name = "tsmishebeixunjianxiang"; this.tsmishebeixunjianxiang.Size = new System.Drawing.Size(154, 22); this.tsmishebeixunjianxiang.Text = "设备巡检项管理"; + this.tsmishebeixunjianxiang.Click += new System.EventHandler(this.tsmishebeixunjianxiang_Click); // // tsmjichu // diff --git a/Application/frmain.cs b/Application/frmMain.cs similarity index 91% rename from Application/frmain.cs rename to Application/frmMain.cs index 5c79d60..3672865 100644 --- a/Application/frmain.cs +++ b/Application/frmMain.cs @@ -9,9 +9,9 @@ namespace WorkStation { - public partial class frmain : Form + public partial class frmMain : Form { - public frmain() + public frmMain() { InitializeComponent(); } @@ -274,8 +274,19 @@ private void tsmiCompanyDel_Click(object sender, EventArgs e) - + //新建设备 + private void tsmishebeixunjianxiang_Click(object sender, EventArgs e) + { + frmAddMachine fm = new frmAddMachine(); + fm.ShowDialog(); + } + + private void tsmixunjianluxian_Click(object sender, EventArgs e) + { + frmAddRoute frm = new frmAddRoute(); + frm.Show(); + } } } diff --git a/Application/frmain.resx b/Application/frmMain.resx similarity index 100% rename from Application/frmain.resx rename to Application/frmMain.resx diff --git "a/\346\217\220\344\272\244.txt" "b/\346\217\220\344\272\244.txt" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" deleted file mode 100644 index e69de29..0000000