347 lines
13 KiB
C#
347 lines
13 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
|
|
|
|
namespace Mtxfw.DAL
|
|
{
|
|
/// <summary>
|
|
/// 数据访问类:P_Category
|
|
/// </summary>
|
|
public partial class P_Category : Mtxfw.Utility.Myabstract
|
|
{
|
|
public P_Category()
|
|
: base("P_Category")
|
|
{ }
|
|
|
|
/// <summary>
|
|
/// 增加一条数据
|
|
/// </summary>
|
|
public int Add(Mtxfw.Model.P_Category model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("insert into P_Category(");
|
|
strSql.Append("C_PARENTID,C_PARENTIDs,C_NAME,C_images,C_LinkID,C_Layer,ttype,GGEnable,gtype)");
|
|
strSql.Append(" values (");
|
|
strSql.Append("@C_PARENTID,@C_PARENTIDs,@C_NAME,@C_images,@C_LinkID,@C_Layer,@ttype,@GGEnable,@gtype)");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@C_PARENTID", SqlDbType.Int),
|
|
new SqlParameter("@C_PARENTIDs", SqlDbType.VarChar,800),
|
|
new SqlParameter("@C_NAME", SqlDbType.VarChar,800),
|
|
new SqlParameter("@C_images", SqlDbType.VarChar,250),
|
|
new SqlParameter("@C_LinkID", SqlDbType.Int),
|
|
new SqlParameter("@C_Layer", SqlDbType.Int),
|
|
new SqlParameter("@ttype", SqlDbType.Int),
|
|
new SqlParameter("@GGEnable", SqlDbType.Int),
|
|
new SqlParameter("@gtype", SqlDbType.Int)};
|
|
parameters[0].Value = model.C_PARENTID;
|
|
parameters[1].Value = model.C_PARENTIDs;
|
|
parameters[2].Value = model.C_NAME;
|
|
parameters[3].Value = model.C_images;
|
|
parameters[4].Value = model.C_LinkID;
|
|
parameters[5].Value = model.C_Layer;
|
|
parameters[6].Value = model.ttype;
|
|
parameters[7].Value = model.GGEnable;
|
|
parameters[8].Value = model.gtype;
|
|
return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
}
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public int Update(Mtxfw.Model.P_Category model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update P_Category set ");
|
|
strSql.Append("C_PARENTID=@C_PARENTID,");
|
|
strSql.Append("C_PARENTIDs=@C_PARENTIDs,");
|
|
strSql.Append("C_NAME=@C_NAME,");
|
|
strSql.Append("C_images=@C_images,");
|
|
strSql.Append("C_LinkID=@C_LinkID,");
|
|
strSql.Append("C_Layer=@C_Layer,");
|
|
strSql.Append("GGEnable=@GGEnable");
|
|
strSql.Append(" where C_ID=@C_ID");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@C_PARENTID", SqlDbType.Int),
|
|
new SqlParameter("@C_PARENTIDs", SqlDbType.VarChar,800),
|
|
new SqlParameter("@C_NAME", SqlDbType.VarChar,800),
|
|
new SqlParameter("@C_images", SqlDbType.VarChar,250),
|
|
new SqlParameter("@C_LinkID", SqlDbType.Int),
|
|
new SqlParameter("@C_Layer", SqlDbType.Int),
|
|
new SqlParameter("@GGEnable", SqlDbType.Int),
|
|
new SqlParameter("@C_ID", SqlDbType.Int)};
|
|
parameters[0].Value = model.C_PARENTID;
|
|
parameters[1].Value = model.C_PARENTIDs;
|
|
parameters[2].Value = model.C_NAME;
|
|
parameters[3].Value = model.C_images;
|
|
parameters[4].Value = model.C_LinkID;
|
|
parameters[5].Value = model.C_Layer;
|
|
parameters[6].Value = model.GGEnable;
|
|
parameters[7].Value = model.C_ID;
|
|
|
|
return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
}
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public int Update(int strID,string Sel,int SelValue)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
if (Sel == "C_ProductCount")
|
|
{
|
|
strSql.Append("update P_Category set " + Sel + "=" + Sel + "+@SelValue where C_ID=@C_ID");
|
|
}
|
|
else
|
|
{
|
|
strSql.Append("update P_Category set " + Sel + "=@SelValue where C_ID=@C_ID");
|
|
}
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@SelValue", SqlDbType.Int,4),
|
|
new SqlParameter("@C_ID", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = SelValue;
|
|
parameters[1].Value = strID;
|
|
return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
}
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public int Update2(int strID, int SelValue)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update P_Category set C_ProductCount=C_ProductCount+@SelValue where C_ID=@C_ID Or charindex(',' + convert(varchar(50),C_ID) + ',',(Select C_PARENTIDs From P_Category where C_ID=@C_ID))>0");
|
|
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@SelValue", SqlDbType.Int,4),
|
|
new SqlParameter("@C_ID", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = SelValue;
|
|
parameters[1].Value = strID;
|
|
return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
}
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool Delete(int C_ID)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from P_Category ");
|
|
strSql.Append(" where C_ID=@C_ID");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@C_ID", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = C_ID;
|
|
|
|
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool Delete2(int C_ID)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from P_Category ");
|
|
strSql.Append(" where C_ID=@C_ID Or C_PARENTIDs like '%,"+ C_ID +",%'");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@C_ID", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = C_ID;
|
|
|
|
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 得到一个对象实体
|
|
/// </summary>
|
|
public Mtxfw.Model.P_Category GetModel(int C_ID)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select top 1 a.*,(select b.C_NAME From P_Category b where b.C_ID=a.C_PARENTID) as CNAME from P_Category a");
|
|
strSql.Append(" where C_ID=@C_ID");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@C_ID", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = C_ID;
|
|
|
|
Mtxfw.Model.P_Category model = new Mtxfw.Model.P_Category();
|
|
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters);
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (ds.Tables[0].Rows[0]["C_ID"].ToString() != "")
|
|
{
|
|
model.C_ID = int.Parse(ds.Tables[0].Rows[0]["C_ID"].ToString());
|
|
}
|
|
if (ds.Tables[0].Rows[0]["C_PARENTID"].ToString() != "")
|
|
{
|
|
model.C_PARENTID = int.Parse(ds.Tables[0].Rows[0]["C_PARENTID"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.C_PARENTID = 0;
|
|
}
|
|
model.C_PARENTIDs = ds.Tables[0].Rows[0]["C_PARENTIDs"].ToString();
|
|
model.C_NAME = ds.Tables[0].Rows[0]["C_NAME"].ToString();
|
|
model.CNAME = ds.Tables[0].Rows[0]["CNAME"].ToString();
|
|
model.C_images = ds.Tables[0].Rows[0]["C_images"].ToString();
|
|
if (ds.Tables[0].Rows[0]["C_LinkID"].ToString() != "")
|
|
{
|
|
model.C_LinkID = int.Parse(ds.Tables[0].Rows[0]["C_LinkID"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.C_LinkID = 0;
|
|
}
|
|
if (ds.Tables[0].Rows[0]["C_Layer"].ToString() != "")
|
|
{
|
|
model.C_Layer = int.Parse(ds.Tables[0].Rows[0]["C_Layer"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.C_Layer = 0;
|
|
}
|
|
if (ds.Tables[0].Rows[0]["GGEnable"].ToString() != "")
|
|
{
|
|
model.GGEnable = int.Parse(ds.Tables[0].Rows[0]["GGEnable"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.GGEnable = 0;
|
|
}
|
|
if (ds.Tables[0].Rows[0]["IfShow"].ToString() != "")
|
|
{
|
|
model.IfShow = int.Parse(ds.Tables[0].Rows[0]["IfShow"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.IfShow = 0;
|
|
}
|
|
if (ds.Tables[0].Rows[0]["ttype"].ToString() != "")
|
|
{
|
|
model.ttype = int.Parse(ds.Tables[0].Rows[0]["ttype"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.ttype = 0;
|
|
}
|
|
if (ds.Tables[0].Rows[0]["C_ProductCount"].ToString() != "")
|
|
{
|
|
model.C_ProductCount = int.Parse(ds.Tables[0].Rows[0]["C_ProductCount"].ToString());
|
|
}
|
|
else
|
|
{
|
|
model.C_ProductCount = 0;
|
|
}
|
|
return model;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得数据列表
|
|
/// </summary>
|
|
public DataSet GetList(string strWhere)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select a.*,(select b.C_NAME From P_Category b where b.C_ID=a.C_PARENTID) as CNAME");
|
|
strSql.Append(" FROM P_Category a");
|
|
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(" a.*");
|
|
strSql.Append(" FROM P_Category a");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
strSql.Append(" order by " + filedOrder);
|
|
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
|
|
}
|
|
/// <summary>
|
|
/// 获得分类名称
|
|
/// </summary>
|
|
public string GetCategoryName(int utype, string Categorys)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
string[] ACategory = Categorys.Split(',');
|
|
foreach (string strc in ACategory)
|
|
{
|
|
if (!String.IsNullOrEmpty(strc))
|
|
{
|
|
string strzd = Getzd("C_NAME", "ttype=" + utype + " And C_ID=" + strc).ToString();
|
|
if (sb.ToString() != "")
|
|
{
|
|
sb.Append("-" + strzd);
|
|
}
|
|
else
|
|
{
|
|
sb.Append(strzd);
|
|
}
|
|
}
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
/// <summary>
|
|
/// 获得分类ID
|
|
/// </summary>
|
|
public string GetCategoryIDs(int utype, string keyword)
|
|
{
|
|
string strid = "";
|
|
DataSet lbds = GetList1("C_ID", "ttype=" + utype + " And C_NAME like '" + keyword + "'");
|
|
if (lbds.Tables[0].Rows.Count > 0)
|
|
{
|
|
foreach (System.Data.DataRow lbdrv in lbds.Tables[0].Rows)
|
|
{
|
|
if (strid != "")
|
|
{
|
|
strid += "," + lbdrv["C_ID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
strid = lbdrv["C_ID"].ToString();
|
|
}
|
|
}
|
|
}
|
|
lbds.Clear();
|
|
return strid;
|
|
}
|
|
}
|
|
}
|
|
|