protected void btnGoodsCheck_Click(object sender, EventArgs e) { lock (GoodsExcelIn._syncObj) { string strUploadPath = this.fileUploadGoods.FileName; this.strSavePath = base.Server.MapPath("~/Upload/Goods/Goods" + DateTime.Now.ToString("yyMMddHHmmssffff") + ".xls"); this.strPath.Value = this.strSavePath; if (strUploadPath == "") { base.OutputWarn("请先选择Excel文件。"); } else { string strFileFix = Path.GetExtension(strUploadPath).ToLower(); if (strFileFix != ".xls") { base.OutputWarn("选择文件的文件格式错误,请重新选择Excel文件。"); } else { if (!Directory.Exists(base.Server.MapPath("~/Upload/Goods"))) { Directory.CreateDirectory(base.Server.MapPath("~/Upload/Goods")); } if (File.Exists(this.strSavePath)) { File.Delete(this.strSavePath); } this.fileUploadGoods.PostedFile.SaveAs(this.strSavePath); } if (File.Exists(this.strSavePath)) { DataTable dtGoods = DataExcelInfo.CheckGoodsDataExcel(this.strSavePath); DataTable dtGoodsCopy = this.CheckGoodsData(dtGoods, false); this.GridView1.Visible = false; this.gvErrorGoods.Visible = true; this.Get_ParameterList(dtGoodsCopy); if (dtGoodsCopy.Rows.Count <= 0 && dtGoods.Rows.Count > 0) { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "message", "<Script Language='JavaScript' defer>art.dialog({title: '系统提示',time: 2,content:'您提交的商品数据检验通过,请导入商品信息。',close: function () { }});</script>"); this.bolMainIndex = true; } else { File.Delete(this.strSavePath); } } else { File.Delete(this.strSavePath); base.OutputWarn("商品数据有错误,请改正。"); } } } }
protected void btnGoodsImport_Click(object sender, EventArgs e) { lock (GoodsExcelIn._syncObj) { this.strSavePath = this.strPath.Value; if (File.Exists(this.strSavePath)) { if (this.bolMainIndex) { DataTable dtGoods = DataExcelInfo.CheckGoodsDataExcel(this.strSavePath); DataTable dtGoodsCopy = this.CheckGoodsData(dtGoods, true); if (DataExcelInfo.GoodsImport(dtGoodsCopy, this._UserID, this._UserShopID)) { base.OutputWarn("恭喜您,导入商品成功!"); DataExcelInfo.GoodsNumberImport(dtGoods, this._UserShopID); this.strSavePath = ""; this.bolMainIndex = false; } else { File.Delete(this.strSavePath); base.OutputWarn("导入商品失败,请再次检验并改正商品数据!"); } } else { File.Delete(this.strSavePath); base.OutputWarn("您导入的商品数据还没有检验成功,请通过检验再导入商品数据。"); } } else { base.OutputWarn("您还没有检验商品数据,请先检验数据"); } } }