//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
#include "CData.h"
#include "AddActive.h"
#include "xxMsg.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
if(!RegisterHotKey(Handle,2000,MOD_ALT,VK_F11)){
ShowMessage("热键注册失败");
}
if(!RegisterHotKey(Handle,2001,MOD_ALT,VK_F12)){
ShowMessage("热键注册失败");
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::OnHotKey(TMessage &Message){
//添加你的代码,你想要在按下热键时响应的代码
TForm::Dispatch(&Message);
if(Message.Msg==WM_HOTKEY&&Message.WParam==2000 )
{
// this->ActionAddActiveExecute(this);
}
if(Message.Msg==WM_HOTKEY&&Message.WParam==2001 )
{
// this->ActionShowMainExecute(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
UnregisterHotKey(Handle, 2000);//退出程序时注销热键
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormActivate(TObject *Sender)
{
AQActiveM->Requery();
// AQActiveM->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
AQ->Active=false;
AQ->SQL->Clear();
AQ->SQL->Add("SELECT top 1 TimeActive.* FROM TimeActive ORDER BY TimeActive.ID DESC;");
AQ->Open();
AnsiString dd=AQ->FieldValues["title"];
if(dd=="不登记"){
Beep(3000,1000);
// ShowMessage("提醒....");
if(!FormXxMsg->Active){
FormXxMsg->ShowModal();
}
}
AQ->Active =false;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionDelActiveExecute(TObject *Sender)
{
//删除当前主窗体上选择的记录,Action
AnsiString id=AQActiveM->FieldValues["ID"];
DM->con->Execute("delete * from timeactive where id="+id);
AQActiveM->Requery();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionNewActiveExecute(TObject *Sender)
{
//新增加一条记录,打开新活动窗体,Action
FormAddActive->AQActive->Append();
FormAddActive->AQActive->FieldValues["beginTime"]=Now();
FormAddActive->AQActive->FieldValues["title"]="新工作";
FormAddActive->Show();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ActionLastActiveExecute(TObject *Sender)
{
//打开活动窗体,显示最后一条记录Action
FormAddActive->AQActive->SQL->Clear();
FormAddActive->AQActive->SQL->Add("SELECT top 1 TimeActive.* FROM TimeActive ORDER BY TimeActive.ID DESC;");
FormAddActive->AQActive->Open();
FormAddActive->AQActive->Requery();
FormAddActive->Show();
}
//---------------------------------------------------------------------------
//显示主窗体Action
void __fastcall TFormMain::ActionShowMainExecute(TObject *Sender)
{
//打开主窗体,Action 如果原先关闭,打开它,如果原先打开,隐藏
if(this->Visible==false){
this->Show();
}else{
this->Hide();
updateIconExecute(Sender);
}
}
//-------------更新图标,function------------------------------------
void __fastcall TFormMain::updateIconExecute(TObject *Sender)
{
AQ->Active=false;
AQ->SQL->Clear();
AQ->SQL->Add("SELECT top 1 TimeActive.* FROM TimeActive ORDER BY TimeActive.ID DESC;");
AQ->Open();
AnsiString dd=AQ->FieldValues["title"];
if(dd=="不登记"){
MyTrayIcon->IconIndex=1;
}else{
MyTrayIcon->IconIndex=0;
}
AQ->Active =false;
}
//---------------------------------------------------------------------------
//隐藏主窗体,Action
void __fastcall TFormMain::ActionHideExecute(TObject *Sender)
{
this->Hide();
updateIconExecute(Sender);
}
//---------------------------------------------------------------------------
//更新记录,Action
void __fastcall TFormMain::ActionUpderRecoderExecute(TObject *Sender)
{
AQ->Active=false;
AQ->SQL->Clear();
AQ->SQL->Add("select * from timeactive order by begintime desc");
AQ->Open();
AQ->First();
while(!AQ->Eof){
String begintime=AQ->FieldValues["begintime"];
AQ->Next();
if(!AQ->Eof){
AQ->Edit();
AQ->FieldValues["endtime"]=begintime;
AQ->Post();
}
}
AQActiveM->Requery();
}
//---------------------------------------------------------------------------
//休息活动,Action
void __fastcall TFormMain::ActionSleepExecute(TObject *Sender)
{
AQ->Active=false;
AQ->SQL->Clear();
AQ->SQL->Add("select * from timeactive where begintime < date()");
AQ->Open();
AQ->Append();
AQ->FieldValues["beginTime"]=Now();
AQ->FieldValues["title"]="不登记";
AQ->FieldValues["project"]="1";
AQ->FieldValues["acttype"]="1";
AQ->Post();
AQActiveM->Requery();
}
//---------------------------------------------------------------------------
//打开当前记录,Action
void __fastcall TFormMain::ActionOpenCurExecute(TObject *Sender)
{
AnsiString id=AQActiveM->FieldValues["ID"];
FormAddActive->AQActive->Close();
FormAddActive->AQActive->SQL->Clear();
FormAddActive->AQActive->SQL->Add("SELECT top 1 TimeActive.* FROM TimeActive where id="+id);
FormAddActive->AQActive->Active=true;
FormAddActive->Show();
}
//---------------------------------------------------------------------------
//退出当前应用,Action
void __fastcall TFormMain::ActionExitExecute(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------