120 lines
5.0 KiB
C#
120 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
|
|
namespace Lskj.Business.Impl
|
|
{
|
|
public class BaseSpecImpl : BaseImpl
|
|
{
|
|
/// <summary>
|
|
/// <para>说明:删除节点</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-04 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="tableName">Name of the table.</param>
|
|
/// <param name="key">The key.</param>
|
|
/// <param name="value">The value.</param>
|
|
/// <returns>System.Int32.</returns>
|
|
public static int DeleteNode(string tableName, string key, string value)
|
|
{
|
|
string sqlValue = string.Format("delete from {0} where {1}='{2}'", tableName, key, value);
|
|
|
|
return ExecSqlValue(sqlValue);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取子节点个数</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-04 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="tableName">Name of the table.</param>
|
|
/// <param name="key">The key.</param>
|
|
/// <param name="value">The value.</param>
|
|
/// <returns>System.Int32.</returns>
|
|
public static int GetNodeChildCount(string tableName,string key,string value)
|
|
{
|
|
string sqlValue = string.Format("select count(1) from {0} where {1} like '{2}%'", tableName, key, value);
|
|
return Convert.ToInt32(GetResult(sqlValue));
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取最大节点号</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-03 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="tableName">Name of the table.</param>
|
|
/// <param name="parentId">The parent identifier.</param>
|
|
/// <returns>System.String.</returns>
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|
public static string GetMaxSpeciesNo(string tableName, string parentKey, string parentValue,string firstNode)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(parentKey) || string.IsNullOrWhiteSpace(parentValue))
|
|
return "01";
|
|
string maxdivision = string.Empty;
|
|
string PrefixNum = string.Empty;
|
|
string maxNum = string.Empty;
|
|
for (int i = 0; i < firstNode.Length; i++)
|
|
{
|
|
maxdivision += "_";
|
|
if (i != 0) PrefixNum += "0";
|
|
maxNum += "9";
|
|
}
|
|
|
|
// SpeciesNo是层级编码,完整编码可能超过bigint范围,只对当前节点编号进行数值运算。
|
|
string sqlValue = string.Format("select max(cast(right({1},{4}) as bigint))+1 from {0} where {1} like '{2}{3}'", tableName, parentKey, parentValue, maxdivision, firstNode.Length);
|
|
string maxNo = GetResult(sqlValue) + "";
|
|
|
|
if (string.IsNullOrWhiteSpace(maxNo))
|
|
maxNo = parentValue + PrefixNum+"1";
|
|
else
|
|
maxNo = parentValue + maxNo.PadLeft(firstNode.Length, '0');
|
|
maxNo = maxNo.PadLeft(parentValue.Length + firstNode.Length, '0');
|
|
|
|
if ((PrefixNum + "0").Equals(maxNo.Substring(maxNo.Length - firstNode.Length)))
|
|
{
|
|
sqlValue = string.Format("select count(1) as cnt from {0} where {1} like '{2}{3}'", tableName, parentKey, parentValue, maxdivision);
|
|
|
|
if (GetResult(sqlValue) + "" == maxNum)
|
|
return maxNum;
|
|
|
|
// 取未使用的编号
|
|
sqlValue = string.Format("select cast(right({1},{4}) as bigint) as SpeciesNo from {0} where {1} like '{2}{3}' order by SpeciesNo", tableName, parentKey, parentValue,maxdivision, firstNode.Length);
|
|
DataTable table = GetDataTableResult(sqlValue);
|
|
|
|
Int64 speciesNo = table.Rows.Count > 0 ? Convert.ToInt64(table.Rows[0]["SpeciesNo"] + "") : 0;
|
|
if (speciesNo != 1)
|
|
return parentValue +PrefixNum+"1";;
|
|
|
|
foreach (DataRow item in table.Rows)
|
|
{
|
|
Int64 rowSpeciesNo = Convert.ToInt64(item["SpeciesNo"] + "");
|
|
if (speciesNo == rowSpeciesNo) continue;
|
|
|
|
if (rowSpeciesNo != speciesNo + 1)
|
|
{
|
|
maxNo = parentValue + (speciesNo + 1).ToString().PadLeft(firstNode.Length, '0');
|
|
|
|
break;
|
|
}
|
|
|
|
speciesNo = rowSpeciesNo;
|
|
}
|
|
}
|
|
|
|
return maxNo;
|
|
}
|
|
}
|
|
}
|