private void btnLogin_Click(object sender, EventArgs e) { cbxUserName.Text = cbxUserName.Text.Trim(); if (cbxUserName.Text == "") return; this.Cursor = Cursors.WaitCursor; if (!Login()) { this.Cursor = Cursors.Default; return; } //成功后 if (ckbSaveUserName.Checked) { try { LoginUserName loginUserName = LocalStoreHelper.Context.LoginUserName.FirstOrDefault(obj => obj.UserName.ToLower() == cbxUserName.Text.Trim().ToLower()); if (loginUserName != null) { loginUserName.LoginTime = DateTime.Now; } else { loginUserName = new LoginUserName(); loginUserName.UserName = cbxUserName.Text.Trim(); loginUserName.LoginTime = DateTime.Now; LocalStoreHelper.Context.LoginUserName.AddObject(loginUserName); } LocalStoreHelper.Context.SaveChanges(); BindUserNameList(); } catch (Exception ex) { this.Cursor = Cursors.Default; ControlsHelper.ShowErrorMessage("保存账号信息失败", ex.Message); } } this.Cursor = Cursors.Default; FrmMain frmMain = new FrmMain(); frmMain.Show(); this.Hide(); }
/// <summary> /// 创建新的 LoginUserName 对象。 /// </summary> /// <param name="userName">UserName 属性的初始值。</param> /// <param name="loginTime">LoginTime 属性的初始值。</param> public static LoginUserName CreateLoginUserName(global::System.String userName, global::System.DateTime loginTime) { LoginUserName loginUserName = new LoginUserName(); loginUserName.UserName = userName; loginUserName.LoginTime = loginTime; return loginUserName; }
/// <summary> /// 用于向 LoginUserName EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToLoginUserName(LoginUserName loginUserName) { base.AddObject("LoginUserName", loginUserName); }