📄 main.~pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, Menus, ExtCtrls, Buttons, ToolWin, ADODB,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, smthread,
CPDrv, SPComm, OoMisc, AdPort;
type
TmainForm = class(TForm)
taskListView: TListView;
userListView: TListView;
MainMenu1: TMainMenu;
N4: TMenuItem;
N11: TMenuItem;
CoolBar1: TCoolBar;
xxglSpeedButton: TSpeedButton;
exitSpeedButton: TSpeedButton;
rwglSpeedButton: TSpeedButton;
hzglSpeedButton: TSpeedButton;
khglSpeedButton: TSpeedButton;
ljszSpeedButton: TSpeedButton;
jlljSpeedButton: TSpeedButton;
Panel1: TPanel;
Splitter1: TSplitter;
Panel2: TPanel;
smsStatusBar: TStatusBar;
groupTreeView: TTreeView;
Splitter2: TSplitter;
Panel3: TPanel;
runSpeedButton: TSpeedButton;
deleteSpeedButton: TSpeedButton;
task_infoSpeedButton: TSpeedButton;
change_timeSpeedButton: TSpeedButton;
jhrwSpeedButton: TSpeedButton;
stopSpeedButton: TSpeedButton;
fsdzSpeedButton: TSpeedButton;
N13: TMenuItem;
procedure exitSpeedButtonClick(Sender: TObject);
procedure khglSpeedButtonClick(Sender: TObject);
procedure xxglSpeedButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure rwglSpeedButtonClick(Sender: TObject);
procedure jhrwSpeedButtonClick(Sender: TObject);
procedure fsdzSpeedButtonClick(Sender: TObject);
procedure deleteSpeedButtonClick(Sender: TObject);
procedure change_timeSpeedButtonClick(Sender: TObject);
procedure jlljSpeedButtonClick(Sender: TObject);
procedure ljszSpeedButtonClick(Sender: TObject);
procedure runSpeedButtonClick(Sender: TObject);
procedure stopSpeedButtonClick(Sender: TObject);
procedure task_infoSpeedButtonClick(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure taskListViewSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure AppException(Sender: TObject; E: Exception);
procedure N13Click(Sender: TObject);
procedure hzglSpeedButtonClick(Sender: TObject);// 捕获异常
private
{ Private declarations }
public
{ Public declarations }
procedure ShowAllusers();//显示所有客户信息到列表中
procedure ShowAllgroups();//显示所有联系组信息到列表中
procedure ShowAlltasks();//显示所有任务信息到列表中
end;
var
mainForm: TmainForm;
implementation
uses client, data, task, changetime, connect, taskinfo, log, about, inbox,
other;
{$R *.dfm}
procedure TmainForm.ShowAllusers();
var
ListItem: TListItem;
begin
// 清除列表中的数据
userlistview.Clear;
useradoquery.First;
// 添加数据到列表中
while not useradoquery.Eof do
begin
ListItem:=userlistview.Items.Add;
ListItem.Caption:=useradoquery.Fields.Fields[1].AsString;
ListItem.SubItems.Add(useradoquery.Fields.Fields[2].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[0].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[4].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[5].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[6].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[7].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[8].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[9].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[10].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[3].AsString);
ListItem.SubItems.Add(useradoquery.Fields.Fields[11].AsString);
useradoquery.Next;
end;
end;
procedure TmainForm.ShowAllgroups();
var
group_clientadoquery:TADOQuery;
TreeNode:TTreeNode;
begin
// 清除列表中的数据
groupTreeview.Items.Clear;
// 检索新的数据
group_clientadoquery:=TADOQuery.Create(self);
group_clientadoquery.ConnectionString:=adodbconnectionstring;
// 取得所有群组名
// 取得所有与群组相关的客户信息
group_clientadoquery.SQL.Add('select groupname,mobile_telephone,username from '+
'[group_client] order by groupname,mobile_telephone');
group_clientadoquery.Open;
groupadoquery.First;
while not groupadoquery.Eof do
begin
TreeNode:=groupTreeview.Items.Add(nil,groupadoquery.Fields.Fields[0].AsString);
TreeNode.ImageIndex:=1;
TreeNode.SelectedIndex:=1;
while (not group_clientadoquery.Eof) and
(group_clientadoquery.Fields.Fields[0].AsString=TreeNode.Text) do
begin
groupTreeview.Items.AddChild(TreeNode,group_clientadoquery.Fields.Fields[1].AsString+
' '+group_clientadoquery.Fields.Fields[2].AsString);
group_clientadoquery.Next;
end;
groupadoquery.Next;
end;
//关闭 group_clientadoquery 对象
group_clientadoquery.Close;
//销毁 group_clientadoquery 对象
group_clientadoquery.Free;
end;
procedure TmainForm.ShowAlltasks();
var
ListItem: TListItem;
begin
// 清除列表中的数据
tasklistview.Clear;
taskadoquery.First;
// 添加数据到列表中
while not taskadoquery.Eof do
begin
ListItem:=tasklistview.Items.Add;
ListItem.ImageIndex:=2;
ListItem.Caption:=taskadoquery.Fields.Fields[0].AsString;
//判断该任务是否已完成
if taskadoquery.Fields.Fields[6].AsInteger>0 then
ListItem.SubItems.Add('等待')
else if taskadoquery.Fields.Fields[6].AsInteger=0 then
begin
ListItem.SubItems.Add('完成');
ListItem.ImageIndex:=4;
end;
ListItem.SubItems.Add(taskadoquery.Fields.Fields[2].AsString);
ListItem.SubItems.Add(taskadoquery.Fields.Fields[3].AsString);
ListItem.SubItems.Add(taskadoquery.Fields.Fields[4].AsString);
ListItem.SubItems.Add(taskadoquery.Fields.Fields[5].AsString);
ListItem.SubItems.Add(taskadoquery.Fields.Fields[6].AsString);
ListItem.SubItems.Add(taskadoquery.Fields.Fields[7].AsString);
taskadoquery.Next;
end;
end;
procedure TmainForm.exitSpeedButtonClick(Sender: TObject);
begin
close();
end;
procedure TmainForm.khglSpeedButtonClick(Sender: TObject);
begin
clientForm.ShowAllgroups;
clientForm.ShowAllusers;
clientForm.ShowModal;
end;
procedure TmainForm.xxglSpeedButtonClick(Sender: TObject);
begin
dataForm.Caption:='数据候选';
dataForm.ReadyforShow;
dataForm.ShowModal;
end;
procedure TmainForm.FormCreate(Sender: TObject);
begin
//捕获异常
Application.OnException := AppException;
//初始化
delete_rec_index:=0;
//设置程序标题
application.Title:='企业短信群发系统';
//生成线程对象
sm_sending_receiving:=smioThread.Create(true);
sm_sending_receiving.Priority:=tpLower;
// 设置连接数据库属性
adodbconnectionstring:='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=qxt.mdb;Persist Security Info=False';
//生成 connect_infoADOQuery 对象
connect_infoADOQuery:=TADOQuery.Create(self);
connect_infoADOQuery.ConnectionString:=adodbconnectionstring;
connect_infoADOQuery.SQL.Add('select comport,baud_speed from [connect_info]');
connect_infoADOQuery.Open;
//取得连接参数
comport:=connect_infoADOQuery.Fields.Fields[0].AsString;
baud_speed:=connect_infoADOQuery.Fields.Fields[1].AsString;
//用新的参数设置端口
smsApdComPort.ComNumber:=StrToInt(Copy(comport,4,1));
smsApdComPort.Baud:=StrToInt(baud_speed);
// 生成 birth_year,company,department,job,occupation,income,address 对象
birth_yearadoquery:=TADOQuery.Create(self);//出生年
birth_yearadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索出生年数据
birth_yearadoquery.SQL.Add('select year from [birth_year]');
birth_yearadoquery.Open;
companyadoquery:=TADOQuery.Create(self);//公司
companyadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索公司数据
companyadoquery.SQL.Add('select name from [company]');
companyadoquery.Open;
departmentadoquery:=TADOQuery.Create(self);//部门
departmentadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索部门数据
departmentadoquery.SQL.Add('select name from [department]');
departmentadoquery.Open;
jobadoquery:=TADOQuery.Create(self);//职位
jobadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索职位数据
jobadoquery.SQL.Add('select name from [job]');
jobadoquery.Open;
occupationadoquery:=TADOQuery.Create(self);//职业
occupationadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索职业数据
occupationadoquery.SQL.Add('select name from [occupation]');
occupationadoquery.Open;
incomeadoquery:=TADOQuery.Create(self);//收入情况
incomeadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索收入数据
incomeadoquery.SQL.Add('select itemdescribe from [income]');
incomeadoquery.Open;
addressadoquery:=TADOQuery.Create(self);//地址
addressadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索地址数据
addressadoquery.SQL.Add('select address from [address]');
addressadoquery.Open;
groupadoquery:=TADOQuery.Create(self);//群组
groupadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索群组名数据
groupadoquery.SQL.Add('select name from [group] order by name');
groupadoquery.Open;
useradoquery:=TADOQuery.Create(self);//客户信息
useradoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索群组名数据
useradoquery.SQL.Add('select * from [client_info]');
useradoquery.Open;
rcyyadoquery:=TADOQuery.Create(self);//日常用语
rcyyadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索日常用语数据
rcyyadoquery.SQL.Add('select content from [rcyy]');
rcyyadoquery.Open;
jrwhadoquery:=TADOQuery.Create(self);//节日问候
jrwhadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索节日问候数据
jrwhadoquery.SQL.Add('select content from [jrwh]');
jrwhadoquery.Open;
gsxxadoquery:=TADOQuery.Create(self);//公司信息
gsxxadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索公司信息数据
gsxxadoquery.SQL.Add('select content from [gsxx]');
gsxxadoquery.Open;
zqzfadoquery:=TADOQuery.Create(self);//真情祝福
zqzfadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索真情祝福数据
zqzfadoquery.SQL.Add('select content from [zqzf]');
zqzfadoquery.Open;
sywhadoquery:=TADOQuery.Create(self);//商业问候
sywhadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索商业问候数据
sywhadoquery.SQL.Add('select content from [sywh]');
sywhadoquery.Open;
jddbadoquery:=TADOQuery.Create(self);//经典对白
jddbadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索经典对白数据
jddbadoquery.SQL.Add('select content from [jddb]');
jddbadoquery.Open;
ymgxadoquery:=TADOQuery.Create(self);//幽默搞笑
ymgxadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索幽默搞笑数据
ymgxadoquery.SQL.Add('select content from [ymgx]');
ymgxadoquery.Open;
blxxadoquery:=TADOQuery.Create(self);//保留信息
blxxadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索保留信息数据
blxxadoquery.SQL.Add('select content from [blxx]');
blxxadoquery.Open;
//检索任务信息
taskadoquery:=TADOQuery.Create(self);
taskadoquery.ConnectionString:=adodbconnectionstring;
//从数据库中检索出生年数据
taskadoquery.SQL.Add('select * from [task]');
taskadoquery.Open;
self.ShowAllusers;//显示所有客户信息到列表中
self.ShowAllgroups;//显示所有联系组信息到列表中
self.ShowAlltasks;//显示所有任务信息到列表中
//显示当前状态
smsStatusBar.Panels.Items[0].Text:='系统空闲';
end;
procedure TmainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//销毁 connect_infoADOQuery 对象
connect_infoADOQuery.Close;
connect_infoADOQuery.Free;
// 销毁 birth_year,company,department,job,occupation,income,address,group
// rcyy,jrwh,gsxx,zczf,sywh,jddb,ymgx,blxx 对象
birth_yearadoquery.Close;//出生年
birth_yearadoquery.Free;
companyadoquery.Close;//公司
companyadoquery.Free;
departmentadoquery.Close;//部门
departmentadoquery.Free;
jobadoquery.Close;//职位
jobadoquery.Free;
occupationadoquery.Close;//职业
occupationadoquery.Free;
incomeadoquery.Close;//收入
incomeadoquery.Free;
addressadoquery.Close;//地址
addressadoquery.Free;
groupadoquery.Close;//群组
groupadoquery.Free;
useradoquery.Close;//客户信息
useradoquery.Free;
rcyyadoquery.Close;//日常用语
rcyyadoquery.Free;
jrwhadoquery.Close;//节日问候
jrwhadoquery.Free;
gsxxadoquery.Close;//公司信息
gsxxadoquery.Free;
zqzfadoquery.Close;//真诚祝福
zqzfadoquery.Free;
sywhadoquery.Close;//商业问候
sywhadoquery.Free;
jddbadoquery.Close;//经典对白
jddbadoquery.Free;
ymgxadoquery.Close;//幽默搞笑
ymgxadoquery.Free;
blxxadoquery.Close;//保留信息
blxxadoquery.Free;
// 销毁 taskadoquery 对象
taskadoquery.Close;
taskadoquery.Free;
try
//销毁线程
sm_sending_receiving.Terminate;
except
logForm.logMemo.Lines.Add('销毁线程出错!');
end;
try
//关闭端口
if smsApdComPort.Open then
smsApdComPort.Open:=False;
except
logForm.logMemo.Lines.Add('关闭通讯端口COM'+
IntToStr(smsApdComPort.ComNumber)+'出错!');
end;
try
//销毁端口对象
smsApdComPort.Free;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -