267 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			267 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using AIMSModel;
 | |
| using AIMSObjectQuery;
 | |
| using HelperDB;
 | |
| using System.Reflection;
 | |
| using System.Text;
 | |
| 
 | |
| namespace AIMSDAL
 | |
| {
 | |
|     internal partial class DBasicDictionary
 | |
|     {
 | |
|         public static DataTable GetBasicDictionaryByWhere(string where)
 | |
|         {
 | |
|             string sql = "select * from BasicDictionary" + (where == "" ? "" : " where " + where);
 | |
|             return DBHelper.GetDataTable(sql);
 | |
|         }
 | |
| 
 | |
|         public static void Add(BasicDictionary BasicDictionaryObj)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("insert into [BasicDictionary](");
 | |
|             strSql.Append("Name,ParentId,HelpCode,[Order],IsValid,OperatorNo,OperatorName,OperateDate,Remark");
 | |
|             strSql.Append(")");
 | |
|             strSql.Append(" values (");
 | |
|             strSql.Append("'" + BasicDictionaryObj.Name + "',");
 | |
|             strSql.Append("" + BasicDictionaryObj.ParentId + ",");
 | |
|             strSql.Append("'" + BasicDictionaryObj.HelpCode + "',");
 | |
|             strSql.Append("" + BasicDictionaryObj.Order + ",");
 | |
|             strSql.Append("" + BasicDictionaryObj.IsValid + ",");
 | |
|             strSql.Append("'" + BasicDictionaryObj.OperatorNo + "',");
 | |
|             strSql.Append("'" + BasicDictionaryObj.OperatorName + "',");
 | |
|             strSql.Append("'" + BasicDictionaryObj.OperateDate + "',");
 | |
|             strSql.Append("'" + BasicDictionaryObj.Remark + "'");
 | |
|             strSql.Append(")");
 | |
|             HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString());
 | |
|         }
 | |
|          
 | |
|         public static BasicDictionary GetModel(int Id)
 | |
|         {
 | |
|             BasicDictionary BasicDictionaryObj = new BasicDictionary();
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select  ");
 | |
|             strSql.Append("Id,Name,ParentId,HelpCode,[Order],IsValid,OperatorNo,OperatorName,OperateDate,Remark ");
 | |
|             strSql.Append(" from BasicDictionary ");
 | |
|             strSql.Append(" where Id=" + Id + "");
 | |
|             DataSet ds = HelperDB.DbHelperSQL.GetDataSet(strSql.ToString());
 | |
|             if (ds.Tables[0].Rows.Count > 0)
 | |
|             {
 | |
|                 if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Name = ds.Tables[0].Rows[0]["Name"].ToString();
 | |
|                 if (ds.Tables[0].Rows[0]["ParentId"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.ParentId = int.Parse(ds.Tables[0].Rows[0]["ParentId"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.HelpCode = ds.Tables[0].Rows[0]["HelpCode"].ToString();
 | |
|                 if (ds.Tables[0].Rows[0]["Order"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Order = int.Parse(ds.Tables[0].Rows[0]["Order"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["IsValid"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.IsValid = int.Parse(ds.Tables[0].Rows[0]["IsValid"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.OperatorNo = ds.Tables[0].Rows[0]["OperatorNo"].ToString();
 | |
|                 BasicDictionaryObj.OperatorName = ds.Tables[0].Rows[0]["OperatorName"].ToString();
 | |
|                 if (ds.Tables[0].Rows[0]["OperateDate"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.OperateDate = DateTime.Parse(ds.Tables[0].Rows[0]["OperateDate"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
 | |
| 
 | |
|                 BasicDictionaryObj.Children = GetChildren(BasicDictionaryObj);
 | |
|             }
 | |
|             return BasicDictionaryObj;
 | |
|         }
 | |
| 
 | |
| 
 | |
|         public static List<BasicDictionary> GetChildren(BasicDictionary BasicDictionary)
 | |
|         {
 | |
|             List<BasicDictionary> children = new List<BasicDictionary>();
 | |
| 
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select  ");
 | |
|             strSql.Append("Id,Name,ParentId,HelpCode,[Order],IsValid,OperatorNo,OperatorName,OperateDate,Remark ");
 | |
|             strSql.Append(" from BasicDictionary ");
 | |
|             strSql.Append(" where ParentId=" + BasicDictionary.Id + " order by [Order]");
 | |
| 
 | |
|             DataTable dt =  HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|             for (int i = 0; i < dt.Rows.Count; i++)
 | |
|             {
 | |
|                 BasicDictionary BasicDictionaryObj = new BasicDictionary();
 | |
| 
 | |
|                 if (dt.Rows[i]["Id"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Id = int.Parse(dt.Rows[i]["Id"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Name = dt.Rows[i]["Name"].ToString();
 | |
|                 if (dt.Rows[i]["ParentId"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.ParentId = int.Parse(dt.Rows[i]["ParentId"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.HelpCode = dt.Rows[i]["HelpCode"].ToString();
 | |
|                 if (dt.Rows[i]["Order"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Order = int.Parse(dt.Rows[i]["Order"].ToString());
 | |
|                 }
 | |
|                 if (dt.Rows[i]["IsValid"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.IsValid = int.Parse(dt.Rows[i]["IsValid"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.OperatorNo = dt.Rows[i]["OperatorNo"].ToString();
 | |
|                 BasicDictionaryObj.OperatorName = dt.Rows[i]["OperatorName"].ToString();
 | |
|                 if (dt.Rows[i]["OperateDate"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.OperateDate = DateTime.Parse(dt.Rows[i]["OperateDate"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Remark = dt.Rows[i]["Remark"].ToString();
 | |
| 
 | |
|                 children.Add(BasicDictionaryObj);
 | |
|                 BasicDictionaryObj.Children = GetChildren(BasicDictionaryObj);
 | |
|             }
 | |
|             return children;
 | |
|         }
 | |
| 
 | |
| 
 | |
|         public static List<BasicDictionary> GetModelList(int ParentId)
 | |
|         {
 | |
|             List<BasicDictionary> BasicDictionaryListObj = new List<BasicDictionary>();
 | |
| 
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select  ");
 | |
|             strSql.Append("Id,Name,ParentId,HelpCode,[Order],IsValid,OperatorNo,OperatorName,OperateDate,Remark ");
 | |
|             strSql.Append(" from BasicDictionary ");
 | |
|             strSql.Append(" where ParentId=" + ParentId + " order by [Order]");
 | |
| 
 | |
|             DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
| 
 | |
|             for (int i = 0; i < dt.Rows.Count; i++)
 | |
|             {
 | |
|                 BasicDictionary BasicDictionaryObj = new BasicDictionary();
 | |
| 
 | |
|                 if (dt.Rows[i]["Id"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Id = int.Parse(dt.Rows[i]["Id"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Name = dt.Rows[i]["Name"].ToString();
 | |
|                 if (dt.Rows[i]["ParentId"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.ParentId = int.Parse(dt.Rows[i]["ParentId"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.HelpCode = dt.Rows[i]["HelpCode"].ToString();
 | |
|                 if (dt.Rows[i]["Order"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Order = int.Parse(dt.Rows[i]["Order"].ToString());
 | |
|                 }
 | |
|                 if (dt.Rows[i]["IsValid"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.IsValid = int.Parse(dt.Rows[i]["IsValid"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.OperatorNo = dt.Rows[i]["OperatorNo"].ToString();
 | |
|                 BasicDictionaryObj.OperatorName = dt.Rows[i]["OperatorName"].ToString();
 | |
|                 if (dt.Rows[i]["OperateDate"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.OperateDate = DateTime.Parse(dt.Rows[i]["OperateDate"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Remark = dt.Rows[i]["Remark"].ToString();
 | |
|                 BasicDictionaryListObj.Add(BasicDictionaryObj);
 | |
|             }
 | |
|             return BasicDictionaryListObj;
 | |
|         }
 | |
| 
 | |
|         public static List<BasicDictionary> GetModelParentList()
 | |
|         {
 | |
|             List<BasicDictionary> BasicDictionaryListObj = new List<BasicDictionary>();
 | |
| 
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select  ");
 | |
|             strSql.Append("Id,Name,ParentId,HelpCode,[Order],IsValid,OperatorNo,OperatorName,OperateDate,Remark ");
 | |
|             strSql.Append(" from BasicDictionary where ParentId=0");
 | |
| 
 | |
|             DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
| 
 | |
|             for (int i = 0; i < dt.Rows.Count; i++)
 | |
|             {
 | |
|                 BasicDictionary BasicDictionaryObj = new BasicDictionary();
 | |
| 
 | |
|                 if (dt.Rows[i]["Id"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Id = int.Parse(dt.Rows[i]["Id"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Name = dt.Rows[i]["Name"].ToString();
 | |
|                 if (dt.Rows[i]["ParentId"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.ParentId = int.Parse(dt.Rows[i]["ParentId"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.HelpCode = dt.Rows[i]["HelpCode"].ToString();
 | |
|                 if (dt.Rows[i]["Order"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.Order = int.Parse(dt.Rows[i]["Order"].ToString());
 | |
|                 }
 | |
|                 if (dt.Rows[i]["IsValid"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.IsValid = int.Parse(dt.Rows[i]["IsValid"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.OperatorNo = dt.Rows[i]["OperatorNo"].ToString();
 | |
|                 BasicDictionaryObj.OperatorName = dt.Rows[i]["OperatorName"].ToString();
 | |
|                 if (dt.Rows[i]["OperateDate"].ToString() != "")
 | |
|                 {
 | |
|                     BasicDictionaryObj.OperateDate = DateTime.Parse(dt.Rows[i]["OperateDate"].ToString());
 | |
|                 }
 | |
|                 BasicDictionaryObj.Remark = dt.Rows[i]["Remark"].ToString();
 | |
|                 BasicDictionaryListObj.Add(BasicDictionaryObj);
 | |
|             }
 | |
|             return BasicDictionaryListObj;
 | |
|         }
 | |
| 
 | |
|         public static   DataTable GetDataDictionaryDataTable(int ParentId)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select [Id],[Name],[ParentId],[HelpCode],[Order],CASE IsValid WHEN  1 THEN '有效' WHEN 0 THEN '无效'  END AS  IsValid,[Remark] ");
 | |
|             strSql.Append(" FROM BasicDictionary WHERE Id=" + ParentId + "");
 | |
| 
 | |
|             strSql.Append("UNION ALL ");
 | |
| 
 | |
| 
 | |
|             strSql.Append("select [Id],[Name],[ParentId],[HelpCode],[Order],CASE IsValid WHEN  1 THEN '有效' WHEN 0 THEN '无效'  END AS  IsValid,[Remark] ");
 | |
|             strSql.Append(" FROM BasicDictionary WHERE ParentId=" + ParentId + " order by [Order]");
 | |
| 
 | |
|             return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static DataTable GetDataDictionaryDataTable(string strWhere)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select [Id],[Name],[ParentId],[HelpCode],[Order],CASE IsValid WHEN  1 THEN '有效' WHEN 0 THEN '无效'  END AS  IsValid,[Remark] ");
 | |
|             strSql.Append(" FROM BasicDictionary ");
 | |
|             if (strWhere.Trim() != "")
 | |
|             {
 | |
|                 strSql.Append(" where " + strWhere);
 | |
|             }
 | |
|             return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static DataTable GetDataDictionaryDataTableByParentName(string ParentName, string HelpCode)
 | |
|         {
 | |
|             string strSql = "SELECT bd.Id, bd.Name FROM BasicDictionary bd WHERE bd.IsValid=1 and ParentId IN  " +
 | |
|                    "(SELECT Id FROM BasicDictionary WHERE NAME='" + ParentName + "')   AND (bd.Name LIKE '%" + HelpCode + "%' OR bd.HelpCode LIKE '%" + HelpCode + "%') ORDER BY bd.[Order]";
 | |
|             return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static DataTable GetDataDictionaryNameAndRemark(string ParentName, string HelpCode)
 | |
|         {
 | |
|             string strSql = "SELECT  bd.Id, CASE  bd.Remark WHEN ''  THEN  bd.NAME ELSE  bd.NAME+ '-' + bd.Remark END  AS NAME FROM BasicDictionary bd WHERE bd.IsValid=1 and ParentId IN  " +
 | |
|                    "(SELECT Id FROM BasicDictionary WHERE NAME='" + ParentName + "')   AND (bd.Name LIKE '%" + HelpCode + "%' OR bd.HelpCode LIKE '%" + HelpCode + "%') ORDER BY bd.[Order]";
 | |
|             return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|     }
 | |
| }
 |