Ejemplo n.º 1
0
 private void LoadNewPic(int pictureId)
 {
     using (var sourceImage = BentaiDataBaseHandler.GetImage(pictureId))
     {
         var targetImage = new Bitmap(sourceImage.Width, sourceImage.Height,
                                      System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         using (var canvas = Graphics.FromImage(targetImage))
         {
             canvas.DrawImageUnscaled(sourceImage, 0, 0);
         }
         hentaiPicBox.Image = targetImage;
     }
 }
Ejemplo n.º 2
0
        internal void SaveFiles()
        {
            if (imageData.Count == 0)
            {
                return;
            }

            Image[] imagesToAddArray = new Image[imagesToAdd.Count];
            for (int i = 0; i < this.imagesToAdd.Count; i++)
            {
                if (File.Exists(this.imagesToAdd[i]))
                {
                    imagesToAddArray[i] = Image.FromFile(imagesToAdd[i]);
                }
            }

            BentaiDataBaseHandler.AddDataBaseEntryWithImage(imagesToAddArray, imageData);

            imageData.Clear();
            this.imagesToAdd.Clear();
        }
Ejemplo n.º 3
0
        private void ExportButton_Click(object sender, EventArgs e)
        {
            {
                string sqlCommandString = "select imageId from imageData";

                Dictionary <string, int> selectedSearch = new Dictionary <string, int>();

                string sqlFieldName;
                for (int i = 0; i < DataBaseNames.Length; i++)
                {
                    sqlFieldName = DataBaseNames[i];
                    selectedSearch.Add(sqlFieldName, tagLabels[i].Text == "Yes" ? 1 : tagLabels[i].Text == "No" ? 0 : 2);
                }

                if (selectedSearch.Count != 0)
                {
                    sqlCommandString += " where";
                    foreach (KeyValuePair <string, int> searchCriteria in selectedSearch)
                    {
                        if (searchCriteria.Value != 2)
                        {
                            sqlCommandString += $" {searchCriteria.Key} = {searchCriteria.Value} and";
                        }
                    }

                    int lastAndIndex = sqlCommandString.LastIndexOf("and");
                    if (lastAndIndex != -1)
                    {
                        sqlCommandString = sqlCommandString.Remove(lastAndIndex, "and".Length);
                    }
                }
                if (sqlCommandString == "select imageId from imageData where")
                {
                    sqlCommandString = "select imageId from imageData";
                }

                List <int> imageIds = new List <int>();
                using (SQLiteConnection sqlConnection = new SQLiteConnection(Globals.dataBaseString))
                {
                    sqlConnection.Open();
                    using (SQLiteCommand sqlCommand = new SQLiteCommand(sqlCommandString, sqlConnection))
                        using (SQLiteDataReader sqlReader = sqlCommand.ExecuteReader())
                        {
                            while (sqlReader.Read())
                            {
                                int imageId = (int)sqlReader["imageId"];
                                imageIds.Add(imageId);
                            }
                        }
                }

                List <Bitmap> imagesToExport = new List <Bitmap>();
                for (int i = 0; i < imageIds.Count; i++)
                {
                    imagesToExport.Add(BentaiDataBaseHandler.GetBitmap(imageIds[i]));
                }

                if (imagesToExport.Count == 0)
                {
                    MessageBox.Show("No images matched the query");
                    return;
                }

                using (var fbd = new FolderBrowserDialog())
                {
                    fbd.Description = "Select the folder to export the files";
                    DialogResult result = fbd.ShowDialog();

                    if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                    {
                        Directory.CreateDirectory(fbd.SelectedPath + "/BentaiImages");
                        for (int i = 0; i < imagesToExport.Count; i++)
                        {
                            imagesToExport[i].Save($"{fbd.SelectedPath}/BentaiImages/{i}.png");
                        }

                        string file = "File";
                        if (imagesToExport.Count > 1)
                        {
                            file = "Files";
                        }

                        MessageBox.Show($@"{imagesToExport.Count} {file} saved under {fbd.SelectedPath}\BentaiImages");
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }