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

        /// <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. Windows Server 2012 R2部署--安装桌面体验

    Windows Server 2012 R2部署(3)---安装桌面体验 1) 打开服务器管理器 2) 选择所有服务器    3)添加角色和功能    4)下一步    5)下一步    6)下一步 ...

  2. Sql语句在SqlServer中创建数据库、表格并添加约束

    通过Sql语句来创建数据库与架构 创建数据库 数据库的创建首先是要引用主数据库的,需要在master数据库的环境下进行创建.大致的语法如下: -- 使用master数据库 use master -- ...

  3. 在Asp.Net MVC中实现上传图片并显示

    实现思路大概分为两步: 1. 通过上传接口,将图片上传到服务器,返回文件路径给客户端: 2. 点击保存上传,将文件路径保存到数据库,如果是多张图片,路径用逗号分隔. 核心上传代码: /// <s ...

  4. 【文文殿下】CF1098C Construct a tree 题解

    题解 挺水的一道题. Rating $ \color{orange} {2300}$ 以下送命题. 首先我们知道,所有子树大小之和就是节点个数加上从根到所有节点的路径长度之和. 他要求度数尽可能小,所 ...

  5. AndroidManifest.xml文件安全探索

    本文作者:i春秋签约作家——icq8756c1a2 最近在做一些apk的安全检测,对AndroidManifest.xml文件进行了研究和探讨,介绍AndroidManifest.xml文件的作用和架 ...

  6. 微信小程序redirect 到tab不刷新

    // 更新2018/11/20:现在小程序的页面栈长度为10 更正 2018/11/20: 经过一段时间的实践,我发现以前方法存在很多问题,比如 getCurrentPages 方法并不在官方的 AP ...

  7. ASP.NET MVC Forms验证机制

    ASP.NET MVC 3 使用Forms身份验证 身份验证流程 一.用户登录 1.验证表单:ModelState.IsValid 2.验证用户名和密码:通过查询数据库验证 3.如果用户名和密码正确, ...

  8. HTML简单登录和注册页面及input标签诠释

    今天第一次接触HTML这种语言,虽然不能完全理解其中的意思,过去学的英语单词几乎也忘了差不多了,但是感觉进入这门语言学习之后就没有那么难了,一步一步来吧!下面巩固下今天学内容: HTML是一种超文本标 ...

  9. html基础+常用标签

    概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...

  10. 53.storm简介

    一.简介 1.storm是twitter开源的一个分布式的实时计算系统,用于数据实时分析,持续计算,分布式RPC等等. 官网地址:http://storm-project.net 源码地址:https ...