form.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:9k
源码类别:
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;
- public partial class web_computer_form : System.Web.UI.Page
- {
- 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"];
- date1.Text = mgr.getDateTime();
- form_id.Text = mgr.getTime();
- emp_name.Text = user.Emp_name;
- // EmpId.Value = user.Id.ToString();
- emp_no.Text = user.Emp_no;
- emp_dept.Text = user.Department.Full_name;
- // DepartmentId.Value = user.Department.Id.ToString();
- emp_position.Text = user.Position;
- // PositionSequence.Value = user.PositionSequence.ToString();
- // PositionId.Value = user.PositionId.ToString();
- Session["department_id"] = user.Department.Id.ToString();
- }
- }
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (CalEnddate.Visible == true)
- {
- CalEnddate.Visible = false;
- CalEnddate.Focus();
- }
- else
- {
- CalEnddate.Visible = true;
- CalEnddate.Focus();
- }
- }
- protected void CalEnddate_SelectionChanged(object sender, EventArgs e)
- {
- CalEnddate.Visible = false;
- string year = CalEnddate.SelectedDate.Year.ToString();
- string month = CalEnddate.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = CalEnddate.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- Enddate.Text = year + "-" + month + "-" + day + " 00:00:00";
- Enddate.Focus();
- }
- protected void btn_ok_Click(object sender, EventArgs e)
- {
- if (CheckValidate())
- {
- this.save(1);
- }
- }
- protected bool CheckValidate()
- {
- int flag = 0;
- if (DepartmentId.Value.Equals("") || DepartmentId.Value.Equals("0"))
- {
- flag = 1;
- Response.Write("<script>alert('請選擇送至部門')</script>");
- TxtDepartment.Focus();
- }
- if (f_item.Text.Equals("") || f_item.Text.Equals("0"))
- {
- flag = 1;
- Response.Write("<script>alert('請填寫聯繫電話')</script>");
- f_item.Focus();
- }
- if (content.Text.Equals("") || content.Text.Equals("0"))
- {
- flag = 1;
- Response.Write("<script>alert('請填寫說明')</script>");
- content.Focus();
- }
- if (flag == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- protected void save(int state)
- {
- 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_computer_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_computer_form(id,form_id,emp_no,emp_name,date1,emp_dept,"+
- "emp_position,item1,enddate,to_dpt_id,content,status,emp_id)values('"+id+
- "','"+form_id.Text+"','"+emp_no.Text+"','"+emp_name.Text+
- "','"+date1.Text+"','"+emp_dept.Text+"','"+emp_position.Text+"','"+f_item.Text+
- "','" + Enddate.Text + "','" + DepartmentId.Value+ "','" + content.Text +
- "','" + total_result + "','" + Session["user_id"] + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- //签核状况
- try
- {
- ArrayList operator_id = new ArrayList();
- ArrayList department_id = new ArrayList();
- ArrayList email_work = new ArrayList();
- ArrayList operator_name = new ArrayList();
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_computer_form_flow", conn);
- cmd.Transaction = tx;
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- int id1 = 1;
- try
- {
- 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);
- cmd.Transaction = tx;
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- operator_id.Add(dr["id"].ToString());
- email_work.Add(dr["email_work"].ToString());
- operator_name.Add(dr["emp_name"].ToString());
- }
- dr.Close();
- // 确定是否有代理人签核
- ArrayList d_people = new ArrayList();
- ArrayList b_d_people = new ArrayList();
- 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();
- }
- //
- int j = 1;
- for (int i = 0; i < operator_id.Count; i++)
- {
- cmd = new SqlCommand("insert into oa_computer_form_flow(id,form_id,f_id,apply_type,operator_id,is_check,is_agree,check_date," +
- "comment,step)values('" + id + "','" + form_id.Text + "','" + id + "','2','" + operator_id[i] + "','N','N','','','" + j + "')", conn);
- j++;
- id++;
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- mail.mail_q(email_work[i], operator_name[i], emp_name.Text, "問題回饋單");
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- }
- else
- {
- Response.Write("沒有部門主管");
- }
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- conn.Close();
- }
- protected void btn_cancel_Click(object sender, EventArgs e)
- {
- Response.Redirect("../computer/form.aspx");
- }
- }