仓酷云 发表于 2015-1-16 22:42:44

ASP.NET编程:一个Ajax.NET的查询实例

不可能天天有学习.net),我一同学说,你应该早就有作品啦。我惶惶然……ajax因轫目中只能用.net1.1,以是atlas是用不了了,只能玩玩AjaxProfession.net,上面是一查的案例。在面上安排一DataGrid1,各N查Y果均放进个中,在client真个JS中SQLZ句鹘oserver真个办法,绦幸查,K能够把持p粜惺欠裾回_一新的查。可DataGrid1的热С龅excel中、模Mgmail的Ajax的loading用
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;
usingSystem.IO;
namespaceeol
{
/**////<summary>
///index的择要形貌。
///</summary>
publicclassindex:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.TextBoxTextBox1;
protectedWebControlLibrary.InputCalendarstartTime;
protectedWebControlLibrary.InputCalendarendTime;
protectedWebControlLibrary.InputCalendarpStartTime;
protectedWebControlLibrary.InputCalendarpEndTime;
protectedSystem.Data.SqlClient.SqlConnectionConn=newSqlConnection();
protectedSystem.Web.UI.WebControls.TextBoxeformsn;
protectedSystem.Web.UI.WebControls.LabelLabel1;
protectedSystem.Web.UI.WebControls.DataGridDataGrid1=newDataGrid();
protectedSystem.Web.UI.WebControls.ButtonButton2;
protectedSystem.Web.UI.HtmlControls.HtmlInputTextapplicant;
publicstringtoExcel;

privatevoidPage_Load(objectsender,System.EventArgse)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(eol.index));
}
publicDataSetDB(stringdataName,stringsqlCmd)
{
stringconnStr="server=172.16.0.120;uid=msikdb;pwd=dbmsik;database="+dataName;
Conn.ConnectionString=connStr;
try
{
Conn.Open();
}
catch(Exceptionex)
{
Conn.Close();
Response.Write(ex.Message);
}
SqlCommandcmd=newSqlCommand(sqlCmd,Conn);
SqlDataAdapterda=newSqlDataAdapter();
da.SelectCommand=cmd;
DataSetds=newDataSet();
da.Fill(ds);
Conn.Close();
returnds;
}
WebFormO工具a生的程式a#regionWebFormO工具a生的程式a
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:此ASP.NETWebFormO工具所需的呼唤。
//
InitializeComponent();
base.OnInit(e);
}

/**////<summary>
///此樵O工具增援所必的办法-勿利用程式a器修正
///@办法的热荨
///</summary>
privatevoidInitializeComponent()
{
this.Conn=newSystem.Data.SqlClient.SqlConnection();
this.Button2.Click+=newSystem.EventHandler(this.Button2_Click);
this.DataGrid1.ItemCreated+=newSystem.Web.UI.WebControls.DataGridItemEventHandler(this.getPageIndexStyle);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion

privatevoidgetPageIndexStyle(objectsender,System.Web.UI.WebControls.DataGridItemEventArgse)
{

if(e.Item.ItemType==ListItemType.Pager)
{
e.Item.Cells.Text="TotalRow:"+this.DataGrid1.Items.Count.ToString();
}
}


publicstringAjaxData(stringsSql,boolclientEvent)
{
if(clientEvent)
{
DataGrid1.ItemDataBound+=newDataGridItemEventHandler(DataGrid1_ItemDataBound);
}
//DataGrid1.AllowPaging=true;
//DataGrid1.PagerStyle.Position=PagerPosition.Top;
//DataGrid1.PagerStyle.Mode=PagerMode.NumericPages;
//DataGrid1.ItemCreated+=newDataGridItemEventHandler(getPageIndexStyle);
DataGrid1.DataSource=DB("query",sSql);
DataGrid1.HeaderStyle.BackColor=System.Drawing.Color.Blue;
DataGrid1.Width=Unit.Percentage(100);
DataGrid1.HeaderStyle.ForeColor=System.Drawing.Color.White;
DataGrid1.DataBind();


System.Text.StringBuildersb=newSystem.Text.StringBuilder();
System.IO.StringWritersw=newSystem.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriterhtw=newHtmlTextWriter(sw);
this.DataGrid1.RenderControl(htw);
strings=sb.ToString().Replace("上午12:00:00","");
this.toExcel=s;
Session["txtExcel"]=s;
returns;
}

publicvoidsetToExcel()
{
//上面@行很主要,attachment当硎咀楦郊螺d,您能够改成online在打_
//filename=FileFlow.xls指定出文件的名Q,注重其U展名和指定文件型符合,能够椋.doc  .xls  .txt .htm  
Response.AppendHeader("Content-Disposition","attachment;filename=EOL_"+eformsn.Text+".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("big5"); 
//Response.ContentType指定文件型能够application/ms-excel,application/ms-word,application/ms-txt,application/ms-html或其他g[器可间接撑持文n 
Response.ContentType="application/ms-excel";
Response.Write(this.toExcel);
Response.Write(Session["txtExcel"]);
Session.Abandon();
Response.End();
}
privatevoidButton2_Click(objectsender,System.EventArgse)
{
setToExcel();
}
privatevoidDataGrid1_ItemDataBound(objectsender,DataGridItemEventArgse)
{
ListItemTypeitemtype=(ListItemType)e.Item.ItemType;
if(itemtype!=ListItemType.Header&&itemtype!=ListItemType.Footer&&itemtype!=ListItemType.Separator)
{
e.Item.Attributes.Add("ondblclick","showDetail("+e.Item.Cells.Text+");");
e.Item.Attributes.Add("onmou搜索引擎优化ver","this.className=mouseOn");
e.Item.Attributes.Add("onmou搜索引擎优化ut","this.className=");
}
}
}
}
Client真个js:
<scriptlanguage="javascript">
varobj=document.all;
varfrm=document.forms;
varbox=document.getElementById("detail");
varlist=document.getElementById("datagrid");
if(typeofASP=="undefined")ASP={};
ASP.LoadingDemo_class=function(){};
Object.extend(ASP.LoadingDemo_class.prototype,Object.extend(newAjaxPro.AjaxClass(),{
LongOperation:function(){
returnthis.invoke("LongOperation",{},this.LongOperation.getArguments().slice(0));
},
url:/ajaxpro/ASP.LoadingDemo,App_Web_t_mu_tej.ashx
}));
ASP.LoadingDemo=newASP.LoadingDemo_class();
varc=0;
AjaxPro.onLoading=function(b){
c++;
window.status=c;
varl=document.getElementById("loadinfo");
l.style.visibility=b?"visible":"hidden";
l.style.right=0;
l.style.pixelTop=document.body.scrollTop;
}
functionshowDetail(n){
c=0;
ASP.LoadingDemo.LongOperation(newFunction(getEolByeFormsn(+n+)));
}
functiongetDataGrid(sql,Event)
{
if(list.style.display==none)
{
list.style.display=;
}
box.style.display==?box.style.display=none:void(0);
varp=eol.index.AjaxData(sql,Event).value;
list.innerHTML=p;
}
functiongetEolByeFormsn(n)
{
if(box.style.display=="none")
{
box.style.display="";
box.innerHTML="<divid=toolbar><divid=btnGoback><imgsrc=http://172.16.0.134/webflow/images/cch.gif>GOBACK</div></div>"
}
list.style.display="none";
varp=eol.index.AjaxData("select*frommsi_eol_list_linetwhereeformsn="+n,false).value;
box.innerHTML+=p;
}
window.onload=function()
{
box.style.display="none";
list.style.display="none";
document.getElementById("btnQuery").onclick=whenQuery;
document.getElementById("btnToexcel").style.visibility="hidden";
document.getElementById("btnHelp").onclick=getHelp;
}
functiongoBack()
{
box.style.display=none;
list.style.display=;
}
functionwhenQuery()
{
vartype=document.getElementById("types");
varerr=time=param=;
varsql="selectdistinct(selectCount(eformsn)fromquery.dbo.msi_eol_list_linewhereeformsn=w.eformsn)Line,w.*from(selecteFormsn,Cast(Apply_Dateasdatetime)asApplyDate,Applicant,LOB,Cast(p_dateasdatetime)asPendingDate,processasStatusfromwebflow.dbo.tb_326_1unionselecteformsn,Cast(apply_dateasdatetime),applicant,lob,Cast(p_dateasdatetime),overasStatusfromwebflowdata.dbo.tb_326_1whereflowendstatus=E)winnerjoinquery.dbo.msi_eol_list_lineaseonw.eformsn=e.eformsnwhere(w.eformsn=e.eformsn)";
switch(type.value)
{
case"eformsn":
if(frm.eformsn.value!=)
{
param="ande.eformsn="+frm.eformsn.value+"";
}else{
err="进申翁.!"
}
break;
case"applytime":
if(frm.startTime.value==&&frm.endTime.value==)
{
err="进申起止rg";
}
break;
case"applicant":
if(frm.applicant.value!="")
{
param+="ande.applicant="+frm.applicant.value+"orderbyw.ApplyDate";
}else{
err=进申者中文名;
}
break;
case"lob":
if(frm.lob.value!="")
{
param="andw.lob="+frm.lob.value+"";
}else{
err="进LOB";
}
break;
case"pendingtime":
if(frm.pStartTime.value!=""&&frm.pEndTime.value!=""){
param="andw.PendingDatebetweencast("+frm.pStartTime.value+"asdatetime)andcast("+frm.pEndTime.value+"asdatetime)orderbyw.PendingDate";
}else{
err="进PendingTime";
}
break;
case"model":
if(frm.model.value!=){
frm.startTime.value=frm.endTime.value=;
sql=;
param="selectdistinct(selectcount(model)fromquery.dbo.msi_eol_list_linewheremodel=e.model)Total,eFormsn,Model,Applicant,LOB,Cast(Creation_dateasdatetime)asApplyDate,Cast(pending_dateasdatetime)asPendingDate,(selectStatusfrom(selecteFormsn,processasStatusfromwebflow.dbo.tb_326_1unionselecteformsn,overasStatusfromwebflowdata.dbo.tb_326_1whereflowendstatus=E)aswwherew.eformsn=e.eformsn)asStatusfromquery.dbo.msi_eol_list_lineasewheree.model="+frm.model.value+"groupbyModel,Applicant,LOB,Creation_date,Pending_Date,eformsn";
}else{
err="进Model";
}
break;
}
if(err==)
{
if(frm.startTime.value!=&&frm.endTime.value!=)
{
time="andApplyDatebetweenCast("+frm.startTime.value+"asdatetime)andCast("+frm.endTime.value+"asdatetime)";
}
sql+=time+param;
//document.write(sql);
c=0;
ASP.LoadingDemo.LongOperation(newFunction(getDataGrid("+sql+",true)));
}else{
alert(err);
}
}
varoPopup=window.createPopup();
functiongetHelp()
{
varoPopupBody=oPopup.document.body;
varlefter=screen.width-150;
vartopper=document.body.scrollTop;
oPopupBody.innerHTML=helpbox.innerHTML;
oPopup.show(lefter,topper,280,document.body.offsetHeight,document.body);
document.body.onmouseup=newFunction("oPopup.hide();");
}
</script>
呵呵,那你就关注微软的招聘信息以及别人的招聘经验啊,还有也不一定去做技术的,你如果真的想去就多了解了解。(其实我的意思是说想到微软做技术是很不容易的。

蒙在股里 发表于 2015-1-19 21:30:06

但是目前在CGI中使用的最为广泛的是Perl语言。所以,狭义上所指的CGI程序一般都是指Perl程序,一般CGI程序的后缀都是.pl或者.cgi。

再见西城 发表于 2015-1-27 09:41:31

虽然在形式上JSP和ASP或PHP看上去很相似——都可以被内嵌在HTML代码中。但是,它的执行方式和ASP或PHP完全不同。在JSP被执行的时候,JSP文件被JSP解释器(JSPParser)转换成Servlet代码,然后Servlet代码被Java编译器编译成.class字节文件,这样就由生成的Servlet来对客户端应答。所以,JSP可以看做是Servlet的脚本语言(ScriptLanguage)版。

若天明 发表于 2015-2-5 06:43:09

网页从开始简单的hmtl到复杂的服务语言,走过了10多个年头,各种技术层出不穷,单个的主流技术也在不断翻新的版本,现在分析下各种语言的区别、优势、劣势、开发注意事项!

透明 发表于 2015-2-11 07:03:52

大哥拜托,Java在95年就出来了,微软垄断个妹啊,服务器市场微软完全是后后来者,当年都是Unix的市场,现在被WindowsServer和Linux抢下大片,包括数据库也一样。

海妖 发表于 2015-3-1 23:28:07

ASP.net的服务器,要求安装一个.net环境,当然我这里指的是windows系统,顺便点一下,.net只能放在windows环境里来运行。Asp.net1.1的就装Framework1.1,Asp.net2.0的就装Framework2.0。

灵魂腐蚀 发表于 2015-3-11 01:12:57

HTML:当然这是网页最基本的语言,每一个服务器语言都需要它的支持,要学习,这个肯定是开始,不说了.

若相依 发表于 2015-3-17 17:49:25

ASP是把代码交给VBScript解释器或Jscript解释器来解释,当然速度没有编译过的程序快了。

柔情似水 发表于 2015-3-24 16:25:23

对于中小项目来说.net技术是完全可以胜任,但为什么现在大型公司或网站都选择php或java呢?就是因为微软不够开放,没有提供从硬件到应用服务器再到业务应用的整套解决方案。
页: [1]
查看完整版本: ASP.NET编程:一个Ajax.NET的查询实例