84 lines
3.3 KiB
C#
84 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace CitySunlight
|
|
{
|
|
public static class ProductClassManager
|
|
{
|
|
public static SqlHelper sql = new SqlHelper("Data Source=.;Initial Catalog=myApplication;Persist Security Info=True;User ID=sa;Password=325325");
|
|
//分类表名
|
|
public const String tbname = "tb_proclass";
|
|
|
|
//获得分类列表默认选择第一个
|
|
public static String getOptionString(String name)
|
|
{
|
|
return getOptionString(name, "0");
|
|
}
|
|
//获得分类列表 可以配置选项
|
|
public static String getOptionString(String name, String df)
|
|
{
|
|
String html = "<select style=\"width: 120px\" Name=\"" + name + "\">";
|
|
html += "<option value=\"0\">请选择分类</option>";
|
|
DataTable option = sql.ExecuteDataTable("select * from " + tbname, CommandType.Text);
|
|
foreach (DataRow item in option.Rows)
|
|
{
|
|
String nid = item["Nid"].ToString();
|
|
String classname = item["ProClassName"].ToString();
|
|
html += String.Format("<option value=\"{0}\"{1}>{2}</option>", nid, df == nid ? " selected=\"selected\"" : "", classname);
|
|
}
|
|
html += "</select>";
|
|
return html;
|
|
}
|
|
//获得分类名称通过ID
|
|
public static String getClassName(int Nid)
|
|
{
|
|
DataTable dt = sql.ExecuteDataTable("select * from " + tbname + " where nid='" + Nid + "'", CommandType.Text);
|
|
if (dt.Rows.Count > 0)
|
|
return dt.Rows[0]["ProClassName"].ToString();
|
|
else
|
|
return "分类已被删除";
|
|
}
|
|
//判断分类是否存在
|
|
public static bool isExist(String name)
|
|
{
|
|
return sql.ExecuteDataTable("select * from " + tbname + " where ProClassName='" + name + "'", CommandType.Text).Rows.Count > 0;
|
|
}
|
|
public static bool isExist(int nid)
|
|
{
|
|
return sql.ExecuteDataTable("select * from " + tbname + " where Nid='" + nid + "'", CommandType.Text).Rows.Count > 0;
|
|
}
|
|
//添加分类
|
|
public static bool addclass(int Pid, String classname)
|
|
{
|
|
int j = sql.ExecuteNonQuery("insert into " + tbname + "(Pid,ProClassName) values('" + Pid + "','" + classname + "')", CommandType.Text);
|
|
if (j > 0)
|
|
return true;
|
|
return false;
|
|
}
|
|
//删除分类
|
|
public static bool removeclass(int Nid)
|
|
{
|
|
if (Nid != 0)
|
|
{
|
|
int j = sql.ExecuteNonQuery("delete from " + tbname + " where Nid='" + Nid + "'", CommandType.Text);
|
|
if (j > 0)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
//修改分类
|
|
public static bool editclass(int Nid, String cname)
|
|
{
|
|
if (Nid != 0)
|
|
{
|
|
int j = sql.ExecuteNonQuery("update " + tbname + " set ProClassName='" + cname + "' where Nid='" + Nid + "'", CommandType.Text);
|
|
if (j > 0)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
} |