如何把这行代码转换用三层架构的MODEL,BLL等调用方法写出来。见 问题补充中得代码。
stringstr=string.Format("insertintoT_Paiban(Num,Name,TheWeek,Monday,Tuesday,Wednesday...
string str = string.Format("insert into T_Paiban (Num,Name,TheWeek,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday) select Num,Name,TheWeek,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday from T_Paiban where TheWeek= '" + week + "'");
展开
1个回答
展开全部
只是一个model的例子,model主要是初始化一下,它的变量个数与数据库里的表对应,如果这一列是外键,要按外键声明。
using System;
using System.Collections.Generic;
using System.Text;
namespace Models
{
[Serializable()]
public class Category
{
private int id;
private string name = String.Empty;
public Category() { }
public int Id
{
get { return this.id; }
set { this.id = value; }
}
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}
}
BLL是业务逻辑层,里面只是调用DAL的方法,下面是一个例子
using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Models;
namespace BLL
{
public static partial class CategoryManager
{
public static int AddCategory(Category category)
{
return CategoryService.AddCategory(category);
}
public static void DeleteCategory(Category category)
{
CategoryService.DeleteCategory(category);
}
DAL层是数据处理层,主要是写SQL语句,这是一个DAL的例子,
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Models;
namespace DAL
{
public static partial class CategoryService
{
public static int AddCategory(Category category)
{
string sql =
"INSERT Categories (Name)" +
"VALUES (@Name)";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@Name", category.Name)
};
return DBHelper.ExecuteCommand(sql,para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
如果你知道哪层都是干什么的,想写出什么功能来就不难了
using System;
using System.Collections.Generic;
using System.Text;
namespace Models
{
[Serializable()]
public class Category
{
private int id;
private string name = String.Empty;
public Category() { }
public int Id
{
get { return this.id; }
set { this.id = value; }
}
public string Name
{
get { return this.name; }
set { this.name = value; }
}
}
}
BLL是业务逻辑层,里面只是调用DAL的方法,下面是一个例子
using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Models;
namespace BLL
{
public static partial class CategoryManager
{
public static int AddCategory(Category category)
{
return CategoryService.AddCategory(category);
}
public static void DeleteCategory(Category category)
{
CategoryService.DeleteCategory(category);
}
DAL层是数据处理层,主要是写SQL语句,这是一个DAL的例子,
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Models;
namespace DAL
{
public static partial class CategoryService
{
public static int AddCategory(Category category)
{
string sql =
"INSERT Categories (Name)" +
"VALUES (@Name)";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@Name", category.Name)
};
return DBHelper.ExecuteCommand(sql,para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
如果你知道哪层都是干什么的,想写出什么功能来就不难了
追问
其实主要是 函数功能不太清楚
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询