form.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:31k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Data.SqlClient;
- 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;
- public partial class web_equipment_form : System.Web.UI.Page
- {
- string departmentid = "";
- string PositionId = "";
- string userid = "";
- int flow_id = 1;
- 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"];
- IFromNo.Text = mgr.getTime();
- txemp_name.Text = user.Emp_name;
- tbdate.Text = mgr.getDate();
- tbdepartment.Text = user.Department.Full_name;
- PositionId = user.PositionId.ToString();
- departmentid = user.Department.Id.ToString();
- userid = user.Id.ToString();
- }
- }
- public void check()
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string sql = "";
- if (!name1.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_1.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_1.Text.ToString();
- charge = charge1_1.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_1.Text.ToString();
- charge = charge + "/" + charge1_1.Text.ToString();
- }
- }
- if (cb_2_1.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_1.Text.ToString();
- charge = charge2_1.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_1.Text.ToString();
- charge = charge + "/" + charge2_1.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +id+"','"+
- IFromNo.Text.ToString() + "','" + name1.Text.ToString() + "','" + standard1.Text + "','" + unit1.Text.ToString() + "','" + num1.Text.ToString() + "','" +
- cause1.Text.ToString() + "','" + date1.Text.ToString() + "','" + type + "','" + charge + "','" + remark1.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name2.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_2.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_2.Text.ToString();
- charge = charge1_2.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_2.Text.ToString();
- charge = charge + "/" + charge1_2.Text.ToString();
- }
- }
- if (cb_2_1.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_2.Text.ToString();
- charge = charge2_2.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_2.Text.ToString();
- charge = charge + "/" + charge2_2.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name2.Text.ToString() + "','" + standard2.Text + "','" + unit2.Text.ToString() + "','" + num2.Text.ToString() + "','" +
- cause2.Text.ToString() + "','" + date2.Text.ToString() + "','" + type + "','" + charge + "','" + remark2.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name3.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_3.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_3.Text.ToString();
- charge = charge1_3.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_3.Text.ToString();
- charge = charge + "/" + charge1_3.Text.ToString();
- }
- }
- if (cb_2_3.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_3.Text.ToString();
- charge = charge2_3.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_3.Text.ToString();
- charge = charge + "/" + charge2_3.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name3.Text.ToString() + "','" + standard3.Text + "','" + unit3.Text.ToString() + "','" + num3.Text.ToString() + "','" +
- cause3.Text.ToString() + "','" + date3.Text.ToString() + "','" + type + "','" + charge + "','" + remark3.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name4.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_4.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_4.Text.ToString();
- charge = charge1_4.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_4.Text.ToString();
- charge = charge + "/" + charge1_4.Text.ToString();
- }
- }
- if (cb_2_4.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_4.Text.ToString();
- charge = charge2_4.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_4.Text.ToString();
- charge = charge + "/" + charge2_4.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name4.Text.ToString() + "','" + standard4.Text + "','" + unit4.Text.ToString() + "','" + num4.Text.ToString() + "','" +
- cause4.Text.ToString() + "','" + date4.Text.ToString() + "','" + type + "','" + charge + "','" + remark4.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name5.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_5.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_5.Text.ToString();
- charge = charge1_5.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_5.Text.ToString();
- charge = charge + "/" + charge1_5.Text.ToString();
- }
- }
- if (cb_2_5.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_5.Text.ToString();
- charge = charge2_5.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_5.Text.ToString();
- charge = charge + "/" + charge2_5.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name5.Text.ToString() + "','" + standard5.Text + "','" + unit5.Text.ToString() + "','" + num5.Text.ToString() + "','" +
- cause5.Text.ToString() + "','" + date5.Text.ToString() + "','" + type + "','" + charge + "','" + remark5.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name6.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_6.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_6.Text.ToString();
- charge = charge1_6.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_6.Text.ToString();
- charge = charge + "/" + charge1_6.Text.ToString();
- }
- }
- if (cb_2_6.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_6.Text.ToString();
- charge = charge2_6.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_6.Text.ToString();
- charge = charge + "/" + charge2_6.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name6.Text.ToString() + "','" + standard6.Text + "','" + unit6.Text.ToString() + "','" + num6.Text.ToString() + "','" +
- cause6.Text.ToString() + "','" + date6.Text.ToString() + "','" + type + "','" + charge + "','" + remark6.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name7.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_7.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_7.Text.ToString();
- charge = charge1_7.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_7.Text.ToString();
- charge = charge + "/" + charge1_7.Text.ToString();
- }
- }
- if (cb_2_7.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_7.Text.ToString();
- charge = charge2_7.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_7.Text.ToString();
- charge = charge + "/" + charge2_7.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name7.Text.ToString() + "','" + standard7.Text + "','" + unit7.Text.ToString() + "','" + num7.Text.ToString() + "','" +
- cause7.Text.ToString() + "','" + date7.Text.ToString() + "','" + type + "','" + charge + "','" + remark7.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name8.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_8.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_8.Text.ToString();
- charge = charge1_8.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_8.Text.ToString();
- charge = charge + "/" + charge1_8.Text.ToString();
- }
- }
- if (cb_2_8.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_8.Text.ToString();
- charge = charge2_8.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_8.Text.ToString();
- charge = charge + "/" + charge2_8.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name8.Text.ToString() + "','" + standard8.Text + "','" + unit1.Text.ToString() + "','" + num8.Text.ToString() + "','" +
- cause8.Text.ToString() + "','" + date8.Text.ToString() + "','" + type + "','" + charge + "','" + remark8.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (!name9.Text.Equals(""))
- {
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) as id from oa_equipment_form_d", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string type = "";
- string charge = "";
- if (cb_1_9.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_1_9.Text.ToString();
- charge = charge1_9.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_1_9.Text.ToString();
- charge = charge + "/" + charge1_9.Text.ToString();
- }
- }
- if (cb_2_9.Checked)
- {
- if (type.Equals(""))
- {
- type = cb_2_9.Text.ToString();
- charge = charge2_9.Text.ToString();
- }
- else
- {
- type = type + "/" + cb_2_9.Text.ToString();
- charge = charge + "/" + charge2_9.Text.ToString();
- }
- }
- sql = "insert into oa_equipment_form_d(id,form_id,equipment_name,standard,equipment_unit,equipment_num,cause,apply_date,type,charge,remark)values('" +
- id + "','" + IFromNo.Text.ToString() + "','" + name9.Text.ToString() + "','" + standard9.Text + "','" + unit9.Text.ToString() + "','" + num9.Text.ToString() + "','" +
- cause9.Text.ToString() + "','" + date9.Text.ToString() + "','" + type + "','" + charge + "','" + remark9.Text.ToString() + "')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- conn.Close();
- }
- public void save(int state)
- {
- if (cb1.Checked || cb2.Checked || cb3.Checked || cb4.Checked || cb5.Checked || cb6.Checked)
- {
- if (!name1.Text.Equals("") || !name2.Text.Equals("") || !name3.Text.Equals("") || !name4.Text.Equals("") || !name5.Text.Equals("") || !name6.Text.Equals("") || !name7.Text.Equals("") || !name8.Text.Equals("") || !name9.Text.Equals(""))
- {
- string type = "";
- if (cb1.Checked)
- {
- if (type.Equals(""))
- {
- type = cb1.Text.ToString();
- }
- else
- {
- type = type + "/" + cb1.Text.ToString();
- }
- }
- if (cb2.Checked)
- {
- if (type.Equals(""))
- {
- type = cb2.Text.ToString();
- }
- else
- {
- type = type + "/" + cb2.Text.ToString();
- }
- }
- if (cb3.Checked)
- {
- if (type.Equals(""))
- {
- type = cb3.Text.ToString();
- }
- else
- {
- type = type + "/" + cb3.Text.ToString();
- }
- }
- if (cb4.Checked)
- {
- if (type.Equals(""))
- {
- type = cb4.Text.ToString();
- }
- else
- {
- type = type + "/" + cb4.Text.ToString();
- }
- }
- if (cb5.Checked)
- {
- if (type.Equals(""))
- {
- type = cb5.Text.ToString();
- }
- else
- {
- type = type + "/" + cb5.Text.ToString();
- }
- }
- if (cb6.Checked)
- {
- if (type.Equals(""))
- {
- type = cb6.Text.ToString();
- }
- else
- {
- type = type + "/" + cb6.Text.ToString();
- }
- }
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- string sql = "";
- try
- {
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from oa_equipment_form", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch
- {
- }
- string total_result = "跑流程中";
- if (state == 2)
- {
- total_result = "未送件";
- }
- sql = "insert into oa_equipment_form(id,form_id,type,emp_id,apply_date,department_id,step,status,finish_date,total_result)values('" +
- +id + "','" + IFromNo.Text.ToString() + "','" + type + "','" + Session["user_id"] + "','" + tbdate.Text.ToString() +
- "','" + departmentid + "','1','" + state + "','','"+total_result+"')";
- cmd = new SqlCommand(sql, conn);
- cmd.ExecuteNonQuery();
- check();
- cmd = new SqlCommand("select max(id) from oa_equipment_flow", conn);
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch (Exception ex)
- {
- }
- if (state == 1)
- {
- ArrayList id1 = new ArrayList();
- ArrayList id2 = new ArrayList();//记录上层节点职级小于登陆者的ID
- ArrayList name_1 = new ArrayList();//记录上层节点职级小于登陆者的name
- ArrayList mail_1 = new ArrayList();//记录上层节点职级小于登陆者的mail
- ArrayList last_id = new ArrayList();//记录上层节点的ID
- //判断是否为副董办公室
- if (departmentid.Equals("50"))
- {
- Response.Redirect("my_list.aspx", true);
- }
- int ceng = 0;
- cmd = new SqlCommand("select ceng from dbo.OA_DEPARTMENT where id='" + departmentid + "'", conn);
- ceng = Convert.ToInt32(cmd.ExecuteScalar()) - 3;
- if (ceng < 0 || ceng == 0)
- {
- ceng = 0;
- }
- last_id.Add(departmentid);
- for (int i = 1; i <=ceng; i++)
- {
- cmd = new SqlCommand("select distinct last_id from oa_department where id='" + last_id[i - 1] + "'", conn);
- SqlDataReader dr1 = cmd.ExecuteReader();
- while (dr1.Read())
- {
- last_id.Add(dr1["last_id"].ToString());
- }
- dr1.Close();
- }
- for (int i = 0; i < last_id.Count; i++)
- {
- cmd = new SqlCommand("select id,email_work,emp_name from oa_employee where department_id='" + last_id[i] + "'and q_manger='1'", conn);
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- id1.Add(dr2["id"].ToString());
- //name_1.Add(dr2["emp_name"].ToString());
- //mail_1.Add(dr2["email_work"].ToString());
- }
- dr2.Close();
- }
- id1.Add("6");
- for (int i = 0; i < id1.Count; i++)
- {
- if (id1[i].Equals(Session["user_id"]))
- {
- id1.RemoveAt(i);
- //name_1.RemoveAt(i);
- //mail_1.RemoveAt(i);
- }
- }
- foreach(string i in id1)
- {
- string str = check_supply(i);
- id2.Add(str);
- cmd = new SqlCommand("select email_work,emp_name from oa_employee where id='" + str + "'", conn);
- SqlDataReader dr3 = cmd.ExecuteReader();
- if (dr3.HasRows)
- {
- while (dr3.Read())
- {
- name_1.Add(dr3["emp_name"].ToString());
- mail_1.Add(dr3["email_work"].ToString());
- }
- }
- dr3.Close();
- }
- if (id2.Count != 0)
- {
- for (int j = 0; j < id2.Count; j++)
- {
- cmd = new SqlCommand("insert into oa_equipment_flow(id,form_id,operator_id,is_check,is_agree,comment,check_date,step)values('" + flow_id + "','" + IFromNo.Text.ToString() + "','" + id2[j].ToString() + "','N','N','','','" + (j + 1) + "')", conn);
- cmd.ExecuteNonQuery();
- flow_id = flow_id + 1;
- }
- if (state == 1)
- {
- mail.mail_q(mail_1[0], name_1[0], txemp_name.Text, "設備申請單");
- }
- Response.Redirect("my_list.aspx");
- }
- else
- {
- ShowMessageBox("沒有找到相關處理流程, 請與管理員聯繫");
- }
- }
- else
- {
- Response.Redirect("my_list.aspx");
- }
- ShowMessageBox("申请成功");
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- ShowMessageBox("申请失败");
- }
- conn.Close();
- }
- else
- {
- ShowMessageBox("請填寫申請品名稱");
- }
- }
- else
- {
- ShowMessageBox("請選擇設備類型");
- }
- }
- public string check_supply(string id)
- {
- string emp_id = id;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DateTime date = DateTime.Now;
- try
- {
- SqlCommand cmd = new SqlCommand("select d_people,s_date,e_date from OA_DELEGATE where b_d_people='" + id + "'", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- if ((!dr["s_date"].ToString().Equals("")) && (!dr["e_date"].ToString().Equals("")))
- {
- if ((date >= Convert.ToDateTime(dr["s_date"])) && (date <= Convert.ToDateTime(dr["e_date"])))
- {
- emp_id = Convert.ToString(dr["d_people"]);
- }
- else
- {
- }
- }
- }
- }
- }
- catch
- {
- }
- return emp_id;
- }
- protected void ShowMessageBox(string strMessage)
- {
- Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- save(1);
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- save(2);
- }
- }