python26.dll_ironpython 调用dll 示例

1 #encoding: gb23122 import clr3 import sys4 from System import *

5 fromSystem.Threading import Thread, ThreadStart6 import socket7 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 classMainForm(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.trans59 #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.clearout66

67 #add the controls to the form68 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.Text78 sOut=cope_with(sIn)79 self.output.Text=sOut80 print "sIn:"+sIn81

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 "挂号建档交易输出:"+sOut94 returnsOut95 elif transType==02:96 #补档97 print "02补档交易开始"

98 sOut=Service.CompleteDocument(sIn)99 print "补档交易输出:"+sOut100 returnsOut101 elif transType==03:102 #挂号103 print "03挂号交易开始"

104 sOut=Service.Register(sIn)105 print "挂号交易输出:"+sOut106 returnsOut107 elif transType==04:108 #缴费预结算109 print "04缴费预结算交易开始"

110 sOut=Service.PrePurchase(sIn)111 print "缴费预结算输出:"+sOut112 returnsOut113 elif transType==05:114 #缴费结算115 print "05缴费结算交易开始"

116 sOut=Service.Purchase(sIn)117 print "缴费结算输出:"+sOut118 returnsOut119 elif transType==06:120 #缴纳预交金121 print "06缴纳预交金"

122 sOut=Service.AddInpatientPrepay(sIn)123 returnsOut124 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:"+sIn143 sOut=cope_with(sIn)144 length=0

145 for i insOut: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:"+length156 n=len(length)157 if n<4:158 for i in range(4-n):159 length='0'+length160 print "4length:"+length161

162

163 #sLen='%04d'%len(sOut)164 #print "sout length:"+sLen165 sOutData=length+sOut166 sOutData=sOutData.encode('gb2312')167 print "outResult:"+sOutData168 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值