my_list.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:13k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class web_equipment_my_list : System.Web.UI.Page
- {
- string departmentid = "";
- string PositionId = "";
- string userid = "";
- string username = "";
- int flow_id = 1;
- protected void Page_Load(object sender, EventArgs e)
- {
- MultiView2.ActiveViewIndex = -1;
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- GridView1.DataKeyNames = new string[] { "form_id" };
- if (Request.QueryString["form_id"] != null)
- {
- MultiView2.ActiveViewIndex = 0;
- Label2.Text = Request.QueryString["form_id"];
- CheckState(Request.QueryString["form_id"]);
- SetTable(Request.QueryString["form_id"]);
- }
- }
- if (Session["user"] != null)
- {
- User user = (User)Session["user"];
- departmentid = user.Department.Id.ToString();
- PositionId = user.PositionId.ToString();
- userid = user.Id.ToString();
- username = user.Emp_name;
- }
- }
- protected void CheckState(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select status from oa_equipment_form where form_id=" + id, conn);
- int state = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- if (state != 1)
- {
- FlowTable.Visible = false;
- Button1.Visible = true;
- }
- conn.Close();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- if (Request.QueryString["form_id"] != null)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string sql = "";
- try
- {
- int id = 1;
- SqlCommand cmd;
- sql = "update oa_equipment_form set status='1',total_result='跑流程中',step='1' where form_id='" + Request.QueryString["form_id"] + "'";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("select max(id) from oa_equipment_flow", conn);
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch (Exception ex)
- {
- }
- ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
- ArrayList id2 = new ArrayList();
- ArrayList name_1 = new ArrayList();//记录上层节点职级小于登陆者的name
- ArrayList mail_1 = new ArrayList();//记录上层节点职级小于登陆者的mail
- ArrayList last_id = new ArrayList();//记录上层节点的ID
- int ceng = 0;
- cmd = new SqlCommand("select ceng from oa_department where id='" + departmentid + "'", conn);
- try
- {
- ceng = Convert.ToInt32(cmd.ExecuteScalar()) - 3;
- if (ceng < 0 || ceng == 0)
- {
- ceng = 0;
- }
- }
- catch (Exception ex)
- {
- }
- last_id.Add(departmentid);
- for (int i = 1; i <= ceng; i++)
- {
- cmd = new SqlCommand("select distinct last_id from oa_department where id='" + last_id[i - 1] + "'", conn);
- SqlDataReader dr1 = cmd.ExecuteReader();
- while (dr1.Read())
- {
- last_id.Add(dr1["last_id"].ToString());
- }
- dr1.Close();
- }
- for (int i = 0; i < last_id.Count; i++)
- {
- cmd = new SqlCommand("select id,email_work,emp_name from oa_employee where department_id='" + last_id[i] + "'and q_manger='1'", conn);
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- id1.Add(dr2["id"].ToString());
- //name_1.Add(dr2["emp_name"].ToString());
- // mail_1.Add(dr2["email_work"].ToString());
- }
- dr2.Close();
- }
- id1.Add("6");
- //删除本人ID
- for (int i = 0; i < id1.Count; i++)
- {
- if (id1[i].Equals(userid))
- {
- id1.RemoveAt(i);
- //name_1.RemoveAt(i);
- // mail_1.RemoveAt(i);
- }
- }
- foreach(string i in id1)
- {
- string str = check_supply(i);
- id2.Add(str);
- cmd = new SqlCommand("select email_work,emp_name from oa_employee where id='"+str+"'",conn);
- SqlDataReader dr3 = cmd.ExecuteReader();
- if (dr3.HasRows)
- {
- while (dr3.Read())
- {
- name_1.Add(dr3["emp_name"].ToString());
- mail_1.Add(dr3["email_work"].ToString());
- }
- }
- dr3.Close();
- }
- if (id2.Count != 0)
- {
- for (int j = 0; j < id2.Count; j++)
- {
- 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);
- cmd.ExecuteNonQuery();
- flow_id = flow_id + 1;
- }
- mail.mail_q(mail_1[0], name_1[0], username, "設備申請單");
- }
- ShowMessageBox("申请成功");
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- ShowMessageBox("申请失败,請與管理員聯繫");
- }
- conn.Close();
- }
- }
- public string check_supply(string id)
- {
- string emp_id = id;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DateTime date=DateTime.Now;
- try
- {
- SqlCommand cmd = new SqlCommand("select d_people,s_date,e_date from OA_DELEGATE where b_d_people='" + id + "'", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- if ((!dr["s_date"].ToString().Equals("")) && (!dr["e_date"].ToString().Equals("")))
- {
- if ((date >= Convert.ToDateTime(dr["s_date"])) && (date <= Convert.ToDateTime(dr["e_date"])))
- {
- emp_id = Convert.ToString(dr["d_people"]);
- }
- else
- {
- }
- }
- }
- }
- }
- catch
- {
- }
- return emp_id;
- }
- protected void ShowMessageBox(string strMessage)
- {
- Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
- }
- public void SetTable(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select operator_id,is_check,is_agree,comment,check_date,step from oa_equipment_flow where form_id='" + id + "'", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["step"].ToString();
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom = new SqlCommand("select emp_name from oa_employee where id='" + dr["operator_id"] + "'", conn1);
- td.Text = sqlcom.ExecuteScalar().ToString();
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = "審批";
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- if (dr["is_check"].ToString().Equals("N"))
- {
- td.Text = "未處理";
- }
- else
- {
- td.Text = "已處理";
- }
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- if (dr["is_check"].ToString().Equals("Y"))
- {
- if (dr["is_agree"].ToString().Equals("Y"))
- {
- td.Text = "已同意";
- }
- else
- {
- td.Text = "不同意";
- }
- }
- else
- {
- td.Text = "<br>";
- }
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- if (!dr["comment"].ToString().Equals(""))
- {
- td.Text = dr["comment"].ToString();
- }
- else
- {
- td.Text = "<br>";
- }
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- if (!dr["check_date"].ToString().Equals(""))
- {
- td.Text = dr["check_date"].ToString();
- }
- else
- {
- td.Text = "<br>";
- }
- tr.Cells.Add(td);
- FlowTable.Rows.Add(tr);
- }
- }
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- int i = 0;
- //执行循环,保证每条数据都可以更新
- for (i = 0; i < GridView1.Rows.Count; i++)
- {
- //首先判断是否是数据行
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- //当鼠标停留时更改背景色
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
- //当鼠标移开时还原背景色
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
- }
- }
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
- e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?form_id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
- }
- }
- public void lbRevoke_Click(object sender, EventArgs e)
- {
- LinkButton lbRevoke = (LinkButton)sender;
- string id = lbRevoke.CommandArgument;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- SqlCommand cmd = new SqlCommand("update oa_equipment_form set status=3, total_result='已撤銷' where form_id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update oa_equipment_flow set is_check='N', is_agree='N', comment='', " +
- "check_date='' where form_id='" + id + "'", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("delect oa_equipment_flow where form_id='"+id+"'",conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- tx.Commit();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- tx.Rollback();
- }
- conn.Close();
- GridView1.DataBind();
- MultiView2.ActiveViewIndex = -1;
- }
- }