unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, Menus, StdCtrls, dxGDIPlusClasses, WideStrings,
FMTBcd, DB, SqlExpr,DateUtils,IniFiles, DBClient, SimpleDS, GIFImg,ShellAPI,
DBXMySql, ImgList,Registry;
type
TMainForm = class(TForm)
StatusBar1: TStatusBar;
Timer1: TTimer;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
Panel1: TPanel;
Splitter1: TSplitter;
Panel2: TPanel;
Splitter2: TSplitter;
Panel3: TPanel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Button1: TButton;
Image1: TImage;
Timer2: TTimer;
Button2: TButton;
SQLConnection1: TSQLConnection;
SimpleDataSet1: TSimpleDataSet;
SimpleDataSet2: TSimpleDataSet;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N11: TMenuItem;
N10: TMenuItem;
SQLConnection2: TSQLConnection;
N12: TMenuItem;
Button3: TButton;
SimpleDataSet3: TSimpleDataSet;
ListBox1: TListBox;
ImageList1: TImageList;
ImageList2: TImageList;
Image2: TImage;
Timer3: TTimer;
PopupMenu1: TPopupMenu;
N13: TMenuItem;
N14: TMenuItem;
TrayIcon1: TTrayIcon;
N15: TMenuItem;
N16: TMenuItem;
N17: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure N10Click(Sender: TObject);
procedure N12Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
const Rect: TRect);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure Timer3Timer(Sender: TObject);
procedure N14Click(Sender: TObject);
procedure N13Click(Sender: TObject);
procedure TrayIcon1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure N15Click(Sender: TObject);
procedure N16Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure N17Click(Sender: TObject);
private
{ Private declarations }
Procedure Send_Shortmessage(Str : String);
procedure FirstRunSystem(bool:Boolean);
Procedure IPToPhoneList(IPStr : String);
Function IPSwitchInt(Str : String):Integer;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
Bitnum,YNnum : Integer;
Textcontent : String;
implementation
uses Unit2, Unit3, Unit4, Unit5, Unit6, DUALLIST;
{$R *.dfm}
procedure TMainForm.FirstRunSystem(bool:Boolean); //当传递过来的参数是false时候,删除开机自启动,是true则写注册表开机自启动
var
Reg :TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey :=HKEY_LOCAL_MACHINE;
try
Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',true);
if bool then
begin
Reg.WriteString(Extractfilename(Application.ExeName),Application.ExeName);
showmessage('添加成功!');
end
else
begin
Reg.DeleteValue(Extractfilename(Application.ExeName));
showmessage('删除成功!');
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;
//====发送短信过程=======
Procedure TMainForm.Send_Shortmessage(Str : String);
var
MHostnameIP,Musrname,Mpasswrd,Mport,Mdataname : String;
list,listTemp,listlog : TStringlist;
i : Integer;
S1,S2,S3,S4 : String;
begin
Textcontent := Str;
listTemp := TStringlist.Create;
//=======短信数据库参数读取=============
list := TStringlist.Create;
list.LoadFromFile(ExtractFilePath(Application.ExeName)+'MessageDataPara.cfg');
MHostnameIP := list[0];
Musrname := list[1];
Mpasswrd := list[2];
Mport := list[3];
Mdataname := list[4];
Try
//===连接短信数据库============
with SQLConnection2 do
begin
DriverName := 'mysql';
GetDriverFunc := 'getSQLDriverMYSQL';
LibraryName := 'dbxmys.dll';
VendorLib := 'libmysql.dll';
Params.Append('HostName='+MhostnameIP);
Params.Append('User_Name='+Musrname);
Params.Append('Password='+Mpasswrd);
Params.Append('port='+Mport);
Params.Append('Database='+MDataname);
Params.Append('ServerCharSet=gb2312');
LoginPrompt := false;
connected := True;
open;
end;
SimpleDataSet3.Connection :=SQLConnection2;
list.Clear;
list.LoadFromFile(ExtractFilePath(Application.ExeName)+'AllMessageMemberlist.cfg');
for i:=0 to list.Count-1 do
begin
if Trim(list[i])<>'' then
begin
listTemp.CommaText :=list[i];
S2 :=Textcontent;
S3 := listTemp[1];
S4 :=listTemp[0];
SimpleDataSet3.Close;
SimpleDataSet3.DataSet.CommandText :='SELECT id FROM message_all ORDER BY id DESC LIMIT 1';
SimpleDataSet3.Open;
S1 :=SimpleDataSet3.FieldByName('id').AsString;
S1 :=IntToStr(StrToInt(S1)+1);
SimpleDataSet3.DataSet.CommandText :='INSERT INTO message_all (id,msg_memo,user_receive_number,user_receive_name,msg_status,send_phone_port,msg_send_numbers,msg_product_system,msg_level) VALUES("'+S1+'","'+S2+'","'+S3+'","'+S4+'","0","0","1","MonitorNagiosSoft","2")';
SimpleDataSet3.Execute;
end
else
break;
end;
SimpleDataSet3.Active := False;
SQLConnection2.Connected := False;
SQLConnection2.Close;
simpledataSet3.Close;
list.Destroy;
listTemp.Destroy;
//showmessage('执行成功!');
Except
listlog := TStringlist.Create;
listlog.LoadFromFile(ExtractFilePath(Application.ExeName)+'log\Runlog.cfg');
listlog.Add(FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+' 反馈:写入短信记录时,发生异常错误!');
listlog.SaveToFile(ExtractFilePath(Application.ExeName)+'log\Runlog.cfg');
listlog.Destroy;
End;
end;
Function TMainForm.IPSwitchInt(Str : String):Integer; //转换字符串IP到整数数值
var
list : TStringlist;
begin
list := TStringlist.Create;
Str := StringReplace(Str,'.',' ',[rfReplaceAll]);
list.CommaText := Str;
Result := StrToInt(list[0])*16777216+StrToInt(list[1])*65536+StrToInt(list[2])*256+StrToInt(list[3]);
list.Destroy;
end;
//====根据IP在sms_ip_area表,phone_number表中找用户通讯录=============
Procedure TMainForm.IPToPhoneList(IPStr : String);
Var
IP_Str : String;
list,listlog,listTemp : TStringlist;
MHostnameIP,Musrname,Mpasswrd,Mport,Mdataname : String;
IP_arae_id,ip_num_min,ip_num_max : String;
IPVar,IPMin,IPMax : Integer;
IP_areaID,UserName,UserPhone : String;
manager_area_id : String;
i,j : Integer;
begin
IP_Str := IPSt