- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections.Generic;
- 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.IO;
- public partial class FileBooks_UpFilesEdit : System.Web.UI.Page
- {
- //模板
- Model.Files MR = new Model.Files();
- //业务
- BLL.Files BR = new BLL.Files();
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginLogic.MatchLoad("../", "FileBooks_UpFilesEdit");
- if (!IsPostBack)
- {
- object objid = Request.QueryString["id"];
- if (objid != null)
- {
- DropLoadSet();
- int ri = int.Parse(objid.ToString());
- MR = BR.GetModel(ri);
- MRID = MR.ID;
- KeyValue_WJH.Text = MR.WJH;
- KeyValue_BJBT.Text = MR.BJBT;
- KeyValue_FWDW.Text = MR.FWDW;
- KeyValue_MJ.SelectedValue = MR.MJ;
- KeyValue_WJFL.SelectedValue = MR.WJFL;
- KeyValue_WJYS.Text = MR.WJYS.ToString();
- KeyValue_BZ.Text = MR.BZ;
- MRFJPath = MR.FJPath;
- KeyValue_WJZTC.Text = MR.WJZTC;
- KeyValue_WJFBT.Text = MR.WJFBT;
- KeyValue_FWRQ.Text = MR.FWRQ.ToString();
- KeyValue_JJDJ.SelectedValue = MR.JJDJ;
- KeyValue_GWLB.SelectedValue = MR.GWLB;
- KeyValue_DYYS.Text = MR.DYYS.ToString();
- KeyValue_SSJA.SelectedValue = MR.SSJA;
- }
- }
- }
- public int MRID
- {
- get
- {
- if (ViewState["FilesMRID"] == null)
- {
- return 0;
- }
- else
- {
- return int.Parse(ViewState["FilesMRID"].ToString());
- }
- }
- set { ViewState["FilesMRID"] = value; }
- }
- public string MRFJPath
- {
- get
- {
- if (ViewState["FilesPathDown"] == null)
- {
- return "";
- }
- else
- {
- return ViewState["FilesPathDown"].ToString();
- }
- }
- set { ViewState["FilesPathDown"] = value; }
- }
- public void DropLoadSet()
- {
- //密级
- KeyValue_MJ.DataTextField = "Text";
- KeyValue_MJ.DataValueField = "Value";
- KeyValue_MJ.DataSource = EnumGet.MiJiGetEnum();
- KeyValue_MJ.DataBind();
- KeyValue_MJ.SelectedIndex = KeyValue_MJ.Items.Count - 1;
- //紧急
- KeyValue_JJDJ.DataTextField = "Text";
- KeyValue_JJDJ.DataValueField = "Value";
- KeyValue_JJDJ.DataSource = EnumGet.JinJiGetEnum();
- KeyValue_JJDJ.DataBind();
- KeyValue_JJDJ.SelectedIndex = KeyValue_JJDJ.Items.Count - 1;
- //文件分类
- KeyValue_WJFL.DataTextField = "Text";
- KeyValue_WJFL.DataValueField = "Value";
- KeyValue_WJFL.DataSource = EnumGet.WenJianGetEnum();
- KeyValue_WJFL.DataBind();
- KeyValue_WJFL.SelectedIndex = KeyValue_WJFL.Items.Count - 1;
- //公文
- KeyValue_GWLB.DataTextField = "Text";
- KeyValue_GWLB.DataValueField = "Value";
- KeyValue_GWLB.DataSource = EnumGet.GongWenGetEnum();
- KeyValue_GWLB.DataBind();
- KeyValue_GWLB.SelectedIndex = KeyValue_GWLB.Items.Count - 1;
- //卷案
- KeyValue_SSJA.DataTextField = "ANMC";
- KeyValue_SSJA.DataValueField = "ID";
- KeyValue_SSJA.DataSource = EnumGet.RollGetEnum();
- KeyValue_SSJA.DataBind();
- KeyValue_SSJA.SelectedIndex = KeyValue_SSJA.Items.Count - 1;
- }
- /// <summary>
- /// 上传一个文件删除原来的文件
- /// </summary>
- /// <returns></returns>
- public string UPdateFile()
- {
- if (!string.IsNullOrEmpty(this.KeyValue_FJPath.PostedFile.FileName))
- {
- string fulname = this.KeyValue_FJPath.PostedFile.FileName;
- string filename = fulname.Substring(fulname.LastIndexOf("\") + 1);
- string type = fulname.Substring(fulname.LastIndexOf(".") + 1);
- if (type == "aspx" || type == "asp" || type == "exe")
- {
- throw new Exception("允许上传执行性文件");
- }
- string GuidStr = Guid.NewGuid().ToString() + "-" + filename;
- string FileUpdatePathFull = AppDomain.CurrentDomain.BaseDirectory + "FileBooks\UpLoadFiles\" + GuidStr;
- this.KeyValue_FJPath.PostedFile.SaveAs(FileUpdatePathFull);
- try
- {
- File.Delete(AppDomain.CurrentDomain.BaseDirectory + "FileBooks\UpLoadFiles\" + MRFJPath);
- }
- catch { }
- return GuidStr;
- }
- else
- {
- return "";
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- try
- {
- if (KeyValue_WJH.Text == "")
- {
- throw new Exception("文件号不能为空!");
- }
- if (KeyValue_BJBT.Text == "")
- {
- throw new Exception("文件标题不能为空!");
- }
- DateTime QKeyValue_FWRQ = new DateTime();
- if (!DateTime.TryParse(KeyValue_FWRQ.Text, out QKeyValue_FWRQ))
- {
- throw new Exception("发文日期格式不正确!");
- }
- int QDYYS = 0;
- if (!int.TryParse(KeyValue_DYYS.Text, out QDYYS))
- {
- throw new Exception("打印页数不正确!");
- }
- int QWJYS = 0;
- if (!int.TryParse(KeyValue_WJYS.Text, out QWJYS))
- {
- throw new Exception("文件页数不正确!");
- }
- MR.ID = MRID;
- MR.WJH = KeyValue_WJH.Text;
- MR.BJBT = KeyValue_BJBT.Text;
- MR.FWDW = KeyValue_FWDW.Text;
- MR.MJ = KeyValue_MJ.SelectedValue;
- MR.WJFL = KeyValue_WJFL.SelectedValue;
- MR.WJYS = QWJYS;
- MR.BZ = KeyValue_BZ.Text;
- // MR.FJPath = UPdateFile();
- MR.WJZTC = KeyValue_WJZTC.Text;
- MR.WJFBT = KeyValue_WJFBT.Text;
- MR.FWRQ = QKeyValue_FWRQ;
- MR.JJDJ = KeyValue_JJDJ.SelectedValue;
- MR.GWLB = KeyValue_GWLB.SelectedValue;
- MR.DYYS = QDYYS;
- MR.SSJA = KeyValue_SSJA.SelectedValue;
- MR.SCR = SessionInclude.SessionId;
- BR.Update(MR);
- MessageBox.Show("更新成功");
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.Message);
- }
- }
- }