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
#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();
}
复制代码
作者:
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
#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();
}
复制代码
作者:
wong
时间:
2013-12-5 13:06
本着贡献精神,希望早日共享,忠心感谢!
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4