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

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_approvel_tw_form : System.Web.UI.Page
  16. {
  17.     ArrayList apply_type = new ArrayList();
  18.     ArrayList operator_id = new ArrayList();  
  19.      
  20.     private int count = 0;
  21.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         if (!IsPostBack)
  24.         {
  25.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  26.             if (Session["user"] != null)
  27.             {
  28.                 DateMgr mgr = new DateMgr();
  29.                 User user = (User)Session["user"];
  30.                 TxtApplyDate.Text = mgr.getDateTime();
  31.                 TxtFormNo.Text = mgr.getTime();
  32.                 TxtEmpName.Text = user.Emp_name;
  33.                 EmpId.Value = user.Id.ToString();
  34.                 TxtEmpNo.Text = user.Emp_no;
  35.                 TxtDepartment.Text = user.Department.Full_name;
  36.                 DepartmentId.Value = user.Department.Id.ToString();
  37.                 TxtPosition.Text = user.Position;
  38.                 PositionSequence.Value = user.PositionSequence.ToString();
  39.                 PositionId.Value = user.PositionId.ToString();
  40.                 Session["department_id"] = user.Department.Id.ToString();
  41.             }
  42.         }
  43.     }
  44.      
  45.     protected void BtnSave_Click(object sender, EventArgs e)
  46.     {
  47.         this.save(2);
  48.     }
  49.     protected void BtnOk_Click(object sender, EventArgs e)
  50.     {
  51.         this.save(1);
  52.     }
  53.    
  54.     protected void save(int state)
  55.     {
  56.         if (this.CheckValidate)
  57.         {
  58.             SqlConnection conn = dbConnection.getConnection();
  59.             conn.Open();
  60.             SqlTransaction tx = conn.BeginTransaction();
  61.             string sql = "";
  62.             try
  63.             {
  64.                 int id = 1;
  65.                 SqlCommand cmd = new SqlCommand("select max(id) from OA_POS_C_FORM", conn);
  66.                 cmd.Transaction = tx;
  67.                 try
  68.                 {
  69.                     id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  70.                 }
  71.                 catch { }
  72.                 string total_result = "跑流程中";
  73.                 if (state == 2)
  74.                 {
  75.                     total_result = "未送件";
  76.                 }
  77.                 sql = "insert into OA_POS_C_FORM(id, form_id, emp_id, department_id, " +
  78.                        "emp_name,emp_position,t_count,t_count1,t_lv,t_date,remark," +
  79.                     "step, total_result, finish_date, is_del, apply_date, state) values (" +
  80.                     id + ", '" + TxtFormNo.Text + "','" + EmpId.Value + "', '" + DepartmentId.Value + "','" +              
  81.                     +TxtEmpName.Text+"','"+TxtPosition.Text+"','"+TextCount.Text+"','"+TextCount1.Text+"','"+
  82.                     +TextLv.Text+"','"+TextDate.Text+"',"+                                                     
  83.                     "0,'" + total_result + "','','N','" + TxtApplyDate.Text + "','" + state + "')";
  84.                 cmd = new SqlCommand(sql, conn);
  85.                 cmd.Transaction = tx;
  86.                 cmd.ExecuteNonQuery();
  87.                 int flow_id = 1;
  88.                 cmd = new SqlCommand("select max(id) from OA_pos_c_FORM_FLOW", conn);
  89.                 cmd.Transaction = tx;
  90.                 try
  91.                 {
  92.                     flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  93.                 }
  94.                 catch { }              
  95.                 
  96.                 if (state == 1)
  97.                 {//逐级签核
  98.                     flow_id++;
  99.                     ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
  100.                     ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
  101.                     ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  102.                     ArrayList last_id = new ArrayList();//记录上层节点的ID
  103.                     ArrayList tmp_people = new ArrayList();//记录待签核人的ID
  104.                     ArrayList d_people = new ArrayList();
  105.                     ArrayList b_d_people = new ArrayList();
  106.                     ArrayList mail2 = new ArrayList();//记录代理人的MAIL
  107.                     ArrayList mail2_name = new ArrayList();//记录代理人姓名
  108.                                   
  109.                     
  110.                    
  111.                   
  112.                         //找到上层节点部门的ID
  113.                         
  114.                         for (int j = 1; j < 2; j++)
  115.                         {
  116.                             
  117.                             cmd = new SqlCommand("select id from oa_department where last_id=39 or id=39", conn);
  118.                             cmd.Transaction = tx;
  119.                             SqlDataReader dr2 = cmd.ExecuteReader();
  120.                             
  121.                             while (dr2.Read())
  122.                             {
  123.                                 last_id.Add(dr2["id"].ToString());
  124.                                 
  125.                             }
  126.                             dr2.Close();
  127.                         }
  128.                         for (int j = 1; j < last_id.Count; j++)
  129.                         {
  130.                             cmd = new SqlCommand("select id from oa_employee where department_id="+last_id[j], conn);
  131.                             cmd.Transaction = tx;
  132.                             SqlDataReader dr2 = cmd.ExecuteReader();
  133.                             while (dr2.Read())
  134.                             {
  135.                                 id1.Add(dr2["id"].ToString());
  136.                             }
  137.                             dr2.Close();
  138.                         }
  139.                        
  140.                     //  确定是否有代理人签核
  141.                         for (int k = 0; k < id1.Count; k++)
  142.                         {
  143.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  144.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + id1[k] + "'", conn);
  145.                             cmd.Transaction = tx;
  146.                             SqlDataReader dr3 = cmd.ExecuteReader();
  147.                             while (dr3.Read())
  148.                             {
  149.                                 d_people.Add(dr3["d_people"].ToString());
  150.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  151.                                 id1.RemoveAt(k);
  152.                                 id1.Add(dr3["d_people"].ToString());
  153.                             }
  154.                             dr3.Close();
  155.                         }
  156.                         
  157.                      //                      
  158.                     }
  159.                   
  160.                     if (id1.Count!= null)
  161.                     {
  162.                       
  163.                         for (int i = 0; i < id1.Count; i++)
  164.                         {
  165.                             cmd = new SqlCommand("insert into OA_pos_c_FORM_FLOW(id,form_id, operator_id, " +
  166.                                 "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  167.                                 flow_id + ", " + id + "," + id1[i] + ",1,'N','N','',''," + (i + 2) + ")", conn);
  168.                             cmd.Transaction = tx;
  169.                             cmd.ExecuteNonQuery();
  170.                     
  171.                            }                         
  172.                    
  173.                     for (int d = 0; d < id1.Count; d++)
  174.                         {
  175.                             cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
  176.                             +DelegateId.Value + "','" + Session["user_id"] + "','" + TxtVacationBegin.Text+"','"+TxtVacationEnd.Text+"')", conn);
  177.                             cmd.Transaction = tx;
  178.                             cmd.ExecuteNonQuery();
  179.                            
  180.                             flow_id++;
  181.                         }
  182.                         tx.Commit();
  183.                         Response.Redirect("my_list.aspx");
  184.                     }
  185.                     else
  186.                     {
  187.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  188.                         tx.Rollback();
  189.                     }               
  190.                 
  191.                     tx.Commit();
  192.                     Response.Redirect("my_list.aspx");
  193.                 
  194.                 #region
  195.               
  196.                 #endregion
  197.             }
  198.             catch (Exception ex)
  199.             {
  200.                 Response.Write(ex.Message);
  201.                 try
  202.                 {
  203.                     tx.Rollback();
  204.                 }
  205.                 catch { }
  206.             }
  207.             conn.Close();
  208.         }
  209.     }
  210.    
  211.     protected bool CheckValidate()
  212.     {
  213.         LblError.Text = "";
  214.         int flag = 0;
  215.         if (TextCount.Text.Equals(""))
  216.         {
  217.             flag = 1;
  218.             Response.Write("<script>alert('來客數不能為空')</script>");
  219.             LblError.Text = "來客數不能為空";
  220.             TextCount.Focus();
  221.         }
  222.         if (TextDate.Text.Equals(""))
  223.         {
  224.             flag = 1;
  225.             Response.Write("<script>alert('提袋日期不能為空')</script>");
  226.             LblError.Text = "提袋日期不能為空";
  227.             TextDate.Focus();
  228.         }
  229.         if (flag == 0)
  230.         {
  231.             return true;
  232.         }
  233.         else
  234.         {
  235.             return false;
  236.         }
  237.     }
  238.     
  239.   
  240. }