Ejemplo n.º 1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == this.dataGridView1.Columns["type"].Index)
            {
                var entry = this.dataGridView1.Rows[e.RowIndex].Tag as rr_history;

                if (entry.type == (Int64)RREntities.rr_history.RowType.Diagnostics)
                {
                    DiagHistoryForm form = new DiagHistoryForm(entry);
                    form.ShowDialog();
                    //var card = serializer.Deserialize<DiagnosticCard>(entry.info);
                }
                else
                {
                    EstimationHistoryForm form = new EstimationHistoryForm(entry);
                    form.ShowDialog();
                    //var estimation = serializer.Deserialize<EstimationCard>(entry.info);
                }
            }
            else if (e.ColumnIndex == this.dataGridView1.Columns["Photo"].Index)
            {
                var entry = this.dataGridView1.Rows[e.RowIndex].Tag as rr_history;
                if (entry.photo != null && entry.photo.Length > 0)
                {
                    // Просмотр

                    MemoryStream ms    = new MemoryStream(entry.photo);
                    Image        image = Image.FromStream(ms);
                    Form         form  = new Form();
                    form.Text = "Просмотр фотографии";

                    PictureBox pictureBox = new PictureBox();
                    pictureBox.Dock     = DockStyle.Fill;
                    pictureBox.Image    = image;
                    pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
                    form.Controls.Add(pictureBox);

                    form.ShowDialog();
                }
                else
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.CheckFileExists = true;
                    openFileDialog.AddExtension    = true;
                    openFileDialog.Multiselect     = false;
                    openFileDialog.Filter          = "Фото (*.jpg; *.jpeg; *.png; *.gif;) | *.jpg; *.jpeg; *.png; *.gif";

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            String s = openFileDialog.FileName;
                            entry.photo = File.ReadAllBytes(s);

                            RrDb db = new RrDb();
                            db.Edit(entry);
                            dataGridView1.Rows[e.RowIndex].Cells["Photo"].Value = "Просмотр";

                            MessageBox.Show("Данные успешно сохранены", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Не удалось сохранить данные: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else if (e.ColumnIndex == dataGridView1.Columns["Action"].Index)
            {
                if (MessageBox.Show("Удалить данные?", "Подтверждение", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {
                        var  entry = dataGridView1.Rows[e.RowIndex].Tag as rr_history;
                        RrDb db    = new RrDb();
                        db.Delete(entry);
                        MessageBox.Show("Данные удалены", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        dataGridView1.Rows.Remove(dataGridView1.Rows[e.RowIndex]);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Не удалось удалить данные: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }