Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
39
Добавлен:
02.05.2014
Размер:
14.28 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PERFGRAP"
#pragma link "trayicon"
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::ComeTimer(TObject *Sender)
{
        if(Och->Caption.ToInt()==5)
        {
                Och_not->Caption=Och_not->Caption.ToInt()+1;

        }
        else
        {
                Och->Caption=Och->Caption.ToInt()+1;
                if(Och->Caption.ToInt()>5)
                {
                        Image1->Picture->LoadFromFile("img/6.bmp");
                }
                else
                {
                        Image1->Picture->LoadFromFile("img/"+Och->Caption+".bmp");
                }
        }

        if(Och_not->Caption.ToInt()>5)
        {
                Image2->Picture->LoadFromFile("img/not_wash.bmp");
                Image3->Picture->LoadFromFile("img/not_wash.bmp");
                Image4->Picture->LoadFromFile("img/not_wash.bmp");
                Image5->Picture->LoadFromFile("img/not_wash.bmp");
                Timer1->Enabled=false;
                Timer2->Enabled=false;
                Timer3->Enabled=false;
                Timer4->Enabled=false;
                Och->Caption="0";
                Och_not->Caption="0";
                Memo1->Lines->Add("Прорыв Дамбы!!! Идут ремонтные работы");
        }
        Come->Interval=AboutBox->come1->Text.ToInt() -AboutBox->come2->Text.ToInt()/2 + rand() % AboutBox->come2->Text.ToInt();
        V->Caption=Och->Caption.ToInt()*20;
        V->Caption=V->Caption+"%";
}
//---------------------------------------------------------------------------



void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
        if(Timer1->Enabled==false && Timer2->Enabled==false && Timer3->Enabled==false && Timer4->Enabled==false)
        {
                Timer5->Enabled=true;
        }
        if(Timer1->Enabled==false)
        {
                Timer1->Enabled=true;
        }
        if(Timer3->Enabled==false)
        {
                Timer2->Enabled=true;
        }
        if(Timer3->Enabled==false)
        {
                Timer3->Enabled=true;
        }
        if(Timer4->Enabled==false)
        {
                Timer4->Enabled=true;
        }
        Image2->Picture->LoadFromFile("img/wash.bmp");
        Image3->Picture->LoadFromFile("img/wash.bmp");
        Image4->Picture->LoadFromFile("img/wash.bmp");
        Image5->Picture->LoadFromFile("img/wash.bmp");
        Memo1->Lines->Add("Ошибка исправлена!!!");
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
        if(Och_not->Caption.ToInt()>0)
        {
                Timer1->Interval=AboutBox->wash11->Text.ToInt() -AboutBox->wash12->Text.ToInt()/2 + rand() % AboutBox->wash12->Text.ToInt();
                Och_not->Caption=Och_not->Caption.ToInt()-1;
                Image2->Visible=true;
        }
        else if(Och_not->Caption.ToInt()>0)
        {
                Timer1->Interval=AboutBox->wash11->Text.ToInt() -AboutBox->wash12->Text.ToInt()/2 + rand() % AboutBox->wash12->Text.ToInt();
                Och->Caption=Och->Caption.ToInt()-1;
                Image2->Visible=true;
        }
        else
        {
                Timer1->Interval=1;
                Image2->Visible=false;
        }
        if(Timer1->Interval>3)
        {
                Label7->Caption=Label7->Caption.ToInt()+1;
        }
        V->Caption=Och->Caption.ToInt()*20;
        V->Caption=V->Caption+"%";

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
        if(Och_not->Caption.ToInt()>0)
        {
                Timer2->Interval=AboutBox->wash11->Text.ToInt() -AboutBox->wash12->Text.ToInt()/2 + rand() % AboutBox->wash12->Text.ToInt();
                Och_not->Caption=Och_not->Caption.ToInt()-1;
                Image3->Visible=true;
        }
        else if(Och->Caption.ToInt()>0)
        {
                Timer2->Interval=AboutBox->wash21->Text.ToInt() -AboutBox->wash22->Text.ToInt()/2 + rand() % AboutBox->wash22->Text.ToInt();;
                Och->Caption=Och->Caption.ToInt()-1;
                Image3->Visible=true;
        }
        else
        {
                Timer2->Interval=1;
                Image3->Visible=false;
        }
        if(Timer2->Interval>3)
        {
                Label8->Caption=Label8->Caption.ToInt()+1;
        }
        V->Caption=Och->Caption.ToInt()*20;
        V->Caption=V->Caption+"%";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
        if(Och_not->Caption.ToInt()>0)
        {
                Timer3->Interval=AboutBox->wash11->Text.ToInt() -AboutBox->wash12->Text.ToInt()/2 + rand() % AboutBox->wash12->Text.ToInt();
                Och_not->Caption=Och_not->Caption.ToInt()-1;
                Image4->Visible=true;
        }
        else if(Och->Caption.ToInt()>0)
        {
                Timer3->Interval=AboutBox->wash31->Text.ToInt() -AboutBox->wash32->Text.ToInt()/2 + rand() % AboutBox->wash32->Text.ToInt();;
                Och->Caption=Och->Caption.ToInt()-1;
                Image4->Visible=true;
        }
        else
        {
                Timer3->Interval=1;
                Image4->Visible=false;
        }
        if(Timer3->Interval>3)
        {
                Label9->Caption=Label9->Caption.ToInt()+1;
        }
        V->Caption=Och->Caption.ToInt()*20;
        V->Caption=V->Caption+"%";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer4Timer(TObject *Sender)
{
        if(Och_not->Caption.ToInt()>0)
        {
                Timer4->Interval=AboutBox->wash11->Text.ToInt() -AboutBox->wash12->Text.ToInt()/2 + rand() % AboutBox->wash12->Text.ToInt();
                Och_not->Caption=Och_not->Caption.ToInt()-1;
                Image5->Visible=true;
        }
        else if(Och->Caption.ToInt()>0)
        {
                Timer4->Interval=AboutBox->wash41->Text.ToInt() -AboutBox->wash42->Text.ToInt()/2 + rand() % AboutBox->wash42->Text.ToInt();
                Och->Caption=Och->Caption.ToInt()-1;
                Image5->Visible=true;
        }
        else
        {
                Timer4->Interval=1;
                Image5->Visible=false;
        }
        if(Timer4->Interval>3)
        {
                Label10->Caption=Label10->Caption.ToInt()+1;
        }
        V->Caption=Och->Caption.ToInt()*20;
        V->Caption=V->Caption+"%";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
        randomize();
        Timer5->Interval=1000;
        Auto->Interval=1000;
        Come->Interval=1;
        Timer5->Enabled=true;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer5Timer(TObject *Sender)
{
        AnsiString errors[5];
        int e=rand()%5, m;
        errors[0]="Сломан аппарат открытия слива";
        errors[1]="Засор Слива";
        errors[2]="Заклинил подъемный механизм";
        errors[3]="Сбой системы РВ";
        errors[4]="Не предвиденная ошибка";
        if(e==1 || e==2 || e==4)
        {
                m=rand()%4;
                if(m==0)
                {
                        Image2->Visible=true;
                        Image2->Picture->LoadFromFile("img/not_wash.bmp");
                        Timer1->Enabled=false;
                }
                if(m==1)
                {
                        Image3->Visible=true;
                        Image3->Picture->LoadFromFile("img/not_wash.bmp");
                        Timer2->Enabled=false;
                }
                if(m==2)
                {
                        Image4->Visible=true;
                        Image4->Picture->LoadFromFile("img/not_wash.bmp");
                        Timer3->Enabled=false;
                }
                if(m==3)
                {
                        Image5->Visible=true;
                        Image5->Picture->LoadFromFile("img/not_wash.bmp");
                        Timer4->Enabled=false;
                }
        }
        else
        {
                Image2->Picture->LoadFromFile("img/not_wash.bmp");
                Image3->Picture->LoadFromFile("img/not_wash.bmp");
                Image4->Picture->LoadFromFile("img/not_wash.bmp");
                Image5->Picture->LoadFromFile("img/not_wash.bmp");
                Timer1->Enabled=false;
                Timer2->Enabled=false;
                Timer3->Enabled=false;
                Timer4->Enabled=false;
                Image2->Visible=true;
                Image3->Visible=true;
                Image4->Visible=true;
                Image5->Visible=true;
        }
        if(Timer1->Enabled==false && Timer2->Enabled==false && Timer3->Enabled==false && Timer4->Enabled==false)
        {
                Timer5->Enabled=false;
        }
        Memo1->Lines->Add(errors[e]);
        Timer5->Interval=rand() % AboutBox->err->Text.ToInt();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
        if(CheckBox1->Checked)
        {
                Auto->Enabled=true;
                BitBtn1->Enabled=false;
        }
        else
        {
                Auto->Enabled=false;
                BitBtn1->Enabled=true;        
        }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::AutoTimer(TObject *Sender)
{
        if(Timer1->Enabled==false || Timer2->Enabled==false || Timer3->Enabled==false || Timer4->Enabled==false)
        {
                Memo1->Lines->Add("Поломка устранена!!!");
        }

        if(Timer1->Enabled==false && Timer2->Enabled==false && Timer3->Enabled==false && Timer4->Enabled==false)
        {
                Timer5->Enabled=true;
        }
        if(Timer1->Enabled==false)
        {
                Image2->Picture->LoadFromFile("img/wash.bmp");
                Timer1->Enabled=true;
        }
        if(Timer2->Enabled==false)
        {
                Image3->Picture->LoadFromFile("img/wash.bmp");
                Timer2->Enabled=true;
        }
        if(Timer3->Enabled==false)
        {
                Image4->Picture->LoadFromFile("img/wash.bmp");
                Timer3->Enabled=true;
        }
        if(Timer4->Enabled==false)
        {
                Image5->Picture->LoadFromFile("img/wash.bmp");
                Timer4->Enabled=true;
        }
        Auto->Interval=AboutBox->auto1->Text.ToInt();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N1Click(TObject *Sender)
{
        Close();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
                N4->Caption="Продолжить поток";
                Come->Enabled=false;
                systime->Enabled=false;
                Timer5->Enabled=false;
                Auto->Enabled=false;
                N4->Enabled=false;
                systime->Enabled=false;
                AboutBox->Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N4Click(TObject *Sender)
{
        if(Come->Enabled)
        {
                N4->Caption="Продолжить Моделирование";
                Come->Enabled=false;
                Timer5->Enabled=false;
                Auto->Enabled=false;
                systime->Enabled=false;
        }
        else
        {
                N4->Caption="Приостановить моделирование";
                Come->Enabled=true;
                Timer5->Enabled=true;
                Auto->Enabled=true;
                systime->Enabled=true;
        }        
}
//---------------------------------------------------------------------------



void __fastcall TForm1::N5Click(TObject *Sender)
{
        Och->Caption="0";
        Och_not->Caption="0";
        Memo1->Clear();
        Image2->Picture->LoadFromFile("img/wash.bmp");
        Image3->Picture->LoadFromFile("img/wash.bmp");
        Image4->Picture->LoadFromFile("img/wash.bmp");
        Image5->Picture->LoadFromFile("img/wash.bmp");
        Image2->Visible=false;
        Image3->Visible=false;
        Image4->Visible=false;
        Image5->Visible=false;
        Timer1->Enabled=false;
        Timer2->Enabled=false;
        Timer3->Enabled=false;
        Timer4->Enabled=false;
        Label7->Caption="0";
        Label8->Caption="0";
        Label9->Caption="0";
        Label10->Caption="0";
        ss->Caption="0";
        mm->Caption="0";
        hh->Caption="0";

}
//---------------------------------------------------------------------------

void __fastcall TForm1::systimeTimer(TObject *Sender)
{
        ss->Caption=ss->Caption.ToInt()+1;
        if(ss->Caption.ToInt()==24)
        {
                mm->Caption=mm->Caption.ToInt()+1;
                ss->Caption="0";
                if(mm->Caption.ToInt()==31)
                {
                        hh->Caption=hh->Caption.ToInt()+1;
                        mm->Caption="0";
                }

        }
}
//---------------------------------------------------------------------------







Соседние файлы в папке Программа для зачета1
  • #
    02.05.20144.41 Кб38Project1.bpr
  • #
    02.05.20141.18 Кб38Project1.cpp
  • #
    02.05.201418.04 Кб38Project1.obj
  • #
    02.05.20141.59 Кб38Project1.res
  • #
    02.05.20142.03 Mб39Project1.tds
  • #
    02.05.201414.28 Кб39Unit1.cpp
  • #
    02.05.201451 б38Unit1.ddp
  • #
    02.05.2014712.05 Кб39Unit1.dfm
  • #
    02.05.20142.73 Кб38Unit1.h
  • #
    02.05.201482.66 Кб38Unit1.obj
  • #
    02.05.20141.68 Кб38Unit2.cpp