暮雨

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

先把文件名上传,之后专程swf的格式,这样添加到数据库中,即可浏览

时间问题只能初步整理到这样,有待进一步完善
js文件

View Code
1 function showMask2(divID) {
2             if (document.readyState == "complete") {
3                 opDiv = new show("批量导入操作", document.getElementById(divID), 350, 500);
4             } else {
5                 alert("文档未加载完毕,稍后再试");
6                 return;
7             }
8         }

 

页面效果

View Code
1 <table>
2   <tr> 
3     </td>
4    <input type="button" value="设置报告路径" class="bganni7" onclick="showMask('div_path');" />
5    <input type="button" value="批量导入处理" class="bganni7" onclick="showMask2('div_Report');" /> 
6    
7     </td>
8   </tr>
9 </table>

 

实现功能层  

View Code
 1 <div id="div_path" class="mod" style="display: none;">
 2         <div style="overflow: auto; width: 80%; margin: 0 auto;">
 3             <asp:UpdatePanel ID="UpdatePanel3" runat="server">
 4                 <ContentTemplate>
 5                     <table width="100%">
 6                         <tr>
 7                             <td class="tbtitle" style="width: 10%">
 8                                 设置简历路径:
 9                             </td>
10                             <td class="tbright" style="width: 20%">
11                                 <asp:TextBox ID="txtReportPath" runat="server" CssClass="x-form-
12 
13 text"></asp:TextBox><asp:RequiredFieldValidator
14                                     ID="RequiredFieldValidator1" runat="server"
15 
16 ControlToValidate="txtReportPath"
17                                     Display="Dynamic" ErrorMessage="设置路径不能为
18 
19 空!"></asp:RequiredFieldValidator>
20                             </td>
21                         </tr>
22                         <tr>
23                             <td colspan="2" style="text-align: center">
24                                  <asp:Button ID="btnSetReport" CssClass="anni1" runat="server"
25 
26 Text="确定" OnClick="btnSetReport_Click" />
27                             </td>
28                         </tr>
29                     </table>
30                 </ContentTemplate>
31             </asp:UpdatePanel>
32         </div>
33     </div>

 

 隐藏层js

隐藏js
1 <script type="text/javascript">
2         function setKinds() {
3             opDiv.Hide();
4         }
5     </script>

 

后台cs文件

cs文件
  1 /// <summary>
  2         /// 设置简历路径
  3         /// </summary>
  4         /// <param name="sender"></param>
  5         /// <param name="e"></param>
  6         protected void btn_bak_Click(object sender, EventArgs e)
  7         {
  8             string ServerPath = System.Web.HttpContext.Current.Server.MapPath("~");//获取服务器路径
  9             string sSavePath = txtReportPath.Text.Trim();
 10             string Virtualurl = "";//虚拟目录设置
 11             if (sSavePath.Contains(ServerPath))//保存路径是否在服务器设定的路径
 12             {
 13                 int index = sSavePath.IndexOf(ServerPath);
 14                 if (index != -1)
 15                 {
 16                     try
 17                     {
 18                         if (!Directory.Exists(sSavePath))
 19                         {
 20                             Directory.CreateDirectory(sSavePath);
 21                         }
 22                         Virtualurl = sSavePath.Substring(ServerPath.Length + index, sSavePath.Length - (ServerPath.Length + index));//虚拟目录
 23                         Virtualurl = "../" + Virtualurl.Replace(@"\", @"/");//获取虚拟目录
 24                     }
 25                     catch
 26                     {
 27                         throw;
 28                     }
 29                 }
 30             }
 31             else
 32             {
 33                 Hlsoft.Framework.Core.SmartMessageBox.AjaxResponseScript(this, "22", "alert('请确认程序路径是否正确!');");
 34                 return;
 35             }
 36 
 37             Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
 38             AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
 39             appSection.Settings["ResumePath"].Value = txtReportPath.Text.Trim();//重新设置路径
 40             config.Save(ConfigurationSaveMode.Modified);
 41 
 42             #region   批量操作
 43 
 44             //获取文件列表 
 45             string[] files = Directory.GetFiles(txtReportPath.Text.Trim());
 46 
 47             string bakSql = "";
 48 
 49             try
 50             {
 51 
 52                 foreach (string f in files)
 53                 {
 54                     if (f.LastIndexOf("\\") != -1 && f.LastIndexOf(".swf") == -1)//过滤已经生成过得swf文件
 55                     {
 56                         int index1 = -1;
 57                         if (f.LastIndexOf(".doc") != -1)
 58                         {
 59                             index1 = f.LastIndexOf(".doc");
 60                         }
 61                         else if (f.LastIndexOf(".docx") != -1)
 62                         {
 63                             index1 = f.LastIndexOf(".docx");
 64                         }
 65 
 66                         string filename = f.Substring(f.LastIndexOf("\\") + 1, (index1 - f.LastIndexOf("\\") - 1));//取文件名称
 67                         dtCan = BLL.CandidateManager.GetAllDataByLoginCode();//读取数据
 68                         if (dtCan != null)
 69                         {
 70                             for (int j = 0; j < dtCan.Rows.Count; j++)
 71                             {
 72                                 string virUrl = "";
 73                                 if (dtCan.Rows[j]["name"] != null)//如果存在
 74                                 {
 75                                     if (filename.Contains(dtCan.Rows[j]["name"].ToString().Trim()))
 76                                     {
 77                                         if (dtCan.Rows[j]["LoginCode"] != null)
 78                                         {
 79 
 80                                             virUrl = Virtualurl + filename + ".swf";
 81                                             if (f.Contains("简历"))
 82                                             {
 83                                                 bakSql += string.Format("update tb_v_candidate set resume =  '{0}' where LoginCode = '{1}';", virUrl, dtCan.Rows[j]["LoginCode"].ToString());//更新简历
 84                                             }
 85                                             else if (f.Contains("述职报告"))
 86                                             {
 87                                                 bakSql += string.Format("update tb_v_candidate set reportwork =  '{0}' where LoginCode = '{1}';", virUrl, dtCan.Rows[j]["LoginCode"].ToString());//更新述职报告
 88                                             }
 89                                             else
 90                                             {
 91                                                 continue;
 92                                             }
 93                                             ConvertWordToSwf(f, txtReportPath.Text.Trim(), Virtualurl);//转换swf格式
 94                                         }
 95                                     }
 96 
 97                                 }
 98                             }
 99                         }
100                         if (dtCan.Rows.Count > 0 && bakSql.Length > 1)
101                         {
102                             BLL.CandidateManager.Update(bakSql);//批量更新数据库
103                         }
104                     }
105                 }
106             }
107             catch (System.Exception ex)
108             {
109 
110             }
111             #endregion
112 
113             Hlsoft.Framework.Core.SmartMessageBox.AjaxResponseScript(this, "22", "alert('处理成功!');setKinds('div_Report');");
114             this.BindCand();
115         }
116 
117         /// <summary>
118         /// 源文件
119         /// </summary>
120         /// <param name="styFileName">源文件路径(物理路径)</param>
121         /// <param name="outputFileFullName">转换后输出地路径(物理路径)</param>
122         /// <param name="outputFileFullName">虚拟目录</param>
123         public string ConvertWordToSwf(String styFileName, String outputFileFullName, string virurl)
124         {
125             try
126             {
127                 int LastIndex = styFileName.LastIndexOf('\\');
128                 string FileName = styFileName.Substring(LastIndex + 1, styFileName.Length - LastIndex - 1);//文件名称
129                 int index = FileName.LastIndexOf(".");
130                 FileName = FileName.Substring(0, index + 1) + "swf";//文件名称
131 
132                 String flashPrinter = System.Web.HttpContext.Current.Server.MapPath("../res/FalshPager/FlashPaper2.2/FlashPrinter.exe");//FlashPrinter.exe  
133                 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(flashPrinter);
134 
135                 String tempFileName = styFileName;//源文件
136 
137                 String swfFileName = String.Concat(outputFileFullName, FileName);//转换后的swf格式
138                 startInfo.Arguments = String.Concat(tempFileName, " -o ", swfFileName);
139 
140                 System.Diagnostics.Process process = new System.Diagnostics.Process();
141                 process.StartInfo = startInfo;
142                 Boolean isStart = process.Start();
143                 process.WaitForExit();
144                 process.Close();
145 
146                 System.IO.File.Delete(styFileName);//删除文件
147 
148                 return virurl + FileName;
149             }
150             catch (Exception ex)
151             {
152                 return ex.ToString();
153             }
154         }

 

 

posted on 2011-12-05 16:25  蕙草  阅读(326)  评论(0编辑  收藏  举报