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

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. public partial class web_computer_form : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             LoginDAO.CheckLogin(Session, Response, "../", 2);
  19.             if (Session["user"] != null)
  20.             {
  21.                 DateMgr mgr = new DateMgr();
  22.                 User user = (User)Session["user"];
  23.                 date1.Text = mgr.getDateTime();
  24.                 form_id.Text = mgr.getTime();
  25.                 emp_name.Text = user.Emp_name;
  26.                // EmpId.Value = user.Id.ToString();
  27.                 emp_no.Text = user.Emp_no;
  28.                 emp_dept.Text = user.Department.Full_name;
  29.               //  DepartmentId.Value = user.Department.Id.ToString();
  30.                 emp_position.Text = user.Position;
  31.              //   PositionSequence.Value = user.PositionSequence.ToString();
  32.              //   PositionId.Value = user.PositionId.ToString();
  33.                 Session["department_id"] = user.Department.Id.ToString();
  34.             }
  35.         }
  36.     }
  37.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  38.     {
  39.         if (CalEnddate.Visible == true)
  40.         {
  41.             CalEnddate.Visible = false;
  42.             CalEnddate.Focus();
  43.         }
  44.         else
  45.         {
  46.             CalEnddate.Visible = true;
  47.             CalEnddate.Focus();
  48.         }
  49.     }
  50.     protected void CalEnddate_SelectionChanged(object sender, EventArgs e)
  51.     {
  52.         CalEnddate.Visible = false;
  53.         string year = CalEnddate.SelectedDate.Year.ToString();
  54.         string month = CalEnddate.SelectedDate.Month.ToString();
  55.         if (month.Length == 1)
  56.         {
  57.             month = "0" + month;
  58.         }
  59.         string day = CalEnddate.SelectedDate.Day.ToString();
  60.         if (day.Length == 1)
  61.         {
  62.             day = "0" + day;
  63.         }
  64.         Enddate.Text = year + "-" + month + "-" + day + " 00:00:00";
  65.         Enddate.Focus();
  66.     }
  67.     protected void btn_ok_Click(object sender, EventArgs e)
  68.     {
  69.         if (CheckValidate())
  70.         {
  71.             this.save(1);
  72.         }
  73.        
  74.     }
  75.         protected bool CheckValidate()
  76.     {
  77.         int flag = 0;
  78.         if (DepartmentId.Value.Equals("") || DepartmentId.Value.Equals("0"))
  79.         {
  80.             flag = 1;
  81.             Response.Write("<script>alert('請選擇送至部門')</script>");
  82.             TxtDepartment.Focus();
  83.         }
  84.         if (f_item.Text.Equals("") || f_item.Text.Equals("0"))
  85.         {
  86.             flag = 1;
  87.             Response.Write("<script>alert('請填寫聯繫電話')</script>");
  88.             f_item.Focus();
  89.         }
  90.         if (content.Text.Equals("") || content.Text.Equals("0"))
  91.         {
  92.             flag = 1;
  93.             Response.Write("<script>alert('請填寫說明')</script>");
  94.             content.Focus();
  95.         }
  96.         if (flag == 0)
  97.         {
  98.             return true;
  99.         }
  100.         else
  101.         {
  102.             return false;
  103.         }
  104.     }
  105.   
  106.    
  107.     protected void save(int state)
  108.     {
  109.             
  110.             SqlConnection conn = dbConnection.getConnection();
  111.             conn.Open();
  112.             SqlTransaction tx = conn.BeginTransaction();
  113.             string sql = "";
  114.             try
  115.             {  //表信息
  116.                 int id = 1;
  117.                 SqlCommand cmd = new SqlCommand("select max(id) from oa_computer_form", conn);
  118.                 cmd.Transaction = tx;
  119.                 try
  120.                 {
  121.                     id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  122.                 }
  123.                 catch 
  124.                 { }
  125.                 string total_result = "跑流程中";
  126.                 if (state == 2)
  127.                 {
  128.                     total_result = "未送件";
  129.                 }
  130.                //插入表的内容
  131.                 sql = "insert into oa_computer_form(id,form_id,emp_no,emp_name,date1,emp_dept,"+
  132.                     "emp_position,item1,enddate,to_dpt_id,content,status,emp_id)values('"+id+
  133.                     "','"+form_id.Text+"','"+emp_no.Text+"','"+emp_name.Text+
  134.                     "','"+date1.Text+"','"+emp_dept.Text+"','"+emp_position.Text+"','"+f_item.Text+
  135.                     "','" + Enddate.Text + "','" + DepartmentId.Value+ "','" + content.Text +
  136.                     "','" + total_result + "','" + Session["user_id"] + "')";
  137.                 cmd = new SqlCommand(sql, conn);
  138.                 cmd.Transaction = tx;
  139.                 cmd.ExecuteNonQuery();    
  140.               
  141.                }   
  142.                                  
  143.                        
  144.               catch (Exception ex)
  145.             {
  146.                 Response.Write(ex.Message);
  147.                
  148.             }
  149.             //签核状况
  150.             try
  151.             {
  152.                 ArrayList operator_id = new ArrayList();
  153.                 ArrayList department_id = new ArrayList();
  154.                 ArrayList email_work = new ArrayList();
  155.                 ArrayList operator_name = new ArrayList();
  156.                 int id = 1;
  157.                 SqlCommand cmd = new SqlCommand("select max(id) from oa_computer_form_flow", conn);
  158.                 cmd.Transaction = tx;
  159.                 try
  160.                 {
  161.                     id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  162.                 }
  163.                 catch { }
  164.                 int id1 = 1;
  165.                 try
  166.                 {
  167.                     cmd = new SqlCommand("select email_work,emp_name, id from oa_employee where department_id=" + DepartmentId.Value + " and q_manger='1' and dimission_date=''", conn);
  168.                     cmd.Transaction = tx;
  169.                     SqlDataReader dr = cmd.ExecuteReader();
  170.                     if (dr.HasRows)
  171.                     {
  172.                         while (dr.Read())
  173.                         {
  174.                             operator_id.Add(dr["id"].ToString());
  175.                             email_work.Add(dr["email_work"].ToString());
  176.                             operator_name.Add(dr["emp_name"].ToString());
  177.                         }
  178.                         dr.Close();
  179.                         //  确定是否有代理人签核
  180.                         ArrayList d_people = new ArrayList();
  181.                         ArrayList b_d_people = new ArrayList();
  182.                         for (int k = 0; k < operator_id.Count; k++)
  183.                         {
  184.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  185.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + operator_id[k] + "'", conn);
  186.                             cmd.Transaction = tx;
  187.                             SqlDataReader dr3 = cmd.ExecuteReader();
  188.                             while (dr3.Read())
  189.                             {
  190.                                 d_people.Add(dr3["d_people"].ToString());
  191.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  192.                                 operator_id.RemoveAt(k);
  193.                                 operator_id.Add(dr3["d_people"].ToString());
  194.                             }
  195.                             dr3.Close();
  196.                         } 
  197.                         //
  198.                        
  199.                         int j = 1;
  200.                         for (int i = 0; i < operator_id.Count; i++)
  201.                         {
  202.                             cmd = new SqlCommand("insert into oa_computer_form_flow(id,form_id,f_id,apply_type,operator_id,is_check,is_agree,check_date," +
  203.                             "comment,step)values('" + id + "','" + form_id.Text + "','" + id + "','2','" + operator_id[i] + "','N','N','','','" + j + "')", conn);
  204.                             j++;
  205.                             id++;
  206.                             cmd.Transaction = tx;
  207.                             cmd.ExecuteNonQuery();
  208.                             mail.mail_q(email_work[i], operator_name[i], emp_name.Text, "問題回饋單");
  209.                         }
  210.                         tx.Commit();
  211.                         Response.Redirect("my_list.aspx");
  212.                     }
  213.                     else 
  214.                     { 
  215.                         Response.Write("沒有部門主管");
  216.                         
  217.                     }
  218.                    
  219.                 }
  220.                    
  221.                 catch (Exception ex)
  222.                 {
  223.                     Response.Write(ex.Message);
  224.                 }
  225.          
  226.             }
  227.             catch (Exception ex)
  228.             {
  229.                 Response.Write(ex.Message);
  230.                
  231.             }
  232.             conn.Close();
  233.         
  234.     }
  235.     protected void btn_cancel_Click(object sender, EventArgs e)
  236.     {
  237.         Response.Redirect("../computer/form.aspx");
  238.     }
  239. }