项目用到的知识点总结,欢迎大家吐槽:

        /// <summary>
/// 转换非yyyy-MM-dd的字符串为DateTime类型
/// </summary>
        public static void ConvertDateFormat() {
string orginStr = "test-test-20130607.xls";
string dateStr = orginStr.Split('-')[2].Split('.')[0];
Console.WriteLine(dateStr);
Console.WriteLine(DateTime.ParseExact(dateStr, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-M-d"));
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

相关资料:

http://www.jb51.net/article/37007.htm

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx

 

 

        /// <summary>
/// get the days of currDate minus lastDate;The result is negative is allowed
/// </summary>
/// <param name="lastDateStr"></param>
/// <param name="currDateStr"></param>
/// <returns></returns>
private int minusTwoDate(string lastDateStr,string currDateStr) {
DateTime lastDate = Convert.ToDateTime(lastDateStr);
DateTime currDate = Convert.ToDateTime(currDateStr);
return (currDate - lastDate).Days;
}

 

       /// <summary>
/// judage whether cross the month;cross:true;
/// </summary>
/// <param name="lastDateStr">the last page recorded</param>
/// <param name="currDateStr"></param>
/// <returns></returns>
private bool whetherCrossMonth(string lastDateStr, string currDateStr)
{
DateTime lastDate = Convert.ToDateTime(lastDateStr);
DateTime currDate = Convert.ToDateTime(currDateStr);
if (currDate.Month == lastDate.Month)//the same month
{
return false;
}
else
{
return true;
}
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

        /// <summary>
/// is last day:true;is not last day:false and return last date of month
/// </summary>
/// <param name="lastDateStr"></param>
/// <param name="lastDayOfMonth">the last day of month or null</param>
/// <returns>is last day:true;or false</returns>
private bool wetherIsLastDay(string lastDateStr,out string lastDayOfMonth)
{
DateTime lastPageDate = Convert.ToDateTime(lastDateStr);
//first day of month
string lastDay = string.Empty;
DateTime lastDateOfMonth = Convert.ToDateTime(lastPageDate.Year + "-" + lastPageDate.Month + "-" + DateTime.DaysInMonth(lastPageDate.Year, lastPageDate.Month));
if ((lastDateOfMonth-lastPageDate).Days>0)
{
lastDayOfMonth =lastDateOfMonth.ToShortDateString();;
return false;
}// less than The last day of each month
else
{
lastDayOfMonth = lastDay;
return true;
}//
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

sqlite方面:

//sql。如果businessDate字段不格式化为yyyy-MM-dd,则在max()对此字段取值会
//出现2013-1-9大于2013-1-10、2013-1-20的情况
sqlList.Add(String.Format("insert into test(businessName,businessDate,indb_datetime) values('{0}','{1}','{2}')", EventOrderKeyStr, fileDate.ToString("yyyy-MM-dd"), DateTime.Now.ToString())); //入库环节
DBHelperSqlite dhSqlite = new DBHelperSqlite();
dhSqlite.ExecuteSqlTran(sqlList);

 

dbhelper:

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

        private string dbName = "cmcc2.db";
private string connectionString = "Data Source=cmcc2.db;Pooling=true;FailIfMissing=false";
/// <summary>
/// if the db is not exists,create it and create the table
/// </summary>
public DBHelperSqlite()
{
string SQLCreateStr = "CREATE TABLE [cmcc_businesses_info] (businessName nvarchar(50),businessDate nvarchar(10),indb_datetime nvarchar(20))"; #region CASE2
FileInfo fi = new FileInfo(dbName);
if (fi.Exists == false)
{
logger.InfoFormat("db不存在");
//Console.WriteLine("db不存在");
SQLiteConnection.CreateFile(dbName);
logger.InfoFormat("db创建完成");
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(SQLCreateStr, conn))
{
if (cmd.ExecuteNonQuery() > 0)
{
logger.InfoFormat("表创建成功");
//Console.WriteLine("表创建成功");
}
}
}
}
#endregion
}//ctor /// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">多条SQL语句</param>
public void ExecuteSqlTran(IList<string> SQLStringList)
{
using (SQLiteConnection conn = new SQLiteConnection(connectionString))
{
conn.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
SQLiteTransaction tran = conn.BeginTransaction();
cmd.Transaction = tran;
try
{
for (int n = 0; n < SQLStringList.Count; n++)
{
string strsql = SQLStringList[n].ToString();
if (strsql.Trim().Length > 1)
{
logger.Debug(strsql);
cmd.CommandText = strsql;
cmd.ExecuteNonQuery();
}
}
tran.Commit();
}
catch (System.Data.SQLite.SQLiteException ex)
{
logger.Error(ex);
tran.Rollback();
//throw new Exception(ex.Message);
}
}
}//trans
SubString函数使用时一个隐藏的“雷”:
        /// <summary>
/// str.Substring(startIndex,length)如果length大于str的长度,就会报错
/// </summary>
public static void SubstringTest2()
{
string str = "4.333";
string[] r = str.Split('.');
if (r.Length == 2)
{
if (r[1].Length > 4)
{
r[1] = r[1].Substring(0, 4);
} Console.WriteLine(r[0] + "." + r[1]);
} }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

c# winform项目用到的部分知识点总结的更多相关文章

  1. Winform项目调用asp.net数据接口

    最近一个WPF项目需要改写成android项目,思路是在asp.net项目中编写一个通用接口,便于其它平台下调用数据.刚接触到这些东西的时候完全是一头雾水,最根本的原因是不明白网站中的一个网页,为什么 ...

  2. NPOI导入导出EXCEL通用类,供参考,可直接使用在WinForm项目中

    以下是NPOI导入导出EXCEL通用类,是在别人的代码上进行优化的,兼容xls与xlsx文件格式,供参考,可直接使用在WinForm项目中,由于XSSFWorkbook类型的Write方法限制,Wri ...

  3. 循序渐进开发WinForm项目(6)--开发使用混合式Winform模块

    1.Winform数据访问模式定义 传统的Winform程序模块:用于传统的数据库通讯获取数据,这种方式获取数据,方便快捷,可以用于常规的业务系统的场景,用于单机版软件或者基于局域网内的业务系统软件. ...

  4. 电梯多媒体WinForm项目Q&A总结

    最近,我给一家公司做了个电梯多媒体软件,该软件使用C#编写,现在我将其中遇到的问题及其解决方法总结一下,以便下次再遇到同样的问题可以快速解决:同时,也给博友分享一下,共同学习,共同提高. 1.Ques ...

  5. 循序渐进开发WinForm项目(5)--Excel数据的导入导出操作

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  6. 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  7. 循序渐进开发WinForm项目(3)--Winform界面层的项目设计

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  8. 循序渐进开发WinForm项目(2)--项目代码的分析

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  9. 循序渐进开发WinForm项目(1) --数据库设计和项目框架的生成

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

随机推荐

  1. 解决微服务网关Ocelot使用AddStoreOcelotConfigurationInConsul后请求404问题

    一个小插曲,最近研究 netcore 微服务网关,在使用AddStoreOcelotConfigurationInConsul将配置存到consul后,任何经过网关的请求都出现404,并且没有任何有用 ...

  2. asp .net api 日志

    方法1:继承IExceptionLogger ExceptionLogger是框架提供的表示未处理的异常记录器的抽象类 public class RecordExceptionLogger : Exc ...

  3. .net core初试 --- 控制台程序

    .net core这个名字对.net程序员来说都不陌生了,但貌似圈子里真正有开发经验的并不多,关键是公司的项目没需求. 今天我就趁着不忙上手玩了玩,搞明白了一些东西,心中也有了十万个为什么.那么现在与 ...

  4. Win(Phone)10开发第(1)弹,桌面和手机的扩展API,还我后退键

    喜大普奔的win10 uap开发预览版终于出了,这次更新跟8.1的变化不是很大,但是将原本win8.1和wp8.1uap的分项目的形式,改为了整合成一个项目,经过一次编译打包成一个appx包,实现了无 ...

  5. XML Web Service架构图

  6. c# 合并重叠时间段的算法

    c# 合并重叠时间段的算法 一.采用非排序: 方案一: 使用递归算法,如不喜欢递归的伙伴们,可以使用whie代替. 1.文件:Extract_Chao.cs(核心) using System; usi ...

  7. 盘点Xcode中开发者最喜爱的十大开源插件

    Xcode IDE拥有着诸如导航.重构.校准等众多非常高大上的工具,而予以辅助的插件更是在Xcode的基础上对相关功能进行改进与扩展.在应用开发过程中,通过开源包管理器Alcatraz对插件进行安装管 ...

  8. Exp2 后门原理与实践 20164321 王君陶

    Exp2 后门原理与实践 20164321 王君陶 一.实验内容 基础问题回答: 1.例举你能想到的一个后门进入到你系统中的可能方式? 答:通过漏洞,点击陌生链接,或者浏览不良网页挂马. 2.例举你知 ...

  9. Flask从入门到精通之自定义错误界面

    如果你在浏览器的地址栏中输入了不可用的路由,那么会显示一个状态码为404 的错误页面.现在这个错误页面太简陋.平庸,而且样式和使用了Bootstrap 的页面不一致. 像常规路由一样,Flask 允许 ...

  10. vsftp小记

    安装一个vsftp都有问题(Version: 3.0.2-14ubuntu1),提示530 错误,之后修改配置如下(红色): # cat /etc/pam.d/vsftpdauth required ...