⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodstype.cs

📁 大话设计大话设计模式所有源代码模式所有源代码大话设计模式所有源代码
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace TBLibrary.Shop.ShopManage
{
	/// <summary>
	/// GoodsType 的摘要说明。
	/// </summary>
	public class GoodsType : TBLibrary.Shop.DbBase.Base
	{
		public GoodsType()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		/// <summary>
		/// 设置父分类
		/// </summary>
		/// <returns></returns>		
		public static DataView GetClass1()
		{
			string strSql;
			DataSet myDs;
			strSql = "Select * From Class_1 order by sequence";
			myDs = ExecuteSqlDs(strSql);
			return myDs.Tables[0].DefaultView;
		}
		/// <summary>
		/// 设置子分类
		/// </summary>
		/// <param name="fatherID"></param>
		/// <returns></returns>
		public static DataView GetClass2(int fatherID)
		{
			string strSql;
			DataSet myDs;
			strSql = "Select * From Class2V Where Class_father =" + fatherID +"order by sequence";
			myDs = ExecuteSqlDs(strSql);
			return myDs.Tables[0].DefaultView;
		}
		/// <summary>
		/// 查找父类ID号
		/// </summary>
		/// <param name="sunID"></param>
		/// <returns></returns>
		public static int FindFatherClass(int sunID)
		{
			string strSql = "Select Class_1ID From Class_1 Where Class_1ID = (Select Class_father From Class_2 Where Class_2ID = "+sunID+" )";
			try
			{
				return (int)EexecuteSqlValue(strSql);
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
			
		}
		/// <summary>
		/// 读取货物所存在的  分类
		/// </summary>
		/// <param name="sunID"></param>
		/// <returns></returns>
		public static DataView ReadGoodsClassName(int sunID)
		{
			try
			{
				string strSql="Select Class_1.className,Class_2.className From Class_1,Class_2 Where(Class_2.Class_2ID = "+sunID+") "
					+"And(Class_2.Class_father = Class_1.Class_1ID)";
				DataSet myDs = new DataSet();
				myDs = ExecuteSqlDs(strSql);
				return myDs.Tables[0].DefaultView;
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}

		/// <summary>
		/// 判断是否存在该分类的名字;
		/// </summary>
		/// <param name="className"></param>
		/// <param name="classId"></param>
		/// <returns></returns>
		public bool IfExist(string className)
		{
			string strSql1 = "Select Class_1ID From Class_1 where className ='"+className+"'";
			//string strSql2 = "Select Class_2ID From Class_2 where className ='"+className+"'";
			try
			{
				
				EexecuteSqlValue(strSql1);					
				
			
				return true;
			}
			catch
			{
				//throw new Exception("Classid Error");
				return false;
			}
		}
		public bool IfExist2(string className,int fatherID)
		{
			string strSql = "Select Class_2ID From Class_2 where(className ='"+className+"')And(Class_father='"+fatherID+"')";
			try
			{
				EexecuteSqlValue(strSql);					
				return true;
			}
			catch
			{
				//throw new Exception("Classid Error");
				return false;
			}
		}
		/// <summary>
		/// 添加分类1
		/// </summary>
		/// <param name="className"></param>
		public void AddClass1(string classname,int i)
		{
			if(IfExist(classname))
			{
				throw new Exception("The Class Exist");
			}
			else
			{
				try
				{
					string strSql = "Insert into Class_1(ClassName,sequence)values('"+classname+"',"+i+")";		
					ExecuteSql(strSql);
				}
				catch(Exception ex)
				{
					throw new Exception(ex.Message);
				}
			}
		}
		/// <summary>
		/// 添加分类2
		/// </summary>
		/// <param name="Id"></param>
		/// <param name="className"></param>
		/// <param name="i"></param>

		public void AddClass2(int class_father,string className,int i)
		{
			if(IfExist2(className,class_father))
			{
				throw new Exception("The Class Exist");
			}
			else
			{
				try
				{
					string strSql = "Insert into Class_2(className,Class_father,sequence) values ('"+className+"','"+class_father+"','"+i+"')";
					ExecuteSql(strSql);
				}
				catch(Exception ex)
				{
					throw new Exception(ex.Message);
				}
			}
		}
		/// <summary>
		/// 删除分类
		/// </summary>
		/// <param name="id"></param>
		/// <param name="classId"></param>
		public void Delete(int id,byte classId)
		{
			string strSql1 = "Delete From Class_1 where Class_1ID ="+id;
			string strSql2 = "Delete From Class_2 where Class_2ID ="+id;
			try
			{
				if(classId == 1)
				{
					ExecuteSql(strSql1);
				}
				else if(classId == 2)
				{
					ExecuteSql(strSql2);
				}
				else
				{
					throw new Exception("分类错误");
				}
			}
			catch
			{
				throw new Exception("delete failed!");
			}
		}
        
		/// <summary>
		/// 更新分类1
		/// </summary>
		/// <param name="id"></param>
		/// <param name="sequence"></param>
		/// <param name="className"></param>
		public static void UpdataClass1(int id,int sequence,string className)
		{
			string strSql = "Update Class_1 Set sequence ="+sequence+",className = '"+className+"'"
				+"Where Class_1ID ="+id;
			try
			{
				ExecuteSql(strSql);
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
		/// <summary>
		/// 更新分类2
		/// </summary>
		/// <param name="id"></param>
		/// <param name="sequence"></param>
		/// <param name="className"></param>
		public static void UpdataClass2(int id,int sequence,string className)
		{
			string strSql = "Update Class_2 Set sequence ="+sequence+",className = '"+className+"'"
				+"Where Class_2ID ="+id;
			try
			{
				ExecuteSql(strSql);
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -