Public partial class readcard: FORM {// function for operating the IC card, encapsulated in the IC class [structlayout (layoutkind. sequential)] public unsafe class IC {// initialize the device [dllimport ("mwic_32.dll", entrypoint = "auto_init", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = callingconvention. stdcall)] public static extern int auto_init (INT port, int baud); // device password format [dllimport ("mwic_32.dll", entrypoint = "Setsc_md", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = callingconvention. stdcall)] public static extern int setsc_md (INT icdev, int mode); // get the current device status [dllimport ("mwic_32.dll", entrypoint = "get_status", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = callingconvention. stdcall)] public static extern int16 get_stat US (INT icdev, int16 * State); // disable the device Communication Interface [dllimport ("mwic_32.dll", entrypoint = "ic_exit", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = callingconvention. stdcall)] public static extern int ic_exit (INT icdev); // enable the device to beep [dllimport ("mwic_32.dll", entrypoint = "dv_beep", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = Ca Llingconvention. stdcall)] public static extern int dv_beep (INT icdev, int time); // write data to the IC card [dllimport ("mwic_32.dll", entrypoint = "swr_4442", setlasterror = true, charset = charset. ANSI, exactspelling = true, callingconvention = callingconvention. stdcall)] public static extern int swr_4442 (INT icdev, int offset, int Len, char * w_string); // check the card password [dllimport ("mwic_32.dll ", entrypoint = "csc_4442 ", Setlasterror = true, charset = charset. auto, exactspelling = true, callingconvention = callingconvention. winapi)] public static extern int16 csc_4442 (INT icdev, int Len, [financialas (unmanagedtype. lparray)] Byte [] p_string);} public readcard () {initializecomponent ();} // write the textbox data to the IC card private void button#click (Object sender, eventargs e) {// initialize int icdev = IC. auto_init (0, 9600); if (I Cdev <0) MessageBox. Show ("port initialization failed. Please check whether the interface line is correctly connected. "," Error message ", messageboxbuttons. OK, messageboxicon. information); int MD = IC. setsc_md (icdev, 1); // The device password format is unsafe {int16 status = 0; int16 result = 0; Result = IC. get_status (icdev, & status); If (result! = 0) {MessageBox. Show ("the current device status is incorrect! "); Int d1 = IC. ic_exit (icdev); // disable the device return;} If (status! = 1) {MessageBox. show ("insert IC Card"); int D2 = IC. ic_exit (icdev); // disable the device return ;}} unsafe {// the default password for the card is 6 F (password: ffffff ), the hexadecimal value of one f is 15, and the hexadecimal value of two F is 255. Byte [] Pwd = new byte [3] {255,255,255}; // byte [] Pwd = new byte [3] {0xff, 0xff, 0xff }; // char [] Pass = new ch {0xff, 0xff, 0xff}; int16 checkic_pwd = IC. csc_4442 (icdev, 3, PWD); If (checkic_pwd <0) {MessageBox. show ("Incorrect IC card password! "); Return;} Char STR = 'a'; int write =-1; for (Int J = 0; j <textbox1.text. length; j ++) {STR = convert. tochar (textbox1.text. substring (J, 1); write = IC. swr_4442 (icdev, 33 + J, textbox1.text. length, & Str);} If (write = 0) {int beep = IC. dv_beep (icdev, 20); // beep message box. show ("data has been successfully written into the IC card! ");} Else {MessageBox. Show (" An error occurred while writing data to the IC card! ") ;}} Int d = IC. ic_exit (icdev); // close the device // find the corresponding data oledbconnection con = new oledbconnection ("provider = Microsoft. jet. oledb.4.0; Data Source = "+" Price. mdb "+"; persist Security info = false "); oledbdataadapter DAP = new oledbdataadapter (" select * from worker where ICID = '"+ textbox1.text +"' ", con ); dataset DS = new dataset (); DAP. fill (DS, "table"); If (Ds. tables. count> 0) {textbox2.text = Ds. Tables [0]. rows [0] [0]. tostring (); textbox3.text = Ds. tables [0]. rows [0] [1]. tostring (); textbox4.text = Ds. tables [0]. rows [0] [2]. tostring (); textbox5.text = Ds. tables [0]. rows [0] [3]. tostring ();} else {MessageBox. show ("this user does not exist! ") ;}} Private void button2_click (Object sender, eventargs e) {application. Exit ();}}}