佩特來項目經驗小集合(6)___ASP.NET模板頁的讀取,佩特來___asp.net

來源:互聯網
上載者:User

佩特來項目經驗小集合(6)___ASP.NET模板頁的讀取,佩特來___asp.net

   在佩特來售後管理系統流程中,其中有一個節點是故障分析,也就是將發回來的整機進行故障分析,傳統的方法是將每個整機的故障資訊錄入一個Excel表,表格Excel樣式:

 

   這裡是將Excel轉換成模板頁,然後根據需要替換模板中的標籤,將功能完整展示,下面介紹在這個功能在項目中實現步驟:

1.將Excel轉換為網頁

   開啟Excel文檔,單擊功能表列中的“檔案”,找到“另存新檔”,。在"另存新檔" 視窗的“檔案類型”,下拉式功能表中找到“單個檔案網頁”。名稱起自己想起的。

 

2.修改模板頁

   先看一下將Excel中模板頭部及尾部產生的靜態模板頁(htm頁),頁面#號顯示的部分都是需要替換的標籤:

   看一下這部分的代碼實現,這些就是簡單的HTML代碼,由EXCEL轉換的網頁代碼略微修改了下:

<body style="width: 95%; margin: 0 auto; padding: 20px;">    <form name="form" method="post" action="#">    [#ChaiFenID#]    <table border="1px" style="border-collapse: collapse;">        <tr style="text-align: center;">            <td colspan="15" class="style1">                起動機故障分析表(A類)            </td>        </tr>        <tr>            <td colspan="2" class="style2">                出廠二維            </td>            <td colspan="5" class="style3">                [#CCEWM#]            </td>            <td colspan="3" class="style2">                售後二維碼            </td>            <td colspan="5" class="style3">                [#SHEWM#]            </td>        </tr>        <tr>            <td rowspan="2" class="style5">                資訊            </td>            <td class="style6">                反饋單位            </td>            <td colspan="3" class="style7">                [#FKDW#]            </td>            <td class="style6">                反饋日期            </td>            <td colspan="2" class="style7">                [#FKRQ#]            </td>            <td class="style5">                型號            </td>            <td colspan="2" class="style7">                [#XH#]            </td>            <td class="style5">                序號            </td>            <td colspan="3" class="style7">                [#XLH#]            </td>        </tr>        <tr>            <td class="style6">                三包機            </td>            <td class="style5">                [#SBJ#]            </td>            <td class="style6">                零公裡機            </td>            <td class="style6">                外觀照片            </td>            <td colspan="5" class="style8">            </td>            <td colspan="3" class="style5">                效能是否正常            </td>            <td colspan="2" class="style10">                <input id="Radio1" type="radio" name="是" value="是" />是                <input id="Radio2" type="radio" valule="否" />否            </td>        </tr>        <tr>            <td class="style5">                故障<br />                組件            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>            <td class="style6">                故障現象            </td>            <td class="style5">                故障<br />                現象            </td>        </tr>        [#Body#]        <tr>            <td rowspan="2" class="style5">                其它<br />                J            </td>            <td class="style4">                1使用者解體            </td>            <td class="style5">            </td>            <td colspan="2" class="style4">                缺件要備忘            </td>            <td class="style4">                2進異物            </td>            <td class="style5">            </td>            <td colspan="2" class="style4">                進何異物要備忘            </td>            <td class="style4">                3進塵土            </td>            <td class="style5">            </td>            <td class="style4">                4進水            </td>            <td class="style5">            </td>            <td class="style4">                5進油            </td>            <td class="style5">            </td>        </tr>        <tr>            <td class="style4">                6錯裝            </td>            <td class="style5">            </td>            <td colspan="2" class="style5">            </td>            <td class="style4">                7穿釘斷            </td>            <td class="style5">            </td>            <td class="style4">                8整機鏽蝕            </td>            <td class="style5">            </td>            <td class="style4">            </td>            <td class="style5">            </td>            <td class="style4">            </td>            <td class="style5">            </td>            <td class="style5">            </td>            <td class="style5">            </td>        </tr>        <tr>            <td class="style5">                備忘<br />                K            </td>            <td class="style4">                1            </td>            <td class="style5">            </td>            <td class="style4">                2            </td>            <td class="style5">            </td>            <td class="style4">                3            </td>            <td class="style5">            </td>            <td class="style4">                4            </td>            <td class="style5">            </td>            <td class="style4">                5            </td>            <td class="style5">            </td>            <td class="style4">                6            </td>            <td class="style5">            </td>            <td class="style4">                7            </td>            <td class="style5">            </td>        </tr>        <tr>            <td colspan="15" class="style11">                註解:請在相應故障現象後空格內“√”、零件故障現象有照片存檔的請用圓圈圈示前面數字編號。            </td>        </tr>        <tr>            <td class="style5">            </td>            <td colspan="2" class="style12">                分析人:            </td>            <td colspan="4" class="style12">            </td>            <td class="style12">            </td>            <td colspan="3" class="style12">                分析日期:            </td>            <td colspan="3" class="style12">            </td>            <td class="style12">            </td>        </tr>    </table>    <input type="button" name="query" onclick="return doSubmit();" language="javascript"        value="提交" />    </form></body>


 

3.ASP.NET讀模數板頁

          ASP.NET讀模數板頁的方法如下,訪問此頁面的效果與產生的模板頁一樣:

   string mbPath = Server.MapPath("FaultMangaeTemplate.htm");  //模板頁        Encoding code = Encoding.GetEncoding("gb2312"); //字元編碼        StreamReader sr = null;         string str = null;        //讀取        try        {            sr = new StreamReader(mbPath, code);            str = sr.ReadToEnd();            str= str.Replace("[#Body#]", tableBody); //Replace方法,替換模板中需要替換的標籤            str = str.Replace("[#FKDW#]", enWXJD.DLSName);            str = str.Replace("[#FKRQ#]", enWXJD.DDDate);            str = str.Replace("[#XH#]", ljxh);            str = str.Replace("[#ChaiFenID#]", "<input id=\"hidChaifenID\" type=\"hidden\" value=\"" + chaifenid + "\"/>");            str = str.Replace("[#SBJ#]", "是");        }        catch (Exception ex)        {            throw ex;        }        finally        {            sr.Close();        }        Response.Clear();        Response.Write(str);        Response.End();


 

   上面產生的模板部分有些標籤,看一下頁面主體部分標籤替換的html代碼:

/// <summary>    ///結合故障組件及組件故障資訊,產生html    /// </summary>    private string  bindGZJBJXX()    {        string strHTML="";        DataTable dtGZBJ = new BT_LJGZ_GZManage().QueryAllGZBJByGZZL("起動機");        for (int i = 0; i < dtGZBJ.Rows.Count; i++)        {            if (i == 0)            {                strHTML = "<tr>  <td  class=\"style5\"";            }            else            {                strHTML += "<tr>  <td  class=\"style5\"";            }            strHTML += " rowspan=\"";            DataTable dtGZXX = new BT_LJGZ_GZManage().QueryAllGZXXByGZBJ(Convert.ToInt32(dtGZBJ.Rows[i]["ID"]));            double rowspan = Math.Ceiling((double)dtGZXX.Rows.Count / (double)7); //每行顯示7個故障資訊            strHTML += Convert.ToString(rowspan);            strHTML += "\">";            strHTML += Convert.ToString(dtGZBJ.Rows[i]["GZBJ"]);            strHTML += "</td>";            for (int j = 0; j < dtGZXX.Rows.Count; j=j+7)            {                if (j % 7 == 0)                {                    if (j != 0) {                        strHTML += "<tr>";                    }                    for (int z = j; z < j + 7; z++)                    {                        if (z < dtGZXX.Rows.Count)                        {                            strHTML += "<td  class=\"style4\">";                            strHTML += Convert.ToString(dtGZXX.Rows[z]["GZMC"]);                            strHTML += "</td>";                            strHTML += "<td  class=\"style5\">";                            strHTML += "<input value=\"" + dtGZXX.Rows[z]["ID"].ToString() + "\"";                            strHTML += " name=\"input\" type=\"checkbox\" />";                            strHTML += "</td>";                        }                        else {                            strHTML += "<td  class=\"style4\">";                            strHTML += "</td>";                            strHTML += "<td  class=\"style5\">";                            strHTML += "</td>";                        }                      }                    strHTML +="</tr>";                }            }        }        return strHTML;    }

   下面看一下,功能實現的頁面:


   這個功能就簡單介紹到這裡了,之所以會寫下這篇部落格,是由於這個功能的設計與實現是第一次做,剛開始實現這個功能的時候不知道從何入手,完成了發現其實它挺簡單的,所有的經驗都來自於經曆,經曆的多了,經驗也就會多了!


ASPNET模板頁的內容空白

建議
1.aspx 輸入字1
2.aspx 輸入字2

看看究竟變沒變!
 
aspnet使用了模板頁 javascript怎擷取div的ID

document.getElementById("warn"); 就可以擷取;
補充下但是如果你是asp.net控制項的話就得
document.getElementById("<%=控制項名稱.ClientID>");
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.