Beispiel #1
0
        /// <summary>
        /// Gets the link. Returns it in the format
        /// ParentLayout.ChildNote
        /// </summary>
        /// <returns>
        /// The link.
        /// </returns>
        protected virtual string GetLink()
        {
            string stringResult = Constants.BLANK;

            // The link Table will be null if we are using the FindNote functions, in which case we ignore this though log it in case its an error
            if (Layout.GetLinkTable() != null)
            {
                LinkTableRecord result = Array.Find(Layout.GetLinkTable().GetRecords(),
                                                    LinkTableRecord => LinkTableRecord.sExtra == String.Format(CoreUtilities.Links.LinkTableRecord.PageLinkFormatString,
                                                                                                               Layout.GUID, this.GuidForNote));
                stringResult = Constants.BLANK;

                if (result != null)
                {
                    lg.Instance.Line("NoteDataXML_LinkNote->GetLink", ProblemType.MESSAGE, result.sFileName);
                    stringResult = result.sFileName;
                }
                else
                {
                    lg.Instance.Line("NoteDataXML_LinkNote->GetLink", ProblemType.WARNING, "No  file defined");
                }
            }
            else
            {
                lg.Instance.Line("NoteDataXML_LinkNote->GetLInk", ProblemType.WARNING, "Possible error in GetLink, the LinkTable was null though that is OKAY if called during a FindNote search");
            }
            return(stringResult);           //@"C:\Users\Public\Pictures\PhotoStage\001.jpg";
        }
        /// <summary>
        /// Uses the data stored in the linktable record to fill in a NEW ROW in a datatable
        /// </summary>
        /// <param name="record"></param>
        public LinkTableRecord Add(LinkTableRecord record)
        {
            if (null == Table)
            {
                throw new Exception("Your data in StickyLinkTable is null. That would be bad.");

            }

            /*
            record.sText = sTitle;
            // Jan 2010: If you ahve a title of text%link the link will be the preview used
            record.sFileName = sLinkURL;
            record.sSource = sSource;
            record.nBookmarkKey = nType;
            //record.sExtra is USED FOR GROUPS, we cannot use it
            record.linkType = LinkType.FILE;  // FILE = Stretch POPUP = Center
            */

            /* Table.Rows.Add(new object[6] {
                record.sText,
                record.sFileName,
                record.sSource,
                record.nBookmarkKey,
                record.sExtra,
                record.linkType.ToString()

            });*/
            DataRow row = BuildRow(record);
            Table.Rows.Add(row);
            record.sKey = row[KEY].ToString();
            return record;
        }
Beispiel #3
0
        // sFile comes in the format of parent.child
        public virtual void SetLink(string file)
        {
            //the sExtra needs to be in Parent.Child form for the REciprocal links to work later

            LinkTableRecord result = Array.Find(Layout.GetLinkTable().GetRecords(), LinkTableRecord => LinkTableRecord.sExtra == String.Format(CoreUtilities.Links.LinkTableRecord.PageLinkFormatString, Layout.GUID, this.GuidForNote));

            //string file = String.Format (CoreUtilities.Links.LinkTableRecord.PageLinkFormatString, LayoutGuid, ChildGuid);


            // August 2013 -- moved this out of the results==null routine BEACAUSE we need this to be updated when
            //editing a link too! Not just on the initial creation
            string newCaption = Constants.BLANK;

            // may 2013 - if we have a * it means we have a caption encoded at end of string and this neesd to be removed.
            if (file.IndexOf("*") > -1)
            {
                string[] details = file.Split(new char[1] {
                    '*'
                });
                if (details != null && details.Length == 2)
                {
                    file         = details[0];
                    newCaption   = details[1];
                    this.Caption = newCaption;
                }
            }

            if (result == null)
            {
                // add new
                result = new LinkTableRecord();


                result.sFileName = file;


                string SourceContainerGUIDToUse = Layout.GUID;



                result.sExtra = String.Format(CoreUtilities.Links.LinkTableRecord.PageLinkFormatString, SourceContainerGUIDToUse, this.GuidForNote);
                result.sText  = this.Caption;

                Layout.GetLinkTable().Add(result);
            }
            else
            {
                // edit existing
                result.sFileName = file;
                Layout.GetLinkTable().Edit(result);
            }
            this.richBox.Text = Constants.BLANK;
            // force a save else table might not be made correctly
            Layout.SaveLayout();
            Update(Layout);
            BringToFrontAndShow();
        }
        /// <summary>
        /// Finds and returns the row matching, nULL otherwise
        /// Used by Edit and Deelete
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        private DataRow FindRow(LinkTableRecord record)
        {
            DataRow FindThisRow = null;
            /*
            foreach (DataRow row in Table.Rows)
            {
                if (row[TITLE].ToString() == record.sText &&
                    row[LINKID].ToString() == record.sFileName &&
                    row[IDFORTHIS].ToString() == record.sSource &&
                    row[ISPICTURE].ToString() == record.nBookmarkKey.ToString() &&
                    ((row[GROUP].ToString() == record.sExtra) || (row[GROUP].GetType() == typeof(DBNull) && record.sExtra == null)) &&
                    row[LINKTYPE].ToString() == record.linkType.ToString()
                    )
                {
                    FindThisRow = row;
                    break;
                }

            }*/
            FindThisRow = Table.Rows.Find(record.sKey);
            //FindThisRow[GROUP] = "boo!";
            return FindThisRow;
        }
        /// <summary>
        /// takes the row and returns a rowtorecord
        /// used for when getting the data out of the table
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private LinkTableRecord RowToRecord(DataRow row)
        {
            LinkTableRecord record = new LinkTableRecord ();
            try {

                record.sKey = row [KEY].ToString ();
                record.sText = row [TITLE].ToString ();
                record.sFileName = row [LINKID].ToString ();
                record.sSource = row [IDFORTHIS].ToString ();
                int isPicture = 0;
                Int32.TryParse (row [ISPICTURE].ToString (), out isPicture);

                record.nBookmarkKey = isPicture;
                record.sExtra = row [GROUP].ToString ();
                record.linkType = (LinkType)Enum.Parse (typeof(LinkType), row [LINKTYPE].ToString ());
                record.bStatus = (bool)row [FILEEXISTS];
                record.ExtraField = row[EXTRA].ToString();
            } catch (Exception ex) {
                NewMessage.Show (ex.ToString());
            }
            return record;
        }
 /// <summary>
 /// returns an array of LinkITable records, the contents of the datatable
 /// </summary>
 /// <returns></returns>
 public LinkTableRecord[] GetRecords()
 {
     LinkTableRecord[] records = new LinkTableRecord[Table.Rows.Count];
     for (int i = 0; i < Table.Rows.Count; i++)
     {
         records[i] = RowToRecord(Table.Rows[i]);
     }
     return records;
 }
 /// <summary>
 /// Used in an Add or Edit operation.
 /// Build the row and then either add it or replace it
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 private DataRow BuildRow(LinkTableRecord record)
 {
     // we let the DataRow decide on the required KEY
     DataRow row = Table.NewRow();
     row[TITLE] = record.sText;
     row[LINKID] = record.sFileName;
     row[IDFORTHIS] = record.sSource;
     row[ISPICTURE] = record.nBookmarkKey;
     row[GROUP] = record.sExtra;
     row[LINKTYPE] = record.linkType.ToString();
     row[FILEEXISTS] = record.bStatus;
     row [EXTRA] = record.ExtraField;
     return row;
 }
        /// <summary>
        /// Will look for a match for this record in the DataTable and remove
        /// the sucker.
        /// </summary>
        /// <param name="record"></param>
        /// <returns>True if found somethign to delete</returns>
        public bool Delete(LinkTableRecord record)
        {
            if (null == Table)
            {
                throw new Exception("Your data in StickyLinkTable is null. That would be bad.");
            }

            DataRow DeleteThisRow = FindRow(record);

            if (null != DeleteThisRow)
            {
                Table.Rows.Remove(DeleteThisRow);
                return true;
            }
            return false;
        }
        /// <summary>
        /// Finds the current record in the database and updates it with the info in here.
        /// </summary>
        /// <param name="record"></param>
        public void Edit(LinkTableRecord record)
        {
            if (null == Table)
            {
                throw new Exception("Your data in StickyLinkTable is null. That would be bad.");
            }
            DataRow EditRow = Table.Rows.Find(record.sKey);
            if (null != EditRow)
            {

                EditRow[TITLE] = record.sText;
                EditRow[LINKID] = record.sFileName;
                EditRow[IDFORTHIS] = record.sSource;
                EditRow[ISPICTURE] = record.nBookmarkKey;
                EditRow[GROUP] = record.sExtra;
                EditRow[LINKTYPE] = record.linkType.ToString();
                EditRow[FILEEXISTS] = record.bStatus;
                /*
                EditRow.BeginEdit();
                BuildRow(record).ItemArray.CopyTo(EditRow.ItemArray, 0);
                EditRow.EndEdit();*/
                // EditRow = BuildRow(record); // replace with a new record
            }
        }
Beispiel #10
0
 /// <summary>
 /// called from the GROUP EM
 /// 
 /// Called one by one from the Convert method in Sticky
 /// </summary>
 public void Convert(LinkTableRecord record)
 {
     Add(record);
 }
        /// <summary>
        /// Adds the record to the listview (it has already bbeen adding to the linktable)
        /// 
        /// Called both from AddItem and when Items are set
        /// </summary>
        /// <param name="record"></param>
        private ListViewItem AddRecord(LinkTableRecord record)
        {
            // by default using image index 0
            // a picture will override this
            int nIdx = 0;
            string sSubfolder = "Note";
            bool bFakePic = false;

            string sThumbnailImage = record.sFileName;
            string sTitle = record.sText;

            try {
                if (record.sText.IndexOf ("%") > -1) {
                    string[] strings = record.sText.Split ('%');
                    sTitle = strings [0];

                    if (strings [1] != "") {
                        sThumbnailImage = strings [1];
                        //record.nBookmarkKey = 1; // temp set to picture so it goes into next part
                        bFakePic = true;
                    }
                }
            } catch (Exception) {
            }

            if (record.nBookmarkKey == 1 || true == bFakePic) { // 1 = picutre

                // do special code, assigning
                // the image indexes
                // NO need to store image indexes

                // july 2013 - if we pass a resource in, we try to load it form resource
                if (sThumbnailImage != Constants.BLANK && sThumbnailImage[0] == '*')
                {
                    int imageKey = imageList.Images.IndexOfKey(sThumbnailImage);
                    if (imageKey == -1)
                    {
                        try
                        {
                            sThumbnailImage = sThumbnailImage.Replace ("*", "");
                        // add new
                        Image image = CoreUtilities.FileUtils.GetImage_ForDLL(sThumbnailImage);

                        //Image image = Image.FromFile (sThumbnailImage);
                        imageList.Images.Add (sThumbnailImage, image);
                        nIdx = imageList.Images.Count - 1;
                        imageListLarge.Images.Add (sThumbnailImage, image);
                        }
                        catch (Exception)
                        {

                        }
                    }
                    else
                    {
                        // use existing
                        nIdx = imageKey;
                    }
                }

                // Jan 2010 if the title is parseable with text%link we use link instead
                // of the otherimage (for character page thumbnails)

                if (File.Exists (sThumbnailImage) == true) {
                    Image image = Image.FromFile (sThumbnailImage);
                    imageList.Images.Add (image);
                    nIdx = imageList.Images.Count - 1;
                    imageListLarge.Images.Add (image);

                }

                // if we've set the image to be for a specified note type, we don't want it to say Picture July 2013
                if (false == bFakePic)
                {
                    sSubfolder = "Picture";
                }

            }
            // add record to arraylist
            ListViewItem item = null;
            item = listView.Items.Add (record.sFileName, sTitle, nIdx);

            //*September 2013 -I am removing this code because I *think* it is no longer needed
            /*
            // truncate text, so it is never too long (to attempt fixing the losing item error)
            if (item.Text.Length > 20) {
                item.Text = item.Text.Substring(0, 20);
            }
            */
            item.Tag =  record;

            //this will only happen on Load
            if (record.sExtra != null && record.sExtra != " " && record.sExtra != "")
            {
               // This is the offending Member (May 2013)
                AddItemToGroup(item, record.sExtra);
            }
            // May 2012 -- add group to the Details view (the subitems)
            if (item.Group != null && item.Group.Name != "")
            {
                // May 2013 - commenting these OUT DID NOT fix the 'missing item' issue.
                item.SubItems.Add(item.Group.Name);
            }
            else
            {
                item.SubItems.Add("_default");
            }
            item.SubItems.Add(sSubfolder);
            // may 2012 - wanted to return the listview item so got rid of the item = null line that was here
            return item;
        }
        /// <summary>
        /// edits the item in the linktable
        /// </summary>
        /// <param name="record"></param>
        public void EditItem(LinkTableRecord record)
        {
            _Ready();

            // replaces the existing record with Tag with a new record

               // linkTable.SetLinkTableRecord(record.sKey, record);
               // linkTable.Save();

            StickyTable.Edit(record);
        }
 /// <summary>
 /// Deletes the indicated record
 /// </summary>
 /// <param name="record"></param>
 public void DeleteItem(LinkTableRecord record)
 {
     _Ready();
        // linkTable.DeleteLinkTableRecord(record.sKey);
     /*January 2012*/
     /*We delete it from the database too*/
     if (null != StickyTable)
     {
         StickyTable.Delete(record);
     }
 }
        // to get rid of drwaing errors
        /// <summary>
        /// Primarily this will be called from drag/drop activities
        /// but could also be called in response to a button press.
        /// <param name="sTitle">Title will be displayed in list</param>
        /// <param name="sLinkURL">Link will be used to retrieve contents.</param>
        /// <param name="AlternativeLink">Some things, like images, supply the image in sLinkURL and the GUID in AlternativeLInk, which is stored in ExtraField</param>
        /// </summary>
        public ListViewItem AddItem(string sTitle, string sLinkURL, int nType, string AlternativeLink)
        {
            _Ready();
            if (sTitle == null || sLinkURL == null)
            {
                throw new Exception("GroupEm.AddItem sTitle or sLinkURL null");
            }
            LinkTableRecord record = new LinkTableRecord();

            record.sText = sTitle;
            // Jan 2010: If you ahve a title of text%link the link will be the preview used
            record.sFileName = sLinkURL;
            record.sSource = sSource;

            record.ExtraField = AlternativeLink;

            record.nBookmarkKey = nType;

            //record.sExtra is USED FOR GROUPS, we cannot use it

            record.linkType = LinkType.FILE;  // FILE = Stretch POPUP = Center

                                    // NOPE, did not work, we already use sExtra Jan 2010 I am piggybacking sExtra -1 or "" = Stretch; -2 = No Stretch; if there is a valid file here
                                 // we use that for the thumbnail instead.

               // linkTable.AddLinkTableRecord(record);
               // linkTable.Save();

            if (null != StickyTable)
            {
                record = StickyTable.Add(record);
            }

            ListViewItem item = AddRecord(record);
            OnNeedSave(this); // January 2012. Added because Adds did not appear to register as needing saves

            record = null;

            // APril 2009: forcing a refresh to minimize the
            // number of times the list gets out of sync
            // will only call this ONE time
            if (bOneSafeRefresh == false)
            {
               // LoadGroupEm();

                bOneSafeRefresh = true;
            }

            return item;
        }