public static bool UpdateCommunication(int communicationId, string exchange, int specialWorkTypeId, DateTime workStartDate, DateTime workEndDate, string type, string name, bool sex, DateTime birthday, string company, string address, string phoneNo, double ballot, bool isReelect, string background, string situation) { try { DbEntry.UsingTransaction(delegate { SpecialWork com = SpecialWork.FindById(communicationId); com.Exchange = exchange; com.SpecialWorkTypeId = specialWorkTypeId; if (DateTime.Compare(workStartDate, new DateTime(1900, 1, 1)) == 0) { com.WorkStartDate = null; } else { com.WorkStartDate = workStartDate; } if (DateTime.Compare(workEndDate, new DateTime(1900, 1, 1)) == 0) { com.WorkEndDate = null; } else { com.WorkEndDate = workEndDate; } com.Type = type; com.Name = name; com.Sex = sex; if (DateTime.Compare(birthday, new DateTime(1900, 1, 1)) == 0) { com.Birthday = null; } else { com.Birthday = birthday; } com.Company = company; com.Address = address; com.PhoneNo = phoneNo; com.Ballot = ballot; com.IsReelect = isReelect; com.Background = background; com.Situation = situation; com.Save(); }); } catch { return(false); } return(true); }
public static bool DeleteCommunication(int communicationId) { try { SpecialWork com = SpecialWork.FindById(communicationId); com.IsDelete = true; com.Save(); } catch { return(false); } return(true); }
public void Output_Word_zdts() { try { if (communicationId == 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } int selectedYear = Convert.ToInt32(ddl_year.SelectedValue); SpecialWork com = SpecialWork.FindById(communicationId); string basePath = Server.MapPath("../../"); Document doc = new Document(basePath + "Template/专项工作情况表.doc"); //对口交流地区 Bookmark bookmark = doc.Range.Bookmarks["Exchange"]; bookmark.Text = com.Exchange == null ? "" : com.Exchange; //交流对象类别 bookmark = doc.Range.Bookmarks["Type"]; bookmark.Text = com.Type == null ? "" : com.Type; //姓名 bookmark = doc.Range.Bookmarks["Name"]; bookmark.Text = com.Name == null ? "" : com.Name; //性别 bookmark = doc.Range.Bookmarks["Sex"]; bookmark.Text = com.Sex == null ? "" : (bool)com.Sex ? "女" : "男"; //出生年月 bookmark = doc.Range.Bookmarks["Birthday"]; bookmark.Text = com.Birthday == null ? "" : ((DateTime)com.Birthday).ToString("yyyy.MM.dd"); //工作单位 bookmark = doc.Range.Bookmarks["Company"]; bookmark.Text = com.Company == null ? "" : com.Company; //联系电话 bookmark = doc.Range.Bookmarks["PhoneNo"]; bookmark.Text = com.PhoneNo == null ? "" : com.PhoneNo; //类别 bookmark = doc.Range.Bookmarks["SpecialWorkTypeText"]; bookmark.Text = SpecialWorkType.FindOne(CK.K["SpecialWorkTypeId"] == com.SpecialWorkTypeId && CK.K["IsDelete"] == false).SpecialWorkTypeText; //任期开始 bookmark = doc.Range.Bookmarks["WorkStartDate"]; bookmark.Text = com.WorkStartDate == null ? "" : ((DateTime)com.WorkStartDate).ToString("yyyy.MM.dd"); //任期结束 bookmark = doc.Range.Bookmarks["WorkEndDate"]; bookmark.Text = com.WorkEndDate == null ? "" : ((DateTime)com.WorkEndDate).ToString("yyyy.MM.dd"); //联系地址 bookmark = doc.Range.Bookmarks["Address"]; bookmark.Text = com.Address == null ? "" : com.Address; //得票数 bookmark = doc.Range.Bookmarks["Ballot"]; bookmark.Text = com.Ballot == null ? "" : com.Ballot.ToString(); //是否连任 bookmark = doc.Range.Bookmarks["IsReelect"]; bookmark.Text = com.IsReelect == null ? "" : (bool)com.IsReelect ? "是" : "否"; //社会关系及人脉 bookmark = doc.Range.Bookmarks["Background"]; bookmark.Text = com.Background == null ? "" : com.Background; //工作单位情况 bookmark = doc.Range.Bookmarks["Situation"]; bookmark.Text = com.Situation == null ? "" : com.Situation; //交流情况表 DataTable dt_fa = SituationToSpecialWork.Find(CK.K["Communication_Id"] == communicationId && CK.K["IsDelete"] == false && CK.K["Time"] >= (new DateTime(selectedYear, 1, 1)) && CK.K["Time"] <= (new DateTime(selectedYear, 12, 31))).ToDataTable(); if (dt_fa.Rows.Count > 0) { int fa_count = dt_fa.Rows.Count <= 5 ? dt_fa.Rows.Count : 5; for (int i = 0; i < fa_count; i++) { //时间 bookmark = doc.Range.Bookmarks["Si_" + i + "_Time"]; bookmark.Text = dt_fa.Rows[i]["Time"].ToString().IsNullOrEmpty() ? "" : Convert.ToDateTime(dt_fa.Rows[i]["Time"].ToString()).ToString("yyyy.MM.dd"); //地点 bookmark = doc.Range.Bookmarks["Si_" + i + "_Lo"]; bookmark.Text = dt_fa.Rows[i]["Location"].ToString(); //交流情况 bookmark = doc.Range.Bookmarks["Si_" + i + "_Si"]; bookmark.Text = dt_fa.Rows[i]["SituationName"].ToString(); } } ////插入图片 if (!com.PhotoName.IsNullOrEmpty()) { DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("Photo"); var img = builder.InsertImage(basePath + "upload/photos/" + com.PhotoName); img.Width = 115; img.Height = 150; img.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center; } string fileNameWithOutExtention = Guid.NewGuid().ToString(); doc.Save(basePath + "upload/word_zxgz/" + fileNameWithOutExtention + ".pdf", SaveFormat.Pdf); FileStream fs = new FileStream(basePath + "upload/word_zxgz/" + fileNameWithOutExtention + ".pdf", FileMode.Open); byte[] file = new byte[fs.Length]; fs.Read(file, 0, file.Length); fs.Close(); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("专项工作情况表-" + ddl_year.SelectedItem.Text + "-" + com.Name + ".pdf", System.Text.Encoding.UTF8)); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(file); Response.End(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载失败,请重新再试!')", true); return; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (communicationId == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } Bind_basic(); if (IsNew == null)//修改 { Button4.Enabled = true; btn_submit.Text = "确认修改"; //回填 try { SpecialWork com = SpecialWork.FindById(communicationId); tb_Exchange.Text = com.Exchange; ddl_SpecialWorkType.SelectedValue = com.SpecialWorkTypeId.ToString(); if (com.WorkStartDate != null) { tb_workStartDate.Value = ((DateTime)com.WorkStartDate).ToString("yyyy/MM/dd"); } if (com.WorkEndDate != null) { tb_workEndDate.Value = ((DateTime)com.WorkEndDate).ToString("yyyy/MM/dd"); } tb_Type.Text = com.Type; tb_Name.Text = com.Name; if ((bool)com.Sex)// true女性 false男性 { Radio_woman.Checked = true; } else { Radio_man.Checked = true; } if (com.Birthday != null) { tb_birth.Value = ((DateTime)com.Birthday).ToString("yyyy/MM/dd"); } tb_company.Text = com.Company; tb_address.Text = com.Address; tb_phoneNo.Text = com.PhoneNo; tb_ballot.Text = com.Ballot.ToString(); if ((bool)com.IsReelect)// 是否连任 { Radio_IsReselect_Yes.Checked = true; } else { Radio_IsReselect_No.Checked = true; } tb_Background.Text = com.Background; tb_Situation.Text = com.Situation; if (!com.PhotoName.IsNullOrEmpty())//照片 { Photo.ImageUrl = "../../upload/photos/" + com.PhotoName; } Bind_Situation(0); } catch (Exception ex) { text(ex.ToString()); Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); } } } }
//照片上传 protected void btn_upload_Click(object sender, EventArgs e) { if (communicationId == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } string fileExtension = null; string file = FileUpload_Photo.FileName; string filename = "ZXGZ-" + communicationId + "-" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss").Replace(" ", "").Replace("/", "").Replace(":", "").Replace("-", ""); bool fileOK = false; string savepath = Server.MapPath("~/upload/photos/"); //判断是否已选择上传文件 if (FileUpload_Photo.HasFile) { //获得文件后缀 fileExtension = System.IO.Path.GetExtension(FileUpload_Photo.FileName).ToLower(); //允许上传文件后缀 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; //判断文件后缀是否被允许上传 for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; filename += fileExtension; } } //文件类型合法 if (fileOK) { try { long strLen = FileUpload_Photo.PostedFile.ContentLength; if (strLen >= 5 * 1024 * 1024) { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('上传照片不能大于5M!')", true); return; } if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } FileUpload_Photo.PostedFile.SaveAs(savepath + filename); string photoUrl = "../../upload/photos/" + filename; Photo.ImageUrl = "../../upload/photos/" + filename; //照片 SpecialWork com = SpecialWork.FindById(communicationId); com.PhotoName = filename; com.Save(); ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('上传成功!')", true); } catch (Exception ex) { text(ex.ToString()); ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('无法上传!')", true); } } else { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('未识别的文件类型!')", true); } } else { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('请选择文件!')", true); } }