/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ctxMenuAcknowledgmentClear_Click(object sender, EventArgs e) { if (listEvents.SelectedObjects.Count == 0) { return; } var list = listEvents.SelectedObjects.Cast <Event>().ToList(); (new Thread(() => { SetProcessingStatus(false); using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { foreach (Event temp in list) { if (temp.AcknowledgmentId == 0) { continue; } Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Id = temp.AcknowledgmentId; var ack = db.SingleById <Acknowledgment>(acknowledgment.Id); db.Delete(ack); } } SetProcessingStatus(true); LoadSearch(_currentPage); })).Start(); }
public int Delete <T>(int id) { using (NPoco.IDatabase dbContext = new NPoco.Database(connectionString, NPoco.DatabaseType.SqlServer2012)) { var obj = dbContext.SingleById <T>(id); return(dbContext.Delete <T>(obj)); } }
/// <summary> /// Deletes a <c>CompanyDto</c> object. /// </summary> /// <param name="company">A <c>Comapny</c>. This will be translated to a <c>ComapnyDto</c> before the update operation.</param> /// <returns><c>int</c> denoting the success value of the operation.</returns> public int Remove(Company company) { int res; using (var conn = new NpgsqlConnection(dbAccess.connectionString)) { using (var db = new NPoco.Database(conn)) { db.Connection.Open(); res = db.Delete(CompanyDto.Translate(company)); db.Connection.Close(); } } return(res); }
/// <summary> /// /// </summary> private void Process() { AcknowledgmentClass acknowledgmentClass = (AcknowledgmentClass)cboClassification.Items[cboClassification.SelectedIndex]; string initials = txtInitials.Text.ToUpper(); string notes = txtNotes.Text; bool successful = chkSuccessful.Checked; btnOk.Enabled = false; btnCancel.Enabled = false; (new Thread(() => { try { bool acknowledgedPrevious = false; bool errors = false; using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { db.BeginTransaction(); foreach (Event temp in _events) { try { bool insert = true; var ack = db.Fetch<Acknowledgment>("select * from acknowledgment where cid=@0 and sid=@1", new object[] { temp.Cid, temp.Sid }); if (ack.Count() > 0) { if (ack.First().Initials.ToUpper() != initials) { acknowledgedPrevious = true; insert = false; } else { db.Delete(ack.First()); } } if (insert == true) { Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Cid = temp.Cid; acknowledgment.Sid = temp.Sid; acknowledgment.Initials = initials; acknowledgment.Notes = notes; acknowledgment.Class = acknowledgmentClass.Id; acknowledgment.Successful = successful; acknowledgment.Timestamp = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.Insert(acknowledgment); } } catch (Exception ex) { db.AbortTransaction(); errors = true; IO.WriteTextToFile("Acknowledgement Insert Error (" + DateTime.Now + "): " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); break; } } if (errors == false) { db.CompleteTransaction(); } } if (acknowledgedPrevious == true) { UserInterface.DisplayMessageBox(this, "Some events were not classified due to being already classified", MessageBoxIcon.Exclamation); } if (errors == true) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); } } catch (Exception ex) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); IO.WriteTextToFile("Acknowledgement Insert Error (" + DateTime.Now + "): " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); } finally { this.DialogResult = DialogResult.OK; } })).Start(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ctxMenuAcknowledgmentClear_Click(object sender, EventArgs e) { if (listEvents.SelectedObjects.Count == 0) { return; } var list = listEvents.SelectedObjects.Cast<Event>().ToList(); (new Thread(() => { SetProcessingStatus(false); using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { foreach (Event temp in list) { if (temp.AcknowledgmentId == 0) { continue; } Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Id = temp.AcknowledgmentId; var ack = db.SingleById<Acknowledgment>(acknowledgment.Id); db.Delete(ack); } } SetProcessingStatus(true); LoadRuleEvents(_currentPage); })).Start(); }
/// <summary> /// /// </summary> /// <param name="acknowledgementClass"></param> private void SetAcknowledgement(string ackClass) { var events = listEvents.SelectedObjects.Cast<Event>().ToList(); if (cboRule.SelectedIndex == -1) { return; } Signature rule = (Signature)cboRule.Items[cboRule.SelectedIndex]; var acknowledgementClass = (from a in _acknowledgmentClasses where a.Desc.ToLower() == ackClass.ToLower() select a).SingleOrDefault(); if (acknowledgementClass == null) { UserInterface.DisplayMessageBox(this, "Cannot locate acknowledgement class", MessageBoxIcon.Exclamation); return; } (new Thread(() => { try { bool errors = false; bool acknowledgedPrevious = false; using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { db.BeginTransaction(); foreach (Event temp in events) { try { bool insert = true; var ack = db.Fetch<Acknowledgment>("select * from acknowledgment where cid=@0 and sid=@1", new object[] { temp.Cid, temp.Sid }); if (ack.Count() > 0) { if (ack.First().Initials != _initials) { acknowledgedPrevious = true; insert = false; } else { db.Delete(ack.First()); } } if (insert == true) { Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Cid = temp.Cid; acknowledgment.Sid = temp.Sid; acknowledgment.Initials = _initials; acknowledgment.Notes = string.Empty; acknowledgment.Class = acknowledgementClass.Id; acknowledgment.Timestamp = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.Insert(acknowledgment); } } catch (Exception ex) { db.AbortTransaction(); errors = true; IO.WriteTextToFile("Acknowledgement Insert Error: " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); break; } } if (errors == false) { db.CompleteTransaction(); } } if (acknowledgedPrevious == true) { UserInterface.DisplayMessageBox(this, "Some events were not classified due to being already classified", MessageBoxIcon.Exclamation); } if (errors == true) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); } LoadRuleEvents(_currentPage); } catch (Exception ex) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); IO.WriteTextToFile("Acknowledgement Insert Error (" + DateTime.Now + "): " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); } })).Start(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listEvents_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ctxMenuPayload_Click(this, new EventArgs()); } else if (e.KeyCode == Keys.F1) { if (_initials.Length == 0) { UserInterface.DisplayMessageBox(this, "The user initials have not been set. Manually classify event to set", MessageBoxIcon.Information); return; } var events = listEvents.Objects.Cast<Event>().ToList(); (new Thread(() => { SetProcessingStatus(false); bool acknowledgedPrevious = false; using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { foreach (Event temp in events) { bool insert = true; var ack = db.Fetch<Acknowledgment>("select * from acknowledgment where cid=@0 and sid=@1", new object[] { temp.Cid, temp.Sid }); if (ack.Count() > 0) { if (ack.First().Initials != _initials) { acknowledgedPrevious = true; insert = false; } else { db.Delete(ack.First()); } } if (insert == true) { Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Cid = temp.Cid; acknowledgment.Sid = temp.Sid; acknowledgment.Initials = _initials; acknowledgment.Class = 1; db.Insert(acknowledgment); } } } if (acknowledgedPrevious == true) { UserInterface.DisplayMessageBox(this, "Some events were not classified due to being already classified", MessageBoxIcon.Exclamation); } SetProcessingStatus(true); LoadRuleEvents(_currentPage); })).Start(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, System.EventArgs e) { if (listExcludes.SelectedObjects.Count == 0) { return; } if (listExcludes.SelectedObjects.Count == 1) { Exclude exclude = (Exclude)listExcludes.SelectedObjects[0]; DialogResult dialogResult = MessageBox.Show(this, "Are you sure you want to delete the exclude?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == System.Windows.Forms.DialogResult.No) { return; } try { using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { Exclude temp = db.SingleOrDefaultById<Exclude>(exclude.Id); if (temp == null) { UserInterface.DisplayMessageBox(this, "Unable to locate exclude", MessageBoxIcon.Exclamation); return; } int ret = db.Delete(temp); if (ret != 1) { UserInterface.DisplayErrorMessageBox(this, "The exclude could not be deleted"); return; } } LoadExcludes(); } catch (Exception ex) { UserInterface.DisplayErrorMessageBox("An error occurred whilst deleting the exclude" + ex.Message); } } else { int count = listExcludes.SelectedObjects.Count; DialogResult dialogResult = MessageBox.Show(this, "Are you sure you want to delete all " + count + " excludes?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == System.Windows.Forms.DialogResult.No) { return; } try { using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { foreach (var item in listExcludes.SelectedObjects) { Exclude exclude = (Exclude)item; Exclude temp = db.SingleOrDefaultById<Exclude>(exclude.Id); if (temp == null) { UserInterface.DisplayMessageBox(this, "Unable to locate exclude", MessageBoxIcon.Exclamation); return; } int ret = db.Delete(temp); if (ret != 1) { UserInterface.DisplayErrorMessageBox(this, "The exclude could not be deleted: " + Environment.NewLine + exclude.ToString()); continue; } } } LoadExcludes(); } catch (Exception ex) { UserInterface.DisplayErrorMessageBox("An error occurred whilst deleting the exclude" + ex.Message); } } }
public int Delete <T>([JetBrains.Annotations.NotNull] T obj) { lock (Dblock) { return(_database.Delete <T>(obj)); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, System.EventArgs e) { if (listExcludes.SelectedObjects.Count == 0) { return; } if (listExcludes.SelectedObjects.Count == 1) { Exclude exclude = (Exclude)listExcludes.SelectedObjects[0]; DialogResult dialogResult = MessageBox.Show(this, "Are you sure you want to delete the exclude?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == System.Windows.Forms.DialogResult.No) { return; } try { using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { Exclude temp = db.SingleOrDefaultById <Exclude>(exclude.Id); if (temp == null) { UserInterface.DisplayMessageBox(this, "Unable to locate exclude", MessageBoxIcon.Exclamation); return; } int ret = db.Delete(temp); if (ret != 1) { UserInterface.DisplayErrorMessageBox(this, "The exclude could not be deleted"); return; } } LoadExcludes(); } catch (Exception ex) { UserInterface.DisplayErrorMessageBox("An error occurred whilst deleting the exclude" + ex.Message); } } else { int count = listExcludes.SelectedObjects.Count; DialogResult dialogResult = MessageBox.Show(this, "Are you sure you want to delete all " + count + " excludes?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == System.Windows.Forms.DialogResult.No) { return; } try { using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { foreach (var item in listExcludes.SelectedObjects) { Exclude exclude = (Exclude)item; Exclude temp = db.SingleOrDefaultById <Exclude>(exclude.Id); if (temp == null) { UserInterface.DisplayMessageBox(this, "Unable to locate exclude", MessageBoxIcon.Exclamation); return; } int ret = db.Delete(temp); if (ret != 1) { UserInterface.DisplayErrorMessageBox(this, "The exclude could not be deleted: " + Environment.NewLine + exclude.ToString()); continue; } } } LoadExcludes(); } catch (Exception ex) { UserInterface.DisplayErrorMessageBox("An error occurred whilst deleting the exclude" + ex.Message); } } }
/// <summary> /// /// </summary> private void Process() { AcknowledgmentClass acknowledgmentClass = (AcknowledgmentClass)cboClassification.Items[cboClassification.SelectedIndex]; string initials = txtInitials.Text.ToUpper(); string notes = txtNotes.Text; bool successful = chkSuccessful.Checked; btnOk.Enabled = false; btnCancel.Enabled = false; (new Thread(() => { try { bool acknowledgedPrevious = false; bool errors = false; using (new HourGlass(this)) using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection())) { db.BeginTransaction(); foreach (Event temp in _events) { try { bool insert = true; var ack = db.Fetch <Acknowledgment>("select * from acknowledgment where cid=@0 and sid=@1", new object[] { temp.Cid, temp.Sid }); if (ack.Count() > 0) { if (ack.First().Initials.ToUpper() != initials) { acknowledgedPrevious = true; insert = false; } else { db.Delete(ack.First()); } } if (insert == true) { Acknowledgment acknowledgment = new Acknowledgment(); acknowledgment.Cid = temp.Cid; acknowledgment.Sid = temp.Sid; acknowledgment.Initials = initials; acknowledgment.Notes = notes; acknowledgment.Class = acknowledgmentClass.Id; acknowledgment.Successful = successful; acknowledgment.Timestamp = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.Insert(acknowledgment); } } catch (Exception ex) { db.AbortTransaction(); errors = true; IO.WriteTextToFile("Acknowledgement Insert Error (" + DateTime.Now + "): " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); break; } } if (errors == false) { db.CompleteTransaction(); } } if (acknowledgedPrevious == true) { UserInterface.DisplayMessageBox(this, "Some events were not classified due to being already classified", MessageBoxIcon.Exclamation); } if (errors == true) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); } } catch (Exception ex) { UserInterface.DisplayMessageBox(this, "Errors occured, check the Errors.txt file", MessageBoxIcon.Exclamation); IO.WriteTextToFile("Acknowledgement Insert Error (" + DateTime.Now + "): " + ex.ToString() + Environment.NewLine, System.IO.Path.Combine(Misc.GetUserDataDirectory(), "Errors.txt"), true); } finally { this.DialogResult = DialogResult.OK; } })).Start(); }