Archive for 十二月, 2014

31
十二月

程式設計一程式 12/31: Ex9Class.java

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

import java.io.*;  //#include <stdio.h>
import java.util.*;//#include <stdlib.h> 
public class Ex9Class {
	public static void main(String[] args) {
		int N=1000;
	    int i, j, k;
	    int max, index;
	    int[] a = new int[6];//int a[6];
	    int[] ball = new int[49];//int ball[49];	    
 
	    Random rnd = new Random();//建立亂數的物件
 
	    try//FILE* fout;
	    {
		    FileWriter writer = new FileWriter("lotto.txt"); //fopen("lotto.txt" "w");
		    PrintWriter pw = new PrintWriter(writer);
 
		    for (k = 0; k < N;  k++)
		    {
		      //給每一顆球不同的重量 
		      for (i=0; i<49; i++)
		      {
		          //ball[i] = rand();
		    	  ball[i] = rnd.nextInt();////產生1個亂數
		      }
		      //取出最重的球(6次) 
		      for (i=0; i<6; i++)
		      {
		          max = 0; index = 0;
		          for (j=0; j<49; j++)
		          {
		              if (ball[j] > max)
		              {
		                  max =ball[j];
		                  index = j;
		              }
		          }
		          a[i] = index + 1;//最重的球編號 
		          ball[index] = 0; //把最重的球重量歸零 
		       }
		       System.out.printf("The number is %2d %2d %2d %2d %2d %2d\n", a[0], a[1], a[2], a[3], a[4], a[5]);
               pw.printf("%2d %2d %2d %2d %2d %2d", a[0], a[1], a[2], a[3], a[4], a[5]); pw.println();
		    }
		    writer.close();
	    }
	    catch (FileNotFoundException fe)
	    {
	    	System.out.printf(fe.getMessage());
	    }
	    catch (IOException fe)
	    {
	    	System.out.printf(fe.getMessage());
	    }
	}
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

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: ,

24
十二月

程式設計一程式 12/24: ex8

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

//ex8a
int compare( const int *arg1, const int *arg2 );
//對陣列a的6個元素是:a[0], a[1], ....a[5]排序
       qsort(a, 6, sizeof(int), compare);
int compare( const int *arg1, const int *arg2 )
{
   return *arg1-*arg2;
}
=========
//ex8b
qsort(bingo, 6, sizeof(int), compare );
//舊的陣列比較,沒有排序
for (i = 0; i&lt; 6; i++)
          {
              for (j = 0; j&lt; 6; j++)
              {
                  if (bingo[i] == a[j])
                       matches++;
              }
          }
//新的陣列比較,有排序
for (i = 0, j=0; i&lt; 6 &amp;&amp; j &lt; 6;   )
          {
              if (bingo[i] == a[j])
              {
                  i++; j++; matches++;
              }
              else if (bingo[i] &gt; a[j])
                   j++
              else //if (bingo[i] &lt; a[j])
                   i++;
          }
//ex8a.c 完整
#include <stdio.h>
#include <stdlib.h> 
#include <time.h> 
int compare( const int *arg1, const int *arg2 );
int main()
{
    int i, j, k, N, a[6];
    int ball[49], max, index;
    FILE* fout;
 
    scanf("%d", &N);
    srand((unsigned) time( NULL ) ); //設定亂數的啟始點
    fout = fopen("lotto.txt", "w");
    for (k = 0; k < N;  k++)
    {
      //給每一顆球不同的重量 
      for (i=0; i<49; i++)
      {
          ball[i] = rand();
      }
      //取出最重的球(6次) 
      for (i=0; i<6; i++)
      {
          max = 0; index = 0;
          for (j=0; j<49; j++)
          {
              if (ball[j] > max)
              {
                  max =ball[j];
                  index = j;
              }
          }
          a[i] = index + 1;//最重的球編號 
          ball[index] = 0; //把最重的球重量歸零 
       }
       //對陣列a的6個元素是:a[0], a[1], ....a[5]排序
       qsort(a, 6, sizeof(int), compare);
       printf("%2d %2d %2d %2d %2d %2d\n", a[0], a[1], a[2], a[3], a[4], a[5]);  
       fprintf(fout, "%2d %2d %2d %2d %2d %2d\n",a[0], a[1], a[2], a[3], a[4], a[5]);      
    }
    fclose(fout);
    return 0;
}
int compare( const int *arg1, const int *arg2 )
{
   return *arg1-*arg2;
}
//ex8b.c
#include <stdio.h>
int compare( const int *arg1, const int *arg2 );
int main()
{
    int N;
    int i, j, k, a[6], bingo[6], count[7];
    int cc, matches;
    FILE* fin;
 
    scanf("%d %d %d %d %d %d", 
          &bingo[0], &bingo[1], &bingo[2], &bingo[3],  &bingo[4],  &bingo[5]);
    qsort(bingo, 6, sizeof(int), compare );
 
    count[0] = count[1] = count[2] = count[3]= count[4]= count[5] = count[6] =0;
 
    fin = fopen("lotto-sort.txt", "r");
    cc = fscanf(fin, "%d %d %d %d %d %d", 
          &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
    while (cc == 6)
    {
          matches = 0;
          /*for (i = 0; i< 6; i++)
          {
              for (j = 0; j< 6; j++)
              {
                  if (bingo[i] == a[j])
                       matches++;
              }
          }*/
          for (i = 0, j=0; i< 6 && j < 6;   )
          {
              if (bingo[i] == a[j])
              {
                  i++; j++; matches++;
              }
              else if (bingo[i] > a[j])
                   j++
              else //if (bingo[i] < a[j])
                   i++; 
          } 
          count[matches]++;
          cc = fscanf(fin, "%d %d %d %d %d %d", 
                        &a[0], &a[1], &a[2], &a[3],  &a[4], &a[5]);
    }
    for (k = 6; k >=0; k--)
         printf("Match %d numbers = %5d\n", k, count[k]);
 
    fclose(fin);
    return 0;
}
int compare( const int *arg1, const int *arg2 )
{
   return *arg1-*arg2;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

23
十二月

醫學資訊管理-NHIRD Ex2-12/23

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

//Form1.cs
private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            textBox1.Text = openFileDialog1.FileName;
        }
 
        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)
            {
                NHIRD_CD cd = ParseCDLine(line);
                int pos1 = cd.ACODE_ICD9_1.IndexOf("250");
                int pos2 = cd.ACODE_ICD9_2.IndexOf("250");
                int pos3 = cd.ACODE_ICD9_3.IndexOf("250");
                if (pos1 == 0 || pos2 == 0 || pos3 == 0)
                {
                    //sw.WriteLine(line);
                    DBEntry_CD dbe = new DBEntry_CD(cd);
                    InsertCDRecord(dbConnection, dbe);
                }
                line = sr.ReadLine();
            }
            sr.Close(); //sw.Close();
            dbConnection.Close();
        }
//
int InsertCDRecord(IDbConnection dbConnection, DBEntry_CD cd)
        {
            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;
            rowsAffected = dbCommand.ExecuteNonQuery();
 
 
            return rowsAffected;
        }
//把下面DBEntry_CD類別的定義加到NHIRD_CD.cs檔案
class DBEntry_CD
    {
        public string FEE_YM;
        public string APPL_TYPE;
        public string HOSP_ID;
        public DateTime APPL_DATE;
        public string CASE_TYPE;
        public int SEQ_NO;
 
        public string CURE_ITEM_NO1;
        public string CURE_ITEM_NO2;
        public string CURE_ITEM_NO3;
        public string CURE_ITEM_NO4;
 
        public string FUNC_TYPE;
        public DateTime FUNC_DATE;
        public DateTime TREAT_END_DATE;
 
        public DateTime ID_BIRTHDAY;
        public string ID;
 
        public string CARD_SEQ_NO;
        public string GAVE_KIND;
        public string PART_NO;
 
        public string ACODE_ICD9_1;
        public string ACODE_ICD9_2;
        public string ACODE_ICD9_3;
 
        public string ICD_OP_CODE;
        public DateTime DRUG_DAY;
        public string MED_TYPE;
 
        public string PRSN_ID;
        public string PHAR_ID;
 
        public int DRUG_AMT;
        public int TREAT_AMT;
        public string TREAT_CODE;
        public int DIAG_AMT;
        public string DSVC_NO;
        public int DSVC_AMT;
        public string BY_PASS_CODE;
        public int T_AMT;
        public int PART_AMT;
        public int T_APPL_AMT;
        public string ID_SEX;
 
        public DBEntry_CD(NHIRD_CD rawCD)
        {
            FEE_YM = rawCD.FEE_YM;
            APPL_TYPE = rawCD.APPL_TYPE;
            HOSP_ID = rawCD.HOSP_ID;
            APPL_DATE = StrToDateTime(rawCD.APPL_DATE);
            CASE_TYPE = rawCD.CASE_TYPE;
            SEQ_NO = StrToInteger(rawCD.SEQ_NO);
 
            CURE_ITEM_NO1 = rawCD.CURE_ITEM_NO1;
            CURE_ITEM_NO2 = rawCD.CURE_ITEM_NO2;
            CURE_ITEM_NO3 = rawCD.CURE_ITEM_NO3;
            CURE_ITEM_NO4 = rawCD.CURE_ITEM_NO4;
 
            FUNC_TYPE = rawCD.FUNC_TYPE;
            FUNC_DATE = StrToDateTime(rawCD.FUNC_DATE);
            TREAT_END_DATE = StrToDateTime(rawCD.TREAT_END_DATE);
            ID_BIRTHDAY = StrToDateTime(rawCD.ID_BIRTHDAY);
            ID = rawCD.ID;
 
 
            CARD_SEQ_NO = rawCD.CARD_SEQ_NO;
            GAVE_KIND = rawCD.GAVE_KIND;
            PART_NO = rawCD.PART_NO;
            ACODE_ICD9_1 = rawCD.ACODE_ICD9_1;
            ACODE_ICD9_2 = rawCD.ACODE_ICD9_2;
            ACODE_ICD9_3 = rawCD.ACODE_ICD9_3;
            ICD_OP_CODE = rawCD.ICD_OP_CODE;
 
            DRUG_DAY = StrToDateTime(rawCD.DRUG_DAY);
 
            MED_TYPE = rawCD.MED_TYPE;
 
            PRSN_ID = rawCD.PRSN_ID;
            PHAR_ID = rawCD.PHAR_ID;
 
            DRUG_AMT = StrToInteger(rawCD.DRUG_AMT);
            TREAT_AMT = StrToInteger(rawCD.TREAT_AMT);
            TREAT_CODE = rawCD.TREAT_CODE;
 
            DIAG_AMT = StrToInteger(rawCD.DIAG_AMT);
            DSVC_NO = rawCD.DSVC_NO;
 
            DSVC_AMT = StrToInteger(rawCD.DSVC_AMT);
            BY_PASS_CODE = rawCD.BY_PASS_CODE;
 
            T_AMT = StrToInteger(rawCD.T_AMT);
            PART_AMT = StrToInteger(rawCD.PART_AMT);
            T_APPL_AMT = StrToInteger(rawCD.T_APPL_AMT);
            ID_SEX = rawCD.ID_SEX;
        }
        private DateTime StrToDateTime(string ss)
        {//YYYYMMDD
            DateTime dt = new DateTime(1911, 1, 1);
            if (ss.Length != 8)
                return dt;
 
            for (int i = 0; i < 8; i++)
            {
                if (!char.IsDigit(ss[i]))
                    return dt;
            }
 
            string yearStr = ss.Substring(0, 4);
 
            string monthStr = ss.Substring(4, 2);
            string dayStr = ss.Substring(6, 2);
            int year = int.Parse(yearStr);
            int month = int.Parse(monthStr);
            int day = int.Parse(dayStr);
            if (month > 12 || day > 31)
                return dt;
            return new DateTime(year, month, day);
        }
        private int StrToInteger(string ss)
        {
            return int.Parse(ss.Trim());
        }
    }

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

17
十二月

程式設計一程式 12/17: Quiz2

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

#include 
 #include <stdio.h>
int main(int argc, char *argv[])
{
    int i, P;
    int H, M, h, m, S, D, Total;
    FILE* fin;
 
    fin = fopen("q2.txt", "r");
 
    fscanf(fin, "%d\n", &P);
    for (i=0; i<P; i++)
    {
        fscanf(fin, "%d %d %d %d %d %d\n",
         &H, &M, &h, &m, &S, &D);
         if (m > M)
            Total = (h -H + 1) * S * D;
         else
            Total = (h -H) * S * D;
        printf("%d\n", Total);
    }
    fclose(fin);
    return 0;
} }}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,