111,120
社区成员
发帖
与我相关
我的任务
分享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 WindowsFormsApplication22
{
public partial class Form1 : Form // 界面层
{
public Form1()
{
InitializeComponent();
E EObj = new B().GetNameByID(2);
if (EObj != null)
MessageBox.Show(EObj.Name);
}
}
class B // 逻辑层
{
public E GetNameByID(int ID)
{
DataTable DT = new D().GetData();
DataRow[] DRS = DT.Select(Table.ID + "=" + ID);
if (DRS.Length > 0)
return ClassFactoryService.GetEByDR(DRS[0]);
else
return null;
}
}
class D // 数据层
{
public DataTable GetData()
{
DataTable DT = new DataTable();
DT.TableName = Table.Tablename;
DT.Columns.Add(Table.ID);
DT.Columns.Add(Table.Name);
DT.Rows.Add(new Object[] { 1, "A" });
DT.Rows.Add(new Object[] { 2, "B" });
DT.Rows.Add(new Object[] { 3, "C" });
return DT;
}
}
class ClassFactoryService // 服务层
{
static public E GetEByDR(DataRow DR)
{
E EObj = new E();
EObj.ID = Convert.ToInt32(DR[Table.ID]);
EObj.Name = DR[Table.Name].ToString();
return EObj;
}
}
class E // 实体类
{
public int ID;
public String Name;
}
class Table // 表定义
{
static public String Tablename = "XXX";
static public String ID = "ID";
static public String Name = "Name";
}
}