MeetingRoomUsersManager.aspx.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:4k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. public partial class General_MeetingRoomUsersManager : System.Web.UI.Page
  13. {
  14.     /// <summary>
  15.     /// 模板 
  16.     /// </summary>
  17.     Model.MeetingManagers MM = new Model.MeetingManagers();
  18.     /// <summary>
  19.     /// 业务
  20.     /// </summary>
  21.     BLL.MeetingManagers BM = new BLL.MeetingManagers();
  22.     protected void Page_Load(object sender, EventArgs e)
  23.     {
  24.         LoginLogic.MatchLoad("../", "General_MeetingRoomUsersManager");
  25.         if (!IsPostBack)
  26.         {
  27.             MyDataBind();
  28.         }
  29.     }
  30.     /// <summary>
  31.     /// 清空
  32.     /// </summary>
  33.     public void Clear()
  34.     {
  35.         KeyValue_GLY.Text = "";
  36.         KeyValue_BZ.Text = ""; 
  37.     }
  38.     protected void Button1_Click(object sender, EventArgs e)
  39.     {
  40.         try
  41.         {
  42.             if (String.IsNullOrEmpty(KeyValue_GLY.Text.Trim()))
  43.             {
  44.                 throw new Exception("管理员不能为空!");
  45.             }
  46.             if (BM.GetCount("GLY = '" + KeyValue_GLY.Text + "'") > 0)
  47.             {
  48.                 throw new Exception("该管理员已经存在!");
  49.             }
  50.             MM.GLY = KeyValue_GLY.Text;
  51.             MM.BZ = KeyValue_BZ.Text;
  52.             BM.Add(MM);
  53.             MessageBox.Show("添加成功!");  
  54.         }
  55.         catch (Exception exp)
  56.         {
  57.             MessageBox.Show(exp.Message);
  58.         }
  59.         Clear();
  60.         MyDataBind();
  61.     }
  62.     protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  63.     {
  64.         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  65.         {
  66.             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  67.             if (CheckBox1.Checked)
  68.             {
  69.                 cbox.Checked = true;
  70.             }
  71.             else
  72.             {
  73.                 cbox.Checked = false;
  74.             }
  75.         }
  76.     }
  77.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  78.     {
  79.         for (int i = 0; i < GridView1.Rows.Count; i++)
  80.         {
  81.             //首先判断是否是数据行
  82.             if (e.Row.RowType == DataControlRowType.DataRow)
  83.             {
  84.                 //当鼠标停留时更改背景色
  85.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F0F0F0'");
  86.                 //当鼠标移开时还原背景色
  87.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  88.             }
  89.         }
  90.     }
  91.     /// <summary>
  92.     /// 获取信息
  93.     /// </summary>
  94.     /// <param name="pidx">页号</param>
  95.     public void MyDataBind()
  96.     {
  97.         List<Model.MeetingManagers> LRData = BM.GetList();
  98.         if (LRData.Count == 0)
  99.         {
  100.             Model.MeetingManagers MM = new Model.MeetingManagers();
  101.             LRData.Add(MM);
  102.         }
  103.         GridView1.DataSource = LRData;
  104.         GridView1.DataBind();
  105.     }
  106.     protected void DelButton1_Click(object sender, EventArgs e)
  107.     {
  108.         try
  109.         {
  110.             for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  111.             {
  112.                 CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  113.                 if (cbox.Checked)
  114.                 {
  115.                     int Id = int.Parse(GridView1.Rows[i].Cells[1].Text.ToString());
  116.                     if (Id == 0)
  117.                     {
  118.                         throw new Exception("该记录不能被删除!");
  119.                     }
  120.                     BM.Delete(Id);
  121.                 }
  122.                 else
  123.                 {
  124.                     
  125.                 }
  126.             }
  127.             MessageBox.Show("删除完成!");
  128.         }
  129.         catch (Exception exp)
  130.         { 
  131.             MessageBox.Show(exp.Message); 
  132.         }
  133.         MyDataBind();
  134.         Clear();
  135.     }
  136. }