예제 #1
0
 public void StoreShapeFileItems(List <ShapefileItem> items)
 {
     lock (this)
     {
         if (_dbcon != null)
         {
             using (var db = new NPoco.Database(_dbcon.Connection, NPoco.DatabaseType.SQLite))
             {
                 db.BeginTransaction();
                 try
                 {
                     db.Execute("delete from ShapeFileItemV2");
                     foreach (var s in items)
                     {
                         db.Insert("ShapeFileItemV2", null, s);
                     }
                     db.CompleteTransaction();
                 }
                 catch
                 {
                     db.AbortTransaction();
                 }
             }
         }
     }
 }
예제 #2
0
        /// <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();
        }
예제 #3
0
        /// <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();
        }
예제 #4
0
        /// <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();
        }