Winform開發(fā)框架中怎么實(shí)現(xiàn)系統(tǒng)登錄,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
成都創(chuàng)新互聯(lián)公司是專業(yè)的江岸網(wǎng)站建設(shè)公司,江岸接單;提供網(wǎng)站制作、做網(wǎng)站,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行江岸網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
在業(yè)務(wù)系統(tǒng)的操作過程中,有時(shí)候,用戶需要切換用戶進(jìn)行重新登錄,這種情況有時(shí)候是因?yàn)橐粋€(gè)人管理多個(gè)用戶賬號(hào),希望通過不同的賬號(hào)登錄進(jìn)行管理不同的資料,另一種情況是酒店的換班操作,另一個(gè)人接替前面的人進(jìn)行系統(tǒng)維護(hù)管理。這種重新登錄其實(shí)也是一種友好的操作之一,試想一下,換個(gè)賬號(hào)登錄,就需要推出系統(tǒng),重新尋找運(yùn)行程序才可以,而且如果系統(tǒng)啟動(dòng)較慢一點(diǎn)的,還需要等待,所以實(shí)現(xiàn)重新登錄,有時(shí)候也是必要的。因此實(shí)現(xiàn)這個(gè)功能,也是體現(xiàn)我們開發(fā)的系統(tǒng)注重細(xì)節(jié)的表現(xiàn)。
另外,自動(dòng)登錄(其實(shí)是接受通過命令行參數(shù)進(jìn)行登錄)也是很常見的,有時(shí)候,讓客戶端記住用戶的賬號(hào)密碼,我們?cè)诤笈_(tái)通過調(diào)動(dòng)命令行方式進(jìn)行登錄,讓系統(tǒng)程序接收到相關(guān)的參數(shù)值即可進(jìn)行登錄了。
1、系統(tǒng)重新登錄實(shí)現(xiàn)
大致的思路,就是登錄系統(tǒng)后,在系統(tǒng)菜單中有一項(xiàng)重新登錄的功能入口,單擊可以要求客戶重新輸入密碼進(jìn)行登錄,如下所示。
代碼實(shí)現(xiàn)就是通過把初始化的時(shí)候,用戶相關(guān)的操作放到一個(gè)函數(shù)里面,保證重新執(zhí)行這個(gè)函數(shù)操作就能重新刷新登錄用戶信息即可。如下所示。
在InitUserRelated函數(shù)里面,我們把用戶相關(guān)的初始化操作放在里面,其中包括顯示登錄用戶信息、用戶可操作按鈕或者菜單、首頁信息等相關(guān)項(xiàng)目,代碼如下所示。
/// <summary> /// 初始化用戶相關(guān)的系統(tǒng)信息 /// </summary> private void InitUserRelated() { ChildWinManagement.LoadMdiForm(this, typeof(FirstPage));//歡迎頁面 #region 初始化系統(tǒng)名稱 try { string Manufacturer = config.AppConfigGet("Manufacturer"); string ApplicationName = config.AppConfigGet("ApplicationName"); string AppWholeName = string.Format("{0}-{1} ", Manufacturer, ApplicationName); Portal.gc.gAppUnit = Manufacturer; Portal.gc.gAppMsgboxTitle = AppWholeName; Portal.gc.gAppWholeName = AppWholeName; this.Text = AppWholeName + " "; this.notifyIcon1.BalloonTipText = AppWholeName; this.notifyIcon1.BalloonTipTitle = AppWholeName; this.notifyIcon1.Text = AppWholeName; string userName = Portal.gc.LoginInfo.RealName; if (string.IsNullOrEmpty(userName)) { userName = Portal.gc.LoginInfo.Name; } UserStatus = string.Format("當(dāng)前用戶:{0}({1})", userName, Portal.gc.RoleInfo.RoleName); CommandStatus = string.Format("歡迎使用 {0}", Portal.gc.gAppWholeName); } catch { } #endregion InitAuthorizedUI();//根據(jù)權(quán)限屏蔽 InitSkinGallery(); UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue"); }
其中InitAuthorizedUI就是判斷用戶有哪些權(quán)限的函數(shù),根據(jù)權(quán)限系統(tǒng)獲取到的功能點(diǎn),在這里對(duì)界面元素進(jìn)行重新刷新,有權(quán)限的就顯示,沒有的就隱藏即可,如下所示。
/// <summary> /// 根據(jù)權(quán)限屏蔽功能 /// </summary> private void InitAuthorizedUI() { this.tool_Report.Enabled = Portal.gc.HasFunction("Report"); this.tool_Dict.Enabled = Portal.gc.HasFunction("Dictionary"); this.tool_ItemDetail.Enabled = Portal.gc.HasFunction("ItemDetail"); this.tool_Purchase.Enabled = Portal.gc.HasFunction("Purchase"); this.tool_StockSearch.Enabled = Portal.gc.HasFunction("StockSearch"); this.tool_TakeOut.Enabled = Portal.gc.HasFunction("TakeOut"); this.tool_WareHouse.Enabled = Portal.gc.HasFunction("WareHouse"); //this.menu_run_systemLog.Enabled = Portal.gc.HasFunction("LoginLog"); this.tool_Settings.Enabled = Portal.gc.HasFunction("Parameters"); this.tool_MonthlyStatistic.Enabled = Portal.gc.HasFunction("MonthlyStatistic"); this.tool_AnnualStatistic.Enabled = Portal.gc.HasFunction("AnnualStatistic"); this.tool_ClearAll.Enabled = Portal.gc.HasFunction("ClearAllData"); this.tool_ImportItemDetail.Enabled = Portal.gc.HasFunction("ImportItemDetail"); }
這樣封裝好后,我們需要重新登錄就方便了,我們?cè)谥匦碌卿浀牟藛尾僮骼锩妫瑢?shí)現(xiàn)代碼如下所示。
private void btnRelogin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageDxUtil.ShowYesNoAndWarning("您確定需要重新登錄嗎?") != DialogResult.Yes) return; Portal.gc.MainDialog.Hide(); Login dlg = new Login(); dlg.StartPosition = FormStartPosition.CenterScreen; if (DialogResult.OK == dlg.ShowDialog()) { if (dlg.bLogin) { CloseAllDocuments(); InitUserRelated(); } } dlg.Dispose(); Portal.gc.MainDialog.Show(); }
實(shí)現(xiàn)上面的操作過程,基本上就完成了重新登錄的操作了。
2、系統(tǒng)自動(dòng)登錄實(shí)現(xiàn)
系統(tǒng)自動(dòng)登錄有時(shí)候很必要,在用戶自己絕對(duì)信任的電腦上,自動(dòng)登錄對(duì)用戶來說,很方便友好的,君不見,QQ如此、旺旺如此等等。其實(shí)實(shí)現(xiàn)思路就是通過給exe執(zhí)行文件傳遞登錄參數(shù)即可,必要時(shí)登錄的參數(shù)值還可以進(jìn)行加密,給第三方進(jìn)行運(yùn)行調(diào)用,以前就做過一個(gè)在Web上自動(dòng)啟動(dòng)桌面程序Visio應(yīng)用軟件的操作,其實(shí)原理就是一樣,通過傳遞參數(shù)給執(zhí)行文件實(shí)現(xiàn)的。
[STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0) { LoginByArgs(args); } else { LoginNormal(args); } }
/// <summary> /// 使用參數(shù)化登錄 /// </summary> /// <param name="args"></param> private static void LoginByArgs(string[] args) { CommandArgs commandArgs = CommandLine.Parse(args); if (commandArgs.ArgPairs.Count > 0) { #region 獲取用戶參數(shù) string userName = string.Empty; string identity = string.Empty; foreach (KeyValuePair<string, string> pair in commandArgs.ArgPairs) { if ("U".Equals(pair.Key, StringComparison.OrdinalIgnoreCase)) { userName = pair.Value; } if ("P".Equals(pair.Key, StringComparison.OrdinalIgnoreCase)) { identity = pair.Value; } } #endregion if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(identity)) { bool bLogin = Portal.gc.LoginByIdentity(userName.Trim(), identity); if (bLogin) { ShowMainDialog(); } else { LoginNormal(args); } } } }
有時(shí)候,即使覺得用戶不需要通過命令行登錄,那么我們自己為了避免開發(fā)過程中,啟動(dòng)程序時(shí)候,總是需要輸入用戶賬號(hào)密碼的問題,也可以使用模擬自動(dòng)登錄的方式解決。
我們只需要在項(xiàng)目的屬性里面輸入內(nèi)置的用戶名密碼,這樣我們測(cè)試起來就不用登錄那么麻煩了。
以上就是Winform開發(fā)框架中對(duì)于系統(tǒng)重新登錄以及系統(tǒng)自動(dòng)登錄(命令行登錄)的思想思路及方式。
看完上述內(nèi)容,你們掌握Winform開發(fā)框架中怎么實(shí)現(xiàn)系統(tǒng)登錄的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文標(biāo)題:Winform開發(fā)框架中怎么實(shí)現(xiàn)系統(tǒng)登錄
文章網(wǎng)址:http://www.2m8n56k.cn/article8/pgcgop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、服務(wù)器托管、、品牌網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)