announce_mgr_list.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:14k
源码类别:
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_mgr_list : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- AnnounceList.DataKeyNames = new string[] { "id" };
- if (Request.QueryString["type_id"] != null && Request.QueryString["type"] != null)
- {
- int type_id = Convert.ToInt32(Request.QueryString["type_id"]);
- int type = Convert.ToInt32(Request.QueryString["type"]);
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name from OA_ANNOUNCEMENT_TYPE where id="+type_id, conn);
- LblTitle.Text = cmd.ExecuteScalar().ToString();
- conn.Close();
- DateMgr mgr = new DateMgr();
- string today = mgr.getDate();
- string sql = "";
- if (type == 1)
- {
- LblTitle.Text = LblTitle.Text + "(正在發佈)";
- sql = "select id, subject, cre_user, cre_date from OA_ANNOUNCEMENT where type_id=" +
- type_id + " and is_del='N' and validate_date>='" + today + "' order by cre_date desc";
- }
- if (type == 2)
- {
- LblTitle.Text = LblTitle.Text + "(已過期)";
- sql = "select id, subject, cre_user, cre_date from OA_ANNOUNCEMENT where type_id=" +
- type_id + " and is_del='N' and validate_date<'" + today + "' order by cre_date desc";
- }
- if (type == 3)
- {
- LblTitle.Text = LblTitle.Text + "(已刪除)";
- sql = "select id, subject, cre_user, cre_date from OA_ANNOUNCEMENT where type_id=" +
- type_id + " and is_del='Y' order by cre_date desc";
- }
- SqlDataSource1.SelectCommand = sql;
- AnnounceList.DataBind();
- if (type == 3)
- {
- AnnounceList.Columns[AnnounceList.Columns.Count - 1].Visible = false;
- AnnounceList.Columns[AnnounceList.Columns.Count - 2].Visible = true;
- }
- }
- }
- }
- protected void AnnounceList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- LblTitle.Visible = true;
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
- e.Row.Cells[e.Row.Cells.Count - 2].Attributes.Add("onclick", "return confirm('確定還原嗎?')");
- }
- }
- protected void AnnounceList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("EditData"))
- {
- string id = e.CommandArgument.ToString();
- Session["id"] = id;
- this.SetValue(id);
- PnlAnnounce.Visible = true;
- }
- if (e.CommandName.Equals("Restore"))
- {
- string id = e.CommandArgument.ToString();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("update OA_ANNOUNCEMENT set is_del='N' where id=" + id, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- AnnounceList.DataBind();
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.location.reload()</script>");
- }
- }
- protected void AnnounceList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- LinkButton btn = (LinkButton)e.Row.FindControl("LbEdit");
- btn.CommandArgument = AnnounceList.DataKeys[e.Row.RowIndex].Value.ToString();
- btn = (LinkButton)e.Row.FindControl("LbRestore");
- btn.CommandArgument = AnnounceList.DataKeys[e.Row.RowIndex].Value.ToString();
- }
- }
- protected void SetValue(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select type_id, subject, content, authority, validate_date, " +
- "attachment, attachment_save_name from OA_ANNOUNCEMENT where id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- int flag = 0;
- if (dr.Read())
- {
- DdlType.SelectedValue = dr["type_id"].ToString();
- TxtSubject.Text = dr["subject"].ToString();
- TxtContent.Text = dr["content"].ToString().Replace("<br>", "n").Replace(" ", " ");
- RbAuthority.SelectedValue = dr["authority"].ToString();
- TxtValidateDate.Text = dr["validate_date"].ToString();
- if (RbAuthority.SelectedValue.Equals("2"))
- {
- flag = 1;
- }
- LbAttachment.Text = dr["attachment"].ToString();
- AttachmentSaveName.Value = dr["attachment_save_name"].ToString();
- if (LbAttachment.Text.Equals(""))
- {
- BtnDelete.Visible = false;
- FileUpload1.Visible = true;
- }
- }
- dr.Close();
- if (flag == 1)
- {
- BtnSelect.Visible = true;
- LblDepartments.Visible = true;
- cmd = new SqlCommand("select a.department_id, d.name department from OA_ANNOUNCEMENT_DEPARTMENT a " +
- "inner join OA_DEPARTMENT d on a.department_id=d.id where a_id=" + id, conn);
- dr = cmd.ExecuteReader();
- string departments = "";
- string department_ids = "";
- while (dr.Read())
- {
- department_ids = department_ids + dr["department_id"].ToString() + ";";
- departments = departments + dr["department"].ToString() + ";";
- }
- if (department_ids.Length >= 1)
- {
- DepartmentIds.Value = department_ids.Substring(0, department_ids.Length - 1);
- LblDepartments.Text = departments.Substring(0, departments.Length - 1);
- }
- dr.Close();
- }
- conn.Close();
- }
- 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 LbAttachment_Click(object sender, EventArgs e)
- {
- this.DownLoadFile(AttachmentSaveName.Value);
- }
- protected void DownLoadFile(string name)
- {
- string directory = "\web\oa_upload\announce\";
- try
- {
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(LbAttachment.Text, System.Text.Encoding.UTF8));
- Response.AppendHeader("Content-Length", ContentLength.Value);
- Response.WriteFile(directory + name);
- Response.Flush();
- Response.End();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- protected void AnnounceList_RowDeleted(object sender, GridViewDeletedEventArgs e)
- {
- //刷新樹
- Response.Write("<script language='javascript'>window.parent.frames.location.reload()</script>");
- AnnounceList.DataBind();
- }
- 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;
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- 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();
- SqlCommand cmd=new SqlCommand("update OA_ANNOUNCEMENT set type_id='" + DdlType.SelectedValue + "', subject='" + TxtSubject.Text +
- "', content='" + TxtContent.Text.Replace("n", "<br>").Replace(" ", " ") + "', authority='" + RbAuthority.SelectedValue +
- "',validate_date='" + TxtValidateDate.Text + "',attachment='" + file_name + "',attachment_save_name='" + save_name +
- "',cre_date='" + mgr.getDateTime() + "' where id=" + Session["id"], 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 (" + Session["id"] + ", " + departments[i] + ")", conn);
- cmd.ExecuteNonQuery();
- }
- }
- else
- {
- string[] departments = DepartmentIds.Value.Split(new char[] { ',' });
- cmd = new SqlCommand("delete from OA_ANNOUNCEMENT_DEPARTMENT where a_id=" + Session["id"], conn);
- cmd.ExecuteNonQuery();
- for (int i = 0; i < departments.Length; i++)
- {
- cmd = new SqlCommand("insert into OA_ANNOUNCEMENT_DEPARTMENT(a_id, department_id)" +
- " values (" + Session["id"] + ", " + departments[i] + ")", conn);
- cmd.ExecuteNonQuery();
- }
- }
- }
- conn.Close();
- Response.Write("<script> alert('修改成功')</script>");
- TxtSubject.Text = "";
- TxtContent.Text = "";
- DepartmentIds.Value = "";
- }
- //
- Response.Redirect("../announcement/announce_mgr_list.aspx");
- }
- protected void BtnDelete_Click(object sender, EventArgs e)
- {
- LbAttachment.Visible = false;
- BtnDelete.Visible = false;
- FileUpload1.Visible = 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;
- }
- }
- }