Example #1
0
        public static SampleAttachments getAttachmetFileFromPc()
        {
            var file            = new SampleAttachments();
            var openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream stream = null;
                    if ((stream = openFileDialog1.OpenFile()) != null)
                    {
                        file.FileData = new byte[stream.Length];

                        stream.Read(file.FileData, 0, file.FileData.Length);
                        stream.Close();
                        stream.Dispose();
                        file.FileName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
                        file.FileExt  = Path.GetExtension(openFileDialog1.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка чтения файла: " + ex.Message);
                    return(null);
                }
                return(file);
            }
            return(null);
        }
Example #2
0
        private void viewSamplesAttachmets_DoubleClick(object sender, EventArgs e)
        {
            CardView view = (CardView)sender;
            Point    pt   = view.GridControl.PointToClient(Control.MousePosition);
            //    DoRowDoubleClick(view, pt);
            CardHitInfo info = view.CalcHitInfo(pt);

            if (info.InCard)
            {
                int sampleAttachmentID = (int)viewSamplesAttachmets.GetRowCellValue(info.RowHandle, "SampleAttachmentID");
                SampleAttachments sampleAttachments = db.SampleAttachments.First(x => x.SampleAttachmentID == sampleAttachmentID);

                if (Tools.FileIsPicture(sampleAttachments.FileExt))
                {
                    //                FrmShowSapmplesAttachments frmShowPicture = new FrmShowSapmplesAttachments(sampleAttachments.FileData, sampleAttachments.FileName + sampleAttachments.FileExt);
                    FrmShowSapmplesAttachments frmShowPicture = new FrmShowSapmplesAttachments(GetSamplesAttachmentsList(), sampleAttachmentID);
                    frmShowPicture.ShowDialog();
                }
                else
                {
                    Tools.openFilefromModel(new FileModel
                    {
                        Name      = sampleAttachments.FileName,
                        Extension = sampleAttachments.FileExt,
                        Data      = sampleAttachments.FileData
                    }
                                            );
                }
            }
        }
Example #3
0
        private void viewSamplesAttachmets_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Delete)
            {
                return;
            }

            CardView view = viewSamplesAttachmets as CardView;

            if (!(view.RowCount > 0 && view.FocusedRowHandle >= -1))
            {
                return;
            }
            try
            {
                int sampleAttachmentID = (int)viewSamplesAttachmets.GetRowCellValue(view.FocusedRowHandle, "SampleAttachmentID");
                SampleAttachments sampleAttachments = db.SampleAttachments.First(x => x.SampleAttachmentID == sampleAttachmentID);
                if (
                    MessageBox.Show(
                        String.Format("Удалить документ \n{0}\nиз текущего образца?",
                                      sampleAttachments.FileName + sampleAttachments.FileExt), "Подтверждение",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                db.SampleAttachments.RemoveRange(db.SampleAttachments.Where(x => x.SampleAttachmentID == sampleAttachmentID));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

            try
            {
                db.SaveChanges();
                sampleAttachmentsBindingSource.DataSource = GetSamplesAttachmentsList(); // db.SampleAttachments.Where(x => x.SampleID == sampleID).ToList();
            }
            catch (Exception ex)
            {
                Tools.showDbSaveExceptions(ex);
            }
        }
Example #4
0
        private void btnSampleAddFile_Click(object sender, EventArgs e)
        {
            // now we must to get current Sample ID
            Samples sample = gridViewSamples.GetFocusedRow() as Samples;

            if (sample == null)
            {
                sampleAttachmentsBindingSource.DataSource = null;
                return;
            }

            int sampleID = sample.ID;

            Trace.WriteLine(string.Format("ID:{0}", sampleID));

            //var sampleAttachmets = db.Samples.FirstOrDefault().SampleAttachments


            if (sampleID == 0)
            {
                return;
            }


            SampleAttachments sampleAttachments = new SampleAttachments();

            sampleAttachments = Tools.getAttachmetFileFromPc();
            if (sampleAttachments == null || sampleAttachments.FileData.Length == 0)
            {
                return;
            }

            sampleAttachments.SampleID = sampleID;

            db.SampleAttachments.Add(sampleAttachments);

            if (savedata())
            {
                LoadSamplesAttachments();
            }
        }