作为AD域服务器,使用静态IP地址,并且DNS地址与IP地址相同
07
2019
06
20
2018
09
VS2017 自带发布工具 ClickOnce发布包遇到的问题:系统必备”对话框中启用“从与我的应用程序相同的位置下载系统必备组件
一、遇到的问题
在安装了VS2017 社区版(Community)之后 想打包安装程序(winform) 还是想用之前的 installshield来打包 发现居然打不了,在官网查了 installshield不支持社区版(Community),后来尝试用vs自带的ClickOnce打包遇到以下问题:
01
2018
05
在Windows Server 2008 SP2 里的IIS 7.0 里添加 TLS 1.2 支持
开发小程序时需要网站使用https,除了正常使用https还需要添加 TLS 1.2 支持,而在阿里云下面购买的Windows Server 2008 SP2中,系统默认是不支持TLS 1.2,所以通过查找资料,找到解决方法,网络参考如下:
1. 默认IIS 7.0不支持TLS 1.2,检测访问地址:
https://cloud.tencent.com/product/ssl
07
2018
04
64位Windows 2008 R2系统下IIS6配置阿里云SSL免费证书
( 1 ) 证书导入
• 开始 -〉运行 -〉MMC;
• 启动控制台程序,选择菜单“文件"中的"添加/删除管理单元”-> “添加”,从“可用的独立管理单元”列表中选择“证书”-> 选择“计算机帐户”;
• 在控制台的左侧显示证书树形列表,选择“个人”->“证书”,右键单击,选择“所有任务"-〉"导入”, 根据"证书导入向导”的提示,导入PFX文件(此过程当中有一步非常重要: “根据证书内容自动选择存储区”)。安装过程当中需要输入密码为您当时设置的密码。导入成功后,可以看到如图所示的证书信息。
24
2016
10
文字生成语音,百度语音Api使用
http://yuyin.baidu.com/申请创建一个语音合成应用,“查看Key”获得ID、KEY、SECRRET_KEY
02
2016
09
C#、Asp.Net 对比两个实体信息前后是否有所改变(结构相同和不相同)
在一些项目中可能需要比较内容是否有所改变,可以使用对比的方法来判断是否内容有所改变(对比某个特定的字段,可以不是所有的都比较),下面是比较笨的方法:
public static string compareStr = "HouseName,HouseType,HouseNum,Status"; //需要对比的字段名
/// <summary>
/// 对比两个实体信息前后是否一致,需要通过compareStr来判断对比那些字段(实体结构不相同)
/// </summary>
/// <param name="oldair">老的乘客信息</param>
/// <param name="newair">新改的乘客信息</param>
/// <returns></returns>
public static int compareAirPassenger<T1, T2>(T1 oldair, T2 newair)
02
2016
09
C#、Asp.Net 将一个实体对象转换为另一个实体对象(结构可以不一样)
直接上调用方法,实体结构不一样的时候只会转换字段名相同的,代码如下:
/// <summary>
/// 将一个实体对象转换为另一个实体对象
/// </summary>
/// <typeparam name="T1">第一个实体对象</typeparam>
/// <typeparam name="T2">第二个实体对象</typeparam>
/// <param name="source">转换的实体对象</param>
/// <returns></returns>
public static T2 CopyToModel<T1, T2>(T1 source)
03
2016
04
MSSql删除数据库中所有表sql语句
MSSql删除数据库中所有表(只是表)sql语句:
declare @tname varchar(8000)
set @tname=''
select @tname=@tname + Name + ',' from sysobjects where xtype='U'
select @tname='drop table ' + left(@tname,len(@tname)-1)
03
2016
04
MSSql查询数据库中所有表的字段及说明sql语句
查询数据库中所有表的字段及说明
SELECT
表名 = case when a.colorder=1 then d.name else '' end,
表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,
16
2016
03
Asp.Net 常用时间计算
统计数据时候读取年月进行分组统计,计算两个日期之间的总天数,计算当前时间的当月的开始时间和结束时间,计算某月的天数,计算某年的天数
/// <summary>
/// 填充年份的下拉列表
/// </summary>
11
2015
07
C#字符串编码帮助类
/// <summary>
/// 字符串编码帮助类
/// </summary>
public class EncodingHelper
{
/// <summary>
/// 字符串编码转换
/// </summary>
/// <param name="srcEncoding">原编码</param>
/// <param name="dstEncoding">目标编码</param>
/// <param name="srcStr">原字符串</param>
/// <returns>字符串</returns>
25
2015
05
C#、Asp.Net XML节点增、删、改操作工具类
C#、Asp.Net中对XML文件进行操作,增、删、改XMl文件里面节点信息
public class XmlHelper
#region 增、删、改操作==============================================
/// <summary>
/// 追加节点
/// </summary>
/// <param name="filePath">XML文档绝对路径</param>
/// <param name="xPath">范例: @"Skill/First/SkillItem"</param>
/// <param name="xmlNode">XmlNode节点</param>
/// <returns></returns>
22
2015
05
Sql语句实现获取汉字首字母和全拼SQLSERVER函数
当需要进行查询某个字符串的首字母缩写或者字符串的全拼,使用C#是可以实现的,但是我们还可以通过Sql函数,调用函数也可以实现,不过这种方法需要数据库连接,代码如下:
--获取字符串全拼
--获取字符串汉字首字母
21
2015
05
对两个相同MSSql数据库表、字段描述进行对比,找出表字段之间的差异
在两个数据库进行同步或者对比的时候,需要对比两个数据库之间的差异,使用Sql语句进行对比分析,具体操作如下:
1、创建两个表(BackUp_TableInfo、BackUp_TableInfo1)来进行存储表结构信息,即表的所有字段信息,这里需要在两个数据库中都同时创建,也可以根据需要两个数据库中分别创建,Sql语句=
07
2015
05
C# 定时执行任务测试实例
需要使用定时程序来进行一些操作,可以使用Timer:
private void button1_Click(object sender, EventArgs e) { System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += new ElapsedEventHandler(TimeEvent); // 设置引发时间的时间间隔 此处设置为1秒(1000毫秒) aTimer.Interval = 1000; aTimer.Enabled = true; richTextBox1.AppendText("按回车键结束程序\n"); richTextBox1.AppendText("等待程序的执行......\n"); } //当时间发生的时候需要进行的逻辑处理等 //在这里仅仅是一种方式,可以实现这样的方式很多. private void TimeEvent(object source, ElapsedEventArgs e) { //得到 hour minute second 如果等于某个值就开始执行某个程序。 int intHour = e.SignalTime.Hour; int intMinute = e.SignalTime.Minute; int intSecond = e.SignalTime.Second; //设置 每秒钟的开始执行一次 if (intSecond % 5 == 0) { richTextBox1.AppendText("每5秒钟的开始执行一次:" + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss") + "!\n"); } }
效果图:
05
2015
05
Asp.Net 微信菜单自定义开发功能实现源代码
1、配置文件中,配置好微信自定义菜单开发需要的AppID和AppSecret:
<?xml version="1.0"?> <configuration> <appSettings> <add key="AppID" value="appid的值"/> <add key="AppSecret" value="appsecret的值"/> </appSettings> <connectionStrings /> <system.web> <compilation debug="true"> </compilation> <!-- 通过 <authentication> 节可以配置 安全身份验证模式,ASP.NET 使用该模式来识别来访用户身份。 --> <authentication mode="Windows" /> <!-- 如果在执行请求的过程中出现未处理的错误, 则通过 <customErrors> 节 可以配置相应的处理步骤。具体而言, 开发人员通过该节可配置要显示的 html 错误页, 以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> </configuration>
2、添加自定义菜单源代码:
20
2015
04
C#、Asp.Net 农历与阴历之间相互转化工具类
在做一些数据统计或者时间方面的开发时,通常会遇到需要对时间的农历与阴历之间相互进行转化,需要查询当前日期是否为春节或其他节日,判断是否为春节期间“jrDate == "除夕" || jrDate == "春节" || jrSDate.Day < 7 && jrMonth == "正月"”,可以使用此工具类。
DateTime nDate = Convert.ToDateTime(date); //当前需要转换的日期
string jrDate = ChinaDate.GetChinaHoliday(nDate); //获取农历节日
string jrMonth = ChinaDate.GetMonth(nDate); //获取农历月份
string jrDay = ChinaDate.GetDay(nDate); //获取农历日期
DateTime jrSDate = ChinaDate.GetSunYearDate(nDate); //阳历转阳历
DateTime jrLDate = ChinaDate.GetLunarYearDate(jrSDate.AddYears(-1)); //阴历转阳历
16
2015
04
C#、Asp.Net 发送邮件工具类
/// <summary> /// SendMail 的摘要说明 /// </summary> public class SendMail { public SendMail() { // // TODO: 在此处添加构造函数逻辑 // } /// <summary> /// 发送邮件 /// </summary> /// <returns></returns> public static bool SendEmail(string EmailPath, string EmailName, string EmailTitle, string EmailContent) { SmtpClient client = new SmtpClient(); //获取或设置用于验证发件人身份的凭据。 client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPwd"]); //经过ssl(安全套接层)加密,163邮箱SSL协议端口号为465/994,关闭SSL时端口为25, //qq邮箱SSL协议端口号为465或587,关闭SSL时端口同样为25,不过用SSL加密后发送邮件都失败,具体原因不知 //client.EnableSsl = true; client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["EmailPort"]); //端口号 client.Host = ConfigurationManager.AppSettings["EmailHost"]; //获取或设置用于 SMTP 事务的主机的名称或 IP 地址 try { client.Send(InitMailMessage(EmailPath, EmailName, EmailTitle, EmailContent)); return true; } catch (System.Net.Mail.SmtpException ex) { return false; } } /// <summary> /// 发送邮件(自定义发送配置) /// </summary> /// <param name="reEmailPath">收件人邮箱地址</param> /// <param name="reEmailName">收件人名称</param> /// <param name="sendEmailTitle">发件标题</param> /// <param name="sendEmailContent">发件内容</param> /// <param name="sendEmailUser">发件人账户</param> /// <param name="sendEmailPwd">发件人密码</param> /// <param name="sendEmailName">发件人名称</param> /// <param name="sendEmailPort">端口</param> /// <param name="sendEmailHost">发送SMTP地址</param> /// <returns></returns> public static bool SendEmail(string reEmailPath, string reEmailName, string sendEmailTitle, string sendEmailContent, string sendEmailUser, string sendEmailPwd, string sendEmailName, string sendEmailPort, string sendEmailHost) { SmtpClient client = new SmtpClient(); //设置为发送认证消息 client.UseDefaultCredentials = true; //string Email = EmailUser.Split('@')[0]; //获取或设置用于验证发件人身份的凭据。 client.Credentials = new System.Net.NetworkCredential(sendEmailUser, sendEmailPwd); //经过ssl(安全套接层)加密,163邮箱SSL协议端口号为465/994,关闭SSL时端口为25, //qq邮箱SSL协议端口号为465或587,关闭SSL时端口同样为25,不过用SSL加密后发送邮件都失败,具体原因不知 //client.EnableSsl = true; client.Port = Convert.ToInt32(sendEmailPort); //端口号 client.Host = sendEmailHost; //获取或设置用于 SMTP 事务的主机的名称或 IP 地址 try { client.Send(InitMailMessage(reEmailPath, reEmailName, sendEmailTitle, sendEmailContent, sendEmailUser, sendEmailName)); return true; } catch (System.Net.Mail.SmtpException ex) { return false; } } /// <summary> /// 初始化信件相关信息 /// </summary> /// <param name="reEmailPath">发件人</param> /// <param name="reEmailName">发件人姓名</param> /// <param name="sendEmailTitle">发送标题</param> /// <param name="sendEmailContent">发送内容</param> /// <returns></returns> public static MailMessage InitMailMessage(string reEmailPath, string reEmailName, string sendEmailTitle, string sendEmailContent) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailName"]); //发件人 if (reEmailName != "") { MailAddress mailAdd = new MailAddress(reEmailPath, reEmailName); //收件人 mail.To.Add(mailAdd); //收件人 } else { mail.To.Add(reEmailPath); //收件人 } mail.Subject = sendEmailTitle; //主题 mail.Body = sendEmailContent; //内容 //邮件主题和正文的编码格式 mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; //邮件正文允许html编码 mail.Priority = MailPriority.Normal; //优先级 //密送——就是将信密秘抄送给收件人以外的人,所有收件人看不到密件抄送的地址 //mail.Bcc.Add("823904362@qq.com"); //抄送——就是将信抄送给收件人以外的人,所有的收件人可以在抄送地址处看到此信还抄送给谁 //mail.CC.Add("823904362@qq.com"); //mail.Attachments.Add(new Attachment("D:\\1.doc")); //添加附件 return mail; } /// <summary> /// 发送邮件 /// </summary> /// <returns></returns> public static bool SendEmail(string EmailPath, string EmailName, string EmailTitle, string EmailContent, string attPath) { SmtpClient client = new SmtpClient(); //获取或设置用于验证发件人身份的凭据。 client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPwd"]); //经过ssl(安全套接层)加密,163邮箱SSL协议端口号为465/994,关闭SSL时端口为25, //qq邮箱SSL协议端口号为465或587,关闭SSL时端口同样为25,不过用SSL加密后发送邮件都失败,具体原因不知 //client.EnableSsl = true; client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["EmailPort"]); //端口号 client.Host = ConfigurationManager.AppSettings["EmailHost"]; //获取或设置用于 SMTP 事务的主机的名称或 IP 地址 try { client.Send(InitMailMessage(EmailPath, EmailName, EmailTitle, EmailContent, attPath)); return true; } catch (System.Net.Mail.SmtpException ex) { return false; } } /// <summary> /// 初始化信件相关信息 /// </summary> /// <param name="address">发送地址</param> /// <param name="title">标题</param> /// <param name="content">内容</param> /// <returns></returns> public static MailMessage InitMailMessage(string address, string name, string title, string content, string attPath) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailName"]); //发件人 if (name != "") { MailAddress mailAdd = new MailAddress(address, name); //收件人 mail.To.Add(mailAdd); //收件人 } else { mail.To.Add(address); //收件人 } mail.Subject = title; //主题 mail.Body = content; //内容 //邮件主题和正文的编码格式 mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; //邮件正文允许html编码 mail.Priority = MailPriority.Normal; //优先级 //密送——就是将信密秘抄送给收件人以外的人,所有收件人看不到密件抄送的地址 //mail.Bcc.Add("823904362@qq.com"); //抄送——就是将信抄送给收件人以外的人,所有的收件人可以在抄送地址处看到此信还抄送给谁 //mail.CC.Add("823904362@qq.com"); Attachment attach = new Attachment(attPath, "application/x-zip-compressed"); mail.Attachments.Add(attach); //mail.Attachments.Add(new Attachment("D:\\1.doc")); //添加附件 return mail; } /// <summary> /// 发送邮件(群发) /// </summary> /// <returns></returns> public static bool SendEmail(string[] EmailPath, string[] EmailName, string EmailTitle, string EmailContent) { SmtpClient client = new SmtpClient(); //获取或设置用于验证发件人身份的凭据。 client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPwd"]); //经过ssl(安全套接层)加密,163邮箱SSL协议端口号为465/994,关闭SSL时端口为25, //qq邮箱SSL协议端口号为465或587,关闭SSL时端口同样为25,不过用SSL加密后发送邮件都失败,具体原因不知 //client.EnableSsl = true; client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["EmailPort"]); //端口号 client.Host = ConfigurationManager.AppSettings["EmailHost"]; //获取或设置用于 SMTP 事务的主机的名称或 IP 地址 try { client.Send(InitMailMessage(EmailPath, EmailName, EmailTitle, EmailContent)); return true; } catch (System.Net.Mail.SmtpException ex) { return false; } } /// <summary> /// 初始化信件相关信息(群发) /// </summary> /// <param name="address">发送地址</param> /// <param name="title">标题</param> /// <param name="content">内容</param> /// <returns></returns> public static MailMessage InitMailMessage(string[] address, string[] name, string title, string content) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailName"]); //发件人 if (name != null && name.Length > 0) { if (address != null && address.Length > 0) { for (int i = 0; i < address.Length; i++) { if (address != null && address[i] != null && address[i] != "") { string nameStr = name != null && name[i] != null ? name[i].ToString() : ""; MailAddress mailAdd = new MailAddress(address[i], nameStr); //收件人 mail.To.Add(mailAdd); //收件人 } } } } else { for (int i = 0; i < address.Length; i++) { if (address[i] != null && address[i] != "") { mail.To.Add(address[i]); //收件人 } } } mail.Subject = title; //主题 mail.Body = content; //内容 //邮件主题和正文的编码格式 mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; //邮件正文允许html编码 mail.Priority = MailPriority.Normal; //优先级 //密送——就是将信密秘抄送给收件人以外的人,所有收件人看不到密件抄送的地址 //mail.Bcc.Add("823904362@qq.com"); //抄送——就是将信抄送给收件人以外的人,所有的收件人可以在抄送地址处看到此信还抄送给谁 //mail.CC.Add("823904362@qq.com"); //mail.Attachments.Add(new Attachment("D:\\1.doc")); //添加附件 return mail; } /// <summary> /// 初始化信件相关信息 /// </summary> /// <param name="reEmailPath">收件人</param> /// <param name="reEmailName">收件人名称</param> /// <param name="sendEmailTitle">发送标题</param> /// <param name="sendEmailContent">发送内容</param> /// <param name="sendEmailUser">发件人</param> /// <param name="sendEmailName">发件人名称</param> /// <returns></returns> public static MailMessage InitMailMessage(string reEmailPath, string reEmailName, string sendEmailTitle, string sendEmailContent, string sendEmailUser, string sendEmailName) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(sendEmailUser, sendEmailName); //发件人 if (reEmailPath != "") { MailAddress mailAdd = new MailAddress(reEmailPath, reEmailName); //收件人 mail.To.Add(mailAdd); //收件人 } else { mail.To.Add(reEmailPath); //收件人 } mail.Subject = sendEmailTitle; //主题 mail.Body = sendEmailContent; //内容 //邮件主题和正文的编码格式 mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; //邮件正文允许html编码 mail.Priority = MailPriority.Normal; //优先级 //密送——就是将信密秘抄送给收件人以外的人,所有收件人看不到密件抄送的地址 //mail.Bcc.Add("823904362@qq.com"); //抄送——就是将信抄送给收件人以外的人,所有的收件人可以在抄送地址处看到此信还抄送给谁 //mail.CC.Add("823904362@qq.com"); //mail.Attachments.Add(new Attachment("D:\\1.doc")); //添加附件 return mail; } }
14
2015
04
C#、Asp.Net 获取汉字全拼音、获得汉字拼音的简操作类
C#中,当需要将汉字转换为拼音或者某个词组转换为首字母缩写的,可以使用下面的类:
/// <summary> /// 中文获取拼音 /// </summary> public class PinyinHelper { private static Hashtable _pinyinHash; private static Regex regWord = new Regex("[a-zA-Z]"); private static Regex regNum = new Regex("[0-9]"); #region static stor. static PinyinHelper() { _pinyinHash = new Hashtable(); _pinyinHash.Add(-20319, "a"); _pinyinHash.Add(-20317, "ai"); _pinyinHash.Add(-20304, "an"); _pinyinHash.Add(-20295, "ang"); _pinyinHash.Add(-20292, "ao"); _pinyinHash.Add(-20283, "ba"); _pinyinHash.Add(-20265, "bai"); _pinyinHash.Add(-20257, "ban"); _pinyinHash.Add(-20242, "bang"); _pinyinHash.Add(-20230, "bao"); _pinyinHash.Add(-20051, "bei"); _pinyinHash.Add(-20036, "ben"); _pinyinHash.Add(-20032, "beng"); _pinyinHash.Add(-20026, "bi"); _pinyinHash.Add(-20002, "bian"); _pinyinHash.Add(-19990, "biao"); _pinyinHash.Add(-19986, "bie"); _pinyinHash.Add(-19982, "bin"); _pinyinHash.Add(-19976, "bing"); _pinyinHash.Add(-19805, "bo"); _pinyinHash.Add(-19784, "bu"); _pinyinHash.Add(-19775, "ca"); _pinyinHash.Add(-19774, "cai"); _pinyinHash.Add(-19763, "can"); _pinyinHash.Add(-19756, "cang"); _pinyinHash.Add(-19751, "cao"); _pinyinHash.Add(-19746, "ce"); _pinyinHash.Add(-19741, "ceng"); _pinyinHash.Add(-19739, "cha"); _pinyinHash.Add(-19728, "chai"); _pinyinHash.Add(-19725, "chan"); _pinyinHash.Add(-19715, "chang"); _pinyinHash.Add(-19540, "chao"); _pinyinHash.Add(-19531, "che"); _pinyinHash.Add(-19525, "chen"); _pinyinHash.Add(-19515, "cheng"); _pinyinHash.Add(-19500, "chi"); _pinyinHash.Add(-19484, "chong"); _pinyinHash.Add(-19479, "chou"); _pinyinHash.Add(-19467, "chu"); _pinyinHash.Add(-19289, "chuai"); _pinyinHash.Add(-19288, "chuan"); _pinyinHash.Add(-19281, "chuang"); _pinyinHash.Add(-19275, "chui"); _pinyinHash.Add(-19270, "chun"); _pinyinHash.Add(-19263, "chuo"); _pinyinHash.Add(-19261, "ci"); _pinyinHash.Add(-19249, "cong"); _pinyinHash.Add(-19243, "cou"); _pinyinHash.Add(-19242, "cu"); _pinyinHash.Add(-19238, "cuan"); _pinyinHash.Add(-19235, "cui"); _pinyinHash.Add(-19227, "cun"); _pinyinHash.Add(-19224, "cuo"); _pinyinHash.Add(-19218, "da"); _pinyinHash.Add(-19212, "dai"); _pinyinHash.Add(-19038, "dan"); _pinyinHash.Add(-19023, "dang"); _pinyinHash.Add(-19018, "dao"); _pinyinHash.Add(-19006, "de"); _pinyinHash.Add(-19003, "deng"); _pinyinHash.Add(-18996, "di"); _pinyinHash.Add(-18977, "dian"); _pinyinHash.Add(-18961, "diao"); _pinyinHash.Add(-18952, "die"); _pinyinHash.Add(-18783, "ding"); _pinyinHash.Add(-18774, "diu"); _pinyinHash.Add(-18773, "dong"); _pinyinHash.Add(-18763, "dou"); _pinyinHash.Add(-18756, "du"); _pinyinHash.Add(-18741, "duan"); _pinyinHash.Add(-18735, "dui"); _pinyinHash.Add(-18731, "dun"); _pinyinHash.Add(-18722, "duo"); _pinyinHash.Add(-18710, "e"); _pinyinHash.Add(-18697, "en"); _pinyinHash.Add(-18696, "er"); _pinyinHash.Add(-18526, "fa"); _pinyinHash.Add(-18518, "fan"); _pinyinHash.Add(-18501, "fang"); _pinyinHash.Add(-18490, "fei"); _pinyinHash.Add(-18478, "fen"); _pinyinHash.Add(-18463, "feng"); _pinyinHash.Add(-18448, "fo"); _pinyinHash.Add(-18447, "fou"); _pinyinHash.Add(-18446, "fu"); _pinyinHash.Add(-18239, "ga"); _pinyinHash.Add(-18237, "gai"); _pinyinHash.Add(-18231, "gan"); _pinyinHash.Add(-18220, "gang"); _pinyinHash.Add(-18211, "gao"); _pinyinHash.Add(-18201, "ge"); _pinyinHash.Add(-18184, "gei"); _pinyinHash.Add(-18183, "gen"); _pinyinHash.Add(-18181, "geng"); _pinyinHash.Add(-18012, "gong"); _pinyinHash.Add(-17997, "gou"); _pinyinHash.Add(-17988, "gu"); _pinyinHash.Add(-17970, "gua"); _pinyinHash.Add(-17964, "guai"); _pinyinHash.Add(-17961, "guan"); _pinyinHash.Add(-17950, "guang"); _pinyinHash.Add(-17947, "gui"); _pinyinHash.Add(-17931, "gun"); _pinyinHash.Add(-17928, "guo"); _pinyinHash.Add(-17922, "ha"); _pinyinHash.Add(-17759, "hai"); _pinyinHash.Add(-17752, "han"); _pinyinHash.Add(-17733, "hang"); _pinyinHash.Add(-17730, "hao"); _pinyinHash.Add(-17721, "he"); _pinyinHash.Add(-17703, "hei"); _pinyinHash.Add(-17701, "hen"); _pinyinHash.Add(-17697, "heng"); _pinyinHash.Add(-17692, "hong"); _pinyinHash.Add(-17683, "hou"); _pinyinHash.Add(-17676, "hu"); _pinyinHash.Add(-17496, "hua"); _pinyinHash.Add(-17487, "huai"); _pinyinHash.Add(-17482, "huan"); _pinyinHash.Add(-17468, "huang"); _pinyinHash.Add(-17454, "hui"); _pinyinHash.Add(-17433, "hun"); _pinyinHash.Add(-17427, "huo"); _pinyinHash.Add(-17417, "ji"); _pinyinHash.Add(-17202, "jia"); _pinyinHash.Add(-17185, "jian"); _pinyinHash.Add(-16983, "jiang"); _pinyinHash.Add(-16970, "jiao"); _pinyinHash.Add(-16942, "jie"); _pinyinHash.Add(-16915, "jin"); _pinyinHash.Add(-16733, "jing"); _pinyinHash.Add(-16708, "jiong"); _pinyinHash.Add(-16706, "jiu"); _pinyinHash.Add(-16689, "ju"); _pinyinHash.Add(-16664, "juan"); _pinyinHash.Add(-16657, "jue"); _pinyinHash.Add(-16647, "jun"); _pinyinHash.Add(-16474, "ka"); _pinyinHash.Add(-16470, "kai"); _pinyinHash.Add(-16465, "kan"); _pinyinHash.Add(-16459, "kang"); _pinyinHash.Add(-16452, "kao"); _pinyinHash.Add(-16448, "ke"); _pinyinHash.Add(-16433, "ken"); _pinyinHash.Add(-16429, "keng"); _pinyinHash.Add(-16427, "kong"); _pinyinHash.Add(-16423, "kou"); _pinyinHash.Add(-16419, "ku"); _pinyinHash.Add(-16412, "kua"); _pinyinHash.Add(-16407, "kuai"); _pinyinHash.Add(-16403, "kuan"); _pinyinHash.Add(-16401, "kuang"); _pinyinHash.Add(-16393, "kui"); _pinyinHash.Add(-16220, "kun"); _pinyinHash.Add(-16216, "kuo"); _pinyinHash.Add(-16212, "la"); _pinyinHash.Add(-16205, "lai"); _pinyinHash.Add(-16202, "lan"); _pinyinHash.Add(-16187, "lang"); _pinyinHash.Add(-16180, "lao"); _pinyinHash.Add(-16171, "le"); _pinyinHash.Add(-16169, "lei"); _pinyinHash.Add(-16158, "leng"); _pinyinHash.Add(-16155, "li"); _pinyinHash.Add(-15959, "lia"); _pinyinHash.Add(-15958, "lian"); _pinyinHash.Add(-15944, "liang"); _pinyinHash.Add(-15933, "liao"); _pinyinHash.Add(-15920, "lie"); _pinyinHash.Add(-15915, "lin"); _pinyinHash.Add(-15903, "ling"); _pinyinHash.Add(-15889, "liu"); _pinyinHash.Add(-15878, "long"); _pinyinHash.Add(-15707, "lou"); _pinyinHash.Add(-15701, "lu"); _pinyinHash.Add(-15681, "lv"); _pinyinHash.Add(-15667, "luan"); _pinyinHash.Add(-15661, "lue"); _pinyinHash.Add(-15659, "lun"); _pinyinHash.Add(-15652, "luo"); _pinyinHash.Add(-15640, "ma"); _pinyinHash.Add(-15631, "mai"); _pinyinHash.Add(-15625, "man"); _pinyinHash.Add(-15454, "mang"); _pinyinHash.Add(-15448, "mao"); _pinyinHash.Add(-15436, "me"); _pinyinHash.Add(-15435, "mei"); _pinyinHash.Add(-15419, "men"); _pinyinHash.Add(-15416, "meng"); _pinyinHash.Add(-15408, "mi"); _pinyinHash.Add(-15394, "mian"); _pinyinHash.Add(-15385, "miao"); _pinyinHash.Add(-15377, "mie"); _pinyinHash.Add(-15375, "min"); _pinyinHash.Add(-15369, "ming"); _pinyinHash.Add(-15363, "miu"); _pinyinHash.Add(-15362, "mo"); _pinyinHash.Add(-15183, "mou"); _pinyinHash.Add(-15180, "mu"); _pinyinHash.Add(-15165, "na"); _pinyinHash.Add(-15158, "nai"); _pinyinHash.Add(-15153, "nan"); _pinyinHash.Add(-15150, "nang"); _pinyinHash.Add(-15149, "nao"); _pinyinHash.Add(-15144, "ne"); _pinyinHash.Add(-15143, "nei"); _pinyinHash.Add(-15141, "nen"); _pinyinHash.Add(-15140, "neng"); _pinyinHash.Add(-15139, "ni"); _pinyinHash.Add(-15128, "nian"); _pinyinHash.Add(-15121, "niang"); _pinyinHash.Add(-15119, "niao"); _pinyinHash.Add(-15117, "nie"); _pinyinHash.Add(-15110, "nin"); _pinyinHash.Add(-15109, "ning"); _pinyinHash.Add(-14941, "niu"); _pinyinHash.Add(-14937, "nong"); _pinyinHash.Add(-14933, "nu"); _pinyinHash.Add(-14930, "nv"); _pinyinHash.Add(-14929, "nuan"); _pinyinHash.Add(-14928, "nue"); _pinyinHash.Add(-14926, "nuo"); _pinyinHash.Add(-14922, "o"); _pinyinHash.Add(-14921, "ou"); _pinyinHash.Add(-14914, "pa"); _pinyinHash.Add(-14908, "pai"); _pinyinHash.Add(-14902, "pan"); _pinyinHash.Add(-14894, "pang"); _pinyinHash.Add(-14889, "pao"); _pinyinHash.Add(-14882, "pei"); _pinyinHash.Add(-14873, "pen"); _pinyinHash.Add(-14871, "peng"); _pinyinHash.Add(-14857, "pi"); _pinyinHash.Add(-14678, "pian"); _pinyinHash.Add(-14674, "piao"); _pinyinHash.Add(-14670, "pie"); _pinyinHash.Add(-14668, "pin"); _pinyinHash.Add(-14663, "ping"); _pinyinHash.Add(-14654, "po"); _pinyinHash.Add(-14645, "pu"); _pinyinHash.Add(-14630, "qi"); _pinyinHash.Add(-14594, "qia"); _pinyinHash.Add(-14429, "qian"); _pinyinHash.Add(-14407, "qiang"); _pinyinHash.Add(-14399, "qiao"); _pinyinHash.Add(-14384, "qie"); _pinyinHash.Add(-14379, "qin"); _pinyinHash.Add(-14368, "qing"); _pinyinHash.Add(-14355, "qiong"); _pinyinHash.Add(-14353, "qiu"); _pinyinHash.Add(-14345, "qu"); _pinyinHash.Add(-14170, "quan"); _pinyinHash.Add(-14159, "que"); _pinyinHash.Add(-14151, "qun"); _pinyinHash.Add(-14149, "ran"); _pinyinHash.Add(-14145, "rang"); _pinyinHash.Add(-14140, "rao"); _pinyinHash.Add(-14137, "re"); _pinyinHash.Add(-14135, "ren"); _pinyinHash.Add(-14125, "reng"); _pinyinHash.Add(-14123, "ri"); _pinyinHash.Add(-14122, "rong"); _pinyinHash.Add(-14112, "rou"); _pinyinHash.Add(-14109, "ru"); _pinyinHash.Add(-14099, "ruan"); _pinyinHash.Add(-14097, "rui"); _pinyinHash.Add(-14094, "run"); _pinyinHash.Add(-14092, "ruo"); _pinyinHash.Add(-14090, "sa"); _pinyinHash.Add(-14087, "sai"); _pinyinHash.Add(-14083, "san"); _pinyinHash.Add(-13917, "sang"); _pinyinHash.Add(-13914, "sao"); _pinyinHash.Add(-13910, "se"); _pinyinHash.Add(-13907, "sen"); _pinyinHash.Add(-13906, "seng"); _pinyinHash.Add(-13905, "sha"); _pinyinHash.Add(-13896, "shai"); _pinyinHash.Add(-13894, "shan"); _pinyinHash.Add(-13878, "shang"); _pinyinHash.Add(-13870, "shao"); _pinyinHash.Add(-13859, "she"); _pinyinHash.Add(-13847, "shen"); _pinyinHash.Add(-13831, "sheng"); _pinyinHash.Add(-13658, "shi"); _pinyinHash.Add(-13611, "shou"); _pinyinHash.Add(-13601, "shu"); _pinyinHash.Add(-13406, "shua"); _pinyinHash.Add(-13404, "shuai"); _pinyinHash.Add(-13400, "shuan"); _pinyinHash.Add(-13398, "shuang"); _pinyinHash.Add(-13395, "shui"); _pinyinHash.Add(-13391, "shun"); _pinyinHash.Add(-13387, "shuo"); _pinyinHash.Add(-13383, "si"); _pinyinHash.Add(-13367, "song"); _pinyinHash.Add(-13359, "sou"); _pinyinHash.Add(-13356, "su"); _pinyinHash.Add(-13343, "suan"); _pinyinHash.Add(-13340, "sui"); _pinyinHash.Add(-13329, "sun"); _pinyinHash.Add(-13326, "suo"); _pinyinHash.Add(-13318, "ta"); _pinyinHash.Add(-13147, "tai"); _pinyinHash.Add(-13138, "tan"); _pinyinHash.Add(-13120, "tang"); _pinyinHash.Add(-13107, "tao"); _pinyinHash.Add(-13096, "te"); _pinyinHash.Add(-13095, "teng"); _pinyinHash.Add(-13091, "ti"); _pinyinHash.Add(-13076, "tian"); _pinyinHash.Add(-13068, "tiao"); _pinyinHash.Add(-13063, "tie"); _pinyinHash.Add(-13060, "ting"); _pinyinHash.Add(-12888, "tong"); _pinyinHash.Add(-12875, "tou"); _pinyinHash.Add(-12871, "tu"); _pinyinHash.Add(-12860, "tuan"); _pinyinHash.Add(-12858, "tui"); _pinyinHash.Add(-12852, "tun"); _pinyinHash.Add(-12849, "tuo"); _pinyinHash.Add(-12838, "wa"); _pinyinHash.Add(-12831, "wai"); _pinyinHash.Add(-12829, "wan"); _pinyinHash.Add(-12812, "wang"); _pinyinHash.Add(-12802, "wei"); _pinyinHash.Add(-12607, "wen"); _pinyinHash.Add(-12597, "weng"); _pinyinHash.Add(-12594, "wo"); _pinyinHash.Add(-12585, "wu"); _pinyinHash.Add(-12556, "xi"); _pinyinHash.Add(-12359, "xia"); _pinyinHash.Add(-12346, "xian"); _pinyinHash.Add(-12320, "xiang"); _pinyinHash.Add(-12300, "xiao"); _pinyinHash.Add(-12120, "xie"); _pinyinHash.Add(-12099, "xin"); _pinyinHash.Add(-12089, "xing"); _pinyinHash.Add(-12074, "xiong"); _pinyinHash.Add(-12067, "xiu"); _pinyinHash.Add(-12058, "xu"); _pinyinHash.Add(-12039, "xuan"); _pinyinHash.Add(-11867, "xue"); _pinyinHash.Add(-11861, "xun"); _pinyinHash.Add(-11847, "ya"); _pinyinHash.Add(-11831, "yan"); _pinyinHash.Add(-11798, "yang"); _pinyinHash.Add(-11781, "yao"); _pinyinHash.Add(-11604, "ye"); _pinyinHash.Add(-11589, "yi"); _pinyinHash.Add(-11536, "yin"); _pinyinHash.Add(-11358, "ying"); _pinyinHash.Add(-11340, "yo"); _pinyinHash.Add(-11339, "yong"); _pinyinHash.Add(-11324, "you"); _pinyinHash.Add(-11303, "yu"); _pinyinHash.Add(-11097, "yuan"); _pinyinHash.Add(-11077, "yue"); _pinyinHash.Add(-11067, "yun"); _pinyinHash.Add(-11055, "za"); _pinyinHash.Add(-11052, "zai"); _pinyinHash.Add(-11045, "zan"); _pinyinHash.Add(-11041, "zang"); _pinyinHash.Add(-11038, "zao"); _pinyinHash.Add(-11024, "ze"); _pinyinHash.Add(-11020, "zei"); _pinyinHash.Add(-11019, "zen"); _pinyinHash.Add(-11018, "zeng"); _pinyinHash.Add(-11014, "zha"); _pinyinHash.Add(-10838, "zhai"); _pinyinHash.Add(-10832, "zhan"); _pinyinHash.Add(-10815, "zhang"); _pinyinHash.Add(-10800, "zhao"); _pinyinHash.Add(-10790, "zhe"); _pinyinHash.Add(-10780, "zhen"); _pinyinHash.Add(-10764, "zheng"); _pinyinHash.Add(-10587, "zhi"); _pinyinHash.Add(-10544, "zhong"); _pinyinHash.Add(-10533, "zhou"); _pinyinHash.Add(-10519, "zhu"); _pinyinHash.Add(-10331, "zhua"); _pinyinHash.Add(-10329, "zhuai"); _pinyinHash.Add(-10328, "zhuan"); _pinyinHash.Add(-10322, "zhuang"); _pinyinHash.Add(-10315, "zhui"); _pinyinHash.Add(-10309, "zhun"); _pinyinHash.Add(-10307, "zhuo"); _pinyinHash.Add(-10296, "zi"); _pinyinHash.Add(-10281, "zong"); _pinyinHash.Add(-10274, "zou"); _pinyinHash.Add(-10270, "zu"); _pinyinHash.Add(-10262, "zuan"); _pinyinHash.Add(-10260, "zui"); _pinyinHash.Add(-10256, "zun"); _pinyinHash.Add(-10254, "zuo"); _pinyinHash.Add(-10247, "zz"); } #endregion /// <summary> /// 获得汉字的拼音,如果输入的是英文字符将原样输出,中文标点符号将被忽略 /// </summary> /// <param name="chineseChars">汉字字符串</param> /// <returns>拼音</returns> public static string GetPinyin(string chineseChars) { byte[] byteArray = System.Text.Encoding.Default.GetBytes(chineseChars); int byteValue; StringBuilder sb = new StringBuilder(chineseChars.Length * 4); for (int i = 0; i < byteArray.Length; i++) { byteValue = (int)byteArray[i]; if (byteValue > 160) { ++i; if (i >= byteArray.Length) { break; } byteValue = byteValue * 256 + byteArray[i] - 65536; sb.Append(GetPinyin(byteValue)); } else { sb.Append((char)byteValue); } } return sb.ToString(); } /// <summary> /// 获得汉字拼音的简写,即每一个汉字的拼音的首字母组成的串,如果输入的是英文字符将原样输出,中文标点符号将被忽略 /// </summary> /// <param name="chineseChars">汉字字符串</param> /// <returns>拼音简写</returns> public static string GetShortPinyin(string chineseChars) { byte[] byteArray = System.Text.Encoding.Default.GetBytes(chineseChars); int byteValue; StringBuilder sb = new StringBuilder(chineseChars.Length * 4); for (int i = 0; i < byteArray.Length; i++) { byteValue = (int)byteArray[i]; if (byteValue > 160) { ++i; if (i >= byteArray.Length) { break; } byteValue = byteValue * 256 + byteArray[i] - 65536; string charPinyin = GetPinyin(byteValue); if (!string.IsNullOrEmpty(charPinyin)) { charPinyin = new string(charPinyin[0], 1); } sb.Append(charPinyin); } else { sb.Append((char)byteValue); } } return sb.ToString(); } private static string GetPinyin(int charValue) { if (charValue < -20319 || charValue > -10247) return ""; while (!_pinyinHash.ContainsKey(charValue)) charValue--; return (string)_pinyinHash[charValue]; } public static string GetFirstWord(string pingyin) { pingyin = pingyin.Trim(); string word = ""; for (int i = 0; i < pingyin.Length; i++) { word = pingyin.Substring(i, 1); if (regWord.IsMatch(word)) { break; } if (regNum.IsMatch(word)) { if (word == "0") word = "l"; else if (word == "1") word = "y"; else if (word == "2") word = "e"; else if (word == "3") word = "s"; else if (word == "4") word = "s"; else if (word == "5") word = "w"; else if (word == "6") word = "l"; else if (word == "7") word = "q"; else if (word == "8") word = "b"; else if (word == "9") word = "q"; else continue; break; } } return word; } }
12
2015
04
C#、Asp.Net 详细文件操作工具类收藏
public class Txt { public Txt() { } /// <summary> /// 新建文件 /// </summary> /// <param name="filename">文件名</param> /// <param name="path">文件路径</param> public static void NewFile(string filename, string path) { filename.Trim(); if (filename == "") { MessageBox.Show("文件名不能为空~!"); } else { if (File.Exists(path + "//" + filename + ".txt")) { MessageBox.Show("该文件名已经存在,请重命名"); } else { string FullName = path + "//" + filename + ".txt"; //获得文件完整信息 StreamWriter Sw = File.CreateText(FullName); } } } /// <summary> /// 新建文件(Enter键触发) /// </summary> /// <param name="filename">文件名</param> /// <param name="path">文件路径</param> public static void Enter(string filename, string path) { filename.Trim(); if (filename == "") { MessageBox.Show("文件名不能为空~!"); } else { if (File.Exists(path + "//" + filename + ".txt")) { MessageBox.Show("该文件名已经存在,请重命名"); } else { string FullName = path + "//" + filename + ".txt"; //获得文件完整信息 StreamWriter Sw = File.CreateText(FullName); } } } /// <summary> /// 读取显示 /// </summary> /// <param name="filename">文本文件名</param> /// <param name="contents">内容</param> public static string Display(string filename) {//读取显示 try { string contents; FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); //读出所打开的文本文件 StreamReader reader = new StreamReader(fs); //实例化一个streamreader contents = reader.ReadToEnd(); //将数据显示 fs.Close(); return contents; } catch (Exception ex) { MessageBox.Show(ex.Message); return ""; } } /// <summary> /// 打开 /// </summary> /// <param name="ofd">打开对话框</param> /// <param name="fullname">文本文件名</param> /// <param name="contents">内容</param> public static void Open(OpenFileDialog ofd, string fullname, string contents) {//打开文本 try { if (ofd.ShowDialog() == DialogResult.OK) { string fileName = ofd.FileName; //文件名 FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(fs); fullname = fileName; contents = reader.ReadToEnd(); fs.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// <summary> /// 保存 /// </summary> /// <param name="fullname">文本文件名</param> /// <param name="contents">内容</param> public static void Save(string fullname, string contents) {//保存 try { StreamWriter writer = new StreamWriter(fullname); writer.Write(contents); //用write()方法把txtContent的数据写入文件 writer.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// <summary> /// 另存为 /// </summary> /// <param name="sfd">保存对话框</param> /// <param name="contents">内容</param> public static void SaveAs(SaveFileDialog sfd, string contents) { if (sfd.ShowDialog() == DialogResult.OK) { string fileName = sfd.FileName; try { Stream stream = File.OpenWrite(fileName); using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(contents); writer.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } /// <summary> /// 粗体 /// </summary> /// <param name="rtb"></param> public static void Bold(RichTextBox rtb) { Font newFont = new Font(rtb.SelectionFont, (rtb.SelectionFont.Bold ? rtb.SelectionFont.Style & ~FontStyle.Bold : rtb.SelectionFont.Style | FontStyle.Bold)); rtb.SelectionFont = newFont; } /// <summary> /// 斜体 /// </summary> /// <param name="rtb"></param> public static void Italic(RichTextBox rtb) { Font newFont = new Font(rtb.SelectionFont, (rtb.SelectionFont.Italic ? rtb.SelectionFont.Style & ~FontStyle.Italic : rtb.SelectionFont.Style | FontStyle.Italic)); rtb.SelectionFont = newFont; } /// <summary> /// 下划线 /// </summary> /// <param name="rtb"></param> public static void Underline(RichTextBox rtb) { Font newFont = new Font(rtb.SelectionFont, (rtb.SelectionFont.Underline ? rtb.SelectionFont.Style & ~FontStyle.Underline : rtb.SelectionFont.Style | FontStyle.Underline)); rtb.SelectionFont = newFont; } /// <summary> /// 复制 /// </summary> /// <param name="rtb"></param> public static void Copy(RichTextBox rtb) { if (rtb.SelectedText.Equals("")) return; Clipboard.SetDataObject(rtb.SelectedText, true); } /// <summary> /// 剪切 /// </summary> /// <param name="rtb"></param> public static void Cut(RichTextBox rtb) { if (rtb.SelectedText.Length > 0) { try { rtb.Cut(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } /// <summary> /// 粘贴 /// </summary> /// <param name="rtb"></param> public static void Paste(RichTextBox rtb) { rtb.Paste(); } /// <summary> /// 退出 /// </summary> /// <param name="fullname">文本文件全名</param> /// <param name="contents">内容</param> public static void Exit(string fullname, string contents) { if (MessageBox.Show("是否保存文件", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { try { StreamWriter writer = new StreamWriter(fullname); writer.Write(contents); //用write()方法把txtContent的数据写入文件 writer.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } /// <summary> /// 在指定目录新建一个文本文件 /// </summary> /// <param name="path"></param> /// <param name="name"></param> /// <returns></returns> public static StreamWriter CreateText(string path, string name) { return File.CreateText(path + "//" + name); } /// <summary> /// 删除指定文件 /// </summary> /// <param name="strFile">文件完整路径</param> public static void DeleteFile(string strFile) { File.Delete(strFile); } }