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

        /// <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. 设计模式之代理模式(Proxy Pattern)_远程代理解析

    一.什么是代理模式? 顾名思义,代理就是第三方,比如明星的经纪人,明星的事务都交给经纪人来处理,明星只要告诉经纪人去做什么,经纪人自然会想办法去做,做完之后再把结果告诉明星就好了 本来是调用者与被调用 ...

  2. kubenetes--Namespace命名空间

    Namespace(命名空间)是kubernetes系统中的另一个重要的概念,通过将系统内部的对象“分配”到不同的Namespace中,形成逻辑上分组的不同项目.小组或用户组,便于不同的分组在共享使用 ...

  3. Android 流媒体播放 live streaming

    安卓支持的协议 RTSP (RTP, SDP)HTTP/HTTPS progressive streamingDynamic adaptive streaming on HTTP => MPEG ...

  4. docker 下载加速

    执行这个命令: curl -SSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud. ...

  5. 5.python内置函数详解

    内置函数 声明,转载至这位大哥,感谢之至 http://blog.csdn.net/oaa608868/article/details/53506188 关于分类 数学运算(7个) 类型转换(24个) ...

  6. 字符串搜索 find()

    参考 <C++ Primer Plus>中文版 P870 #include <map> #include <fstream> #include <iostre ...

  7. java-斐波那契数列的解法

    public class Feibo { static long[] temp = new long[1000000]; static long fun1(int n){ if(temp[n]!=0) ...

  8. 我与网站的日常-webshell命令执行

    本文比较基础,其中有一个知识点关于php执行系统命令的函数 ,我们用最简单的webshell来说说传值问题的影响, 本文作者: i春秋签约作家——屌丝绅士 0×01前言:    小表弟又来写文章了,这 ...

  9. Dockerfile指令详解下

    VOLUME 定义匿名卷 VOLUME指令的格式为: VOLUME [,...] VOLUME 之前我们说过,容器运行时应该尽量保持容器存储层不发生写操作,对于数据库类需要保存动态数据的应用,其数据库 ...

  10. Manjaro Linux执行某些命令缺少libtinfo.so.5问题

    Manjaro默认有libtinfo.so.6而没有libtinfo.so.5,软件如果需要可执行以下命令安装: sudo pacman -S ncurses5-compat-libs #或 sudo ...