private void editToolStripMenuItem_Click(object sender, EventArgs e) { DataGridViewSelectedCellCollection cells = tbldocDataGridView.SelectedCells; if (cells.Count > 0) { try { DataGridViewTextBoxCell cell = cells[0] as DataGridViewTextBoxCell; tbldoc rec_doc_view = cell.OwningRow.DataBoundItem as tbldoc; frmAddDoc m_frmAddDoc = new frmAddDoc(); m_frmAddDoc.Ref_nr = (int)rec_doc_view.ref_nr; m_frmAddDoc.Dokument = rec_doc_view.kilde_sti; m_frmAddDoc.Virksomhed = rec_doc_view.virksomhed; m_frmAddDoc.Emne = rec_doc_view.emne; m_frmAddDoc.Dokument_type = rec_doc_view.dokument_type; m_frmAddDoc.År = (int)rec_doc_view.år; m_frmAddDoc.Ekstern_kilde = rec_doc_view.ekstern_kilde; m_frmAddDoc.Beskrivelse = rec_doc_view.beskrivelse; m_frmAddDoc.Oprettet_af = rec_doc_view.oprettes_af; m_frmAddDoc.Oprettet_dato = (DateTime)rec_doc_view.oprettet_dato; m_frmAddDoc.Opret = false; DialogResult Result = m_frmAddDoc.ShowDialog(); if (Result == System.Windows.Forms.DialogResult.OK) { tbldoc rec_doc_db = null; try { rec_doc_db = (from doc in dblite.tbldoc where doc.id == rec_doc_view.id select doc).First(); rec_doc_db.virksomhed = m_frmAddDoc.Virksomhed; rec_doc_db.emne = m_frmAddDoc.Emne; rec_doc_db.dokument_type = m_frmAddDoc.Dokument_type; rec_doc_db.år = m_frmAddDoc.År; rec_doc_db.ekstern_kilde = m_frmAddDoc.Ekstern_kilde; rec_doc_db.beskrivelse = m_frmAddDoc.Beskrivelse; rec_doc_view.virksomhed = m_frmAddDoc.Virksomhed; rec_doc_view.emne = m_frmAddDoc.Emne; rec_doc_view.dokument_type = m_frmAddDoc.Dokument_type; rec_doc_view.år = m_frmAddDoc.År; rec_doc_view.ekstern_kilde = m_frmAddDoc.Ekstern_kilde; rec_doc_view.beskrivelse = m_frmAddDoc.Beskrivelse; dblite.SaveChanges(); } catch { } } } catch { } } }
void Stifinder_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { FileInfo fileInfo = new FileInfo(file); string kilde_sti = fileInfo.FullName; frmAddDoc m_frmAddDoc = new frmAddDoc(); m_frmAddDoc.Dokument = kilde_sti; DialogResult Result = m_frmAddDoc.ShowDialog(); if (Result == System.Windows.Forms.DialogResult.OK) { Guid id = Guid.NewGuid(); int ref_nr = 0; try { tblrefnr rec_refnr = (from n in dblite.tblrefnr where n.keyname == "ref_nr" select n).First(); rec_refnr.nr++; ref_nr = rec_refnr.nr; dblite.SaveChanges(); } catch { ref_nr = 1; tblrefnr rec_refnr = new tblrefnr { keyname = "ref_nr", nr = ref_nr }; dblite.tblrefnr.AddObject(rec_refnr); dblite.SaveChanges(); } tbldoc rec_doc = new tbldoc { id = id, ref_nr = ref_nr, virksomhed = m_frmAddDoc.Virksomhed, emne = m_frmAddDoc.Emne, dokument_type = m_frmAddDoc.Dokument_type, år = m_frmAddDoc.År, ekstern_kilde = m_frmAddDoc.Ekstern_kilde, beskrivelse = m_frmAddDoc.Beskrivelse, oprettes_af = m_frmAddDoc.Oprettet_af, oprettet_dato = m_frmAddDoc.Oprettet_dato, kilde_sti = kilde_sti }; dblite.tbldoc.AddObject(rec_doc); dblite.SaveChanges(); blSortableBindingList.Add(rec_doc); FileStream fs = fileInfo.OpenRead(); long ln = fileInfo.Length; byte[] file_bytes = new byte[ln]; fs.Read(file_bytes, 0, (int)ln); tblData rec_Data = new tblData { id = id, data = file_bytes }; dblite.tblData.AddObject(rec_Data); dblite.SaveChanges(); } } }
void Outlook_DragDrop(object sender, DragEventArgs e) { //wrap standard IDataObject in OutlookDataObject OutlookDataObject dataObject = new OutlookDataObject(e.Data); //get the names and data streams of the files dropped string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor"); MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents"); for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { //use the fileindex to get the name and data stream string file = filenames[fileIndex]; MemoryStream fs = filestreams[fileIndex]; FileInfo fileInfo = new FileInfo(file); string kilde_sti = fileInfo.Name; frmAddDoc m_frmAddDoc = new frmAddDoc(); m_frmAddDoc.Dokument = kilde_sti; DialogResult Result = m_frmAddDoc.ShowDialog(); if (Result == System.Windows.Forms.DialogResult.OK) { Guid id = Guid.NewGuid(); int ref_nr = 0; try { tblrefnr rec_refnr = (from n in dblite.tblrefnr where n.keyname == "ref_nr" select n).First(); rec_refnr.nr++; ref_nr = rec_refnr.nr; dblite.SaveChanges(); } catch { ref_nr = 1; tblrefnr rec_refnr = new tblrefnr { keyname = "ref_nr", nr = ref_nr }; dblite.tblrefnr.AddObject(rec_refnr); dblite.SaveChanges(); } tbldoc rec_doc = new tbldoc { id = id, ref_nr = ref_nr, virksomhed = m_frmAddDoc.Virksomhed, emne = m_frmAddDoc.Emne, dokument_type = m_frmAddDoc.Dokument_type, år = m_frmAddDoc.År, ekstern_kilde = m_frmAddDoc.Ekstern_kilde, beskrivelse = m_frmAddDoc.Beskrivelse, oprettes_af = m_frmAddDoc.Oprettet_af, oprettet_dato = m_frmAddDoc.Oprettet_dato, kilde_sti = kilde_sti }; dblite.tbldoc.AddObject(rec_doc); dblite.SaveChanges(); blSortableBindingList.Add(rec_doc); //FileStream fs = fileInfo.OpenRead(); long ln = fs.Length; byte[] file_bytes = new byte[ln]; fs.Read(file_bytes, 0, (int)ln); tblData rec_Data = new tblData { id = id, data = file_bytes }; dblite.tblData.AddObject(rec_Data); dblite.SaveChanges(); } } }