form.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:10k
源码类别:
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;
- using System.Net.Mail;
- using System.Net;
- using System.Net.Sockets;
- public partial class web_approvel_tw_form : System.Web.UI.Page
- {
- ArrayList apply_type = new ArrayList();
- ArrayList operator_id = new ArrayList();
- private int count = 0;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- if (Session["user"] != null)
- {
- DateMgr mgr = new DateMgr();
- User user = (User)Session["user"];
- TxtApplyDate.Text = mgr.getDateTime();
- TxtFormNo.Text = mgr.getTime();
- TxtEmpName.Text = user.Emp_name;
- EmpId.Value = user.Id.ToString();
- TxtEmpNo.Text = user.Emp_no;
- TxtDepartment.Text = user.Department.Full_name;
- DepartmentId.Value = user.Department.Id.ToString();
- TxtPosition.Text = user.Position;
- PositionSequence.Value = user.PositionSequence.ToString();
- PositionId.Value = user.PositionId.ToString();
- Session["department_id"] = user.Department.Id.ToString();
- }
- }
- }
- protected void BtnSave_Click(object sender, EventArgs e)
- {
- this.save(2);
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- this.save(1);
- }
- protected void save(int state)
- {
- if (this.CheckValidate)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- string sql = "";
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_POS_C_FORM", conn);
- cmd.Transaction = tx;
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- string total_result = "跑流程中";
- if (state == 2)
- {
- total_result = "未送件";
- }
- sql = "insert into OA_POS_C_FORM(id, form_id, emp_id, department_id, " +
- "emp_name,emp_position,t_count,t_count1,t_lv,t_date,remark," +
- "step, total_result, finish_date, is_del, apply_date, state) values (" +
- id + ", '" + TxtFormNo.Text + "','" + EmpId.Value + "', '" + DepartmentId.Value + "','" +
- +TxtEmpName.Text+"','"+TxtPosition.Text+"','"+TextCount.Text+"','"+TextCount1.Text+"','"+
- +TextLv.Text+"','"+TextDate.Text+"',"+
- "0,'" + total_result + "','','N','" + TxtApplyDate.Text + "','" + state + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- int flow_id = 1;
- cmd = new SqlCommand("select max(id) from OA_pos_c_FORM_FLOW", conn);
- cmd.Transaction = tx;
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- if (state == 1)
- {//逐级签核
- flow_id++;
- ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
- ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
- ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
- ArrayList last_id = new ArrayList();//记录上层节点的ID
- ArrayList tmp_people = new ArrayList();//记录待签核人的ID
- ArrayList d_people = new ArrayList();
- ArrayList b_d_people = new ArrayList();
- ArrayList mail2 = new ArrayList();//记录代理人的MAIL
- ArrayList mail2_name = new ArrayList();//记录代理人姓名
- //找到上层节点部门的ID
- for (int j = 1; j < 2; j++)
- {
- cmd = new SqlCommand("select id from oa_department where last_id=39 or id=39", conn);
- cmd.Transaction = tx;
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- last_id.Add(dr2["id"].ToString());
- }
- dr2.Close();
- }
- for (int j = 1; j < last_id.Count; j++)
- {
- cmd = new SqlCommand("select id from oa_employee where department_id="+last_id[j], conn);
- cmd.Transaction = tx;
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- id1.Add(dr2["id"].ToString());
- }
- dr2.Close();
- }
- // 确定是否有代理人签核
- for (int k = 0; k < id1.Count; k++)
- {
- cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where s_date<=convert(varchar, getdate(), 120)" +
- " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + id1[k] + "'", conn);
- cmd.Transaction = tx;
- SqlDataReader dr3 = cmd.ExecuteReader();
- while (dr3.Read())
- {
- d_people.Add(dr3["d_people"].ToString());
- b_d_people.Add(dr3["b_d_people"].ToString());
- id1.RemoveAt(k);
- id1.Add(dr3["d_people"].ToString());
- }
- dr3.Close();
- }
- //
- }
- if (id1.Count!= null)
- {
- for (int i = 0; i < id1.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_pos_c_FORM_FLOW(id,form_id, operator_id, " +
- "apply_type, is_check, is_agree, comment, check_date, step)values(" +
- flow_id + ", " + id + "," + id1[i] + ",1,'N','N','',''," + (i + 2) + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- for (int d = 0; d < id1.Count; d++)
- {
- cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
- +DelegateId.Value + "','" + Session["user_id"] + "','" + TxtVacationBegin.Text+"','"+TxtVacationEnd.Text+"')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- flow_id++;
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- }
- else
- {
- LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
- tx.Rollback();
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- #region
- #endregion
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- try
- {
- tx.Rollback();
- }
- catch { }
- }
- conn.Close();
- }
- }
- protected bool CheckValidate()
- {
- LblError.Text = "";
- int flag = 0;
- if (TextCount.Text.Equals(""))
- {
- flag = 1;
- Response.Write("<script>alert('來客數不能為空')</script>");
- LblError.Text = "來客數不能為空";
- TextCount.Focus();
- }
- if (TextDate.Text.Equals(""))
- {
- flag = 1;
- Response.Write("<script>alert('提袋日期不能為空')</script>");
- LblError.Text = "提袋日期不能為空";
- TextDate.Focus();
- }
- if (flag == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }