📄 mainunit.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;
namespace OI.SendMessage
{
/// <summary>
/// MainUnit 的摘要说明。
/// </summary>
public class MainUnit : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.Button ButtonAdd;
protected System.Web.UI.WebControls.Button ButtonSub;
protected System.Web.UI.WebControls.ListBox ListBoxUnit;
protected System.Web.UI.HtmlControls.HtmlInputHidden parentid;
protected OI.UserControls .Department DepartmentGet;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (Session["userid"]==null)
{
Response.Write ("<script>alert('超时,请重新登录');top.location.href='../userpass.aspx';</script>");
return ;
}
if (!Page.IsPostBack )
{
try
{
ViewState["parentID"]=Request.Params ["parentid"].ToString ();
parentid.Value =ViewState["parentID"].ToString ();
}
catch
{
ViewState["parentID"]=null;
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
this.ButtonSub.Click += new System.EventHandler(this.ButtonSub_Click);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
// bool isHave=false;
// string strValue="";
// for(int i=0;i<ListBoxUnit.Items .Count ;i++)
// {
// if(i==0)
// {
// isHave=true;
// strValue=ListBoxUnit.Items [i].Value ;
// }
// else
// {
// strValue+=","+ListBoxUnit.Items [i].Value ;
// }
//
// }
// if(!isHave)
// {
// Page.RegisterStartupScript ("","<script>alert('列表框中没有部门')</script>");
// return;
// }
// if (ViewState["parentID"]==null)
// {
// string javascript="<script>opener.Form1.TextBoxMainRecord.value=\""+ strValue +"\";window.close();</script>";
// Page.RegisterStartupScript ("",javascript);
// }
//Page.RegisterStartupScript ("","<script>ControlParentElement(1,1)</script>");
returnValues();
}
private void returnValues()
{
string Javascript="";
if (ListBoxUnit.Items .Count <1)
{
Page.RegisterStartupScript ("","<script>alert('列表框中没有部门')</script>");
return;
}
else
{
Javascript="<script>" ;
foreach ( ListItem li in ListBoxUnit.Items)
{
Javascript += "ControlParentElement('"+li.Value+"','"+li.Text+ "');";
}
Javascript +="</script>";
Response.Write (Server.HtmlEncode( Javascript));
Page.RegisterStartupScript ("",Javascript);
}
}
private void ButtonAdd_Click(object sender, System.EventArgs e)
{
if(DepartmentGet.DEPT_ID ==0)
{
Page.RegisterStartupScript ("","<script>alert(\"不能选择‘开始’,请重新选择部门\")</script>");
return;
}
ListItem li=new ListItem (DepartmentGet.DEPT_NAME);
if(ListBoxUnit.Items .FindByValue (li.Value )==null&&(li.Value !=null||li.Value !=""))
ListBoxUnit.Items .Add (li);
ListBoxUnit.SelectedIndex =-1;
}
private void ButtonSub_Click(object sender, System.EventArgs e)
{
int nCount=0;
foreach(ListItem li in ListBoxUnit.Items )
{
if(li.Selected )
{
nCount++ ;
}
}
string[] strText=new string [nCount];
nCount=0;
foreach(ListItem li in ListBoxUnit.Items )
{
if(li.Selected )
{
strText[nCount++]=li.Text ;
}
}
for(int i=0;i<nCount;i++)
{
ListBoxUnit.Items .Remove (ListBoxUnit.Items .FindByText (strText[i]));
}
ListBoxUnit.SelectedIndex =-1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -