protected void StartLongAction(object sender, DirectEventArgs e) { if (Request["listno"] == null || Request["depotid"] == null) { X.Msg.Alert("异常", "参数错误!请关闭重试!").Show(); return; } string filename = UpFile.PostedFile.FileName; string ext = Path.GetExtension(filename).ToLower(); if (ext != ".xls" && ext != ".xlsx" && ext != ".txt") { X.Msg.Alert("提示", "文件格式不正确,仅支持.xls,.txt格式文件!").Show(); return; } filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ext; UpFile.PostedFile.SaveAs(Server.MapPath("File/" + filename)); DataTable dt = new DataTable(); if (Path.GetExtension(filename).ToLower().Contains("xls")) { CJ_DevelopHelper.OtherCon_Str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("File/" + filename) + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'"; CJ_DevelopHelper.SqlStr = "select 条码 as sku,数量 as amount from [sheet1$] where 条码<>''"; dt = CJ_DevelopHelper.Other_ReturnDateTable; } else if (Path.GetExtension(filename).ToLower().Contains("txt")) { dt = ImportTxt(Server.MapPath("File/" + filename), filename); } File.Delete(Server.MapPath("File/" + filename));//删除文档 if (dt.Rows.Count <= 0) { X.Msg.Alert("提示", "导入的文件无记录!").Show(); return; } this.Session["mainDT"] = dt; this.Session["LongActionProgress"] = 0; this.Session["listno"] = Request["listno"].ToString(); ThreadPool.QueueUserWorkItem(LongAction); MainResourceMgr.AddScript("{0}.startTask('longactionprogress');", TaskManager1.ClientID); }
protected void RefreshProgress(object sender, DirectEventArgs e) { object progress = this.Session["LongActionProgress"]; if (this.Session["Total"] == null) { return; } int totalnum = (int)this.Session["Total"]; if (progress != null) { Progress1.UpdateProgress(((int)progress) / (float)totalnum, string.Format("已完成 {0} 条,共计 {1} 条", progress.ToString(), totalnum)); } else { MainResourceMgr.AddScript("{0}.stopTask('longactionprogress');", TaskManager1.ClientID); Progress1.UpdateProgress(1, "完成"); X.Msg.Alert("提示", this.Session["result"].ToString()).Show(); this.Session.Remove("result"); } }