add_report.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:7k
源码类别:
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_report_add_report : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnOK_Click(object sender, EventArgs e)
- {
- if (Employee_ids.Value.Equals(""))
- {
- LblReceivers.Text = "收件人不能為空";
- }
- else
- {
- DateMgr date = new DateMgr();
- string time = date.getTime();
- //上傳檔案
- if (!this.uploadFile(time))
- {
- if (FileUpload1.HasFile)
- {
- //上傳檔案不成功
- }
- else
- {
- //沒有上傳附件
- this.saveReport();
- }
- }
- else
- {
- this.saveReport();
- }
- }
- }
- protected bool uploadFile(string time)
- {
- bool flag = false;
- string server_ip = "";
- string root = "";
- string folder = "";
- if (Application["FILE_SERVER_IP"] != null)
- {
- server_ip = Application["FILE_SERVER_IP"].ToString();
- }
- if (Application["FILE_SERVER_ROOT"] != null)
- {
- root = Application["FILE_SERVER_ROOT"].ToString();
- }
- if (Application["REPORT_FOLDER"] != null)
- {
- folder = Application["REPORT_FOLDER"].ToString();
- }
- string directory = "d:\oa(new)\web\oa_upload\report\";
- if (FileUpload1.HasFile)
- {
- bool extenstion = false;
- string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- string[] allowedExtensions =
- { ".gif", ".jpg", ".doc", ".xls", ".rar", ".zip", ".txt", ".vsd", ".vss", ".vst", ".vdx", ".vsx", ".vtx" };
- for (int i = 0; i < allowedExtensions.Length; i++)
- {
- if (fileExtension == allowedExtensions[i])
- {
- extenstion = true;
- break;
- }
- }
- if (!extenstion)
- {
- LblFileError.Text = "只允許上傳格式為gif, jpg, doc, xls, rar, zip, txt, vsd, vss, vst, vdx, vsx, vtx的檔案";
- return false;
- }
- else
- {
- string name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- FileUpload1.PostedFile.SaveAs(directory + name);
- ContentLength.Value = FileUpload1.PostedFile.ContentLength.ToString();
- flag = true;
- }
- }
- return flag;
- }
- protected void saveReport()
- {
- //添加數据
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- int report_id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_REPORT_CONTENT", conn);
- try
- {
- report_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch { }
- int sender_id = 1;
- cmd = new SqlCommand("select max(id) from OA_REPORT_SENDER", conn);
- try
- {
- sender_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch { }
- int receiver_id = 1;
- cmd = new SqlCommand("select max(id) from OA_REPORT_RECEIVER", conn);
- try
- {
- receiver_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch { }
- int attachment_id = 1;
- cmd = new SqlCommand("select max(id) from OA_REPORT_ATTACHMENT", conn);
- try
- {
- attachment_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch { }
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- //添加報告內容
- cmd = new SqlCommand("insert into OA_REPORT_CONTENT(id, title, content, proposal, summarize) values (" +
- report_id + ", '" + TxtTitle.Text + "', '" + TxtContent.Text.Replace("n", "<br>").Replace(" ", " ") +
- "', '" + TxtProposal.Text.Replace("n", "<br>").Replace(" ", " ") + "', '" +
- TxtSummarize.Text.Replace("n", "<br>").Replace(" ", " ") + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- //添加發件人信息
- int user_id = 0;
- if (Session["user"] != null)
- {
- user_id = ((User)Session["user"]).Id;
- }
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- cmd = new SqlCommand("insert into OA_REPORT_SENDER(id, report_id, sender, " +
- "is_del, send_date)values(" + sender_id + ", " + report_id + ", " + user_id +
- ", 0, '" + time + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- //添加收件人
- if (!Employee_ids.Value.Equals(""))
- {
- string[] receiver_ids = Employee_ids.Value.Split(new char[] { ';' });
- for (int i = 0; i < receiver_ids.Length; i++)
- {
- cmd = new SqlCommand("insert into OA_REPORT_RECEIVER(id, report_id, " +
- "receiver, is_read, is_del, read_date, sign, sign_date) values (" + receiver_id + ", " +
- report_id + ", " + receiver_ids[i] + ", 0, 0, '', '', '')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- receiver_id++;
- }
- }
- //添加附件
- DateMgr date = new DateMgr();
- time = date.getTime();
- string name = "";
- try
- {
- name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- }
- catch { }
- cmd = new SqlCommand("insert into OA_REPORT_ATTACHMENT(id, report_id, name, content_length)" +
- " values (" + attachment_id + ", " + report_id + ", '" + name + "','" + ContentLength.Value + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- tx.Commit();
- Response.Redirect("report_list_send.aspx");
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- // tx.Rollback();
- }
- conn.Close();
- }
- }