Example #1
0
        private void StoreRow(DataGridViewRow rw)
        {
            inupdate = true;
            CaptainsLogClass entry = rw.Tag as CaptainsLogClass; // may be null

            if (rw.Cells[1].IsNullOrEmpty())                     // we must have system
            {
                rw.Cells[1].Value = "?";
            }

            if (rw.Cells[2].IsNullOrEmpty())    // and body. User can remove these during editing.
            {
                rw.Cells[2].Value = "?";
            }

            string notes = rw.Cells[3].IsNullOrEmpty() ? "" : (string)rw.Cells[3].Value;
            string tags  = rw.Cells[4].Tag != null?string.Join(";", rw.Cells[4].Tag as List <string>) : null;

            CaptainsLogClass cls = GlobalCaptainsLogList.Instance.AddOrUpdate(entry, EDCommander.CurrentCmdrID,
                                                                              rw.Cells[1].Value as string,
                                                                              rw.Cells[2].Value as string,
                                                                              (DateTime)rw.Cells[0].Tag, // tag is UTC
                                                                              notes,
                                                                              tags);

            rw.Tag = cls;

            inupdate = false;
        }
Example #2
0
 void DumpCL(ActionProgramRun ap, string prefix, CaptainsLogClass cl)
 {
     ap[prefix + "Id"]         = cl.ID.ToStringInvariant();
     ap[prefix + "TimeUTC"]    = cl.TimeUTC.ToStringUS();
     ap[prefix + "TimeLocal"]  = cl.TimeLocal.ToStringUS();
     ap[prefix + "SystemName"] = cl.SystemName ?? "";
     ap[prefix + "BodyName"]   = cl.BodyName ?? "";
     ap[prefix + "Note"]       = cl.Note ?? "";
     ap[prefix + "Tags"]       = cl.Tags ?? "";
 }
Example #3
0
 private void LogChanged(CaptainsLogClass bk, bool deleted)
 {
     if (!inupdate)
     {
         if (dataGridView.IsCurrentCellInEditMode)
         {
             dataGridView.EndEdit();
         }
         Display();
     }
 }
Example #4
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            int[] rows = null;

            if (dataGridView.SelectedCells.Count > 0)      // being paranoid
            {
                rows = (from DataGridViewCell x in dataGridView.SelectedCells select x.RowIndex).Distinct().ToArray();
            }

            //System.Diagnostics.Debug.WriteLine("cells {0} rows {1} selrows {2}", dataGridViewBookMarks.SelectedCells.Count, dataGridViewBookMarks.SelectedRows.Count , rows.Length);

            if (rows != null && rows.Length > 1)
            {
                if (ExtendedControls.MessageBoxTheme.Show(FindForm(), string.Format(("Do you really want to delete {0} notes?" + Environment.NewLine + "Confirm or Cancel").Tx(this, "CFN"), rows.Length), "Warning".Tx(), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    foreach (int r in rows)
                    {
                        CaptainsLogClass entry = (CaptainsLogClass)dataGridView.Rows[r].Tag;

                        if (entry != null)
                        {
                            GlobalCaptainsLogList.Instance.Delete(entry);
                        }
                    }
                    Display();
                }
            }
            else if (dataGridView.CurrentCell != null)       // if we have a current cell..
            {
                DataGridViewRow rw = dataGridView.CurrentCell.OwningRow;

                if (rw.Tag != null)
                {
                    CaptainsLogClass entry = (CaptainsLogClass)rw.Tag;

                    if (ExtendedControls.MessageBoxTheme.Show(FindForm(), string.Format(("Do you really want to delete the note for {0}" + Environment.NewLine + "Confirm or Cancel").Tx(this, "CF"), entry.SystemName + ":" + entry.BodyName), "Warning".Tx(), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        GlobalCaptainsLogList.Instance.Delete(entry);
                        Display();
                    }
                }
                else
                {
                    Display();
                }
            }
        }
Example #5
0
        private void StoreRow(DataGridViewRow rw)
        {
            inupdate = true;
            CaptainsLogClass entry = rw.Tag as CaptainsLogClass;        // may be null

            string notes = rw.Cells[3].Value != null ? (string)rw.Cells[3].Value : "";
            string tags  = rw.Cells[4].Tag != null?string.Join(";", rw.Cells[4].Tag as List <string>) : null;

            CaptainsLogClass cls = GlobalCaptainsLogList.Instance.AddOrUpdate(entry, EDCommander.CurrentCmdrID,
                                                                              rw.Cells[1].Value as string,
                                                                              rw.Cells[2].Value as string,
                                                                              (DateTime)rw.Cells[0].Tag, // tag is UTC
                                                                              notes,
                                                                              tags);

            rw.Tag = cls;

            inupdate = false;
        }
Example #6
0
        private void dataGridView_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)         // right click on travel map, get in before the context menu
            {
                rightclickentry = null;
            }

            if (dataGridView.SelectedCells.Count < 2 || dataGridView.SelectedRows.Count == 1)      // if single row completely selected, or 1 cell or less..
            {
                DataGridView.HitTestInfo hti = dataGridView.HitTest(e.X, e.Y);
                if (hti.Type == DataGridViewHitTestType.Cell)
                {
                    dataGridView.ClearSelection();                // select row under cursor.
                    dataGridView.Rows[hti.RowIndex].Selected = true;

                    if (e.Button == MouseButtons.Right)         // right click on travel map, get in before the context menu
                    {
                        rightclickentry = (CaptainsLogClass)dataGridView.Rows[hti.RowIndex].Tag;
                    }
                }
            }
        }
Example #7
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                StringParser sp = new StringParser(res);

                string prefix  = "CL_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                int cmdrid = EDCommander.CurrentCmdrID;

                if (cmdname != null && cmdname.Equals("CMDR", StringComparison.InvariantCultureIgnoreCase))
                {
                    string name = sp.NextQuotedWord() ?? "-----!";

                    EDCommander cmdr = EDCommander.GetCommander(name);

                    if (cmdr != null)
                    {
                        cmdrid = cmdr.Nr;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

                List <CaptainsLogClass> cllist = GlobalCaptainsLogList.Instance.LogEntriesCmdrTimeOrder(cmdrid);

                EDDiscoveryForm discoveryform = (ap.actioncontroller as ActionController).DiscoveryForm;

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        Func <CaptainsLogClass, string, bool> validate = CheckSystemBody;

                        string field = sp.NextQuotedWord() ?? "--";
                        if (field.Equals("Body", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckBody;
                        }
                        else if (field.Equals("System", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckSystem;
                        }
                        else if (field.Equals("Tag", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckTags;
                        }
                        else if (field.Equals("Note", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckNote;
                        }
                        else if (field != "--")
                        {
                            ap.ReportError("Unknown field type to list");
                            return(true);
                        }

                        int count = 1;
                        foreach (CaptainsLogClass cl in cllist)       // only current commander ID considered
                        {
                            if (validate(cl, wildcard))
                            {
                                DumpCL(ap, prefix + count++.ToStringInvariant() + "_", cl);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = cllist.Count.ToStringInvariant();
                    }
                    else if (cmdname.Equals("ADDHERE", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string note    = sp.NextQuotedWord();
                        string taglist = sp.NextQuotedWord();

                        HistoryEntry he = discoveryform.history.GetLast;

                        if (he != null)
                        {       // taglist can be null.. note must be set.
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, he.System.Name, he.WhereAmI, DateTime.UtcNow, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("History has no locations");
                        }
                    }
                    else if (cmdname.Equals("ADD", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string   systemname = sp.NextQuotedWord();
                        string   bodyname   = sp.NextQuotedWord();
                        DateTime?dte        = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                        string   note       = sp.NextQuotedWord();
                        string   taglist    = sp.NextQuotedWord();

                        if (systemname != null && bodyname != null && dte != null)
                        {
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, systemname, bodyname, dte.Value, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("Missing parameters in ADD");
                        }
                    }
                    else if (cmdname.Equals("TAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = EDDConfig.Instance.CaptainsLogTags;
                        ap[prefix + "Tags"] = tags;
                    }
                    else if (cmdname.Equals("SETTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = tags;
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else if (cmdname.Equals("APPENDTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = EDDConfig.Instance.CaptainsLogTags.AppendPrePad(tags, ";");
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else
                    {   // ********************** Iterator forms, FROM/LAST/FIRST/TIME [Forward|Backward]
                        long?cid = -1;

                        if (cmdname.Equals("From", StringComparison.InvariantCultureIgnoreCase))
                        {
                            cid = sp.NextWord().InvariantParseLongNull();

                            if (cid == null)
                            {
                                ap.ReportError("Non integer CID after FROM");
                                return(true);
                            }
                        }
                        else if (cmdname.Equals("First", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0) //prevent crash if cllist is empty
                            {
                                var mintime = cllist.Min(x => x.TimeUTC);
                                cid = cllist.First(x => x.TimeUTC == mintime).ID;
                            }
                        }
                        else if (cmdname.Equals("Last", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0)
                            {
                                var maxtime = cllist.Max(x => x.TimeUTC);
                                cid = cllist.Last(x => x.TimeUTC == maxtime).ID;
                            }
                        }
                        else if (cmdname.Equals("Time", StringComparison.InvariantCultureIgnoreCase))
                        {
                            DateTime?dte = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                            if (dte != null)
                            {
                                if (cllist.Count > 0)
                                {
                                    var firstafter = cllist.FirstOrDefault(x => x.TimeUTC >= dte);

                                    if (firstafter != null)
                                    {
                                        cid = firstafter.ID;
                                    }
                                }
                            }
                            else
                            {
                                ap.ReportError("Missing US date from Time");
                                return(true);
                            }
                        }
                        else
                        {
                            ap.ReportError("Unknown command");
                            return(true);
                        }

                        int indexof = cllist.FindIndex(x => x.ID == cid);   // -1 if not found..

                        string nextcmd = sp.NextWord();

                        if (nextcmd != null)
                        {
                            if (nextcmd.Equals("FORWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (indexof >= 0)   // don't ruin -1 if set
                                {
                                    indexof++;
                                }

                                nextcmd = sp.NextWord();
                            }
                            else if (nextcmd.Equals("BACKWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                indexof--;      // if -1, its okay to make it -2.

                                nextcmd = sp.NextWord();
                            }
                        }

                        bool validindex = indexof >= 0 && indexof < cllist.Count;

                        if (nextcmd != null)
                        {
                            if (!validindex)     // these must have a valid target..
                            {
                                ap.ReportError("Entry is not found");
                            }
                            else
                            {
                                CaptainsLogClass cl = cllist[indexof];

                                if (nextcmd.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    GlobalCaptainsLogList.Instance.Delete(cl);
                                }
                                else
                                {
                                    string text = sp.NextQuotedWord();

                                    if (text != null && sp.IsEOL)
                                    {
                                        if (nextcmd.Equals("NOTE", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, cl.BodyName, cl.TimeUTC,
                                                                                       text, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("SYSTEM", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, text, cl.BodyName, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("BODY", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, text, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else
                                        {
                                            ap.ReportError("Unknown command " + nextcmd);
                                        }
                                    }
                                    else
                                    {
                                        ap.ReportError("Missing text or unquoted spaced text after " + nextcmd);
                                    }
                                }
                            }

                            return(true);
                        }


                        if (nextcmd != null)
                        {
                            ap.ReportError("Unknown iterator or command " + nextcmd);
                        }
                        else
                        {       // straight report
                            if (validindex)
                            {
                                DumpCL(ap, prefix, cllist[indexof]);
                            }
                            else
                            {
                                ap[prefix + "Id"] = "-1";
                            }
                        }

                        return(true);
                    }
                }
                else
                {
                    ap.ReportError("Missing command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Example #8
0
 bool CheckTags(CaptainsLogClass cl, string match)
 {
     return(cl.Tags != null && cl.Tags.WildCardMatch(match));
 }
Example #9
0
 bool CheckNote(CaptainsLogClass cl, string match)
 {
     return(cl.Note != null && cl.Note.WildCardMatch(match));
 }
Example #10
0
 bool CheckBody(CaptainsLogClass cl, string match)
 {
     return(cl.BodyName.WildCardMatch(match));
 }
Example #11
0
 bool CheckSystem(CaptainsLogClass cl, string match)
 {
     return(cl.SystemName.WildCardMatch(match));
 }
Example #12
0
        private void extButtonExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View", "All" }, disablestartendtime: true);

            if (frm.ShowDialog(this.FindForm()) == DialogResult.OK)
            {
                BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                grd.SetCSVDelimiter(frm.Comma);

                grd.GetLineHeader += delegate(int c)
                {
                    if (c == 0)
                    {
                        return new string[] { "Time", "System", "Body", "Note", "Tags" }
                    }
                    ;
                    else
                    {
                        return(null);
                    }
                };

                if (frm.SelectedIndex == 1)
                {
                    List <CaptainsLogClass> logs = GlobalCaptainsLogList.Instance.LogEntries;
                    int i = 0;

                    grd.GetLine += delegate(int r)
                    {
                        while (i < logs.Count)
                        {
                            CaptainsLogClass ent = logs[i++];
                            if (ent.Commander == EDCommander.CurrentCmdrID)
                            {
                                return(new object[] { EDDConfig.Instance.ConvertTimeToSelectedFromUTC(ent.TimeUTC),
                                                      ent.SystemName, ent.BodyName, ent.Note, ent.Tags });
                            }
                        }

                        return(null);
                    };
                }
                else
                {
                    grd.GetLine += delegate(int r)
                    {
                        if (r < dataGridView.RowCount)
                        {
                            DataGridViewRow  rw  = dataGridView.Rows[r];
                            CaptainsLogClass ent = rw.Tag as CaptainsLogClass;
                            return(new Object[] { rw.Cells[0].Value, rw.Cells[1].Value, rw.Cells[2].Value, rw.Cells[3].Value, ent.Tags });
                        }

                        return(null);
                    };
                }

                grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm());
            }
        }
Example #13
0
 private void dataGridView_MouseDown(object sender, MouseEventArgs e)
 {
     rightclickentry = dataGridView.RightClickRowValid ? (CaptainsLogClass)dataGridView.Rows[dataGridView.RightClickRow].Tag : null;
 }
Example #14
0
 private void dataGridView_MouseDown(object sender, MouseEventArgs e)
 {
     dataGridView.HandleClickOnDataGrid(e, out int unusedleftclickrow, out int rightclickrow);
     rightclickentry = (rightclickrow != -1) ? (CaptainsLogClass)dataGridView.Rows[rightclickrow].Tag : null;
 }
 bool CheckSystemBody(CaptainsLogClass cl, string match)
 {
     return(cl.SystemName.WildCardMatch(match, true) || cl.BodyName.WildCardMatch(match, true));
 }