|
5#
楼主 |
发表于 2013-12-5 11:55:43
|
只看该作者
不明原理的请看三生石头的文章:http://www.cnblogs.com/sanshi/archive/2012/03/04/2379271.html
- #region 进度条
-
- public static string GetAutoPostBackReference(FineUI.Button btn)
- {
- return string.Format("window.setTimeout(function(){{ {0};}},100);", btn.GetPostBackEventReference());
- }
- /// <summary>
- /// 显示进度条
- /// </summary>
- /// <param name="title">窗口标题</param>
- /// <param name="msg"></param>
- /// <returns></returns>
- public static string GetShowProgressReference(FineUI.Button btnNext,string title,string msg)
- {
- string script = string.Format("Ext.MessageBox.progress('{0}', '{1}');",title,msg);
- script += ";" + GetAutoPostBackReference(btnNext);
- return script;
- }
- public static string GetUpdateProgressReference(FineUI.Button btnNext, string processText, float percentage)
- {
- string script = string.Format("Ext.MessageBox.updateProgress({0},'{1}')", percentage, processText);
- script += ";" + GetAutoPostBackReference(btnNext);
- return script;
- }
- public static string GetHideProgressReference()
- {
- return "Ext.MessageBox.hide();";
- }
- #endregion
复制代码
使用方法
- protected void btnNext_Click(object sender, EventArgs e)
- {
- Import();
- }
- private void Import()
- {
- DataTable dt = null;
- if (VHelper.SessionIsExist("bStudentImport_datatable"))
- dt = VHelper.SessionRead<DataTable>("bStudentImport_datatable");
- else
- {
- if (!file.HasFile)
- {
- FineUI.Alert.ShowInTop("请选择导入文件.");
- return;
- }
- string fileName = this.file.ShortFileName;
- string fileExt = Path.GetExtension(fileName);
- if (",.xls,".Contains("," + fileExt.ToLower() + ",") == false)
- {
- FineUI.Alert.ShowInTop("只能上传xls文件." + fileExt);
- return;
- }
- //string filePath = Server.MapPath("~/Upload/bStudentImport/" + fileName);
- string filePath = Server.MapPath("~/Upload/bStudentImport/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
- if (FileHelper.Exists(filePath))
- {
- FineUI.Alert.ShowInTop(fileName + "文件已经存在,请改名后重新上传,或先删除已经存在的文件!");
- return;
- }
- this.file.SaveAs(filePath);
- dt = NPOIHelper.Import(filePath);
- dt.Rows.RemoveAt(0);
- if (VHelper.SessionIsExist("bStudentImport_curIndex"))
- VHelper.SessionRemove("bStudentImport_curIndex");
- if (VHelper.SessionIsExist("bStudentImport_datatable"))
- VHelper.SessionRemove("bStudentImport_datatable");
- VHelper.SessionWrite<DataTable>("bStudentImport_datatable", dt);
- }
- //if (dt == null)
- // FineUI.Alert.ShowInTop("no");
- //else
- // FineUI.Alert.ShowInTop(dt.Rows.Count.ToString());
- //var query = dt.AsEnumerable()
- // .GroupBy(p => new { xh = p.Field<string>("xh") })
- // .Where(g => g.Count() > 1)
- // .Select(g=> new {g.Key.xh});
- //this.Grid1.DataSource = dt;
- //this.Grid1.DataBind();
- //int i = 10;
- var stuImportMgr = Ioc.GetObject<IStudentImportManager>();
- var totle = dt.Rows.Count;
- var curIndex = VHelper.SessionRead<int>("bStudentImport_curIndex");
- var step = 100;
- for (int i = curIndex; i < totle && i <= curIndex + step; i++)
- {
- if (dt.Columns.Contains("xh"))
- {
- var xh = dt.Rows[i]["xh"].ToString();
- if (xh == "学号")
- continue;
- StudentImport stuImport = new StudentImport();
- stuImport.xh = xh;
- stuImportMgr.Save(stuImport);
- }
- }
- var percent = (float)curIndex / totle;
- if (curIndex == 0)
- {
- FineUI.PageContext.RegisterStartupScript(DExt.GetShowProgressReference(this.btnNext,"数据导入中,请耐心等待","总共需要导入" + totle.ToString() + "条记录"));
- VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
- }
- else if (curIndex < totle)
- {
- FineUI.PageContext.RegisterStartupScript(DExt.GetUpdateProgressReference(this.btnNext, string.Format("已经导入{0}", curIndex+1), percent));
- VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
- }
- else
- {
- FineUI.PageContext.RegisterStartupScript(DExt.GetHideProgressReference());
- FineUI.Alert.ShowInTop("OK");
- if (VHelper.SessionIsExist("bStudentImport_curIndex"))
- VHelper.SessionRemove("bStudentImport_curIndex");
- if (VHelper.SessionIsExist("bStudentImport_datatable"))
- VHelper.SessionRemove("bStudentImport_datatable");
- }
- }
- protected void btnNext2_Click(object sender, EventArgs e)
- {
- FineUI.Alert.ShowInTop("OK");
- if (VHelper.SessionIsExist("bStudentImport_curIndex"))
- VHelper.SessionRemove("bStudentImport_curIndex");
- if (VHelper.SessionIsExist("bStudentImport_datatable"))
- VHelper.SessionRemove("bStudentImport_datatable");
- Import();
- }
复制代码 |
|