o_form.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:16k
源码类别:
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_ch_o_form : System.Web.UI.Page
- {
- private int count = 0;
- ArrayList apply_type = new ArrayList();
- ArrayList operator_id = new ArrayList();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- if (Session["user"] != null)
- {
- DateMgr mgr = new DateMgr();
- TxtFormId.Text = mgr.getTime();
- TxtApplyDate.Text = mgr.getDateTime();
- User user = (User)Session["user"];
- TxtEmpName.Text = user.Emp_no + user.Emp_name;
- EmpId.Value = user.Id.ToString();
- TxtPosition.Text = user.Position;
- DepartmentId.Value = user.Department.Id.ToString();
- TxtDepartment.Text = user.Department.Full_name;
- PositionSequence.Value = user.PositionSequence.ToString();
- PositionId.Value = user.PositionId.ToString();
- }
- }
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar1.Visible == true)
- {
- Calendar1.Visible = false;
- }
- else
- {
- Calendar1.Visible = true;
- }
- }
- protected void Calendar1_SelectionChanged(object sender, EventArgs e)
- {
- Calendar1.Visible = false;
- string year = Calendar1.SelectedDate.Year.ToString();
- string month = Calendar1.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = Calendar1.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- TxtBeginTime.Text = year + "-" + month + "-" + day + " 00:00:00";
- }
- protected void Calendar2_SelectionChanged(object sender, EventArgs e)
- {
- Calendar2.Visible = false;
- string year = Calendar2.SelectedDate.Year.ToString();
- string month = Calendar2.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = Calendar2.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- TxtEndTime.Text = year + "-" + month + "-" + day + " 00:00:00";
- }
- protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar2.Visible == true)
- {
- Calendar2.Visible = false;
- }
- else
- {
- Calendar2.Visible = true;
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- this.Save(1);
- }
- protected void BtnSave_Click(object sender, EventArgs e)
- {
- this.Save(2);
- }
- protected void Save(int state)
- {
- if (this.CheckValidate()&&this.checktime())
- {
- 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_CH_OFF_FORM", conn);
- cmd.Transaction = tx;
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- string total_result = "跑流程中";
- if (state == 2)
- {
- total_result = "未送件";
- }
- //添加表單
- cmd = new SqlCommand("insert into OA_CH_OFF_FORM(id, form_id, emp_id, department_id, delegate_id, " +
- "off_type, begin_time, end_time, hours, apply_date, parenthesis, reason, step, total_result, " +
- "finish_date, state)values(" + id + ",'" + TxtFormId.Text + "','" + EmpId.Value + "','" + DepartmentId.Value +
- "','" + DelegateId.Value + "','" + DdlOffType.SelectedValue + "','" + TxtBeginTime.Text + "','" +
- TxtEndTime.Text + "','" + TxtHours.Text + "','" + TxtApplyDate.Text + "','" + TxtParenthesis.Text +
- "','" + TxtReason.Text.Replace("n", "<br>") + "',0,'" + total_result + "',''," + state + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- //添加流程
- int flow_id = 1;
- cmd = new SqlCommand("select max(id) from OA_CH_APPROVEL_FORM_FLOW", conn);
- cmd.Transaction = tx;
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- //跑代理人
- cmd = new SqlCommand("select email_work from oa_employee where id=" + DelegateId.Value, conn);
- cmd.Transaction = tx;
- string email_work = cmd.ExecuteScalar().ToString();
- sql = "insert into OA_CH_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
- "apply_type, is_check, is_agree, comment, check_date, step, is_business) values (" +
- flow_id + ", " + id + "," + DelegateId.Value + ",2,'N','N','','',1,'N')";
- cmd = new SqlCommand(sql, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- if (state == 1)
- {
- mail.mail_d(email_work, TxtDelegate.Text.Substring(7), TxtEmpName.Text);
- }
- flow_id++;
- ArrayList operator_id = 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();//记录代理人姓名
- int ceng = 0;
- cmd = new SqlCommand("select ceng from oa_department where id=" + DepartmentId.Value, conn);
- cmd.Transaction = tx;
- try
- {
- ceng = Convert.ToInt32(cmd.ExecuteScalar());
- }
- catch { }
- //找到上层节点部门的ID
- last_id.Add(DepartmentId.Value.ToString());
- for (int j = 1; j < ceng; j++)
- {
- cmd = new SqlCommand("select distinct last_id from oa_department where id=" + last_id[j - 1], conn);
- cmd.Transaction = tx;
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- last_id.Add(dr2["last_id"].ToString());
- }
- dr2.Close();
- }
- //找到上层节点人的ID
- for (int i = 1; i < last_id.Count; i++)
- {
- cmd = new SqlCommand("select a.id as id,a.email_work,a.emp_name from oa_employee as a left join oa_department as b on a.department_id=b.id" +
- " where position<" + PositionId.Value + "and b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
- cmd.Transaction = tx;
- SqlDataReader dr1 = cmd.ExecuteReader();
- while (dr1.Read())
- {
- operator_id.Add(dr1["id"].ToString());
- name1.Add(dr1["emp_name"].ToString());
- mail1.Add(dr1["email_work"].ToString());
- }
- dr1.Close();
- }
- for (int p = 0; p < operator_id.Count; p++)
- {
- if (Convert.ToInt32(operator_id[p]) == 128)
- { operator_id.RemoveAt(p); }
- }
- // 确定是否有代理人签核
- for (int k = 0; k < operator_id.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='" + operator_id[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());
- operator_id.RemoveAt(k);
- operator_id.Add(dr3["d_people"].ToString());
- }
- dr3.Close();
- }
- for (int i = 0; i < operator_id.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_CH_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
- "apply_type, is_check, is_agree, comment, check_date, step, is_business)values(" +
- flow_id + ", " + id + "," + operator_id[i] + ",2,'N','N','',''," + (i + 2) + ",'N')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- flow_id++;
- }
- for (int d = 0; d < operator_id.Count; d++)
- {
- cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
- + DelegateId.Value + "','" + Session["user_id"] + "','" + TxtApplyDate.Text + "','" + TxtEndTime.Text + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- flow_id++;
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- // tx.Rollback();
- }
- conn.Close();
- }
- }
- //遞歸取出辦理人-- position:6-經理; 2-副董
- protected void getEmployee(int department_id, int position)
- {
- int operator_id = 0;
- int flag = 0;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string sql = "select id from OA_EMPLOYEE where department_id=" + department_id + " and position=" + position;
- if (position == 2)
- {
- sql = "select id from OA_EMPLOYEE where position=" + position;
- }
- SqlCommand cmd = new SqlCommand(sql, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- operator_id = Convert.ToInt32(dr["id"].ToString());
- OperatorId.Value = operator_id.ToString();
- }
- else
- {
- flag = 1;
- }
- dr.Close();
- count = count + 1;
- if (count == 6)
- {
- flag = 0;
- OperatorId.Value = "0";
- }
- if (flag == 1)
- {
- cmd = new SqlCommand("select last_id from OA_DEPARTMENT where id=" + department_id, conn);
- this.getEmployee(Convert.ToInt32(cmd.ExecuteScalar()), position);
- }
- conn.Close();
- }
- protected bool CheckValidate()
- {
- LblError.Text = "";
- int flag = 0;
- try
- {
- int hours = Convert.ToInt32(TxtHours.Text);
- }
- catch
- {
- flag = 1;
- LblError.Text = "休假時數格式有误";
- Response.Write("<script>alert('休假時數格式有误')</script>");
- TxtHours.Focus();
- }
- if (DelegateId.Value.Equals("") || DelegateId.Value.Equals("0"))
- {
- flag = 1;
- LblError.Text = "請選擇代理人";
- Response.Write("<script>alert('請選擇代理人')</script>");
- TxtDelegate.Focus();
- }
- if (flag == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- protected bool checktime()
- {
- LblError.Text = "";
- int flag = 0;
- if (TxtBeginTime.Text == "" || TxtEndTime.Text == "")
- { flag = 1; }
- if (flag == 1)
- {
- LblError.Text = "开始时间和结束时间不能为空";
- Response.Write("<script>alert('开始时间和结束时间不能为空')</script>");
- TxtBeginTime.Focus();
- return false;
- }
- else {
- return true;
- }
- }
- //遞歸取自由流程
- protected void GetFlow(int main_id, int number, SqlConnection conn, SqlTransaction tx)
- {
- string sql = "select top 1 apply_type, operator_id, number, next_number, " +
- "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " order by number";
- if (number != 0)
- {
- sql = "select top 1 apply_type, operator_id, number, next_number, " +
- "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " and number=" + number;
- }
- SqlCommand cmd = new SqlCommand(sql, conn);
- cmd.Transaction = tx;
- int next = 0;
- int flag = 0;
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- apply_type.Add(dr["apply_type"].ToString());
- operator_id.Add(dr["operator_id"].ToString());
- if (!dr["larger_than"].ToString().Equals("0"))
- {
- //if (Convert.ToInt32(dr["larger_than"].ToString()) < Convert.ToInt32(TxtDays.Text))
- //{
- // if (!dr["larger_next"].Equals(""))
- // {
- // flag = 1;
- // next = Convert.ToInt32(dr["larger_next"].ToString());
- // }
- //}
- //else
- //{
- // if (!dr["next_number"].Equals(""))
- // {
- // flag = 1;
- // next = Convert.ToInt32(dr["next_number"].ToString());
- // }
- //}
- }
- else
- {
- if (!dr["next_number"].ToString().Equals(""))
- {
- flag = 1;
- next = Convert.ToInt32(dr["next_number"].ToString());
- }
- }
- }
- dr.Close();
- if (flag == 1)
- {
- this.GetFlow(main_id, next, conn, tx);
- }
- }
- }