小马的天空
我为软狂

导航

 

直接能把前台格式按wor显示

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 IAMS.BLL;
using IAMS.Model;

namespace IAMS.Web
{
    
public partial class Application_frmExportToWord : PageBase
    
{
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
if (!IsPostBack)
            
{
                String strApplyID 
= String.Empty;
                
if (Request.QueryString["ID"!= null)
                
{
                    strApplyID 
= Request.QueryString["ID"].ToString();
                }

                
else
                
{
                    
return;
                }

                
this.LoadApplyBasic(strApplyID);
                
this.ShowWord(strApplyID);
            }

        }


        
private void LoadApplyBasic(String strApplyID)
        
{
            RoleApplication objRoleApplication 
= new RoleApplication();
            DataTable dtApply 
= objRoleApplication.GetBasicApplyInfo(strApplyID);
            
if (dtApply == null || dtApply.Rows.Count == 0)
                
return;

            lblApplyID.Text 
= strApplyID;
            lblApplyIDCode.Text 
= strApplyID;
            lblRemark.Text 
= dtApply.Rows[0]["ReMark"].ToString();
            hidApplyType.Value 
= dtApply.Rows[0]["Apply_Type"].ToString();
            Int32 intUserID 
= Convert.ToInt32(dtApply.Rows[0]["Apply_User_ID"].ToString());
            
            
this.LoadApplyUserInfo(intUserID);
            
this.LoadApplyFunctionServiceRole(strApplyID);
            
this.LoadApplyDetail(strApplyID);
        }


        
private void LoadApplyUserInfo(Int32 intUserID)
        
{
            IAMS.BLL.User objUser 
= new IAMS.BLL.User();
            DataTable dtUser 
= objUser.GetUserInfoByUserID(intUserID);

            
if (dtUser == null || dtUser.Rows.Count == 0)
                
return;

            lblPersonalNo.Text 
= dtUser.Rows[0]["Personal_No"].ToString();
            lblName.Text 
= dtUser.Rows[0]["Su_Name"].ToString() + dtUser.Rows[0]["Given_Name"].ToString();
            lblAccountID.Text 
= dtUser.Rows[0]["Account_ID"].ToString();
            lblPhoneNo.Text 
= dtUser.Rows[0]["Phone_No"].ToString();
            lblDepartment.Text 
= dtUser.Rows[0]["Department_Name"].ToString();
            lblGroup.Text 
= dtUser.Rows[0]["Group_Name"].ToString();
            lblCostCenter.Text 
= dtUser.Rows[0]["CostCenter"].ToString();
            lblEmail.Text 
= dtUser.Rows[0]["Email"].ToString();
        }


        
private void LoadApplyFunctionServiceRole(String strApplyID)
        
{
            AAF objAAF 
= new AAF();
            DataTable dtApply 
= objAAF.Get_IASFunctionServiceRoleScope_Detail_By_Apply_ID(strApplyID);
            
if (dtApply == null || dtApply.Rows.Count == 0)
                
return;

            lblFunctionGroup.Text 
= dtApply.Rows[0]["Group_Name"].ToString();
            lblService.Text 
= dtApply.Rows[0]["Service_Name"].ToString();
        }


        
private void LoadApplyDetail(String strApplyID)
        
{
            Equipment objEquipment 
= new Equipment();
            DataTable dtEquipment 
= objEquipment.SelectEquipmentExportToWord(strApplyID);
            
if (dtEquipment == null)
                
return;

            String strApplyType 
= hidApplyType.Value.ToString();

            
this.grdScope.DataSource = dtEquipment.DefaultView;
            
this.grdScope.DataBind();

            
for (int i = 0; i < grdScope.Items.Count; i++)
            
{
                DataGridItem item 
= grdScope.Items[i];
                Label lblDesc 
= new Label();
                lblDesc.CssClass 
= "workflowapprove";
                
if (strApplyType == "4")
                
{
                    item.Cells[
1].Controls.Add(lblDesc);
                }

                
else
                
{
                    item.Cells[
0].Controls.Add(lblDesc);
                }

                
                HtmlTable tbl 
= new HtmlTable();
                tbl.Width 
= "100%";
                tbl.Border 
= 0;
                HtmlTableRow row 
= new HtmlTableRow();
                HtmlTableCell cell 
= new HtmlTableCell();
                cell.InnerText 
=  PageBase.FormatDate(item.Cells[6].Text);
                cell.Attributes.Add(
"class""descbottomrightNew");
                cell.Width 
= "100%";
                row.Cells.Add(cell);
                tbl.Rows.Add(row);

                row 
= new HtmlTableRow();
                cell 
= new HtmlTableCell();
                cell.InnerText 
= PageBase.FormatDate(item.Cells[7].Text);
                cell.Attributes.Add(
"class""desc");
                cell.Width 
= "100%";
                row.Cells.Add(cell);
                tbl.Rows.Add(row);

                item.Cells[
4].Controls.Add(tbl);
            }

        }


        
private void ShowWord(String strApplyID)
        
{
            HttpContext.Current.Response.AppendHeader(
"Content-Disposition""attachment;filename="+ strApplyID + ".doc");
            HttpContext.Current.Response.Charset 
= "UTF-8";
            HttpContext.Current.Response.ContentEncoding 
= System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType 
= "application/ms-word ";
            Page.EnableViewState 
= false;
            System.IO.StringWriter tw 
= new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw 
= new System.Web.UI.HtmlTextWriter(tw);
        }

        
    }

}

posted on 2006-08-04 15:24  Vinson  阅读(243)  评论(0)    收藏  举报