예제 #1
0
        // Repopulate the data grid with the new search results
        public void FillDataGrid(List <String> tags)
        {
            dgd_Results.Rows.Clear();

            List <PasteDBRow> results;

            if (tags == null || tags.Count == 0 || tags[0] == "")
            {
                results = db.returnAll();
            }
            else
            {
                results = new List <PasteDBRow>();

                //List<PasteDBRow> dbResults = db.getTopPastesByTags(tags);
                PasteDBRow dbResults = db.getTopPasteByTags(tags);
                if (dbResults != null)
                {
                    results.Add(dbResults);
                }
            }

            if (results.Count > 0)
            {
                // Add rows to datagrid
                object[] tempobj = new object[4];
                foreach (PasteDBRow resultRow in results)
                {
                    // Set image preview
                    Image preview   = Image.FromFile(resultRow.location);
                    int   newHeight = preview.Height;
                    int   newWidth  = preview.Width;
                    if (preview.Width > preview.Height)
                    {
                        newWidth  = dgd_ROWHEIGHT;
                        newHeight = (int)(((double)dgd_ROWHEIGHT / preview.Width) * preview.Height);
                    }
                    else
                    {
                        newHeight = dgd_ROWHEIGHT;
                        newWidth  = (int)(((double)dgd_ROWHEIGHT / preview.Height) * preview.Width);
                    }
                    tempobj[0] = new Bitmap(preview, newWidth, newHeight);

                    // Add in the upload address, and tag list
                    tempobj[1] = resultRow.uploadAddress;
                    tempobj[2] = resultRow.TagsAsString;
                    tempobj[3] = resultRow.id;

                    dgd_Results.Rows.Add(tempobj);
                }

                // Size all the rows to be the proper height
                for (int rowCount = 0; rowCount < dgd_Results.Rows.Count; rowCount++)
                {
                    dgd_Results.Rows[rowCount].Height = dgd_ROWHEIGHT;
                }
            }
        }
예제 #2
0
        static private Boolean outputDatabase()                                                                         //TODO
        {
            //TODO: Output database in human-readable format


            List <PasteDBRow> results = db.returnAll();

            foreach (PasteDBRow row in results)
            {
                string filename = Path.GetFileName(row.location);
                //Console.WriteLine(filename + "\t" + "\t" + row.uploadAddress);
                //CmdUtil.colorWriteLine(filename + "\t" + "\t" + row.uploadAddress, ConsoleColor.Green);
                CmdUtil.colorWrite(String.Format("{0,-30}", filename), ConsoleColor.White);
                CmdUtil.colorWriteLine(String.Format("{0,30}", row.uploadAddress), ConsoleColor.Gray);
                if (row.tags.Count > 0)
                {
                    CmdUtil.colorWrite("\t" + String.Join(", ", row.tags), ConsoleColor.Gray);
                }
                System.Console.WriteLine(System.Environment.NewLine);
            }

            return(true);
        }