//动态库中的函数<br>//MFacility 为自定意类型<br>function State_100(var query: TADOQuery; shebei: MFacility; shuju:array of byte;idhao: integer):MFacility; StdCall;<br>var<br> tan:integer;<br><br> old_mod:integer;// 校验和 下位机返的<br> new_mod:integer;// 校验和 上位机计算<br> datalen:integer;// 要处理的数据长度<br> datahe:integer; // 要处理的数据和<br> cuowu:string; ///错误 ——医生操作设备<br> conerg:integer; //下位机的 监视 和 控制 状态<br> yunxing:integer; //下位机的运行状态<br> usecount:integer; //返回的使用次数<br> yun:string; //运行状态字符<br> yuangongid:string;//员工ID号<br> i_100:integer;<br>begin<br> try<br> datahe:=shuju[4];<br> datahe:=datahe+shuju[5];<br> conerg:=shuju[6];<br> datahe:=datahe+conerg;<br> yunxing:=bintoint(copy(inttobin(shuju[7]),29,4));<br> datahe:=datahe+shuju[7];<br> usecount:=shuju[8];//返回的使用次数<br> datahe:=datahe+usecount;<br> //取得下位机传上的参数中的校验和<br> old_mod:=shuju[9]; //old 校验和<br> new_mod:=datahe mod 256; //new 校验和<br> except<br> result := shebei;<br> exit;<br> end;<br>////////////////////////////<br> try<br> if old_mod=new_mod then<br> begin //****校验和正确****//——BEGIN<br> case yunxing of<br> 0: begin //****待机****//——BEGIN<br> if shebei.New_Carfare<>'' then<br> begin<br> //改写票号的使用状态<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Tmp_USING=0 where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //写入检查结束时间<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Employ set Degree=:ci,Endtime=:tim where Carfare=
h and Item_id=xm');<br> query.Parameters.ParamByName('ci').Value:=shebei.Call_Degree-shebei.TMP_Degree;<br> query.Parameters.ParamByName('tim').Value:=strtodatetime(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //改写有效票号表中的可用项目次数。<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Valid_num=Valid_num-1 where Carfare=
h and Item_id=:xm ');<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //清除无效票号<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Availability=0 where Valid_num=0'); //当TMP_Carfare 表中的 Availability=0 时触发器清除此票号,说明此号已无效<br> query.ExecSQL;<br><br> shebei.New_Carfare:='';<br> shebei.Item_ID:='';<br> shebei.Item_Type:=0;<br> shebei.Patient:='';<br> end;<br> //当第一次进行待机状态更改设备的<br> if shebei.zhuangtan<>0 then<br> begin<br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=0 where Equipment_id=:eid');<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> shebei.zhuangtan:=0;<br> end; //****待机****//——END<br> 1: begin //****使用****//——BEGIN<br> //****改写表中设备的状态*****//<br> if shebei.zhuangtan<>1 then<br> begin<br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=:sid where Equipment_id=:eid');<br> if shebei.Item_Type=5 then<br> query.Parameters.ParamByName('sid').Value:=6<br> else<br> query.Parameters.ParamByName('sid').Value:=1;<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> //****CT下位机上传次数少于软件中的次数****//<br> if shebei.TMP_Degree>usecount then<br> begin<br> //****修改余次数****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Use_num=:u_num where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('u_num').Value:=usecount;<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //****改临时使用次数****//<br> shebei.TMP_Degree:=usecount;<br> //****修改使用次数****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Employ set Degree=:u_num where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('u_num').Value:=shebei.Call_Degree-shebei.TMP_Degree;<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //******修改预热时间*****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update Warm_up set Warm_up_time=:wtime where Equipment_id=:eid');<br> query.Parameters.ParamByName('wtime').Value:=strtoint(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> //******增加CT触发时间******//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('insert into Touch_Off(Equipment_id,Availability_num,Touch_Off_time,Style,Doctor_id)');<br> query.SQL.Add('values
Equipment_id,:Availability_num,:Touch_Off_time,:Style,
octor_id)');<br> query.Parameters.ParamByName('Equipment_id').Value:=shebei.IDhao;<br> query.Parameters.ParamByName('Availability_num').Value:=1;<br> query.Parameters.ParamByName('Touch_Off_time').Value:=strtoint(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('Style').Value:=shebei.Item_Type;<br> query.Parameters.ParamByName('Doctor_id').Value:=shebei.Doctor_id;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> shebei.zhuangtan:=1;<br> end; //****使用****//——END<br> 2: begin //****非法关机****//——BEGIN<br> if shebei.zhuangtan<>2 then<br> begin<br> ////记非法使用一次<br> query.Close;<br> query.SQL.Clear;<br> query.sql.Add('insert into S_down(Equipment_id,S_down_time,State_id,Doctor_id)');<br> query.sql.Add('values
Equipment_id,:S_down_time,:State_id,
octor_id)');<br> query.Parameters.ParamByName('Equipment_id').Value:=shebei.IDhao;<br> query.Parameters.ParamByName('S_down_time').Value:=strtodatetime(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('Doctor_id').Value:=shebei.Doctor_id;<br> query.Prepared;<br> query.ExecSQL;<br> ////改写票号的项目可用次数<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Valid_num=Valid_num-1,Tmp_USING=0 where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br><br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=2 where Equipment_id=:eid');<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> shebei.zhuangtan:=2;<br> end; //****非法关机****//——END<br> 4: begin //****开放使用****//——BEGIN<br> if shebei.zhuangtan<>4 then<br> begin<br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=4 where Equipment_id=:eid');<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> shebei.zhuangtan:=4; <br> end; //****开放使用****//——END<br> 6: begin //****就绪****//——BEGIN<br> shebei.Clean_Heft:=shuju[4];<br> shebei.Overall_Heft:=shuju[5];<br> if shebei.New_Carfare<>'' then<br> begin<br> //改写票号的使用状态<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Tmp_USING=0 where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //写入检查结束时间<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Employ set Degree=:ci,Endtime=:tim where Carfare=
h and Item_id=xm');<br> query.Parameters.ParamByName('ci').Value:=shebei.Call_Degree-shebei.TMP_Degree;<br> query.Parameters.ParamByName('tim').Value:=strtodatetime(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //改写有效票号表中的可用项目次数。<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Valid_num=Valid_num-1 where Carfare=
h and Item_id=:xm ');<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //清除无效票号<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Availability=0 where Valid_num=0'); //当TMP_Carfare 表中的 Availability=0 时触发器清除此票号,说明此号已无效<br> query.ExecSQL;<br><br> shebei.New_Carfare:='';<br> shebei.Item_ID:='';<br> shebei.Item_Type:=0;<br> shebei.Patient:='';<br> end;<br> //当第一次进行待机状态更改设备的<br> if shebei.zhuangtan<>0 then<br> begin<br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=6 where Equipment_id=:eid');<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> shebei.zhuangtan:=6;<br> end; //****就绪****//——END<br> 7: begin //****使用后延时****//——BEGIN<br> if shebei.TMP_Degree>usecount then<br> begin<br> //****修改余次数****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Carfare set Use_num=:u_num where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('u_num').Value:=usecount;<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //****改临时使用次数****//<br> shebei.TMP_Degree:=usecount;<br> //****修改使用次数****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update TMP_Employ set Degree=:u_num where Carfare=
h and Item_id=:xm');<br> query.Parameters.ParamByName('u_num').Value:=shebei.Call_Degree-shebei.TMP_Degree;<br> query.Parameters.ParamByName('ph').Value:=shebei.New_Carfare;<br> query.Parameters.ParamByName('xm').Value:=shebei.Item_ID;<br> query.Prepared;<br> query.ExecSQL;<br> //******修改预热时间*****//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('update Warm_up set Warm_up_time=:wtime where Equipment_id=:eid');<br> query.Parameters.ParamByName('wtime').Value:=strtoint(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> //******增加CT触发时间******//<br> query.Close;<br> query.SQL.Clear;<br> query.SQL.Add('insert into Touch_Off(Equipment_id,Availability_num,Touch_Off_time,Style,Doctor_id)');<br> query.SQL.Add('values
Equipment_id,:Availability_num,:Touch_Off_time,:Style,
octor_id)');<br> query.Parameters.ParamByName('Equipment_id').Value:=shebei.IDhao;<br> query.Parameters.ParamByName('Availability_num').Value:=1;<br> query.Parameters.ParamByName('Touch_Off_time').Value:=strtoint(formatdatetime('yyyy-mm-dd hh:mm:ss',now));<br> query.Parameters.ParamByName('Style').Value:=shebei.Item_Type;<br> query.Parameters.ParamByName('Doctor_id').Value:=shebei.Doctor_id;<br> query.Prepared;<br> query.ExecSQL;<br> end; <br> shebei.zhuangtan:=7;<br> end; //****使用后延时****//——END<br> 8: begin //****使用前延时****//——BEGIN<br> if shebei.zhuangtan<>8 then<br> begin<br> query.Close;<br> query.sql.Clear;<br> query.SQL.Add('update Equipment set State_id=8 where Equipment_id=:eid');<br> query.Parameters.ParamByName('eid').Value:=shebei.IDhao;<br> query.Prepared;<br> query.ExecSQL;<br> end;<br> end; //****使用前延时****//——END<br> end;<br> result := shebei;<br> end //****校验和正确****//——END<br> else<br> begin //****校验和不正确****//——BEGIN<br> result := shebei;<br> exit;<br> end; //****校验和不正确****//——END<br> except<br> result := shebei;<br> exit;<br> end;<br> query.Close;<br> query.SQL.Clear;<br> result := shebei;<br>end;