Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Image files(*.JPG;*.PNG)|*.JPG;*.PNG";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    pictureBox1.Image = new Bitmap(ofd.FileName);
                    picture           = (Bitmap)pictureBox1.Image;
                    Image        img          = pictureBox1.Image;
                    Dataproc     obj1         = new Dataproc();
                    MemoryStream memoryStream = new MemoryStream();
                    img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                    binaryImage = memoryStream.ToArray();
                    obj1.load_file_BD("Pictures", binaryImage, idCell);
                    memoryStream.Dispose();
                }
                catch
                {
                    MessageBox.Show("ошибка открытия файла", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
 public Form2(string s, int index, string id, int modAccess)
 {
     try
     {
         mod = modAccess;
         InitializeComponent();
         Text = s;
         Dataproc obj1 = new Dataproc();
         obj1.get_spec(id);
         obj1.readimages(id);
         textBox1.Text = obj1.spec;
         if (obj1.images[0].Data != null)
         {
             byte[]         bytearray = obj1.images[0].Data;
             ImageConverter converter = new ImageConverter();
             Image          img       = (Image)converter.ConvertFrom(bytearray);
             Bitmap         bmp       = new Bitmap(img);
             pictureBox1.Image = bmp;
             picture           = bmp;
             idCell            = id;
         }
         idCell = id;
         SetAcess();
     }
     catch
     {
         MessageBox.Show("При инициализации окна произошла ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 3
0
 public Form1(int modAccess)
 {
     try
     {
         mod = modAccess;
         InitializeComponent();
         Dataproc obj1 = new Dataproc();
         obj1.loadbase();
         obj1.max_allowed_packet();
         foreach (string[] s in obj1.adata)
         {
             dataGridView1.Rows.Add(s);
         }
         int i = 0;
         while (dataGridView1.Rows[i].Cells[0].Value != null)
         {
             pic_id.Add(i, dataGridView1.Rows[i].Cells[0].Value.ToString());
             i++;
         }
         i = 0;
         while (dataGridView1.Rows[i].Cells[0].Value != null)
         {
             dataGridView1.Rows[i].Cells[0].Value = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); //конвертируем значения некоторых столбцов для корректной сортировки
             i++;
         }
         i = 0;
         while (dataGridView1.Rows[i].Cells[3].Value != null)
         {
             if (dataGridView1.Rows[i].Cells[3].Value.ToString() != "")
             {
                 dataGridView1.Rows[i].Cells[3].Value = Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value); //конвертируем значения некоторых столбцов для корректной сортировки
             }
             else
             {
                 dataGridView1.Rows[i].Cells[3].Value = null;
             }
             i++;
         }
         i = 0;
         while (dataGridView1.Rows[i].Cells[4].Value != null)
         {
             if (dataGridView1.Rows[i].Cells[4].Value.ToString() != "")
             {
                 dataGridView1.Rows[i].Cells[4].Value = Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value); //конвертируем значения некоторых столбцов для корректной сортировки
             }
             else
             {
                 dataGridView1.Rows[i].Cells[4].Value = null;
             }
             i++;
         }
         i = 0;
         while (dataGridView1.Rows[i].Cells[6].Value != null)
         {
             if (dataGridView1.Rows[i].Cells[6].Value.ToString() != "")
             {
                 dataGridView1.Rows[i].Cells[6].Value = Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value); //конвертируем значения некоторых столбцов для корректной сортировки
             }
             else
             {
                 dataGridView1.Rows[i].Cells[6].Value = null;
             }
             i++;
         }
         SetAcess();
         events();
     }
     catch
     {
         MessageBox.Show("При инициализации окна произошла ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 4
0
        public void saveExcel(DataGridView dataGridView1)
        {
            SaveFileDialog save = new SaveFileDialog();

            save.Title           = "Сохранить изображение как...";
            save.OverwritePrompt = true;
            save.CheckPathExists = true;
            save.Filter          = "Excel Files|.xlsx";
            if (save.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Excel.Application excelApp  = new Excel.Application();
                    Excel.Workbook    workbook  = excelApp.Workbooks.Add();
                    Excel.Worksheet   worksheet = workbook.ActiveSheet;
                    for (int j = 1; j < dataGridView1.ColumnCount; j++)
                    {
                        if (j + 1 == dataGridView1.ColumnCount)
                        {
                            worksheet.Rows[1].Columns[j] = "Изображение";
                        }
                        else
                        {
                            worksheet.Rows[1].Columns[j] = dataGridView1.Columns[j - 1].HeaderText; // заполненине заголовков.
                        }
                    }
                    for (int i = 2; i < dataGridView1.RowCount + 1; i++)
                    {
                        for (int j = 1; j < dataGridView1.ColumnCount - 1; j++)
                        {
                            worksheet.Rows[i].Columns[j] = dataGridView1.Rows[i - 2].Cells[j - 1].Value; // заполнение остальных ячеек
                            if (j == 1 || j == 4)
                            {
                                worksheet.Cells[i, j].NumberFormat = "0";
                            }
                            if (j == 5)
                            {
                                worksheet.Cells[i, j].NumberFormat = "0,000";
                            }
                            if (j == 7)
                            {
                                worksheet.Cells[i, j].NumberFormat = "0,00";
                            }
                        }
                    }
                    worksheet.Columns.AutoFit();
                    for (int i = 0; i < dataGridView1.RowCount - 1; i++)
                    {
                        Excel.Range rg   = worksheet.get_Range("A" + 1, "A" + 1);
                        Dataproc    obj1 = new Dataproc();
                        obj1.readimages(dataGridView1.Rows[i].Cells[0].Value.ToString());
                        if (obj1.images[0].Data != null)
                        {
                            object         missing   = System.Reflection.Missing.Value;
                            byte[]         bytearray = obj1.images[0].Data;
                            ImageConverter converter = new ImageConverter();
                            Image          img       = (Image)converter.ConvertFrom(bytearray);
                            Bitmap         objBitmap = new Bitmap(img, new Size(400, 400));
                            Clipboard.SetImage(objBitmap);
                            Excel.Range oRange = (Excel.Range)worksheet.Cells[i + 2, 8];
                            rg.Rows[i + 2].RowHeight  = 300;
                            rg.Columns[8].ColumnWidth = 56.43F;
                            worksheet.Paste(oRange, missing);
                        }
                        rg.Columns[8].ColumnWidth = 56.43F;
                    }
                    excelApp.AlertBeforeOverwriting = false;
                    workbook.SaveAs(save.FileName);
                    excelApp.Quit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка не удалось экспортировать БД в файл Excel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }