/// <summary> /// 打开单个工作表 /// </summary> /// <param name="Id">工作表名</param> /// <returns></returns> public ActionResult btnOpen_Click(string Id) { Thread.Sleep(3000); if (Id != null) { //取得excel文件路径 //FileInfo file = new FileInfo(@"D:\ExcelPath" + userInfo.User.Id + ".txt"); //Stream stream = file.Open(FileMode.Open); //StreamReader r = new StreamReader(stream); //string filePath = r.ReadToEnd(); //r.Close(); //stream.Close(); ExcelOperationbll excel = new ExcelOperationbll(); Exception ex; DataSet ds = excel.GetData(@"" + rtnPath() + "", Id, out ex); if (ds != null) { //dataGridView1.DataSource = ds.Tables[0]; //foreach (DataColumn v in ds.Tables[0].Columns) //{ // textBox3.Text += v.ColumnName + "\r\n"; //} string html = "<table id='content'>"; List <string> list = new List <string>(); html += "<tr>"; foreach (DataColumn c in ds.Tables[0].Columns) { if (c.ColumnName != "") { list.Add(c.ColumnName); html += "<td>" + c.ColumnName + "</td>"; } } html += "</tr>"; foreach (DataRow dr in ds.Tables[0].Rows) { html += "<tr>"; foreach (string c in list) { html += "<td>" + (dr[c] == null ? "" : dr[c].ToString()) + "</td>"; } html += "</tr>"; } html += "</table>"; return(Content(html)); } else { return(Content("false|" + ex.Message)); } } else { return(Content("未传入工作表名!")); } }
/// <summary> /// 添加税号表 /// </summary> public ActionResult btnYes_Click2(string Id) { AddDefeatScode.Clear(); string[] temp = Id.Split('!'); //textBox3.Clear(); //if (textBox2.Text == "") //{ // MessageBox.Show("请输入类别编号!"); // return; //} //添加属性调用 //取得excel文件路径 //FileInfo file = new FileInfo(@"D:\ExcelPath" + userInfo.User.Id + ".txt"); //Stream stream = file.Open(FileMode.Open); //StreamReader r = new StreamReader(stream); //string filePath = r.ReadToEnd(); //r.Close(); //stream.Close(); string filePath = @"" + rtnPath() + ""; if (temp[0] == "1") { //取得 if (temp[1] != "") { //OnBtnEnabled(false); //MSG msg = obj as MSG; ExcelOperationbll excel = new ExcelOperationbll(); Exception ex; productPorpertybll bll = new productPorpertybll(); productPorpertybll.SetOnAddProValAndOnAddProValDefeat(AddValError, AddProValDefeat); DataSet ds = excel.GetData(filePath, temp[1], out ex); List <PorpertyModel> list = new List <PorpertyModel>(); if (ds != null) { //------------把海关表excel信息插入数据库 for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string sql = @"insert into Tarifftab (TariffNo,TariffName,Unit,DutiableValue,Tariff,ConditionOne,ConditionTwo) values('" + ds.Tables[0].Rows[i][0] + "','" + ds.Tables[0].Rows[i][1] + "','" + ds.Tables[0].Rows[i][2] + "','" + ds.Tables[0].Rows[i][3] + "','" + ds.Tables[0].Rows[i][4] + "','" + ds.Tables[0].Rows[i][5] + "','" + ds.Tables[0].Rows[i][6] + "')"; DbHelperSQL.ExecuteSql(sql); } //------------ //dataGridView1.DataSource = ds.Tables[0]; } Dictionary <int, string> li; bool bol = bll.Insert(list, out li); if (bol) { return(Content("true")); } //OnBtnEnabled(true); return(Content("false")); } else { return(Content("true")); } } //添加属性值调用 else if (temp[0] == "2") { if (temp[1] != "") { ExcelOperationbll excel = new ExcelOperationbll(); Exception ex; productPorpertybll dal = new productPorpertybll(); DataSet ds = excel.GetData(filePath, temp[1], out ex); if (ds != null) { bool bol = dal.InsertPropertyValue(ds.Tables[0], out ex); if (bol) { string addErr = ""; foreach (string s in AddDefeatScode) { addErr += "|" + s + "添加失败!\r\n"; //if (OnAddText != null) //{ // OnAddText(s + "添加失败!"); // this.textBox3.SelectionStart = this.textBox3.Text.Length; // this.textBox3.ScrollToCaret(); //} } if (addErr == "") { return(Content("true")); } else { return(Content("true" + addErr)); } } else { return(Content("false|" + ex.Message)); } } } else { return(Content("请选择类别!")); } } return(Content("No!")); }