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