自己构造公共程序(5)--可以设置焦点的服务器确认框
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Reflection;
using System.IO;
namespace Isd.Apple
{
/// <summary>
///
/// </summary>
public class CustomerConfirm
{
public CustomerConfirm()
{
}
#region 方法
/// <summary>
/// 功能: 可以设置焦点的确认对话框
/// 创建人: AppleGreen
/// 更新时间: 2004.11.10
/// 版本: 1.0
/// </summary>
/// <param name="strTitle">弹出对话框的标题</param>
/// <param name="strMessage">弹出对话框的消息</param>
/// <param name="intType">等于1表示焦点在确定按钮上,等于2表示焦点在取消按钮上</param>
/// <param name="intWidth">对话框的宽度</param>
/// <param name="intHeight">对话框的高度</param>
/// <param name="strBtnOKName">确认按钮上的文字</param>
/// <param name="strBtnCalName">取消按钮上的文字</param>
/// <param name="Page">父窗体的Page</param>
/// <param name="serverButtonOkName"></param>
/// <param name="serverButtonCalName"></param>
/// <param name="serverButtonCloseName"></param>
public static void Isdconfirm(string strTitle,string strMessage,string intType,string intWidth,string intHeight,string strBtnOKName,string strBtnCalName,System.Web.UI.Page Page,string serverButtonOkName,string serverButtonCalName,string serverButtonCloseName)
{
StringBuilder sb = new StringBuilder();
sb.Append("function myConfirm(strTitle,strMessage,intType,intWidth,intHeight,strBtnOKName,strBtnCalName) \n");
sb.Append("{\n");
sb.Append("var strDialogFeatures = \"status=no;center=yes;help=no;dialogWidth=\"+intWidth+\";dialogHeight=\"+intHeight+\";scroll=yes;resize=no\";\n");
sb.Append("var args = new Array();\n");
sb.Append("args[args.length] = strTitle;\n");
sb.Append("args[args.length] = strMessage;\n");
sb.Append("args[args.length] = intType;\n");
sb.Append("args[args.length] = strBtnOKName;\n");
sb.Append("args[args.length] = strBtnCalName;\n");
sb.Append("var result = showModalDialog(\""+Page.Request.ApplicationPath + "/INDEX/Web/"+"myConfirm.htm\",args,strDialogFeatures);\n");
sb.Append("return result;\n");
sb.Append("}\n");
sb.Append("var myConfirmResult = myConfirm(\""+strTitle+"\",\""+strMessage+"?\","+intType+","+intWidth+","+intHeight+",\" "+strBtnOKName+" \",\" "+strBtnCalName+" \");\n");
sb.Append("if(myConfirmResult)\n");
if(serverButtonOkName!=string.Empty) {
sb.Append("document.getElementById('"+serverButtonOkName+"').click();\n");
}
else{
sb.Append(";\n");
}
if(serverButtonCalName!=string.Empty)
{
sb.Append("else if(myConfirmResult == false)\n");
sb.Append("document.getElementById('"+serverButtonCalName+"').click();\n");
}
if(serverButtonCloseName!=string.Empty)
{
sb.Append("else\n");
sb.Append("document.getElementById('"+serverButtonCloseName+"').click();\n");
}
Page.RegisterStartupScript("ScripOpenConfirm","<script language=javascript>"+sb.ToString()+"</script>");
}
#endregion
public void ProcessRequest(HttpContext context)
{
String imageRequested = context.Request.QueryString["image"];
switch( imageRequested )
{
case "exclamation":
case "information":
case "question":
case "stop":
Assembly asm = Assembly.GetExecutingAssembly();
String resourceName = "MetaBuilders.WebControls." + imageRequested + ".gif";
context.Response.ContentType = "image/gif";
using( Stream imageStream = asm.GetManifestResourceStream(resourceName) )
{
Byte[] imageBuffer = new byte[1024];
Int32 bufferLength = 1;
Stream outputStream = context.Response.OutputStream;
while ((bufferLength > 0))
{
bufferLength = imageStream.Read(imageBuffer, 0, 1024);
outputStream.Write(imageBuffer, 0, bufferLength);
}
}
break;
}
context.Response.End();
}
}
}