work_form.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_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.     protected void ImageButton2_Click(object sender, EventArgs e)
  45.     {
  46.         if (Calendar2.Visible == true)
  47.         {
  48.             Calendar2.Visible = false;
  49.             Calendar2.Focus();
  50.         }
  51.         else
  52.         {
  53.             Calendar2.Visible = true;
  54.             Calendar2.Focus();
  55.         }
  56.     }
  57.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  58.     {
  59.         Calendar2.Visible = false;
  60.         string year = Calendar2.SelectedDate.Year.ToString();
  61.         string month = Calendar2.SelectedDate.Month.ToString();
  62.         if (month.Length == 1)
  63.         {
  64.             month = "0" + month;
  65.         }
  66.         string day = Calendar2.SelectedDate.Day.ToString();
  67.         if (day.Length == 1)
  68.         {
  69.             day = "0" + day;
  70.         }
  71.         TextDate.Text = year + "-" + month + "-" + day ;
  72.         TxtRemark.Focus();
  73.     }
  74.     protected void BtnSave_Click(object sender, EventArgs e)
  75.     {
  76.         this.save(2);
  77.     }
  78.     protected void BtnOk_Click(object sender, EventArgs e)
  79.     {
  80.         this.save(1);
  81.     }
  82.    
  83.     protected void save(int state)
  84.     {
  85.         if (this.CheckValidate())
  86.         {
  87.             SqlConnection conn = dbConnection.getConnection();
  88.             conn.Open();
  89.             SqlTransaction tx = conn.BeginTransaction();
  90.             string sql = "";
  91.             try
  92.             {
  93.                 int id = 1;
  94.                 SqlCommand cmd = new SqlCommand("select max(id) from OA_POS_C_FORM", conn);
  95.                 cmd.Transaction = tx;
  96.                 try
  97.                 {
  98.                     id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  99.                 }
  100.                 catch { }
  101.                 string total_result = "完成";
  102.                 if (state == 2)
  103.                 {
  104.                     total_result = "未送件";
  105.                 }
  106.                 sql = "insert into OA_POS_C_FORM(id, form_id, emp_id, department_id, " +
  107.                        "emp_name,emp_position,t_count,t_count1,t_lv,t_date,remark," +
  108.                     "step, total_result, finish_date, is_del, apply_date, state) values (" +
  109.                     id + ", '" + TxtFormNo.Text + "','" + EmpId.Value + "', '" + DepartmentId.Value + "','" +              
  110.                     TxtEmpName.Text+"','"+TxtPosition.Text+"','"+TextCount.Text+"','"+TextCount1.Text+"','"+
  111.                    TextLv.Text+"','"+TextDate.Text+"','"+TxtRemark.Text+"',"+                                                     
  112.                     "0,'" + total_result + "','','N','" + TxtApplyDate.Text + "','" + state + "')";
  113.                 cmd = new SqlCommand(sql, conn);
  114.                 cmd.Transaction = tx;
  115.                 cmd.ExecuteNonQuery();
  116.                 int flow_id = 1;
  117.                 cmd = new SqlCommand("select max(id) from OA_pos_c_FORM_FLOW", conn);
  118.                 cmd.Transaction = tx;
  119.                 try
  120.                 {
  121.                     flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  122.                 }
  123.                 catch { }              
  124.                 
  125.               //  if (state == 1)
  126.              //   {//逐级签核
  127.                     flow_id++;
  128.                     ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
  129.                     ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
  130.                     ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  131.                     ArrayList last_id = new ArrayList();//记录上层节点的ID
  132.                     ArrayList tmp_people = new ArrayList();//记录待签核人的ID
  133.                     ArrayList d_people = new ArrayList();
  134.                     ArrayList b_d_people = new ArrayList();
  135.                     ArrayList mail2 = new ArrayList();//记录代理人的MAIL
  136.                     ArrayList mail2_name = new ArrayList();//记录代理人姓名
  137.                                   
  138.                     
  139.                    
  140.                   
  141.                         //找到上层节点部门的ID
  142.                         
  143.                         for (int j = 1; j < 2; j++)
  144.                         {
  145.                             
  146.                             cmd = new SqlCommand("select id from oa_department where last_id=39 or id=39", conn);
  147.                             cmd.Transaction = tx;
  148.                             SqlDataReader dr2 = cmd.ExecuteReader();
  149.                             
  150.                             while (dr2.Read())
  151.                             {
  152.                                 last_id.Add(dr2["id"].ToString());
  153.                                 
  154.                             }
  155.                             dr2.Close();
  156.                         }
  157.                         for (int j = 1; j < last_id.Count; j++)
  158.                         {
  159.                             cmd = new SqlCommand("select id from oa_employee where department_id="+last_id[j], conn);
  160.                             cmd.Transaction = tx;
  161.                             SqlDataReader dr2 = cmd.ExecuteReader();
  162.                             while (dr2.Read())
  163.                             {
  164.                                 id1.Add(dr2["id"].ToString());
  165.                             }
  166.                             dr2.Close();
  167.                         }
  168.                        
  169.                     //  确定是否有代理人签核
  170.                         for (int k = 0; k < id1.Count; k++)
  171.                         {
  172.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  173.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + id1[k] + "'", conn);
  174.                             cmd.Transaction = tx;
  175.                             SqlDataReader dr3 = cmd.ExecuteReader();
  176.                             while (dr3.Read())
  177.                             {
  178.                                 d_people.Add(dr3["d_people"].ToString());
  179.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  180.                                 id1.RemoveAt(k);
  181.                                 id1.Add(dr3["d_people"].ToString());
  182.                             }
  183.                             dr3.Close();
  184.                         }
  185.                         
  186.                      //                      
  187.                    
  188.                   
  189.                    
  190.                       
  191.                      /*   for (int i = 0; i < id1.Count; i++)
  192.                         {
  193.                             cmd = new SqlCommand("insert into OA_pos_c_FORM_FLOW(id,form_id, operator_id, " +
  194.                                 "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  195.                                 flow_id + ", " + id + "," + id1[i] + ",1,'N','N','',''," + (i + 2) + ")", conn);
  196.                             cmd.Transaction = tx;
  197.                             cmd.ExecuteNonQuery();
  198.                     
  199.                            }
  200.                  */      
  201.                     
  202.                     
  203.                         tx.Commit();
  204.                         Response.Write("簽核成功!");
  205.                         Response.Redirect("../pos_c/my_list.aspx");
  206.                         TextCount.Text = "";
  207.                         TextCount1.Text = "";
  208.                         TextLv.Text = "";
  209.                         TextDate.Text = "";
  210.                         TxtRemark.Text = "";
  211.                  //   }
  212.                     
  213.                      
  214.                   //  else
  215.                   //  {
  216.                   //      LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  217.                   //      tx.Rollback();
  218.                   //  }               
  219.                 
  220.                    
  221.                 #region
  222.               
  223.                 #endregion
  224.             }
  225.             catch (Exception ex)
  226.             {
  227.                 Response.Write(ex.Message);
  228.                 try
  229.                 {
  230.                     tx.Rollback();
  231.                 }
  232.                 catch { }
  233.             }
  234.             conn.Close();
  235.         }
  236.     }
  237.     protected void change(EventArgs eventArgs)
  238.     {
  239.        
  240.         double lv = 0.00;
  241.               
  242.         lv = Convert.ToInt32(TextCount1.Text) / Convert.ToInt32(TextCount.Text);
  243.         TextLv.Text = lv.ToString();
  244.            
  245.         
  246.         
  247.     }
  248.    
  249.     protected bool CheckValidate()
  250.     {
  251.         LblError.Text = "";
  252.         int flag = 0;
  253.         if (TextCount.Text.Equals(""))
  254.         {
  255.             flag = 1;
  256.             Response.Write("<script>alert('來客數不能為空')</script>");
  257.             LblError.Text = "來客數不能為空";
  258.             TextCount.Focus();
  259.         }
  260.         if (TextDate.Text.Equals(""))
  261.         {
  262.             flag = 1;
  263.             Response.Write("<script>alert('提袋日期不能為空')</script>");
  264.             LblError.Text = "提袋日期不能為空";
  265.             TextDate.Focus();
  266.         }
  267.         if (flag == 0)
  268.         {
  269.             return true;
  270.         }
  271.         else
  272.         {
  273.             return false;
  274.         }
  275.     }
  276.     
  277.   
  278. }