Пример #1
0
        private void AddSampleData()
        {
            using (var db = new MarjieiDb())
            {
                if (db.ReferenceDocuments.Any())
                {
                    return;
                }

                foreach (var file in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)))
                {
                    var fi = new FileInfo(file);
                    if (fi.Extension == ".docx" || fi.Extension == ".pdf")
                    {
                        var doc = new ReferenceDocument
                        {
                            Title        = file,
                            DocumentType = DocumentType.Book.ToString(),
                            Author       = Environment.UserName,
                            //ReferenceFile = File.ReadAllBytes(file),
                        };
                        doc.DocumentId = Convert.ToInt32(db.InsertWithIdentity(doc));
                    }
                }
            }
        }
Пример #2
0
        private void Ribbon_Load(object sender, RibbonUIEventArgs e)
        {
            #region Checking database connection

            try
            {
                using (var db = new MarjieiDb())
                {
                    var b = db.Books.FirstOrDefault();
                }

                btnAddReference.Enabled = true;

#if DEBUG
                AddSampleData();
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    $"Can't access local database:\n{ex.Message}", @"CITATION",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnAddReference.Enabled = false;
            }

            #endregion
        }
Пример #3
0
 private void FrmAddCitation_Shown(object sender, EventArgs e)
 {
     using (var db = new MarjieiDb())
     {
         var docs = db.ReferenceDocuments.OrderBy(d => d.Title).ToList();
         lv.SetObjects(docs);
     }
 }
Пример #4
0
        private void btnAddReference_Click(object sender, RibbonControlEventArgs e)
        {
            using (var frm = new FrmAddCitation())
            {
                frm.ShowDialog();
                var id = frm.SelectedId;
                if (id > 0)
                {
                    using (var db = new MarjieiDb())
                    {
                        var item = (from doc in db.ReferenceDocuments
                                    where doc.DocumentId == id
                                    select doc).FirstOrDefault();
                        //MessageBox.Show($"Selected document:\n[{b?.DocumentId}] {b?.Title}", @"DOCUMENT", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        if (item == null)
                        {
                            return;
                        }

                        var wdoc   = Globals.ThisAddIn.Application.ActiveDocument;
                        var tag    = "Cit01";
                        var strXml =
                            $"<b:Source xmlns:b=\"http://schemas.microsoft.com/office/word/2004/10/bibliography\">" +
                            $"<b:Tag>{tag}</b:Tag>" +
                            $"<b:SourceType>{item.DocumentType}</b:SourceType>" +
                            $"<b:Author><b:Author><b:NameList><b:Person><b:Last>{item.Author}</b:Last><b:First></b:First></b:Person></b:NameList></b:Author></b:Author>" +
                            $"<b:Title>{item.Title}</b:Title>" +
                            $"<b:Year>{item.PublishYear}</b:Year>" +
                            $"<b:City></b:City>" +
                            $"<b:Publisher>{item.Publisher}</b:Publisher>" +
                            $"</b:Source>";
                        wdoc.Bibliography.Sources.Add(strXml); // Here is a problem
                        wdoc.Fields.Add(wdoc.Range(), WdFieldType.wdFieldCitation, tag);

                        var citation = new Citation
                        {
                            CitationIndex = 0,
                            Style         = cboStyle.SelectedItem.Label,
                        };
                        citation.WordFileId = Convert.ToInt32(db.InsertWithIdentity(citation));
                    }
                }
            }
        }