delphi5.0 的internetexpress 中的cgi的数据库的问题(100分)

  • 主题发起人 主题发起人 zeusangel
  • 开始时间 开始时间
Z

zeusangel

Unregistered / Unconfirmed
GUEST, unregistred user!

您好!我做的一个CGI如下,有一个问题不明白,请多多指教。(数据库parasox, delphi5.0)
unit uwmWebClientStep2;
interface
uses
Windows, Messages, SysUtils, Classes, HTTPApp, Db, DBClient, XMLBrokr,
MidItems, CompProd, PagItems, MidProd, MConnect;
type
TWebModule1 = class(TWebModule)
dcomSeminars: TDCOMConnection;
mppDefault: TMidasPageProducer;
QueryForm1: TQueryForm;
QueryFieldGroup1: TQueryFieldGroup;
qtName: TQueryText;
qtAddress: TQueryText;
qtPhone: TQueryText;
qtPayMethod: TQueryText;
qrgPayMethod: TQueryRadioGroup;
xmlbTrainees: TXMLBroker;
cdsWorkShops: TClientDataSet;
cdsTrainees: TClientDataSet;
QueryButtons1: TQueryButtons;
sqbJoin: TSubmitQueryButton;
ppDefault: TPageProducer;
cdsRegJoiners: TClientDataSet;
ppReplyMessage: TPageProducer;
procedure mppDefaultHTMLTag(Sender: TObject;
Tag: TTag;
const TagString: String;
TagParams: TStrings;
var ReplaceText: String);
procedure WebModule1waJoinSeminarAction(Sender: TObject;
Request: TWebRequest;
Response: TWebResponse;
var Handled: Boolean);
procedure WebModule1waDefaultAction(Sender: TObject;
Request: TWebRequest;
Response: TWebResponse;
var Handled: Boolean);
procedure ppReplyMessageHTMLTag(Sender: TObject;
Tag: TTag;
const TagString: String;
TagParams: TStrings;
var ReplaceText: String);
private
{ Private declarations }
vJID : OleVariant;
aWSIDList : TStringList;
aWSNameList : TStringList;
aWSsaveList : TStringList;
public
{ Public declarations }
end;

var
WebModule1: TWebModule1;
implementation
{$R *.DFM}
const
sSeminars = 'Seminars';
sReplyMessage = 'ReplyMessage';
procedure TWebModule1.mppDefaultHTMLTag(Sender: TObject;
Tag: TTag;
const TagString: String;
TagParams: TStrings;
var ReplaceText: String);
function CreateSeminarsForm: String;
var
slContent : TStringList;

procedure AddCheckBoxControl;(过程建立checkbox)
var
sStr : String;
begin
sStr := '<input type="checkbox" name="' + cdsWorkShops.FieldByName('WSID').AsString + '" value="ON">';
slContent.Add('<td>');
slContent.Add(sStr);
slContent.Add('<font color="red">');
slContent.Add('请购买');
slContent.Add('</font>');
slContent.Add('</td>');
end;
procedure addtext;(这个过程中建立的text: 是给客户端输入数据的,但是我怎么把它的数据返回数据库中呢?)
var
ystr:string;
begin
ystr:='<input type="text" name="textfield">';
slcontent.add('<td>');
slcontent.Add(ystr);
slcontent.add('</td>');
end;

procedure AddFormTitle(sJoin, amount,sID , sName, sDate,sprice: String);
begin
slContent.Add('<tr>');
slContent.Add('<td>');
slContent.Add(sJoin);
slContent.Add('</td>');
slcontent.add('<td>');
slcontent.add(amount);
slcontent.add('</td>');

slContent.Add('<td>');
slContent.Add(sID);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(sName);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(sDate);
slContent.Add('</td>');
slcontent.add('<td>');
slcontent.add(sprice);
slcontent.add('</td>');
slContent.Add('</tr>');
end;

begin

try
slContent := TStringList.Create;
slContent.Add('<table border="1">');
//
AddFormTitle('购买','购买数量', '纸张型号', '纸张名称', '库存','价格');
//这个地方加入表头。
while not cdsWorkShops.Eofdo
begin
slContent.Add('<tr>');
AddCheckBoxControl;
//调用建立过程。
addtext;//这里面建立的text中返回的数据,我怎么样把它insert到数据库中呢?

slContent.Add('<td>');
slContent.Add(cdsWorkShops.FieldByName('WSID').AsString);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(cdsWorkShops.FieldByName('WSNAME').AsString);
slContent.Add('</td>');

slContent.Add('<td>');
slContent.Add(cdsWorkShops.FieldByName('save').AsString);
slContent.Add('</td>');
slContent.Add('<td>');//加入价格这一项。
slcontent.add(cdsworkshops.fieldbyname('price').asstring);
slcontent.add('</td>');
slContent.Add('</tr>');
cdsWorkShops.Next;
end;
// while
slContent.Add('</table>');
Result := slContent.Text;
finally
slContent.Free;
// free resources
end;
// try/finally
end;

begin
if (Tag = tgCustom) and (CompareText(TagString, sSeminars) = 0) then
begin
ReplaceText := '> ' + CreateSeminarsForm + '<INPUT TYPE=Hidden NAME="tt" VALUE="代刚"';
// ReplaceText := CreateSeminarsForm;
end
end;

procedure TWebModule1.WebModule1waJoinSeminarAction(Sender: TObject;
Request: TWebRequest;
Response: TWebResponse;
var Handled: Boolean);
var
sWSID: string;
begin
//
try
cdsTrainees.Active := True;
cdsRegJoiners.Active := True;
dcomSeminars.AppServer.GetJID(vJID);
aWSIDList := TStringList.Create;
//?WSID
aWSNameList := TStringList.Create;
//?WSName
aWSsaveList := TStringList.Create;
//?JDate
cdsTrainees.Insert;
//象这种要返回数据还不难。因为我知道它是什么啊!它是:Request.ContentFields.Values['Name'];
cdsTrainees.FieldByName('JID').Value := vJID;
cdsTrainees.FieldByName('Name').Value := Request.ContentFields.Values['Name'];
cdsTrainees.FieldByName('Address').Value := Request.ContentFields.Values['Address'];
cdsTrainees.FieldByName('Phone').Value := Request.ContentFields.Values['Phone'];
cdsTrainees.FieldByName('EMail').Value := Request.ContentFields.Values['EMail'];
cdsTrainees.FieldByName('PayMethod').Value := Request.ContentFields.Values['qrgPayMethod'];
cdsTrainees.FieldByName('JDate').Value := Now;
// cdstrainees.fieldbyname('amount').value:=request.
cdsTrainees.Post;
我怎么在这里加入INSERT在表中的数据呢?但是象上面提到的text中的数据又是什么东西呢?请帮帮我.
cdsWorkShops.First;
while not cdsWorkShops.Eofdo
begin
sWSID := cdsWorkShops.FieldByName('WSID').AsString;
if (Request.ContentFields.IndexOfName(sWSID) <> -1)then
begin
cdsRegJoiners.Insert;
cdsRegJoiners.FieldByName('WSID').Value := sWSID;
cdsRegJoiners.FieldByName('JID').Value := vJID;
cdsRegJoiners.Post;
aWSIDList.Add(sWSID);
aWSNameList.Add(cdsWorkShops.FieldByName('WSName').AsString);
aWSsaveList.Add(cdsWorkShops.FieldByName('save').AsString);
end;
cdsWorkShops.Next;
end;
// while
if (cdsRegJoiners.ChangeCount > 0) then
begin
cdsTrainees.ApplyUpdates(0);
cdsRegJoiners.ApplyUpdates(0);
end
else
begin
cdsTrainees.Cancel;
cdsRegJoiners.Cancel;
end;
finally // wrap up
cdsTrainees.Active := False;
cdsregJoiners.Active := False;
Response.Content := ppReplyMessage.Content;
aWSIDList.Free;
aWSNameList.Free;
aWSsaveList.Free;
end;
// try/finally
Handled := True;
end;

procedure TWebModule1.WebModule1waDefaultAction(Sender: TObject;
Request: TWebRequest;
Response: TWebResponse;
var Handled: Boolean);
begin
response.content:=response.content+formatdatetime ('dddd,mmmm,d,yyyy',now) ;
ppDefault.HTMLDoc.Text := mppDefault.Content;
Response.Content := response.content+ppDefault.Content;
Handled := True;
end;

procedure TWebModule1.ppReplyMessageHTMLTag(Sender: TObject;
Tag: TTag;
const TagString: String;
TagParams: TStrings;
var ReplaceText: String);
function AssemblyJoinLession: String;
var
iCount: Integer;
slContent : TStringList;
procedure AddFormTitle(sID ,sName, sDate: String);
begin
slContent.Add('<tr>');
slContent.Add('<td>');
slContent.Add(sID);
slContent.Add('</td>');
//slcontent.add('<td>');
// slcontent.add(amount);
// slcontent.add('</td>');
slContent.Add('<td>');
slContent.Add(sName);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(sDate);
slContent.Add('</td>');
slContent.Add('</tr>');
end;

begin

try
slContent := TStringList.Create;
slContent.Add('<table border="1">');
//?
AddFormTitle('型号', '名称', '库存');
slContent.Add('<tr>');
for iCount := 0 to (aWSIDList.Count - 1)do
// Iterate
begin
slContent.Add('<tr>');
slContent.Add('<td>');
slContent.Add(aWSIDList.Strings[iCount]);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(aWSNameList.Strings[iCount]);
slContent.Add('</td>');
slContent.Add('<td>');
slContent.Add(aWSsaveList.Strings[iCount]);
slContent.Add('</td>');
slContent.Add('</tr>');
end;
// while
slContent.Add('</table>');
Result := slContent.Text;
finally
slContent.Free;
end;
// try/finally
end;

begin
if (Tag = tgCustom) and (CompareText(TagString, sReplyMessage) = 0) then
begin
ReplaceText := '<P> 请确认: </P>';
ReplaceText := ReplaceText + AssemblyJoinLession;
ReplaceText := ReplaceText + '<P>' + '你的个人注册号是 : ' + '<font color="red" size="5"><strong>' + vJID + '</strong></font><font color="red"></font></P>';
ReplaceText := ReplaceText + '<P>请记下,以便用来在线查询.</P>';
ReplaceText := ReplaceText + '<P>谢谢你的订单,祝你有愉快的一天!</P>';
end
end;

end.
 
不知道你想问什么问题
 
an:
谢谢你的回应,我想问的是:如果在DELPHI中做的CGI,如果要获得由HTML生成的TEXT中的数据时应该怎么去做。请多多指教。
 
我感觉你的主要问题是Request.ContentFields名称没有对头;
如:‘<input type="text" name="textfield">‘在获取时为Request.ContentFields.Values['textfield'],如果不行,将你的程序寄过来
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
800
import
I
后退
顶部