//---------------------------------------------------------------------------
#include <time.h>
#include <vcl.h>
#include <DateUtils.hpp>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CCALENDR"
#pragma resource "*.dfm"
AnsiString mies,naz;
int rok,dzien;
TForm1 *Form1;
//------------------------------------------------------------------------------
void TForm1:: wczytaj_mies(AnsiString m)
{
FILE *mies_wczytaj;
float wartosc_wczytaj;
int tmp=0;
ListView1->Visible=false;
Button2->Visible=false;
Button3->Visible=false;
if ( FileExists(m)==false)
{
if(Application->MessageBox("Miesiąc nie istnieje, utworzyć nowy?",
"Nowy miesiąc",MB_YESNO | MB_ICONQUESTION)== IDYES)
{
mies_wczytaj=fopen(m.c_str(),"w");
fclose(mies_wczytaj);
}
else
{
Button1->Enabled=true;
ComboBox1->Enabled=true;
ComboBox2->Enabled=true;
return;
}
}
ListView1->Visible=true;
Button2->Visible=true;
Button3->Visible=true;
mies_wczytaj=fopen(m.c_str(),"r");
for (int i=1; i<=4; i++)
{
fscanf(mies_wczytaj,"%f",&wartosc_wczytaj);
ListView1->Items->Item[i-1]->SubItems->Strings[0]=RoundTo((float)wartosc_wczytaj,-2);
}
fclose(mies_wczytaj);
Label1->Caption="Wybrałeś: "+ComboBox1->Text+" "+ComboBox2->Text;
Label1->Visible=true;
}
//---------------------------------------------------------------------------
void TForm1:: zapisz_mies(AnsiString m1,double godz_pracy, int feiertag,int urlop)
{
FILE *mies_zapisz;
double gp,ngdz;
int frt,url;
gp=StrToFloat(ListView1->Items->Item[0]->SubItems->Strings[0]);
ngdz=StrToFloat(ListView1->Items->Item[1]->SubItems->Strings[0]);
frt=StrToFloat(ListView1->Items->Item[2]->SubItems->Strings[0]);
url=StrToFloat(ListView1->Items->Item[3]->SubItems->Strings[0]);
gp=RoundTo(gp+godz_pracy,-2);
if (godz_pracy>8)
{
ngdz=RoundTo(ngdz+(godz_pracy-8),-2);
}
frt=frt+feiertag;
url=url+urlop;
mies_zapisz=fopen(m1.c_str(),"r+");
fprintf(mies_zapisz,"%.2f\n",(double)gp);
fprintf(mies_zapisz,"%.2f\n",(double)ngdz);
fprintf(mies_zapisz,"%i\n",frt);
fprintf(mies_zapisz,"%i\n",url);
fclose(mies_zapisz);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Form1->Color=clMedGray;
HMENU hMenu = GetSystemMenu(Handle, FALSE);
DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
Left=100;
Top=50;
Width=800;
Height=550;
StatusBar1->Width=45;
StatusBar1->Left=738;
StatusBar1->Top=491;
StatusBar2->Width=63;
StatusBar2->Left=675;
StatusBar2->Top=491;
StatusBar3->Width=675;
StatusBar3->Left=0;
StatusBar3->Top=491;
ComboBox1->Left=22;
ComboBox1->Width=89;
ComboBox1->Top=48;
ComboBox2->Left=115;
ComboBox2->Width=90;
ComboBox2->Top=48;
ComboBox3->Left=350;
ComboBox3->Width=75;
ComboBox3->Top=384;
ComboBox3->Visible=false;
Button1->Left=215;
Button1->Width=75;
Button1->Top=48;
Button1->Caption="Otwórz";
Button2->Left=215;
Button2->Width=75;
Button2->Top=48;
Button2->Visible=false;
Button2->Caption="Zmień";
Button3->Left=496;
Button3->Width=75;
Button3->Top=200;
Button3->Visible=false;
Button3->Caption="Edytuj";
Button4->Left=610;
Button4->Width=75;
Button4->Top=390;
Button4->Visible=false;
Button4->Caption="Zapisz";
ListView1->Color=clMedGray;
ListView1->Column[0]->Width=100;
ListView1->Left=408;
ListView1->Width=250;
ListView1->Top=64;
ListView1->Visible=false;
ListView1->Items->Add();
ListView1->Items->Item[0]->Caption = "Suma godzin:";
ListView1->Items->Item[0]->SubItems->Add("");
ListView1->Items->Item[0]->SubItems->Strings[0]="0";
ListView1->Items->Add();
ListView1->Items->Item[1]->Caption = "Nadgodziny:";
ListView1->Items->Item[1]->SubItems->Add("");
ListView1->Items->Item[1]->SubItems->Strings[0]="0";
ListView1->Items->Add();
ListView1->Items->Item[2]->Caption = "Święto (dni):";
ListView1->Items->Item[2]->SubItems->Add("");
ListView1->Items->Item[2]->SubItems->Strings[0]="0";
ListView1->Items->Add();
ListView1->Items->Item[3]->Caption = "Urlop (dni):";
ListView1->Items->Item[3]->SubItems->Add("");
ListView1->Items->Item[3]->SubItems->Strings[0]="0";
Label1->Left=432;
Label1->Top= 32;
Label1->Width=49;
Label1->Font->Color=clBlue;
Label1->Font->Size=12;
Label1->Caption="";
Label1->Visible=false;
Label2->Left=460;
Label2->Top= 352;
Label2->Width=38;
Label2->Visible=false;
Label3->Left=460;
Label3->Top= 392;
Label3->Width=38;
Label3->Visible=false;
Label4->Left=288;
Label4->Top= 320;
Label4->Width=220;
Label4->Font->Color=clBlue;
Label4->Font->Size=12;
Label4->Visible=false;
Label4->Caption="" ;
Label5->Left=368;
Label5->Top= 368;
Label5->Width=70;
Label5->Font->Size=8;
Label5->Visible=false;
Label5->Caption="Zmiana:" ;
DateTimePicker1->Left=450;
DateTimePicker1->Width=80;
DateTimePicker1->Top=368;
DateTimePicker1->Visible=false;
DateTimePicker1->Enabled=false;
DateTimePicker2->Left=450;
DateTimePicker2->Width=80;
DateTimePicker2->Top=408;
DateTimePicker2->Visible=false;
DateTimePicker2->Enabled=false;
RadioButton1->Left=192;
RadioButton1->Top=376;
RadioButton1->Width=100;
RadioButton1->Caption="Czas pracy";
RadioButton1->Visible=false;
RadioButton2->Left=192;
RadioButton2->Top=392;
RadioButton2->Width=100;
RadioButton2->Caption="Urlop";
RadioButton2->Visible=false;
RadioButton3->Left=192;
RadioButton3->Top=408;
RadioButton3->Width=100;
RadioButton3->Caption="Święto";
RadioButton3->Visible=false;
unsigned short dd,mm,yy;
Date().DecodeDate(&yy,&mm,&dd);
rok=yy;
dzien=dd;
MonthCalendar1->Visible=false;
MonthCalendar1->ShowToday=false;
switch(mm)
{
case 1: mies="Styczeń";break;
case 2: mies="Luty";break;
case 3: mies="Marzec";break;
case 4: mies="Kwiecień";break;
case 5: mies="Maj";break;
case 6: mies="Czerwiec";break;
case 7: mies="Lipiec";break;
case 8: mies="Sierpień";break;
case 9: mies="Wrzesień";break;
case 10: mies="Październik";break;
case 11: mies="Listopad";break;
case 12: mies="Grudzień";break;
}
ComboBox1->Text=mies;
ComboBox2->Text=yy;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
StatusBar1->SimpleText = TimeToStr(Time()); //Aktualny czas
StatusBar2->SimpleText = DateToStr(Date()); //Aktualna data
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Button1->Enabled=false;
ComboBox1->Enabled=false;
ComboBox2->Enabled=false;
Button2->Visible=true;
Button3->Visible=true;
Button3->Enabled=true;
naz=ComboBox1->Text;
rok=ComboBox2->Text.ToInt();
mies="Data/"+naz+"_"+rok+".mjh" ;
wczytaj_mies(mies); //pokazanie wyników miesiąca w listview1
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Button1->Enabled=true;
Button1->Visible=true;
Button2->Visible=false;
Button3->Visible=false;
Button4->Visible=false;
ComboBox1->Enabled=true;
ComboBox2->Enabled=true;
ComboBox3->Visible=false;
ListView1->Visible=false;
Label1->Visible=false;
Label2->Visible=false;
Label3->Visible=false;
Label4->Visible=false;
Label5->Visible=false;
RadioButton1->Visible=false;
RadioButton1->Checked=false;
RadioButton2->Visible=false;
RadioButton2->Checked=false;
RadioButton3->Visible=false;
RadioButton3->Checked=false;
DateTimePicker1->Visible=false;
DateTimePicker2->Visible=false;
DateTimePicker2->Enabled=false;
DateTimePicker2->Enabled=false;
MonthCalendar1->Visible=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int x=ComboBox1->Items->IndexOf(ComboBox1->Text)+1;
AnsiString *data= new AnsiString;
*data=ComboBox2->Text+"-"+x+"-"+dzien;
MonthCalendar1->Date=*data;
delete data;
Button3->Enabled=false;
Label2->Visible=true;
Label2->Enabled=false;
Label3->Visible=true;
Label3->Enabled=false;
Label4->Caption="Edytujesz: "+MonthCalendar1->Date.DateString();
MonthCalendar1->Visible=true;
RadioButton1->Visible=true;
RadioButton1->Checked=true;
RadioButton2->Visible=true;
RadioButton3->Visible=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
naz=ComboBox1->Text;
rok=ComboBox2->Text.ToInt();
mies="Data/"+naz+"_"+rok+".mjh" ;
double godzin_pracy;
int g_d;
if (RadioButton1->Checked==true)
{
TDateTime czas_wejscia, czas_wyjscia;
ComboBox3->Text="Wybierz...";
ComboBox3->Enabled=false;
DateTimePicker1->Enabled=false;
DateTimePicker2->Enabled=false;
czas_wejscia=DateTimePicker1->Time;
czas_wyjscia=DateTimePicker2->Time;
if (czas_wejscia<czas_wyjscia) g_d = MinutesBetween(czas_wyjscia,czas_wejscia);
else g_d = fabs(MinutesBetween(czas_wejscia,czas_wyjscia)-1440);
godzin_pracy=RoundTo((float)g_d/60,-2);
Label6->Caption=(String)g_d;
}
Button2->Enabled=true;
Button4->Enabled=false;
RadioButton1->Checked=false;
RadioButton2->Checked=false;
RadioButton3->Checked=false;
zapisz_mies(mies,godzin_pracy,1,2);
wczytaj_mies(mies);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MonthCalendar1Click(TObject *Sender)
{
Button4->Visible=true;
Button4->Enabled=false;
RadioButton2->Checked=false;
RadioButton3->Checked=false;
Label2->Visible=true;
Label2->Enabled=false;
Label3->Visible=true;
Label3->Enabled=false;
Label4->Caption="Edytujesz: "+MonthCalendar1->Date.DateString();
Label5->Visible=true;
ComboBox3->Visible=true;
DateTimePicker1->Visible=true;
DateTimePicker1->Enabled=false;
DateTimePicker2->Visible=true;
DateTimePicker2->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox3Change(TObject *Sender)
{
Button4->Visible=true;
Button4->Enabled=true;
Label2->Visible=true;
Label2->Enabled=true;
Label3->Visible=true;
Label3->Enabled=true;
DateTimePicker1->Enabled=true;
DateTimePicker2->Enabled=true;
int nr_zmiany=ComboBox3->Items->IndexOf(ComboBox3->Text)+1;
switch (nr_zmiany)
{
case 1: DateTimePicker1->Time=TDateTime("07:00");
DateTimePicker2->Time=TDateTime("15:30");break;
case 2: DateTimePicker1->Time=TDateTime("14:00");
DateTimePicker2->Time=TDateTime("22:30");break;
case 3: DateTimePicker1->Time=TDateTime("22:00");
DateTimePicker2->Time=TDateTime("06:30");break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
Button4->Visible=true;
Button4->Enabled=false;
Label2->Visible=true;
Label2->Caption="Wejście:";
Label3->Visible=true;
Label3->Caption="Wyjście:";
Label4->Visible=true;
Label5->Visible=true;
ComboBox3->Visible=true;
ComboBox3->Enabled=true;
DateTimePicker1->Visible=true;
DateTimePicker1->Kind=dtkTime;
DateTimePicker1->Format=("HH:mm");
DateTimePicker2->Visible=true;
DateTimePicker2->Kind=dtkTime;
DateTimePicker2->Format=("HH:mm");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
Button4->Visible=true;
Button4->Enabled=true;
Label2->Visible=true;
Label2->Enabled=true;
Label2->Caption="Od";
Label3->Visible=true;
Label3->Enabled=true;
Label3->Caption="Do:";
Label4->Visible=true;
Label5->Visible=false;
ComboBox3->Visible=false;
DateTimePicker1->Kind=dtkDate;
DateTimePicker1->Format=("dd-MM-yyyy");
DateTimePicker1->Visible=true;
DateTimePicker1->Enabled=true;
DateTimePicker1->Date=MonthCalendar1->Date.DateString();
DateTimePicker2->Kind=dtkDate;
DateTimePicker2->Format=("dd-MM-yyyy");
DateTimePicker2->Visible=true;
DateTimePicker2->Enabled=true;
DateTimePicker2->Date=MonthCalendar1->Date.DateString();
}
//---------------------------------------------------------------------------
Odświeżę temat bo nie rozwiązałem problemu. wkleję pełny kod, chociaż nie bardzo chę zaśmiecać forum.... A przy okazji... Wszelkie wytykanie błędów będzie mile widziane :) Pozdrawiam, Mariusz.