shopdal.cs
来自「c#三层架构项目开发的全过程」· CS 代码 · 共 230 行
CS
230 行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
namespace DAL.Branch
{
public class ShopDal
{
#region 添加分店
/// <summary>
/// 添加分店
/// </summary>
/// <param name="shop_name">分店名称</param>
/// <param name="shop_un">分店负责人</param>
/// <param name="shop_address">分店地址</param>
/// <param name="shop_tel">联系电话</param>
/// <returns></returns>
public int BranchAdd(string shop_name,string shop_un,string shop_address,string shop_tel)
{
string commandtext = "Branch_Add";
SqlParameter name = new SqlParameter("@Shop_name", SqlDbType.VarChar, 20);
SqlParameter un = new SqlParameter("@shop_un", SqlDbType.VarChar, 20);
SqlParameter address = new SqlParameter("@shop_address", SqlDbType.VarChar, 30);
SqlParameter tel = new SqlParameter("@shop_tel", SqlDbType.VarChar, 20);
name.Value = shop_name;
un.Value = shop_un;
address.Value = shop_address;
tel.Value = shop_tel;
return SqlHelper.ExecuteNonQuery(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, new SqlParameter[] { name, un, address, tel });
}
#endregion
#region 显示分店信息
/// <summary>
/// 显示分店信息
/// </summary>
/// <returns></returns>
public List<Model.Branch.ShopModel> BranchSelect()
{
string commandtext = "Branch_Select";
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { "Users" }, null);
List<Model.Branch.ShopModel> bs = new List<Model.Branch.ShopModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
Model.Branch.ShopModel li = new Model.Branch.ShopModel();
li.Shop_id = (int)item["Shop_id"];
li.Shop_name = item["Shop_name"].ToString();
li.Shop_un = item["Shop_un"].ToString();
li.Shop_address = item["Shop_address"].ToString();
li.Shop_tel = item["Shop_tel"].ToString();
bs.Add(li);
}
return bs;
}
#endregion
#region 分店信息在修改框显示
/// <summary>
/// 分店信息在修改框显示
/// </summary>
/// <param name="shop_id"></param>
/// <returns></returns>
public List<Model.Branch.ShopModel> BranchUpdateShow(int shop_id)
{
string commandtext = "Branch_Update_Show";
SqlParameter shopid = new SqlParameter("@shop_id", SqlDbType.Int);
shopid.Value = shop_id;
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { "Users" }, new SqlParameter[] { shopid });
List<Model.Branch.ShopModel> bus = new List<Model.Branch.ShopModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
Model.Branch.ShopModel bu = new Model.Branch.ShopModel();
bu.Shop_id = (int)item["Shop_id"];
bu.Shop_name = item["Shop_name"].ToString();
bu.Shop_un = item["Shop_un"].ToString();
bu.Shop_address = item["Shop_address"].ToString();
bu.Shop_tel = item["Shop_tel"].ToString();
bus.Add(bu);
}
return bus;
}
#endregion
#region 分店修改
/// <summary>
/// 分店修改
/// </summary>
/// <param name="shop_name">分店名称</param>
/// <param name="shop_un">分店负责人</param>
/// <param name="shop_address">分店地址</param>
/// <param name="shop_tel">联系电话</param>
/// <returns></returns>
public int BranchUpdate(int shop_id ,string shop_name, string shop_un, string shop_address, string shop_tel)
{
string commandtext = "Branch_Update";
SqlParameter uid = new SqlParameter("@Shop_id", SqlDbType.Int);
SqlParameter uname = new SqlParameter("@Shop_name", SqlDbType.VarChar, 20);
SqlParameter uun = new SqlParameter("@Shop_un", SqlDbType.VarChar, 20);
SqlParameter uaddress = new SqlParameter("@Shop_address", SqlDbType.VarChar, 30);
SqlParameter utel = new SqlParameter("@Shop_tel", SqlDbType.VarChar, 20);
uid.Value = shop_id;
uname.Value = shop_name;
uun.Value = shop_un;
uaddress.Value = shop_address;
utel.Value = shop_tel;
return SqlHelper.ExecuteNonQuery(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, new SqlParameter[] {uid, uname, uun, uaddress, utel });
}
#endregion
#region 删除分店
public int ShopDelete(int shop_id)
{
string com = "Branch_Delete";
SqlParameter id = new SqlParameter("@Shop_id", SqlDbType.Int);
id.Value = shop_id;
return SqlHelper.ExecuteNonQuery(SqlHelper.conStr, CommandType.StoredProcedure, com, new SqlParameter[] { id });
}
#endregion
#region 通过分店名称查询
public List<Model.Branch.ShopModel> SelectBranchByName(string shop_name)
{
string commandtext = "BranchById_Select";
DataSet ds = new DataSet();
SqlParameter name = new SqlParameter("@Shop_name", SqlDbType.VarChar, 20);
name.Value = shop_name;
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { "ue" }, name);
List<Model.Branch.ShopModel> li1 = new List<Model.Branch.ShopModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
Model.Branch.ShopModel md = new Model.Branch.ShopModel();
md.Shop_id =(int)item["Shop_id"];
md.Shop_name = item["Shop_name"].ToString();
md.Shop_un = item["Shop_un"].ToString();
md.Shop_address = item["Shop_address"].ToString();
md.Shop_tel = item["Shop_tel"].ToString();
li1.Add(md);
}
return li1;
}
#endregion
#region 分店查看详情
/// <summary>
/// 分店查看详情
/// </summary>
/// <param name="shop_id">分店编号</param>
/// <returns></returns>
public List<Model.Branch.ShopModel> BranchSelectDetail(int shop_id)
{
string commandtext = "Branch_Select_Detail";
DataSet ds = new DataSet();
SqlParameter shopid = new SqlParameter("@Shop_id",SqlDbType.Int);
shopid.Value = shop_id;
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { "ue" }, new SqlParameter[]{ shopid});
List<Model.Branch.ShopModel> bsd = new List<Model.Branch.ShopModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
Model.Branch.ShopModel bds = new Model.Branch.ShopModel();
bds.Shop_id = (int)item["Shop_id"];
bds.Shop_name = item["Shop_name"].ToString();
bds.Shop_un = item["Shop_un"].ToString();
bds.Shop_address = item["Shop_address"].ToString();
bds.Shop_tel = item["Shop_tel"].ToString();
bsd.Add(bds);
}
return bsd;
}
#endregion
#region 找出所有的分店编号
public List<Model.Branch.ShopModel> SelectID()
{
string commandtext = "ShopById_select";
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { }, null);
List<Model.Branch.ShopModel> li = new List<Model.Branch.ShopModel>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
Model.Branch.ShopModel inf = new Model.Branch.ShopModel();
inf.Shop_id = (int)dr["Shop_id"];
li.Add(inf);
}
return li;
}
#endregion
#region 通过分店编号来查找分店信息
public List<Model.Branch.ShopModel> selectname(string shop_un)
{
string commandtext = "ShowByName";
SqlParameter na = new SqlParameter("@Shop_un",SqlDbType.VarChar,20);
na.Value = shop_un;
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { }, na );
List<Model.Branch.ShopModel> list = new List<Model.Branch.ShopModel>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
Model.Branch.ShopModel in1 = new Model.Branch.ShopModel();
in1.Shop_id =(int) dr["Shop_id"];
in1.Shop_name = dr["Shop_name"].ToString();
in1.Shop_un = dr["Shop_un"].ToString();
in1.Shop_address = dr["Shop_address"].ToString();
in1.Shop_tel = dr["Shop_tel"].ToString();
list.Add(in1);
}
return list;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?