1 #encoding: gb2312 2 import clr 3 import sys 4 from System import * 5 from System.Threading import Thread, ThreadStart 6 import socket 7 clr.AddReferenceByPartialName("System.Windows.Forms") 8 clr.AddReferenceByPartialName("System.Drawing") 9 from System.Windows.Forms import * 10 from System.Drawing import * 11 12 clr.AddReferenceToFile("HIS.YYT.dll") 13 from HIS.YYT import * 14 HOST='127.0.0.1' 15 PORT = 8888 16 17 class MainForm(Form): 18 def __init__(self): 19 #define the layout of the form 20 self.Text="YCAdaptor" 21 self.Name="YCAdaptor" 22 self.Height=350 23 self.Width=400 24 25 #define the label for the input Message 26 self.inputLabel=Label() 27 self.inputLabel.Text="input" 28 self.inputLabel.Location=Point(180,25) 29 self.inputLabel.Height=20 30 self.inputLabel.Width=50 31 32 #define the textbox for the input field 33 self.input=TextBox() 34 self.input.Location=Point(50,70) 35 self.input.Height=80 36 self.input.Width=300 37 38 #define the label for the output Message 39 self.outputLabel=Label() 40 self.outputLabel.Text="output" 41 self.outputLabel.Location=Point(180,150) 42 self.outputLabel.Height=20 43 self.outputLabel.Width=50 44 45 #define the textbox for the output field 46 self.output=TextBox() 47 self.output.Location=Point(50,180) 48 self.output.Height=30 49 self.output.Width=300 50 51 52 #define send button to get the input msg and send to his 53 self.send=Button() 54 self.send.Text="Send" 55 self.send.Location=Point(50,230) 56 self.send.Height=30 57 self.send.Width=50 58 self.send.Click += self.trans 59 #define clear button to clean the output field 60 self.clear=Button() 61 self.clear.Text="Clear" 62 self.clear.Location=Point(200,230) 63 self.clear.Height=30 64 self.clear.Width=50 65 self.clear.Click += self.clearout 66 67 #add the controls to the form 68 self.Controls.Add(self.inputLabel) 69 self.Controls.Add(self.input) 70 self.Controls.Add(self.outputLabel) 71 self.Controls.Add(self.output) 72 self.Controls.Add(self.send) 73 self.Controls.Add(self.clear) 74 self.CenterToScreen() 75 76 def trans(self,data,event): 77 sIn=self.input.Text 78 sOut=cope_with(sIn) 79 self.output.Text=sOut 80 print "sIn:"+sIn 81 82 def clearout(self,data,event): 83 self.output.Text="" 84 85 def cope_with(sIn): 86 transType=int(sIn[0:2]) 87 sIn=sIn[2:len(sIn)] 88 #sIn=sIn.decode('gb2312') 89 if transType==01: 90 #挂号建档 91 print "01挂号建档交易开始" 92 sOut=Service.RegisterAndEnroll(sIn) 93 print "挂号建档交易输出:"+sOut 94 return sOut 95 elif transType==02: 96 #补档 97 print "02补档交易开始" 98 sOut=Service.CompleteDocument(sIn) 99 print "补档交易输出:"+sOut 100 return sOut 101 elif transType==03: 102 #挂号 103 print "03挂号交易开始" 104 sOut=Service.Register(sIn) 105 print "挂号交易输出:"+sOut 106 return sOut 107 elif transType==04: 108 #缴费预结算 109 print "04缴费预结算交易开始" 110 sOut=Service.PrePurchase(sIn) 111 print "缴费预结算输出:"+sOut 112 return sOut 113 elif transType==05: 114 #缴费结算 115 print "05缴费结算交易开始" 116 sOut=Service.Purchase(sIn) 117 print "缴费结算输出:"+sOut 118 return sOut 119 elif transType==06: 120 #缴纳预交金 121 print "06缴纳预交金" 122 sOut=Service.AddInpatientPrepay(sIn) 123 return sOut 124 else: 125 return "error" 126 127 128 129 130 131 132 def serverThread(): 133 s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 134 s.bind((HOST,PORT)) 135 s.listen(10) 136 while 1: 137 print "Listening activated now starting to accept" 138 conn,addr=s.accept() 139 print "client connection accepted ,sending data:"+"addr:"+str(addr) 140 sIn=conn.recv(1024) 141 sIn=sIn.decode('gb2312') 142 print "recv data:"+sIn 143 sOut=cope_with(sIn) 144 length=0 145 for i in sOut: 146 n=ord(i) 147 if n>32: 148 if n<126: 149 length+=1 150 else: 151 length+=2 152 else: 153 length+=2 154 length=repr(length) 155 print "length:"+length 156 n=len(length) 157 if n<4: 158 for i in range(4-n): 159 length='0'+length 160 print "4length:"+length 161 162 163 #sLen='%04d'%len(sOut) 164 #print "sout length:"+sLen 165 sOutData=length+sOut 166 sOutData=sOutData.encode('gb2312') 167 print "outResult:"+sOutData 168 conn.send(sOutData) 169 print "connection closing" 170 conn.close() 171 print "connection closed" 172 173 174 175 176 177 t=Thread(ThreadStart(serverThread)) 178 t.Start() 179 myform=MainForm() 180 Application.Run(myform) 181 182 183 184