Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Main;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls, CandidateView,
- Vcl.StdCtrls, Vcl.Imaging.pngimage, BidirectionalCandidate, BidirectionalCountyNumber, BidirectionalParty,
- PartyView, CountyNumberVIew, CandidateAdd;
- type
- TMainForm = class(TForm)
- PanelMenu: TPanel;
- PGMenu: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- TabSheet3: TTabSheet;
- TabSheet4: TTabSheet;
- TabSheet5: TTabSheet;
- TabSheet6: TTabSheet;
- TabSheet7: TTabSheet;
- TabSheet8: TTabSheet;
- Panel8: TPanel;
- Panel9: TPanel;
- Panel10: TPanel;
- Panel17: TPanel;
- Panel18: TPanel;
- ImageExitWithSave: TImage;
- Label1: TLabel;
- ImageExit: TImage;
- Label2: TLabel;
- Panel1: TPanel;
- ImageImportData: TImage;
- Label3: TLabel;
- Label4: TLabel;
- ImageViewParty: TImage;
- Label5: TLabel;
- ImageViewCountyNumber: TImage;
- Label6: TLabel;
- ImageViewCandidate: TImage;
- PanelFrame: TPanel;
- Panel2: TPanel;
- ImageSearchByParty: TImage;
- Label7: TLabel;
- Panel3: TPanel;
- Label8: TLabel;
- ImageCandidateDelete: TImage;
- Panel4: TPanel;
- ImagePartyDelete: TImage;
- Label9: TLabel;
- Panel5: TPanel;
- ImageCountyNumberDelete: TImage;
- Label10: TLabel;
- Panel6: TPanel;
- Label11: TLabel;
- ImageCandidateAdd: TImage;
- Panel7: TPanel;
- ImageAddParty: TImage;
- Label12: TLabel;
- Panel11: TPanel;
- ImageCountyNumberAdd: TImage;
- Label13: TLabel;
- Panel12: TPanel;
- Label14: TLabel;
- ImageEditCandidate: TImage;
- Panel13: TPanel;
- ImageEditParty: TImage;
- Label15: TLabel;
- Panel14: TPanel;
- ImageCountyNumberEdit: TImage;
- Label16: TLabel;
- Panel15: TPanel;
- Label17: TLabel;
- ImageNewsLetter: TImage;
- TabSheet9: TTabSheet;
- TabSheet10: TTabSheet;
- Label18: TLabel;
- Panel16: TPanel;
- Label19: TLabel;
- ImageHelp: TImage;
- procedure FormCreate(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure ImageExitClick(Sender: TObject);
- procedure ImageExitWithSaveClick(Sender: TObject);
- procedure ImageImportDataClick(Sender: TObject);
- procedure Image1Click(Sender: TObject);
- procedure ImageViewPartyClick(Sender: TObject);
- procedure ImageViewCountyNumberClick(Sender: TObject);
- procedure ImageCandidateAddClick(Sender: TObject);
- procedure ImageAddPartyClick(Sender: TObject);
- procedure ImageCountyNumberAddClick(Sender: TObject);
- procedure ImageViewCandidateClick(Sender: TObject);
- procedure ImageCandidateDeleteClick(Sender: TObject);
- procedure ImagePartyDeleteClick(Sender: TObject);
- procedure ImageCountyNumberDeleteClick(Sender: TObject);
- procedure ImageEditCandidateClick(Sender: TObject);
- procedure ImageEditPartyClick(Sender: TObject);
- procedure ImageCountyNumberEditClick(Sender: TObject);
- procedure ImageSearchByPartyClick(Sender: TObject);
- procedure ImageNewsLetterClick(Sender: TObject);
- procedure ImageHelpClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- MainForm: TMainForm;
- CurrentFrame : TFrame;
- FrameList : array of TFrame;
- CandidateList : TCandidateList;
- PartyList : TPartyList;
- CountyNumberList : TCountyNumberList;
- implementation
- {$R *.dfm}
- uses ConstFile, MainView, PartyAdd, CountyNumberAdd, CandidateDelete,
- CountyNumberDelete, PartyDelete, CandidateEdit, CountyNumberEdit, PartyEdit,
- SearchByParty, Newsletter, HelpView;
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- PGMenu.ActivePageIndex := 0;
- CurrentFrame := NIL;
- // Инициализация списков
- CandidateList := TCandidateList.Create;
- PartyList := TPartyList.Create;
- CountyNumberList := TCountyNumberList.Create;
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TMainFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- end;
- procedure TMainForm.ImageImportDataClick(Sender: TObject);
- begin
- try
- CandidateList := TCandidateList.GetCandidateListFromFile(ConstFile.FILENAME_CANDIDATE);
- PartyList := TPartyList.GetPartyListFromFile(ConstFile.FILENAME_PARTY);
- CountyNumberList := TCountyNumberList.GetCountyNumberListFromFile(FILENAME_COUNTYNUMBER);
- Application.MessageBox('Успешный импорт!','Импорт данных',MB_OK+MB_ICONINFORMATION);
- except
- On E : Exception do
- Application.MessageBox('В доступе к файлу отказано. Вы можете пользоваться программой, при этом сохранить/загрузить данные не получится.','Ошибка чтения из файла',MB_OK + MB_ICONWARNING);
- end;
- end;
- procedure TMainForm.ImageNewsLetterClick(Sender: TObject);
- begin
- if Main.PartyList.Count <> 0 then
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TNewsLetterFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список партий пуст.','Информационная бюллетень',MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImagePartyDeleteClick(Sender: TObject);
- begin
- if PartyList.Count <> 0 then
- begin
- // TODO: Фрейм удаления партии
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TPartyDeleteFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список партий пуст.','Удаление партии',MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageSearchByPartyClick(Sender: TObject);
- begin
- if CandidateList.Count <> 0 then
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TSearchByPartyFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Вам отказано в поиске! Список кандидатов пуст.','Поиск полной инфоррмации по каждой партии',MB_OK+MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageCountyNumberAddClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCountyNumberAddFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageCountyNumberDeleteClick(Sender: TObject);
- begin
- if CountyNumberList.Count <> 0 then
- begin
- // TODO : Фрейм удаления округа
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCountyNumberDeleteFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список округов пуст.','Удаление округа',MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageCountyNumberEditClick(Sender: TObject);
- begin
- if CountyNumberList.Count <> 0 then
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCountyNumberEditFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список округов пуст.','Редактирование округа', MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.Image1Click(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCandidateViewFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageViewPartyClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TPartyViewFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageViewCandidateClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCandidateViewFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageViewCountyNumberClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCountyNumberViewFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageAddPartyClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TPartyAddFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- procedure TMainForm.ImageCandidateAddClick(Sender: TObject);
- begin
- if (CountyNumberList.Count = 0) OR (PartyList.Count = 0) then
- begin
- Application.MessageBox('Список округов или/и список партий пуст.','Добавление кандидата',MB_OK+MB_ICONSTOP);
- end
- else
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCandidateAddFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end;
- end;
- procedure TMainForm.ImageCandidateDeleteClick(Sender: TObject);
- begin
- if CandidateList.Count <> 0 then
- begin
- // TODO : Фрейм удаления кандидата
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCandidateDeleteFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список кандидатов пуст.','Удаление кандидата', MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageEditCandidateClick(Sender: TObject);
- begin
- if CandidateList.Count <> 0 then
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TCandidateEditFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список кандидатов пуст.','Редактирование кандидата', MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageEditPartyClick(Sender: TObject);
- begin
- if PartyList.Count <> 0 then
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := TPartyEditFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- CurrentFrame.OnEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Список партий пуст.','Редактирование партии', MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TMainForm.ImageExitClick(Sender: TObject);
- begin
- ImageExit.Tag := 1;
- Close;
- end;
- procedure TMainForm.ImageExitWithSaveClick(Sender: TObject);
- begin
- try
- ImageExitWithSave.Tag := 1;
- try
- // Сохранение данных
- CandidateList.SaveCandidateList(ConstFile.FILENAME_CANDIDATE);
- PartyList.SavePartyList(ConstFile.FILENAME_PARTY);
- CountyNumberList.SaveCountyNumberList(ConstFile.FILENAME_COUNTYNUMBER);
- except
- Application.MessageBox('В доступе к файлу отказано. Программа закроется, без сохранения данных.','Ошибка сохранения',MB_OK + MB_ICONINFORMATION);
- ImageExitWithSave.Tag := 0;
- ImageExit.Tag := 1;
- end;
- finally
- // Выход из программы
- Close;
- end;
- end;
- procedure TMainForm.ImageHelpClick(Sender: TObject);
- begin
- if CurrentFrame <> NIL then
- begin
- CurrentFrame.Free;
- CurrentFrame := NIL;
- end;
- CurrentFrame := THelpFrame.Create(Self);
- CurrentFrame.Parent := PanelFrame;
- end;
- procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := False;
- PGMenu.ActivePageIndex := 7;
- if ImageExitWithSave.Tag = 1 then
- begin
- CanClose := Application.MessageBox('Вы уверены, что хотите закрыть программу, сохранив данные?','Закрытие программы', MB_YESNO + MB_ICONQUESTION) = IDYES;
- if not CanClose then
- ImageExitWithSave.Tag := 0;
- // TODO : Добавить сохранение
- end
- else
- if ImageExit.Tag = 1 then
- begin
- CanClose := Application.MessageBox('Вы уверены, что хотите закрыть программу без сохранения?','Закрытие программы', MB_YESNO + MB_ICONQUESTION) = IDYES;
- if not CanClose then
- ImageExit.Tag := 0;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement