1.日期毫秒转换为标准的C#日期格式

//使用时,先将秒Convert.ToInt64,返回格式2015-2-10 14:03:33
public DateTime JavaTimeToC(long ltime)
{
long time_JAVA_Long = ltime;//java长整型日期,毫秒为单位
DateTime dt_1970 = new DateTime(, , );
long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
long time_tricks = tricks_1970 + time_JAVA_Long * ;//日志日期刻度
DateTime dt = new DateTime(time_tricks, DateTimeKind.Unspecified).AddHours();//转化为DateTime
return dt;
}

2.带事务的数据库插入更新删除方法

public void DbOp(List<string> sqlNum, ref string error)
{
if (sqlNum.Count <= )
{
error = "sql语句为空,没有订单数据!";
return;
}
try
{
if (!string.IsNullOrEmpty(strDbConnection))//缺少数据库连接字符串
{
using (OracleConnection con = new OracleConnection(strDbConnection))
{
using (OracleCommand cmd = con.CreateCommand())
{
con.Open();
OracleTransaction trans = con.BeginTransaction();//开始事务
cmd.Transaction = trans;//设置事务
string[] sql = sqlNum.ToArray();
try
{ for (int i = ; i < sql.Length; i++)
{
cmd.CommandText = sql[i];
cmd.ExecuteNonQuery();
}
trans.Commit();//提交事务
}
catch (Exception ex)
{
error += ex;
trans.Rollback();//回滚
}
finally
{
con.Close();//始终关闭数据库连接
}
}
}
}
else
{
//缺少数据库连接字符串
error += "缺少数据库连接字符串";
}
}
catch (Exception ex)
{ error += ex;
}
}

3.数据库查询方法

public  DataSet Query(string SQLString)
{
using (OracleConnection connection = new OracleConnection(strDbConnection))
{
DataSet ds = new DataSet();
try
{
connection.Open();
OracleDataAdapter command = new OracleDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.OracleClient.OracleException ex)
{
throw new Exception(ex.Message);
}
finally
{
connection.Close();
}
return ds;
}
}

4.DataTime,转换为string类型

public string DateTimeChange(DateTime dt)
{
string strDT = dt.Year.ToString();
if (dt.Month.ToString().Length == )
{
strDT += "-0" + dt.Month.ToString();
}
else
{
strDT += "-" + dt.Month.ToString();
} if (dt.Day.ToString().Length == )
{
strDT += "-0" + dt.Day.ToString();
}
else
{
strDT += "-" + dt.Day.ToString();
} if (dt.Hour.ToString().Length == )
{
strDT += "" + dt.Hour.ToString();
}
else
{
strDT += " " + dt.Hour.ToString();
} if (dt.Minute.ToString().Length == )
{
strDT += ":0" + dt.Minute.ToString();
}
else
{
strDT += ":" + dt.Minute.ToString();
} if (dt.Second.ToString().Length == )
{
strDT += ":0" + dt.Second.ToString();
}
else
{
strDT += ":" + dt.Second.ToString();
}
return strDT;
}

5.写日志dll

//地址:http://files.cnblogs.com/files/valiant1882331/%E5%86%99%E6%97%A5%E5%BF%97.rar
//使用
Log.ClsLog lo = new Log.ClsLog();
lo.writelogtype("",);
lo.writelogtype("", ,"日志文件名称");

dll源代码

public class ClsLog
{
/// 不限定名称写日志主方法
/// <summary>
/// 不限定名称写日志主方法
/// </summary>
/// <param name="msg">1string2Exception</param>
/// <param name="code">1应用程序日志2SQL日志3应用程序错误4SQL错误5下载错误6上传错误7下载日志8上传日志9初1错10初1日11初2错12初2日13初3错14初3日15初4错16初4日17初5错18初5日19初6错20初6日21初0错22初0日23实1错24实1日25实2错26实2日27实0错28实0日29打0错30打0日31池0错32池0日33判0错34判0日35按键36xssql37upsql38downsql39dayinsql40chu1sql41chu2sql42chu3sql43chu4sql44chu5sql45upbeifensql46upedsql</param>
public void writelogtype(object msg, int code)
{
string strErr = "";
Exception e = null;
switch (code)
{
case :
writelog(msg.ToString().Trim(), "applog");
break;
case :
writelog(msg.ToString().Trim(), "sqllog");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "apperr");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "sqlerr");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "downerr");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "uperr");
break;
case :
writelog(msg.ToString().Trim(), "downlog");
break;
case :
writelog(msg.ToString().Trim(), "uplog");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr1");
break;
case :
writelog(msg.ToString().Trim(), "initlog1");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr2");
break;
case :
writelog(msg.ToString().Trim(), "initlog2");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr3");
break;
case :
writelog(msg.ToString().Trim(), "initlog3");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr4");
break;
case :
writelog(msg.ToString().Trim(), "initlog4");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr5");
break;
case :
writelog(msg.ToString().Trim(), "initlog5");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr6");
break;
case :
writelog(msg.ToString().Trim(), "initlog6");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "initerr0");
break;
case :
writelog(msg.ToString().Trim(), "initlog0");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "shierr1");
break;
case :
writelog(msg.ToString().Trim(), "shilog1");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "shierr2");
break;
case :
writelog(msg.ToString().Trim(), "shilog2");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "shierr0");
break;
case :
writelog(msg.ToString().Trim(), "shilog0");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "dayinerr0");
break;
case :
writelog(msg.ToString().Trim(), "dayinlog0");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "chierr0");
break;
case :
writelog(msg.ToString().Trim(), "chilog0");
break;
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
writelog(strErr, "panerr0");
break;
case :
writelog(msg.ToString().Trim(), "panlog0");
break;
case :
writelog(msg.ToString().Trim(), "anjian");
break;
case :
//writelog(msg.ToString().Trim(), "xssql");
break;
case :
writelog(msg.ToString().Trim(), "upsql");
break;
case :
writelog(msg.ToString().Trim(), "downsql");
break;
case :
writelog(msg.ToString().Trim(), "dayinsql");
break;
case :
writelog(msg.ToString().Trim(), "chu1sql");
break;
case :
writelog(msg.ToString().Trim(), "chu2sql");
break;
case :
writelog(msg.ToString().Trim(), "chu3sql");
break;
case :
writelog(msg.ToString().Trim(), "chu4sql");
break;
case :
writelog(msg.ToString().Trim(), "chu5sql");
break;
case :
writelog(msg.ToString().Trim(), "upbeifensql");
break;
case :
writelog(msg.ToString().Trim(), "upedsql");
break;
case :
writelog(msg.ToString().Trim(), "lianjisql");
break;
case :
writelog(msg.ToString().Trim(), "JieKou");
break;
case :
writelog(msg.ToString().Trim(), "ShuHao");
break;
//40chu1sql41chu2sql42chu3sql43chu4sql44chu5sql
}
} ///写日志,自定义日志名称,类型
/// <summary>
/// 写日志,自定义日志名称,类型
/// </summary>
/// <param name="msg">错误信息</param>
/// <param name="code">1:异常错误信息ex.Message 2,ex</param>
/// <param name="logName">日志名称</param>
/// <returns></returns>
public string writeLogType(object msg, int code, string logName)
{
string strErr = "";
logName = logName.Replace(':','!');
Exception e = null;
switch (code)
{
case :
return writelog(msg.ToString().Trim(), logName);
case :
e = msg as Exception;
strErr = "Source:" + e.Source + Environment.NewLine;
strErr += "Message:" + e.Message + Environment.NewLine;
strErr += "StackTrace:" + e.StackTrace;
return writelog(strErr, logName);
}
return "";
}
///写日志主方法,仅调用
/// <summary>
/// 写日志主方法,仅调用
/// </summary>
/// <param name="value">错误信息</param>
/// <param name="name">日志名称</param>
/// <returns></returns>
private string writelog(string value, string name)
{
string strPath = "";//定义日志路径
try
{
//如果是http,web请求,则路径为web服务器上的虚拟路径对应的物理路径
strPath = System.Web.HttpContext.Current.Server.MapPath("log");
}
catch (Exception)
{
}
if (strPath == "")
{
//如果没有web路径,就设置路径为本地可执行文件个目录
strPath = Application.StartupPath;
}
FileStream logFile = null;
//
string strDate = DateTime.Now.Year.ToString();//获取当前如期年份部分
strDate += "-" + DateTime.Now.Month.ToString();//2000-01
strDate += "-" + DateTime.Now.Day.ToString();//2000-01-01
if(!Directory.Exists(strPath+"\\log"))
{
Directory.CreateDirectory(strPath+"\\log");
}
if (!Directory.Exists(strPath + "\\log\\" + strDate))
{
Directory.CreateDirectory(strPath + "\\log\\" + strDate);
}
//设置文件路径下的文件名称
strPath = strPath + "\\log\\" + strDate + "\\" + name + ".txt";
if (logFile == null)
{
logFile = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);//FileShare.ReadWrite允许以后打开文件读写
}
string strLine = Environment.NewLine;//换行符
string strTime = DateTime.Now.ToString("HH:mm:ss");//当前时间格式
string str = "";
if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql")
str = strTime + strLine;
str += value + strLine;
if (name != "upbeifensql" && name != "upedsql" && name != "lianjisql")
str += "*****************************************************************************************************************************" + strLine;
#region old
//if (name == "upbeifensql" || name == "upedsql" || name == "lianjisql")
//{
// CompressionHelper compress = new CompressionHelper();
// str = compress.CompressToString(str);
// str += strLine;
//}
#endregion
byte[] bytes = System.Text.Encoding.Default.GetBytes(str);
logFile.Position = logFile.Length;
logFile.Write(bytes, , (int)bytes.Length);
logFile.Close();
logFile = null;
return strPath;
}
}

6. 省市区三级联动js版(自定义控件)

http://files.cnblogs.com/files/valiant1882331/%E7%9C%81%E5%B8%82%E5%8E%BF%E4%B8%89%E7%BA%A7%E8%81%94%E5%8A%A8-js%E7%89%88.zip

7.正则表达式去除html标签

public static string NoHTML(string Htmlstring)
{
//删除脚本
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring = Htmlstring.Replace("<", "&lt;");
Htmlstring = Htmlstring.Replace(">", "&gt;");
Htmlstring = Htmlstring.Replace("\r\n", "");
return Htmlstring;
}

c#个人记录常用方法(更新中)的更多相关文章

  1. C# 知识点记录(持续更新中)

    从看C#入门经典开始系统的学习C#,本文主要记录学习过程中的一些知识点,也是我博客生涯的开始,比较重要成体系的部分会单重新写文章整理归纳. 1.一字不变的字符串 @字符 使转义序列不被处理,按照原样输 ...

  2. CLR via C# 第五章学习记录(更新中)

    1.设置全局溢出检查,项目属性->生成->高级->检测运算上溢/下溢 2.局部使用溢出检测 Byte b = ; b = ));// 不检测溢出 checked// 检测溢出代码段 ...

  3. BUUCTF刷题记录(更新中...)

    极客大挑战 2019]EasySQL-1 直接通过输入万能密码:' or 1=1#实现注入: 思考:服务端sql语句应该为:select * from users where username='xx ...

  4. Linux系统编程重要细节记录(持续更新中)

    1.在打印rlim_t值时,需要将其转换为long long并使用%lld printf()修饰符.

  5. 小程序 - API 踩坑记录(更新中...)

    API 小程序API结构导览图: 声明: 请尊重博客园原创精神,转载或使用图片请注明: 博主:xing.org1^ 出处:http://www.cnblogs.com/padding1015/

  6. 【小TIP】记录各种错误【更新中】

    最好程序一遍通过,为了提高代码能力,这里将用TIP的形式记录来犯过的错误.不断更新中. *已经转移到闪存.. [150214]WA:检查是否数组开小了. [150212]WA:如果程序中有乘号,需要留 ...

  7. Atom使用记录(持续更新中)

    部分内容取自:http://www.jianshu.com/p/dd97cbb3c22d,我自己也在使用,持续更新中 Atom安装插件在窗口中File---Setting---install 在里面进 ...

  8. Appium学习实践(五)遇到的坑(记录自己工作中遇到的坑以及解决方案,不定时更新)

    1.错误截图,有时候测试用例执行错误的话,相对于复杂的log,一张错误截图也许能更明确哪里出的问题(当然有时,截图+log还是最好了) 坑:本来是想测试用例fail的时候捕获异常来执行截图操作,但是由 ...

  9. vue项目常用方法封装,持续更新中。。。

    vue项目中可以直接使用 1.常用工具类untils.js中 /* * 验证手机号是否合格 * true--说明合格 */ export function isPhone(phoneStr){ let ...

随机推荐

  1. delphi中使用webbrowser提交表单

    转自:http://blog.163.com/hehaifeng1984@126/blog/static/6900113620133504644998/ 我们以百度搜索为例,使用webbrowser组 ...

  2. NodeJs + gm图片缩略图

    我的另一篇文章: Nginx/Apache图片缩略图技术 gm官网 1, 软件环境 nodejs npm GraphicsMagick or ImageMagick 貌似ImageMagick在处理大 ...

  3. 出栈入栈动画demo

    项目做了一个切换界面动画的功能,用到了出栈入栈的,写了一个demo package com.myron.stackview; import java.util.Stack; import androi ...

  4. ajax检查用户名

    Ajax实现的效果 究竟Ajax能实现什么功能呢?今天下午学习了一下Ajax,现在跟大家分享一下我的学习心得.Ajax是什么?工作机制又是什么?可能不大准确,只是我个人看了视频学习后的一点点看法. A ...

  5. java_jdbc_反射技术将查询结果封装为对象

    package cn.itcast.Reflect; import java.lang.reflect.InvocationTargetException; import java.lang.refl ...

  6. dynamic_cast用法

    dynamic_cast < type-id > ( expression ) 该运算符把expression转换成type-id类型的对象.Type-id必须是类的指针.类的引用或者vo ...

  7. Azure CLI (一)如何安装和配置Azure CLI

    什么是Azure CLI 快速安装 Azure 命令行界面 (Azure CLI),以便使用一组基于 shell 的开源命令在 Azure 中创建和管理资源. 步骤 1:安装 . 登录https:// ...

  8. linux系统下搭建自己的web服务器

    之前在windows 2008 server上搭建了一个用于测试的web服务器,但是在打开网站的时候特别的慢,尤其是图片的加载都会失败,当时以为是路径的问题,但是在服务器上自己打开都特别慢,自己实在找 ...

  9. Java系统程序员修炼之道

    一:Java语言学习 对线程(thread),串行化,反射,网络编程,JNI技术,容器(Map,List, Iterator), 类加载器 (ClassLoader),输入输出流,垃圾回收机制, 有比 ...

  10. Jquery选择器,操作DOM

    刚接触jQuery,她真的是个好东西,操作DOM,修改样式,都很方便,主要获取DOM树的类和子代很方便. 今天用jq做了tab面包屑,不过用的是别人的代码,自己修改的,不错也做出来了,原理也有些明白, ...