在c/s專案中,通常會遇到一些耗時的操作,這個時候為了更好的客戶體驗,我們通常會加上乙個進度條。 而且頁面傳值在c/s端也比較麻煩。畢竟不像b/s那樣可以使用session、querystring、cookie,或者提交**等那麼方便。
開始了:
頁面很簡單, 同樣這裡還有乙個backgroundworker類
using system;
using system.componentmodel;
using system.windows.forms;
using system.threading;
namespace quicklogisticsassistant
public actionrunworkercompleted
public runworkercompletedeventargs executionresult
public apartmentstate threadapartmentstate
public
backgroundworkerview(actiondowork, actionrunworkercompleted = null)
public
backgroundworkerview(string title, actiondowork, actionrunworkercompleted = null)
...", title);
this.text = title;
this.dowork = dowork;
this.runworkercompleted = runworkercompleted;
this.progressbar1.style = progressbarstyle.marquee;
}public
backgroundworkerview(int upperbound, actiondowork, actionrunworkercompleted = null)
public
void
runworkerasync()
private
void
backgroundworker1_dowork(object sender, doworkeventargs e)
catch (exception exception)
});th.setapartmentstate(apartmentstate.sta);
th.start();
th.join();
if (error != null)
throw error;
}else
this.dowork(sender as backgroundworker, e);
}private
void
backgroundworker1_runworkercompleted(object sender, runworkercompletedeventargs e)
private
void
backgroundworkerview_formclosing(object sender, formclosingeventargs e)
}private
void
backgroundworker1_progresschanged(object sender, progresschangedeventargs e)
private
void
backgroundworkerview_load(object sender, eventargs e)}}
接下來看呼叫的方面:
_dicexcelinfo = new dictionary();
if (_selectfiles == null || _selectfiles.count == 0)
//檔案預處理,簡單的判斷是否完整
bool checkfail = false;
//這裡呼叫該進度條窗體。此時,當裡面的內容執行完,該窗體才關閉。
backgroundworkerview view = new backgroundworkerview("正在檢查選擇的檔案是否完整...", (worker, arg) =>
else
else
]的信用負債檔案", zhi.tradedate));
checkfail = true;
return;}}
if (zhi.jybflag)
else
]的交易資料檔案", zhi.tradedate));
= new runworkercompletedeventargs(false, new exception(string.format("選擇了多個的交易資料檔案", zhi.tradedate)), true);
checkfail = true;
return;}}
}}});//設定進度條窗體為顯示為對話方塊
varret = view.showdialog
(); if
(ret == system.windows.forms.dialogresult.ok)}if
(ret == system.windows.forms.dialogresult.cancel)
if(checkfail)
string
msg = "";
foreach
(var tradedate in _dicexcelinfo.keys)
else
if(!exinfo.xyfzbflag)
else
if(!exinfo.jybflag)}if
(!string.isnullorempty(msg))
//這一步是設定當前窗體為對話方塊,這一步是跨頁面傳值的重要的非同步
this.dialogresult = system.windows.forms.dialogresult.ok;
this.close
();
呼叫importdata頁面 的資訊
importdata imp = new importdata();
if (imp.showdialog() == system.windows
.forms
.dialogresult
.ok)
{//選擇了一批檔案
dictionarydicselectfiles = imp.dicexcelinfo
;
複製和刪除進度條的完成
鑑於我原來 的基礎上,由listtable對話方塊去呼叫popmenu對話方塊,實現檔案的複製功能,而我要想實現進度條的完成,必須要傳資料給這個進度條。因此這個進度條的位置不能在listtable裡面,必須新建乙個對話方塊prograss,而這個對話方塊僅僅是有progress這乙個進度條而已。從p...
前端跨頁面傳值的幾種方式
1.url傳值這個就不說了獲取location.href之後打斷也好,擷取也好 2.cookie儲存引入jq的js庫cookie.js,之後 cookie key 存,cookie key,value 取 即可,設定時間 刪除cookie等等自己看一下文件 3.h5的web儲存,localstora...
利用Python計算 的值,並顯示進度條
利用python計算 的值,並顯示進度條 第二步 編寫 from math import from tqdm import tqdm from time import total,s,n,t 0.0,1,1.0,1.0 clock while fabs t 1e 6 total t n 2 s s ...