MatCodeIn.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:2k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using com.etong.BusinessRule.MatCode;
  12. public partial class MatCode_MatCodeIn : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             daoru.Attributes.Add("onclick", "javascript:return confirm('您将覆盖原有数据,您确定导入吗?');");
  19.         }
  20.        
  21.     }
  22.     protected void daoru_Click(object sender, EventArgs e)
  23.     {
  24.         //string message;
  25.         
  26.         if (this.ExcelFile.HasFile)
  27.         {  
  28.             
  29.             //保存在服务器上
  30.             Random ran = new Random();
  31.             int itmp = ran.Next(1000, 9999);
  32.             string sFile = ConfigurationSettings.AppSettings["MatCodeData"] + itmp.ToString() + ".xls";            
  33.             ExcelFile.PostedFile.SaveAs(sFile);
  34.             //导入到数据库
  35.             try
  36.             {
  37.                 InExcel inexcel = new InExcel();
  38.                 string message = inexcel.inexcel(sFile);
  39.                 if (message=="")
  40.                     ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('数据成功导入数据库!');</script>");
  41.                 else
  42.                     ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('"+message+"');</script>");
  43.             }
  44.             catch (Exception ex)
  45.             {
  46.                 ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('" + ex.Message.Replace("'", "") + "');</script>");
  47.             }
  48.         }
  49.         else
  50.             Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入需要导入的文件路径!');</script>");
  51.     }  
  52. }