//添加用户信息 public bool AddUserInfo(appleAcount userInfo) { dbSet.Add(userInfo); int ad = db.SaveChanges(); return(true); }
//删除用户信息 public bool DeleteUserInfo(appleAcount userInfo) { db.Entry <appleAcount>(userInfo).State = System.Data.Entity.EntityState.Deleted; int de = db.SaveChanges(); return(true); }
//编辑用户信息 public int EditUserInfo(appleAcount editUserInfo) { appleAcount user = dbSet.Where(a => a.ID == editUserInfo.ID).FirstOrDefault(); CopyObj(ref user, editUserInfo); db.Entry <appleAcount>(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(user.ID); }
//深复制 public void CopyObj(ref appleAcount original, appleAcount editUserInfo) { Type T = editUserInfo.GetType(); PropertyInfo[] PI = T.GetProperties(); for (int i = 0; i < PI.Length; i++) { PropertyInfo P = PI[i]; P.SetValue(original, P.GetValue(editUserInfo)); } }
// 登陆测试,登陆成功后,修改数据库remarks=“登陆成功”并返回用户信息 private static appleAcount LoginTest(ServiceContractClient client) { appleAcount user = client.Login(); userInfo = user; OrderMethods orderMethod = new OrderMethods(); string loginResult = orderMethod.LoginTest(user.loginAppleId, user.loginPassword); user.remarks = loginResult; client.EditUserInfo(user); return(user); }
private string AsyncLoginTest() { delegateTryAsyncLoginTest asyncDelegate = new delegateTryAsyncLoginTest(LoginTest); string t = ""; asyncDelegate.BeginInvoke(client, new AsyncCallback(asyncResult => { AsyncResult result = (AsyncResult)asyncResult; delegateTryAsyncLoginTest getOriginalDelegate = (delegateTryAsyncLoginTest)result.AsyncDelegate; //获得原委托 appleAcount dataOfLoginTest = getOriginalDelegate.EndInvoke(result); //执行原委托的EndInvoke方法,获得LoginTest方法执行后的结果 GetTextBox(dataOfLoginTest); t = dataOfLoginTest.remarks; }), null); return(t); }
// 把userInfo映射成表以textBox的方式显示出来 private void GetTextBox(appleAcount user) { Task.Factory.StartNew(() => { #region Invoke //新建的工作线程是非创建Form窗体的窗口线程,所以不能直接调用窗口线程。 //开启一个一部委托捆绑要执行的方法。 this.Invoke(new Action(() => { gb.Dispose(); gb = new GroupBox(); int x = 40; int y = 80; gb.Width = 900; gb.Height = 800; this.Controls.Add(gb); for (int i = 0; i < propertyInfo.Length; i++) { TextBox tb = new TextBox(); tb.Tag = "name"; tb.Text = propertyInfo[i].Name; tb.Location = new Point(x, y); tb.Width = 130; tb.Height = 20; gb.Controls.Add(tb); TextBox tbValue = new TextBox(); tbValue.Tag = "value"; try { tbValue.Text = propertyInfo[i].GetValue(user).ToString(); } catch { } tbValue.Location = new Point(x + 130, y); tbValue.Width = 200; tbValue.Height = 20; gb.Controls.Add(tbValue); y += 20; } })); #endregion }); }