//上传文件并返回路径 protected void fileUpload(out string newFilePath) { newFilePath = String.Empty; //文件上传后的路径, 如:"/UploadFilesx/201010/guid.doc" string newFileName = String.Empty; //文件上传后的文件名, 如:"guid.doc" string oldFileName = string.Empty; //上传前的文件名,如:"我的文档.doc" int fileSize = 0; //文件大小(kb) if (this.fu_fileLoad.HasFile) { UploadFile up = new UploadFile(); string[] str = { ".jpg", ".bmp", ".gif", ".jpeg" }; string msg; if (UploadFile.CheckFileType(Request.Files, this.fu_fileLoad.UniqueID, str, 4, out msg)) { bool flag = UploadFile.FileUpLoad(this.fu_fileLoad.PostedFile, "UploadFiles", out newFilePath, out newFileName); if (flag) { oldFileName = this.fu_fileLoad.FileName; fileSize = this.fu_fileLoad.PostedFile.ContentLength / 1024; } else { //文件上传失败 MessageBox.ResponseScript(this, "alert('文件上传失败!');"); return; } } else { //文件上传失败 MessageBox.ResponseScript(this, string.Format("alert('{0}');", msg)); return; } } }
/// <summary> /// 保存按钮点击事件执行方法 /// </summary> protected void PageSave(string doType, string id) { //t为false为编辑,true时为新增 bool t = String.Equals(doType, "update", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(id) ? false : true; //数据验证开始 StringBuilder strMsg = new StringBuilder(); if (String.IsNullOrEmpty(this.txtTitle.Value.Trim())) { strMsg.Append("标题不能为空!\\n"); } if (String.IsNullOrEmpty(this.txtSubmitTime.Value)) { strMsg.Append("提交时间不能为空!\\n"); } if (strMsg.Length > 0) { MessageBox.ResponseScript(this, String.Format("alert('{0}');", strMsg)); return; } //数据验证结束 //附件 string newFilePath = String.Empty; //文件上传后的路径, 如:"/UploadFiles/xxx/201010/guid.doc" string newFileName = String.Empty; //文件上传后的文件名, 如:"guid.doc" string oldFileName = string.Empty; //上传前的文件名,如:"我的文档.doc" int fileSize = 0; //文件大小(kb) if (this.txtFile.HasFile) { string[] str = { ".txt", ".doc", ".docx", ".xls", ".xlsx", ".jpg", ".bmp", ".gif", ".jpeg", ".rar", ".zip" }; string msg; if (UploadFile.CheckFileType(Request.Files, "txtFile", str, 4, out msg)) { bool flag = UploadFile.FileUpLoad(this.txtFile.PostedFile, "ManageCenter/Advice", out newFilePath, out newFileName); if (flag) { oldFileName = this.txtFile.FileName; fileSize = this.txtFile.PostedFile.ContentLength / 1024; } else { //文件上传失败 MessageBox.ResponseScript(this, "alert('文件上传失败!');"); return; } } else { //文件上传失败 MessageBox.ResponseScript(this, string.Format("alert('{0}');", msg)); return; } } BOpinion BLL = new BOpinion(); MGovOpinion Model; bool result = false; if (t) {//-----新增----- Model = new MGovOpinion(); this.commonModel(Model, newFilePath, newFileName, oldFileName, fileSize); result = BLL.AddGovOpinion(Model); } else {//-----编辑----- Model = BLL.GetGovOpinionModel(id); this.commonModel(Model, newFilePath, newFileName, oldFileName, fileSize); result = BLL.UpdateGovOpinion(Model); } string m = t ? "新增" : "修改"; if (result) { Utils.ShowMsgAndCloseBoxy(m + "成功!", Utils.GetQueryStringValue("IframeId"), true); } else { MessageBox.ResponseScript(this, string.Format("alert('{0}失败!');", m)); } }