Example #1
0
        // fills the different fields in the collection view.
        private void PopulateFields(int id)
        {
            Collection collection = CollectionController.GetCollections(new List <int>()
            {
                id
            })[0];

            tbCollectionId.Text       = collection.Id.ToString();
            tbDateTime.Text           = collection.CaptureDateTime.ToString("yyyy-MM-Dd hh:mm:ss");
            cbCatalogue.SelectedIndex = listCatalogues.IndexOf(listCatalogues.Find(x => x.Id == collection.Catalogue.Id));
            tbObjectId.Text           = collection.Object.ToString();
            tbObjectTitle.Text        = collection.ObjectTitle;
            tbMetadataFile.Text       = collection.MetaDataFileName;
            toolTipInfo.SetToolTip(tbMetadataFile, tbMetadataFile.Text);
            tbFile.Text = collection.FileName;
            toolTipInfo.SetToolTip(tbFile, tbFile.Text);
            tbTotalFrames.Value          = collection.NumberFrames;
            cbFileFormat.SelectedIndex   = listFileFormats.IndexOf(listFileFormats.Find(x => x.Id == collection.FileFormat.Id));
            cbColorSpace.SelectedIndex   = listColorSpaces.IndexOf(listColorSpaces.Find(x => x.Id == collection.ColorSpace.Id));
            tbResolutionX.Text           = collection.Resolution.Width.ToString();
            tbResolutionY.Text           = collection.Resolution.Height.ToString();
            cbPhotographer.SelectedIndex = listPhotographers.IndexOf(listPhotographers.Find(x => x.Id == collection.Photographer.Id));
            cbSite.SelectedIndex         = listSites.IndexOf(listSites.Find(x => x.Id == collection.Site.Id));
            tbComments.Text        = collection.Comments;
            cbScope.SelectedIndex  = listScopes.IndexOf(listScopes.Find(x => x.Id == collection.Scope.Id));
            cbCamera.SelectedIndex = listCameras.IndexOf(listCameras.Find(x => x.Id == collection.Camera.Id));

            clbOptics.Items.Clear();
            bool opticChecked;

            foreach (var item in listOptics)
            {
                opticChecked = collection.Optics.Contains(item);
                clbOptics.Items.Add(item.Id + "|  " + item.OpticType + " " + item.Value, opticChecked);
            }
        }
Example #2
0
        public static void PopulateTreeView(ref TreeView treeView, bool isAscending, string format = "")
        {
            SqlConnection con = DbManager.GetConnection();
            SqlCommand    cmd = con.CreateCommand();

            treeView.Nodes.Clear();

            // returns dates, ids and object titles of collections
            cmd.CommandText = "SELECT [Id],CAST(FLOOR(CAST([CaptureDateTime] as FLOAT)) as DateTime) FROM tblCollections ORDER BY [CaptureDateTime] " + (isAscending ? "ASC" : "DESC");

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                // for every collection, add to a new or existing group - by date.
                int        id  = reader.GetInt32(0);
                Collection col = CollectionController.GetCollections(new List <int>()
                {
                    id
                })[0];

                string folderKey;

                if (Properties.Preferences.Default.NodeGrouping == 0)
                {
                    folderKey = reader.GetDateTime(1).ToString("yyyy-MM-dd");
                }
                else if (Properties.Preferences.Default.NodeGrouping == 1)
                {
                    folderKey = col.Catalogue.LongName;
                }
                else
                {
                    folderKey = col.ObjectTitle;
                }

                string posibleKey = "f" + folderKey; // f is for folder.
                if (!treeView.Nodes.ContainsKey(posibleKey))
                {
                    treeView.Nodes.Add(posibleKey, posibleKey.Substring(1));
                }

                string namingFormat = string.IsNullOrEmpty(format) ? Properties.Preferences.Default.TreeNodeFormat : format;

                foreach (Match match in Regex.Matches(namingFormat, @"\{([^}]+)\}"))
                {
                    // parse the match:
                    string matchVal = match.Value.Replace("{", "").Replace("}", "");

                    string command, parameter = "";
                    if (matchVal.Contains("|"))
                    {
                        command   = matchVal.Split('|')[0];
                        parameter = matchVal.Split('|')[1];
                    }
                    else
                    {
                        command = matchVal;
                    }

                    matchVal = "{" + matchVal + "}";

                    switch (command)
                    {
                    case "dt":
                        namingFormat = namingFormat.Replace(matchVal, col.CaptureDateTime.ToString(parameter));

                        break;

                    case "o":
                        if (parameter == "id")
                        {
                            namingFormat = namingFormat.Replace(matchVal, col.Object.ToString());
                        }

                        if (parameter == "n")
                        {
                            namingFormat = namingFormat.Replace(matchVal, col.ObjectTitle);
                        }

                        break;

                    case "c":
                        if (parameter == "id")
                        {
                            namingFormat = namingFormat.Replace(matchVal, col.Catalogue.Id.ToString());
                        }

                        if (parameter == "sn")
                        {
                            namingFormat = namingFormat.Replace(matchVal, col.Catalogue.ShortName);
                        }

                        if (parameter == "ln")
                        {
                            namingFormat = namingFormat.Replace(matchVal, col.Catalogue.LongName);
                        }

                        break;

                    default:
                        break;
                    }
                }


                //treeView.Nodes[posibleKey].Nodes.Add("i" + reader.GetString(0), // key. i for item.
                //    reader.GetDateTime(3).ToString("hh:mm:ss") + " - " + reader.GetString(2));

                treeView.Nodes[posibleKey].Nodes.Add("i" + id.ToString(), // key. i for item.
                                                     namingFormat);

                treeView.ExpandAll();
            }
        }