//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Help_FlexTens.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
THelp_FlexTensForm *Help_FlexTensForm;
static int RowSelect = -1;
static int ColSelect = -1;

//---------------------------------------------------------------------------
__fastcall THelp_FlexTensForm::THelp_FlexTensForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexTensForm::FormShow(TObject *Sender)
{
   Fill_Grid();
}
void __fastcall THelp_FlexTensForm::Fill_Grid()
{
   int i, j, k;
   Koeff_FlexTens = 0;

   StringGrid_FlexTens->DefaultDrawing = false;
   //StringGrid_FlexTens->Canvas->Font->Style = TFontStyles() >> fsItalic;
   StringGrid_FlexTens->Cells[0][0] = " Номер";
   StringGrid_FlexTens->Cells[1][0] = "                                    Элементы конструкций";
   StringGrid_FlexTens->Cells[2][0] = " динамических, приложенных непосредственно к конструкции";
   StringGrid_FlexTens->Cells[3][0] = " статических";
   StringGrid_FlexTens->Cells[4][0] = " от кранов (см. прим. 4) и железнодорожных составов";
   Koeff[1][0] = 0;
   Koeff[1][1] = 0;
   k = 1;
   StringGrid_FlexTens->Cells[0][k] = "  1.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_1;
   Koeff[k][0] = Koeff_33_1_1;
   Koeff[k][1] = Koeff_33_1_2;
   Koeff[k][2] = Koeff_33_1_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  2.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_2;
   Koeff[k][0] = Koeff_33_2_1;
   Koeff[k][1] = Koeff_33_2_2;
   Koeff[k][2] = Koeff_33_2_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  3.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_3;
   Koeff[k][0] = Koeff_33_3_1;
   Koeff[k][1] = Koeff_33_3_2;
   Koeff[k][2] = Koeff_33_3_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  4.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_4;
   Koeff[k][0] = Koeff_33_4_1;
   Koeff[k][1] = Koeff_33_4_2;
   Koeff[k][2] = Koeff_33_4_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  5.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_5;
   Koeff[k][0] = Koeff_33_5_1;
   Koeff[k][1] = Koeff_33_5_2;
   Koeff[k][2] = Koeff_33_5_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  6.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_6;
   Koeff[k][0] = Koeff_33_6_1;
   Koeff[k][1] = Koeff_33_6_2;
   Koeff[k][2] = Koeff_33_6_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  7.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_7;
   Koeff[k][0] = Koeff_33_7_1;
   Koeff[k][1] = Koeff_33_7_2;
   Koeff[k][2] = Koeff_33_7_3;
   k++;
   StringGrid_FlexTens->Cells[0][k] = "  8.";
   StringGrid_FlexTens->Cells[1][k] = Tabl_33_8;
   Koeff[k][0] = Koeff_33_8_1;
   Koeff[k][1] = Koeff_33_8_2;
   Koeff[k][2] = Koeff_33_8_3;
   k++;
   for (j=1; j<k; j++) {
	 for (i=0; i<3; i++) {
	   if (Koeff[j][i]!=0)
		 StringGrid_FlexTens->Cells[i+2][j] = "  "+FloatToStr(Koeff[j][i]);
	   else
		 StringGrid_FlexTens->Cells[i+2][j] = "   -";
	 }
   }


   StringGrid_FlexTens->RowCount = k;
   int n  = 48;
   StringGrid_FlexTens->RowHeights[0] = 48;
   for (i=0; i<k-1; i++) {

	 StringGrid_FlexTens->RowHeights[i+1]= 24*ceil(StringGrid_FlexTens->Cells[1][i+1].Length()/130.0);
	 n += StringGrid_FlexTens->RowHeights[i+1];
   }
}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexTensForm::StringGrid_FlexTensDrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
{
   HDC hdc;
   int length;
   //if (ACol!=1)
   //	 return;
   AnsiString Text;
   Text = StringGrid_FlexTens->Cells[ACol][ARow];
   StringGrid_FlexTens->Canvas->Brush->Color = clWhite;
   if (ACol >1 && RowSelect == ARow && ColSelect == ACol && Koeff[ARow][ACol-2]!=0 ) {
	 StringGrid_FlexTens->Canvas->Brush->Color = cl3DLight;
   }
   else {
	 StringGrid_FlexTens->Canvas->Brush->Color = clWhite;
   }
   StringGrid_FlexTens->Canvas->FillRect(Rect);
   DrawText(StringGrid_FlexTens->Canvas->Handle, Text.c_str(), Text.Length(), &Rect, DT_WORDBREAK);


}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexTensForm::StringGrid_FlexTensSelectCell(TObject *Sender,
          int ACol, int ARow, bool &CanSelect)
{
	  if (ACol == 2)
		Koeff_FlexTens = Koeff[ARow][0];
	  if (ACol == 3)
		Koeff_FlexTens = Koeff[ARow][1];
	  if (ACol == 4)
		Koeff_FlexTens = Koeff[ARow][2];

	  ColSelect = ACol;
	  RowSelect = ARow;

	  Fill_Grid();

}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexTensForm::BitBtnCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexTensForm::BitBtn_ApplyClick(TObject *Sender)
{
   if (RowSelect == -1) {
	  int i =Application->MessageBox(L"Коэффициенты предельной гибкости не выбраны. Продолжить/Выйти (Да/Нет)", L" ",
						  MB_YESNO | MB_ICONQUESTION);
		if (i==IDYES) return;
		else {
		  Close();
		  return;
		}
   }
   Koeff_FlexTens = Koeff[RowSelect][ColSelect-2];
	  if (Koeff_FlexTens==0) {
	  int i =Application->MessageBox(L"Предельная гибкость не выбрана. Продолжить/Выйти (Да/Нет)", L" ",
						  MB_YESNO | MB_ICONQUESTION);
		if (i==IDYES) return;
   }
   Close();
}

//---------------------------------------------------------------------------


