/// <summary> /// 增加一条数据 /// </summary> public long Add(Model.UserAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into UserAccount("); strSql.Append("RealName,Sex,Email,PassWord,Status,CreateDate,OpenId,Mobile,Age,Addr,Descri,Integral)"); strSql.Append(" values ("); strSql.Append("@RealName,@Sex,@Email,@PassWord,@Status,@CreateDate,@OpenId,@Mobile,@Age,@Addr,@Descri,@Integral)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "RealName", DbType.String, model.RealName); db.AddInParameter(dbCommand, "Sex", DbType.Int16, model.Sex); db.AddInParameter(dbCommand, "Email", DbType.AnsiString, model.Email); db.AddInParameter(dbCommand, "PassWord", DbType.AnsiString, model.PassWord); db.AddInParameter(dbCommand, "Status", DbType.Int16, model.Status); db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "OpenId", DbType.AnsiString, model.OpenId); db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile); db.AddInParameter(dbCommand, "Age", DbType.Int32, model.Age); db.AddInParameter(dbCommand, "Addr", DbType.String, model.Addr); db.AddInParameter(dbCommand, "Descri", DbType.String, model.Descri); db.AddInParameter(dbCommand, "Integral", DbType.Decimal, model.Integral); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.UserAccount DataRowToModel(DataRow row) { Model.UserAccount model=new Model.UserAccount(); if (row != null) { if(row["UID"]!=null && row["UID"].ToString()!="") { model.UID=Convert.ToInt64(row["UID"].ToString()); } if(row["RealName"]!=null) { model.RealName=row["RealName"].ToString(); } if(row["Sex"]!=null && row["Sex"].ToString()!="") { model.Sex=Convert.ToInt32(row["Sex"].ToString()); } if(row["Email"]!=null) { model.Email=row["Email"].ToString(); } if(row["PassWord"]!=null) { model.PassWord=row["PassWord"].ToString(); } if(row["Status"]!=null && row["Status"].ToString()!="") { model.Status=Convert.ToInt32(row["Status"].ToString()); } if(row["CreateDate"]!=null && row["CreateDate"].ToString()!="") { model.CreateDate=Convert.ToDateTime(row["CreateDate"].ToString()); } if(row["OpenId"]!=null) { model.OpenId=row["OpenId"].ToString(); } if(row["Mobile"]!=null) { model.Mobile=row["Mobile"].ToString(); } if(row["Age"]!=null && row["Age"].ToString()!="") { model.Age=Convert.ToInt32(row["Age"].ToString()); } if(row["Addr"]!=null) { model.Addr=row["Addr"].ToString(); } if(row["Descri"]!=null) { model.Descri=row["Descri"].ToString(); } if(row["Integral"]!=null && row["Integral"].ToString()!="") { model.Integral=Convert.ToDecimal(row["Integral"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.UserAccount DataRowToModel(DataRow row) { Model.UserAccount model = new Model.UserAccount(); if (row != null) { if (row["UID"] != null && row["UID"].ToString() != "") { model.UID = Convert.ToInt64(row["UID"].ToString()); } if (row["RealName"] != null) { model.RealName = row["RealName"].ToString(); } if (row["Sex"] != null && row["Sex"].ToString() != "") { model.Sex = Convert.ToInt32(row["Sex"].ToString()); } if (row["Email"] != null) { model.Email = row["Email"].ToString(); } if (row["PassWord"] != null) { model.PassWord = row["PassWord"].ToString(); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = Convert.ToInt32(row["Status"].ToString()); } if (row["CreateDate"] != null && row["CreateDate"].ToString() != "") { model.CreateDate = Convert.ToDateTime(row["CreateDate"].ToString()); } if (row["OpenId"] != null) { model.OpenId = row["OpenId"].ToString(); } if (row["Mobile"] != null) { model.Mobile = row["Mobile"].ToString(); } if (row["Age"] != null && row["Age"].ToString() != "") { model.Age = Convert.ToInt32(row["Age"].ToString()); } if (row["Addr"] != null) { model.Addr = row["Addr"].ToString(); } if (row["Descri"] != null) { model.Descri = row["Descri"].ToString(); } if (row["Integral"] != null && row["Integral"].ToString() != "") { model.Integral = Convert.ToDecimal(row["Integral"].ToString()); } } return(model); }
async void profile(String name) { string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Chattydata.db3"); SQLiteAsyncConnection _database = new SQLiteAsyncConnection(path); Model.UserAccount d1 = await _database.Table <Model.UserAccount>().Where(x => x.Username == name).FirstOrDefaultAsync(); users = d1; }
async public Task <string> AddUser(Model.UserAccount user) { Model.UserAccount d1 = await _database.Table <Model.UserAccount>().Where(x => x.Username == user.Username).FirstOrDefaultAsync(); if (d1 == null) { await _database.InsertAsync(user); return("Successfully Added"); } else { return("The username already exist"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.UserAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update UserAccount set "); strSql.Append("RealName=@RealName,"); strSql.Append("Sex=@Sex,"); strSql.Append("Email=@Email,"); strSql.Append("PassWord=@PassWord,"); strSql.Append("Status=@Status,"); strSql.Append("CreateDate=@CreateDate,"); strSql.Append("OpenId=@OpenId,"); strSql.Append("Mobile=@Mobile,"); strSql.Append("Age=@Age,"); strSql.Append("Addr=@Addr,"); strSql.Append("Descri=@Descri,"); strSql.Append("Integral=@Integral"); strSql.Append(" where UID=@UID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UID", DbType.Int64, model.UID); db.AddInParameter(dbCommand, "RealName", DbType.String, model.RealName); db.AddInParameter(dbCommand, "Sex", DbType.Int16, model.Sex); db.AddInParameter(dbCommand, "Email", DbType.AnsiString, model.Email); db.AddInParameter(dbCommand, "PassWord", DbType.AnsiString, model.PassWord); db.AddInParameter(dbCommand, "Status", DbType.Int16, model.Status); db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "OpenId", DbType.AnsiString, model.OpenId); db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile); db.AddInParameter(dbCommand, "Age", DbType.Int32, model.Age); db.AddInParameter(dbCommand, "Addr", DbType.String, model.Addr); db.AddInParameter(dbCommand, "Descri", DbType.String, model.Descri); db.AddInParameter(dbCommand, "Integral", DbType.Decimal, model.Integral); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.UserAccount ReaderBind(IDataReader dataReader) { Model.UserAccount model = new Model.UserAccount(); object ojb; ojb = dataReader["UID"]; if (ojb != null && ojb != DBNull.Value) { model.UID = Convert.ToInt64(ojb); } model.RealName = dataReader["RealName"].ToString(); ojb = dataReader["Sex"]; if (ojb != null && ojb != DBNull.Value) { model.Sex = Convert.ToInt32(ojb); } model.Email = dataReader["Email"].ToString(); model.PassWord = dataReader["PassWord"].ToString(); ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = Convert.ToInt32(ojb); } ojb = dataReader["CreateDate"]; if (ojb != null && ojb != DBNull.Value) { model.CreateDate = Convert.ToDateTime(ojb); } model.OpenId = dataReader["OpenId"].ToString(); model.Mobile = dataReader["Mobile"].ToString(); ojb = dataReader["Age"]; if (ojb != null && ojb != DBNull.Value) { model.Age = Convert.ToInt32(ojb); } model.Addr = dataReader["Addr"].ToString(); model.Descri = dataReader["Descri"].ToString(); ojb = dataReader["Integral"]; if (ojb != null && ojb != DBNull.Value) { model.Integral = Convert.ToDecimal(ojb); } return(model); }
/// <summary> /// 根据手机号(用户名)得到一个对象实体 /// </summary> public Model.UserAccount GetModelforMobile(string Mobile) { StringBuilder strSql = new StringBuilder(); strSql.Append("select UID,RealName,Email,PassWord,Status,CreateDate,OpenId,Mobile from UserAccount "); strSql.Append(" where Mobile=@Mobile "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "Mobile", DbType.String, Mobile); Model.UserAccount model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.UserAccount GetModel(long UID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select UID,RealName,Sex,Email,PassWord,Status,CreateDate,OpenId,Mobile,Age,Addr,Descri,Integral from UserAccount "); strSql.Append(" where UID=@UID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UID", DbType.Int64, UID); Model.UserAccount model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
async void AddFriend(object sender, System.EventArgs e) { if (!string.IsNullOrEmpty(friendid)) { Console.WriteLine("testing 0 " + friendid); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Chattydata.db3"); SQLiteAsyncConnection _database = new SQLiteAsyncConnection(path); Model.UserAccount d1 = await _database.Table <Model.UserAccount>().Where(x => x.ID == friendid).FirstOrDefaultAsync(); Model.FriendAccount d2 = await _database.Table <Model.FriendAccount>().Where(x => (x.Username == users.Username && x.FriendUsername == d1.Username) || (x.Username == d1.Username && x.FriendUsername == users.Username)).FirstOrDefaultAsync(); Model.FriendID d3 = await _database.Table <Model.FriendID>().Where(x => x.ID == "1").FirstOrDefaultAsync(); if (d2 == null) { List <Model.FriendAccount> usercnt = await _database.Table <Model.FriendAccount>().ToListAsync(); int id = Convert.ToInt32(d3.FriendlistID); id = id + 1; friend.ID = id.ToString(); friend.Username = users.Username; friend.FriendUsername = d1.Username; d3.FriendlistID = id.ToString(); await App.MyDatabase.SaveFriendIDInfo(d3); await App.MyDatabase.SaveFriendInfo(friend); await DisplayAlert("Successful", "Add friend successfully", "OK"); } else { await DisplayAlert("Fail", "he/she is your friend", "OK"); } } else { await DisplayAlert("Add Friend", "Please select a friend", "OK"); } }
public ProfilePage(Model.UserAccount user) { InitializeComponent(); Showuser(user.Username); }
public SearchFriendPage(Model.UserAccount user) { InitializeComponent(); Showuser(user.Username); }
public FriendListPage(Model.UserAccount username) { InitializeComponent(); Showfriend(username.Username); }
public Task <List <Model.FriendAccount> > FriendList(Model.UserAccount user) { return(_database.Table <Model.FriendAccount>().Where(x => x.Username == user.Username || x.FriendUsername == user.Username).ToListAsync()); }
//when this method invoked, it pass useraccount object and write info object data to database public async Task SaveInfo(Model.UserAccount info) { await _database.InsertAsync(info); }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.UserAccount ReaderBind(IDataReader dataReader) { Model.UserAccount model=new Model.UserAccount(); object ojb; ojb = dataReader["UID"]; if(ojb != null && ojb != DBNull.Value) { model.UID=Convert.ToInt64(ojb); } model.RealName=dataReader["RealName"].ToString(); ojb = dataReader["Sex"]; if(ojb != null && ojb != DBNull.Value) { model.Sex=Convert.ToInt32(ojb); } model.Email=dataReader["Email"].ToString(); model.PassWord=dataReader["PassWord"].ToString(); ojb = dataReader["Status"]; if(ojb != null && ojb != DBNull.Value) { model.Status=Convert.ToInt32(ojb); } ojb = dataReader["CreateDate"]; if(ojb != null && ojb != DBNull.Value) { model.CreateDate=Convert.ToDateTime(ojb); } model.OpenId=dataReader["OpenId"].ToString(); model.Mobile=dataReader["Mobile"].ToString(); ojb = dataReader["Age"]; if(ojb != null && ojb != DBNull.Value) { model.Age=Convert.ToInt32(ojb); } model.Addr=dataReader["Addr"].ToString(); model.Descri=dataReader["Descri"].ToString(); ojb = dataReader["Integral"]; if(ojb != null && ojb != DBNull.Value) { model.Integral=Convert.ToDecimal(ojb); } return model; }