Archive for 十二月, 2013

18
十二月

程式設計一程式 12/18 C程式複習

   Posted by: admin    in 102(上)程式設計(一)

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

1217mim

使用Webmatrix產生插入資料到資料庫的程式

使用Webmatrix產生插入資料到資料庫的程式

健保資料原始檔轉Access資料庫

健保資料原始檔轉Access資料庫

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

private void button3_Click(object sender, EventArgs e)
        {
 
            StreamReader sr = new StreamReader(textBox1.Text);//開啟原始資料的檔案
            string line = sr.ReadLine();//從原始資料檔讀入一行
            int linecount = 0;
            while (line != null && line.Length > 0)
            {
                NHIRD_CD cd = ParseCDLine(line);//把原始資料切成不同欄位
                DBEntry_CD dbe_cd = new DBEntry_CD(cd);//轉換成資料庫的欄位
                InsertCDRecord(dbe_cd);//插入資料庫
                linecount++;
                line = sr.ReadLine();
            }
            label2.Text = "lines=" + linecount.ToString();
        }
        public int InsertCDRecord(DBEntry_CD cd)
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=\\\\172.16.5.19\\desktop_dat\\htchu\\桌面\\NHIRD-Student.mdb";
            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
 
            string queryString = @"INSERT INTO [CD] ([FEE_YM], [APPL_TYPE], [HOSP_ID], [APPL_DATE], [CASE_TYPE], [SEQ_NO], [CURE_ITEM_NO1], [CURE_ITEM_NO2], [CURE_ITEM_NO3], [CURE_ITEM_NO4], [FUNC_TYPE], [FUNC_DATE], [TREAT_END_DATE], [ID_BIRTHDAY], [ID], [CARD_SEQ_NO], [GAVE_KIND], [PART_NO], [ACODE_ICD9_1], [ACODE_ICD9_2], [ACODE_ICD9_3], [ICD_OP_CODE], [DRUG_DAY], [MED_TYPE], [PRSN_ID], [PHAR_ID], [DRUG_AMT], [TREAT_AMT], [TREAT_CODE], [DIAG_AMT], [DSVC_NO], [DSVC_AMT], [BY_PASS_CODE], [T_AMT], [PART_AMT], [T_APPL_AMT], [ID_SEX]) VALUES (@FEE_YM, @APPL_TYPE, @HOSP_ID, @APPL_DATE, @CASE_TYPE, @SEQ_NO, @CURE_ITEM_NO1, @CURE_ITEM_NO2, @CURE_ITEM_NO3, @CURE_ITEM_NO4, @FUNC_TYPE, @FUNC_DATE, @TREAT_END_DATE, @ID_BIRTHDAY, @ID, @CARD_SEQ_NO, @GAVE_KIND, @PART_NO, @ACODE_ICD9_1, @ACODE_ICD9_2, @ACODE_ICD9_3, @ICD_OP_CODE, @DRUG_DAY, @MED_TYPE, @PRSN_ID, @PHAR_ID, @DRUG_AMT, @TREAT_AMT, @TREAT_CODE, @DIAG_AMT, @DSVC_NO, @DSVC_AMT, @BY_PASS_CODE, @T_AMT, @PART_AMT, @T_APPL_AMT, @ID_SEX)";
            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;
 
            System.Data.IDataParameter dbParam_fEE_YM = new System.Data.OleDb.OleDbParameter();
            dbParam_fEE_YM.ParameterName = "@FEE_YM";
            dbParam_fEE_YM.Value = cd.FEE_YM;
            dbParam_fEE_YM.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_fEE_YM);
 
            System.Data.IDataParameter dbParam_aPPL_TYPE = new System.Data.OleDb.OleDbParameter();
            dbParam_aPPL_TYPE.ParameterName = "@APPL_TYPE";
            dbParam_aPPL_TYPE.Value = cd.APPL_TYPE;
            dbParam_aPPL_TYPE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_aPPL_TYPE);
 
            System.Data.IDataParameter dbParam_hOSP_ID = new System.Data.OleDb.OleDbParameter();
            dbParam_hOSP_ID.ParameterName = "@HOSP_ID";
            dbParam_hOSP_ID.Value = cd.HOSP_ID;
            dbParam_hOSP_ID.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_hOSP_ID);
 
            System.Data.IDataParameter dbParam_aPPL_DATE = new System.Data.OleDb.OleDbParameter();
            dbParam_aPPL_DATE.ParameterName = "@APPL_DATE";
            dbParam_aPPL_DATE.Value = cd.APPL_DATE;
            dbParam_aPPL_DATE.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_aPPL_DATE);
 
            System.Data.IDataParameter dbParam_cASE_TYPE = new System.Data.OleDb.OleDbParameter();
            dbParam_cASE_TYPE.ParameterName = "@CASE_TYPE";
            dbParam_cASE_TYPE.Value = cd.CASE_TYPE;
            dbParam_cASE_TYPE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cASE_TYPE);
 
            System.Data.IDataParameter dbParam_sEQ_NO = new System.Data.OleDb.OleDbParameter();
            dbParam_sEQ_NO.ParameterName = "@SEQ_NO";
            dbParam_sEQ_NO.Value = cd.SEQ_NO;
            dbParam_sEQ_NO.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_sEQ_NO);
 
            System.Data.IDataParameter dbParam_cURE_ITEM_NO1 = new System.Data.OleDb.OleDbParameter();
            dbParam_cURE_ITEM_NO1.ParameterName = "@CURE_ITEM_NO1";
            dbParam_cURE_ITEM_NO1.Value = cd.CURE_ITEM_NO1;
            dbParam_cURE_ITEM_NO1.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cURE_ITEM_NO1);
 
            System.Data.IDataParameter dbParam_cURE_ITEM_NO2 = new System.Data.OleDb.OleDbParameter();
            dbParam_cURE_ITEM_NO2.ParameterName = "@CURE_ITEM_NO2";
            dbParam_cURE_ITEM_NO2.Value = cd.CURE_ITEM_NO2;
            dbParam_cURE_ITEM_NO2.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cURE_ITEM_NO2);
 
            System.Data.IDataParameter dbParam_cURE_ITEM_NO3 = new System.Data.OleDb.OleDbParameter();
            dbParam_cURE_ITEM_NO3.ParameterName = "@CURE_ITEM_NO3";
            dbParam_cURE_ITEM_NO3.Value = cd.CURE_ITEM_NO3;
            dbParam_cURE_ITEM_NO3.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cURE_ITEM_NO3);
 
            System.Data.IDataParameter dbParam_cURE_ITEM_NO4 = new System.Data.OleDb.OleDbParameter();
            dbParam_cURE_ITEM_NO4.ParameterName = "@CURE_ITEM_NO4";
            dbParam_cURE_ITEM_NO4.Value = cd.CURE_ITEM_NO4;
            dbParam_cURE_ITEM_NO4.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cURE_ITEM_NO4);
 
            System.Data.IDataParameter dbParam_fUNC_TYPE = new System.Data.OleDb.OleDbParameter();
            dbParam_fUNC_TYPE.ParameterName = "@FUNC_TYPE";
            dbParam_fUNC_TYPE.Value = cd.FUNC_TYPE;
            dbParam_fUNC_TYPE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_fUNC_TYPE);
 
            System.Data.IDataParameter dbParam_fUNC_DATE = new System.Data.OleDb.OleDbParameter();
            dbParam_fUNC_DATE.ParameterName = "@FUNC_DATE";
            dbParam_fUNC_DATE.Value = cd.FUNC_DATE;
            dbParam_fUNC_DATE.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_fUNC_DATE);
 
            System.Data.IDataParameter dbParam_tREAT_END_DATE = new System.Data.OleDb.OleDbParameter();
            dbParam_tREAT_END_DATE.ParameterName = "@TREAT_END_DATE";
            dbParam_tREAT_END_DATE.Value = cd.TREAT_END_DATE;
            dbParam_tREAT_END_DATE.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_tREAT_END_DATE);
 
            System.Data.IDataParameter dbParam_iD_BIRTHDAY = new System.Data.OleDb.OleDbParameter();
            dbParam_iD_BIRTHDAY.ParameterName = "@ID_BIRTHDAY";
            dbParam_iD_BIRTHDAY.Value = cd.ID_BIRTHDAY;
            dbParam_iD_BIRTHDAY.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_iD_BIRTHDAY);
 
            System.Data.IDataParameter dbParam_iD = new System.Data.OleDb.OleDbParameter();
            dbParam_iD.ParameterName = "@ID";
            dbParam_iD.Value = cd.ID;
            dbParam_iD.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_iD);
 
            System.Data.IDataParameter dbParam_cARD_SEQ_NO = new System.Data.OleDb.OleDbParameter();
            dbParam_cARD_SEQ_NO.ParameterName = "@CARD_SEQ_NO";
            dbParam_cARD_SEQ_NO.Value = cd.CARD_SEQ_NO;
            dbParam_cARD_SEQ_NO.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_cARD_SEQ_NO);
 
            System.Data.IDataParameter dbParam_gAVE_KIND = new System.Data.OleDb.OleDbParameter();
            dbParam_gAVE_KIND.ParameterName = "@GAVE_KIND";
            dbParam_gAVE_KIND.Value = cd.GAVE_KIND;
            dbParam_gAVE_KIND.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_gAVE_KIND);
 
            System.Data.IDataParameter dbParam_pART_NO = new System.Data.OleDb.OleDbParameter();
            dbParam_pART_NO.ParameterName = "@PART_NO";
            dbParam_pART_NO.Value = cd.PART_NO;
            dbParam_pART_NO.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_pART_NO);
 
            System.Data.IDataParameter dbParam_aCODE_ICD9_1 = new System.Data.OleDb.OleDbParameter();
            dbParam_aCODE_ICD9_1.ParameterName = "@ACODE_ICD9_1";
            dbParam_aCODE_ICD9_1.Value = cd.ACODE_ICD9_1;
            dbParam_aCODE_ICD9_1.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_aCODE_ICD9_1);
 
            System.Data.IDataParameter dbParam_aCODE_ICD9_2 = new System.Data.OleDb.OleDbParameter();
            dbParam_aCODE_ICD9_2.ParameterName = "@ACODE_ICD9_2";
            dbParam_aCODE_ICD9_2.Value = cd.ACODE_ICD9_2;
            dbParam_aCODE_ICD9_2.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_aCODE_ICD9_2);
 
            System.Data.IDataParameter dbParam_aCODE_ICD9_3 = new System.Data.OleDb.OleDbParameter();
            dbParam_aCODE_ICD9_3.ParameterName = "@ACODE_ICD9_3";
            dbParam_aCODE_ICD9_3.Value = cd.ACODE_ICD9_3;
            dbParam_aCODE_ICD9_3.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_aCODE_ICD9_3);
 
            System.Data.IDataParameter dbParam_iCD_OP_CODE = new System.Data.OleDb.OleDbParameter();
            dbParam_iCD_OP_CODE.ParameterName = "@ICD_OP_CODE";
            dbParam_iCD_OP_CODE.Value = cd.ICD_OP_CODE;
            dbParam_iCD_OP_CODE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_iCD_OP_CODE);
 
            System.Data.IDataParameter dbParam_dRUG_DAY = new System.Data.OleDb.OleDbParameter();
            dbParam_dRUG_DAY.ParameterName = "@DRUG_DAY";
            dbParam_dRUG_DAY.Value = cd.DRUG_DAY;
            dbParam_dRUG_DAY.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_dRUG_DAY);
 
            System.Data.IDataParameter dbParam_mED_TYPE = new System.Data.OleDb.OleDbParameter();
            dbParam_mED_TYPE.ParameterName = "@MED_TYPE";
            dbParam_mED_TYPE.Value = cd.MED_TYPE;
            dbParam_mED_TYPE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_mED_TYPE);
 
            System.Data.IDataParameter dbParam_pRSN_ID = new System.Data.OleDb.OleDbParameter();
            dbParam_pRSN_ID.ParameterName = "@PRSN_ID";
            dbParam_pRSN_ID.Value = cd.PRSN_ID;
            dbParam_pRSN_ID.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_pRSN_ID);
 
            System.Data.IDataParameter dbParam_pHAR_ID = new System.Data.OleDb.OleDbParameter();
            dbParam_pHAR_ID.ParameterName = "@PHAR_ID";
            dbParam_pHAR_ID.Value = cd.PHAR_ID;
            dbParam_pHAR_ID.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_pHAR_ID);
 
            System.Data.IDataParameter dbParam_dRUG_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_dRUG_AMT.ParameterName = "@DRUG_AMT";
            dbParam_dRUG_AMT.Value = cd.DRUG_AMT;
            dbParam_dRUG_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_dRUG_AMT);
 
            System.Data.IDataParameter dbParam_tREAT_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_tREAT_AMT.ParameterName = "@TREAT_AMT";
            dbParam_tREAT_AMT.Value = cd.TREAT_AMT;
            dbParam_tREAT_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_tREAT_AMT);
 
            System.Data.IDataParameter dbParam_tREAT_CODE = new System.Data.OleDb.OleDbParameter();
            dbParam_tREAT_CODE.ParameterName = "@TREAT_CODE";
            dbParam_tREAT_CODE.Value = cd.TREAT_CODE;
            dbParam_tREAT_CODE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_tREAT_CODE);
 
            System.Data.IDataParameter dbParam_dIAG_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_dIAG_AMT.ParameterName = "@DIAG_AMT";
            dbParam_dIAG_AMT.Value = cd.DIAG_AMT;
            dbParam_dIAG_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_dIAG_AMT);
 
            System.Data.IDataParameter dbParam_dSVC_NO = new System.Data.OleDb.OleDbParameter();
            dbParam_dSVC_NO.ParameterName = "@DSVC_NO";
            dbParam_dSVC_NO.Value = cd.DSVC_NO;
            dbParam_dSVC_NO.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_dSVC_NO);
 
            System.Data.IDataParameter dbParam_dSVC_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_dSVC_AMT.ParameterName = "@DSVC_AMT";
            dbParam_dSVC_AMT.Value = cd.DSVC_AMT;
            dbParam_dSVC_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_dSVC_AMT);
 
            System.Data.IDataParameter dbParam_bY_PASS_CODE = new System.Data.OleDb.OleDbParameter();
            dbParam_bY_PASS_CODE.ParameterName = "@BY_PASS_CODE";
            dbParam_bY_PASS_CODE.Value = cd.BY_PASS_CODE;
            dbParam_bY_PASS_CODE.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_bY_PASS_CODE);
 
            System.Data.IDataParameter dbParam_t_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_t_AMT.ParameterName = "@T_AMT";
            dbParam_t_AMT.Value = cd.T_AMT;
            dbParam_t_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_t_AMT);
 
            System.Data.IDataParameter dbParam_pART_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_pART_AMT.ParameterName = "@PART_AMT";
            dbParam_pART_AMT.Value = cd.PART_AMT;
            dbParam_pART_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_pART_AMT);
 
            System.Data.IDataParameter dbParam_t_APPL_AMT = new System.Data.OleDb.OleDbParameter();
            dbParam_t_APPL_AMT.ParameterName = "@T_APPL_AMT";
            dbParam_t_APPL_AMT.Value = cd.T_APPL_AMT;
            dbParam_t_APPL_AMT.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_t_APPL_AMT);
 
            System.Data.IDataParameter dbParam_iD_SEX = new System.Data.OleDb.OleDbParameter();
            dbParam_iD_SEX.ParameterName = "@ID_SEX";
            dbParam_iD_SEX.Value = cd.ID_SEX;
            dbParam_iD_SEX.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_iD_SEX);
 
            int rowsAffected = 0;
            dbConnection.Open();
            try
            {
                rowsAffected = dbCommand.ExecuteNonQuery();
            }
            finally
            {
                dbConnection.Close();
            }
 
            return rowsAffected;
 
        }

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

1211prog

 

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

11
十二月

程式設計一程式 12/11: ex12.c

   Posted by: admin    in 102(上)程式設計(一)

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
 
namespace Ex12
{
    class Program
    {
        static void Main(string[] args)
        {
            int i; 
            int num, pos;
 
            //從命令列讀入一個參數 
            //num = atoi(argv[1]);
            num = int.Parse(args[0]);
 
            //設定亂數的啟始點
            //srand( (unsigned) time( NULL ) );
 
            //建立亂數的物件
		    		Random rnd = new Random();
 
            //out = fopen("number.txt", "w");
            StreamWriter sw = new StreamWriter("number.txt");
 
            //產生1000個亂數
            for (i=0; i<num; i++)
            {
                //pos = rand();////產生1個亂數
                pos = rnd.Next();
                //printf("%d\n", pos);
                Console.WriteLine(pos);
                //fprintf(out, "%d\n", pos);
                sw.WriteLine(pos);
            } 
            //fclose(out);
            sw.Close();
        }
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,