Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit PavilionPageMain;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, EntityShopCenter;
- type
- TPavilionFrameMain = class(TFrame)
- SGPavilion: TStringGrid;
- Label1: TLabel;
- LBCurrentShopCenter: TLabel;
- BtnEdit: TButton;
- BtnDelete: TButton;
- BtnAdd: TButton;
- Label2: TLabel;
- LBPKShopCenter: TLabel;
- ButtonCalcRent: TButton;
- ButtonBack: TButton;
- procedure BtnAddClick(Sender: TObject);
- procedure BtnDeleteClick(Sender: TObject);
- procedure BtnEditClick(Sender: TObject);
- procedure FrameEnter(Sender: TObject);
- procedure ButtonBackClick(Sender: TObject);
- procedure ButtonCalcRentClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- const
- HEADER_ID_PAVILION = '№';
- HEADER_NAME = '№ павильона';
- HEADER_FLOOR = 'Этаж';
- HEADER_STATUS = 'Статус';
- HEADER_AREA = 'Площадь';
- HEADER_LEVEL_COFF = 'Доб. стоимость павильона';
- HEADER_COST_PER_METER = 'Стоимость кв. м.';
- var
- CurrentShopCenter : TShopCenter;
- implementation
- {$R *.dfm}
- uses BidirectionalPavilionList, ConstantsFile, Main, ConstantsTitleMainFrame,
- BidirectionalShopCenterList, EntityPavilion, UnitCalcRentForm;
- Procedure FillHeadersSG(SGPavilion : TStringGrid);
- begin
- SGPavilion.Cells[0,0] := HEADER_ID_PAVILION;
- SGPavilion.Cells[1,0] := HEADER_NAME;
- SGPavilion.Cells[2,0] := HEADER_FLOOR;
- SGPavilion.Cells[3,0] := HEADER_STATUS;
- SGPavilion.Cells[4,0] := HEADER_AREA;
- SGPavilion.Cells[5,0] := HEADER_LEVEL_COFF;
- SGPavilion.Cells[6,0] := HEADER_COST_PER_METER;
- end;
- Procedure ClearStringGrid(SG : TStringGrid);
- Var
- I, J : Integer;
- Begin
- For I := 0 to SG.RowCount - 1 do
- Begin
- SG.Rows[I].Clear;
- End;
- End;
- Procedure FillPavilions(SG : TStringGrid; ShopCenterID : Integer);
- var
- TempList : TPavilionList;
- Amount, J, I : Integer;
- begin
- ClearStringGrid(SG);
- FillHeadersSG(SG);
- CurrentShopCenter := TShopCenterList.GetShopCenterByPrimaryKey(ShopCenterID, ConstantsFile.FILE_NAME_SHOPCENTER);
- Main.MainForm.PavilionFrameMain.LBCurrentShopCenter.Caption := CurrentShopCenter.Name;
- TempList := TPavilionList.GetPavilionListByShopCenterIDFromFile(ShopCenterID, ConstantsFile.FILE_NAME_PAVILION);
- Amount := TempList.Count;
- SG.RowCount := Amount + 1;
- I := 1;
- J := 0;
- while TempList.Head <> NIL do
- begin
- SG.Cells[J, I] := TempList.Head.Pavilion.ID_Pavilion.ToString;
- SG.Cells[J + 1, I] := TempList.Head.Pavilion.Name;
- SG.Cells[J + 2, I] := TempList.Head.Pavilion.Floor.ToString;
- SG.Cells[J + 3, I] := TempList.Head.Pavilion.Status;
- SG.Cells[J + 4, I] := TempList.Head.Pavilion.Area.ToString;
- SG.Cells[J + 5, I] := TempList.Head.Pavilion.LevelCoff.ToString;
- SG.Cells[J + 6, I] := TempList.Head.Pavilion.CostPerMeter.ToString;
- Inc(I);
- TempList.Head := TempList.Head^.Next
- end;
- end;
- procedure TPavilionFrameMain.BtnAddClick(Sender: TObject);
- begin
- try
- with MainForm do
- begin
- LBCurrentPage.Caption := ConstantsTitleMainFrame.TITLE_PAVILION_ADD_PAGE;
- PavilionFrameMain.Visible := False;
- PavilionFrameAddEdit.Visible := True;
- PavilionFrameAddEdit.UpdateFrame;
- Main.MainForm.PavilionFrameAddEdit.EditShopCenter.Text := LBCurrentShopCenter.Caption;
- end;
- except
- On E : Exception do
- Application.MessageBox(PCHAR(Concat('Передайте системному администратору код ошибки - ',E.Message)),'Ошибка добавления',MB_OK + MB_ICONERROR);
- end;
- end;
- procedure TPavilionFrameMain.BtnDeleteClick(Sender: TObject);
- var
- C, R : Word;
- TempList : TPavilionList;
- PavilionForDelete : TPavilion;
- begin
- try
- if SGPavilion.RowCount - 1 <> 0 then
- begin
- C := SGPavilion.Col;
- R := SGPavilion.Row;
- TempList := TPavilionList.GetPavilionListFromFile(ConstantsFile.FILE_NAME_PAVILION);
- PavilionForDelete := TPavilionList.GetPavilionById(SGPavilion.Cells[0,R].ToInteger, ConstantsFile.FILE_NAME_PAVILION);
- if Application.MessageBox(PCHAR(Concat('Вы уверены что хотите удалить павильон №"',PavilionForDelete.Name, '", в ТЦ "', LBCurrentShopCenter.Caption ,'" ?')),'Удаление торгового центра',MB_YESNO + MB_ICONQUESTION) = IDYES then
- begin
- TempList.DeletePavilionByID(PavilionForDelete.ID_Pavilion);
- TempList.SavePavilionList(ConstantsFile.FILE_NAME_PAVILION);
- Self.FrameEnter(NIL);
- end;
- end
- else
- begin
- Application.MessageBox('Список павильонов пуст. Добавьте сначала павильон.','Удаление невозможно',MB_OK+MB_ICONERROR);
- end;
- Except
- Application.MessageBox('Выберите павильон','Удаление невозможно',MB_OK + MB_ICONERROR)
- end;
- end;
- procedure TPavilionFrameMain.BtnEditClick(Sender: TObject);
- var
- C, R : Word;
- PavilionForEdit : TPavilion;
- TempList : TPavilionList;
- begin
- try
- if SGPavilion.RowCount - 1 <> 0 then
- begin
- C := SGPavilion.Col;
- R := SGPavilion.Row;
- PavilionForEdit := TPavilionList.GetPavilionById(SGPavilion.Cells[0, R].ToInteger, ConstantsFile.FILE_NAME_PAVILION);
- TempList := TPavilionList.GetPavilionListFromFile(ConstantsFile.FILE_NAME_PAVILION);
- if PavilionForEdit <> NIL then
- TempList.DeletePavilionByID(PavilionForEdit.ID_Pavilion);
- with MainForm do
- begin
- PavilionFrameMain.Visible := False;
- PavilionFrameAddEdit.Visible := True;
- PavilionFrameAddEdit.UpdateFrameForEdit(PavilionForEdit);
- LBCurrentPage.Caption := ConstantsTitleMainFrame.TITLE_PAVILION_EDIT_PAGE;
- end;
- end
- else
- begin
- Application.MessageBox('Список павильонов пуст. Добавьте сначала павильон.','Редактирование невозможно',MB_OK+MB_ICONERROR);
- end;
- except
- Application.MessageBox('Выберите павильон','Редактирование невозможно',MB_OK + MB_ICONERROR);
- end;
- end;
- procedure TPavilionFrameMain.ButtonBackClick(Sender: TObject);
- begin
- Self.Visible := False;
- Main.MainForm.ManagerAFrameMain.Visible := True;
- end;
- procedure TPavilionFrameMain.ButtonCalcRentClick(Sender: TObject);
- var
- FormCalc : TFormCalcRent;
- C, R : Word;
- Pav : TPavilion;
- SC : TShopCenter;
- FCResult : Integer;
- begin
- try
- if SGPavilion.RowCount - 1 <> 0 then
- begin
- FCResult := 0;
- C := SGPavilion.Col;
- R := SGPavilion.Row;
- Pav := TPavilionList.GetPavilionById(SGPavilion.Cells[0,R].ToInteger,ConstantsFile.FILE_NAME_PAVILION);
- SC := TShopCenterList.GetShopCenterByPrimaryKey(StrToInt(LBPKShopCenter.Caption), ConstantsFile.FILE_NAME_SHOPCENTER);
- try
- FormCalc := TFormCalcRent.Create(Main.MainForm, Pav, SC);
- FCResult := FormCalc.ShowModal;
- finally
- FormCalc.Free;
- end
- end
- else
- begin
- Application.MessageBox('Список павильонов пуст. Добавьте сначала павильон.','Рассчитать аренду невозможно',MB_OK+MB_ICONERROR);
- end;
- except
- Application.MessageBox('Выберите павильон','Рассчитать аренду невозможно',MB_OK + MB_ICONERROR);
- end;
- end;
- procedure TPavilionFrameMain.FrameEnter(Sender: TObject);
- begin
- FillPavilions(SGPavilion, StrToInt(LBPKShopCenter.Caption));
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement