MatCodeIn.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:2k
- 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 com.etong.BusinessRule.MatCode;
- public partial class MatCode_MatCodeIn : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- daoru.Attributes.Add("onclick", "javascript:return confirm('您将覆盖原有数据,您确定导入吗?');");
- }
-
- }
- protected void daoru_Click(object sender, EventArgs e)
- {
- //string message;
-
- if (this.ExcelFile.HasFile)
- {
-
- //保存在服务器上
- Random ran = new Random();
- int itmp = ran.Next(1000, 9999);
- string sFile = ConfigurationSettings.AppSettings["MatCodeData"] + itmp.ToString() + ".xls";
- ExcelFile.PostedFile.SaveAs(sFile);
- //导入到数据库
- try
- {
- InExcel inexcel = new InExcel();
- string message = inexcel.inexcel(sFile);
- if (message=="")
- ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('数据成功导入数据库!');</script>");
- else
- ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('"+message+"');</script>");
- }
- catch (Exception ex)
- {
- ClientScript.RegisterStartupScript(GetType(),"", "<script>alert('" + ex.Message.Replace("'", "") + "');</script>");
- }
- }
- else
- Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入需要导入的文件路径!');</script>");
- }
- }