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

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

#include "Advanced_gamma_c.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TAdvanced_gamma_cForm *Advanced_gamma_cForm;
static int RowSelect = -1;
//---------------------------------------------------------------------------
__fastcall TAdvanced_gamma_cForm::TAdvanced_gamma_cForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TAdvanced_gamma_cForm::FormShow(TObject *Sender)
{
   int i, k;
   Koeff_gamma_c = -1;
   StringGrid_gamma_c->DefaultDrawing = false;
   //StringGrid_gamma_c->Canvas->Font->Style = TFontStyles() >> fsItalic;
   StringGrid_gamma_c->Cells[0][0] = " Номер";
   StringGrid_gamma_c->Cells[1][0] = "                                    Элементы конструкций";
   StringGrid_gamma_c->Cells[2][0] = " Коэффициент";
   Koeff[1] = 0;
   k = 1;
   StringGrid_gamma_c->Cells[0][k] = " 1.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_1;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_1);
   Koeff[k] = Koeff_1_1;
   k++;
   StringGrid_gamma_c->Cells[0][k] = " 2.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_2;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_2);
   Koeff[k] = Koeff_1_2;
   k++;
   StringGrid_gamma_c->Cells[0][k] = "   ";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_2a;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_2a);
   Koeff[k] = Koeff_1_2a;
   k++;
   StringGrid_gamma_c->Cells[0][k] = "   ";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_2b;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_2b);
   Koeff[k] = Koeff_1_2b;
   k++;
   StringGrid_gamma_c->Cells[0][k] = "   ";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_2c;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_2c);
   Koeff[k] = Koeff_1_2c;
   k++;

   StringGrid_gamma_c->Cells[0][k] = " 3.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_3;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_3);
   Koeff[k] = Koeff_1_3;
   k++;

   StringGrid_gamma_c->Cells[0][k] = " 4.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_4;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_4);
   Koeff[k] = Koeff_1_4;
   k++;

   StringGrid_gamma_c->Cells[0][k] = " 5.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_5;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_5);
   Koeff[k] = Koeff_1_5;
   k++;

   StringGrid_gamma_c->Cells[0][k] = " 6.";
   StringGrid_gamma_c->Cells[1][k] = Tabl_1_6;
   StringGrid_gamma_c->Cells[2][k] = FloatToStr(Koeff_1_6);
   Koeff[k] = Koeff_1_6;
   k++;
   /*
   StringGrid_gamma_c->Cells[0][7] = " 7.";
   StringGrid_gamma_c->Cells[1][7] = Tabl_1_7;
   StringGrid_gamma_c->Cells[2][7] = " ";
   Koeff[7] = Koeff_1_7;

   StringGrid_gamma_c->Cells[0][8] = " ";
   StringGrid_gamma_c->Cells[1][8] = Tabl_1_8;
   StringGrid_gamma_c->Cells[2][8] = " ";
   Koeff[8] = Koeff_1_8;

   StringGrid_gamma_c->Cells[0][9] = " ";
   StringGrid_gamma_c->Cells[1][9] = Tabl_1_9;
   StringGrid_gamma_c->Cells[2][9] = FloatToStr(Koeff_1_9);
   Koeff[9] = Koeff_1_9;

   StringGrid_gamma_c->Cells[0][10] = " ";
   StringGrid_gamma_c->Cells[1][10] = Tabl_1_10;
   StringGrid_gamma_c->Cells[2][10] = FloatToStr(Koeff_1_10);
   Koeff[10] = Koeff_1_10;

   StringGrid_gamma_c->Cells[0][11] = " ";
   StringGrid_gamma_c->Cells[1][11] = Tabl_1_11;
   StringGrid_gamma_c->Cells[2][11] = FloatToStr(Koeff_1_11);
   Koeff[11] = Koeff_1_11;

   StringGrid_gamma_c->Cells[0][12] = " 8.";
   StringGrid_gamma_c->Cells[1][12] = Tabl_1_12;
   StringGrid_gamma_c->Cells[2][12] = FloatToStr(Koeff_1_12);
   Koeff[12] = Koeff_1_12;

   StringGrid_gamma_c->Cells[0][13] = " 9.";
   StringGrid_gamma_c->Cells[1][13] = Tabl_1_13;
   StringGrid_gamma_c->Cells[2][13] = " ";
   Koeff[13] = Koeff_1_13;

   StringGrid_gamma_c->Cells[0][14] = " ";
   StringGrid_gamma_c->Cells[1][14] = Tabl_1_14;
   StringGrid_gamma_c->Cells[2][14] = FloatToStr(Koeff_1_14);
   Koeff[14] = Koeff_1_14;

   StringGrid_gamma_c->Cells[0][15] = " ";
   StringGrid_gamma_c->Cells[1][15] = Tabl_1_15;
   StringGrid_gamma_c->Cells[2][15] = FloatToStr(Koeff_1_15);
   Koeff[15] = Koeff_1_15;

   StringGrid_gamma_c->Cells[0][16] = " ";
   StringGrid_gamma_c->Cells[1][16] = Tabl_1_16;
   StringGrid_gamma_c->Cells[2][16] = FloatToStr(Koeff_1_16);
   Koeff[16] = Koeff_1_16;
   */

   StringGrid_gamma_c->RowCount = k;
   int n  = 24;
   for (i=0; i<k-1; i++) {
	 StringGrid_gamma_c->RowHeights[i+1]= 24*ceil(StringGrid_gamma_c->Cells[1][i+1].Length()/120.0);
	 n += StringGrid_gamma_c->RowHeights[i+1];
   }
}

void __fastcall TAdvanced_gamma_cForm::StringGrid_gamma_cDrawCell(
      TObject *Sender, int ACol, int ARow, TRect &Rect,
      TGridDrawState State)
{
   HDC hdc;
   int length;

   /*
   AnsiString str = StringGrid_gamma_c->Cells[ACol][ARow];
   length = strlen(str.c_str());
   if (RowSelect == ARow && Koeff[ARow] > 0) {
     StringGrid_gamma_c->Canvas->Brush->Color = cl3DLight;
     StringGrid_gamma_c->Canvas->FillRect(Rect);
   }
   else {
     StringGrid_gamma_c->Canvas->Brush->Color = clWhite;
     StringGrid_gamma_c->Canvas->FillRect(Rect);
   }
   hdc = GetDC(StringGrid_gamma_c->Handle);
   DrawText(hdc, str.c_str(), length, &Rect, DT_WORDBREAK);
   ReleaseDC(StringGrid_gamma_c->Handle,hdc);
   */
   //if (ACol!=1)
   //	 return;
   AnsiString Text;
   Text = StringGrid_gamma_c->Cells[ACol][ARow];
   if (RowSelect == ARow && Koeff[ARow] > 0) {
	 StringGrid_gamma_c->Canvas->Brush->Color = cl3DLight;
   }
   else {
	 StringGrid_gamma_c->Canvas->Brush->Color = clWhite;
   }
   StringGrid_gamma_c->Canvas->FillRect(Rect);
   DrawText(StringGrid_gamma_c->Canvas->Handle, Text.c_str(), Text.Length(), &Rect, DT_WORDBREAK);

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

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

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

void __fastcall TAdvanced_gamma_cForm::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_c = Koeff[RowSelect];

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

   Close();

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

