FineUI 官方论坛

标题: ProgressBox官方有没有集成了? [打印本页]

作者: shiningrise    时间: 2013-12-3 20:43
标题: ProgressBox官方有没有集成了?
本帖最后由 shiningrise 于 2013-12-5 11:58 编辑

ProgressBox官方有没有集成了?

[attach]3849[/attach]
不明原理的请看三生石头的文章:http://www.cnblogs.com/sanshi/archive/2012/03/04/2379271.html

  1. #region 进度条
  2.    
  3.     public static string GetAutoPostBackReference(FineUI.Button btn)
  4.     {
  5.         return string.Format("window.setTimeout(function(){{ {0};}},100);", btn.GetPostBackEventReference());
  6.     }

  7.     /// <summary>
  8.     /// 显示进度条
  9.     /// </summary>
  10.     /// <param name="title">窗口标题</param>
  11.     /// <param name="msg"></param>
  12.     /// <returns></returns>
  13.     public static string GetShowProgressReference(FineUI.Button btnNext,string title,string msg)
  14.     {
  15.         string script = string.Format("Ext.MessageBox.progress('{0}', '{1}');",title,msg);
  16.         script += ";" + GetAutoPostBackReference(btnNext);
  17.         return script;
  18.     }

  19.     public static string GetUpdateProgressReference(FineUI.Button btnNext, string processText, float percentage)
  20.     {
  21.         string script = string.Format("Ext.MessageBox.updateProgress({0},'{1}')", percentage, processText);
  22.         script += ";" + GetAutoPostBackReference(btnNext);
  23.         return script;
  24.     }

  25.     public static string GetHideProgressReference()
  26.     {
  27.         return "Ext.MessageBox.hide();";
  28.     }

  29.     #endregion
复制代码

使用方法

  1.         protected void btnNext_Click(object sender, EventArgs e)
  2.         {
  3.             Import();
  4.         }

  5.         private void Import()
  6.         {
  7.             DataTable dt = null;
  8.             if (VHelper.SessionIsExist("bStudentImport_datatable"))
  9.                 dt = VHelper.SessionRead<DataTable>("bStudentImport_datatable");
  10.             else
  11.             {
  12.                 if (!file.HasFile)
  13.                 {
  14.                     FineUI.Alert.ShowInTop("请选择导入文件.");
  15.                     return;
  16.                 }
  17.                 string fileName = this.file.ShortFileName;
  18.                 string fileExt = Path.GetExtension(fileName);
  19.                 if (",.xls,".Contains("," + fileExt.ToLower() + ",") == false)
  20.                 {
  21.                     FineUI.Alert.ShowInTop("只能上传xls文件." + fileExt);
  22.                     return;
  23.                 }
  24.                 //string filePath = Server.MapPath("~/Upload/bStudentImport/" + fileName);

  25.                string filePath =
  26. Server.MapPath("~/Upload/bStudentImport/" +
  27. System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
  28.                 if (FileHelper.Exists(filePath))
  29.                 {
  30.                     FineUI.Alert.ShowInTop(fileName + "文件已经存在,请改名后重新上传,或先删除已经存在的文件!");
  31.                     return;
  32.                 }
  33.                 this.file.SaveAs(filePath);

  34.                 dt = NPOIHelper.Import(filePath);
  35.                 dt.Rows.RemoveAt(0);

  36.                 if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  37.                     VHelper.SessionRemove("bStudentImport_curIndex");
  38.                 if (VHelper.SessionIsExist("bStudentImport_datatable"))
  39.                     VHelper.SessionRemove("bStudentImport_datatable");

  40.                 VHelper.SessionWrite<DataTable>("bStudentImport_datatable", dt);
  41.             }

  42.             //if (dt == null)
  43.             //    FineUI.Alert.ShowInTop("no");
  44.             //else
  45.             //    FineUI.Alert.ShowInTop(dt.Rows.Count.ToString());


  46.             //var query = dt.AsEnumerable()
  47.             //    .GroupBy(p => new { xh = p.Field<string>("xh") })
  48.             //    .Where(g => g.Count() > 1)
  49.             //    .Select(g=> new {g.Key.xh});

  50.             //this.Grid1.DataSource = dt;
  51.             //this.Grid1.DataBind();


  52.             //int i = 10;

  53.             var stuImportMgr = Ioc.GetObject<IStudentImportManager>();
  54.             var totle = dt.Rows.Count;
  55.             var curIndex = VHelper.SessionRead<int>("bStudentImport_curIndex");
  56.             var step = 100;
  57.             for (int i = curIndex; i < totle && i <= curIndex + step; i++)
  58.             {
  59.                 if (dt.Columns.Contains("xh"))
  60.                 {
  61.                     var xh = dt.Rows[i]["xh"].ToString();
  62.                     if (xh == "学号")
  63.                         continue;
  64.                     StudentImport stuImport = new StudentImport();
  65.                     stuImport.xh = xh;
  66.                     stuImportMgr.Save(stuImport);
  67.                 }
  68.             }
  69.             var percent = (float)curIndex / totle;
  70.             if (curIndex == 0)
  71.             {

  72.                
  73. FineUI.PageContext.RegisterStartupScript(DExt.GetShowProgressReference(this.btnNext,"
  74. 数据导入中,请耐心等待","总共需要导入" + totle.ToString() + "条记录"));
  75.                 VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
  76.             }
  77.             else if (curIndex < totle)
  78.             {

  79.                
  80. FineUI.PageContext.RegisterStartupScript(DExt.GetUpdateProgressReference(this.btnNext,
  81. string.Format("已经导入{0}", curIndex+1), percent));
  82.                 VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
  83.             }
  84.             else
  85.             {
  86.                 FineUI.PageContext.RegisterStartupScript(DExt.GetHideProgressReference());

  87.                 FineUI.Alert.ShowInTop("OK");
  88.                 if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  89.                     VHelper.SessionRemove("bStudentImport_curIndex");
  90.                 if (VHelper.SessionIsExist("bStudentImport_datatable"))
  91.                     VHelper.SessionRemove("bStudentImport_datatable");
  92.             }
  93.         }

  94.         protected void btnNext2_Click(object sender, EventArgs e)
  95.         {
  96.             FineUI.Alert.ShowInTop("OK");
  97.             if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  98.                 VHelper.SessionRemove("bStudentImport_curIndex");
  99.             if (VHelper.SessionIsExist("bStudentImport_datatable"))
  100.                 VHelper.SessionRemove("bStudentImport_datatable");
  101.             Import();
  102.         }
复制代码


作者: Neal.六道    时间: 2013-12-4 11:15
我也正想问这个问题,EXT有progressBar,为什么FineUI没有
作者: shiningrise    时间: 2013-12-4 21:51
我自己搞定了一个,有空时整理下共享给大家
作者: Tiger    时间: 2013-12-5 10:55
shiningrise 发表于 2013-12-4 21:51
我自己搞定了一个,有空时整理下共享给大家

这么牛,你可以把代码和三石共享一下,就是代码贡献者了
作者: shiningrise    时间: 2013-12-5 11:55
不明原理的请看三生石头的文章:http://www.cnblogs.com/sanshi/archive/2012/03/04/2379271.html

  1. #region 进度条
  2.    
  3.     public static string GetAutoPostBackReference(FineUI.Button btn)
  4.     {
  5.         return string.Format("window.setTimeout(function(){{ {0};}},100);", btn.GetPostBackEventReference());
  6.     }

  7.     /// <summary>
  8.     /// 显示进度条
  9.     /// </summary>
  10.     /// <param name="title">窗口标题</param>
  11.     /// <param name="msg"></param>
  12.     /// <returns></returns>
  13.     public static string GetShowProgressReference(FineUI.Button btnNext,string title,string msg)
  14.     {
  15.         string script = string.Format("Ext.MessageBox.progress('{0}', '{1}');",title,msg);
  16.         script += ";" + GetAutoPostBackReference(btnNext);
  17.         return script;
  18.     }

  19.     public static string GetUpdateProgressReference(FineUI.Button btnNext, string processText, float percentage)
  20.     {
  21.         string script = string.Format("Ext.MessageBox.updateProgress({0},'{1}')", percentage, processText);
  22.         script += ";" + GetAutoPostBackReference(btnNext);
  23.         return script;
  24.     }

  25.     public static string GetHideProgressReference()
  26.     {
  27.         return "Ext.MessageBox.hide();";
  28.     }

  29.     #endregion
复制代码

使用方法

  1.         protected void btnNext_Click(object sender, EventArgs e)
  2.         {
  3.             Import();
  4.         }

  5.         private void Import()
  6.         {
  7.             DataTable dt = null;
  8.             if (VHelper.SessionIsExist("bStudentImport_datatable"))
  9.                 dt = VHelper.SessionRead<DataTable>("bStudentImport_datatable");
  10.             else
  11.             {
  12.                 if (!file.HasFile)
  13.                 {
  14.                     FineUI.Alert.ShowInTop("请选择导入文件.");
  15.                     return;
  16.                 }
  17.                 string fileName = this.file.ShortFileName;
  18.                 string fileExt = Path.GetExtension(fileName);
  19.                 if (",.xls,".Contains("," + fileExt.ToLower() + ",") == false)
  20.                 {
  21.                     FineUI.Alert.ShowInTop("只能上传xls文件." + fileExt);
  22.                     return;
  23.                 }
  24.                 //string filePath = Server.MapPath("~/Upload/bStudentImport/" + fileName);
  25.                 string filePath = Server.MapPath("~/Upload/bStudentImport/" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
  26.                 if (FileHelper.Exists(filePath))
  27.                 {
  28.                     FineUI.Alert.ShowInTop(fileName + "文件已经存在,请改名后重新上传,或先删除已经存在的文件!");
  29.                     return;
  30.                 }
  31.                 this.file.SaveAs(filePath);

  32.                 dt = NPOIHelper.Import(filePath);
  33.                 dt.Rows.RemoveAt(0);

  34.                 if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  35.                     VHelper.SessionRemove("bStudentImport_curIndex");
  36.                 if (VHelper.SessionIsExist("bStudentImport_datatable"))
  37.                     VHelper.SessionRemove("bStudentImport_datatable");

  38.                 VHelper.SessionWrite<DataTable>("bStudentImport_datatable", dt);
  39.             }

  40.             //if (dt == null)
  41.             //    FineUI.Alert.ShowInTop("no");
  42.             //else
  43.             //    FineUI.Alert.ShowInTop(dt.Rows.Count.ToString());


  44.             //var query = dt.AsEnumerable()
  45.             //    .GroupBy(p => new { xh = p.Field<string>("xh") })
  46.             //    .Where(g => g.Count() > 1)
  47.             //    .Select(g=> new {g.Key.xh});

  48.             //this.Grid1.DataSource = dt;
  49.             //this.Grid1.DataBind();


  50.             //int i = 10;

  51.             var stuImportMgr = Ioc.GetObject<IStudentImportManager>();
  52.             var totle = dt.Rows.Count;
  53.             var curIndex = VHelper.SessionRead<int>("bStudentImport_curIndex");
  54.             var step = 100;
  55.             for (int i = curIndex; i < totle && i <= curIndex + step; i++)
  56.             {
  57.                 if (dt.Columns.Contains("xh"))
  58.                 {
  59.                     var xh = dt.Rows[i]["xh"].ToString();
  60.                     if (xh == "学号")
  61.                         continue;
  62.                     StudentImport stuImport = new StudentImport();
  63.                     stuImport.xh = xh;
  64.                     stuImportMgr.Save(stuImport);
  65.                 }
  66.             }
  67.             var percent = (float)curIndex / totle;
  68.             if (curIndex == 0)
  69.             {
  70.                 FineUI.PageContext.RegisterStartupScript(DExt.GetShowProgressReference(this.btnNext,"数据导入中,请耐心等待","总共需要导入" + totle.ToString() + "条记录"));
  71.                 VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
  72.             }
  73.             else if (curIndex < totle)
  74.             {
  75.                 FineUI.PageContext.RegisterStartupScript(DExt.GetUpdateProgressReference(this.btnNext, string.Format("已经导入{0}", curIndex+1), percent));
  76.                 VHelper.SessionWrite<int>("bStudentImport_curIndex", curIndex + step);
  77.             }
  78.             else
  79.             {
  80.                 FineUI.PageContext.RegisterStartupScript(DExt.GetHideProgressReference());

  81.                 FineUI.Alert.ShowInTop("OK");
  82.                 if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  83.                     VHelper.SessionRemove("bStudentImport_curIndex");
  84.                 if (VHelper.SessionIsExist("bStudentImport_datatable"))
  85.                     VHelper.SessionRemove("bStudentImport_datatable");
  86.             }
  87.         }

  88.         protected void btnNext2_Click(object sender, EventArgs e)
  89.         {
  90.             FineUI.Alert.ShowInTop("OK");
  91.             if (VHelper.SessionIsExist("bStudentImport_curIndex"))
  92.                 VHelper.SessionRemove("bStudentImport_curIndex");
  93.             if (VHelper.SessionIsExist("bStudentImport_datatable"))
  94.                 VHelper.SessionRemove("bStudentImport_datatable");
  95.             Import();
  96.         }
复制代码

作者: wong    时间: 2013-12-5 13:06
本着贡献精神,希望早日共享,忠心感谢!




欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) Powered by Discuz! X3.4