/// <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="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 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="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(); } }