七月 4th, 2010  Posted at   杂七杂八
arrow   |   评论关闭arrow

应该是去年的今天(或者是昨天),我离开了我的大学,正式告别了大学生活。之后辗转到青岛(就现在住的地儿),在这工作了也快一年了。在这一年里,我得到了什么?失去了什么?我自己都说不清楚,每天就跟和尚撞钟似地,自己都感觉很无聊。吃饭-工作-睡觉三点一线,这就是现在我的生活状态。现在的生活毫无目的可言,或许是因爲我不思进取、或许是因为生活太过安逸、或许是因为我容易满足。

现在我对什么事情都没什么太大的心兴趣,想多看会儿书却看不进去、想继续提高一下自己的编码能力去只有三分钟的热度,之后就慢慢搁浅。有时还会找些借口说工作忙~~起始现在工作还真就不忙,下班后基本没什么事情可干。思来想去,还是一个字“懒”。现在很疲惫,也不知道怎么搞的~~~~~~~~~~~~

现在想想还是在大学里好啊,大学之前也不愿意去想,除了学习没别的(搞的自己学习也不咋地,囧…………)。认为大学好不是因爲还想再去上课(尽管有些老师说毕业之后的学生都会有种感觉说是想再回到课堂上,我还是比较贪玩的),我早已厌恶上课了,我在大学的课堂上还真就没学到啥东西,即使学到了也早就忘了。我想念大学是因为在哪了比较自由,还有就是非常怀念在工作室里跟那帮朋友(其中包括老孟,其实我们早就没有把他当做老师了~~~哈哈哈)呆着,自从毕业到现在已经一年不见了,现在工作室里的人绝大部分都毕业了吧,本打算在他们毕业前回去聚聚来着,结果由于种种原因搁浅了,嗨………………也不知道我们下次能全都聚在一起是什么时候了………………

二月 5th, 2010  Posted at   .NET
arrow   |   评论关闭arrow

       做导出Excel时导出成功后会遇到一个问题就是如何杀死Excel进程,用GC.Collect()回收不了,找了个杀死进程的方法。这个方法是强行将电脑中的所有Excel进程杀死。缺点是如果电脑中本来有打开的Excle文档,当使用导出Excel后调用此方法杀死进程就会将原来开着的Excel文档强行关闭。

        private void KillProcess(string processName)
        {
            System.Diagnostics.Process myproc = new System.Diagnostics.Process();
            //得到所有打开的进程
            try
            {
                foreach (Process thisproc in Process.GetProcessesByName(processName))
                {
                    if (!thisproc.CloseMainWindow())
                    {
                        thisproc.Kill();
                    }
                }
            }
            catch (Exception Exc)
            {
                Page.RegisterStartupScript(“Error”,”<script>alert(‘杀死进程失败!\n’”+Exc.Message+”);</script>”);
            }
        }

            通过KillProcess(“Excel”);调用。同样如果要杀死Word进程只需将Excel替换成Word即可

二月 5th, 2010  Posted at   .NET
arrow   |   评论关闭arrow

            添加引用:using Excel = Microsoft.Office.Interop.Excel;
                          using Microsoft.Office.Interop.Excel;

            Excel.Application application = new Excel.Application();
            Excel.Workbook book = application.Workbooks.Add(true);
            Excel.Worksheet sheet = book.ActiveSheet as Excel.Worksheet;

            Excel.Range range1 = sheet.get_Range(sheet.Cells[1, 1], sheet.Cells[2, 1]) as Excel.Range;//合并一列两行
            range1.Merge(0);
            range1.Value2 = “Test1″;

            Excel.Range range2 = sheet.get_Range(sheet.Cells[1, 2], sheet.Cells[1, 3]) as Excel.Range;//合并一行两列
            range2.Merge(true);
            range2.Columns.ColumnWidth = 20;
            range2.HorizontalAlignment = XlVAlign.xlVAlignCenter;    //居中
            range2.Value2 = “Test2″;

            Excel.Range range3 = sheet.Cells[2, 2] as Excel.Range;
            range3.Merge(true);
            range3.Value2 = “Test1″;

            Excel.Range range4 = sheet.Cells[2, 3] as Excel.Range;
            range4.Merge(true);
            range4.Value2 = “Test2″;
            string fileName = Guid.NewGuid().ToString() + “.xls”;
            string pathFileName = HttpContext.Current.Server.MapPath(fileName);
            book.SaveAs(pathFileName, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            book.Close(Type.Missing, Type.Missing, Type.Missing);
            application.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
            book = null;
            application = null;
            sheet = null;
            GC.Collect();

            HttpResponse response = HttpContext.Current.Response;
            string fileName1 = HttpContext.Current.Server.UrlEncode(“test.xls”);
            response.AppendHeader(“Content-Disposition”, “attachment; filename=” + fileName1);
            response.Charset = “UTF-8″;
            response.ContentEncoding = System.Text.Encoding.Default;
            response.ContentType = “application/ms-excel”;

            response.Clear();
            response.WriteFile(pathFileName);
            response.End();

效果图

二月 3rd, 2010  Posted at   .NET
arrow   |   评论关闭arrow

这个问题一般是由于iis与.NET Framework的安装顺序引起的。iis在.NET Framework之后安装会出现此错误。

解决:打开Visual Studio 命令提示(一般会在开始菜单中Visual Studio Tools中),然后运行aspnet_regiis -i然后重启一下IIS,看看好用不,

如果问题没有解决则在Visual Studio 命令提示中运行aspnet_regiis -ua卸载掉电脑中的.NET Framework程序,然后在上网下一个.NET Framework装上。这样一般就能搞定

十月 28th, 2009  Posted at   CSS
arrow   |   评论关闭arrow

div+css样式表的id的常用命名规则如下表所示:

页头
header
登录条
loginBar
标志
logo
侧栏
sideBar
广告
Banner
导航
nav
子导航
subNav
菜单
menu
子菜单
subMenu
搜索
search
滚动
scroll
页面主体
main
内容
content
标签页
tab
文章列表
list
提示信息
msg
小技巧
tips
栏目标题
title
加入
joinus
指南
guild
服务
service
热点
hot
新闻
news
下载
download
注册
regsiter
状态
status
按钮
btn
投票
vote
合作伙伴
partner
友情链接
friendLink
页脚
footer
版权
copyRight
 
 

实际上上面的div+css样式表的id命名也会经常用大小写和_来区分,比如主导航就是MainNav,如果还有必要在区分就是MainNav_1,MainNav_2等等。也可以使用”类型+变量名称”的规则来命名,比如写一个红色字体的class,可以.f_red {}(f是font 字体的缩写)。总之原则是:大小写、_、缩写,大大增强代码的可读性。

div+css样式表的class的常用命名规则如下表所示:

外 套
wrap
主导航
mainNav
子导航
subnav
页 脚
footer
整个页面
content
页 眉
header
商 标
label
标 题
title
主导航
mainNav
边导航
sidebar
左导航
leftsideBar
右导航
rightsideBar
旗 志
logo
标 语
banner
菜单内容
menu1Content
菜单容量
menuContainer
子菜单
submenu
边导航图标
sidebarIcon
注释
note
面包屑
breadCrumb
容器
container
内容
content
搜索
search
登陆
login
功能区
shop
当前的
current
 
 
九月 27th, 2009  Posted at   杂七杂八
arrow   |   评论关闭arrow

window.opener用法:
A窗口有一个链接Show Next Page,点击链接后弹出B窗口,在B窗口中有一关闭按钮,点击关闭按钮后B页面关闭然后刷新A窗口。
代码:
A页面代码:
<script type=”text/javascript”>
function openNewWindow(strfileName)
{
var url = strfileName ;
var screenw=screen.width;
var screenh=screen.height;
var mw=screenw-11;
var mh=screenh-78;
nwin = window.open(url, null, “top=0,left=0,Width=”+ mw +”,Height=”+ mh +”,status=yes”)
}
</script>
<a style=”cursor:hand” onclick=”openNewWindow(‘B.htm’)”>Show Next Page</a>
B页面代码:
<input onclick=”closed();” type=”button” value=”Close” />
<script type=”text/javascript”>
function closed()
{
if(!window.opener.closed)//判断A页面是否关闭
{
window.opener.location.reload();//刷新A页面
//window.opener.location = window.opener.location;//另一种写法
}
window.close();
}
//如果想点击B页面中的关闭按钮实现刷新A页面,添加如下代码 window.onbeforeunload   =   function()
{
var   n   =   window.event.screenX   -   window.screenLeft;
var   b   =   n   >   document.documentElement.scrollWidth-20;
if(b   &&   window.event.clientY <  0 || window.event.altKey)
{
if(!window.opener.closed)//判断A页面是否关闭
{
window.opener.location.reload();//刷新A页面
//window.opener.location = window.opener.location;//另一种写法
}
window.close();
}
}
</script>
window.opener只能是以open形式打开窗口时才能用,
window.open的一些参数:
‘B.htm’ 弹出窗口的文件名;
‘newwindow’ 弹出窗口的名字(不是文件名),非必须,可用null代替,如果想打开多次B页面只需吧newwindow的值改变就可以;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

如果A页面的链接弹出的是B页面时一个框架结构,在B中有子框架C,如果关闭C页面同时关闭B页面,然后刷新A页面那么得用window.parent。
具体做法是,在C页面中写代码:
window.parent.opener.location = window.parent.opener.location;
window.parent.close();
如果是只刷新父框架页面则:
window.parent.location = window.parent.location;

九月 13th, 2009  Posted at   .NET
arrow   |   评论关闭arrow

(1) Helper扩展
public ActionResult HtmlHelper()
{
this.ViewData["Name"] = “Fanxinfu”;
var employees = new List<object>
{
new {ID = 1,Name = “xiao fu”},
new {ID = 2,Name = “zhanshen”},
new {ID = 3,Name = “daqing”},
new {ID = 4,Name = “laomeng”},
};
return this.View();
}
<%= Html.TextBox(“Name”) %>
<%= Html.DropDownList(“Employees”) %>

<%= Html.ActionLink(“Go Back To Index”,”Index”) %>
//跳转到Index
<hr />
<%= Html.ActionLink(“Go Back To Index with id=1″, “Index”, new { id=1})%><br />
//跳转到Index,同时传递id参数
<%= Html.ActionLink(“Go back to Index”,”Index”,new{},new{style=”color:red;”}) %>
//跳转到Index,设置连接颜色为红色。个人认为由于ActionLink并没有设置(链接文字,链接地址,连接颜色)的重载,只有(链接文字,链接地址,参数,连接颜色)所以设置了一个new{}空对象
<hr />
<% using (Html.BeginForm(“Index”,”form1″,FormMethod.Post)) {%>
<%= Html.TextBox(“textBox_simple”) %>
<%} %>
//输出一个form表单,必须用using
(2) Routing规则
routes.IgnoreRoute(“Home/About”);//取消路径
(3) 不同方式的循环输出(脚本或控件)
public ActionResult ScriptOrNot()
{
this.ViewData["Number"] = new int[] { 1, 2, 3, 4, 5, 6 };
return View();
}

protected void Page_Load(object sender, EventArgs e)
{
this.rptNumbers.DataSource = this.Numbers;
this.rptNumbers.DataBind();
}
public int[] Numbers
{
get
{
return (int[])this.ViewData["Number"];
}
}

//脚本输出
<% for (int i = 0; i < this.Numbers.Length; i++)
{ %>
<%= this.Numbers[i] %>
<% if (i != this.Numbers.Length – 1)
{%>
,
<%} %>
<%} %>
//控件输出
<asp:Repeater runat=”server” ID=”rptNumbers”>
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
(4) ViewData强类型输出
//创建一个类
public class TypedIndexViewData
{
public string Title { get; set; }

public string Message { get; set; }
}
//设置类属性值
public ActionResult TypedIndex()
{
var viewData = new TypedIndexViewData
{
Title = “Home Page”,
Message = “Welcome to ASP.NET MVC!”
};
return View(viewData);
}
//输出
<%= Html.Encode(Model.Message) %>

八月 21st, 2009  Posted at   .NET
arrow   |   评论关闭arrow

在GridView控件的<Columns></Columns>之外加入代码:

<PagerTemplate>
<asp:LinkButton ID=”btnFirst” runat=”server” CausesValidation=”False” CommandArgument=”First” CommandName=”Page”>首页</asp:LinkButton>
<asp:LinkButton ID=”btnPrev” runat=”server” CausesValidation=”False” CommandArgument=”Prev” CommandName=”Page”>上一页</asp:LinkButton>
<asp:LinkButton ID=”btnNext” runat=”server” CausesValidation=”False” CommandArgument=”Next” CommandName=”Page”>下一页</asp:LinkButton>
<asp:LinkButton ID=”btnLast” runat=”server” CausesValidation=”False” CommandArgument=”Last” CommandName=”Page”>尾页</asp:LinkButton>
第<asp:Label ID=”lbpage” runat=”server” Text=” <%#((GridView)Container.Parent.Parent).PageIndex + 1 %>”> </asp:Label>页
共<asp:Label ID=”lbpagecount” runat=”server” Text=” <%# ((GridView)Container.Parent.Parent).PageCount %>”></asp:Label>页
跳到<asp:TextBox ID=”txtPage” runat=”server” Text=” <%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>” Width=”27px”></asp:TextBox>
<asp:LinkButton ID=”btnGO” runat=”server” CausesValidation=”False” CommandArgument=”-1″ CommandName=”Page” Text=”GO”></asp:LinkButton>
</PagerTemplate>

之后再控件的PageIndexChangin事件中加入代码:(pagesize为公共变量)

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (Session["pagesize"] == “”)
{
if (e.NewPageIndex < 0)
{
pagesize = 0;
}
else if (e.NewPageIndex > GridView1.PageCount – 1)
{
pagesize = GridView1.PageCount – 1;
}
else
{
pagesize = e.NewPageIndex;
}
}
else
{
pagesize = Convert.ToInt32(Session["pagesize"].ToString());
Session["pagesize"] = “”;
}
BindGridView(pagesize);//绑定GridView数据
}

再在RowCommand事件中加入代码:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “Page”)
{
if (e.CommandArgument == “-1″)
{
int page = Convert.ToInt32(((TextBox)GridView1.BottomPagerRow.FindControl(“txtPage”)).Text.ToString()) – 1;
Session["pagesize"] = page;
}
}
}

八月 18th, 2009  Posted at   .NET
arrow   |   评论关闭arrow

首先在当前目录下创建一个Table.xls的模板文件。

添加引用
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
using System.IO;

protected void btnExport_Click(object sender, EventArgs e)
{
string templateFilePath = MapPath(“Table.xls”);
Excel.Application appliction = new Application();
Excel.Workbook book = appliction.Workbooks.Add(templateFilePath);
Excel.Worksheet sheet = book.ActiveSheet as Excel.Worksheet;

//设置Excel中第一行,第一列的内容
Excel.Range range1 = sheet.Cells[1, 1] as Excel.Range;
range1.Value2 = “aa”;
//设置单元格中内容左对齐
range1.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
//设置单元格的背景颜色,16代表灰色
range1.Interior.ColorIndex = 16;
//设置Excel中第一行,第二列的内容
Excel.Range range2 = sheet.Cells[1, 2] as Excel.Range;
range2.Value2 = “bb”;

//设置Excel中第二行,第一列的内容
Excel.Range range3 = sheet.Cells[2, 1] as Excel.Range;
range3.Value2 = “cc”;
//设置Excel中第二行,第二列的内容
Excel.Range range4 = sheet.Cells[2, 2] as Excel.Range;
range4.Value2 = “dd”;
string tmpfilePath = SaveAndCloseBook(book);
RenderExcelFile(tmpfilePath, “Table.xls”);
DeleteFile(tmpfilePath);
}

public static string SaveAndCloseBook(Workbook book)
{
string pathFileName = GenerateTempExcelFileName();
book.SaveAs(pathFileName, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
book.Close(Type.Missing, Type.Missing, Type.Missing);

return pathFileName;
}

public static string GenerateTempExcelFileName()
{
string fileName = Guid.NewGuid().ToString() + “.xls”;
string pathFileName = HttpContext.Current.Server.MapPath(fileName);
return pathFileName;
}

public static void RenderExcelFile(string pathFileName, string clientFileName)
{
HttpResponse response = HttpContext.Current.Response;
string fileName = HttpContext.Current.Server.UrlEncode(clientFileName);
response.AppendHeader(“Content-Disposition”, “attachment; filename=” + fileName);
response.Charset = “UTF-8″;
response.ContentEncoding = System.Text.Encoding.Default;
response.ContentType = “application/ms-excel”;

response.Clear();
response.WriteFile(pathFileName);
response.Flush();
}

public static void DeleteFile(string pathFileName)
{
if (!string.IsNullOrEmpty(pathFileName))
{
File.Delete(pathFileName);
}
}

七月 13th, 2009  Posted at   杂七杂八
arrow   |   评论关闭arrow
ASP(特指VBS)里自带了两个函数:
LCase:转成小写
UCase:转成大写

<%
dim str,str1,str2
str="AbCdEfGHiJkLmnOpQ"
str1=LCase(str)
str2=UCase(str)
Response.write(str1 & "," & str2)
%>

完整的代码(含FSO)
<%
Dim fso,r,content,w
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set r=fso.OpenTextFile(Server.MapPath("text1.txt"))
content = r.ReadAll
Response.Write("<hr>原文:" & content)
r.close
set r=nothing
Set w=fso.CreateTextFile(Server.MapPath("text2.txt"))
content = UCase(content)
w.Write content
w.close
set w=nothing
set fso=nothing
Response.Write("<hr>大写:" & content)
Response.Write("<hr>以上内容已保存到text2.txt")

tablename = trim(request.Form("tablename"))
fieldname = trim(request.Form("fieldname"))
mainname = trim(request.Form("mainname"))
if tablename = "" or fieldname = "" or mainname = "" then
response.Write("输入不合法~")
else
set rs = server.CreateObject("adodb.recordset")
sql = "select * from "&tablename
rs.open sql,conn,1,3
do while not rs.eof
str1 = UCase(rs(fieldname))
sql1 = "update "&tablename&" set "&fieldname&" = '"&str1&"' where "&mainname&" = "&rs(mainname
)
'response.Write(sql1)
conn.execute(sql1)
rs.movenext
loop
rs.close
conn.close
set conn = nothing
response.Write("转化成功")
end if