print2.aspx.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. public partial class print2 : System.Web.UI.Page
  8. {
  9. LYS.UserData1 myud = new LYS.UserData1();
  10. protected void Page_Load(object sender, EventArgs e)
  11. {
  12. //用Session保存当前页
  13. //if (Session["Username"] == null)
  14. //{ Response.Redirect("LoginNew.aspx"); }
  15. string myURL = myud.GetAddressUrl().ToString();
  16. if (myURL.LastIndexOf("ID") < 0)
  17. {
  18. Response.Write("<script>alert('错误!参数不正确!不能正常显示')</script>");
  19. Response.End();
  20. }
  21. int ID = Convert.ToInt16(Request.QueryString["ID"].ToString());
  22. if (!IsPostBack)
  23. {
  24. ZJ.Text = Convert.ToDateTime(myud.GetFieldValue(5, ID, "TKJL").ToString()).ToLongDateString();
  25. ZJ1.Text = ZJ.Text;
  26. DDXM.Text = myud.GetFieldValue(4, ID, "TKJL").ToString();
  27. DD.Text = myud.GetFieldValue(9, ID, "TKJL").ToString();
  28. // DDXM1.Text = myud.GetFieldValue(4, ID, "TKJL").ToString();
  29. // DDXM2.Text = myud.GetFieldValue(4, ID, "TKJL").ToString();
  30. // DDXM4.Text = myud.GetFieldValue(4, ID, "TKJL").ToString();
  31. JSXM.Text = myud.GetFieldValue(1, ID, "TKJL").ToString();
  32. XB.Text = myud.GetFieldValue(2, ID, "TKJL").ToString();
  33. KM.Text = myud.GetFieldValue(3, ID, "TKJL").ToString();
  34. BJ.Text = myud.GetFieldValue(6, ID, "TKJL").ToString();
  35. XQ.Text = myud.GetFieldValue(7, ID, "TKJL").ToString();
  36. JC.Text = myud.GetFieldValue(8, ID, "TKJL").ToString();
  37. PF.Text = myud.GetFieldValue(28, ID, "TKJL").ToString();
  38. PJ.Text = myud.GetFieldValue(26, ID, "TKJL").ToString();
  39. }
  40. }
  41. protected void Button3_Click(object sender, EventArgs e)
  42. {
  43. HttpContext.Current.Response.Buffer = true;
  44. HttpContext.Current.Response.Clear();
  45. HttpContext.Current.Response.Charset = "gb2312";
  46. HttpContext.Current.Response.ClearContent();
  47. HttpContext.Current.Response.ClearHeaders();
  48. Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
  49. HttpContext.Current.Response.ContentType = "application/ms-word";
  50. HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=fileDown.doc");
  51. //关闭控件的视图状态 ,如果仍然为true,RenderControl将启用页的跟踪功能,存储与控件有关的跟踪信息
  52. this.EnableViewState = false;
  53. //将要下载的页面输出到HtmlWriter
  54. System.IO.StringWriter writer = new System.IO.StringWriter();
  55. System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
  56. this.RenderControl(htmlWriter);
  57. //提取要输出的内容
  58. string pageHtml = writer.ToString();
  59. int startIndex = pageHtml.IndexOf("<div style=\"margin: 0 auto;\" id=\"mainContent\">");
  60. int endIndex = pageHtml.LastIndexOf("</div>");
  61. int lenth = endIndex - startIndex;
  62. pageHtml = pageHtml.Substring(startIndex, lenth);
  63. //输出
  64. HttpContext.Current.Response.Write(pageHtml.ToString());
  65. HttpContext.Current.Response.End();
  66. }
  67. }