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

📄 dbclass.cs

📁 这是个短信群发的程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
	        ctime = ctime.Replace("FM", "");
	        return ctime;
	    }
	    public bool SaveWWWPicture(string filename, System.Drawing.Imaging.ImageFormat picformat, string url)
	    {
	        try
	        {
	            HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(url.Trim().ToString());
	            WebResponse ws = hwr.GetResponse();
	            Stream st = ws.GetResponseStream();
	            Bitmap bt = new Bitmap(st);
	            bt.Save(filename, picformat);
	            bt.Dispose();
	            st.Close();
	            ws.Close();

	        }
	        catch 
	        {

	            return false;

	        }
	        return true;
	    }
	}

	//对字符串操作
	public class NString
	{
		//[DllImport("KERNEL32.DLL", EntryPoint="RtlZeroMemory")]
		//public static extern bool ZeroMemory(IntPtr Destination, int Length);

		// private string sqlstr;

		public static string MessageBox(string message)
		{
			string js = "<script language=\"javascript\">";
			js += "alert(\"";
			js += message;
			js += "\")</script>";
			return js;

		}

		/// <summary>
		/// 转换小数点后N位
		/// </summary>
		/// <param name="number">被转换的数字</param>
		/// <param name="length">保留小数点几位</param>
		/// <returns></returns>
		public static string StringFormat(string number, int length)
		{
			string zero = "";
			for (int i = 0; i < length; i++)
			{
				zero += "0";
			}
			string ret = number.ToString().Trim();
			int del_pos = ret.IndexOf(".");
			int del_len = ret.Length;
			string temp = "";
			string leftstr = "";
			if (del_pos == -1)
			{
				ret = ret + "." + zero;
				return ret;
			}
			leftstr = ret.Substring(0, del_pos);
			temp = ret.Substring(del_pos + 1, del_len - del_pos - 1);
			if (temp.Length == length)
			{
				return ret;
			}
			if (temp.Length < length)
			{
				zero = "";
				for (int i = 0; i < length - temp.Length; i++)
				{
					zero += "0";
				}
				ret = leftstr + "." + temp + zero;
				return ret;
			}
			if (temp.Length > length)
			{
				temp = temp.Substring(0, length);
				ret = leftstr + "." + temp;
				return ret;
			}
			return ret;
		}

		public static string CutAndSql(string sql)
		{
			string reu = sql.ToString().Trim();
			string reuU = sql.ToString().Trim().ToUpper();
			int a1 = reuU.IndexOf("WHERE");
			if (a1 != -1)
			{
				string b1 = reu.Substring(0, a1 + 5);
				string b2 = reuU.Substring(a1 + 5);
				b2 = b2.Trim();
				if (b2.IndexOf("AND") == 0)
				{
					string s2 = b2.Substring(3);
					reu = b1 + s2;
				}

			}
			return reu;
		}
		public static string DelSqlChar(string sql)
		{
			string result = sql.ToString().Trim();
			result = result.Replace("\'", "");
			result = result.Replace("\"", "");
			result = result.Replace(";", "");
			result = result.Replace("-", "");
			result = result.Replace("==", "");

			return result;
		}
		public static string CutIp(string ip)
		{

			string reu = "";
			string rip = ip.ToString().Trim();
			int begin = rip.LastIndexOf(".");
			if (begin != -1)
			{
				reu = rip.Substring(0, begin + 1);
				reu += "*";
			}
			else
			{
				reu = "未知";
			}
			return reu;
		}

		public static string ReturnHtml(string html)
		{
			string reu = html.ToString().Trim();
			reu = reu.Replace("\r\n", "<br>");
			reu = reu.Replace("\t", "&nbsp;");
			return reu;
		}
		public static string GetStringFromTime(string time)
		{
			string ctime = time.ToString().Trim();
			try
			{
				ctime = ctime.Replace(":", "");
				ctime = ctime.Replace("-", "");
				ctime = ctime.Replace(" ", "");
				ctime = ctime.Replace("AM", "");
				ctime = ctime.Replace("FM", "");
			}
			catch
			{
				ctime = "";
			}
			return ctime;

		}

		public static string DESGenerateKey()
		{
			DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();
			return ASCIIEncoding.ASCII.GetString(desCrypto.Key);

		}
		//sKey长度为64BIT,8个ASCII码
		public static string DESDecodeString(string sInputString, string sKey)
		{
            if (sInputString.Trim().Length <= 0)
            {
                return "";
            }
			string[] sInput = sInputString.Split("-".ToCharArray());
			byte[] data = new byte[sInput.Length];
			byte[] result;
			//string temp="";
			for (int i = 0; i < sInput.Length; i++)
			{
				data[i] = byte.Parse(sInput[i], System.Globalization.NumberStyles.HexNumber);
				//temp += sInput[i]+"<br>";
			}
			//return temp;
			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
			DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
			DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
			ICryptoTransform desencrypt = DES.CreateDecryptor();
			result = desencrypt.TransformFinalBlock(data, 0, data.Length);
			return Encoding.Default.GetString(result);
		}

		public static void DESDecryptFile(string sInputFilename, string sOutputFilename, string sKey)
		{
			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
			DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
			DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

			FileStream fsread = new FileStream(sInputFilename,
				FileMode.Open,
				FileAccess.Read);
			ICryptoTransform desdecrypt = DES.CreateDecryptor();
			CryptoStream cryptostreamDecr = new CryptoStream(fsread,
				desdecrypt,
				CryptoStreamMode.Read);
			StreamWriter fsDecrypted = new StreamWriter(sOutputFilename);
			fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
			fsDecrypted.Flush();
			fsDecrypted.Close();
		}


		public static void DESEncryptFile(string sInputFilename, string sOutFilename, string sKey)
		{
			FileStream fsInput = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read);
			FileStream fsEncrypted = new FileStream(sOutFilename, FileMode.Create, FileAccess.Write);
			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
			DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
			DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
			ICryptoTransform desencrypt = DES.CreateEncryptor();
			CryptoStream cryptostream = new CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write);
			byte[] bytearrayinput = new byte[fsInput.Length];
			fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
			cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);
			cryptostream.Close();
			fsInput.Close();
			fsEncrypted.Close();

		}

		//sKey长度为64BIT,8个ASCII码
		public static string DESEncodeString(string sInputString, string sKey)
		{
			byte[] data = Encoding.Default.GetBytes(sInputString);
			byte[] result;
			DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
			DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
			DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
			ICryptoTransform desencrypt = DES.CreateEncryptor();
			result = desencrypt.TransformFinalBlock(data, 0, data.Length);
			//string desString = "";
			/*for(int i=0;i<result.Length;i++)
			{
				desString+=result[i].ToString() + "-";
			}*/
			return BitConverter.ToString(result);

		}

		public static string MD5(string s_encode)
		{
			MD5 md5 = new MD5CryptoServiceProvider();
			byte[] data = System.Text.Encoding.Default.GetBytes(s_encode);
			byte[] result = md5.ComputeHash(data);
			string ret = "";
			for (int i = 0; i < result.Length; i++)
			{
				ret += result[i].ToString("x").PadLeft(2, '0');
			}
			return ret;

		}

		public static string SHA1(string Sha1String)
		{
			/*SHA1Managed hash_sha1 = new SHA1Managed();
			byte[] ByteIn = UTF8Encoding.UTF8.GetBytes(sha1);
			byte[] ByteOut = hash_sha1.ComputeHash(ByteIn);
			return Convert.ToBase64String(ByteOut);*/
			SHA1 sha1 = new SHA1CryptoServiceProvider();
			byte[] data = System.Text.Encoding.Default.GetBytes(Sha1String);
			byte[] result = sha1.ComputeHash(data);
			string ret = "";
			for (int i = 0; i < result.Length; i++)
			{
				ret += result[i].ToString("x").PadLeft(2, '0');
			}
			//return ret;
			return ret;

		}
		public static bool Check_Name(string str)
		{
			if (str.Length <= 0)
			{
				return true;
			}
			try
			{
				string temp = "";
				string in_str = "!@#$%^&*()_+|:\"?>,./[]{}-=\\<";
				if (str != null && str.Length >= 1)
				{
					for (int i = 0; i < str.Length; i++)
					{
						temp = str.Substring(i, 1);
						if (in_str.IndexOf(temp.ToUpper().Trim()) != -1)
						{
							return false;
						}
					}
				}
				else
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;

		}
        public static bool ChcekStr(string source, string template)
        {
            if (source.Trim().Length <= 0 || template.Trim().Length<=0)
            {
                return false;
            }

            try
            {
                string str = source.ToString().Trim();
                string temp = "";
                string in_str = template.Trim();
                if (str != null && str.Length >= 1)
                {
                    for (int i = 0; i < str.Length; i++)
                    {
                        temp = str.Substring(i, 1);
                        if (in_str.IndexOf(temp.ToUpper().Trim()) == -1)
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
            return true;

        }

		public static bool Check_QQ(string str)
		{
			if (str.Length <= 0)
			{
				return true;
			}
			try
			{
				string temp = "";
				string in_str = "0123456789";
				if (str != null && str.Length >= 1)
				{
					for (int i = 0; i < str.Length; i++)
					{
						temp = str.Substring(i, 1);
						if (in_str.IndexOf(temp.ToUpper().Trim()) == -1)
						{
							return false;
						}
					}
				}
				else
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;

		}

		public static bool Check_Tell(string str)
		{
			if (str.Length <= 0)
			{
				return true;
			}
			try
			{
				string temp = "";
				string in_str = "0123456789-()";
				if (str != null && str.Length >= 1)
				{
					for (int i = 0; i < str.Length; i++)
					{
						temp = str.Substring(i, 1);
						if (in_str.IndexOf(temp.ToUpper().Trim()) == -1)
						{
							return false;
						}
					}
				}
				else
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;

		}

		public static bool CheckValidateString(string sql)
		{
			if (sql.Length <= 0)
			{
				return true;
			}
            string shield_str = System.Configuration.ConfigurationManager.AppSettings["ValidateString"].ToString().Trim();
			string[] s_list = shield_str.Split('|');
			for (int i = 0; i < s_list.Length; i++)
			{
				if (sql.Trim().IndexOf(s_list[i].ToLower().ToString().Trim()) != -1)
				{
					return false;
				}
			}
			return true;
		}
		public static bool Check_Email(string str)
		{
			if (str.Length <= 0)
			{
				return true;
			}
			string temp = "";
			string in_str = "QWERTYUIOPLKJHGFDSAZXCVBNM123456790_@.";
			if (str != null && str.Length >= 1)
			{
				for (int i = 0; i < str.Length; i++)
				{
					temp = str.Substring(i, 1);
					if (in_str.IndexOf(temp.ToUpper().Trim()) == -1)
					{
						return false;
					}
				}
			}
			else
			{
				return false;
			}
			return true;

		}
		public static bool CheckEandNum(string str)
		{
			if (str.Length <= 0)
			{
				return true;
			}
			string temp = "";
			string in_str = "QWERTYUIOPLKJHGFDSAZXCVBNM123456790_";
			if (str != null && str.Length >= 1)
			{
				for (int i = 0; i < str.Length; i++)
				{
					temp = str.Substring(i, 1);
					if (in_str.IndexOf(temp.ToUpper().Trim()) == -1)
					{
						return false;
					}
				}
			}
			else
			{
				return false;
			}
			return true;
		}

		public static bool IsValidateSql(string sql)
		{
			string sqlstr = sql.ToString().Trim().ToUpper();
			if (sqlstr.IndexOf(";") > -1)
			{
				return false;
			}
			if (sqlstr.IndexOf("\'") > -1)
			{
				return false;
			}
			/*if(sqlstr.IndexOf("-")>-1)
			{
				return false;
			}*/
			/*if(sqlstr.IndexOf("%")>-1)
			{
				return false;
			}*/
			if (sqlstr.IndexOf("\"") > -1)
			{
				return false;
			}
			if (sqlstr.IndexOf("!=") > -1)
			{
				return false;
			}
			/*if(sqlstr.IndexOf("INSERT")>-1)
			{
				return false;
			}
			if(sqlstr.IndexOf("UPDATE")>-1)
			{
				return false;
			}
			if(sqlstr.IndexOf("DELETE")>-1)
			{
				return false;
			}*/
			return true;

		}
	}
}

⌨️ 快捷键说明

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