public void DeleteAccount(IList<string> idList) { foreach (var id in idList) { Site acc = new Site(); acc["Id"] = id; this._access.Delete(acc); } }
public void UpdateAccount(Site acc) { this._access.Update(acc); }
public string InsertAccount(Site acc) { return this._access.Insert(acc); }
private void Grid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { var name = this.dgvLevel0.Columns[e.ColumnIndex].DataPropertyName; var row = this.DataSource.Rows[e.RowIndex]; Site acc = new Site(); acc[name] = row[name].ToString(); if (row["Id"] == null || string.IsNullOrEmpty(row["Id"].ToString())) { row["Id"] = this._biz.InsertAccount(acc); } else { acc["Id"] = row["id"].ToString(); this._biz.UpdateAccount(acc); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IList<Group> Load() { IList<Group> ret = new List<Group>(); using (SQLiteCommand cmd = new SQLiteCommand(this._con)) { cmd.CommandText = "Select g.rowid, g.Id as GroupId, g.GroupName, s.Id as SiteId, s.SiteName, u.Id as UrlId, u.UrlString, a.Id as AccId, a.UserName, a.Password from Group g left join Site s on g.Id = s.GroupId left join Url u on s.Id = u.SiteId left join Accout a on s.Id = a.SiteId order by g.rowid, s.SiteName"; #region test //DataTable dat = new DataTable(); //SQLiteDataAdapter ada = new SQLiteDataAdapter(cmd); //var cnt = ada.Fill(dat); #endregion var dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { var grpId = dataReader["GroupId"].ToString(); var grp = (from loop in ret where loop.Id == grpId select loop).FirstOrDefault(); if (grp == null) { grp = new Group(grpId, dataReader["GroupName"].ToString()); ret.Add(grp); } var siteId = dataReader["SiteId"].ToString(); var site = (from loop in grp.SiteList where loop.Id == siteId select loop).FirstOrDefault(); if (site == null) { site = new Site(siteId, dataReader["SiteName"].ToString()); grp.SiteList.Add(site); } if (dataReader["UrlId"] != null && dataReader["UrlId"] != DBNull.Value && !string.IsNullOrEmpty(dataReader["UrlId"].ToString())) { var urlId = dataReader["UrlId"].ToString(); var url = (from loop in site.UrlList where loop.Id == urlId select loop).FirstOrDefault(); if (url == null) { url = new Url(urlId, dataReader["UrlString"].ToString()); site.UrlList.Add(url); } } if (dataReader["AccId"] != null && dataReader["AccId"] != DBNull.Value && !string.IsNullOrEmpty(dataReader["AccId"].ToString())) { var accId = dataReader["AccId"].ToString(); var acc = (from loop in site.AccountList where loop.Id == accId select loop).FirstOrDefault(); if (acc == null) { acc = new Account(accId, dataReader["UserName"].ToString(), dataReader["Password"].ToString()); site.AccountList.Add(acc); } } } } return ret; }