30
十二月

醫學資訊管理-NHIRD Ex3-12/30

   Posted by: admin   in 103(上)醫學資訊管理

//在Form1表單:加入
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.OpenFileDialog openFileDialog2;
        private System.Windows.Forms.Label label3;
//加入
HashSet<string> setID = new HashSet<string>();
//加入
private void button3_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            int cc = 0;
            foreach (string filename in openFileDialog2.FileNames)
            {
                StreamReader sr = new StreamReader(filename);
                string line = sr.ReadLine();
                while (line != null)
                {
                    string DrugNo = line.Substring(58, 10);
                    if (DrugNo == "A002658100")
                    {
                        cc++;
                        string ID = line.Substring(0, 57);
                        if (!setID.Contains(ID))
                            setID.Add(ID);
                    }
                    line = sr.ReadLine();
                }
                sr.Close();
            }
            label3.Text = cc.ToString() + "(" + setID.Count + ")";
        }
//修改button2_Click()函數
private void button2_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(textBox1.Text);
            //StreamWriter sw = new StreamWriter(textBox2.Text);
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" + textBox2.Text;
            IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
 
            dbConnection.Open();
            string line = sr.ReadLine();
            while (line != null)
            {
                string ID = line.Substring(0, 57);
                if (setID.Contains(ID))
                {
                    NHIRD_CD cd = ParseCDLine(line);
                    DBEntry_CD dbe = new DBEntry_CD(cd);
                    InsertCDRecord(dbConnection, dbe);
                }
                line = sr.ReadLine();
            }
            sr.Close(); //sw.Close();
            dbConnection.Close();
 
        }

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

This entry was posted on 星期二, 十二月 30th, 2014 at 09:04:47 and is filed under 103(上)醫學資訊管理. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment