public void Delete(SQLiteDatabase db) { // delete users db.ExecuteNonQuery("DELETE FROM ProjectUser WHERE ProjectID=" + Id); // delete project db.ExecuteNonQuery("DELETE FROM Project WHERE ID=" + Id); }
public void Insert(SQLiteDatabase db) { if (Id != 0) { throw new Exception("Already inserted"); } String sql = "INSERT INTO ProjectUser (ProjectID, Login, Notified) VALUES ('" + ProjectId + "', '" + Login + "', 0); SELECT last_insert_rowid()"; Id = Int16.Parse(db.ExecuteScalar(sql)); }
/// <summary> /// Collect users from the current page in browser /// </summary> private void TakePeople() { stText.Text = "Reading users"; SQLiteDatabase db = new SQLiteDatabase(); // take people HtmlElementCollection tdlist = browser.Document.GetElementsByTagName("td"); foreach (HtmlElement td in tdlist) { if (td.GetAttribute("className").Equals("cf-user")) { // there is a user login in the first image HtmlElement img = td.GetElementsByTagName("img")[0]; String login = img.GetAttribute("alt"); bool found = false; try { users.First(user => user.Login.Equals(login)); found = true; } catch { } if (!found) { ProjectUser user = new ProjectUser(); user.ProjectId = activeProject.Id; user.Login = login; // insert into db user.Insert(db); // add to list users.Add(user); } } } // check 'Next page' HtmlElement a = browser.Document.GetElementById("PrevLink"); if (a != null) { a.InvokeMember("Click"); return; } // No more users ResetParser(); MessageBox.Show("Done"); }
public void ChangeNotificationStatus(SQLiteDatabase db) { int n = Notified ? 1 : 0; String sql = "UPDATE ProjectUser SET Notified=" + n + " where ID=" + Id; db.ExecuteNonQuery(sql); }
/// <summary> /// Stores the Project into database. Returns true if the project is new. /// </summary> /// <param name="db"></param> /// <returns></returns> public bool Store(SQLiteDatabase db) { // make the texts safe String t = Title.Replace("'", "''"); String m = Message.Replace("'", "''"); String a = Attachment == null ? "" : Attachment.Replace("'", "''"); if (id == 0) { // insert String sql = "INSERT INTO Project (Title, Message, Attachment) VALUES ('" + t + "', '" + m + "', '" + a + "'); SELECT last_insert_rowid()"; Id = Int16.Parse(db.ExecuteScalar(sql)); return true; } else { // update String sql = "UPDATE Project SET Title='" + t + "', Message='" + m + "', Attachment='" + a + "' WHERE ID=" + Id; db.ExecuteNonQuery(sql); return false; } }