public static bool UsingWcf(Action action) { try { if (!AppServer.WcfService_Open()) { return(false); } action(); return(true); } catch (Exception ex) { AppServer.ShowMsg_ExceptError(ex.Message); return(false); } finally { AppServer.WcfService_Close(); } }
private void btnLogin_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.None; if (this.txtLoginName.Text.Trim().Length == 0) { AppServer.ShowMsg("请输入要登录的用户账号!"); this.txtLoginName.Focus(); this.DialogResult = DialogResult.None; return; } //开始验证登录 base.Cursor = Cursors.WaitCursor; try { if (!AppServer.WcfService_Open()) { return; } // var model = new Ref_WS_STK.DataType_User(); model.LoginName = this.txtLoginName.Text; model.LoginPswd = this.txtLoginPswd.Text; model.LoginDate = this.dtpLoginDate.Value; model.LoginAddr = TY.Common.NetWork.GetLocalIP(); model.LoginID = AppServer.LoginID; //重新登录时会用于注册退出使用 AppServer.wcfClient.SYS_Login(ref model); if (model.ExResult != 0) { AppServer.ShowMsg_Error(model.ErrorMsg, "登录失败了!"); switch (model.ExResult) { case 1: this.txtLoginName.Focus(); break; case 2: this.txtLoginPswd.Focus(); break; case 3: this.dtpLoginDate.Focus(); break; } return; } AppServer.LoginUserCode = model.UserCode; AppServer.LoginUserName = model.UserName; AppServer.LoginWorkDate = this.dtpLoginDate.Value; AppServer.LoginID = model.LoginID; //获取用户菜单列表 DataSet tdb = AppServer.wcfClient.SYS_Login_Menu(ref model); if (model.ExResult != 0) { AppServer.ShowMsg_Error(model.ErrorMsg, "登录失败了!"); return; } if (AppServer.UserQxMenuList != null) { AppServer.UserQxMenuList.Dispose(); } AppServer.UserQxMenuList = tdb.Tables[0].Copy(); AppServer.UserQxMenuList.PrimaryKey = new DataColumn[1] { AppServer.UserQxMenuList.Columns["MenuCode"] }; //获取系统参数 AppServer.wcfClient.SYS_Param_Get(ref AppServer.Sys_Param); } catch (Exception ex) { AppServer.ShowMsg_Error("系统登录时出现异常,请确认您的网络连接是否有问题!\n错误信息:" + ex.Message, "登录失败了!"); return; } finally { AppServer.WcfService_Close(); base.Cursor = Cursors.Arrow; } //登录成功了 if (this.chkRemember.Checked) { Properties.Settings.Default.LoginName = this.txtLoginName.Text; Properties.Settings.Default.LoginPswd = Cmn_DataProtection.ProtectData(txtLoginPswd.Text, "GLG_STK_Password"); Properties.Settings.Default.LoginRemb = this.chkRemember.Checked; } else { Properties.Settings.Default.LoginName = string.Empty; Properties.Settings.Default.LoginPswd = string.Empty; Properties.Settings.Default.LoginRemb = this.chkRemember.Checked; } Properties.Settings.Default.Save(); this.DialogResult = DialogResult.OK; }
public static bool OpenUserMenu(string AMenuCode, string AMenuName) { if (!AppServer.UserQxMenuList.Rows.Contains(AMenuCode)) { AppServer.ShowMsg_Warn(string.Format("对不起,您没有“{0}”模块的操作权限,请与系统管理员联系解决!", AMenuName), "权限验证"); return(false); } //已打开的就不再重复创建了 foreach (Form fForm in Application.OpenForms) { if (fForm.Name == AMenuName) { fForm.BringToFront(); return(true); } } //开始创建表单 Form fMdiForm = null; switch (AMenuCode) { #region 基础设置-01 case "0101": { fMdiForm = new BAS_仓库设置(); break; } case "0102": { fMdiForm = new BAS_货架设置(); break; } case "0103": { fMdiForm = new BAS_储物箱设置(); break; } case "0104": { fMdiForm = new BAS_供应商设置(); break; } case "0105": { fMdiForm = new BAS_存货类别设置(); break; } case "0106": { fMdiForm = new BAS_存货设置(); break; } case "0107": { fMdiForm = new BAS_期初库存设置(); break; } //case "0108": { fMdiForm = new BAS_存货出库单价设置(); break; } #endregion #region 库存管理-02 case "0201": { var fm = new STK_库存入库_Editor(); fm.Editor_Add(); fm.ShowDialog(); break; } case "0202": { var fm = new STK_库存出库_Editor(); fm.Editor_Add(); fm.ShowDialog(); break; } //case "0206": // { // var fm = new M01_申请单_Edit(); // fm.Editor_Add(2); // fm.ShowDialog(); // break; // } case "0207": { fMdiForm = new STK_库存入库(); break; } case "0208": { fMdiForm = new STK_库存出库(); break; } #endregion #region 期末管理-03 case "0301": { fMdiForm = new STK_期末结账(); break; } //case "0303": { fMdiForm = new Bas_盘点(); break; } #endregion #region 库存报表-04 case "0501": { fMdiForm = new STK_库存分布(); break; } //case "0402": { fMdiForm = new Bas_出入库信息记录(); break; } case "0503": { fMdiForm = new STK_库存总账(); break; } #endregion #region 系统管理-09 case "0901": { (new Man_Param()).ShowDialog(); break; } case "0902": { fMdiForm = new Man_UserMngr(); break; } case "0903": { (new Man_UserPswd()).ShowDialog(); break; } #endregion } // if (fMdiForm != null) { fMdiForm.Name = AMenuName; fMdiForm.Text = AMenuName; fMdiForm.MdiParent = AppServer.MainForm; fMdiForm.WindowState = FormWindowState.Maximized; fMdiForm.Show(); fMdiForm.BringToFront(); AppServer.CurrentForm = fMdiForm; } //调用成功了 return(true); }
public Boolean Login(Boolean AFirst = false) { bool bLogined = false; if (!string.IsNullOrWhiteSpace(AppServer.LoginUserCode) && AFirst) { var model = new Ref_WS_STK.DataType_User(); model.ExAction = "OA"; model.LoginName = AppServer.LoginUserCode; AppServer.UsingWcf(() => { AppServer.wcfClient.SYS_Login(ref model); }); if (model.ExResult == 0) { AppServer.LoginUserCode = model.UserCode; AppServer.LoginUserName = model.UserName; AppServer.LoginWorkDate = DateTime.Now; AppServer.LoginID = model.LoginID; //获取用户菜单列表 AppServer.UsingWcf(() => { DataSet tdb = AppServer.wcfClient.SYS_Login_Menu(ref model); if (model.ExResult != 0) { bLogined = false; } else { if (AppServer.UserQxMenuList != null) { AppServer.UserQxMenuList.Dispose(); } AppServer.UserQxMenuList = tdb.Tables[0].Copy(); AppServer.UserQxMenuList.PrimaryKey = new DataColumn[1] { AppServer.UserQxMenuList.Columns["MenuCode"] }; //获取系统参数 AppServer.wcfClient.SYS_Param_Get(ref AppServer.Sys_Param); bLogined = true; } }); } } // if (!bLogined) { using (var fLogin = new Man_Login()) { fLogin.Visible = false; fLogin.LoginType(AFirst); if (fLogin.ShowDialog() != DialogResult.OK) { //登录失败了,直接返回 return(false); } //登录成功了 base.Cursor = Cursors.WaitCursor; } } // try { //更新界面属性 this.Text = string.Format("{0} {1}", AppServer.Sys_Param.AppName, Man_About.AssemblyAppVer); this.toolStripLabelTitle.Text = string.Format("『{0}』的功能树", AppServer.LoginUserName); this.tsslAppHost.Text = string.Format("应用服务器:{0}", AppServer.wcfClient.Endpoint.Address.Uri.Host.ToString()); this.tsslWorkDate.Text = string.Format("业务日期:{0:yyyy-MM-dd}", AppServer.LoginWorkDate); this.tsslLoginUser.Text = string.Format(" 操作员:({0}){1} ", AppServer.LoginUserCode, AppServer.LoginUserName); this.tsslAppUnit.Text = string.Format(" 公司名称:{0}", AppServer.Sys_Param.公司名称); //创建用户功能树 if (AppServer.UserQxMenuList != null) { //DataView dv = new DataView(AppServer.UserQxMenuList); //dv.RowFilter = "MenuType=0 or MenuType=1"; DataTable dt = AppServer.UserQxMenuList.Clone(); foreach (DataRow row in AppServer.UserQxMenuList.Select("MenuType=0 or MenuType=1", "MenuPCode, MenuOrder, MenuCode")) { dt.Rows.Add(row.ItemArray); } this.dbTreeView.DataSource = dt; // AppServer.UserQxMenuList; this.dbTreeView.BuildTrees(); } //重新登录后要把子窗口全部关闭 if (!AFirst) { foreach (Form fMDI in this.MdiChildren) { fMDI.Close(); } } //返回成功登录了 return(true); } finally { base.Cursor = Cursors.Arrow; } }
public void ShowMsg() { this.Show(); AppServer.SetWindowTop(this, true); this.Refresh(); }