Files
g.hnyhua.cn/Mtxfw.DAL/user_address.cs
2026-02-07 15:48:27 +08:00

268 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Mtxfw.DAL
{
/// <summary>
/// 数据访问类:user_address
/// </summary>
public partial class user_address : Mtxfw.Utility.Myabstract
{
public user_address()
: base("user_address")
{ }
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Mtxfw.Model.user_address model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into user_address(");
strSql.Append("UserID,Contactname,Contacttel,Province,City,County,IFFill,Tradingarea,Address,Zipcode,Guests,IFIndex,gtype)");
strSql.Append(" values (");
strSql.Append("@UserID,@Contactname,@Contacttel,@Province,@City,@County,@IFFill,@Tradingarea,@Address,@Zipcode,@Guests,@IFIndex,@gtype)");
strSql.Append(";select SCOPE_IDENTITY()");
SqlParameter[] parameters = {
new SqlParameter("@UserID", SqlDbType.Int),
new SqlParameter("@Contactname", SqlDbType.VarChar,50),
new SqlParameter("@Contacttel", SqlDbType.VarChar,50),
new SqlParameter("@Province", SqlDbType.VarChar,50),
new SqlParameter("@City", SqlDbType.VarChar,50),
new SqlParameter("@County", SqlDbType.VarChar,50),
new SqlParameter("@IFFill", SqlDbType.Int),
new SqlParameter("@Tradingarea", SqlDbType.VarChar,50),
new SqlParameter("@Address", SqlDbType.VarChar,100),
new SqlParameter("@Zipcode", SqlDbType.VarChar,50),
new SqlParameter("@Guests", SqlDbType.VarChar,500),
new SqlParameter("@IFIndex", SqlDbType.Int),
new SqlParameter("@gtype", SqlDbType.Int)};
parameters[0].Value = model.UserID;
parameters[1].Value = model.Contactname;
parameters[2].Value = model.Contacttel;
parameters[3].Value = model.Province;
parameters[4].Value = model.City;
parameters[5].Value = model.County;
parameters[6].Value = model.IFFill;
parameters[7].Value = model.Tradingarea;
parameters[8].Value = model.Address;
parameters[9].Value = model.Zipcode;
parameters[10].Value = model.Guests;
parameters[11].Value = model.IFIndex;
parameters[12].Value = model.gtype;
string obj = Mtxfw.Utility.SqlDbHelper_U.GetObject(strSql.ToString(), parameters).ToString();
if (obj == "")
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Mtxfw.Model.user_address model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update user_address set ");
strSql.Append("Contactname=@Contactname,");
strSql.Append("Contacttel=@Contacttel,");
strSql.Append("Province=@Province,");
strSql.Append("City=@City,");
strSql.Append("County=@County,");
strSql.Append("IFFill=@IFFill,");
strSql.Append("Tradingarea=@Tradingarea,");
strSql.Append("Address=@Address,");
strSql.Append("Zipcode=@Zipcode,");
strSql.Append("Guests=@Guests,IFIndex=@IFIndex");
strSql.Append(" where ID=@ID");
SqlParameter[] parameters = {
new SqlParameter("@ID", SqlDbType.Int),
new SqlParameter("@Contactname", SqlDbType.VarChar,50),
new SqlParameter("@Contacttel", SqlDbType.VarChar,50),
new SqlParameter("@Province", SqlDbType.VarChar,50),
new SqlParameter("@City", SqlDbType.VarChar,50),
new SqlParameter("@County", SqlDbType.VarChar,50),
new SqlParameter("@IFFill", SqlDbType.Int),
new SqlParameter("@Tradingarea", SqlDbType.VarChar,50),
new SqlParameter("@Address", SqlDbType.VarChar,100),
new SqlParameter("@Zipcode", SqlDbType.VarChar,50),
new SqlParameter("@Guests", SqlDbType.VarChar,500),
new SqlParameter("@IFIndex", SqlDbType.Int)};
parameters[0].Value = model.Id;
parameters[1].Value = model.Contactname;
parameters[2].Value = model.Contacttel;
parameters[3].Value = model.Province;
parameters[4].Value = model.City;
parameters[5].Value = model.County;
parameters[6].Value = model.IFFill;
parameters[7].Value = model.Tradingarea;
parameters[8].Value = model.Address;
parameters[9].Value = model.Zipcode;
parameters[10].Value = model.Guests;
parameters[11].Value = model.IFIndex;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public void UpdateIFIndex(int userid)
{
List<string> list = new List<string>();
list.Add("Update user_address set IFIndex=0 Where UserID=" + userid);
Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(list);
}
/// <summary>
/// 更新一条数据
/// </summary>
public void UpdateIFIndex(int id,int userid)
{
List<string> list = new List<string>();
list.Add("Update user_address set IFIndex=1 Where id=" + id + " And UserID=" + userid);
list.Add("Update user_address set IFIndex=0 Where id<>" + id + " And UserID=" + userid);
Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(list);
}
/// <summary>
/// 更新一条数据
/// </summary>
public void UpdateIFIndex0(int id, int userid)
{
List<string> list = new List<string>();
list.Add("Update user_address set IFIndex=0 Where id=" + id + " And UserID=" + userid);
Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(list);
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int Id, int userid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from user_address ");
strSql.Append(" where Id=@Id");
if (userid > 0)
{
strSql.Append(" And userid=@userid");
}
SqlParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4),
new SqlParameter("@userid", SqlDbType.Int,4)
};
parameters[0].Value = Id;
parameters[1].Value = userid;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Mtxfw.Model.user_address GetModel(int Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 * from user_address ");
strSql.Append(" where Id=@Id");
SqlParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4)
};
parameters[0].Value = Id;
Mtxfw.Model.user_address model = new Mtxfw.Model.user_address();
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
{
model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
}
if (ds.Tables[0].Rows[0]["UserID"].ToString() != "")
{
model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
}
model.Contactname = ds.Tables[0].Rows[0]["Contactname"].ToString();
model.Contacttel = ds.Tables[0].Rows[0]["Contacttel"].ToString();
model.Province = ds.Tables[0].Rows[0]["Province"].ToString();
model.City = ds.Tables[0].Rows[0]["City"].ToString();
model.County = ds.Tables[0].Rows[0]["County"].ToString();
model.IFFill = Convert.ToInt32(ds.Tables[0].Rows[0]["IFFill"].ToString());
model.Tradingarea = ds.Tables[0].Rows[0]["Tradingarea"].ToString();
model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
model.Zipcode = ds.Tables[0].Rows[0]["Zipcode"].ToString();
model.Guests = ds.Tables[0].Rows[0]["Guests"].ToString();
if (ds.Tables[0].Rows[0]["IFIndex"].ToString() != "")
{
model.IFIndex = int.Parse(ds.Tables[0].Rows[0]["IFIndex"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM user_address ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" * ");
strSql.Append(" FROM user_address ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
}
}
}