読者です 読者をやめる 読者になる 読者になる

6日間で文献管理アプリを作る(おまけ)

Form1.cs

using System;
using System.Windows.Forms;
using System.IO;

namespace 文献管理
{
    public partial class Form1 : Form
    {
        string choose_file;                 //選択したファイルの名前
        int article_number;                 //文献数
        string[] article_array;             //PMIDの配列
        const string ver_no = "1.0.0";      //バージョンナンバー

        public Form1()
        {
            InitializeComponent();
        }

        private void バージョン情報AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Version " + ver_no);
        }

        private void 終了XToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 開くOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            open_file();
        }

        private void 新規作成NToolStripMenuItem_Click(object sender, EventArgs e)
        {
            make_new_file();
        }

        private void 追加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (choose_file != null)
            {
                input_form f = new input_form();
                f.Text = "追加";
                f.button1.Text = "追加";
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    int kensyo; //入力された文字が0以上の数字であることを確認
                    int.TryParse(f.textBox1.Text, out kensyo);
                    if (kensyo > 0)
                    {
                        article_add(f.textBox1.Text);
                    }
                    else
                    {
                        MessageBox.Show("入力が不適切です");
                    }
                    f.Dispose();
                }
            }
        }

        private void 削除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (choose_file != null)
            {
                input_form f = new input_form();
                f.Text = "削除";
                f.button1.Text = "削除";
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    int kensyo; //入力された文字が0以上の数字であることを確認
                    int.TryParse(f.textBox1.Text, out kensyo);
                    if (kensyo > 0)
                    {
                        article_remove(f.textBox1.Text);
                    }
                    else
                    {
                        MessageBox.Show("入力が不適切です");
                    }
                    f.Dispose();
                }
            }
        }

        private void hTML出力ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (choose_file != null)
            {
               output_html();
            }
        }

        private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if(e.Url.Scheme=="about")
            {
                e.Cancel = true;
                article_form f = new article_form();
                f.file_info = new FileInfo(choose_file);
                f.article_array2 = article_array;
                f.article_number2 = article_number;
                f.toolStripStatusLabel1.Text = e.Url.LocalPath;
                f.ShowDialog(this);
            }
        }
    }
}

article_form.cs

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace 文献管理
{
    public partial class article_form : Form
    {
        public FileInfo file_info;      //選択しているXMLファイルの情報
        public int article_number2;     //文献数(Form1から受け取る)
        public string[] article_array2; //PMIDの配列(Form1から受け取る)
        int current_no;                 //PMID配列の何番目か?
        string pdffile;                 //PDFファイルのパス

        public article_form()
        {
            InitializeComponent();
        }

        private void 大ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            大ToolStripMenuItem.Checked = true;ToolStripMenuItem.Checked = false;ToolStripMenuItem.Checked = false;
            textBox1.Font = new Font("MS UI Gothic", 20);
        }

        private void 中ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            大ToolStripMenuItem.Checked = false;ToolStripMenuItem.Checked = true;ToolStripMenuItem.Checked = false;
            textBox1.Font = new Font("MS UI Gothic", 16);
        }

        private void 小ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            大ToolStripMenuItem.Checked = false;ToolStripMenuItem.Checked = false;ToolStripMenuItem.Checked = true;
            textBox1.Font = new Font("MS UI Gothic", 12);
        }

        private void article_form_Load(object sender, EventArgs e)
        {
            form_reload();
            current_no = Array.IndexOf(article_array2, toolStripStatusLabel1.Text);
        }

        private void pubmed_Click(object sender, EventArgs e)
        {
            Process.Start("http://www.ncbi.nlm.nih.gov/pubmed/" + toolStripStatusLabel1.Text);
        }

        private void pdf_Click(object sender, EventArgs e)
        {
            Process.Start(pdffile);
        }

        private void first_Click(object sender, EventArgs e)
        {
            current_no = 0;
            toolStripStatusLabel1.Text = article_array2[current_no];
            form_reload();
        }

        private void last_Click(object sender, EventArgs e)
        {
            current_no = article_number2 - 1;
            toolStripStatusLabel1.Text = article_array2[current_no];
            form_reload();
        }

        private void down_Click(object sender, EventArgs e)
        {
            current_no--;
            if (current_no > -1)
            {
                toolStripStatusLabel1.Text = article_array2[current_no];
                form_reload();
            }
            else
            {
                current_no = 0;
            }
        }

        private void up_Click(object sender, EventArgs e)
        {
            current_no++;
            if (current_no < article_number2)
            {
                toolStripStatusLabel1.Text = article_array2[current_no];
                form_reload();
            }
            else
            {
                current_no = article_number2 - 1;
            }
        }
    }
}