C# 基础知识小结

设置操作系统日期格式

//公司电脑各式各样的都有,里面的设置也有很多不统一的,我们做软件一般会从系统中获取一些数据,比如日期时间,
//环境变量的路径参数,可以用批处理文件达到我们所想要的目的,也可以用C#代码 也可以使用批处理,拷贝到新建文本里面另存为 时间修复.reg 即可
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\International]
"iCountry"="86"
"iCurrDigits"="2"
"iCurrency"="0"
"iDate"="2"
"iDigits"="2"
"iLZero"="0"
"iMeasure"="0"
"iNegCurr"="2"
"iTime"="1"
"iTLZero"="1"
"Locale"="00000804"
"s1159"="上午"
"s2359"="下午"
"sCountry"="中华人民共和国"
"sCurrency"="¥"
"sDate"="-"
"sDecimal"="."
"sLanguage"="CHS"
"sList"=","
"sLongDate"="yyyy-MM-dd"
"sShortDate"="yyyy-MM-dd"
"sThousand"=","
"sTime"=":"
"sLongDate16"="dddd', 'MMMM' 'dd', 'yyyy"
"iTimePrefix"="0"
"iCentury"="0"
"iDayLZero"="1"
"iMonLZero"="1"
"iChinaYear"="0"
"iCalendar"="1"
"sTimeFormat"="HH:mm:ss"
"sMonDecimalSep"="."
"sMonThousandSep"=","
"iNegNumber"="1"
"sNativeDigits"="0123456789"
"NumShape"="1"
"iCalendarType"="1"
"iFirstDayOfWeek"="6"
"iFirstWeekOfYear"="0"
"sGrouping"="3;0"
"sMonGrouping"="3;0"
"sPositiveSign"=""
"sNegativeSign"="-"

[HKEY_CURRENT_USER\Control Panel\International\Geo]
"Nation"="45"
View Code

 


[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")] public static extern int GetSystemDefaultLCID(); [DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")] public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData); public const int LOCALE_SLONGDATE = 0x20; public const int LOCALE_SSHORTDATE = 0x1F; public const int LOCALE_STIME = 0x1003; public void SetDateTimeFormat() { try { int x = GetSystemDefaultLCID(); SetLocaleInfo(x, LOCALE_STIME, "HH:mm:ss"); //时间格式 SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd"); //短日期格式 SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy-MM-dd"); //长日期格式 } catch (Exception ex) { Console.WriteLine(ex); } }

 

SQL 动态添加查找条件
if object_id('test')> 0 drop table test
 
create table test 
(id int primary key ,
name nvarchar(111))
 
 
insert test 
select 1,'施瓦辛格'
union all select 2,'陈道明'
 
select * from test
 
 
ALTER proc tSDFSDFest
@name nvarchar(20) = null
as
begin
--等于
select * from test where name =  
case when @name is null OR @NAME = '' then  name else @name end
--相似
select * from test where name LIKE 
case when @name is null OR @NAME = '' then  name else  '%'+@name+'%' end
end
 
 
exec tSDFSDFest 
exec tSDFSDFest '陈道明'
exec tSDFSDFest '陈道'

 

posted @ 2013-03-24 21:34  maanshancss  阅读(830)  评论(0编辑  收藏  举报