gw_senddocument.aspx.cs
上传用户:lishan0805
上传日期:2019-12-08
资源大小:12048k
文件大小:5k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using COM.OA.BLL;
  13. using System.Collections.Generic;
  14. using COM.OA.Entity;
  15. public partial class gw_senddocument : System.Web.UI.Page
  16. {
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.     }
  20.     //连动
  21.     protected void ddldepartment_SelectedIndexChanged(object sender, EventArgs e)
  22.     {
  23.         //取部门的值
  24.         string ddldepartment = this.ddldepartment.Text;
  25.         SqlParameter parambumen = new SqlParameter("@deptid", ddldepartment);
  26.         IList<liandongren> lists = BLLGeneric.Select<liandongren>(CommandType.StoredProcedure, "liandong", parambumen);
  27.         this.ddlname.DataSource = lists;
  28.         this.ddlname.DataTextField = "Em_name";
  29.         this.ddlname.DataValueField = "Em_name";
  30.         this.ddlname.DataBind();
  31.     }
  32.     protected void btnUpload_Click(object sender, EventArgs e)
  33.     {
  34.         //接收人
  35.         string takeuser = this.tboxperson.Text;
  36.         //判断接收人是否为空
  37.         if (takeuser == null || takeuser == "")
  38.         {
  39.             this.Response.Write(string.Format(GetRedirect.WINALERT,"接收人不能为空"));
  40.             return;
  41.         }
  42.         //部门
  43.         string dept = this.tboxdept.Text;
  44.         //判断接收部门是否为空
  45.         if (dept == null || dept == "")
  46.         {
  47.             this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择接收部门!!"));
  48.             return;
  49.         }
  50.         //标题
  51.         string title = this.txttitle.Text;
  52.         //判断标题是否为空
  53.         if (title == null || title == "")
  54.         {
  55.             this.Response.Write(string.Format(GetRedirect.WINALERT, "请输入标题!!"));
  56.             return;
  57.         }
  58.         //判断上传文件时候为空
  59.         if (string.IsNullOrEmpty(this.fileUpload1.PostedFile.FileName)) 
  60.         {
  61.             this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择你要发送的公文!"));
  62.             return;
  63.         }
  64.         //接收人id
  65.         int takeuserid = 0;
  66.         string sql = "em_name='{0}'";
  67.         sql = string.Format(sql, takeuser);
  68.         IList<employee> elist = employeeBLL.Select(sql);
  69.         if (elist.Count == 1)
  70.         {
  71.             foreach (employee em in elist)
  72.             {
  73.                 takeuserid = em.em_id;
  74.             }
  75.             string uid = "u_em_id={0}";
  76.             uid = string.Format(uid,takeuserid);
  77.             IList<users> u = usersBLL.Select(uid);
  78.             if (u.Count == 1)
  79.             {
  80.                 foreach(users user in u)
  81.                 {
  82.                     takeuserid = user.u_id;
  83.                 }
  84.             }
  85.         }
  86.         //部门id
  87.         int deptid = 0;
  88.         string sql2 = "dept_department='{0}'";
  89.         sql2 = string.Format(sql2, dept);
  90.         IList<department> deptlist = departmentBLL.Select(sql2);
  91.         if (deptlist.Count == 1)
  92.         {
  93.             foreach (department d in deptlist)
  94.             {
  95.                 deptid = d.dept_id;
  96.             }
  97.         }
  98.       
  99.         //附件
  100.         string gwpath = this.Server.MapPath("gwupload") + @"" + this.fileUpload1.FileName;
  101.         //将文件保存在指定的路径
  102.         this.fileUpload1.SaveAs(gwpath);
  103.         //附件路径
  104.         string annexpath = "gwupload/" + this.fileUpload1.FileName;
  105.         //发送人
  106.         string username = this.Request.Form["txtusername"];
  107.         //发送人id
  108.         int userid = 0;
  109.         string sql3 = "u_username='{0}'";
  110.         sql3 = string.Format(sql3, username);
  111.         IList<users> userlist = usersBLL.Select(sql3);
  112.         if (userlist.Count == 1)
  113.         {
  114.             foreach (users u in userlist)
  115.             {
  116.                 userid = u.u_id;
  117.             }
  118.         }
  119.         //发送时间
  120.         DateTime sendtime = DateTime.Parse(this.Request.Form["txtsendtime"]);
  121.         //下载次数
  122.         int download = 0;
  123.         //阅读次数
  124.         int reads = 0;
  125.         //点击次数
  126.         int clicks = 0;
  127.         //群组id
  128.         int gid = 1;
  129.         //将数据存进实体
  130.         document docu = new document();
  131.         docu.doc_dept_id = deptid;//部门
  132.         docu.doc_u_id=takeuserid;//接收人id
  133.         docu.doc_title=title;//标题
  134.         docu.doc_annex = annexpath;//附件
  135.         docu.doc_downloads=download;//下载次数
  136.         docu.doc_reads=reads;//阅读次数
  137.         docu.doc_clicks=clicks;//点击次数
  138.         docu.doc_releasetime=sendtime;//发送时间
  139.         docu.doc_sendu_id=userid;//发送人id
  140.         docu.doc_g_id = gid;//群组id
  141.         //执行插入,判断返回值
  142.         int flag = documentBLL.Insert(docu);
  143.         if (flag == 0)
  144.         {
  145.             this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('公文发送失败!!');</script>");
  146.         }
  147.         this.Response.Redirect("gw_success.aspx");
  148.     }
  149.   
  150. }