您的位置:知识库 » 程序人生

回忆孔先生

作者: 梁逸晨  来源: 博客园  发布时间: 2008-12-25 23:34  阅读: 1481 次  推荐: 0   原文链接   [收藏]  
摘要:由鲁迅笔下的孔乙己这一人物展开的对程序员的描绘
[1] 1.人物刻画
[2] 2.敲击代码
[3] 3.结尾

 

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);
        }

    }

}

 

0
0
标签:人生经验

程序人生热门文章

    程序人生最新文章

      最新新闻

        热门新闻