announce_add.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_announcement_announce_add : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- if (this.CheckValidate())
- {
- DateMgr mgr = new DateMgr();
- string time = mgr.getTime();
- string user = "";
- if (Session["user"] != null)
- {
- user = ((User)Session["user"]).Emp_name;
- }
- if (this.uploadFile(time))
- {
- string file_name = "";
- string save_name = "";
- if (FileUpload1.HasFile)
- {
- file_name = FileUpload1.FileName;
- save_name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- }
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- int id = 1;
- SqlCommand cmd = new SqlCommand("select max(id) from OA_ANNOUNCEMENT", conn);
- try
- {
- id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
- }
- catch { }
- cmd = new SqlCommand("insert into OA_ANNOUNCEMENT(id, type_id, subject, content, authority, "+
- "validate_date, attachment, attachment_save_name, attachment_length, is_del, cre_user, cre_date)"+
- "values("+id+",'"+ DdlType.SelectedValue+"','"+TxtSubject.Text+"','"+
- TxtContent.Text.Replace("n","<br>").Replace(" "," ")+"','"+
- RbAuthority.SelectedValue+"','"+TxtValidateDate.Text+"','"+file_name+"','"+save_name+"','"+
- ContentLength.Value+"','N','"+ user+"','"+mgr.getDateTime()+"')", conn);
- cmd.ExecuteNonQuery();
- if (RbAuthority.SelectedValue.Equals("2"))
- {
- if (!DepartmentIds.Value.Equals(""))
- {
- string [] departments = DepartmentIds.Value.Split(new char[]{','});
- for (int i = 0; i < departments.Length; i++)
- {
- cmd = new SqlCommand("insert into OA_ANNOUNCEMENT_DEPARTMENT(a_id, department_id)"+
- " values ("+id+", "+departments[i]+")", conn);
- cmd.ExecuteNonQuery();
- }
- }
- }
- conn.Close();
- Response.Write("<script> alert('发布成功')</script>");
- TxtSubject.Text = "";
- TxtContent.Text = "";
- DepartmentIds.Value = "";
- }
- }
- }
- protected bool CheckValidate()
- {
- if (TxtSubject.Text.Trim().Equals(""))
- {
- Response.Write("<script language='javascript'>alert('主旨不能為空!');</script>");
- return false;
- }
- if (TxtContent.Text.Trim().Equals(""))
- {
- Response.Write("<script language='javascript'>alert('內容不能為空!');</script>");
- return false;
- }
- if (RbAuthority.SelectedValue.Equals("2"))
- {
- if (DepartmentIds.Value.Equals(""))
- {
- Response.Write("<script language='javascript'>alert('請選擇部門!');</script>");
- return false;
- }
- }
- return true;
- }
- protected void RbAuthority_Change(object sender, EventArgs e)
- {
- if (RbAuthority.SelectedValue.Equals("2"))
- {
- BtnSelect.Visible = true;
- LblDepartments.Visible = true;
- }
- else
- {
- BtnSelect.Visible = false;
- LblDepartments.Visible = false;
- }
- }
- protected bool uploadFile(string time)
- {
- bool flag = false;
- string directory = "d:\oa(new)\web\oa_upload\announce\";
- 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", ".html", ".htm" };
- for (int i = 0; i < allowedExtensions.Length; i++)
- {
- if (fileExtension == allowedExtensions[i])
- {
- extenstion = true;
- break;
- }
- }
- if (!extenstion)
- {
- Response.Write("<script language='javascript'>alert('只允許上傳格式為gif, jpg, doc, xls, rar, zip, txt, vsd, vss, vst, vdx, vsx, vtx, html, htm的檔案!');</script>");
- 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;
- }
- }
- else
- {
- flag = true;
- }
- return flag;
- }
- protected void Calendar1_SelectionChanged(object sender, EventArgs e)
- {
- string year = Calendar1.SelectedDate.Year.ToString();
- string month = Calendar1.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = Calendar1.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- TxtValidateDate.Text = year + "-" + month + "-"+ day;
- Calendar1.Visible = false;
- }
- protected void ImageButton1_Click(object sender, EventArgs e)
- {
- if (Calendar1.Visible == true)
- {
- Calendar1.Visible = false;
- }
- else
- {
- Calendar1.Visible = true;
- }
- }
- }