my_list.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:13k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  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 web_equipment_my_list : System.Web.UI.Page
  13. {
  14.     string departmentid = "";
  15.     string PositionId = "";
  16.     string userid = "";
  17.     string username = "";
  18.     int flow_id = 1;
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         MultiView2.ActiveViewIndex = -1;
  22.         if (!IsPostBack)
  23.         {
  24.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  25.             GridView1.DataKeyNames = new string[] { "form_id" };
  26.             if (Request.QueryString["form_id"] != null)
  27.             {
  28.                 MultiView2.ActiveViewIndex = 0;
  29.                 Label2.Text = Request.QueryString["form_id"];
  30.                 CheckState(Request.QueryString["form_id"]);
  31.                 SetTable(Request.QueryString["form_id"]);
  32.             }
  33.         }
  34.         if (Session["user"] != null)
  35.         {
  36.             User user = (User)Session["user"];
  37.             departmentid = user.Department.Id.ToString();
  38.             PositionId = user.PositionId.ToString();
  39.             userid = user.Id.ToString();
  40.             username = user.Emp_name;
  41.         }
  42.     }
  43.     protected void CheckState(string id)
  44.     {
  45.         SqlConnection conn = dbConnection.getConnection();
  46.         conn.Open();
  47.         SqlCommand cmd = new SqlCommand("select status from oa_equipment_form where form_id=" + id, conn);
  48.         int state = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  49.         if (state != 1)
  50.         {
  51.             FlowTable.Visible = false;
  52.             Button1.Visible = true;
  53.         }
  54.         conn.Close();
  55.     }
  56.     protected void Button1_Click(object sender, EventArgs e)
  57.     {
  58.         if (Request.QueryString["form_id"] != null)
  59.         {
  60.             SqlConnection conn = dbConnection.getConnection();
  61.             conn.Open();
  62.             string sql = "";
  63.             try
  64.             {
  65.                 int id = 1;
  66.                 SqlCommand cmd;
  67.                 sql = "update oa_equipment_form set status='1',total_result='跑流程中',step='1' where form_id='" + Request.QueryString["form_id"] + "'";
  68.                 cmd = new SqlCommand(sql, conn);
  69.                 cmd.ExecuteNonQuery();
  70.                 cmd = new SqlCommand("select max(id) from oa_equipment_flow", conn);
  71.                 try
  72.                 {
  73.                     flow_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
  74.                 }
  75.                 catch (Exception ex)
  76.                 {
  77.                 }
  78.                 ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
  79.                 ArrayList id2 = new ArrayList();
  80.                 ArrayList name_1 = new ArrayList();//记录上层节点职级小于登陆者的name
  81.                 ArrayList mail_1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  82.                 ArrayList last_id = new ArrayList();//记录上层节点的ID
  83.                 int ceng = 0;
  84.                 cmd = new SqlCommand("select ceng from oa_department where id='" + departmentid + "'", conn);
  85.                 try
  86.                 {
  87.                     ceng = Convert.ToInt32(cmd.ExecuteScalar()) - 3;
  88.                      if (ceng < 0 || ceng == 0)
  89.                          {
  90.                                 ceng = 0;
  91.                          }
  92.                 }
  93.                 catch (Exception ex)
  94.                 {
  95.                 }
  96.                 last_id.Add(departmentid);
  97.                 for (int i = 1; i <= ceng; i++)
  98.                 {
  99.                     cmd = new SqlCommand("select distinct last_id from oa_department where id='" + last_id[i - 1] + "'", conn);
  100.                     SqlDataReader dr1 = cmd.ExecuteReader();
  101.                     while (dr1.Read())
  102.                     {
  103.                         last_id.Add(dr1["last_id"].ToString());
  104.                     }
  105.                     dr1.Close();
  106.                 }
  107.                 for (int i = 0; i < last_id.Count; i++)
  108.                 {
  109.                     cmd = new SqlCommand("select id,email_work,emp_name from oa_employee where department_id='" + last_id[i] + "'and q_manger='1'", conn);
  110.                     SqlDataReader dr2 = cmd.ExecuteReader();
  111.                     while (dr2.Read())
  112.                     {
  113.                         id1.Add(dr2["id"].ToString());
  114.                         //name_1.Add(dr2["emp_name"].ToString());
  115.                        // mail_1.Add(dr2["email_work"].ToString());
  116.                     }
  117.                     dr2.Close();
  118.                 }
  119.                 id1.Add("6");
  120.                 //删除本人ID
  121.                 for (int i = 0; i < id1.Count; i++)
  122.                 {
  123.                     if (id1[i].Equals(userid))
  124.                     {
  125.                         id1.RemoveAt(i);
  126.                         //name_1.RemoveAt(i);
  127.                        // mail_1.RemoveAt(i);
  128.                     }
  129.                 }
  130.                 foreach(string i in id1)
  131.                 {
  132.                     string str = check_supply(i);
  133.                     id2.Add(str);
  134.                     cmd = new SqlCommand("select email_work,emp_name from oa_employee where id='"+str+"'",conn);
  135.                     SqlDataReader dr3 = cmd.ExecuteReader();
  136.                     if (dr3.HasRows)
  137.                     {
  138.                         while (dr3.Read())
  139.                         {
  140.                           name_1.Add(dr3["emp_name"].ToString());
  141.                           mail_1.Add(dr3["email_work"].ToString());
  142.                         }
  143.                     }
  144.                     dr3.Close();
  145.                 }
  146.                 if (id2.Count != 0)
  147.                 {
  148.                     for (int j = 0; j < id2.Count; j++)
  149.                     {
  150.                         cmd = new SqlCommand("insert into oa_equipment_flow(id,form_id,operator_id,is_check,is_agree,comment,check_date,step)values('" + flow_id + "','" + Request.QueryString["form_id"] + "','" + id2[j].ToString() + "','N','N','','','" + (j + 1) + "')", conn);
  151.                         cmd.ExecuteNonQuery();
  152.                         flow_id = flow_id + 1;
  153.                     }
  154.                         mail.mail_q(mail_1[0], name_1[0], username, "設備申請單");
  155.                 }
  156.                 ShowMessageBox("申请成功");
  157.             }
  158.             catch (Exception ex)
  159.             {
  160.                 Response.Write(ex.Message);
  161.                 ShowMessageBox("申请失败,請與管理員聯繫");
  162.             }
  163.             conn.Close();
  164.         }
  165.     }
  166.     public string check_supply(string id)
  167.     {
  168.         string emp_id = id;
  169.         SqlConnection conn = dbConnection.getConnection();
  170.         conn.Open();
  171.         DateTime date=DateTime.Now;
  172.         try
  173.         {
  174.             SqlCommand cmd = new SqlCommand("select d_people,s_date,e_date from OA_DELEGATE where b_d_people='" + id + "'", conn);
  175.             SqlDataReader dr = cmd.ExecuteReader();
  176.             if (dr.HasRows)
  177.             {
  178.                 while (dr.Read())
  179.                 {
  180.                     if ((!dr["s_date"].ToString().Equals("")) && (!dr["e_date"].ToString().Equals("")))
  181.                     {
  182.                         if ((date >= Convert.ToDateTime(dr["s_date"])) && (date <= Convert.ToDateTime(dr["e_date"])))
  183.                         {
  184.                             emp_id = Convert.ToString(dr["d_people"]);
  185.                         }
  186.                         else
  187.                         {
  188.                         }
  189.                     }
  190.                 }
  191.             }
  192.         }
  193.         catch
  194.         {
  195.         }
  196.         return emp_id;
  197.     }
  198.     protected void ShowMessageBox(string strMessage)
  199.     {
  200.         Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
  201.     }
  202.     public void SetTable(string id)
  203.     {
  204.         SqlConnection conn = dbConnection.getConnection();
  205.         conn.Open();
  206.         SqlCommand cmd = new SqlCommand("select operator_id,is_check,is_agree,comment,check_date,step from oa_equipment_flow where form_id='" + id + "'", conn);
  207.         SqlDataReader dr = cmd.ExecuteReader();
  208.         if (dr.HasRows)
  209.         {
  210.             while (dr.Read())
  211.             {
  212.                 TableRow tr = new TableRow();
  213.                 TableCell td = new TableCell();
  214.                 td.BorderWidth = Unit.Pixel(1);
  215.                 td.Text = dr["step"].ToString();
  216.                 tr.Cells.Add(td);
  217.                 td = new TableCell();
  218.                 td.BorderWidth = Unit.Pixel(1);
  219.                 SqlConnection conn1 = dbConnection.getConnection();
  220.                 conn1.Open();
  221.                 SqlCommand sqlcom = new SqlCommand("select emp_name from oa_employee where id='" + dr["operator_id"] + "'", conn1);
  222.                 td.Text = sqlcom.ExecuteScalar().ToString();
  223.                 tr.Cells.Add(td);
  224.                 td = new TableCell();
  225.                 td.BorderWidth = Unit.Pixel(1);
  226.                 td.Text = "審批";
  227.                 tr.Cells.Add(td);
  228.                 td = new TableCell();
  229.                 td.BorderWidth = Unit.Pixel(1);
  230.                 if (dr["is_check"].ToString().Equals("N"))
  231.                 {
  232.                     td.Text = "未處理";
  233.                 }
  234.                 else
  235.                 {
  236.                     td.Text = "已處理";
  237.                 }
  238.                 tr.Cells.Add(td);
  239.                 td = new TableCell();
  240.                 td.BorderWidth = Unit.Pixel(1);
  241.                 if (dr["is_check"].ToString().Equals("Y"))
  242.                 {
  243.                     if (dr["is_agree"].ToString().Equals("Y"))
  244.                     {
  245.                         td.Text = "已同意";
  246.                     }
  247.                     else
  248.                     {
  249.                         td.Text = "不同意";
  250.                     }
  251.                 }
  252.                 else
  253.                 {
  254.                     td.Text = "<br>";
  255.                 }
  256.                 tr.Cells.Add(td);
  257.                 td = new TableCell();
  258.                 td.BorderWidth = Unit.Pixel(1);
  259.                 if (!dr["comment"].ToString().Equals(""))
  260.                 {
  261.                     td.Text = dr["comment"].ToString();
  262.                 }
  263.                 else
  264.                 {
  265.                     td.Text = "<br>";
  266.                 }
  267.                 tr.Cells.Add(td);
  268.                 td = new TableCell();
  269.                 td.BorderWidth = Unit.Pixel(1);
  270.                 if (!dr["check_date"].ToString().Equals(""))
  271.                 {
  272.                     td.Text = dr["check_date"].ToString();
  273.                 }
  274.                 else
  275.                 {
  276.                     td.Text = "<br>";
  277.                 }
  278.                 tr.Cells.Add(td);
  279.                 FlowTable.Rows.Add(tr);
  280.             }
  281.         }
  282.     }
  283.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  284.     {
  285.         int i = 0;
  286.         //执行循环,保证每条数据都可以更新
  287.          for (i = 0; i < GridView1.Rows.Count; i++)
  288.          {
  289.              //首先判断是否是数据行
  290.              if (e.Row.RowType == DataControlRowType.DataRow)
  291.              {
  292.                  //当鼠标停留时更改背景色
  293.                  e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  294.                  //当鼠标移开时还原背景色
  295.                  e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  296.              }
  297.          }
  298.          if (e.Row.RowType == DataControlRowType.DataRow)
  299.          {
  300.              e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  301.              e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?form_id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  302.          }
  303.     }
  304.    public void lbRevoke_Click(object sender, EventArgs e)
  305.     {
  306.         LinkButton lbRevoke = (LinkButton)sender;
  307.         string id = lbRevoke.CommandArgument;
  308.         SqlConnection conn = dbConnection.getConnection();
  309.         conn.Open();
  310.         SqlTransaction tx = conn.BeginTransaction();
  311.         try
  312.         {
  313.             SqlCommand cmd = new SqlCommand("update oa_equipment_form set status=3, total_result='已撤銷' where form_id=" + id, conn);
  314.             cmd.Transaction = tx;
  315.             cmd.ExecuteNonQuery();
  316.             cmd = new SqlCommand("update oa_equipment_flow set is_check='N', is_agree='N', comment='', " +
  317.                 "check_date='' where form_id='" + id + "'", conn);
  318.             cmd.Transaction = tx;
  319.             cmd.ExecuteNonQuery();
  320.             cmd = new SqlCommand("delect oa_equipment_flow where form_id='"+id+"'",conn);
  321.             cmd.Transaction = tx;
  322.             cmd.ExecuteNonQuery();
  323.             tx.Commit();
  324.         }
  325.         catch (Exception ex)
  326.         {
  327.             Response.Write(ex.Message);
  328.             tx.Rollback();
  329.         }
  330.         conn.Close();
  331.         GridView1.DataBind();
  332.         MultiView2.ActiveViewIndex = -1;
  333.     }
  334. }