欢迎使用CSDN-markdown编辑器

来源:互联网 发布:短信接收软件下载 编辑:程序博客网 时间:2024/06/05 00:58
<form id="fm" method="post" enctype="multipart/form-data">    <div class="easyui-layout" style="width: 770px; height: 495px;">        <div data-options="region:'north'" style="height: 130px">            <table class="ContentMain">                <tr>                    <td class="tb_left">                        版本号:                    </td>                    <td>                        <select id="drpBanbenhao" class="easyui-combobox" style="width: 150px;" panelheight="auto"  required="true"                            runat="server">                        </select>                        <input name="Flag" id="flag" type="hidden" />                        <input name="Flag" id="FieldId" type="hidden" />                    </td>                    <td class="tb_left">                        模板编号:                    </td>                    <td>                        <select id="drpMobanbianhao" class="easyui-combobox" style="width: 150px;"  required="true" panelheight="auto"                            runat="server">                        </select>                    </td>                    <td class="tb_left">                        模板名称:                    </td>                    <td>                        <input id="txtSTempName" class="easyui-textbox"  required="true" />                    </td>                </tr>                <tr>                    <%--<td class="tb_left">                        是否必填:                    </td>                    <td>                        <input type="radio" class="radio" name="RidCMandatory" style="width: 25px;" value="0"                            checked="checked" /><label style="display: inline-block; height: 17px;">否</label>                        <input type="radio" class="radio" name="RidCMandatory" style="width: 25px;" value="1" /><label                            style="display: inline-block; height: 17px;">是</label>                    </td>--%>                     <td class="tb_left">                        文件:                    </td>                    <td>                        <div id="isShow">                            <a id="linFileUrl" href="#" onclick="DownLoad()">下载模板</a>                        </div>                    </td>                    <td class="tb_left">                        文件名称:                    </td>                    <td>                        <input id="txtSFileName" class="easyui-textbox" required="true" />                    </td>                    <td class="tb_left">                        文件类型:                    </td>                    <td>                        <input id="txtSFileType" class="easyui-textbox" required="true" />                    </td>                </tr>                <tr>                    <td class="tb_left">                        上传模板:                    </td>                    <td colspan="3">                        <input id="txtUploadMB" name="txtSFileUnit" class="easyui-filebox" required="true"                            data-options="prompt:'选择文件...',buttonText:'选择文件',onChange:function(){uploadFiles()}"                            style="width: 370px;" />                    </td>                </tr>                <%--data-options="buttonText:'上传'"--%>            </table>        </div>        <div data-options="region:'south',split:true" style="height: 50px;">            <center style="vertical-align: middle">                <a href="#" class="easyui-linkbutton" onclick="save()">保 存</a> <a href="#" class="easyui-linkbutton"                    onclick="windowClose();">返 回</a>            </center>        </div>        <div data-options="region:'center',iconCls:'icon-ok'">            <table id="dd" class="easyui-datagrid" data-options="fit:true">                <thead>                    <tr>                        <th data-options="field:'a',checkbox:true">                            序号                        </th>                        <th data-options="field:'SVariId',width:80" hidden="true">                            变量id(隐藏id)                        </th>                        <th data-options="field:'STempId',width:80" hidden="true">                            模板id(隐藏id)                        </th>                        <th data-options="field:'NVariType',width:100,                        formatter:function(value,row){                            return row.NVariName;                        },                        editor:{                             type:'combobox',                            options:{                                valueField:'NVariType',                                textField:'NVariName',                                method:'get',                                 url: '/Handler/SysMod/Docunmen.ashx/ProcessRequest?random=<%=Session["Random"] %>&flag=VariType'                            }                        }">                            变量类型                        </th>                        <th data-options="field:'SVariName',width:280,align:'left',editor:'textbox'">                            变量名                        </th>                        <th data-options="field:'SVariCnName',width:280,align:'left',editor:'textbox'">                            中文名                        </th>                        <th data-options="field:'SVariWdTableName',width:80">                            对应文档表格名称                        </th>                        <th data-options="field:'SVariWdTableOrder',width:580,align:'left',editor:'textbox'" hidden="true">                            对应文档表格下标                        </th>                        <th data-options="field:'SVariCoName',width:100,                        formatter:function(value,row){                            return row.tableNameComment;                        },                        editor:{                             type:'combobox',                            options:{                                valueField:'SVariCoName',                                textField:'tableNameComment',                                method:'get',                                 url: '/Handler/SysMod/Docunmen.ashx/ProcessRequest?random=<%=Session["Random"] %>&flag=QueryTableInfoList',                                 onSelect: GetValue                            }                        }">                            源名称                        </th>                        <th data-options="field:'NVariCoType',width:100,                        formatter:function(value,row){                            return row.NVariCoName;                        },                        editor:{                             type:'combobox',                            options:{                                valueField:'NVariCoType',                                textField:'NVariCoName',                                method:'get',                                 url: '/Handler/SysMod/Docunmen.ashx/ProcessRequest?random=<%=Session["Random"] %>&flag=MajorOrSub'                            }                        }">                            源类型                        </th>                        <th data-options="field:'SVariColumn',width:100,                        formatter:function(value,row){                            return row.SVariCoCommonets;                        },                        editor:{                             type:'combobox',                            options:{                                valueField:'SVariColumn',                                textField:'SVariCoCommonets',                                method:'get'                            }                        }">                            字段名                        </th>                    </tr>                </thead>            </table>        </div>    </div>    <%--在这里将变量列表体现出来--%>    </form>

<td class="tb_left">
上传模板:
</td>
<td colspan="3">
<input id="txtUploadMB" name="txtSFileUnit" class="easyui-filebox" required="true"
data-options="prompt:'选择文件...',buttonText:'选择文件',onChange:function(){uploadFiles()}"
style="width: 370px;" />
</td>//这里是前台页面使用easyui实现的功能,需要引用easyui文件

function uploadFiles() {
$('#fm').form('submit', {
url: '/Handler/SysMod/Docunmen.ashx/ProcessRequest?Ran=' + Math.random() + '&flag=UploadFile',
success: function (result) {
var result = eval('(' + result + ')');
//可以写一些提示的代码等等..
$("#dd").datagrid({
rownumbers: true,
data: result,
pageSize: 10,
height: 500,
onEndEdit: onEndEdit,
singleSelect: true, //单选
method: 'get',
striped: true,
fit: true,
onClickCell: onClickCell
});
}
});
}``

//在这里是实现的具体方法
//在一般处理性程序页面中
public void ProcessRequest(HttpContext context)
{
if (context.Request[“flag”] == “UploadFile”)
{
UploadFile(context);
}
}

private void UploadFile(HttpContext context)    {        context.Response.ContentType = "text/plain";        int length = context.Request.Files.Count;        HttpFileCollection files = context.Request.Files;        if (files.Count > 0)        {            for (int i = 0; i < files.Count; i++)            {                HttpPostedFile file = files[i];                if (file.ContentLength > 0)                {                    //全路径                    string FullFullName = file.FileName;                    FileName = FullFullName;                    //获取名称                    string sPt = context.Request.ApplicationPath + FileName;                    file.SaveAs(sPt);                    String fileName = FullFullName.Substring(FullFullName.LastIndexOf("\\") + 1);                    string path = "UploadFile";                    fileName = Guid.NewGuid().ToString() + fileName;//防重名                    SaveFileName = fileName;                    Stream requestStream = null;                    Stream fileStream = null;                    FtpWebResponse uploadResponse = null;//创建FtpWebResponse实例uploadResponse                      try                    {                        //获取文件长度                          int FileLength = file.ContentLength;                        FtpWebRequest uploadRequest = createFtpWebRequest(fileName);                        uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;//将FtpWebRequest属性设置为上传文件                          requestStream = uploadRequest.GetRequestStream();//获得用于上传FTP的流                          byte[] buffer = new byte[FileLength];                        fileStream = file.InputStream;//截取FileUpload1获取的文件流,作为上传FTP的流                          fileStream.Read(buffer, 0, FileLength);                        requestStream.Write(buffer, 0, FileLength);//将buffer写入流                          requestStream.Close();                        uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();//返回FTP服务器响应,上传完成                          //上传成功                      }                    catch (Exception ex)                    {                        string s = ex.Message.ToString();                        context.Response.Write(s.Substring(0, s.Length - 4) + "\n请联系管理员!");                        context.Response.End();                        return;                    }                    finally                    {                        if (uploadResponse != null)                            uploadResponse.Close();                        if (fileStream != null)                            fileStream.Close();                        if (requestStream != null)                            requestStream.Close();                    }                    //if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))                    //{                    //    Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(path));                    //}                    ////保存文件。                    //file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + fileName);                    //FileName = System.Web.HttpContext.Current.Server.MapPath(path) + "\\" + fileName;                    #region 读取文档中的内容                    List<ModelPmVariable> variablList = new List<ModelPmVariable>();                    #region 读取单一值                    //string str="$fdddd$";                    //var docum = copyWordDoc(FileName);                    var docum = new Aspose.Words.Document(sPt);                    string[] str = docum.Range.Text.Split(' ');                    string pattern = @"^\$.*\$$";                    foreach (var item in str)                    {                        Regex regex = new Regex(pattern, RegexOptions.Singleline);                        if (regex.IsMatch(item.Replace("\r", "").Replace("\n", "")))                        {                            ModelPmVariable mbv = new ModelPmVariable();                            mbv.SVariName = regex.Match(item).Value;                            mbv.NVariType = "1";                            mbv.NVariName = "单一值";                            variablList.Add(mbv);                        }                    }                    variablList = variablList.Where((x, j) => variablList.FindIndex(z => z.SVariName == x.SVariName) == j).ToList();                    #endregion                    #region 读取表格变量                    doc = new Document(sPt);                    string result = Read();//这里是读取表格中的变量                    if (!string.IsNullOrEmpty(result))                    {                        string[] strtb = result.TrimEnd('&').Split('&');                        foreach (var item in strtb)                        {                            ModelPmVariable mbv = new ModelPmVariable();                            mbv.SVariWdTableOrder = Convert.ToInt32(item.Replace("\r", "").Replace("\n", "").Split(';')[0].Split('+')[0]);                            mbv.SVariWdTableName = item.Replace("\r", "").Replace("\n", "").Split(';')[0].Split('+')[1];                            mbv.SVariName = item.Replace("\r", "").Replace("\n", "").Split(';')[1];                            mbv.NVariType = "2";                            mbv.NVariName = "表格";                            variablList.Add(mbv);                        }                    }                    #endregion                    //System.IO.Directory.Delete(sPt);//将服务器文件删除                    var sbJson = com.json(variablList, variablList.Count);                    context.Response.Write(sbJson.ToString());                    context.Response.End();                    #endregion                }            }        }    }```在这里可以下载Aspose

http://download.csdn.net/detail/airforcetwo/9770778

0 0