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

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using System.Net.Mail;
  13. using System.Net;
  14. using System.Net.Sockets;
  15. public partial class web_fair_deal_list : System.Web.UI.Page
  16. {
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         if (!IsPostBack)
  20.         {
  21.             LoginDAO.CheckLogin(Session, Response, "../", 2);
  22.             this.SetTable();
  23.         }
  24.         if (Request.QueryString["f_id"] != null)
  25.         {
  26.             this.SetForm(Request.QueryString["f_id"]);
  27.             PnlFair.Visible = true;
  28.             PnlDeal.Visible = true;
  29.             PnlFlow.Visible = true;
  30.             FlowList.DataKeyNames = new string[] { "id"};
  31.         }
  32.     }
  33.     //mail给待签核人
  34.     
  35.     protected void SetForm(string id)
  36.     {
  37.         string fair_id = "0";
  38.         SqlConnection conn = dbConnection.getConnection();
  39.         conn.Open();
  40.         SqlCommand cmd = new SqlCommand("select form_id from OA_FAIR_FORM_FLOW where id=" + id, conn);
  41.         fair_id = cmd.ExecuteScalar().ToString();
  42.         cmd = new SqlCommand("select e.emp_name, e.emp_no, f.apply_date, f.amount, f.remark, f.form_no, " +
  43.             "f.subject, f.form_id, f.form_table from OA_FAIR f inner join OA_EMPLOYEE e on f.emp_id=e.id " +
  44.             "where f.id=" + fair_id + " and total_result<>'已撤銷'", conn);
  45.         SqlDataReader dr = cmd.ExecuteReader();
  46.         string form_id = "0";
  47.         string form_table = "";
  48.         if (dr.Read())
  49.         {
  50.             TxtEmpName.Text = dr["emp_name"].ToString();
  51.             TxtEmpNo.Text = dr["emp_no"].ToString();
  52.             TxtApplyDate.Text = dr["apply_date"].ToString();
  53.             TxtAmount.Text = dr["amount"].ToString();
  54.             TxtRemark.Text = dr["remark"].ToString();
  55.             TxtFormNo.Text = dr["form_no"].ToString();
  56.             TxtSubject.Text = dr["subject"].ToString();
  57.             if (!dr["form_id"].Equals("0"))
  58.             {
  59.                 TblFair.Rows[7].Visible = true;
  60.                 form_id = dr["form_id"].ToString();
  61.                 form_table = dr["form_table"].ToString();
  62.             }
  63.         }
  64.         dr.Close();
  65.         if (!form_id.Equals("0"))
  66.         {
  67.             cmd = new SqlCommand("select form_id from " + form_table + " where id=" + form_id, conn);
  68.             HlFormNo.Text = cmd.ExecuteScalar().ToString();
  69.             HlFormNo.NavigateUrl = "form_show.aspx?id=" + form_id + "&table=" + form_table;
  70.             HlFormNo.Target = "_blank";
  71.         }
  72.         cmd = new SqlCommand("select attachment, attachment_save_name, content_length from OA_FAIR_ATTACHMENT where fair_id=" + fair_id, conn);
  73.         dr = cmd.ExecuteReader();
  74.         while (dr.Read())
  75.         {
  76.             TblFair.Rows[9].Visible = true;
  77.             HyperLink img = new HyperLink();
  78.             img.ToolTip = dr["attachment"].ToString();
  79.             img.ImageUrl = "../fair_picture/" + dr["attachment_save_name"].ToString();
  80.             img.Target = "_blank";
  81.             img.Width = Unit.Pixel(450);
  82.             img.NavigateUrl = img.ImageUrl;
  83.             PnlPicture.Controls.Add(img);
  84.         }
  85.         dr.Close();
  86.         conn.Close();
  87.     }
  88.     protected void SetTable()
  89.     {
  90.         SqlConnection conn = dbConnection.getConnection();
  91.         conn.Open();
  92.         string user_id = "0";
  93.         if (Session["user_id"] != null)
  94.         {
  95.             user_id = Session["user_id"].ToString();
  96.         }
  97.         SqlCommand cmd = new SqlCommand("SELECT f.id,f.form_id, f.step f_step, a.step a_step, e.department_id, "+
  98.             "e.emp_name, a.apply_date FROM dbo.OA_FAIR_FORM_FLOW AS f INNER JOIN dbo.OA_FAIR AS a ON "+
  99.             "f.form_id = a.id INNER JOIN dbo.OA_EMPLOYEE AS e ON a.emp_id = e.id WHERE (f.operator_id = " + 
  100.             user_id + ") AND (f.is_check = 'N') order by a.apply_date desc", conn);
  101.         SqlDataReader dr = cmd.ExecuteReader();
  102.         while (dr.Read())
  103.         {
  104.             int a_step = Convert.ToInt32(dr["a_step"].ToString()) + 1;
  105.             int f_step = Convert.ToInt32(dr["f_step"].ToString());
  106.             if (a_step == f_step)
  107.             {
  108.                 TblFlow.Visible = true;
  109.                 TableRow tr = new TableRow();
  110.                 TableCell td = new TableCell();
  111.                 td.BorderWidth = Unit.Pixel(1);
  112.                 td.Text = dr["emp_name"].ToString();
  113.                 tr.Cells.Add(td);
  114.                 td = new TableCell();
  115.                 td.BorderWidth = Unit.Pixel(1);
  116.                 DepartmentDAO departmentDAO = new DepartmentDAO();
  117.                 string department = departmentDAO.queryById(Convert.ToInt32(dr["department_id"].ToString())).Full_name;
  118.                 td.Text = department;
  119.                 tr.Cells.Add(td);
  120.                 td = new TableCell();
  121.                 td.BorderWidth = Unit.Pixel(1);
  122.                 td.Text = dr["apply_date"].ToString();
  123.                 tr.Cells.Add(td);
  124.                 td = new TableCell();
  125.                 td.BorderWidth = Unit.Pixel(1);
  126.                 HyperLink hl = new HyperLink();
  127.                 hl.Text = "查看";
  128.                 hl.NavigateUrl = "deal_list.aspx?f_id=" + dr["id"].ToString()+"&f_id1="+dr["form_id"].ToString();
  129.                 td.Controls.Add(hl);
  130.                 tr.Cells.Add(td);
  131.                 TblFlow.Rows.Add(tr);
  132.             }
  133.         }
  134.         dr.Close();
  135.         
  136.         conn.Close();
  137.     }
  138.     protected void RbAgree_SelectedIndexChanged(object sender, EventArgs e)
  139.     {
  140.         if (TxtComment.Text.Equals("已同意") || TxtComment.Text.Equals("不同意"))
  141.         {
  142.             if (RbAgree.SelectedValue.Equals("Y"))
  143.             {
  144.                 TxtComment.Text = "已同意";
  145.             }
  146.             else
  147.             {
  148.                 TxtComment.Text = "不同意";
  149.             }
  150.         }
  151.     }
  152.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  153.     {
  154.         if (e.Row.RowType == DataControlRowType.DataRow)
  155.         {
  156.             SqlConnection conn = dbConnection.getConnection();
  157.             conn.Open();
  158.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  159.                 "OA_FAIR_FORM_FLOW where id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  160.             SqlDataReader dr = cmd.ExecuteReader();
  161.             if (dr.Read())
  162.             {
  163.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  164.                 if (dr["apply_type"].ToString().Equals("1"))
  165.                 {
  166.                     label.Text = "會簽";
  167.                 }
  168.                 else
  169.                 {
  170.                     label.Text = "審批";
  171.                 }
  172.                 label = (Label)e.Row.FindControl("LblIsCheck");
  173.                 if (dr["is_check"].ToString().Equals("N"))
  174.                 {
  175.                     label.Text = "未處理";
  176.                 }
  177.                 else
  178.                 {
  179.                     label.Text = "已處理";
  180.                     label = (Label)e.Row.FindControl("LblIsAgree");
  181.                     if (dr["is_agree"].ToString().Equals("Y"))
  182.                     {
  183.                         label.Text = "已同意";
  184.                     }
  185.                     else
  186.                     {
  187.                         label.Text = "不同意";
  188.                     }
  189.                 }
  190.                 label = (Label)e.Row.FindControl("LblComment");
  191.                 label.Text = dr["comment"].ToString();
  192.             }
  193.             dr.Close();
  194.             conn.Close();
  195.         }
  196.     }
  197.     protected void BtnOk_Click(object sender, EventArgs e)
  198.     {
  199.         SqlConnection conn = dbConnection.getConnection();
  200.         conn.Open();
  201.         SqlTransaction tx = conn.BeginTransaction();
  202.         try
  203.         {
  204.             DateMgr mgr = new DateMgr();
  205.             SqlCommand cmd = new SqlCommand("update OA_FAIR_FORM_FLOW set is_check='Y', is_agree='" +
  206.                 RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + "', check_date='" + mgr.getDateTime() +
  207.                 "' where id=" + Request.QueryString["f_id"], conn);
  208.             cmd.Transaction = tx;
  209.             cmd.ExecuteNonQuery();
  210.             cmd = new SqlCommand("select form_id from OA_FAIR_FORM_FLOW where id=" + Request.QueryString["f_id"], conn);
  211.             cmd.Transaction = tx;
  212.             int form_id = Convert.ToInt32(cmd.ExecuteScalar());
  213.             cmd = new SqlCommand("select max(step) from OA_FAIR_FORM_FLOW where form_id=" + form_id, conn);
  214.             cmd.Transaction = tx;
  215.             int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  216.             cmd = new SqlCommand("select step from OA_FAIR where id=" + form_id, conn);
  217.             cmd.Transaction = tx;
  218.             int step = Convert.ToInt32(cmd.ExecuteScalar());
  219.             string total_result = "跑流程中";
  220.             string time = "";
  221.             if (max_step == step + 1)
  222.             {
  223.                 if (RbAgree.SelectedValue.Equals("N"))
  224.                 {
  225.                     total_result = "不同意";
  226.                 }
  227.                 else
  228.                 {
  229.                     total_result = "同意";
  230.                 }
  231.                 time = mgr.getDateTime();
  232.             }
  233.             else
  234.             {
  235.                 if (RbAgree.SelectedValue.Equals("N"))
  236.                 {
  237.                     total_result = "不同意";
  238.                     time = mgr.getDateTime();
  239.                 }
  240.             }
  241.             cmd = new SqlCommand("update OA_FAIR set step=step+1, total_result='" +
  242.                 total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  243.             cmd.Transaction = tx;
  244.             cmd.ExecuteNonQuery();
  245.             tx.Commit();
  246.      //mail
  247.             ArrayList name1 = new ArrayList();
  248.             ArrayList mail1 = new ArrayList();
  249.             cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join "+
  250.                "OA_FAIR_FORM_FLOW as b on b.operator_id=a.id left join OA_FAIR as c "+
  251.                  "on b.form_id=c.id where b.step=c.step+1 and c.id=" + form_id + " order by position desc", conn);
  252.             cmd.Transaction = tx;
  253.             SqlDataReader dr3 = cmd.ExecuteReader();
  254.             while (dr3.Read())
  255.             {
  256.                 name1.Add(dr3["emp_name"].ToString());
  257.                 mail1.Add(dr3["email_work"].ToString());
  258.                 //mail_q(mail1[0],name1[0]);
  259.                 //mail.mail_q(mail1[0],name1[0],TxtEmpName.Text,"費用申請單");
  260.             } dr3.Close();
  261.        //     
  262.         }
  263.         catch (Exception ex)
  264.         {
  265.             Response.Write(ex.ToString());
  266.             //tx.Rollback();
  267.         }
  268.         conn.Close();
  269.         Response.Redirect("finish_list.aspx");
  270.     }
  271. }