ManageInfoCategory.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:6k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- 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 OA
- {
- /// <summary>
- /// ManageInfoSection 的摘要说明。
- /// </summary>
- public class ManageInfoSection : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.DataGrid MyDataGrid;
- protected System.Web.UI.WebControls.TextBox InfoCategoryName;
- protected System.Web.UI.HtmlControls.HtmlInputButton AddInfoCategory;
- protected System.Web.UI.WebControls.DropDownList DropDownList1;
- public string PID;
- private void Page_Load(object sender, System.EventArgs e)
- {
- CheckUser CHU = new CheckUser();
- CHU.UserName = User.Identity.Name;
- PID = CHU.UserID.ToString();
- if(CHU.Is_FileManager() == false)
- Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if(!IsPostBack)
- {
- BindGrid();
- Page.DataBind();
- }
- // 在此处放置用户代码以初始化页面
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.AddInfoCategory.ServerClick += new System.EventHandler(this.AddInfoCategory_ServerClick);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- public void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E)
- {
- MyDataGrid.EditItemIndex = (int)E.Item.ItemIndex;
- BindGrid();
- }
- public void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs E)
- {
- MyDataGrid.EditItemIndex = -1;
- BindGrid();
- }
- public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs E)
- {
- if(((System.Web.UI.WebControls.TextBox)E.Item.Cells[2].Controls[0]).Text.Trim()!="")
- {
- SqlCommand MyCommand = new SqlCommand("UpdateInfoCategory", MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID", SqlDbType.Int, 4));
- MyCommand.Parameters["@InfoCategoryID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
- MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryName", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@InfoCategoryName"].Value = ((System.Web.UI.WebControls.TextBox)E.Item.Cells[2].Controls[0]).Text;
- MyCommand.Parameters.Add(new SqlParameter("@OrganizationID", SqlDbType.Int, 4));
- MyCommand.Parameters["@OrganizationID"].Value = ((DropDownList)E.Item.FindControl("edit_OR")).SelectedValue.ToString();
- MyCommand.Connection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- MyDataGrid.EditItemIndex = -1;
- }
- catch
- {
- }
- MyCommand.Connection.Close();
- BindGrid();
- }
- }
- public void BindGrid()
- {
- SqlDataAdapter MyCommand2 = new SqlDataAdapter("InfoCategorySelect",MyConnection);
- MyCommand2.SelectCommand.CommandType = CommandType.StoredProcedure;
- DataSet ds = new DataSet();
- MyCommand2.Fill(ds, "InfoCategory");
- MyDataGrid.DataSource=ds.Tables["InfoCategory"].DefaultView;
- MyDataGrid.DataBind();
- }
- public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E)
- {
- SqlCommand MyCommand = new SqlCommand("DeleteInfoCategory",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID", SqlDbType.Int, 4));
- MyCommand.Parameters["@InfoCategoryID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- RegisterStartupScript("alert","<script>alert('出现错误:未能删除记录!')</" + "script>");
- }
- MyConnection.Close();
- BindGrid();
- }
- public void MyDataGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
- {
- if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
- {
- LinkButton myDeleteButton;
- myDeleteButton = (LinkButton) e.Item.Cells[1].Controls[0];
- myDeleteButton.Attributes.Add("onclick", @"return confirm('你确认要删除此信息吗?');");
- }
- if(e.Item.ItemType == ListItemType.EditItem)
- {
- DropDownList DropList;
- DropList= (DropDownList)e.Item.FindControl("Edit_OR");
- String myRole = DataBinder.Eval(e.Item.DataItem, "Expr1").ToString();
- DropList.Items.FindByText(myRole).Selected = true;
- }
- }
- private void AddInfoCategory_ServerClick(object sender, System.EventArgs e)
- {
- Page.Validate();
- if ( !Page.IsValid )
- {
- return;
- }
- if(InfoCategoryName.Text.Trim()!="")
- {
- SqlCommand MyCommand = new SqlCommand("InsertInfoCategory", MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryName", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@InfoCategoryName"].Value = InfoCategoryName.Text;
- MyCommand.Parameters.Add(new SqlParameter("@OrganizationID", SqlDbType.Int, 4));
- MyCommand.Parameters["@OrganizationID"].Value = DropDownList1.SelectedValue.ToString();
- MyCommand.Connection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- }
- MyCommand.Connection.Close();
- InfoCategoryName.Text = "";
- BindGrid();
- }
- else
- RegisterStartupScript("alert","<script>alert('公司名称不能为空!')</" + "script>");
- }
- }
- }