📄 roomfileupload.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using System.Configuration;
namespace RoomMngSystem.Operator
{
/// <summary>
/// Test2 的摘要说明。
/// </summary>
public class Test2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
protected System.Web.UI.WebControls.DropDownList DropDownList4;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.Button Button5;
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.Image Image1;
private void InitDropdownList1(System.Web.UI.WebControls.DropDownList listname,string tablename,string cellname)
{//初始化下拉列表框
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString=ConfigurationSettings.AppSettings["oCn_Str"];
try
{
conn.Open();
OdbcCommand cmd=new OdbcCommand("select distinct ["+cellname+"] from ["+tablename+"]",conn);
listname.DataTextField=cellname;
listname.DataSource=cmd.ExecuteReader();
listname.DataBind();
}
finally
{
conn.Close();
}
}
private void Page_Load(object sender, System.EventArgs e)
{
string user;
try
{
user=Session["UserName"].ToString();
}
catch
{
this.Response.Redirect("../Enter.aspx");
}
if(!IsPostBack)
{
InitDropdownList1(DropDownList1,"floorinfo","bno");
InitDropdownList1(DropDownList3,"floorinfo","bno");
InitDropdownList1(DropDownList4,"floorinfo","floor");
InitDropdownList1(DropDownList2,"floorinfo","floor");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if(""!=File1.PostedFile.FileName)
{
string filePath=File1.PostedFile.FileName;
try
{
//取得虚拟路径对应的物理路径
string mPath=Server.MapPath("../Picture/");
//设置文件名
string mFileName=DropDownList1.SelectedItem.Text+DropDownList2.SelectedItem.Text+".jpg";
//保存上传文件到指定目录
File1.PostedFile.SaveAs(mPath+mFileName);
}
catch
{
}
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
Image1.ImageUrl="../Picture/"+DropDownList3.SelectedItem.Text+DropDownList4.SelectedItem.Text+".jpg";
}
private void Button3_Click(object sender, System.EventArgs e)
{
this.Response.Redirect("RoomFloorInfoMng.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -