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

📄 common.cs

📁 某个公司需要维持良好的客户关系
💻 CS
字号:
using System;
using System.Data;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using CRM.Model;
namespace CRM.SQLServerDAL
{
	/// <summary>
	/// Common 的摘要说明。
	/// </summary>
	public class Common
	{	
		#region 加解密字符串
		/// <summary>
		/// 加解密字符串
		/// </summary>
		/// <param name="String">字符串</param>
		/// <returns></returns>
		public  static  string Encrypt(string str)
		{
			Byte[] clearBytes = new UnicodeEncoding().GetBytes(str);
			Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
			
			return BitConverter.ToString(hashedBytes);
		}
		#endregion

		#region 获得指定表中下一个ID值
		/// <summary>
		///  获得指定表中下一个ID值
		/// </summary>
		/// <param name="table">表名</param>
		/// <param name="type">类型(MulLayer--多层结构)(SingleLayer--单层结构)</param>
		/// <param name="prefix">字符串前缀</param>
		/// <param name="len">变动ID长度</param>
		/// <returns></returns>
		public  static  string GetNextIdByTable(string TableName,string id,string type,string prefix,int len)
		{//取记录集中满足 {当前字符串长度 < 字段长度(除去空格) < (当前字符串长度+步长) 的最后一条记录
			DataTable table = new DataTable();
			//prefix.Trim();
			if(type == "MulLayer")
			{//多层结构的ID求法
				switch (TableName)
				{
					case "CustomerTypeInfo":
					{
						table =new CustomerType().GetAllType();
						break;
					}
				}
				return CreatNextId(table,id,"MulLayer",prefix,len);
			}
			if (type == "SingleLayer")
			{
				switch (TableName)
				{
					case "SysLog":
					{
						table = new SysLog().GetAllSysLog();
						break;
					}
					case "SysUserInfo":
					{
						table = new SysUser().GetAllSysUser();
						break;
					}
					case "CustomerInfo":
					{
						table = new Customer().GetAllCustomer();
						break;
					}
					case "DeputyInfo":
					{
						 table = new Deputy().GetAllDeputy();
						 break;
					}
					case "OrderInfo":
					{
						table = new Order().GetAllOrder();
						break;
					}
					case "BargainInfo":
					{
						table = new Bargain().GetAllBargain();
						break;
					}

				}
				return CreatNextId(table,id,"SingleLayer",prefix,len);
			}
			return "";
		}
		
	
		public static string CreatNextId(DataTable table,string id,string type,string prefix,int len)
		{
			string nextid;
			int temp;
			DataRow[] funcRows=null;
			if (type == "MulLayer")
			{
				if (prefix == null || prefix == string.Empty)//根
				{funcRows = table.Select(String.Format("len(trim({0}))={1}",id,len),id+" asc");}
				else
				{	funcRows = table.Select(String.Format("{0} like '{1}%' and len(trim({0}))< {2} and len(trim({0})) > {3}",id,prefix,prefix.Length+len+1,prefix.Length),id+" asc");}
			}
			if (type == "SingleLayer")
			{
				funcRows = table.Select("len("+id+")>0",id+" asc");
			}
			if (funcRows.Length > 0)
			{
				if (prefix == null || prefix == string.Empty)//根
				{ nextid = Convert.ToString(int.Parse(funcRows[funcRows.Length-1].ItemArray[0].ToString().Substring(0,len))+1);}
				else
				{ nextid = Convert.ToString(int.Parse(funcRows[funcRows.Length-1].ItemArray[0].ToString().Substring(prefix.Length,len))+1);}
			}
			else
			{
				nextid = "1";
			}
			temp = nextid.Trim().Length;
			//填充0
			for (int i=1; i<= len-temp;i++)
			{
				nextid = "0"+nextid;
			}
			return prefix+nextid;
		}
		#endregion
	}
}

⌨️ 快捷键说明

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