M
mawei0913_green
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个添加到数据库的操作,菜鸟想实现如下功能:当memo1中的汉字数目长度<70时,直接添加到数据库,若memo1中的数目长度>70个汉字时,分若干条添加到数据库中,菜鸟现把程序列出来,还望各位高人帮忙修改一下,谢谢!
控件有memo1,datetimepicker1,listbox(lbxlink2),adoquery(linkquery)
var idstr,contentstr,Telstr,receiveStr,headstr,namestr,sendstr,depstr,CutStr,riqi:string;
i,j,k,count,l:integer;
begin
//自己手工发送
if (memo1.Text='')or (lbxlink2.Items.Text='') then
begin
showmessage('联系人没有添加或内容为空');
exit;
end;
datetimepicker1.Time:=now;
datetimetostring(riqi,'yyyy-mm-dd hh:mm:ss',DateTimePicker1.DateTime+0.001);
contentstr:=trim(memo1.text);
CutStr:='';
//短信分割
j:=1;
count:=length(contentstr);
while (count>70) do
begin
j:=j+1;
count:=count-70;
end;
//发送
for i:=0 to lbxlink2.Items.Count-1 do
begin
linkquery.Close;
linkquery.SQL.Clear;
linkquery.SQL.Add('select id,Department,HeadShip,name,tel from colleague where name='''+trim(lbxlink2.Items)+'''');
linkquery.Open;
while not linkquery.Eof do
begin
idstr:=linkquery.fieldbyname('id').AsString; //id
depstr:=linkquery.fieldbyname('Department').AsString;
headstr:=linkquery.fieldbyname('HeadShip').AsString;
namestr:=linkquery.fieldbyname('name').AsString;
telstr:=linkquery.fieldbyname('tel').AsString;
linkquery.Next;
end;
if (telstr<>'') then
begin
for k:=0 to j do
begin
l:=k*70;
CutStr:='';
if (k=j-1) then
begin
cutstr:=copy(contentstr,l,length(contentstr)-l); //关键是这里,怎么好像没执行
end
else
begin
cutstr:=copy(contentstr,l,70); ////关键是这里,怎么好像没执行
end;
with sendquery do
begin
Close;
SQL.Clear;
SQL.Add('insert into messages(id,time_s,Priority,operator,sender,receiver,tel,content,flag) values('''+trim(idstr)+''','''+trim(riqi)+''',12,'''+trim(depstr)+''','''+trim(headstr)+''','''+trim(namestr)+''','''+trim(telstr)+''','''+trim(cutstr)+''',0)');
try
ExecSQL ;
showmessage('发送成功');
except
messagedlg('数据库连接失败,请检查连接是否成功',mtwarning,[mbok],0);
exit;
end;
end;
end;
end;
end;
end;
控件有memo1,datetimepicker1,listbox(lbxlink2),adoquery(linkquery)
var idstr,contentstr,Telstr,receiveStr,headstr,namestr,sendstr,depstr,CutStr,riqi:string;
i,j,k,count,l:integer;
begin
//自己手工发送
if (memo1.Text='')or (lbxlink2.Items.Text='') then
begin
showmessage('联系人没有添加或内容为空');
exit;
end;
datetimepicker1.Time:=now;
datetimetostring(riqi,'yyyy-mm-dd hh:mm:ss',DateTimePicker1.DateTime+0.001);
contentstr:=trim(memo1.text);
CutStr:='';
//短信分割
j:=1;
count:=length(contentstr);
while (count>70) do
begin
j:=j+1;
count:=count-70;
end;
//发送
for i:=0 to lbxlink2.Items.Count-1 do
begin
linkquery.Close;
linkquery.SQL.Clear;
linkquery.SQL.Add('select id,Department,HeadShip,name,tel from colleague where name='''+trim(lbxlink2.Items)+'''');
linkquery.Open;
while not linkquery.Eof do
begin
idstr:=linkquery.fieldbyname('id').AsString; //id
depstr:=linkquery.fieldbyname('Department').AsString;
headstr:=linkquery.fieldbyname('HeadShip').AsString;
namestr:=linkquery.fieldbyname('name').AsString;
telstr:=linkquery.fieldbyname('tel').AsString;
linkquery.Next;
end;
if (telstr<>'') then
begin
for k:=0 to j do
begin
l:=k*70;
CutStr:='';
if (k=j-1) then
begin
cutstr:=copy(contentstr,l,length(contentstr)-l); //关键是这里,怎么好像没执行
end
else
begin
cutstr:=copy(contentstr,l,70); ////关键是这里,怎么好像没执行
end;
with sendquery do
begin
Close;
SQL.Clear;
SQL.Add('insert into messages(id,time_s,Priority,operator,sender,receiver,tel,content,flag) values('''+trim(idstr)+''','''+trim(riqi)+''',12,'''+trim(depstr)+''','''+trim(headstr)+''','''+trim(namestr)+''','''+trim(telstr)+''','''+trim(cutstr)+''',0)');
try
ExecSQL ;
showmessage('发送成功');
except
messagedlg('数据库连接失败,请检查连接是否成功',mtwarning,[mbok],0);
exit;
end;
end;
end;
end;
end;
end;