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

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_CarsManager : System.Web.UI.Page
  13. {
  14.     /// <summary>
  15.     /// 模板 
  16.     /// </summary>
  17.     Model.Cars MF = new Model.Cars();
  18.     /// <summary>
  19.     /// 业务
  20.     /// </summary>
  21.     BLL.Cars BF = new BLL.Cars();
  22.     /// <summary>
  23.     /// 查询条件
  24.     /// </summary>
  25.     public string TiaoJian
  26.     {
  27.         get
  28.         {
  29.             if (ViewState["UseThingsTiaoJian"] == null)
  30.             {
  31.                 return "";
  32.             }
  33.             else
  34.             {
  35.                 return ViewState["UseThingsTiaoJian"].ToString();
  36.             }
  37.         }
  38.         set { ViewState["UseThingsTiaoJian"] = value; }
  39.     }
  40.     protected void Page_Load(object sender, EventArgs e)
  41.     {
  42.         LoginLogic.MatchLoad("../", "Vehicles_CarsManager");
  43.         if (!IsPostBack)
  44.         {
  45.             TiaoJian = "";
  46.             if (Request.QueryString["TiaoJian"] != null)
  47.             {
  48.                 TiaoJian = Server.UrlDecode(Request.QueryString["TiaoJian"].ToString());
  49.             }
  50.             MyDataBind(1);
  51.         }
  52.     }
  53.     /// <summary>
  54.     /// 获取信息
  55.     /// </summary>
  56.     /// <param name="pidx">页号</param>
  57.     public void MyDataBind(int pidx)
  58.     {
  59.         AspNetPager1.RecordCount = BF.GetCount(TiaoJian);
  60.         List<Model.Cars> LRData = BF.GetPageList(20, pidx, "ID", false, TiaoJian);
  61.         if (LRData.Count == 0)
  62.         {
  63.             Model.Cars MF = new Model.Cars();
  64.             LRData.Add(MF);
  65.         }
  66.         GridView1.DataSource = LRData;
  67.         GridView1.DataBind();
  68.     }
  69.     /// <summary>
  70.     /// 部门
  71.     /// </summary>
  72.     /// <returns></returns>
  73.     public string YPLB()
  74.     {
  75.         //int Id = int.Parse(Eval("YPLB").ToString());
  76.         //return EnumGet.GetUseThingsTypeName(Id);
  77.         return SessionInclude.SessionId;
  78.     }
  79.     /// <summary>
  80.     /// 车辆类型
  81.     /// </summary>
  82.     /// <returns></returns>
  83.     public string CLLX()
  84.     {
  85.         string id = "0";
  86.         if (BF.GetCount(TiaoJian) > 0)
  87.         {
  88.             id = Eval("CLLX").ToString();
  89.         }
  90.         return EnumGet.GetCarTypeName(id);
  91.     }
  92.     /// <summary>
  93.     /// 状态
  94.     /// </summary>
  95.     /// <returns></returns>
  96.     public string DQZT()
  97.     {
  98.         string id = "0";
  99.         if (BF.GetCount(TiaoJian) > 0)
  100.         {
  101.             id = Eval("DQZT").ToString();
  102.         }
  103.         return EnumGet.GetCurrentStateName(id);
  104.     }
  105.     /// <summary>
  106.     /// 操作
  107.     /// </summary>
  108.     /// <returns></returns>
  109.     public string CaoZuo()
  110.     {
  111.         string Id = Eval("Id").ToString();
  112.         //编辑 清空密码 删除
  113.         //string Rtstr = "<a href='ArticlesInfoAdd.aspx'>添加用品</a>&nbsp;&nbsp;";
  114.         //Rtstr += "<a href='ArticlesInfoEditor.aspx?id=" + Id + "'>修改用品</a>&nbsp;&nbsp;";
  115.         string Rtstr = "";
  116.         if (BF.GetCount(TiaoJian) > 0)
  117.         {
  118.             Rtstr = "<a href='CarEditor.aspx?id=" + Id + "'>详细信息(可编辑)</a>&nbsp;&nbsp;";
  119.         }
  120.         else
  121.         {
  122.             Rtstr = "还没有车辆!";
  123.         }
  124.         return Rtstr;
  125.     }
  126.     protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
  127.     {
  128.         MyDataBind(e.NewPageIndex);
  129.     }
  130.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  131.     {
  132.         for (int i = 0; i < GridView1.Rows.Count; i++)
  133.         {
  134.             //首先判断是否是数据行
  135.             if (e.Row.RowType == DataControlRowType.DataRow)
  136.             {
  137.                 //当鼠标停留时更改背景色
  138.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F0F0F0'");
  139.                 //当鼠标移开时还原背景色
  140.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  141.             }
  142.         }
  143.     }
  144.     protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  145.     {
  146.         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  147.         {
  148.             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  149.             if (CheckBox1.Checked)
  150.             {
  151.                 cbox.Checked = true;
  152.             }
  153.             else
  154.             {
  155.                 cbox.Checked = false;
  156.             }
  157.         }
  158.     }
  159.     protected void DelButton1_Click(object sender, EventArgs e)
  160.     {
  161.         try
  162.         {
  163.             for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  164.             {
  165.                 CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  166.                 if (cbox.Checked)
  167.                 {
  168.                     int Id = int.Parse(GridView1.Rows[i].Cells[1].Text.ToString());
  169.                     if (Id == 0)
  170.                     {
  171.                         throw new Exception("该记录不能删除!");
  172.                     }
  173.                     BF.Delete(Id);
  174.                 }
  175.                 else
  176.                 {
  177.                 }
  178.             }
  179.             MessageBox.Show("删除完成!");
  180.         }
  181.         catch (Exception exp)
  182.         { MessageBox.Show(exp.Message); }
  183.         MyDataBind(AspNetPager1.CurrentPageIndex);
  184.     }
  185. }