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

#include <vcl.h>
#include <math.h>
#pragma hdrstop

#include "Advanced_gamma_n.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TAdvanced_gamma_nForm *Advanced_gamma_nForm;
static int RowSelect = -1;
//---------------------------------------------------------------------------
__fastcall TAdvanced_gamma_nForm::TAdvanced_gamma_nForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TAdvanced_gamma_nForm::FormShow(TObject *Sender)
{
   int i, k;
   String Gamm = "\u03B3";

   Label1->Caption = L"Таблица 2. Коэффициенты условий работы \u03B3n ( ГОСТ 27751-2014))";
   Koeff_gamma_n = -1;
   StringGrid_gamma_n->DefaultDrawing = false;
   //StringGrid_gamma_n->Canvas->Font->Style = TFontStyles() >> fsItalic;
   StringGrid_gamma_n->Cells[0][0] = L"  Класс сооружений";
   StringGrid_gamma_n->Cells[1][0] = L"  Уровень ответственности";
   StringGrid_gamma_n->Cells[2][0] = L"  Минимальные значения коэффициента ";
   //StringGrid_gamma_n->Cells[2][0] = L" Коэффициент \u03BBu";
   Koeff[1] = 0;
   k = 1;
   StringGrid_gamma_n->Cells[0][k] = "  КС-3";
   StringGrid_gamma_n->Cells[1][k] = L" Повышенный";
   StringGrid_gamma_n->Cells[2][k] = "      1.1";
   Koeff[k] = 1.1;
   k++;
   StringGrid_gamma_n->Cells[0][k] = "  КС-2";
   StringGrid_gamma_n->Cells[1][k] = L"  Нормальный";
   StringGrid_gamma_n->Cells[2][k] = "      1.0";
   Koeff[k] = 1.0;
   k++;
   StringGrid_gamma_n->Cells[0][k] = "  КС-1";
   StringGrid_gamma_n->Cells[1][k] = L" Пониженный";
   StringGrid_gamma_n->Cells[2][k] = "      0.8";
   Koeff[k] = 0.8;
   k++;

   StringGrid_gamma_n->RowCount = k;
   int n  = 24;
   for (i=0; i<k-1; i++) {
	 StringGrid_gamma_n->RowHeights[i+1]= 24*ceil(StringGrid_gamma_n->Cells[1][i+1].Length()/120.0);
	 n += StringGrid_gamma_n->RowHeights[i+1];
   }
}
//----------------------------------------------------------------------------
void __fastcall TAdvanced_gamma_nForm::StringGrid_gamma_nDrawCell(
      TObject *Sender, int ACol, int ARow, TRect &Rect,
      TGridDrawState State)
{
   HDC hdc;
   int length;


   AnsiString Text;
   Text = StringGrid_gamma_n->Cells[ACol][ARow];
   if (RowSelect == ARow && Koeff[ARow] > 0) {
	 StringGrid_gamma_n->Canvas->Brush->Color = cl3DLight;
   }
   else {
	 StringGrid_gamma_n->Canvas->Brush->Color = clWhite;
   }
   StringGrid_gamma_n->Canvas->FillRect(Rect);
   DrawText(StringGrid_gamma_n->Canvas->Handle, Text.c_str(), Text.Length(), &Rect, DT_WORDBREAK);

}
//---------------------------------------------------------------------------

void __fastcall TAdvanced_gamma_nForm::StringGrid_gamma_nSelectCell(
      TObject *Sender, int ACol, int ARow, bool &CanSelect)
{
	  RowSelect = ARow;

}
//---------------------------------------------------------------------------
void __fastcall TAdvanced_gamma_nForm::BitBtnCancelClick(TObject *Sender)
{
   Koeff_gamma_n = 0;
   Close();
}
//---------------------------------------------------------------------------

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

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

   Close();

}
//---------------------------------------------------------------------------

