📄 waichu.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "WaiChu.h"
#include "DM1.h"
#include "stdio.h"
#include "QuerySql.h"
#include "SortSelect.h"
#include "PrintSet.h"
#include "ColumnSelect.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormWaiChu *FormWaiChu;
//---------------------------------------------------------------------------
__fastcall TFormWaiChu::TFormWaiChu(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::FormClose(TObject *Sender,
TCloseAction &Action)
{
pAdd->Close();
pYgbh->Close();
pChaxun->Close();
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::ComboBoxJjChange(TObject *Sender)
{
MKs->Text = "";
MJs->Text = "";
MRq->Text = "";
MZsj->Text = "";
if (ComboBoxJj->Text == "外出")
{
LabelRq->Visible = true;
MRq->Visible = true;
MKs->EditMask = "99:99;1; ";
MJs->EditMask = "99:99;1; ";
LabelZsj->Caption = "小时)";
}
else if (ComboBoxJj->Text == "出差")
{
LabelRq->Visible = false;
MRq->Visible = false;
MKs->EditMask = "9999-99-99;1; ";
MJs->EditMask = "9999-99-99;1; ";
LabelZsj->Caption = "天)";
}
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtnSaveClick(TObject *Sender)
{
int nYgbh,nZsj;
AnsiString sYgxm,sBmmc,sBzmc,sJz,sRq,sKssj,sJssj,sYy,sSp,temp;
char pTemp[500];
if (Trim(MBh->Text) == "")
{
ShowMessage("请输入员工编号!");
MBh->SetFocus();
return;
}
if (Trim(ComboBoxJj->Text) == "")
{
ShowMessage("请选择外出类别!");
ComboBoxJj->SetFocus();
return;
}
if (ComboBoxJj->Text == "外出")
{
try
{
StrToDateTime(Trim(MRq->Text));
}
catch(...)
{
ShowMessage("请输入正确的日期!");
MRq->SetFocus();
return;
}
try
{
StrToTime(Trim(MKs->Text));
}
catch(...)
{
ShowMessage("请输入正确的时间!");
MKs->SetFocus();
return;
}
try
{
StrToTime(Trim(MJs->Text));
}
catch(...)
{
ShowMessage("请输入正确的时间!");
MJs->SetFocus();
return;
}
sRq = FormatDateTime("yyyy-mm-dd",StrToDate(Trim(MRq->Text)));
sKssj = sRq + " " + FormatDateTime("hh:mm",StrToTime(Trim(MKs->Text)));
sJssj = sRq + " " + FormatDateTime("hh:mm",StrToTime(Trim(MJs->Text)));
}
else
{
try
{
StrToDateTime(Trim(MKs->Text));
}
catch(...)
{
ShowMessage("请输入正确的日期!");
MKs->SetFocus();
return;
}
try
{
StrToDateTime(Trim(MJs->Text));
}
catch(...)
{
ShowMessage("请输入正确的日期!");
MJs->SetFocus();
return;
}
sKssj = FormatDateTime("yyyy-mm-dd",StrToDateTime(Trim(MKs->Text)));
sJssj = FormatDateTime("yyyy-mm-dd",StrToDateTime(Trim(MJs->Text)));
}
if (sJssj < sKssj)
{
ShowMessage("结束时间不能小于开始时间!");
MJs->SetFocus();
return;
}
if (Trim(MZsj->Text) == "")
{
ShowMessage("请输入总时间!");
MZsj->SetFocus();
return;
}
nYgbh = Trim(MBh->Text).ToInt();
sYgxm = Trim(EditXm->Text);
sBmmc = Trim(EditBm->Text);
sBzmc = Trim(EditBz->Text);
sJz = Trim(ComboBoxJj->Text);
nZsj = Trim(MZsj->Text).ToInt();
sYy = Trim(EditYy->Text);
sSp = Trim(EditSp->Text);
temp = "insert into kq_waichu(ygbh,ygxm,bmmc,bzmc,qjzl,kssj,jssj,zsj,qjyy,spren) values(";
sprintf(pTemp,"%d,'%s','%s','%s','%s','%s','%s',%d,'%s','%s')",nYgbh,sYgxm.c_str(),sBmmc.c_str(),sBzmc.c_str(),sJz.c_str(),sKssj.c_str(),sJssj.c_str(),nZsj,sYy.c_str(),sSp.c_str());
pAdd->Close();
pAdd->SQL->Clear();
pAdd->SQL->Add(temp);
pAdd->SQL->Add(pTemp);
try
{
pAdd->ExecSQL();
}
catch(Exception &exception)
{
ShowMessage("保存失败! \n因为:" + exception.Message);
return;
}
pAdd->Close();
MBh->Text = "";
EditXm->Text = "";
EditBm->Text = "";
EditBz->Text = "";
ComboBoxJj->Text = "";
MRq->Text = "";
MKs->Text = "";
MJs->Text = "";
MZsj->Text = "";
EditYy->Text = "";
EditSp->Text = "";
MBh->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::MBhExit(TObject *Sender)
{
if (Trim(MBh->Text) == "")
{
EditXm->Text = "";
EditBm->Text = "";
EditBz->Text = "";
return;
}
pYgbh->Close();
pYgbh->SQL->Clear();
pYgbh->SQL->Add("select holdername,departmentname,groupname from renshi where holderno = " + Trim(MBh->Text));
pYgbh->Open();
if (pYgbh->RecNo == 1)
{
EditXm->Text = pYgbh->FieldByName("holdername")->AsString;
EditBm->Text = pYgbh->FieldByName("departmentname")->AsString;
EditBz->Text = pYgbh->FieldByName("groupname")->AsString;
}
else
{
ShowMessage("没有编号为" + Trim(MBh->Text) + "的员工!");
EditXm->Text = "";
EditBm->Text = "";
EditBz->Text = "";
MBh->Text = "";
}
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::MZsjEnter(TObject *Sender)
{
try
{
StrToDateTime(Trim(MKs->Text));
StrToDateTime(Trim(MJs->Text));
}
catch(...)
{
MZsj->Text = "";
return;
}
TDateTime tKssj,tJssj;
tKssj = StrToDateTime(Trim(MKs->Text));
tJssj = StrToDateTime(Trim(MJs->Text));
if (tJssj < tKssj)
{
MZsj->Text = "";
return;
}
if (ComboBoxJj->Text == "外出")
{
MZsj->Text = Round((double)(tJssj - tKssj) * 24,0);
}
else if (ComboBoxJj->Text == "出差")
{
MZsj->Text = (int)(tJssj - tKssj) +1;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::FormKeyPress(TObject *Sender, char &Key)
{
if(Key==VK_RETURN)
{
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
Key=0;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::FormShow(TObject *Sender)
{
pChaxun->Close();
pChaxun->SQL->Clear();
pChaxun->SQL->Add("select lshao,ygbh,ygxm,bmmc,bzmc,qjzl,kssj,jssj,zsj,qjyy,spren from kq_waichu where 1 =2");
pChaxun->Open();
TIniFile* pIni = new TIniFile(ExtractFilePath(Application->ExeName) + "reckq.ini");
pIni->ReadSection(Name,ComboBoxCol->Items);
for (int i= 0; i< ComboBoxCol->Items->Count;i++)
{
pIni->ReadBool(Name,ComboBoxCol->Items->Strings[i],true);
for (int j = 0; j< DBGrid1->Columns->Count;j++)
{
if (DBGrid1->Columns->Items[j]->FieldName == ComboBoxCol->Items->Strings[i])
{
DBGrid1->Columns->Items[j]->Visible = pIni->ReadBool(Name,ComboBoxCol->Items->Strings[i],true);
break;
}
}
}
delete pIni;
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::FormCreate(TObject *Sender)
{
pAdd= GetQuery("QQingjia1");
pYgbh= GetQuery("QQingjia2");
pChaxun= GetQuery("QQingjia3");
if (pAdd == NULL || pYgbh == NULL || pChaxun == NULL)
{
ShowMessage("打开外出、出差表失败!");
BitBtnSave->Enabled = false;
return;
}
DataSource1->DataSet = pChaxun;
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtnDeleteClick(TObject *Sender)
{
if (!(pChaxun->RecNo >0)) return;
if ( Application->MessageBox("确定要取消该次外出、出差登记吗?","警告", MB_OKCANCEL) == IDOK)
{
pChaxun->Delete();
LabelCount->Caption = LabelCount->Caption.ToInt() - 1;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtnPrintClick(TObject *Sender)
{
TFormPrintSet *FormPrintSet = new TFormPrintSet(this);
FormPrintSet->SetDataSource(pChaxun);
FormPrintSet->SetGrid(DBGrid1);
FormPrintSet->EditTitle->Text = "临时外出&出差";
FormPrintSet->ShowModal();
delete FormPrintSet;
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtnSortClick(TObject *Sender)
{
TFormSortSelect *FormSortSelect = new TFormSortSelect(this);
FormSortSelect->SetItem(DBGrid1);
if (FormSortSelect->ShowModal() == mrOk)
pChaxun->Sort = FormSortSelect->sSort;
delete FormSortSelect;
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtnQueryClick(TObject *Sender)
{
AnsiString sNewSql;
TFormQuerySql *FormQuerySql = new TFormQuerySql(this);
FormQuerySql->pGrid = DBGrid1;
FormQuerySql->pQuery = pChaxun;
if(FormQuerySql->ShowModal() == mrCancel)
{
delete FormQuerySql;
return;
}
sNewSql = "select lshao,ygbh,ygxm,bmmc,bzmc,qjzl,kssj,jssj,zsj,qjyy,spren from kq_waichu " + FormQuerySql->sSql + " order by kssj";
pChaxun->Close();
pChaxun->SQL->Clear();
pChaxun->SQL->Add(sNewSql);
pChaxun->Open();
LabelCount->Caption = pChaxun->RecordCount;
delete FormQuerySql;
}
//---------------------------------------------------------------------------
void __fastcall TFormWaiChu::BitBtn1Click(TObject *Sender)
{
TFormColumnSelect *FormColumnSelect = new TFormColumnSelect(this);
FormColumnSelect->pGrid = DBGrid1;
FormColumnSelect->asWinName = Name;
FormColumnSelect->ShowModal();
delete FormColumnSelect;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -