📄 organization.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 BusinessRules;
namespace xx8910
{
/// <summary>
/// Organization 的摘要说明。
/// </summary>
public class Organization : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtQueryWithKey;
protected System.Web.UI.WebControls.Button btnQueryWithKey;
protected System.Web.UI.WebControls.TextBox txtQueryWithCond;
protected System.Web.UI.WebControls.Button btnQueryWithCond;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Button btnInsertGiveUp;
protected System.Web.UI.WebControls.Button btnInsertOk;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Button btnEditGiveUp;
protected System.Web.UI.WebControls.Button btnEditOk;
protected System.Web.UI.WebControls.Panel Panel3;
protected System.Web.UI.WebControls.Label lOrganizationID;
protected System.Web.UI.WebControls.Label lOrganizationTypeID;
protected System.Web.UI.WebControls.Label lSuperiorID;
protected System.Web.UI.WebControls.Label lOrganizationName;
protected System.Web.UI.WebControls.Label lRemark;
protected System.Web.UI.WebControls.TextBox txtInsertOrganizationID;
protected System.Web.UI.WebControls.TextBox txtInsertSuperiorID;
protected System.Web.UI.WebControls.TextBox txtInsertOrganizationName;
protected System.Web.UI.WebControls.TextBox txtInsertRemark;
protected System.Web.UI.WebControls.TextBox txtEditOrganizationID;
protected System.Web.UI.WebControls.TextBox txtEditOrganizationName;
protected System.Web.UI.WebControls.TextBox txtEditRemark;
protected System.Web.UI.WebControls.TextBox txtEditSuperiorID;
protected System.Web.UI.WebControls.DropDownList drpInsertOrganizationTypeID;
protected System.Web.UI.WebControls.DropDownList drpEditOrganizationTypeID;
protected System.Web.UI.WebControls.Button btnQueryAll;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
this.Bind();
}
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnQueryWithKey.Click += new System.EventHandler(this.btnQueryWithKey_Click);
this.btnQueryWithCond.Click += new System.EventHandler(this.btnQueryWithCond_Click);
this.btnQueryAll.Click += new System.EventHandler(this.btnQueryAll_Click);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.btnInsertOk.Click += new System.EventHandler(this.btnInsertOk_Click);
this.btnEditOk.Click += new System.EventHandler(this.btnEditOk_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region 绑定DataGrid数据
void Bind()
{
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
this.DataGrid1.DataSource=myOrganization.Query();
this.DataGrid1.DataBind();
}
#endregion
#region 绑定DropDownList数据OrganizationTypeID
void drpBindForOrganizationTypeID()
{
//BusinessRules.Organization myOrganization=new BusinessRules.Organization();
BusinessRules.OrgaType myOrgaType=new BusinessRules.OrgaType();
this.drpInsertOrganizationTypeID.DataSource=myOrgaType.Query();
this.drpInsertOrganizationTypeID.DataTextField="OrganizationTypeID";
this.drpInsertOrganizationTypeID.DataValueField="OrganizationTypeID";
this.drpInsertOrganizationTypeID.DataBind();
this.drpEditOrganizationTypeID.DataSource=myOrgaType.Query();
this.drpEditOrganizationTypeID.DataTextField="OrganizationTypeID";
this.drpEditOrganizationTypeID.DataValueField="OrganizationTypeID";
this.drpEditOrganizationTypeID.DataBind();
}
#endregion
private void btnQueryAll_Click(object sender, System.EventArgs e)//查询所有
{
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
this.Bind();
}
private void btnQueryWithCond_Click(object sender, System.EventArgs e)//条件查询
{
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
this.DataGrid1.DataSource=myOrganization.Query(this.txtQueryWithCond.Text);
this.DataGrid1.DataBind();
}
private void btnQueryWithKey_Click(object sender, System.EventArgs e)//主键查询
{
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
myOrganization.QueryWithKey(this.txtQueryWithKey.Text);
this.lOrganizationID.Text=myOrganization.OrganizationID;
this.lOrganizationTypeID.Text=myOrganization.OrganizationTypeID;
this.lSuperiorID.Text=myOrganization.SuperiorID;
this.lOrganizationName.Text=myOrganization.OrganizationName;
this.lRemark.Text=myOrganization.Remark;
this.DataGrid1.Visible=false;
this.Panel1.Visible=true;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
}
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//添加命令
{
if(e.CommandName=="Insert")
{
this.DataGrid1.Visible=false;
this.Panel1.Visible=false;
this.Panel2.Visible=true;
this.Panel3.Visible=false;
}
this.drpBindForOrganizationTypeID();// 绑定DropDownList数据OrganizationTypeID
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//删除命令
{
string str;
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
str=myOrganization.IsDelete(key);
if(str==null)
{
myOrganization.Delete(key);
Response.Write("<script language='javascript'>alert('删除成功!');</script>");
this.Bind();
}
else
{
Response.Redirect("Error.aspx?"+"ErrorMsg="+str);
}
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//编辑命令
{
this.DataGrid1.Visible=false;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=true;
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
this.txtEditOrganizationID.Text=key;//取,显示 主键
this.drpBindForOrganizationTypeID();//绑定DropDownList数据OrganizationTypeID
BusinessRules.Organization myOrganization=new BusinessRules.Organization();//显示.....
myOrganization.QueryWithKey(key);
this.drpEditOrganizationTypeID.SelectedItem.Text=myOrganization.OrganizationTypeID;
this.txtEditSuperiorID.Text=myOrganization.SuperiorID;
this.txtEditOrganizationName.Text=myOrganization.OrganizationName;
this.txtEditRemark.Text=myOrganization.Remark;
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)//绑定激活
{
if((e.Item.ItemType == ListItemType.Item || (e.Item.ItemType == ListItemType.AlternatingItem) ))
{
LinkButton IsDelete=(LinkButton)e.Item.Cells[e.Item.Cells.Count-1].FindControl("lbtnDelete");
IsDelete.Attributes.Add("onclick","return confirm('确定删除吗?')");
}
}
private void btnInsertOk_Click(object sender, System.EventArgs e)//确定添加
{
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
myOrganization.OrganizationID=this.txtInsertOrganizationID.Text;
// 从下拉菜单中选择 组织类别ID(OrganizationTypeID)
myOrganization.OrganizationTypeID=this.drpInsertOrganizationTypeID.SelectedItem.Text;
myOrganization.SuperiorID=this.txtInsertSuperiorID.Text;
myOrganization.OrganizationName=this.txtInsertOrganizationName.Text;
myOrganization.Remark=this.txtInsertRemark.Text;
if(myOrganization.Insert()>0)
{
Response.Write("<script language='javascript'>alert('添加成功!');</script>");
}
this.Bind();
}
private void btnEditOk_Click(object sender, System.EventArgs e)//确定编辑
{
BusinessRules.Organization myOrganization=new BusinessRules.Organization();
myOrganization.OrganizationID=this.txtEditOrganizationID.Text;
myOrganization.OrganizationTypeID=this.drpEditOrganizationTypeID.SelectedItem.Text;
if(this.txtEditSuperiorID.Text!="")//当SuperiorID不为空是才修改SuperiorID
{
myOrganization.SuperiorID=this.txtEditSuperiorID.Text;
}
myOrganization.OrganizationName=this.txtEditOrganizationName.Text;
myOrganization.Remark=this.txtEditRemark.Text;
if(myOrganization.UpdateWithKey(this.txtEditOrganizationID.Text)>0)
{
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
this.Bind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -