学生成绩查分系统(Delphi脚本)
发表日期:2005-5-12 |
代码内容 //******************************// // 学生成绩查分系统(演示案例) // // 宁波宇讯信息技术有限公司 // // 2005年4月 www.sms2008.net // //******************************// //适用范围:短信网关服务器(专业版) //使用方法:编辑您的手机短信,如:CF#0503#003,并发送指定的手机号,如:13XXXXXXXXX,系统将返回该学生的成绩。 program KoSMSGateWay; var dbSchool: TADOConnection; //连接学校数据库 procedure ConnectDatabase; const SConnStr = ’Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%S;Persist Security Info=False’; begin dbSchool := TADOConnection.Create(nil); try dbSchool.Connected := False; dbSchool.LoginPrompt := False; dbSchool.ConnectionString := Format(SConnStr, [ProgramPath + ’脚本库\演示案例\DemoData.mdb’]); //ShowMessage(dbSchool.ConnectionString); dbSchool.Connected := True; except ShowMessage(’数据库连接失败!’); end; end; //关闭学校数据库连接 procedure DisconnectDatabase; begin dbSchool.Connected := False; dbSchool.Free; end; //查询学生成绩 StdNo=学号,StdPwd=查询密码 function QueryStudentScore(StdNo, StdPwd: string; var Content: string): Boolean; var Query: TADOQuery; begin Result := False; Query := TADOQuery.Create(nil); try Query.Connection := dbSchool; with Query do begin Close; SQL.Clear; SQL.Add(’SELECT * FROM 成绩表 WHERE (学号=:StdNo) AND (密码=:StdPwd)’); Parameters[0].Value := StdNo; //学号 Parameters[1].Value := StdPwd; //密码 Open; Result := not IsEmpty; if Result then begin Content := FieldByName(’姓名’).AsString + ’:你的期中考试成绩为,’ + ’语文:’ + FieldByName(’语文’).AsString + ’分/’ + ’数学:’ + FieldByName(’数学’).AsString + ’分/’ + ’英语:’ + FieldByName(’英语’).AsString + ’分’; end; Close; end; finally Query.Free; end; end; //----------------------------------------------------------------------------// //短信网关服务启动后的处理事件 procedure SMSGateWay_OnStartServer(Sender: TObject); begin //ShowMessage(’OnStartServer’); ConnectDatabase; end; //短信网关服务停止后的处理事件 procedure SMSGateWay_OnStopServer(Sender: TObject); begin //ShowMessage(’OnStopServer’); DisconnectDatabase; end; //收到新短信后的处理事件 procedure SMSGateWay_OnRecvSMS(Sender: TObject; SMSPhoneNo, SMSMessage: string; TimeStamp: TDateTime); var sCommand, sStdNo, sStdPwd, sContent: string; Len, Idx: Integer; Params: Variant; begin if Trim(SMSMessage) = ’000’ then Exit; //系统运行状态查询命令 //简单检查是不是手机号码查询 //if (not BeginWithString(’13’, SMSPhoneNo)) or (Length(SMSPhoneNo) <> 11) then Exit; //查分格式为:命令字#学号#查询密码,如:CF#0501#001 Len := StringToArray(SMSMessage, ’#’, Params); //拆分短信内容 if Len <= 2 then begin SendSMS(SMSPhoneNo, ’您的查询格式不正确。正确的格式为:命令字#学号#查询密码。如:CF#0501#001’, ’’); Exit; end; sCommand := Params[0]; Idx := StringPosArray(’CF#PW’, ’#’, sCommand); //定位命令字的位置 case Idx of 0: begin //CF sStdNo := Trim(Params[1]); //学生学号 sStdPwd := Params[2]; //查询密码 if not QueryStudentScore(sStdNo, sStdPwd, sContent) then //开始查成绩 sContent := ’您的身份验证无法通过!’; end; 1: sContent := ’修改密码的功能尚未实现。’; //PW -1: sContent := ’您的命令字不正确。正确的命令字可为:CF查分,PW修改密码。’; end; SendSMS(SMSPhoneNo, sContent, ’’); end; //发送短信后的处理事件 procedure SMSGateWay_OnSendSMS(Sender: TObject; SMSPhoneNo, SMSMessage, CustomNo: string; Succeed: Boolean); begin //ShowMessage(’OnSendSMS ’ + SMSPhoneNo + ’ / ’ + SMSMessage); end; begin end. |
宇讯短信 By 管理员
|
| |
|
|