学会放弃

my blog is here

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  103 随笔 :: 20 文章 :: 145 评论 :: 0 引用

公告

置顶随笔 #

摘要: 朋友的网站,原来的域名是 sitea.com,现在要换成siteb.com。当然sitea.com还未到期,要过度一段时间。网上看了这篇文章。seo网站如何实现301跳转?http://smt.fortuneage.com/uemarketer/18655-155226.aspx是这么个意思,如何在asp.net实现。 以前实现过泛域名,用的是URLRewriter,前几天看NHibernate的...阅读全文
posted @ 2010-01-07 16:55 leohuang 阅读(94) 评论(0) 编辑

2010年6月6日 #

DateTime dt = DateTime.Now;
dt.ToString();
//2005-11-5 13:21:25
dt.ToFileTime().ToString();//127756416859912816
dt.ToFileTimeUtc().ToString();//127756704859912816
dt.ToLocalTime().ToString();//2005-11-5 21:21:25
dt.ToLongDateString().ToString();//2005年11月5日
dt.ToLongTimeString().ToString();//13:21:25
dt.ToOADate().ToString();//38661.5565508218
dt.ToShortDateString().ToString();//2005-11-5
dt.ToShortTimeString().ToString();//13:21
dt.ToUniversalTime().ToString();//2005-11-5 5:21:25
dt.Year.ToString();//2005
dt.Date.ToString();//2005-11-5 0:00:00
dt.DayOfWeek.ToString();//Saturday
dt.DayOfYear.ToString();//309
dt.Hour.ToString();//13
dt.Millisecond.ToString();//441
dt.Minute.ToString();//30
dt.Month.ToString();//11
dt.Second.ToString();//28
dt.Ticks.ToString();//632667942284412864
dt.TimeOfDay.ToString();//13:30:28.4412864
dt.ToString();//2005-11-5 13:47:04
dt.AddYears(1).ToString();//2006-11-5 13:47:04
dt.AddDays(1.1).ToString();//2005-11-6 16:11:04
dt.AddHours(1.1).ToString();//2005-11-5 14:53:04
dt.AddMilliseconds(1.1).ToString();//2005-11-5 13:47:04
dt.AddMonths(1).ToString();//2005-12-5 13:47:04
dt.AddSeconds(1.1).ToString();//2005-11-5 13:47:05
dt.AddMinutes(1.1).ToString();//2005-11-5 13:48:10
dt.AddTicks(1000).ToString();//2005-11-5 13:47:04
dt.CompareTo(dt).ToString();//0
dt.Add(?).ToString();//问号为一个时间段
dt.Equals("2005-11-6 16:11:04").ToString();//False
dt.Equals(dt).ToString();//True
dt.GetHashCode().ToString();//1474088234
dt.GetType().ToString();//System.DateTime
dt.GetTypeCode().ToString();//DateTime
   
dt.GetDateTimeFormats(
's')[0].ToString();//2005-11-05T14:06:25
dt.GetDateTimeFormats('t')[0].ToString();//14:06
dt.GetDateTimeFormats('y')[0].ToString();//2005年11月
dt.GetDateTimeFormats('D')[0].ToString();//2005年11月5日
dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05
dt.GetDateTimeFormats('D')[2].ToString();//星期六 2005 11 05
dt.GetDateTimeFormats('D')[3].ToString();//星期六 2005年11月5日
dt.GetDateTimeFormats('M')[0].ToString();//11月5日
dt.GetDateTimeFormats('f')[0].ToString();//2005年11月5日 14:06
dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06
dt.GetDateTimeFormats('r')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT
string.Format("{0:d}",dt);//2005-11-5
string.Format("{0:D}",dt);//2005年11月5日
string.Format("{0:f}",dt);//2005年11月5日 14:23
string.Format("{0:F}",dt);//2005年11月5日 14:23:23
string.Format("{0:g}",dt);//2005-11-5 14:23
string.Format("{0:G}",dt);//2005-11-5 14:23:23
string.Format("{0:M}",dt);//11月5日
string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT
string.Format("{0:s}",dt);//2005-11-05T14:23:23
string.Format("{0:t}",dt);//14:23
string.Format("{0:T}",dt);//14:23:23
string.Format("{0:u}",dt);//2005-11-05 14:23:23Z
string.Format("{0:U}",dt);//2005年11月5日 6:23:23
string.Format("{0:Y}",dt);//2005年11月
string.Format("{0}",dt);//2005-11-5 14:23:23 
string.Format("{0:yyyyMMddHHmmssffff}",dt);

计算2个日期之间的天数差
-----------------------------------------------
DateTime dt1 
= Convert.DateTime("2007-8-1");    
DateTime dt2 
= Convert.DateTime("2007-8-15");   
TimeSpan span 
= dt2.Subtract(dt1);              
int dayDiff = span.Days + 1;                    
计算某年某月的天数
-----------------------------------------------    
int days = DateTime.DaysInMonth(20078);       
days 
= 31;                                      
给日期增加一天、减少一天
-----------------------------------------------
DateTime dt 
=DateTime.Now;
dt.AddDays(
1); //增加一天
dt.AddDays(-1);//减少一天
其它年份方法类似
Oracle SQL里转换日期函数
-----------------------------------------------
to_date(
"2007-6-6",'YYYY-MM-DD");
to_date("2007/6/6",'yyyy/mm/dd");

如下一组数据,如何查找表里包含9月份的记录:
CGGC_STRATDATE  CGGC_ENDDATE
=========================================
2007-8-4  2007-9-5
2007-9-5  2007-9-20
2007-9-22  2007-10-5
SELECT 
* FROM TABLE
(TO_DATE(
'2007/9/1','yyyy/mm/dd') BETWEEN CGGC_STRATDATE
AND CGGC_ENDDATE OR CGGC_STRATDATE 
>=TO_DATE('2007/9/1','yyyy/mm/dd')
AND CGGC_ENDDATE
<=TO_DATE('2007/9/30','yyyy/mm/dd'"
OR TO_DATE('2007/9/30','yyyy/mm/dd') BETWEEN CGGC_STRATDATE
AND CGGC_ENDDATE) ORDER BY CGGC_STRATDATE ASC
posted @ 2010-06-06 17:39 leohuang 阅读(23) 评论(0) 编辑

2010年3月10日 #

转:http://hi.baidu.com/zhangge9477/blog/item/1db061d4b4ec7f08a08bb7da.html

 

如题,需要详细解释!每个匹配模式都需要解释清楚,那 /g 是什么意思呀?谢谢。

还有str.replace(/^\s*(.*?)[\s\n]*$/g, '$1')的$1'是什么意思?

答:g全称是global(全部),作用是打开全局匹配,$1 等于前面匹配的()中的内容

补充知识:

i:代表不区分大小写匹配。 英文是ignore(忽略),表明在被查找的字符串中匹配样式的时候查找操作将不区分大小写。
m:代表可以进行多行匹配。 英文是multiple(多选),标志在多行的字符串中进行查找

第一个^表示从你要查找的字符串的第一位开始匹配比如123 正则为1 那么这里123的1 就匹配这个正则。。如果是213 这里213里面的1 就不匹配这个正则 \s 包括空格、制表符、换页符等空白字符的其中任意一个后面跟个*表示 可以匹配0-N次,(.*?)这个小括号里面的“.”小数点可以匹配除了换行符(\n)以外的任意一个字符而后面跟*也是说的 可以匹配0-N次后面的[\s\n]*表示这里匹配一个字符而这个字符只能是\s或者\n里面的 \n表示回车和换行符,*就不多说了 最后$表示正则匹配的结束,这个与^合起来用。,也就是说 这个匹配的字符串 必须以\s\n里面包含的字符结束
这个JS函数的作用就是正则替换。。符合正则条件的就替换成$1

replace ( string1, start, n, string2 )
参数string1:string类型,指定要使用string2替换其中一部分内容的字符串;start:long类型,指定要从哪个字符位置开始替换字符串,字符串中第一个字符的位置为1;n:long类型,指定要替换多少个字符;string2:string类型,指定用哪个字符串替换string1的部分字符返回值String。函数执行成功时返回替换后的字符串,发生错误时返回空字符串("")。如果任何参数的值为NULL,Replace()函数返回NULL。用法如果start参数指定的位置超过了string1的长度,那么Replace()函数把将string2拼接到string1的后面形成的字符串返回。如果n的值为0,那么Replace()函数把string2插入到string1指定位置后形成的字符串返回。

 

posted @ 2010-03-10 15:03 leohuang 阅读(250) 评论(0) 编辑

2010年3月2日 #

http://www.sqlusa.com/articles2005/rowversion/

Timestamp (rowversion) Data Type

By Kalman Toth, M.Phil., M.Phil., MCDBA, MCITP

November 17 , 2009

A table can have only one timestamp column. The value in the timestamp column is updated every time a row containing a timestamp column is inserted or updated. Of course this means we should not use it as a primary key, because we can get many orphans quickly if updates are performed on other columns. As a row is modified in a table, the timestamp is updated with the current database timestamp value obtained from the @@DBTS function.

Timestamp is the wrong name, quite confusing in fact. It has nothing to do with time. Microsoft will rename it rowversion in the future. Rowversion is the synonym for timestamp in SQL Server 2005 and SQL Server 2008.

It is an 8 bytes unique binary key within the database.

Here is how it looks like: 0x0000000000000743. After an update to the row: 0x0000000000000745.

The rowversion(timestamp) starts changing as soon as the transaction begins. If the transaction is rolled back, it returns to the original value.

So how can we use it?

The main purpose is row versioning in multi user environment, in other words concurrency checking.
Assume you are a developer and developing a program in Visual Basic to update the name and address table of customers. There will be 100 staff member who can perform this application function. How can you be sure that while staff A typing in the change, staff X is not changing the same row?

Here is what you do:

1. Read the name and address table including the timestamp. You display the info to the user for update and save the timestamp.
2. Certain amount of time later, like 2 minutes, the user presses the submit button after changes were typed in.
3. You open a transaction with Begin Transaction
4. You read the timestamp of the name and address row
5. You compare the current timestamp to the saved timestamp.
6. If the timestamps are same, you update the row and commit the transaction
7. If timestamps are different, you roll back the transaction and notify the user about the fact that the data was changed by someone else. You can let the user decide what to do or follow the appropriate company business rule for data entry conflict resolution.

This is pretty common practice in multi user environment. The alternate would be to examine a datetime column, or the entire row which is more processing intensive.

The following example shows timestamp (rowversion in SQL Server 2008) in action:

-- SQL Server 2008 T-SQL Code

USE tempdb;

 

-- SQL create table for Concurrency Checking demo

CREATE TABLE Celebrity (

  CelebrityID INT    IDENTITY    PRIMARY KEY,

  FirstName   VARCHAR(25),

  LastName    VARCHAR(30),

  VERSIONSTAMP  ROWVERSION)

GO

 

-- SQL insert - populate table

INSERT Celebrity (FirstName, LastName)

VALUES

('Jessica', 'Simpson'),

('Nick', 'Carter'),

('Stevie', 'Brock'),

('Christina', 'Aguilera'),

('Frank','Sinatra'),

('Doris','Day'),

('Elvis', 'Presley')

GO

 

SELECT * FROM Celebrity

GO

 

/* Results

CelebrityID FirstName   LastName    VERSIONSTAMP

1           Jessica     Simpson     0x0000000000000876

2           Nick        Carter      0x0000000000000877

3           Stevie      Brock       0x0000000000000878

4           Christina   Aguilera    0x0000000000000879

5           Frank       Sinatra     0x000000000000087A

6           Doris       Day         0x000000000000087B

7           Elvis       Presley     0x000000000000087C

*/

 

-- SQL update demo: SOMEONE UPDATED RECORD since it was read

CREATE TABLE #Semaphore (ID int identity(1,1) primary key,

                          StartVersion bigint,

                          PK int)

DECLARE @MyKey int

INSERT INTO #Semaphore (StartVersion, PK)

SELECT  VERSIONSTAMP, 1

FROM Celebrity WHERE CelebrityID=1

SELECT @MyKey = SCOPE_IDENTITY()

 

-- SIMULATION: somebody else updating the same record

UPDATE Celebrity

SET    FirstName = 'Celine',

       LastName = 'Dion'

WHERE  CelebrityID = 1

 

-- We are attempting to update.

BEGIN TRANSACTION

IF (SELECT StartVersion

    FROM   #Semaphore

    WHERE  ID = @MyKey) = (SELECT VERSIONSTAMP

                           FROM   Celebrity

                           WHERE  CelebrityID = 1)

  BEGIN

    UPDATE Celebrity

    SET    FirstName = 'Lindsay',

           LastName = 'Lohan'

    WHERE  CelebrityID = 1

    

    COMMIT TRANSACTION

  END

ELSE

  BEGIN

    ROLLBACK TRANSACTION

    PRINT 'ROLLBACK - UPDATE CONFLICT'

    RAISERROR ('Celebrity update conflict.',10,0)

  END

DELETE #Semaphore WHERE ID = @MyKey

SELECT * FROM   Celebrity

GO

/* CelebrityID    FirstName   LastName    VERSIONSTAMP

1           Celine      Dion        0x000000000000087D

2           Nick        Carter      0x0000000000000877

3           Stevie      Brock       0x0000000000000878

4           Christina   Aguilera    0x0000000000000879

5           Frank       Sinatra     0x000000000000087A

6           Doris       Day         0x000000000000087B

7           Elvis       Presley     0x000000000000087C

*/

 

-- SQL UPDATE with NO CONFLICT

DECLARE @MyKey int

INSERT INTO #Semaphore (StartVersion, PK)

SELECT  VERSIONSTAMP, 1

FROM Celebrity WHERE CelebrityID=1

SELECT @MyKey = SCOPE_IDENTITY()

 

-- We are trying to update.

BEGIN TRANSACTION

IF (SELECT StartVersion

    FROM   #Semaphore

    WHERE  ID = @MyKey) = (SELECT VERSIONSTAMP

                           FROM   Celebrity

                           WHERE  CelebrityID = 1)

  BEGIN

    UPDATE Celebrity

    SET    FirstName = 'Lindsay',

           LastName = 'Lohan'

    WHERE  CelebrityID = 1

    

    COMMIT TRANSACTION

  END

ELSE

  BEGIN

    ROLLBACK TRANSACTION

    PRINT 'ROLLBACK - UPDATE CONFLICT'

    RAISERROR ('Celebrity update conflict.',10,0)

  END

DELETE #Semaphore WHERE ID = @MyKey

SELECT * FROM   Celebrity

GO

/*

CelebrityID FirstName   LastName    VERSIONSTAMP

1           Lindsay     Lohan       0x000000000000087E

2           Nick        Carter      0x0000000000000877

3           Stevie      Brock       0x0000000000000878

4           Christina   Aguilera    0x0000000000000879

5           Frank       Sinatra     0x000000000000087A

6           Doris       Day         0x000000000000087B

7           Elvis       Presley     0x000000000000087C

*/

-- Cleanup

DROP TABLE #Semaphore

DROP TABLE Celebrity

 

 

这篇写的比较好,通过rowversion控制并发操作。
posted @ 2010-03-02 10:34 leohuang 阅读(215) 评论(0) 编辑

2010年2月24日 #

最近,工作量不是太多,自己去看点书,现在看 《Pro SQL Server 2005 Database Design and Optimization》

就是SQL Server 2005 数据库设计与优化,看书中说,是作者出的第2版了。以前一版是针对 SQL 2000的吧。

 

我现在看了前面3章,感觉写的比较详细,认真,条理性强。 查了一下,当当网也没中文版的。搞不懂,这种书为什么没人去引进,去翻译。读英文就是看起来慢,遇到一些单词要用金山词霸。如果有中文版,我肯定会去买一本。

 

上次,看的《Pro WF》的,有中文版的,后来我看了一半英文版的,又去买了一本。

 

现在开发系统与数据库打交道,这种设计优化的书其实很重要。

 

posted @ 2010-02-24 10:35 leohuang 阅读(66) 评论(1) 编辑

2010年1月7日 #

朋友的网站,原来的域名是 sitea.com,现在要换成siteb.com。当然sitea.com还未到期,要过度一段时间。网上看了这篇文章。

seo网站如何实现301跳转?http://smt.fortuneage.com/uemarketer/18655-155226.aspx

是这么个意思,如何在asp.net实现。 以前实现过泛域名,用的是URLRewriter,前几天看NHibernate的一些东西,也有朋友通过httpModules实现每个请求创建一个session连接,请求结束后释放session。

是啊,微软就提供了这么一个类似管道链的东西,一个一个Modules挨着处理。当然,也可以通过这种方法,判断只有认证过的用户才能下载对应扩展名的文件,也就是在交给最终成现之前先截获进行处理。

当然你可以自己新建一个类,继承于public class GoXueHttpModule : IHttpModule

 

public class GoXueHttpModule : IHttpModule
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        public GoXueHttpModule()
        {

        }

        #region IHttpModule 成员
        /// <summary>
        /// 释放
        /// </summary>
        public void Dispose()
        {

        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="context">http应用程序</param>
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(Context_BeginRequest);
            //关闭页面的时候
            //context.EndRequest += new EventHandler(Context_EndRequest);
        }
        #endregion

        /// <summary>
        /// 开始请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Context_BeginRequest(object sender, EventArgs e)
        {
            string url = HttpContext.Current.Request.Url.ToString();
            if (url.Contains("sitea.com"))
            {
                string url2 = url.Replace("sitea.com", "siteb.com");
                HttpContext.Current.Response.Status = "301 Moved Permanently";
                HttpContext.Current.Response.AddHeader("Location", url2);
                HttpContext.Current.Response.End();
            }
            else
            {
                HttpContext.Current.Response.Redirect(url);
            }

        }

        /// <summary>
        /// 结束请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Context_EndRequest(object sender, EventArgs e)
        {
          }

    }

 

当然,上面的红色的,可以直接写在URLRewriter.ModuleRewriter,这样既实现了二级域名,又实现了域名的变更。

同时,旧的访问方式可以不变,通过旧的搜索引擎地址过来的,也会用新的域名的网址来显示。

posted @ 2010-01-07 16:55 leohuang 阅读(94) 评论(0) 编辑

2009年12月23日 #

摘要: 最近年底,我的工作相对少点。就学一些东西吧,上个项目用的Grid++做报表工具。主要是套打发票时,调试花的时间比较长,其实,最终还是打印机的原因吧,不同的打印机,走纸的长短有时不一样,一开始用的四通的打印机,10年前一款吧,在Xp下始终套打走纸调不准,不过A4比较准的。后来,用Epson的,先是300K,再680K,不同的打印机,纸张也要调了不一样。有时候,觉得是Grid++的问题,想换一个工具,...阅读全文
posted @ 2009-12-23 14:24 leohuang 阅读(293) 评论(2) 编辑

2009年12月17日 #

摘要: 好久没有写blog,感觉今年一年都没怎么真正开心过,整天有一些事围绕在身边,使心情难以平静下来,真正写点有意义的东西。博客园是天天看的,看得多,写的少,偶尔也是Copy一篇技术文章放一下,便于自己将来查询。最近有Winfom做了一个小系统,后台数据库是用Access,主要是单机版,考虑方便性,现在总结一些值得后来人参考的地方。一,数据库操作基类一般都要写个基类,这样,将来换数据库,换一下这个DA基...阅读全文
posted @ 2009-12-17 17:01 leohuang 阅读(1107) 评论(1) 编辑

2009年12月10日 #

摘要: @lunlun童鞋今天下午在Twitter上和我说二肯工作室怎么没有网站的Logo?囧rz...其实不是我不想有,只是小为我能力有限做不出好看的LOGO啊。所以勉强只用Photoshop做了个Favicon图标放到网站上了。 小为的PS技术就不行了。做的丑了点,具体的效果你可以看下现在浏览器上面的效果。Favicon.ico是网站的图标,具体的效果可以查看二肯工作室地址栏旁边的图标。一下方法能帮...阅读全文
posted @ 2009-12-10 11:31 leohuang 阅读(625) 评论(0) 编辑

2009年11月11日 #

摘要: 利用IE 下載EXCEL 檔後,按[開啟檔案]後,會直接利用IE 打開,而不是MICROSOFT EXCEL 來打開,請問如何停用此設定。以往WINDOWS XP 可以:Open Control PanelOpen Folder OptionsClick File TypesLocate "XLS Microsoft Excel Worksheet"Click the Advanced butto...阅读全文
posted @ 2009-11-11 11:07 leohuang 阅读(195) 评论(0) 编辑

2009年10月9日 #

摘要: 5 楼bjshasha(傻傻)回复于 2003-04-28 17:54:05 得分 0 我搞定了 like this: select * from (select rownum as m,a.* from scc_user a) where m between 3 and 8 Top6 楼dawnzdy(dawn)回复于 2003-04-29 09:37:40 得分 ...阅读全文
posted @ 2009-10-09 13:00 leohuang 阅读(290) 评论(0) 编辑

仅列出标题  下一页