上传者: asp12345678
|
上传时间: 2021-12-26 21:53:01
|
文件大小: 6.2MB
|
文件类型: -
统实施
完成了系统的概念结构及逻辑结构设计之后,就进入了系统的功能模块及相应的代码设计。我是用分层架构设计来设计功能模块及代码的实施过程。
4.1 逻辑架构设计
分层设计代码架构,其中包括与数据库连接的基础代码及相对于个功能实现的操作代码,具体如下图:
由于各窗体的增加、删除、修改及查询操作都采用同样的方式,我就举一例而代之,实现的具体代码如下:
namespace 超市采购管理系统.DAL
{
public class GoodMenthod
{
SQLHelper sqlhelper = null;
MGood mg = null;
SqlDataReader dr = null;
public GoodMenthod()
{
sqlhelper = new SQLHelper();
mg = new MGood();
}
public bool GoodAdd(MGood mg)
{
bool flag = false;
string sql = "insert into Good values(@gdId ,@gdName ,@gdDw ,@gdjhPrice ,@gdsellPrice ,@cgId,@kcId)";
SqlParameter[] paras = new SqlParameter[] {new SqlParameter ("@gdId",mg.pgdId),new SqlParameter ("@gdName",mg.pgdName),
new SqlParameter ("@gdDw",mg.pgdDw),new SqlParameter ("@gdjhPrice",mg.pgdjhPrice),new SqlParameter ("@gdsellPrice",mg.pgdsellPrice),
new SqlParameter ("@cgId",mg.pcgId),new SqlParameter("@kcId",mg.pkcId)};
int i = sqlhelper.ExecuteNonQuery(sql, paras);
if (i > 0)
{ flag = true; }
return flag;
}
public bool GoodDelete(string str)
{
bool flag = false;
string sql = "delete from Good where gdId ='" + str + "'";
int i = sqlhelper.exec(sql);
if (i > 0)
{ flag = true; }
return flag;
}
public void GoodFind(Object dataObject)
{
string str = null;
try
{
str = "select gdId 商品编号,gdName 商品名称,gdDw 计量单位,gdjhPrice 进价,gdsellPrice 计划售价,cgId 所属类别编号,kcId 所属仓库编号 from Good ";
DataTable dt = sqlhelper.ExecuteQuery(str);
DataGridView dv = (DataGridView)dataObject;
dv.DataSource = dt;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public SqlDataReader Fill(string str)
{
string sql = "select * from Good where gdId= '" + str + "'";
SqlCommand cmd = new SqlCommand();
using (cmd = new SqlCommand(sql, sqlhelper.GetConn()))
{ dr = cmd.ExecuteReader(); }
return dr;
}
public void GoodFind(string s, string str, Object dataObject)
{
string sql = null;
try
{
switch (s)
{
case "商品编号":
sql = "select gdId 商品编号,gdName 商品名称,gdDw 计量单位,gdjhPrice 进价,gdsellPrice 计划售价 ,cgId 所属类别编号,kcId 所属仓库编号 from Good where gdId = '" + str + "'";
break;
case "商品名称":
sql = "select gdId 商品编号,gdName 商品名称,gdDw 计量单位,gdjhPrice 进价,gdsellPrice 计划售价 ,cgId 所属类别编号,kcId 所属仓库编号 from Good where gdName = '" + str + "'";
break;
case "查询所有信息":
sql = "select gdId 商品编号,gdName 商品名称,gdDw 计量单位,gdjhPrice 进价,gdsellPrice 计划售价 ,cgId 所属类别编号,kcId 所属仓库编号 from Good ";
break;
}
DataTable dt = sqlhelper.ExecuteQuery(sql);
System.Windows.Forms.DataGridView dv = (DataGridView)dataObject;
dv.DataSource = dt;
}
catch (Exception ee)
{ MessageBox.Show(ee.Message); }
}
}
}
其中传递该方法用到的实体类如下:
namespace 超市采购管理系统.Model
{
public class MGood
{
private string gdId;
private string gdName;
private string gdDw;
private string gdjhPrice;
private string gdsellPrice;
private string cgId;
private string kcId;
public string pgdId
{
get { return gdId; }
set { gdId = value; }
}
public string pgdName
{
get { return gdName; }
set { gdName = value; }
}
public string pgdDw
{
get { return gdDw; }
set { gdDw = value; }
}
public string pgdjhPrice
{
get { return gdjhPrice; }
set { gdjhPrice = value; }
}
public string pgdsellPrice
{
get { return gdsellPrice; }
set { gdsellPrice = value; }
}
public string pcgId
{
get { return cgId; }
set { cgId = value; }
}
public string pkcId
{
get { return kcId; }
set { kcId = value; }
}
}
}