时间:2016-02-15 21:33 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP.NET的适配器设计模式(Adapter)应用详解】,下面是详细的讲解!
ASP.NET的适配器设计模式(Adapter)应用详解
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page
{
string offLight="~/Images/Light_C.gif";
string onLight="~/Images/Light_O.gif";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBoxSwitch_CheckedChanged(object sender, EventArgs e)
{
var cb=(CheckBox)sender;
//插座缺少电压为220伏
int input=Convert.ToInt32(string.IsNullOrEmpty(this.TextBox1.Text.Trim()) ? "220" : this.TextBox1.Text.Trim());
//开关打开
if (cb.Checked)
{
try
{
//实例一个电灯
Light light=new Light();
//插入插座,使用插座电压
light.InputVoltage=input;
//电灯被打开
this.Image1.ImageUrl=onLight;
//显示正常输出电压
this.Label1.Text=light.InputVoltage.ToString();
}
catch (Exception ex)
{
//如果电压不正常,电灯打不开或是被烧坏。
this.Image1.ImageUrl=offLight;
//显示异常信息。
this.Label1.Text=ex.Message;
}
try
{
Light light=new Light();
//使用电源适配器
PowerAdapter pa=new PowerAdapter(light);
pa.InputVoltage=input;
this.Image2.ImageUrl=onLight;
this.Label2.Text=pa.InputVoltage.ToString();
}
catch (Exception ex)
{
this.Image2.ImageUrl=offLight;
this.Label2.Text=ex.Message;
}
this.TextBox1.Enabled=false;
}
//开关关闭
else
{
this.TextBox1.Text=string.Empty;
this.TextBox1.Enabled=true;
this.Image1.ImageUrl=offLight;
this.Image2.ImageUrl=offLight;
}
}
}
关于ASP.NET的适配器设计模式(Adapter)应用详解的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【服务器】asp.net页面状态管理cookie和服务器状
- 【客户端】获取客户端IP地址c#/vb.net各自实现代
- 【NET】10个.NET中删除空白字符串的方法-删除空白
- 【asp】asp.net 计划任务管理程序实现,多线程任务
- 【asp】asp.net读取磁盘文件、删除实例代码-net-
- 【TextBox】Asp.net TextBox的TextChanged事件使
- 【Forms身份认证】Forms身份认证在IE11下无法保存
- 【B2B】asp.net B2B网站对接支付宝接口-支付宝接
- 【GridView】GridView使用CommandField删除列实现
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
