简体   繁体   English

如何在我的项目中实现进度栏?

[英]How to implement a progress bar in my project?

I have been looking at so many examples regarding progress bars that I have confused myself. 我一直在看太多关于进度条的例子,这些使我感到困惑。

In my project I have a an excel.png icon which when clicked runs a page that exports table data to excel. 在我的项目中,我有一个excel.png图标,单击该图标会运行一个将表数据导出到excel的页面。

As you can understand compiling and exporting the data can take some time about 30+ seconds. 如您所知,编译和导出数据可能需要30秒钟以上的时间。 This is enough time for users to start clicking other items because there is no indication that anything is happening. 用户有足够的时间开始单击其他项目,因为没有迹象表明发生了任何事情。

The solution is of course a progress indicator and there are so many examples that show how the progress indicator can be built. 解决方案当然是进度指示器,并且有太多示例说明了如何构建进度指示器。 However, I cannot see how the indicator can be used in my project, my difficulty is where to put the code and what does it look like. 但是,我看不到指标如何在我的项目中使用,我的困难在于代码的放置位置以及它的外观。

My page that exports the data to excel is called GenSRPFLens.cshtml: 我将数据导出到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();


}

The part that calls the above page is in a page called DiscountCustomers.cshtml: 调用上述页面的部分位于一个名为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>

I have a progress bar .css file called progressbarT2.css: 我有一个名为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;

} }

Then I get stuck, there are so many examples that I cannot make any sense of what the code should be and where it should be placed to get this to work. 然后我被困住了,有太多的例子使我无法理解代码应该是什么以及应该放置在什么地方才能使它起作用。 Your guidance is needed, thanks. 需要您的指导,谢谢。

<div id="progressBar"> <div>

css: 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: JS:

  function progress(percent, $el) {
            var progressBarWidth = percent * $el.width() / 100;
            $el.find('div').animate({ width: progressBarWidth }, 500).html(percent + "%&nbsp;");
        }

  var globalP = 0;

        var startProgressBar = function(){
            if(globalP < 100){
                globalP = globalP + 1;
                progress(globalP, $('#progressBar')); 
                setTimeout(startProgressBar, 500); 
            }
            else {
                //done
            }
        }

        $(document).ready(function(){
            startProgressBar();
        })

for complete gist: 完整的要点:

https://gist.github.com/railscash/5804857 https://gist.github.com/railscash/5804857

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM