aseProvide;
27 this.Connection = this.DatabaseProvide.Factory.CreateConnection();
28 this.Connection.ConnectionString = this.DatabaseProvide.ConnectionString;
29 }
30
31 this.Initialization();
32 }
33
34 public void Initialization() //初始化默认执行过一次
35 {
36 this.Open();
37 }
38
39 public void Open()
40 {
41 if (ConnectionState.Closed == this.Connection.State)
42 {
43 this.Connection.Open();
44 }
45 }
46
47 public void Change(string argument_DatabaseName)
48 {
49 if (null != this.DatabaseProvide && null != this.Connection)
50 {
51 this.Connection.ChangeDatabase(argument_DatabaseName);
52 this.DatabaseProvide.ConnectionString = this.Connection.ConnectionString;
53 }
54 }
55 }
?
?
?它只有一个构造,必须提供Database,因为Connection需要Database来提供创建.提供了如下操作:
?
?
?
1 public interface IDatabaseConnectionProvide
2 {
3 void Initialization();
4 void Change(string argument_DatabaseName);
5 void Open();
6 }
?
?
?
DatabaseCommandText 和 DatabaseCommandProcedure:
?
?
1 public sealed class DatabaseCommandText : IDatabaseCommandTextProvide
2 {
3 public DatabaseCommandText(DatabaseConnection argument_Connection)
4 {
5 this.Connection = argument_Connection;
6 }
7
8 public DatabaseConnection Connection { get; private set; }
9 public string CommandName { get; set; }
10
11 public DbParameter NewParameter()
12 {
13 return this.Connection.DatabaseProvide.Factory.CreateParameter();
14 }
15
16 public DbParameter NewParameter(string argument_ParameterName, object argument_Value, DbType argument_DbType, ParameterDirection Direction)
17 {
18 DbParameter _Parameter = this.Connection.DatabaseProvide.Factory.CreateParameter();
19 _Parameter.ParameterName = argument_ParameterName;
20 _Parameter.Value = argument_Value;
21 _Parameter.DbType = argument_DbType;
22 _Parameter.Direction = Direction;
23 return _Parameter;
24 }
25
26 public OperationValue TransactionDelete(string argument_SqlText, DbParameter[] argument_Parameters)
27 {
28 int _CommandResult = 0;
29 DbCommand _Command = this.Connection.DatabaseProvide.Factory.CreateCommand();
30 DbTransaction _Transaction = this.Connection.Connection.BeginTransaction();
31 _Command.Connection = this.Connection.Connection;
32 _Command.Transaction = _Transaction;
33 _Command.CommandText = argument_SqlText;
34 _Command.CommandType = CommandType.Text;
35 if (null != argument_Parameters)
36 {
37 _Command.Parameters.AddRange(argument_Parameters);
38 }
39
40 try
41 {
42 this.Connection.Open();
43 _CommandResult = _Command.ExecuteNonQuery();
44 _Transaction.Commit();
45 }
46 catch (Exception)
47 {
48 _Transaction.Rollback();
49 }
50
51 OperationValue _Value = new OperationValue();
52 _Value.Value = _CommandResult;
53
54 return _Value;
55 }
56
57 public OperationValue Delete(string argument_SqlText, DbParameter[] argument_Parameters)
58 {
59 int _CommandResult = 0;
60 DbCommand _Command = this.Connection.DatabaseProvide.Factory.CreateCommand();
61 _Command.Connection = this.Connection.Connection;
62 _Command.CommandText = argument_SqlText;
63 _Command.CommandType = CommandType.Text;
64 if (null != argument_Parameters)
65 {
66 _Command.Parameters.AddRange(arg