回忆孔先生
using System;
using System.Data;
using System.Data.Common;
namespace kongyiji
{
interface IHui
{
void Print();
void Print(int step);
}
///
/// 抽象基类,实现通用的草字头输出
///
abstract class AHui: IHui
{
IHui i;
private IDbCommand comm;
private IDbConnection conn;
private DbProviderFactory _dbFac;
private IDbDataParameter pram;
public AHui(DbProviderFactory DbFac)
{
Console.WriteLine("艹");
_dbFac = DbFac;
}
public abstract void Print();
protected void SaveSwitch(string hui_type)
{
conn = _dbFac.CreateConnection();
conn.ConnectionString = @"Data Source=localhost;Initial Catalog=local_db;Persist Security Info=True;User ID=sa;Password=123456789";
comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO LOG(hui_type) VALUES(@hui_type);";
pram = comm.CreateParameter();
pram.DbType = DbType.String;
pram.ParameterName = "@hui_type";
pram.Value = hui_type;
//conn.Open();
//comm.ExecuteNonQuery();
//conn.Close();
}
public void Print(int step)
{
i = HuiFactory.Hui(_dbFac,step);
i.Print();
}
}
///
/// 回字写法
///
class SelectHui: AHui
{
string _hui;
public SelectHui(string select_hui, DbProviderFactory DbFac)
: base(DbFac)
{
_hui = select_hui;
}
public override void Print()
{
Console.WriteLine(_hui);
SaveSwitch(_hui);
}
}
class HuiFactory
{
public static IHui Hui(DbProviderFactory DbFac,int step)
{
IHui temp = null;
switch(step)
{
case 1:
temp = new SelectHui("回", DbFac);
break;
case 2:
temp = new SelectHui("囘", DbFac);
break;
case 3:
temp = new SelectHui("囬", DbFac);
break;
case 4:
temp = new SelectHui("廻", DbFac);
break;
default:
temp = new SelectHui("廻", DbFac);
break;
}
return temp;
}
}
class Program
{
static void Main(string[] args)
{
DbProviderFactory fac = DbProviderFactories.GetFactory("System.Data.SqlClient");
IHui i = HuiFactory.Hui(fac,4);
i.Print();
i.Print(2);
}
}
}
using System.Data;
using System.Data.Common;
namespace kongyiji
{
interface IHui
{
void Print();
void Print(int step);
}
///
/// 抽象基类,实现通用的草字头输出
///
abstract class AHui: IHui
{
IHui i;
private IDbCommand comm;
private IDbConnection conn;
private DbProviderFactory _dbFac;
private IDbDataParameter pram;
public AHui(DbProviderFactory DbFac)
{
Console.WriteLine("艹");
_dbFac = DbFac;
}
public abstract void Print();
protected void SaveSwitch(string hui_type)
{
conn = _dbFac.CreateConnection();
conn.ConnectionString = @"Data Source=localhost;Initial Catalog=local_db;Persist Security Info=True;User ID=sa;Password=123456789";
comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO LOG(hui_type) VALUES(@hui_type);";
pram = comm.CreateParameter();
pram.DbType = DbType.String;
pram.ParameterName = "@hui_type";
pram.Value = hui_type;
//conn.Open();
//comm.ExecuteNonQuery();
//conn.Close();
}
public void Print(int step)
{
i = HuiFactory.Hui(_dbFac,step);
i.Print();
}
}
///
/// 回字写法
///
class SelectHui: AHui
{
string _hui;
public SelectHui(string select_hui, DbProviderFactory DbFac)
: base(DbFac)
{
_hui = select_hui;
}
public override void Print()
{
Console.WriteLine(_hui);
SaveSwitch(_hui);
}
}
class HuiFactory
{
public static IHui Hui(DbProviderFactory DbFac,int step)
{
IHui temp = null;
switch(step)
{
case 1:
temp = new SelectHui("回", DbFac);
break;
case 2:
temp = new SelectHui("囘", DbFac);
break;
case 3:
temp = new SelectHui("囬", DbFac);
break;
case 4:
temp = new SelectHui("廻", DbFac);
break;
default:
temp = new SelectHui("廻", DbFac);
break;
}
return temp;
}
}
class Program
{
static void Main(string[] args)
{
DbProviderFactory fac = DbProviderFactories.GetFactory("System.Data.SqlClient");
IHui i = HuiFactory.Hui(fac,4);
i.Print();
i.Print(2);
}
}
}