private void Save(Model_GroupDetails group_details) { string sql = "INSERT INTO Groups(groupid, group_name) VALUES((select count(Groups.groupid) from groups) + 1, @gname);"; SQLiteParameter[] parameters = { new SQLiteParameter("@gname", group_details.GroupName) }; string result = base.ExecuteNonQuery(sql, parameters); if (result == string.Empty) { } else { base.Database.CloseConnection(); System.Diagnostics.Debug.WriteLine(result); if (result.Contains("Abort due to constraint violation")) { throw new DatabaseException(DatabaseException.ExceptionTypes.DUPLICATE_ENTRY); } else { throw new Exception(result); } } base.Database.CloseConnection(); }
private void Update(Model_GroupDetails group_details) { string sql = "UPDATE Groups SET groupid = @gid, group_name = @gname WHERE groupid = @gid"; SQLiteParameter[] parameters = { new SQLiteParameter("@gid", group_details.GroupID), new SQLiteParameter("@gname", group_details.GroupName) }; string result = base.ExecuteNonQuery(sql, parameters); if (result == string.Empty) { } else { base.Database.CloseConnection(); System.Diagnostics.Debug.WriteLine(result); if (result.Contains("Abort due to constraint violation")) { throw new DatabaseException(DatabaseException.ExceptionTypes.DUPLICATE_ENTRY); } else { throw new Exception(result); } } base.Database.CloseConnection(); }
public void GetGroupsWithServerCount() { string sql = "select * from viewGroupsWithServerCount"; string result = base.ExecuteQuery(sql, null); if (result == string.Empty) { if (base.Database.Reader.HasRows) { this.ArrayListGroups.Clear(); while (base.Database.Reader.Read()) { Model_GroupDetails gd = new Model_GroupDetails(); gd.GroupID = int.Parse(base.Database.Reader["groupid"].ToString()); gd.GroupName = base.Database.Reader["group_name"].ToString(); gd.ServerCount = int.Parse(base.Database.Reader["ServerCount"].ToString()); this.ArrayListGroups.Add(gd); } } } else { base.Database.CloseConnection(); throw new Exception(result); } base.Database.CloseConnection(); }
public void Read() { string sql = "SELECT groupid, group_name FROM Groups"; string result = base.ExecuteQuery(sql, null); this.ArrayListGroups.Clear(); if (result == string.Empty) { while (base.Database.Reader.Read()) { Model_GroupDetails gd = new Model_GroupDetails(); gd.GroupID = int.Parse(base.Database.Reader["groupid"].ToString()); gd.GroupName = base.Database.Reader["group_name"].ToString(); this.ArrayListGroups.Add(gd); } } else { base.Database.CloseConnection(); System.Diagnostics.Debug.WriteLine(result); throw new Exception(result); } base.Database.CloseConnection(); }
void btnCreate_Click(object sender, EventArgs e) { string group_name = CreateForm(string.Empty); if (group_name == null) { return; } Model_GroupDetails gd = new Model_GroupDetails(); gd.GroupName = group_name; try { GlobalHelper.dbGroups.Save(true, gd); } catch (Database.DatabaseException ex) { if (ex.ExceptionType == Database.DatabaseException.ExceptionTypes.DUPLICATE_ENTRY) { MessageBox.Show("A group by that name is already exist. Please give a different name.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show("Unable to save the group due to error.\r\n\r\nError Message: " + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } // let's just repopulate for a while PopulateListView(lvGroups); }
public void Save(bool isNew, Model_GroupDetails group_details) { if (isNew) { Save(group_details); } else { Update(group_details); } }
void btnUpdate_Click(object sender, EventArgs e) { string group_name = CreateForm(string.Empty); if (group_name == null) { return; } int groupid = int.Parse(lvGroups.SelectedItems[0].Tag.ToString()); Model_GroupDetails gd = new Model_GroupDetails(); gd.GroupID = groupid; gd.GroupName = group_name; GlobalHelper.dbGroups.Save(false, gd); // let's just repopulate for a while PopulateListView(lvGroups); }