Advertisement
ksyshshot

курсач 6

May 28th, 2023
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.64 KB | Source Code | 0 0
  1. unit UnitEditDictionary;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.ValEdit,
  8.   Vcl.ExtCtrls, Vcl.StdCtrls;
  9.  
  10. type
  11.   TFrameEditDictionary = class(TFrame)
  12.     PanelLeftBorder: TPanel;
  13.     PanelRightBorder: TPanel;
  14.     PanelBottomBorder: TPanel;
  15.     PanelTopBorder: TPanel;
  16.     ButtonMakeFavorite: TButton;
  17.     ButtonDeleteWord: TButton;
  18.     ButtonAddWord: TButton;
  19.     ButtonSaveChange: TButton;
  20.     PanelForFaQ: TPanel;
  21.     ButtonHowWork: TButton;
  22.     ButtonChangeWord: TButton;
  23.     Dictionary: TValueListEditor;
  24.     procedure DictionarySelectCell(Sender: TObject; ACol, ARow: Integer;
  25.       var CanSelect: Boolean);
  26.     procedure ButtonAddWordClick(Sender: TObject);
  27.     procedure ButtonDeleteWordClick(Sender: TObject);
  28.     procedure ButtonChangeWordClick(Sender: TObject);
  29.     procedure ButtonSaveChangeClick(Sender: TObject);
  30.     procedure ButtonMakeFavoriteClick(Sender: TObject);
  31.     procedure ButtonHowWorkClick(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. implementation
  39.  
  40. {$R *.dfm}
  41.  
  42. uses UnitChangeWord, MainForm, UnitFavorites, UnitHelp;
  43.  
  44. type
  45.     TPartsOfSpeech = MainForm.TPartsOfSpeech;
  46.     EnglStr = MainForm.EnglStr;
  47.     RussStr = MainForm.RussStr;
  48.     TWord = MainForm.TWord;
  49.  
  50. const
  51.     FILE_NAME = MainForm.FILE_NAME;
  52.     TEMP_FILE_NAME = MainForm.TEMP_FILE_NAME;
  53.  
  54. procedure TFrameEditDictionary.ButtonAddWordClick(Sender: TObject);
  55. var
  56.     EnglishWord: EnglStr;
  57.     RussianWord: RussStr;
  58.     PartOfSpeech: TPartsOfSpeech;
  59.     EnglishPresence, RussianPresence: Boolean;
  60. begin
  61.     UnitChangeWord.FormChangeWord.EditEnglishWord.Text := '';
  62.     UnitChangeWord.FormChangeWord.EditRussianWord.Text := '';
  63.     UnitChangeWord.FormChangeWord.RadioGroupPartsOfSpeech.ItemIndex := -1;
  64.     if UnitChangeWord.FormChangeWord.ShowModal = mrOk then
  65.     begin
  66.         with UnitChangeWord.FormChangeWord do
  67.         begin
  68.             RussianWord := EditRussianWord.Text;
  69.             PartOfSpeech := MainForm.FormMenu.GetPartOfSpeech(EnglishWord, RadioGroupPartsOfSpeech, true);
  70.             EnglishWord := MainForm.FormMenu.GetFinalAppearance(PartOfSpeech, EditEnglishWord.Text);
  71.             EnglishPresence := MainForm.FormMenu.IsWordInDictionary(Dictionary, EnglishWord);
  72.             RussianPresence := MainForm.FormMenu.IsWordInDictionary(Dictionary, RussianWord);
  73.             if not(EnglishPresence) and not(RussianPresence) then
  74.             begin
  75.                 Dictionary.InsertRow(RussianWord, EnglishWord, true);
  76.             end;
  77.         end;
  78.     end;
  79. end;
  80.  
  81. procedure TFrameEditDictionary.ButtonChangeWordClick(Sender: TObject);
  82. var
  83.     EnglishWord: EnglStr;
  84.     RussianWord: RussStr;
  85.     PartOfSpeech: TPartsOfSpeech;
  86.     EnglishPresence, RussianPresence: Boolean;
  87. begin
  88.     RussianWord := Dictionary.Keys[Dictionary.Row];
  89.     EnglishWord := Dictionary.Cells[1, Dictionary.Row];
  90.     PartOfSpeech := MainForm.FormMenu.GetPartOfSpeech(EnglishWord, UnitChangeWord.FormChangeWord.RadioGroupPartsOfSpeech, false);
  91.     UnitChangeWord.FormChangeWord.EditEnglishWord.Text := EnglishWord;
  92.     UnitChangeWord.FormChangeWord.EditRussianWord.Text := RussianWord;
  93.     if UnitChangeWord.FormChangeWord.ShowModal = mrOk then
  94.     begin
  95.         with UnitChangeWord.FormChangeWord do
  96.         begin
  97.             RussianWord := EditRussianWord.Text;
  98.             PartOfSpeech := MainForm.FormMenu.GetPartOfSpeech(EnglishWord, RadioGroupPartsOfSpeech, true);
  99.             EnglishWord := MainForm.FormMenu.GetFinalAppearance(PartOfSpeech, EditEnglishWord.Text);
  100.             EnglishPresence := MainForm.FormMenu.IsWordInDictionary(Dictionary, EnglishWord);
  101.             RussianPresence := MainForm.FormMenu.IsWordInDictionary(Dictionary, RussianWord);
  102.             if not(EnglishPresence) and not(RussianPresence) then
  103.             begin
  104.                 Dictionary.Keys[Dictionary.Row] := RussianWord;
  105.                 Dictionary.Cells[1, Dictionary.Row] := EnglishWord;
  106.             end;
  107.         end;
  108.     end;
  109. end;
  110.  
  111. procedure TFrameEditDictionary.ButtonDeleteWordClick(Sender: TObject);
  112. var
  113.     CanSel: Boolean;
  114. begin
  115.     CanSel := true;
  116.     MainForm.FormMenu.DeleteWord(Dictionary);
  117.     DictionarySelectCell(Sender, 0, Dictionary.Row, CanSel);
  118. end;
  119.  
  120. procedure TFrameEditDictionary.ButtonHowWorkClick(Sender: TObject);
  121. begin
  122.     UnitHelp.FormHelp.Show;
  123. end;
  124.  
  125. procedure TFrameEditDictionary.ButtonMakeFavoriteClick(Sender: TObject);
  126. var
  127.     EnglishPresence, RussianPresence: Boolean;
  128. begin
  129.     EnglishPresence := MainForm.FormMenu.IsWordInDictionary(MainForm.FormMenu.FrameFavorites.Dictionary, Dictionary.Cells[1, Dictionary.Row]);
  130.     RussianPresence := MainForm.FormMenu.IsWordInDictionary(MainForm.FormMenu.FrameFavorites.Dictionary, Dictionary.Keys[Dictionary.Row]);
  131.     if not(EnglishPresence) and not(RussianPresence) then
  132.     begin
  133.         MainForm.FormMenu.WriteToFavorites(Dictionary.Row, Dictionary, FILE_FAVORITES);
  134.     end;
  135. end;
  136.  
  137. procedure TFrameEditDictionary.ButtonSaveChangeClick(Sender: TObject);
  138. begin
  139.     MainForm.FormMenu.SaveDictionaryToFile(Dictionary, FILE_NAME);
  140. end;
  141.  
  142. procedure TFrameEditDictionary.DictionarySelectCell(Sender: TObject; ACol,
  143.   ARow: Integer; var CanSelect: Boolean);
  144. begin
  145.     ButtonChangeWord.Enabled := true;
  146.     if not(MainForm.FormMenu.IsRowEmpty(Dictionary, Dictionary.Row)) then
  147.     begin
  148.         ButtonMakeFavorite.Enabled := true;
  149.         ButtonDeleteWord.Enabled := true;
  150.     end
  151.     else
  152.     begin
  153.         ButtonMakeFavorite.Enabled := false;
  154.         ButtonDeleteWord.Enabled := false;
  155.     end;
  156. end;
  157.  
  158. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement