my_list.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:14k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- 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;
- using System.Data.SqlClient;
- public partial class web_approvel_tw_my_list : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- ApprovelList.DataKeyNames = new string[] { "id" };
- if (Request.QueryString["a_id"] != null)
- {
- PnlApprovel.Visible = true;
- FlowList.DataKeyNames = new string[] { "id" };
- this.SetData(Request.QueryString["a_id"]);
- this.CheckState(Request.QueryString["a_id"]);
- }
- if (Session["user"] != null)
- {
- User user = (User)Session["user"];
- DepartmentId.Value = user.Department.Id.ToString();
- PositionId.Value = user.PositionId.ToString();
- }
- }
- }
- protected void CheckState(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select state from OA_TW_APPROVEL_FORM where id=" + id, conn);
- int state = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- State.Value = state.ToString();
- if (state != 1)
- {
- FlowList.Visible = false;
- Panel1.Visible = true;
- }
- conn.Close();
- }
- protected void SetData(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, " +
- "d.name department, e1.emp_name delegate, t.name off_type, a.parenthesis, a.days, a.vacation_begin, " +
- "a.vacation_end, vp.name vacation_place, fp1.name flight_go_depart, fp2.name flight_go_arrive, " +
- "a.flight_go_time, a.flight_back_time, fp3.name flight_back_depart, fp4.name flight_back_arrive, " +
- "a.business_begin, a.business_end, a.reason, a.apply_date, b.name business_place " +
- "from OA_TW_APPROVEL_FORM a " +
- "inner join OA_EMPLOYEE e on a.emp_id=e.id " +
- "inner join OA_EMPLOYEE e1 on a.delegate_id=e1.id " +
- "inner join OA_DEPARTMENT d on e.department_id=d.id " +
- "inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
- "inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
- "inner join OA_VACATION_PLACE vp on a.vacation_place=vp.id " +
- "inner join OA_FLIGHT_PLACE fp1 on a.flight_go_depart=fp1.id " +
- "inner join OA_FLIGHT_PLACE fp2 on a.flight_go_arrive=fp2.id " +
- "inner join OA_FLIGHT_PLACE fp3 on a.flight_back_depart=fp3.id " +
- "inner join OA_FLIGHT_PLACE fp4 on a.flight_back_arrive=fp4.id " +
- "inner join OA_BUSINESS_PLACE b on a.business_place=b.id where a.id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- TxtFormNo.Text = dr["form_id"].ToString();
- TxtEmpName.Text = dr["emp_name"].ToString();
- TxtEmpNo.Text = dr["emp_no"].ToString();
- TxtPosition.Text = dr["position"].ToString();
- TxtDepartment.Text = dr["department"].ToString();
- TxtDelegate.Text = dr["delegate"].ToString();
- TxtOffType.Text = dr["off_type"].ToString();
- TxtParenthesis.Text = dr["parenthesis"].ToString();
- TxtDays.Text = dr["days"].ToString();
- TxtVacationBegin.Text = dr["vacation_begin"].ToString();
- TxtVacationEnd.Text = dr["vacation_end"].ToString();
- TxtVacationPlace.Text = dr["vacation_place"].ToString();
- TxtFlightGoDepart.Text = dr["flight_go_depart"].ToString();
- TxtFlightGoArrive.Text = dr["flight_go_arrive"].ToString();
- TxtFlightGoTime.Text = dr["flight_go_time"].ToString();
- TxtFlightBackTime.Text = dr["flight_back_time"].ToString();
- TxtFlightBackDepart.Text = dr["flight_back_depart"].ToString();
- TxtFlightBackArrive.Text = dr["flight_back_arrive"].ToString();
- TxtBusinessBegin.Text = dr["business_begin"].ToString();
- TxtBusinessEnd.Text = dr["business_end"].ToString();
- TxtReason.Text = dr["reason"].ToString();
- TxtApplyDate.Text = dr["apply_date"].ToString();
- TxtBusinessPlace.Text = dr["business_place"].ToString();
- }
- dr.Close();
- conn.Close();
- }
- protected void ApprovelList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- 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?a_id=" + ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
- }
- }
- protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from "+
- "OA_TW_APPROVEL_FORM_FLOW where id="+FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- Label label = (Label)e.Row.FindControl("LblApplyType");
- if (dr["apply_type"].ToString().Equals("1"))
- {
- label.Text = "會簽";
- }
- else if (dr["apply_type"].ToString().Equals("2"))
- {
- label.Text = "審批";
- }
- else if (dr["apply_type"].ToString().Equals("3"))
- {
- label.Text = "審批(代理)";
- }
- label = (Label)e.Row.FindControl("LblIsCheck");
- if (dr["is_check"].ToString().Equals("N"))
- {
- label.Text = "未處理";
- }
- else
- {
- label.Text = "已處理";
- label = (Label)e.Row.FindControl("LblIsAgree");
- if (dr["is_agree"].ToString().Equals("Y"))
- {
- label.Text = "已同意";
- }
- else
- {
- label.Text = "不同意";
- }
- }
- label = (Label)e.Row.FindControl("LblComment");
- label.Text = dr["comment"].ToString();
- }
- dr.Close();
- conn.Close();
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- if (Request.QueryString["a_id"] != null)
- {
- string id = Request.QueryString["a_id"];
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- if (State.Value.Equals("2"))
- {
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- SqlCommand cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- int flow_id = 1;
- cmd = new SqlCommand("select max(id) from OA_TW_APPROVEL_FORM_FLOW", conn);
- cmd.Transaction = tx;
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- ArrayList main_ids = new ArrayList();
- cmd = new SqlCommand("select id from OA_FLOW_MAIN where department_id=" +
- DepartmentId.Value, conn);
- cmd.Transaction = tx;
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- main_ids.Add(dr["id"].ToString());
- }
- dr.Close();
- int flag = 0;
- int main_id = 0;
- for (int i = 0; i < main_ids.Count; i++)
- {
- cmd = new SqlCommand("select position_id from OA_FLOW_POSITION where main_id=" +
- main_ids[i], conn);
- cmd.Transaction = tx;
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- if (dr["position_id"].ToString().Equals(PositionId.Value))
- {
- flag = 1;
- main_id = Convert.ToInt32(main_ids[i]);
- }
- }
- dr.Close();
- if (flag == 1)
- {
- break;
- }
- }
- if (main_id != 0)
- {
- ArrayList operator_ids = new ArrayList();
- cmd = new SqlCommand("select operator_id from OA_FLOW_DETAIL where main_id=" +
- main_id + " order by number", conn);
- cmd.Transaction = tx;
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- operator_ids.Add(dr["operator_id"].ToString());
- }
- dr.Close();
- for (int i = 0; i < operator_ids.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_TW_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
- "apply_type, is_check, is_agree, comment, check_date, step)values(" +
- flow_id + ", " + id + "," + operator_ids[i] + ",2,'N','N','',''," + (i + 2) + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- flow_id++;
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- }
- else
- {
- LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
- tx.Rollback();
- }
- }
- catch (Exception ex)
- {
- Response.Write(ex.ToString());
- tx.Rollback();
- }
- }
- else
- {
- SqlCommand cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
- cmd.ExecuteNonQuery();
- }
- conn.Close();
- ApprovelList.DataBind();
- PnlApprovel.Visible = false;
- PnlFlow.Visible = false;
- Panel1.Visible = false;
- }
- }
- protected void ApprovelList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select total_result from OA_TW_APPROVEL_FORM where id=" +
- ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
- LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke");
- string total_result = cmd.ExecuteScalar().ToString();
- if (total_result.Equals("跑流程中"))
- {
- lbRevoke.Enabled = true;
- lbRevoke.CommandArgument = ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString();
- lbRevoke.Click += new EventHandler(lbRevoke_Click);
- }
- else
- {
- lbRevoke.OnClientClick = "";
- }
- conn.Close();
- }
- }
- 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_TW_APPROVEL_FORM set state=3, total_result='已撤銷' where id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='N', is_agree='N', comment='', " +
- "check_date='' where form_id='" + id + "'", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- tx.Commit();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- tx.Rollback();
- }
- conn.Close();
- ApprovelList.DataBind();
- PnlApprovel.Visible = false;
- PnlFlow.Visible = false;
- Panel1.Visible = false;
- }
- }