11 May 2004

TechNet月度光盘资料+贺卡+msn贴纸+TechNet体恤 被哄抢而光

前阵子换了工作,没有及时的更新TechNet的资料4月份的光盘资料被寄到原来单位去了
连同一张贺卡,msn贴纸,TechNet的体恤 昨天同事带给了我。
好消息和MM共享之... ...

随之贺卡和msn贴纸全部被没收(单人哄抢),XL号的体恤我竟然穿上象紧身装(PS:俺190多斤重的),也被剥夺,MM曰:这体恤我晚上穿出去乘凉,宽宽松松的,刚好。

55555......

一堆东西只剩下张光盘是我的了。
MM的话“微软是关心你们这些开发人员,不想让你们打光棍,这些卡啊贴纸啊的就是让你送女朋友的!”
惊人之语啊~~
当然MM也不忘抚慰一下我,把贴纸里那只美丽的MSN蝴蝶贴在我的手机上,剩下的MSN小人一个也不许我要了

07 May 2004

一个好地方~SharpLibrary

07 May 2004

一个好地方~SharpLibrary

30 Apr 2004

一个关于DataGrid的打印类,分享,感谢作者

手中的活计需要打印,就到处找找。
google中扑获,挺不错的,大家共享~
how can i print the data in DataGrid?

http://forums.aspfree.com/archive/t-17107
http://forums.aspfree.com/t17107/s.html

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;

using System.Windows.Forms;

namespace Hooooo.Print { public class DataGridPrinter { private DataGrid dataGrid; private PrintDocument printDocument; private PageSetupDialog pageSetupDialog; private PrintPreviewDialog printPreviewDialog;

public DataGridPrinter(DataGrid dataGrid) { this.dataGrid = dataGrid; printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage); }

private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int rowCount = 0; int colCount = 0; int x = 0; int y = 0; int rowGap = 20; int colGap = 5; int leftMargin = 50; Font font = new Font(“Arial”, 10); Font headingFont = new Font(“Arial”, 11, FontStyle.Underline); Font captionFont = new Font(“Arial”, 10, FontStyle.Bold); Brush brush = new SolidBrush(Color.Black); string cellValue = “”;

if(dataGrid.DataSource.GetType().ToString() == “System.Data.DataTable”) { rowCount = ((DataTable)dataGrid.DataSource).Rows.Count; } else if(dataGrid.DataSource.GetType().ToString() == “System.Collections.ArrayList”) { rowCount = ((ArrayList)dataGrid.DataSource).Count; } colCount = dataGrid.TableStyles[0].GridColumnStyles.Count;

//print caption if(dataGrid.CaptionVisible) { y += rowGap; x = leftMargin; e.Graphics.DrawString(dataGrid.CaptionText, captionFont, brush, x, y); }

//print headings y += rowGap; x = leftMargin; for(int j = 0; j < colCount; j++) { if(dataGrid.TableStyles[0].GridColumnStyles[j].Width > 0) { cellValue = dataGrid.TableStyles[0].GridColumnStyles[j].HeaderText; e.Graphics.DrawString(cellValue, headingFont, brush, x, y); x += dataGrid.TableStyles[0].GridColumnStyles[j].Width + colGap; } }

//print all rows for(int i = 0; i < rowCount; i++) { y += rowGap; x = leftMargin; for(int j = 0; j < colCount; j++) { if(dataGrid.TableStyles[0].GridColumnStyles[j].Width > 0) { cellValue = dataGrid[i,j].ToString(); e.Graphics.DrawString(cellValue, font, brush, x, y); x += dataGrid.TableStyles[0].GridColumnStyles[j].Width + colGap; y = y + rowGap * (cellValue.Split(new char[] {’\r’, ‘\n’}).Length - 1); } } } string s = cellValue; string f3 = cellValue; }

public PrintDocument GetPrintDocument() { return printDocument; }

public void Print() { try { pageSetupDialog = new PageSetupDialog(); pageSetupDialog.Document = printDocument; pageSetupDialog.ShowDialog(); printPreviewDialog = new PrintPreviewDialog(); printPreviewDialog.Document = printDocument; printPreviewDialog.Height = 600; printPreviewDialog.Width = 800; printPreviewDialog.ShowDialog(); } catch(Exception e) { throw new Exception(“Printer error.” + e.Message); }

} } }


需要打印表格线条及分页的朋友,可以看一下下面这篇文章:
 

30 Apr 2004

可以弹出确认对话框的自定义Web服务器控件ConfirmButton

经常在论坛里看到类似这样的问题:“如何在点击删除按钮的时候弹出个确认删除对话框”。

下面我们来自己写一个这样的自定义Web服务器控件!

思路如下:

继承System.Web.UI.WebControls.Button控件

增加一个属性“ConfirmMessage”来表示弹出确认框上面的提示信息。

在服务器控件呈现在页面之前把一段javascript写到页面

内容如下:

<script language="JavaScript">

<!--

function _doAspxBoyConfirm()

{

return confirm("你确认删除/保存吗??")

}

//-->

</script>

查一下msdn中对于Control.OnPreRender 方法的描述

可以得到“此方法通知服务器控件在保存视图状态和呈现内容之前,执行任何必要的预呈现步骤”.

所以我们只要在OnPreRender方法内 Page.RegisterClientScriptBlock把这段javascript发送到客户端,并且给Button. Attributes属性内添加一个“onclick”的客户端属性对应值为: "return _doAspxBoyConfirm()”.

详细情况可以查阅

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwebuiwebcontrolswebcontrolclassattributestopic.htm

这样一个具有ConFirm功能的Button就基本上建立起来了。

新建一个测试该控件的工程

在工具箱上点右键选择“添加/移除项”,点击浏览选择编译好的dll文件,点击确定,你会发现ConFirmButton已经添加到工具箱内了

将其托到一个Aspx页面内 在属性设置内给ConfirmMessage值为你要的弹出框内容比如“确定删除吗?”,按F5运行。

当点该按钮时会弹出一个confirm对话框询问“确定删除吗?,如果点击确定则执行buttonButton_Click事件,如果点击取消则不执行。

你可以查看他生成的html代码,以加深对该控件工作原理的理解

完整的代码如下:

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Text;

 

namespace AspxBoy.Com.ConfirmButton

{

       /// <summary>

       /// Button点击时会弹出一个对话框要求确认

       /// </summary>

       public class ConfirmButton : System.Web.UI.WebControls.Button

       {

              private string _confirmMessage;

              /// <summary>

              /// 当客户端点击此Button时弹出的提示消息筐的内容

              /// </summary>

              public string ConfirmMessage

              {

                     get

                     {

                            return _confirmMessage;

                     }

 

                     set

                     {

                            _confirmMessage = value;

                     }

              }

 

              protected override void OnPreRender(System.EventArgs e)

              {

                     StringBuilder sb = new StringBuilder();

                     sb.Append("<script language=\"JavaScript\">");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("<!--");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("/*--------------------------------------------");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("ControlName:\t\tAspxBoy.Com.ConfirmButton");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("AuthorName:\t\t\tHuobazi,WuMeibo");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("CopyRight:\t\t\twww.github.Com");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("---------------------------------------------*/");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("function _doAspxBoyConfirm()");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("{");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("return confirm(\"");

                     sb.Append(ConfirmMessage);

                     sb.Append("\")");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("}");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("//-->");

                     sb.Append("</script>");

                     Page.RegisterClientScriptBlock("_doAspxBoyConfirm",sb.ToString());

                     this.Attributes.Add("onclick","return _doAspxBoyConfirm()");

                     base.OnPreRender(e);

              }

              public override void RenderBeginTag(HtmlTextWriter writer)

              {

                     writer.WriteLine();

                     writer.Write("<!-------------------");

                     writer.Write("AspxBoy.Com.ConfirmButton Start");

                     writer.Write("\tAuthorName: \tHuobazi");

                     writer.WriteLine(" --------------------->");

                     writer.Write("<!-------------------- ");

                     writer.Write("Copyright:2004 Huobazi(www.github.com)");

                     writer.Write(" ---------------------");

                     writer.WriteLine(">");

                     base.RenderBeginTag(writer);

              }

              public override void RenderEndTag(HtmlTextWriter writer)

              {

                     base.RenderEndTag(writer);

                     writer.WriteLine();

                     writer.Write("<!------------------------------- ");

                     writer.Write("AspxBoy.Com.ConfirmButton  End");

                     writer.Write(" --------------------------------");

                     writer.WriteLine(">");

                     writer.WriteLine();

              }

       }

}


30 Apr 2004

可以弹出确认对话框的自定义Web服务器控件ConfirmButton

经常在论坛里看到类似这样的问题:“如何在点击删除按钮的时候弹出个确认删除对话框”。

下面我们来自己写一个这样的自定义Web服务器控件!

思路如下:

继承System.Web.UI.WebControls.Button控件

增加一个属性“ConfirmMessage”来表示弹出确认框上面的提示信息。

在服务器控件呈现在页面之前把一段javascript写到页面

内容如下:

<script language="JavaScript">

<!--

function _doAspxBoyConfirm()

{

return confirm("你确认删除/保存吗??")

}

//-->

</script>

查一下msdn中对于Control.OnPreRender 方法的描述

可以得到“此方法通知服务器控件在保存视图状态和呈现内容之前,执行任何必要的预呈现步骤”.

所以我们只要在OnPreRender方法内 Page.RegisterClientScriptBlock把这段javascript发送到客户端,并且给Button. Attributes属性内添加一个“onclick”的客户端属性对应值为: "return _doAspxBoyConfirm()”.

详细情况可以查阅

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwebuiwebcontrolswebcontrolclassattributestopic.htm

这样一个具有ConFirm功能的Button就基本上建立起来了。

新建一个测试该控件的工程

在工具箱上点右键选择“添加/移除项”,点击浏览选择编译好的dll文件,点击确定,你会发现ConFirmButton已经添加到工具箱内了

将其托到一个Aspx页面内 在属性设置内给ConfirmMessage值为你要的弹出框内容比如“确定删除吗?”,按F5运行。

当点该按钮时会弹出一个confirm对话框询问“确定删除吗?,如果点击确定则执行buttonButton_Click事件,如果点击取消则不执行。

你可以查看他生成的html代码,以加深对该控件工作原理的理解

完整的代码如下:

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Text;

 

namespace AspxBoy.Com.ConfirmButton

{

       /// <summary>

       /// Button点击时会弹出一个对话框要求确认

       /// </summary>

       public class ConfirmButton : System.Web.UI.WebControls.Button

       {

              private string _confirmMessage;

              /// <summary>

              /// 当客户端点击此Button时弹出的提示消息筐的内容

              /// </summary>

              public string ConfirmMessage

              {

                     get

                     {

                            return _confirmMessage;

                     }

 

                     set

                     {

                            _confirmMessage = value;

                     }

              }

 

              protected override void OnPreRender(System.EventArgs e)

              {

                     StringBuilder sb = new StringBuilder();

                     sb.Append("<script language=\"JavaScript\">");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("<!--");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("/*--------------------------------------------");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("ControlName:\t\tAspxBoy.Com.ConfirmButton");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("AuthorName:\t\t\tHuobazi,WuMeibo");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("CopyRight:\t\t\twww.github.Com");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("---------------------------------------------*/");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("function _doAspxBoyConfirm()");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("{");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("return confirm(\"");

                     sb.Append(ConfirmMessage);

                     sb.Append("\")");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("}");

                     sb.Append(System.Environment.NewLine);

                     sb.Append("//-->");

                     sb.Append("</script>");

                     Page.RegisterClientScriptBlock("_doAspxBoyConfirm",sb.ToString());

                     this.Attributes.Add("onclick","return _doAspxBoyConfirm()");

                     base.OnPreRender(e);

              }

              public override void RenderBeginTag(HtmlTextWriter writer)

              {

                     writer.WriteLine();

                     writer.Write("<!-------------------");

                     writer.Write("AspxBoy.Com.ConfirmButton Start");

                     writer.Write("\tAuthorName: \tHuobazi");

                     writer.WriteLine(" --------------------->");

                     writer.Write("<!-------------------- ");

                     writer.Write("Copyright:2004 Huobazi(www.github.com)");

                     writer.Write(" ---------------------");

                     writer.WriteLine(">");

                     base.RenderBeginTag(writer);

              }

              public override void RenderEndTag(HtmlTextWriter writer)

              {

                     base.RenderEndTag(writer);

                     writer.WriteLine();

                     writer.Write("<!------------------------------- ");

                     writer.Write("AspxBoy.Com.ConfirmButton  End");

                     writer.Write(" --------------------------------");

                     writer.WriteLine(">");

                     writer.WriteLine();

              }

       }

}


27 Apr 2004

打开一个Excel模板文件填充数据另存为一个文件

最近做的东西要求打开一个Excel文件模板后填充数据
开始用OleDb连接该Excel文件更新老是出错误 “需要一个可更新的.....“
http://expert.csdn.net/Expert/topic/2992/2992809.xml?temp=.4825403
如果是access这个错误多半是权限引起的 可是我做的是winform 权限是admin啊
未果
后来用ODBC测试了几个字段 都成功了
开始写程序 后发现就有那么2个单元格不听话 提示参数错误
郁闷
http://expert.csdn.net/Expert/topic/3000/3000113.xml?temp=.3331262
仍未果
没办法翻google
获得
http://www.c-sharpcorner.com/winforms/ExcelReadMG.asp
用com组件,可行哦,今早上csdn就有网友pm我问是如何搞定的
那就写到这里,
以下是部分代码,使用前要先按上文中的说明添加Com引用
...........
string strFileName = Environment.CurrentDirectory+@"\template\template.tpl";
    string strSaveFileName =
Environment.CurrentDirectory+@"\excel\"+System.DateTime.Now.ToString().Replace(":","").Replace("-","").Replace(" ","")+@".xls";
    Excel.Application ThisApplication = new Excel.ApplicationClass();
    Excel.Workbook ThisWorkBook;
    object missing = System.Reflection.Missing.Value;
    try
    { 
     //加载Excel模板文件
     ThisWorkBook = ThisApplication.Workbooks.Open(strFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
     Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];
     ThisSheet.Cells[7,1] = dtEnd.ToShortDateString();
     progressBar.Value = 30;
     ThisApplication.Visible = false;
     DataRow dr = dt.Rows[0];
     for( int i=0; i     {
      ThisSheet.Cells[7,i+2] = dr[i].ToString();
      progressBar.Value +=1;
     }
     //更新数据后另存为新文件
     ThisSheet.SaveAs(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing);
    }
    catch{}
    finally
    {
     ThisApplication.Quit();
     ThisWorkBook = null;
     ThisApplication = null;
     //dt = null;
    }
    try
    { //打开刚才生成的Excel文件
     Excel.Workbook NewWorkBook;
     NewWorkBook = NewApplication.Workbooks.Open(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
     Excel.Worksheet NewSheet = (Excel.Worksheet)NewWorkBook.Sheets[1];
     NewApplication.Visible = true;

//也可以使用System.Diagnostics.Process.Start(strSaveFileName);来打开新文件

    }

打开Excel后进程内会多出一个excel进程
需要手工清理
参考这片文章

http://www.eggheadcafe.com/articles/20021012.asp

http://www.github.com/476/archive.aspx

27 Apr 2004

打开一个Excel模板文件填充数据另存为一个文件

最近做的东西要求打开一个Excel文件模板后填充数据
开始用OleDb连接该Excel文件更新老是出错误 “需要一个可更新的.....“
http://expert.csdn.net/Expert/topic/2992/2992809.xml?temp=.4825403
如果是access这个错误多半是权限引起的 可是我做的是winform 权限是admin啊
未果
后来用ODBC测试了几个字段 都成功了
开始写程序 后发现就有那么2个单元格不听话 提示参数错误
郁闷
http://expert.csdn.net/Expert/topic/3000/3000113.xml?temp=.3331262
仍未果
没办法翻google
获得
http://www.c-sharpcorner.com/winforms/ExcelReadMG.asp
用com组件,可行哦,今早上csdn就有网友pm我问是如何搞定的
那就写到这里,
以下是部分代码,使用前要先按上文中的说明添加Com引用
...........
string strFileName = Environment.CurrentDirectory+@"\template\template.tpl";
    string strSaveFileName =
Environment.CurrentDirectory+@"\excel\"+System.DateTime.Now.ToString().Replace(":","").Replace("-","").Replace(" ","")+@".xls";
    Excel.Application ThisApplication = new Excel.ApplicationClass();
    Excel.Workbook ThisWorkBook;
    object missing = System.Reflection.Missing.Value;
    try
    { 
     //加载Excel模板文件
     ThisWorkBook = ThisApplication.Workbooks.Open(strFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
     Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];
     ThisSheet.Cells[7,1] = dtEnd.ToShortDateString();
     progressBar.Value = 30;
     ThisApplication.Visible = false;
     DataRow dr = dt.Rows[0];
     for( int i=0; i     {
      ThisSheet.Cells[7,i+2] = dr[i].ToString();
      progressBar.Value +=1;
     }
     //更新数据后另存为新文件
     ThisSheet.SaveAs(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing);
    }
    catch{}
    finally
    {
     ThisApplication.Quit();
     ThisWorkBook = null;
     ThisApplication = null;
     //dt = null;
    }
    try
    { //打开刚才生成的Excel文件
     Excel.Workbook NewWorkBook;
     NewWorkBook = NewApplication.Workbooks.Open(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
     Excel.Worksheet NewSheet = (Excel.Worksheet)NewWorkBook.Sheets[1];
     NewApplication.Visible = true;

//也可以使用System.Diagnostics.Process.Start(strSaveFileName);来打开新文件

    }

打开Excel后进程内会多出一个excel进程
需要手工清理
参考这片文章

http://www.eggheadcafe.com/articles/20021012.asp

http://www.github.com/476/archive.aspx

26 Apr 2004

关于 “编译器失败,错误代码为 128”

csdn上有位兄弟遇到这个错误了
http://expert.csdn.net/Expert/topic/3009/3009791.xml?temp=2.024478E-02
我先是搜索baidu发现一个帖子
http://www.devmanclub.com/showpost.aspx?PostID=1791
没有解决办法
翻google从gotdotnet翻出一贴 作者称其为“horrible dream”的错误,并给出解决方案

First of all, update your antivirus software and make a full scan on your computer. I guess the cause of the problem is that some hacker has entered in my computer and made some change in my account and security settings, so the sensitive asp.net found it and then stopped working.

After u are sure no viruse is in your computer, u can follow the steps below.

1. run "aspnet_regiis -ua" in the cmd. u can start the cmd from the vs.net tools in the start menu, otherwise u need type the full path.

2. remove the aspnet account from your computer

3. uninstall iis

4. restart your computer

5. reinstall iis

6. run "aspnet_regiss -i" in the cmd

7. add vs_developers group to iis operators (u can operation in iis)

8. open the file "machine.config" which is in "C:\WINNT\Microsoft.NET\Framework\v1.1.xxxx\CONFIG", then find and replace
userName="machine"
with
userName="SYSTEM"

9. restart your computer and pray silently

地址 http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=209899&Page=1#209899
记在这里,免今后自己和其他朋友遇到

---------------------------------------------------------------------------------------------------------

2004-7-1补记

我们一个客户机器也出了这个问题
咨询了微软动力营专家,专家提出2点:
//=====以下内容来字微软动力营=======
您好!
    谢谢您使用微软动力营!
    对于你的这个问题,通常都是由于以下两个原因引起的,你可以去查看一下:
1. 你的客户的机器可能感染了这个病毒
http://de.mcafee.com/root/genericVIL.asp?genericURL=/VirusInfo/VIL/dispVirus.asp&virus_k=100252
2. 你的客户的服务器运行着一些防病毒软件(象norton),这有可能导致了这个错误。


对于第一个可能,我提供的那篇网页里面提供了清除方法。对于第二个可能你可以将防病毒软件关闭掉试试。


希望对你有帮助


谭映辉 [微软] 
微软全球技术中心 微软动力营合作伙伴技术支持


使您100%满意是"微软动力营"合作伙伴支持服务的唯一目标。我们真诚希望您能够对"微软动力营"服务提出宝贵建议和意见,我们将针对您的反馈不断改进服务质量。如有任何问题,请发信至:
cmsdn@microsoft.com
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。
//=================

06 Apr 2004

弹出窗口刷新它的父页面后。出现不重新发送信息,则无法刷新网页

做的东西弹出一个窗口处理某些动作后刷新父窗口

window.opener.location.reload();
刷新
如果父窗口在此之前如果有过提交数据的动作,则会出现这么个讨厌的对话筐
“不重新发送信息,则无法刷新网页”
痛苦......
CSDN搜索未果(有几贴都是用Response.Redirect的方法,但我这里是刷父窗口)。
痛苦.
........
翻我的小本本 后找到办法

window.opener.location.href=window.opener.location.href
去刷新(其实是重定位了一下)父窗口
可行。
总结: 不能一棵树上掉死 :P