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

#include <vcl.h>
#pragma hdrstop

#include "Help_FlexComp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
THelp_FlexCompForm *Help_FlexCompForm;
static int RowSelect = -1;
static int ColSelect = -1;

//---------------------------------------------------------------------------
__fastcall THelp_FlexCompForm::THelp_FlexCompForm(TComponent* Owner)
	: TForm(Owner)
{
   Koeff_FlexComp[0] = 0;
   Koeff_FlexComp[1] = 0;

}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexCompForm::FormShow(TObject *Sender)
{
   int i, k;
   String Ustr = u"\u03B1";

   Koeff_FlexComp[0] = 0;
   Koeff_FlexComp[1] = 0;
   StringGrid_FlexComp->Cells[0][0] = " Номер";
   StringGrid_FlexComp->Cells[1][0] = L"                        Элементы конструкций";
   //StringGrid_FlexComp->Cells[0][0] = L" Коэффициент \u03BBu";
   //StringGrid_FlexComp->Cells[1][0] = L" Коэффициент \u03BBu";
   StringGrid_FlexComp->Cells[2][0] = L" Коэффициент \u03BBu";


   Koeff[1][0] = 0;
   Koeff[1][1] = 0;
   k = 1;
   StringGrid_FlexComp->Cells[0][k] = " 1.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_1;
   StringGrid_FlexComp->Cells[2][k] = " ";
   Koeff[k][0] = 0;
   Koeff[k][1] = 0;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "   ";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_1a;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_1a_1) + "-" + FloatToStr(Koeff_32_1a_2) + Ustr;
   Koeff[k][0] = Koeff_32_1a_1;
   Koeff[k][1] = Koeff_32_1a_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "   ";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_1b;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_1b_1); // + "-" + FloatToStr(Koeff_32_1b_2) + Ustr;
   Koeff[k][0] = Koeff_32_1b_1;
   Koeff[k][1] = Koeff_32_1b_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = " 2.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_2;
   StringGrid_FlexComp->Cells[2][k] = " ";
   Koeff[k][0] = 0;
   Koeff[k][1] = 0;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "   ";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_2a;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_2a_1) + "-" + FloatToStr(Koeff_32_2a_2) + Ustr;
   Koeff[k][0] = Koeff_32_2a_1;
   Koeff[k][1] = Koeff_32_2a_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "   ";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_2b;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_2b_1) + "-" + FloatToStr(Koeff_32_2b_2) + Ustr;
   Koeff[k][0] = Koeff_32_2b_1;
   Koeff[k][1] = Koeff_32_2b_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "  3.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_3;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_3_1); // + "-" + FloatToStr(Koeff_32_3_2) + Ustr;
   Koeff[k][0] = Koeff_32_3_1;
   Koeff[k][1] = Koeff_32_3_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "  4.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_4;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_4_1) + "-" + FloatToStr(Koeff_32_4_2) + Ustr;
   Koeff[k][0] = Koeff_32_4_1;
   Koeff[k][1] = Koeff_32_4_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "  5.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_5;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_5_1) + "-" + FloatToStr(Koeff_32_5_2) + Ustr;
   Koeff[k][0] = Koeff_32_5_1;
   Koeff[k][1] = Koeff_32_5_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "  6.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_6;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_6_1); //+ "-" + FloatToStr(Koeff_32_6_2) + Ustr;
   Koeff[k][0] = Koeff_32_6_1;
   Koeff[k][1] = Koeff_32_6_2;
   k++;
   StringGrid_FlexComp->Cells[0][k] = "  7.";
   StringGrid_FlexComp->Cells[1][k] = Tabl_32_7;
   StringGrid_FlexComp->Cells[2][k] = "  "+FloatToStr(Koeff_32_7_1); //+ "-" + FloatToStr(Koeff_32_7_2) + Ustr;
   Koeff[k][0] = Koeff_32_7_1;
   Koeff[k][1] = Koeff_32_7_2;
   k++;


   StringGrid_FlexComp->RowCount = k;

   int n  = 20;
   for (i=0; i<k-1; i++) {
	 StringGrid_FlexComp->RowHeights[i+1]= 20*ceil(StringGrid_FlexComp->Cells[1][i+1].Length()/140.0);
	 n += StringGrid_FlexComp->RowHeights[i+1];
   }

}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexCompForm::StringGrid_FlexCompDrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
{
   HDC hdc;
   int length;

   /*
   String Ustr = StringGrid_FlexComp->Cells[ACol][ARow];
   AnsiString Astr = StringGrid_FlexComp->Cells[ACol][ARow];
   length = strlen(Astr.c_str());
   if (RowSelect == ARow && Koeff[ARow] > 0) {
	 StringGrid_FlexComp->Canvas->Brush->Color = cl3DLight;
	 StringGrid_FlexComp->Canvas->FillRect(Rect);
   }
   else {
	 StringGrid_FlexComp->Canvas->Brush->Color = clWhite;
	 StringGrid_FlexComp->Canvas->FillRect(Rect);
   }
   hdc = GetDC(StringGrid_FlexComp->Handle);
   DrawText(hdc, Astr.c_str(), length, &Rect, DT_WORDBREAK);
   ReleaseDC(StringGrid_FlexComp->Handle,hdc);
   */
   if (ACol!=1)
	 return;
   AnsiString Text;
   Text = StringGrid_FlexComp->Cells[ACol][ARow];
   StringGrid_FlexComp->Canvas->Brush->Color = clWhite;
   if (ACol >1 && ColSelect == ACol && RowSelect == ARow && Koeff[ARow][0] > 0) {
	 StringGrid_FlexComp->Canvas->Brush->Color = cl3DLight;
   }
   else {
	 StringGrid_FlexComp->Canvas->Brush->Color = clWhite;
   }
   StringGrid_FlexComp->Canvas->FillRect(Rect);
   DrawText(StringGrid_FlexComp->Canvas->Handle, Text.c_str(), Text.Length(), &Rect, DT_WORDBREAK);
}
//---------------------------------------------------------------------------
void __fastcall THelp_FlexCompForm::StringGrid_FlexCompSelectCell(TObject *Sender,
          int ACol, int ARow, bool &CanSelect)
{
	  RowSelect = ARow;
	  ColSelect = ACol;

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

   if (Koeff_FlexComp[0]==0) {
	  int i =Application->MessageBox(L"Коэффициенты предельной гибкости не выбраны. Продолжить/Выйти (Да/Нет)", L" ",
						  MB_YESNO | MB_ICONQUESTION);
		if (i==IDYES) return;
   }

   Close();
}
//---------------------------------------------------------------------------

