C# - Lee 公共类库

我的公共类库

using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using CY.CommonLibrary.Common;

namespace Lee
{
    public class Common
    {
        public static string ServerIPAndPort = System.Configuration.ConfigurationManager.AppSettings["ServerIPAndPort"];

        public static string Md5Key = System.Configuration.ConfigurationManager.AppSettings["Md5Key"];

        public static string Test_Swich = System.Configuration.ConfigurationManager.AppSettings["Test_Swich"]; //只要不为空,都为测试模式

        /// <summary>
        /// 是否处于测试模式.只要不为空,都为测试模式
        /// </summary>
        /// <returns>布尔值</returns>
        public static bool Is_测试模式()
        #region
        {
            if (Test_Swich != "")
            {
                return true;
            }
            return false;
        }

        #endregion

        /// <summary>
        /// send_发送POST请求
        /// </summary>
        /// <param name="vServerPage"></param>
        /// <param name="vPostData"></param>
        /// <returns></returns>
        public static string send_发送POST请求(string vServerPage, string vPostData)
        #region
        {
            byte[] dataArray = Encoding.UTF8.GetBytes(vPostData);
            //创建请求
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(vServerPage);
            request.Method = "POST";
            request.ContentLength = dataArray.Length;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Timeout = 5000;
            //创建输入流
            Stream dataStream = null;
            try
            {
                dataStream = request.GetRequestStream();
            }
            catch (Exception)
            {
                return null;//连接服务器失败
            }

            //发送请求
            dataStream.Write(dataArray, 0, dataArray.Length);
            dataStream.Close();
            //读取返回消息
            string res = string.Empty;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
                reader.Close();
            }
            catch (Exception ex)
            {
                return null;//连接服务器失败
            }
            return res;
        }

        #endregion

        /// <summary>
        /// send_发送Get请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string send_发送GET请求(string url)
        #region
        {
            string str = "";

            HttpWebRequest hwr = WebRequest.Create(url) as HttpWebRequest;

            hwr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            hwr.Method = "GET";
            hwr.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:34.0) Gecko/20100101 Firefox/34.0";
            hwr.ContentType = "application/x-www-form-urlencoded";
            hwr.Headers["Accept-Language"] = "zh-cn";
            hwr.Timeout = 3000;

            try
            {
                HttpWebResponse _rep = hwr.GetResponse() as HttpWebResponse;
                Stream _stream = _rep.GetResponseStream();
                StreamReader read = new StreamReader(_stream, Encoding.UTF8);

                str = read.ReadToEnd();
                _rep.Close();
            }
            catch (Exception ex)
            {
                log.WriteLog("商学院数据获取超时? :" + ex.Message + "请求地址为:" + url);
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>数据超时..</p></div>");
                HttpContext.Current.Response.End();
            }
            return str;
        }

        #endregion

        /// <summary>
        /// 发送一张笑脸
        /// </summary>
        public static void send_smiling_face(string str)
        #region
        {
            HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:)</h1><p>" + str + "</p></div>");
        }

        #endregion

        /// <summary>
        /// 发送一张哭脸
        /// </summary>
        /// <param name="str"></param>
        public static void send_unhappy_face(string str)
        #region
        {
            HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>" + str + "</p></div>");
        }

        #endregion

        /// <summary>
        /// 维护中
        /// </summary>
        public static void Send_repair()
        #region
        {
            if (HttpContext.Current.Session["Current_Shop_Id"].ToNotNullString() != "6634")
            {
                send_smiling_face("维修中...");
            }
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "')</script>");
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert_back(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "');history.back();</script>");
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert_href(object obj, string url)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "');window.location.href='" + url + "';</script>");
        }

        #endregion

        /// <summary>
        /// 在控制台打印出数据
        /// </summary>
        /// <param name="obj"></param>
        public static void log_Console(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script>console.log(\"" + obj + "\")</script>");
        }

        #endregion

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="obj"></param>
        public static void print(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString());
        }

        #endregion

        /// <summary>
        /// 输出,不换行,使用完直接结束
        /// </summary>
        /// <param name="obj"></param>
        public static void echo(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString());
        }

        #endregion

        /// <summary>
        /// 打印,带换行
        /// </summary>
        /// <param name="obj"></param>
        public static void println(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString() + "<br />");
        }

        #endregion

        /// <summary>
        /// 结束网页输出
        /// </summary>
        public static void End()
        #region
        {
            HttpContext.Current.Response.End();
        }

        #endregion

        /// <summary>
        /// 清除网页输出
        /// </summary>
        public static void Clear()
        #region
        {
            HttpContext.Current.Response.Clear();
        }

        #endregion

        /// <summary>
        /// ASE_128_ECB_无填充_64Base_加密函数
        /// </summary>
        /// <param name="content">要加密的内容</param>
        /// <param name="key">一定要16位的密钥</param>
        /// <returns>加密的字符串(字节)</returns>
        public static byte[] Func_AES128加密(string content, string key)
        #region
        {
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(content);

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            //返回字节数组,可用Convert.FromBase64String()转换为字节
            //return Convert.ToBase64String(resultArray, 0, resultArray.Length);

            return resultArray;
        }
        #endregion


        /// <summary>
        ///  ASE_128_ECB_无填充_64Base_解密函数
        /// </summary>
        /// <param name="content">密串(字节)</param>
        /// <param name="keyArray">密钥(字节)</param>
        /// <returns>解密后的字符串</returns>
        public static byte[] Func_AES128解密(byte[] content, byte[] keyArray)
        #region
        {
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.None;
            rDel.BlockSize = 128;

            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(content, 0, content.Length);

            return resultArray;
        }

        #endregion

    }
}

 

类很多,不写全了。。下载下来好好看 ----------Database-------------- 1.DataTable帮助类(DataTableHelper.cs) 2.Access数据库文件操作辅助类(JetAccessUtil.cs) 5.查询条件组合辅助类(SearchCondition.cs) 6.查询信息实体类(SearchInfo.cs) 8.Sql命令操作函数(可用于安装程序的时候数据库脚本执行)(SqlScriptHelper.cs) ----------Device-------------- 声音播放辅助类(AudioHelper.cs) 摄像头操作辅助类,包括开启、关闭、抓图、设置等功能(Camera.cs) 提供用于操作【剪切板】的方法(ClipboardHelper.cs) 获取电脑信息(Computer.cs) 提供用户硬件唯一信息的辅助类(FingerprintHelper.cs) 读取指定盘符的硬盘序列号(HardwareInfoHelper.cs) 提供访问键盘当前状态的属性(KeyboardHelper.cs) 全局键盘钩子。这可以用来在全球范围内捕捉键盘输入。(KeyboardHook.cs) 模拟鼠标点击(MouseHelper.cs) 全局鼠标钩子。这可以用来在全球范围内捕获鼠标输入。(MouseHook.cs) MP3文件播放操作辅助类(MP3Helper.cs) 关联文件(ExtensionAttachUtil.cs) 注册文件关联的辅助类(FileAssociationsHelper.cs) 打开、保存文件对话框操作辅助类(FileDialogHelper.cs) 常用的文件操作辅助类FileUtil(FileUtil.cs) INI文件操作辅助类(INIFileUtil.cs) 独立存储操作辅助类(IsolatedStorageHelper.cs) 序列号操作辅助类(Serializer.cs) 获取一个对象,它提供用于访问经常引用的目录的属性。(SpecialDirectories.cs) 简单的Word操作对象(WordCombineUtil.cs) 这个类提供了一些实用的方法来转换XML和对象。(XmlConvertor.cs) XML操作类(XmlHelper.cs) ----------Format-------------- 参数验证的通用验证程序。(ArgumentValidation.cs) 这个类提供了实用方法的字节数组和图像之间的转换。(ByteImageConvertor.cs) byte字节数组操作辅助类(BytesTools.cs) 处理数据类型转换,数制转换、编码转换相关的类(ConvertHelper.cs) CRC校验辅助类(CRCUtils.cs) 枚举操作公共类(EnumHelper.cs) 身份证操作辅助类(IDCardHelper.cs) 检测字符编码的类(IdentifyEncoding.cs) RGB颜色操作辅助类(MyColors.cs) 日期操作类(MyDateTime.cs) 转换人民币大小金额辅助类(RMBUtil.cs) 常用的字符串常量(StringConstants.cs) 简要说明TextHelper。(StringUtil.cs) 获取中文字首字拼写,随机发生器,按指定概率随机执行操作(Util.cs) 各种输入格式验证辅助类(ValidateUtil.cs) ----------Network-------------- Cookie操作辅助类(CookieManger.cs) FTP操作辅助类(FTPHelper.cs) HTML操作类(HttpHelper.cs) 网页抓取帮助(HttpWebRequestHelper.cs) Net(NetworkUtil.cs) IE代理设置辅助类(ProxyHelper.cs) ----------Winform-------------- 跨线程的控件安全访问方式(CallCtrlWithThreadSafety.cs) CheckBoxList(CheckBoxListUtil.cs) 窗口管理类(ChildWinManagement.cs) 由马丁·米勒http://msdn.microsoft.com/en-us/library/ms996492.aspx提供一个简单的方法打印工作的一个RichTextBox一个帮手(ExRichTextBoxPrintHelper.cs) 显示,隐藏或关闭动画形式。(FormAnimator.cs) 对窗体进行冻结、解冻操作辅助类(FreezeWindowUtil.cs) 窗体全屏操作辅助类(FullScreenHelper.cs) GDI操作辅助类(GDI.cs) 提供静态方法来读取这两个文件夹和文件的系统图标。(IconReaderHelper.cs) 图片对象比较、缩放、缩略图、水印、压缩、转换、编码等操作辅助类(ImageHelper.cs) 输入法帮助,全角 转换为半角(ImeHelper.cs) Winform提示框 的摘要说明。(MessageUtil.cs) 包含互操作方法调用的应用程序中使用。(NativeMethods.cs) 托盘图标辅助类(NotifyIconHelper.cs) 打印机类(POSPrinter.cs) 图片、光标、图标、位图等资源操作辅助类(ResourceHelper.cs) RTF字符格式辅助类(RTFUtility.cs) 串口开发辅助类(SerialPortUtil.cs) 设置文本属性提供一个ToolStripStatusLabel(SafeToolStripLabel.cs) 只运行一个实例及系统自动启动辅助类(StartupHelper.cs) Web页面预览效果图片抓取辅助类(WebPageCapture.cs) 供Asp.Net直接调用的包装类(WebPreview.cs) 计算机重启、关电源、注销、关闭显示器辅助类(WindowsExitHelper.cs) 简单写了点,还有很多,希望能对大家有帮助 ================================================================================================ 本资料共包含以下附件: WHC.OrderWater.Commons.rar 公共类文档.docx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值