fair_add.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:15k
源码类别:
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_fair_index : System.Web.UI.Page
- {
- private ArrayList attachments;
- private ArrayList attachment_save_names;
- private ArrayList content_lengths;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- if (Session["user"] != null)
- {
- User user = (User)Session["user"];
- EmpId.Value = user.Id.ToString();
- DepartmentId.Value = user.Department.Id.ToString();
- PositionId.Value = user.PositionSequence.ToString();
- TxtEmpName.Text = user.Emp_name;
- TxtEmpNo.Text = user.Emp_no;
- DateMgr mgr = new DateMgr();
- TxtFormNo.Text = mgr.getTime();
- TxtApplyDate.Text = mgr.getDateTime();
- }
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- if (this.CheckValidate())
- {
- if (this.UploadFiles(TxtFormNo.Text))
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- int fair_id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_FAIR", conn);
- cmd.Transaction = tx;
- try
- {
- fair_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- int form_id = 0;
- string form_table = "";
- if (!FormValue.Value.Equals(""))
- {
- try
- {
- string[] values = FormValue.Value.Split(new char[] { '-'});
- form_id = Convert.ToInt32(values[0]);
- form_table = values[2];
- }
- catch { }
- }
- //添加表單
- cmd = new SqlCommand("insert into OA_FAIR(id, emp_id, apply_date, subject, amount, " +
- "remark, form_no, step, total_result, finish_date, form_id, form_table)values(" +
- fair_id + "," + EmpId.Value + ",'" + TxtApplyDate.Text + "','" + TxtSubject.Text + "','" +
- TxtAmount.Text + "','" + TxtRemark.Text + "','" + TxtFormNo.Text +
- "',0,'跑流程中','','" + form_id + "','" + form_table + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- //添加圖檔
- int attachment_id = 1;
- if (attachments.Count > 0)
- {
- cmd = new SqlCommand("select max(id) from OA_FAIR_ATTACHMENT", conn);
- cmd.Transaction = tx;
- try
- {
- attachment_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- }
- for (int i = 0; i < attachments.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_FAIR_ATTACHMENT(id, fair_id, attachment, " +
- "attachment_save_name, content_length)values(" + attachment_id + "," +
- fair_id + ",'" + attachments[i] + "','" + attachment_save_names[i] + "','" +
- content_lengths[i] + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- attachment_id++;
- }
- //添加流程
- int flow_id = 1;
- cmd = new SqlCommand("select max(id) from OA_FAIR_FORM_FLOW", conn);
- cmd.Transaction = tx;
- try
- {
- flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- //添加逐级签核流程
- // if (main_id != 0)
- // {
- 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 mail2 = new ArrayList();//记录代理人的MAIL
- ArrayList mail2_name = new ArrayList();//记录代理人姓名
- ArrayList operator_ids = new ArrayList();
- ArrayList d_people = new ArrayList();
- ArrayList b_d_people=new ArrayList();
- if (Convert.ToInt32(PositionId.Value) >8)
- {
- last_id.Add(DepartmentId.Value.ToString());
- int times = 3;
- if (Convert.ToInt32(PositionId.Value) == 9) { times = 2; }
- else if (Convert.ToInt32(PositionId.Value) == 10) { times = 2; }
- else if (Convert.ToInt32(PositionId.Value) == 11) { times = 3; }
- else { times = 3; }
- for (int j = 1; j < times; 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
- if (last_id.Count != 0)
- {
- 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_ids.Add(dr1["id"].ToString());
- name1.Add(dr1["emp_name"].ToString());
- mail1.Add(dr1["email_work"].ToString());
- } dr1.Close();
- }
- }
- cmd = new SqlCommand("select a.id as id from oa_employee as a left join oa_department as b on a.department_id=b.id" +
- " where b.id=90 and q_manger=1 order by position desc", conn);
- cmd.Transaction = tx;
- SqlDataReader dr3 = cmd.ExecuteReader();
- while (dr3.Read())
- {
- operator_ids.Add(dr3["id"].ToString());
- } dr3.Close();
- operator_ids.Add("128");
- // 确定是否有代理人签核
- for (int k = 0; k < operator_ids.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_ids[k] + "'", conn);
- cmd.Transaction = tx;
- SqlDataReader dr4 = cmd.ExecuteReader();
- while (dr4.Read())
- {
- d_people.Add(dr4["d_people"].ToString());
- b_d_people.Add(dr4["b_d_people"].ToString());
- operator_ids.RemoveAt(k);
- operator_ids.Add(dr4["d_people"].ToString());
- }
- dr4.Close();
- }
- }
- else {
- 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 b.id=90 and q_manger=1 order by position desc", conn);
- cmd.Transaction = tx;
- SqlDataReader dr1 = cmd.ExecuteReader();
- while (dr1.Read())
- {
- operator_ids.Add(dr1["id"].ToString());
- name1.Add(dr1["emp_name"].ToString());
- mail1.Add(dr1["email_work"].ToString());
- tmp_people.Add(dr1["id"].ToString());
- } dr1.Close();
- operator_ids.Add("128");
- // 确定是否有代理人签核
- for (int k = 0; k < operator_ids.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_ids[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_ids.RemoveAt(k);
- operator_ids.Add(dr3["d_people"].ToString());
- }
- dr3.Close();
- }
- }
- mail.mail_q(mail1[0], name1[0], TxtEmpName.Text);
- for (int i = 0; i < operator_ids.Count; i++)
- {
- cmd = new SqlCommand("insert into OA_FAIR_FORM_FLOW(id, form_id, operator_id, " +
- "apply_type, is_check, is_agree, comment, check_date, step)values(" +
- flow_id + ", " + fair_id + "," + operator_ids[i] + ",2,'N','N','',''," + (i + 1) + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- flow_id++;
- }
- tx.Commit();
- Response.Redirect("my_list.aspx");
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- try
- {
- tx.Rollback();
- }
- catch { }
- }
- conn.Close();
- }
- }
- }
- protected bool CheckValidate()
- {
- try
- {
- double amount = Convert.ToDouble(TxtAmount.Text.Trim());
- }
- catch
- {
- LblError.Text = "申請金額格式有誤";
- Response.Write("<script>alert('申請金額格式有誤')</script>");
- return false;
- }
- return true;
- }
- protected bool UploadFiles(string time)
- {
- attachments = new ArrayList();
- attachment_save_names = new ArrayList();
- content_lengths = new ArrayList();
- bool flag = Upload(FileUpload1, time) && Upload(FileUpload2, time) && Upload(FileUpload3, time)
- && Upload(FileUpload4, time) && Upload(FileUpload5, time);
- return flag;
- }
- protected bool Upload(FileUpload fileUpload, string time)
- {
- bool flag = true;
- try
- {
- string directory = Server.MapPath("~/web/fair_picture/");
- string file_extension = System.IO.Path.GetExtension(fileUpload.FileName).ToLower();
- string[] allowed_extensions = { ".jpg", ".gif" };
- bool extenstion = false ;
- if (fileUpload.HasFile)
- {
- for (int i = 0; i < allowed_extensions.Length; i++)
- {
- if (file_extension == allowed_extensions[i])
- {
- extenstion = true;
- break;
- }
- }
- if (!extenstion)
- {
- LblError.Text = "只允許上傳格式為gif, jpg的圖檔!";
- Response.Write("<script>alert('只允許上傳格式為gif, jpg的圖檔')</script>");
- return false;
- }
- else
- {
- string name = fileUpload.FileName.Substring(0, fileUpload.FileName.Length - 4) +
- time + System.IO.Path.GetExtension(fileUpload.FileName).ToLower();
- fileUpload.PostedFile.SaveAs(directory + name);
- attachments.Add(fileUpload.FileName);
- attachment_save_names.Add(name);
- content_lengths.Add(fileUpload.PostedFile.ContentLength.ToString());
- flag = true;
- }
- }
- }
- catch
- {
- LblError.Text = "上傳檔案失敗!";
- Response.Write("<script>alert('上傳檔案失敗')</script>");
- return false;
- }
- return flag;
- }
- }