我一直在看很多关于进度条的例子,我自己也很困惑。
在我的项目中,我有一个excel.png图标,点击它时会运行一个将表数据导出为excel的页面。
您可以理解编译和导出数据可能需要大约30秒以上的时间。这足以让用户开始点击其他项目,因为没有迹象表明发生了任何事情。
解决方案当然是一个进度指示器,有很多例子可以显示如何构建进度指示器。但是,我无法看到指标如何在我的项目中使用,我的难点在于放置代码的位置以及它的外观。
将数据导出到excel的页面名为GenSRPFLens.cshtml:
@{
Layout = null;
var appData = Server.MapPath("~/App_Data");
var originalFileName = "orgSRPLens.xls";
var newFileName = string.Format("{0}.xls", Guid.NewGuid().ToString());
var originalFile = Path.Combine(appData, originalFileName);
var newFile = Path.Combine(appData, newFileName);
File.Copy(originalFile, newFile);
var lenscat =Database.Open("A-LensCatFE-01SQL");
var CustomerCode = !UrlData[0].IsEmpty()?UrlData[0]:"1";
var sql = "Select * from dbo.qryDiscountLensPrice WHERE CustomerCode=@0 Order by LensForm, LensCode";
var srplensdata = lenscat.Query(sql, CustomerCode);
var connString = string.Format(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source={0}/{1};Extended Properties='Excel 8.0;HDR=Yes;'", appData, newFileName);
var provider = "System.Data.OleDb";
using (var SRPLens = Database.OpenConnectionString(connString, provider)){
sql = @"INSERT INTO [Sheet1$] (CustomerCode, LensCode, LensForm, ShortName, Description, [Index], Discount, LensMultFactor, DispensingFee, VAT, VATRate, SRPBasedOn, iScription, Cost, DiscountPrice, NoVATprice, AddVAT, SRP)
VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17)";
foreach(var LensCode in srplensdata){
SRPLens.Execute(sql,
LensCode.CustomerCode,
LensCode.LensCode,
LensCode.LensForm,
LensCode.ShortName,
LensCode.Description,
LensCode.Index,
LensCode.Discount,
LensCode.LensMultFactor,
LensCode.DispensingFee,
LensCode.VAT,
LensCode.VATRate,
LensCode.SRPBasedOn,
LensCode.iScription,
LensCode.Cost,
LensCode.DiscountPrice,
LensCode.NoVATPrice,
LensCode.AddVAT,
LensCode.SRP);
}
}
Response.AddHeader("Content-disposition", "attachment; filename=SRPFLens.xls");
Response.ContentType = "application/octet-stream";
Response.TransmitFile(newFile);
Response.Flush();
File.Delete(newFile);
Response.End();
}
调用上述页面的部分位于名为DiscountCustomers.cshtml的页面中:
<img src="/images/ExcelIconGreen25x25.png" id="SRPLens" alt="Export SRP Lens" title="Export SRP F Data to Excel: Lens" />
@section script{
<script type="text/javascript">
$(function () {
$('#SRPLens').live('hover', function () {
$(this).css('cursor', 'pointer');
});
$('#SRPLens').live('click', function () {
$('<iframe src=@linkSRPFLens></iframe>').appendTo('body').hide();
});
});
</script>
我有一个名为progressbarT2.css的进度条.css文件:
#progressBar {
width: 150px;
height: 8px;
border: 1px solid #111;
background-color: #fff;
float: left; margin-top: 10px; margin-left: 20px;
visibility: visible;
}
#progressBar div {
height: 100%;
color: #fff;
text-align: right;
line-height: 7px; /* same as #progressBar height if we want text middle aligned */
width: 0;
background-color: #b200ff;
}
然后我卡住了,有很多例子我无法理解代码应该是什么以及应该放在哪里以使其工作。需要你的指导,谢谢。
答案 0 :(得分:1)
<div id="progressBar"> <div>
的CSS:
#progressBar {
width: 400px;
height: 22px;
border: 1px solid #111;
background-color: #292929;
}
#progressBar div {
height: 100%;
color: #fff;
text-align: right;
line-height: 22px; /* same as #progressBar height if we want text middle aligned */
width: 0;
background-color: #0099ff;
}
JS:
function progress(percent, $el) {
var progressBarWidth = percent * $el.width() / 100;
$el.find('div').animate({ width: progressBarWidth }, 500).html(percent + "% ");
}
var globalP = 0;
var startProgressBar = function(){
if(globalP < 100){
globalP = globalP + 1;
progress(globalP, $('#progressBar'));
setTimeout(startProgressBar, 500);
}
else {
//done
}
}
$(document).ready(function(){
startProgressBar();
})
完整要点: