#include "alg.h"
#include "mylib.h"
#include "alg_cfg.h"
#include "demohelp.h"
#include "comtabl.h"

db_str_rec Com_tabl[] =
 {
  {"SHIFR",'C',0,9,0},{"N_ROW",'N',0,1,0},{"N_CLN",'N',0,1,0},
  {"NAMEW_1",'C',0,29,0},
  {"OBJ_1_1",'C',0,8,0}, {"SH_1_1",'C',0,9,0}, {"NC_1_1",'N',0,1,0}, {"T_1_1",'N',0,1,0}, {"NZ_1_1",'C',0,4,0},
  {"OBJ_1_2",'C',0,8,0}, {"SH_1_2",'C',0,9,0}, {"NC_1_2",'N',0,1,0}, {"T_1_2",'N',0,1,0}, {"NZ_1_2",'C',0,4,0},
  {"OBJ_1_3",'C',0,8,0}, {"SH_1_3",'C',0,9,0}, {"NC_1_3",'N',0,1,0}, {"T_1_3",'N',0,1,0}, {"NZ_1_3",'C',0,4,0},
  {"OBJ_1_4",'C',0,8,0}, {"SH_1_4",'C',0,9,0}, {"NC_1_4",'N',0,1,0}, {"T_1_4",'N',0,1,0}, {"NZ_1_4",'C',0,4,0},
  {"OBJ_1_5",'C',0,8,0}, {"SH_1_5",'C',0,9,0}, {"NC_1_5",'N',0,1,0}, {"T_1_5",'N',0,1,0}, {"NZ_1_5",'C',0,4,0},
  {"NAMEW_2",'C',0,29,0},
  {"OBJ_2_1",'C',0,8,0}, {"SH_2_1",'C',0,9,0}, {"NC_2_1",'N',0,1,0}, {"T_2_1",'N',0,1,0}, {"NZ_2_1",'C',0,4,0},
  {"OBJ_2_2",'C',0,8,0}, {"SH_2_2",'C',0,9,0}, {"NC_2_2",'N',0,1,0}, {"T_2_2",'N',0,1,0}, {"NZ_2_2",'C',0,4,0},
  {"OBJ_2_3",'C',0,8,0}, {"SH_2_3",'C',0,9,0}, {"NC_2_3",'N',0,1,0}, {"T_2_3",'N',0,1,0}, {"NZ_2_3",'C',0,4,0},
  {"OBJ_2_4",'C',0,8,0}, {"SH_2_4",'C',0,9,0}, {"NC_2_4",'N',0,1,0}, {"T_2_4",'N',0,1,0}, {"NZ_2_4",'C',0,4,0},
  {"OBJ_2_5",'C',0,8,0}, {"SH_2_5",'C',0,9,0}, {"NC_2_5",'N',0,1,0}, {"T_2_5",'N',0,1,0}, {"NZ_2_5",'C',0,4,0},
  {"NAMEW_3",'C',0,29,0},
  {"OBJ_3_1",'C',0,8,0}, {"SH_3_1",'C',0,9,0}, {"NC_3_1",'N',0,1,0}, {"T_3_1",'N',0,1,0}, {"NZ_3_1",'C',0,4,0},
  {"OBJ_3_2",'C',0,8,0}, {"SH_3_2",'C',0,9,0}, {"NC_3_2",'N',0,1,0}, {"T_3_2",'N',0,1,0}, {"NZ_3_2",'C',0,4,0},
  {"OBJ_3_3",'C',0,8,0}, {"SH_3_3",'C',0,9,0}, {"NC_3_3",'N',0,1,0}, {"T_3_3",'N',0,1,0}, {"NZ_3_3",'C',0,4,0},
  {"OBJ_3_4",'C',0,8,0}, {"SH_3_4",'C',0,9,0}, {"NC_3_4",'N',0,1,0}, {"T_3_4",'N',0,1,0}, {"NZ_3_4",'C',0,4,0},
  {"OBJ_3_5",'C',0,8,0}, {"SH_3_5",'C',0,9,0}, {"NC_3_5",'N',0,1,0}, {"T_3_5",'N',0,1,0}, {"NZ_3_5",'C',0,4,0},
  {"NAMEW_4",'C',0,29,0},
  {"OBJ_4_1",'C',0,8,0}, {"SH_4_1",'C',0,9,0}, {"NC_4_1",'N',0,1,0}, {"T_4_1",'N',0,1,0}, {"NZ_4_1",'C',0,4,0},
  {"OBJ_4_2",'C',0,8,0}, {"SH_4_2",'C',0,9,0}, {"NC_4_2",'N',0,1,0}, {"T_4_2",'N',0,1,0}, {"NZ_4_2",'C',0,4,0},
  {"OBJ_4_3",'C',0,8,0}, {"SH_4_3",'C',0,9,0}, {"NC_4_3",'N',0,1,0}, {"T_4_3",'N',0,1,0}, {"NZ_4_3",'C',0,4,0},
  {"OBJ_4_4",'C',0,8,0}, {"SH_4_4",'C',0,9,0}, {"NC_4_4",'N',0,1,0}, {"T_4_4",'N',0,1,0}, {"NZ_4_4",'C',0,4,0},
  {"OBJ_4_5",'C',0,8,0}, {"SH_4_5",'C',0,9,0}, {"NC_4_5",'N',0,1,0}, {"T_4_5",'N',0,1,0}, {"NZ_4_5",'C',0,4,0},
  {"NAMEW_5",'C',0,29,0},
  {"OBJ_5_1",'C',0,8,0}, {"SH_5_1",'C',0,9,0}, {"NC_5_1",'N',0,1,0}, {"T_5_1",'N',0,1,0}, {"NZ_5_1",'C',0,4,0},
  {"OBJ_5_2",'C',0,8,0}, {"SH_5_2",'C',0,9,0}, {"NC_5_2",'N',0,1,0}, {"T_5_2",'N',0,1,0}, {"NZ_5_2",'C',0,4,0},
  {"OBJ_5_3",'C',0,8,0}, {"SH_5_3",'C',0,9,0}, {"NC_5_3",'N',0,1,0}, {"T_5_3",'N',0,1,0}, {"NZ_5_3",'C',0,4,0},
  {"OBJ_5_4",'C',0,8,0}, {"SH_5_4",'C',0,9,0}, {"NC_5_4",'N',0,1,0}, {"T_5_4",'N',0,1,0}, {"NZ_5_4",'C',0,4,0},
  {"OBJ_5_5",'C',0,8,0}, {"SH_5_5",'C',0,9,0}, {"NC_5_5",'N',0,1,0}, {"T_5_5",'N',0,1,0}, {"NZ_5_5",'C',0,4,0},
  {"NAMEW_6",'C',0,29,0},
  {"OBJ_6_1",'C',0,8,0}, {"SH_6_1",'C',0,9,0}, {"NC_6_1",'N',0,1,0}, {"T_6_1",'N',0,1,0}, {"NZ_6_1",'C',0,4,0},
  {"OBJ_6_2",'C',0,8,0}, {"SH_6_2",'C',0,9,0}, {"NC_6_2",'N',0,1,0}, {"T_6_2",'N',0,1,0}, {"NZ_6_2",'C',0,4,0},
  {"OBJ_6_3",'C',0,8,0}, {"SH_6_3",'C',0,9,0}, {"NC_6_3",'N',0,1,0}, {"T_6_3",'N',0,1,0}, {"NZ_6_3",'C',0,4,0},
  {"OBJ_6_4",'C',0,8,0}, {"SH_6_4",'C',0,9,0}, {"NC_6_4",'N',0,1,0}, {"T_6_4",'N',0,1,0}, {"NZ_6_4",'C',0,4,0},
  {"OBJ_6_5",'C',0,8,0}, {"SH_6_5",'C',0,9,0}, {"NC_6_5",'N',0,1,0}, {"T_6_5",'N',0,1,0}, {"NZ_6_5",'C',0,4,0},
  {"NAMEW_7",'C',0,29,0},
  {"OBJ_7_1",'C',0,8,0}, {"SH_7_1",'C',0,9,0}, {"NC_7_1",'N',0,1,0}, {"T_7_1",'N',0,1,0}, {"NZ_7_1",'C',0,4,0},
  {"OBJ_7_2",'C',0,8,0}, {"SH_7_2",'C',0,9,0}, {"NC_7_2",'N',0,1,0}, {"T_7_2",'N',0,1,0}, {"NZ_7_2",'C',0,4,0},
  {"OBJ_7_3",'C',0,8,0}, {"SH_7_3",'C',0,9,0}, {"NC_7_3",'N',0,1,0}, {"T_7_3",'N',0,1,0}, {"NZ_7_3",'C',0,4,0},
  {"OBJ_7_4",'C',0,8,0}, {"SH_7_4",'C',0,9,0}, {"NC_7_4",'N',0,1,0}, {"T_7_4",'N',0,1,0}, {"NZ_7_4",'C',0,4,0},
  {"OBJ_7_5",'C',0,8,0}, {"SH_7_5",'C',0,9,0}, {"NC_7_5",'N',0,1,0}, {"T_7_5",'N',0,1,0}, {"NZ_7_5",'C',0,4,0},
  {"NAMEW_8",'C',0,29,0},
  {"OBJ_8_1",'C',0,8,0}, {"SH_8_1",'C',0,9,0}, {"NC_8_1",'N',0,1,0}, {"T_8_1",'N',0,1,0}, {"NZ_8_1",'C',0,4,0},
  {"OBJ_8_2",'C',0,8,0}, {"SH_8_2",'C',0,9,0}, {"NC_8_2",'N',0,1,0}, {"T_8_2",'N',0,1,0}, {"NZ_8_2",'C',0,4,0},
  {"OBJ_8_3",'C',0,8,0}, {"SH_8_3",'C',0,9,0}, {"NC_8_3",'N',0,1,0}, {"T_8_3",'N',0,1,0}, {"NZ_8_3",'C',0,4,0},
  {"OBJ_8_4",'C',0,8,0}, {"SH_8_4",'C',0,9,0}, {"NC_8_4",'N',0,1,0}, {"T_8_4",'N',0,1,0}, {"NZ_8_4",'C',0,4,0},
  {"OBJ_8_5",'C',0,8,0}, {"SH_8_5",'C',0,9,0}, {"NC_8_5",'N',0,1,0}, {"T_8_5",'N',0,1,0}, {"NZ_8_5",'C',0,4,0},
  {"NAMEW_9",'C',0,29,0},
  {"OBJ_9_1",'C',0,8,0}, {"SH_9_1",'C',0,9,0}, {"NC_9_1",'N',0,1,0}, {"T_9_1",'N',0,1,0}, {"NZ_9_1",'C',0,4,0},
  {"OBJ_9_2",'C',0,8,0}, {"SH_9_2",'C',0,9,0}, {"NC_9_2",'N',0,1,0}, {"T_9_2",'N',0,1,0}, {"NZ_9_2",'C',0,4,0},
  {"OBJ_9_3",'C',0,8,0}, {"SH_9_3",'C',0,9,0}, {"NC_9_3",'N',0,1,0}, {"T_9_3",'N',0,1,0}, {"NZ_9_3",'C',0,4,0},
  {"OBJ_9_4",'C',0,8,0}, {"SH_9_4",'C',0,9,0}, {"NC_9_4",'N',0,1,0}, {"T_9_4",'N',0,1,0}, {"NZ_9_4",'C',0,4,0},
  {"OBJ_9_5",'C',0,8,0}, {"SH_9_5",'C',0,9,0}, {"NC_9_5",'N',0,1,0}, {"T_9_5",'N',0,1,0}, {"NZ_9_5",'C',0,4,0},
  {"NAMEW_10",'C',0,29,0},
  {"OBJ_10_1",'C',0,8,0}, {"SH_10_1",'C',0,9,0}, {"NC_10_1",'N',0,1,0}, {"T_10_1",'N',0,1,0}, {"NZ_10_1",'C',0,4,0},
  {"OBJ_10_2",'C',0,8,0}, {"SH_10_2",'C',0,9,0}, {"NC_10_2",'N',0,1,0}, {"T_10_2",'N',0,1,0}, {"NZ_10_2",'C',0,4,0},
  {"OBJ_10_3",'C',0,8,0}, {"SH_10_3",'C',0,9,0}, {"NC_10_3",'N',0,1,0}, {"T_10_3",'N',0,1,0}, {"NZ_10_3",'C',0,4,0},
  {"OBJ_10_4",'C',0,8,0}, {"SH_10_4",'C',0,9,0}, {"NC_10_4",'N',0,1,0}, {"T_10_4",'N',0,1,0}, {"NZ_10_4",'C',0,4,0},
  {"OBJ_10_5",'C',0,8,0}, {"SH_10_5",'C',0,9,0}, {"NC_10_5",'N',0,1,0}, {"T_10_5",'N',0,1,0}, {"NZ_10_5",'C',0,4,0},
  {"NAMEW_11",'C',0,29,0},
  {"OBJ_11_1",'C',0,8,0}, {"SH_11_1",'C',0,9,0}, {"NC_11_1",'N',0,1,0}, {"T_11_1",'N',0,1,0}, {"NZ_11_1",'C',0,4,0},
  {"OBJ_11_2",'C',0,8,0}, {"SH_11_2",'C',0,9,0}, {"NC_11_2",'N',0,1,0}, {"T_11_2",'N',0,1,0}, {"NZ_11_2",'C',0,4,0},
  {"OBJ_11_3",'C',0,8,0}, {"SH_11_3",'C',0,9,0}, {"NC_11_3",'N',0,1,0}, {"T_11_3",'N',0,1,0}, {"NZ_11_3",'C',0,4,0},
  {"OBJ_11_4",'C',0,8,0}, {"SH_11_4",'C',0,9,0}, {"NC_11_4",'N',0,1,0}, {"T_11_4",'N',0,1,0}, {"NZ_11_4",'C',0,4,0},
  {"OBJ_11_5",'C',0,8,0}, {"SH_11_5",'C',0,9,0}, {"NC_11_5",'N',0,1,0}, {"T_11_5",'N',0,1,0}, {"NZ_11_5",'C',0,4,0},
  {"NAMEW_12",'C',0,29,0},
  {"OBJ_12_1",'C',0,8,0}, {"SH_12_1",'C',0,9,0}, {"NC_12_1",'N',0,1,0}, {"T_12_1",'N',0,1,0}, {"NZ_12_1",'C',0,4,0},
  {"OBJ_12_2",'C',0,8,0}, {"SH_12_2",'C',0,9,0}, {"NC_12_2",'N',0,1,0}, {"T_12_2",'N',0,1,0}, {"NZ_12_2",'C',0,4,0},
  {"OBJ_12_3",'C',0,8,0}, {"SH_12_3",'C',0,9,0}, {"NC_12_3",'N',0,1,0}, {"T_12_3",'N',0,1,0}, {"NZ_12_3",'C',0,4,0},
  {"OBJ_12_4",'C',0,8,0}, {"SH_12_4",'C',0,9,0}, {"NC_12_4",'N',0,1,0}, {"T_12_4",'N',0,1,0}, {"NZ_12_4",'C',0,4,0},
  {"OBJ_12_5",'C',0,8,0}, {"SH_12_5",'C',0,9,0}, {"NC_12_5",'N',0,1,0}, {"T_12_5",'N',0,1,0}, {"NZ_12_5",'C',0,4,0}
 };

TComtDialog::TComtDialog( ) :
               TDialog( TRect( 0, 0, 70, 19 ),""),
               TWindowInit( TComtDialog::initFrame )
{
 char str[256], *str1;
 int i;

 options |= ofCentered;
 helpCtx=hcAllASave;

 getcwd(PathDir,sizeof(PathDir));

 sprintf(str,Text_msg[40],PathDir);
 title=newStr(str);

 TView *Monosel = new TView(TRect(13,2,68,4)); Monosel->options |= ofFramed; insert(Monosel);
 Monosel = new TView(TRect(13,5,49,17)); Monosel->options |= ofFramed; insert(Monosel);

 myApp->LoadCompt(NameComt,&BasaDBF);

 Colect = new TCompCollect(10,10);
 ScrollBar1 = new TScrollBar( TRect( 11, 2, 12, 17) ); insert(ScrollBar1);
 MyTListBox1 = new TMyTListBox(TRect( 2, 2, 11, 17), 1, ScrollBar1,NULL); insert(MyTListBox1);
 MyTListBox1->helpCtx=hcMax;
 TMyLabel *Label = new TMyLabel(TRect(2, 1, 12, 2),"Кадры",MyTListBox1,1); insert(Label);

 EditRow = new TEdit( TRect(22, 2, 23, 3),2,EnterNumber); insert(EditRow);
 Label = new TMyLabel(TRect(13, 2, 18, 3),"Строк",EditRow,1); insert(Label);
 EditLine = new TEdit( TRect(22, 3, 23, 4),2,EnterNumber); insert(EditLine);
 Label = new TMyLabel(TRect(13, 3, 20, 4),"Колонок",EditLine,1); insert(Label);

 ScrollBar2 = new TScrollBar( TRect( 48, 5, 49, 17) ); insert(ScrollBar2);
 MyTListBox2 = new TMyTListBox(TRect( 13, 5, 48, 17), 1, ScrollBar2,SelectInput1); insert(MyTListBox2);
 MyTListBox2->helpCtx = hcComboEdit;
 Label = new TMyLabel(TRect(17, 4, 45, 5),"Окна",MyTListBox2,1); insert(Label);
 Colect2 = new TCompCollect(10,10); MyTListBox2->newList(Colect2);

 Label = new TMyLabel(TRect(50, 5, 58, 6),"Имя",NULL,1); insert(Label);
 Label = new TMyLabel(TRect(59, 5, 68, 6),"Шифр",NULL,1); insert(Label);
 for(i=0;i<5;i++)
 {Edit2[i] = new TEdit( TRect(50, 6+i, 58, 7+i),9,EnterNumber1); insert(Edit2[i]); }
 for(i=0;i<5;i++)
 {Edit3[i] = new TEdit( TRect(59, 6+i, 68, 7+i),10,SelectInput); insert(Edit3[i]); }

 TButton *Button = new TButton( TRect( 52,12, 62, 14),Text_msg[115], cmOK, bfDefault ); insert(Button);
 Button = new TButton( TRect( 52,14, 62, 16),Text_msg[114], cmCancel, bfNormal ); insert(Button);

 for(i=0;i<BasaDBF->GetCountItems();i++)
 {
  str1 = new char[10];
  BasaDBF->GetFieldIt(i,"SHIFR",str1);
  Colect->insert(str1);
 }
 MyTListBox1->newList(Colect);

 View(OldIndChek=0);

 MyTListBox1->select();

 Modif=False;
 Modifs=False;
}

TComtDialog::~TComtDialog()
{
 delete BasaDBF;
 myApp->FreeColect(Colect);
 myApp->FreeColect(Colect2);
}

void TComtDialog::handleEvent ( TEvent& event )
{
 int i,iii;
 char str[256],*str1,*str2;
 ushort control;

 if( event.what == evCommand && event.message.command == cmClose)
 {
  if(Modif || Modifs)
  {
   control = messageBox(Text_msg[26],mfWarning | mfOKCancel);
   if(control==cmOK)
   {
    if(Modif) SaveChenge(MyTListBox1->focused);
    sprintf(str,Text_msg[109],PathDir,NameComt);
    BasaDBF->SaveFile(str);
   }
  }
 }

 TDialog::handleEvent(event);

#ifdef __DOS32__
 if( event.what == evBroadcast && event.message.command == cmGetBuf) Modif=True;
#endif

 if( event.what == evBroadcast && event.message.command == cmScrollBarChanged) //List ListBox
 {
  if(MyTListBox1->state & sfFocused)    // ListBox1
  {
   if(Modif)
   {
    control = messageBox(mfWarning | mfOKCancel,"Группа изменена. Сохранить изменения?");
    if(control==cmOK)
    {
     SaveChenge(OldIndChek);
     Modifs=True;
    }
    Modif=False;
   }
#ifdef __DOS32__
   if(getShiftState() & (kbLeftShift|kbRightShift))
   {
    str1=(char *)BasaDBF->getItem(OldIndChek);
    str2=(char *)BasaDBF->getItem(MyTListBox1->focused);
    BasaDBF->DeleteItems(OldIndChek,0);
    BasaDBF->AddItem(OldIndChek,str2);
    BasaDBF->DeleteItems(MyTListBox1->focused,0);
    BasaDBF->AddItem(MyTListBox1->focused,str1);

    Colect->freeAll();
    for(i=0;i<BasaDBF->GetCountItems();i++)
    {
     str1 = new char[10];
     BasaDBF->GetFieldIt(i,"SHIFR",str1);
     Colect->insert(str1);
    }
    MyTListBox1->drawView();
    Modifs=True;
   }
#endif
   View(MyTListBox1->focused);
   clearEvent(event);
   OldIndChek=MyTListBox1->focused;
  }
  if(MyTListBox2->state & sfFocused)    // ListBox1
  {  ViewWin(); }
 }

 if( event.what == evBroadcast && event.message.command == cmChange)
 {
  if(EditRow->state & sfFocused)
  {
   if(EditRow->data[0]>'3') EditRow->setData((char *)"3");
   if(EditRow->data[0]<'1') EditRow->setData((char *)"1");
  }
  if(EditLine->state & sfFocused)
  {
   if(EditLine->data[0]>'4') EditLine->setData((char *)"4");
   if(EditLine->data[0]<'1') EditLine->setData((char *)"1");
  }
  MaskEdit(atoi(EditRow->data),atoi(EditLine->data),MyTListBox1->focused);
  ViewWin();
  Modif=True;
 }

 if( event.what == evCommand )
 {
  switch( event.message.command )
  {
   case cmOK:
        SaveChenge(MyTListBox1->focused);
        Modifs=True; Modif=False;
        clearEvent(event);
        break;
   case cmCancel:
        View(MyTListBox1->focused);
        Modif=False;
        clearEvent(event);
        break;
   case cmSave1:
        control = messageBox(mfWarning | mfOKCancel,Text_msg[37]);
        if(control!=cmOK) break;
        SaveChenge(MyTListBox1->focused);
        sprintf(str,Text_msg[109],PathDir,NameComt);
        BasaDBF->SaveFile(str);
        Modif=Modifs=False;
        break;
   case cmReLoad:
        control = messageBox(mfWarning | mfOKCancel,Text_msg[38]);
        if(control!=cmOK) break;
        sprintf(str,Text_msg[109],PathDir,NameComt);
        myApp->LoadCompt(str,&BasaDBF); Colect->freeAll();
        for(i=0;i<BasaDBF->GetCountItems();i++)
        {
         str1 = new char[12];
         BasaDBF->GetFieldIt(i,"SHIFR",str1);
         Colect->insert(str1);
        }
        MyTListBox1->setRange( MyTListBox1->list()->getCount());
        MyTListBox1->drawView(); View(OldIndChek=0);
        Modif=Modifs=False;
        break;
   case cmInsert:
   case cmAdd:
        str1 = new char[12];
        str1[0]=0;
        control = inputBox("Ввод имени", "Группа",str1, 8);
        if(control==cmOK)
        {
         for(i=0;i<BasaDBF->GetCountItems();i++)
         {
          BasaDBF->GetFieldIt(i,"SHIFR",str);
          for(iii=7;iii>=0;iii--)if(str[iii]==' ')str[iii]=0;else break;
          if(!strncmp(str1,str,8)){ i= -1; break;}
         }
         if(i== -1){ DispFixErr(0,Text_msg[15],str1); delete str1; break;}
         if(event.message.command==cmInsert)
         {
          BasaDBF->CreateItems(MyTListBox1->focused);
          BasaDBF->ModifiFieldIt(MyTListBox1->focused,"SHIFR",str1);
          BasaDBF->ModifiFieldIt(MyTListBox1->focused,"N_ROW","1");
          BasaDBF->ModifiFieldIt(MyTListBox1->focused,"N_CLN","1");
          MyTListBox1->list()->atInsert(MyTListBox1->focused,str1);
         }
         if(event.message.command==cmAdd)
         {
          BasaDBF->CreateItems(BasaDBF->GetCountItems());
          BasaDBF->ModifiFieldIt(BasaDBF->GetCountItems()-1,"SHIFR",str1);
          BasaDBF->ModifiFieldIt(BasaDBF->GetCountItems()-1,"N_ROW","1");
          BasaDBF->ModifiFieldIt(BasaDBF->GetCountItems()-1,"N_CLN","1");
          MyTListBox1->list()->insert(str1);
         }
         MyTListBox1->setRange( MyTListBox1->list()->getCount() );
         MyTListBox1->drawView();
         View(MyTListBox1->focused);
         Modifs=True;
        }
        else delete str1;
        clearEvent(event);
        break;
   case cmDelete:
        if(!MyTListBox1->list()->getCount()) break;
        BasaDBF->DeleteItems(MyTListBox1->focused,1);
        MyTListBox1->list()->atFree(MyTListBox1->focused);
        MyTListBox1->setRange( MyTListBox1->list()->getCount() );
        MyTListBox1->drawView();
        View(MyTListBox1->focused);
        Modifs=True;
        clearEvent(event);
        break;
   case cmRename:
        str1 = new char[12];
        BasaDBF->GetFieldIt(MyTListBox1->focused,"SHIFR",str1);
        control = inputBox("Ввод имени", "Группа",str1, 8);
        if(control==cmOK)
        {
         for(i=0;i<BasaDBF->GetCountItems();i++)
         {
          BasaDBF->GetFieldIt(i,"SHIFR",str);
          if(!strncmp(str1,str,8)){ i= -1; break;}
         }
         if(i== -1){ DispFixErr(0,Text_msg[15],str1); delete str1; break;}
         BasaDBF->ModifiFieldIt(MyTListBox1->focused,"SHIFR",str1);
         MyTListBox1->list()->atFree(MyTListBox1->focused);
         MyTListBox1->list()->atInsert(MyTListBox1->focused,str1);
         MyTListBox1->setRange( MyTListBox1->list()->getCount() );
         MyTListBox1->drawView();
         View(MyTListBox1->focused);
         Modifs=True;
        }
        else delete str1;
        clearEvent(event);
        break;
   default: ;
  }
 }
}

void TComtDialog::View(int item)
{
 char str1[40];
 int x,y;

 if(!BasaDBF->GetCountItems()) return;

 BasaDBF->GetFieldIt(item,"N_ROW",str1); EditRow->setData(str1); x = atoi(str1);
 BasaDBF->GetFieldIt(item,"N_CLN",str1); EditLine->setData(str1); y = atoi(str1);

 MaskEdit(x,y,item);
 ViewWin();
}

void TComtDialog::ViewWin()
{
 char str1[10];
 int i,y,x1,y1,x3;

 y = atoi(EditLine->data);
 x1=(MyTListBox2->focused)/y;
 y1=(MyTListBox2->focused+1)-x1*y;
 x3=x1*4+y1;

 for(i=0;i<5;i++)
 {
  sprintf(str1,"OBJ_%d_%d",x3,i+1);
  BasaDBF->GetFieldIt(MyTListBox1->focused,str1,str1); Edit2[i]->setData(str1);
  sprintf(str1,"SH_%d_%d",x3,i+1);
  BasaDBF->GetFieldIt(MyTListBox1->focused,str1,str1); Edit3[i]->setData(str1);
 }
}

void TComtDialog::MaskEdit(int x,int y,int item)
{
 int i,ii;
 char *str2,str1[40];

 Colect2->freeAll();

 for(i=0;i<3;i++)
  for(ii=0;ii<4;ii++)
  {
   if((y-1)<ii || (x-1)<i) continue;
   str2 = new char[34];
   sprintf(str1,"NAMEW_%d",i*4+ii+1); if(BasaDBF->GetFieldIt(item,str1,str1)== -1)return;
   sprintf(str2,"%d.%d - %s",i+1,ii+1,str1);
   Colect2->insert(str2);
  }

 MyTListBox2->newList(Colect2,0);
}

int TComtDialog::SelectInput(void* source,TEvent& event)
{
 TEdit *Edit = (TEdit *)source;
 TComtDialog *Dialog = (TComtDialog *)Edit->owner;

 ushort control;

 if(event.what == evKeyboard)
  switch(event.keyDown.keyCode)
  {
   case 0x3920:
     control = myApp->execView( myApp->SelDialog = new TSelDialog(Dialog->PathDir,2,((TEdit *)source)->data/*Text_msg[49]*/));
     if(control==cmOK)
     {
      ((TEdit *)source)->setData( (char *)myApp->SelDialog->Colect2->at(myApp->SelDialog->ListBox2->focused) );
      Dialog->Modif=True;
     }
     destroy(myApp->SelDialog);
     break;
   case kbDel: ((TEdit *)source)->setData(Text_msg[49]); Dialog->Modif=True; break;
   case kbUp: Dialog->selectNext(True); Edit->clearEvent(event); break;
   case kbDown: Dialog->selectNext(False); Edit->clearEvent(event); break;
  }
 return(1);
}

int TComtDialog::SelectInput1(void* source,TEvent& event)
{
 TMyTListBox *ListBox = (TMyTListBox *)source;
 TComtDialog *Dialog = (TComtDialog *)ListBox->owner;
 char str[40];

 ushort control;

// DispFixErr(1,"Key = %d",event.message.command);

 if(event.what == evCommand && event.message.command == cmChange)
 {
  strcpy(str,(char *)ListBox->list()->at(ListBox->focused)+6);
  control = inputBox("Ввод имени", "Окно",str, 29);
  if(control==cmOK)
  {
   strcpy((char *)ListBox->list()->at(ListBox->focused)+6,str);
   Dialog->Modif=True;
   ListBox->drawView();
  }
 }

 if(event.what == evKeyboard && event.keyDown.keyCode == kbDel)
 {
  strcpy((char *)ListBox->list()->at(ListBox->focused)+6,"");
  Dialog->Modif=True; ListBox->drawView();
 }
 return(1);
}


int TComtDialog::EnterNumber(void* source,TEvent& event)
{
 char code;
 TEdit *Edit = (TEdit *)source;
 TComtDialog *Dialog = (TComtDialog *)Edit->owner;

 if(event.what == evKeyboard)
 {
  switch(event.keyDown.keyCode)
  {
   case kbDown: Dialog->selectNext(False); Edit->clearEvent(event); break;
   case kbUp: Dialog->selectNext(True); Edit->clearEvent(event); break;
  }
  code=event.keyDown.charScan.charCode;
  if( code>='0'&&code<='9')
  {
   Edit->setData(&code);
   message(Dialog,evBroadcast,cmChange,Edit); // Clicked
   Edit->clearEvent(event);
  }
 }
 return(1);
}

int TComtDialog::EnterNumber1(void* source,TEvent& event)
{
 TEdit *Edit = (TEdit *)source;
 TComtDialog *Dialog = (TComtDialog *)Edit->owner;

 if(event.what == evKeyboard)
 {
  switch(event.keyDown.keyCode)
  {
   case kbDown: Dialog->selectNext(False); Edit->clearEvent(event); break;
   case kbUp: Dialog->selectNext(True); Edit->clearEvent(event); break;
  }
 }
 return(0);
}


void TComtDialog::SaveChenge(int item)
{
 char str1[40];
 int ii,i,x,y,x1,y1,x3;

 BasaDBF->ModifiFieldIt(item,"N_ROW",EditRow->data);  x = atoi(EditRow->data);
 BasaDBF->ModifiFieldIt(item,"N_CLN",EditLine->data); y = atoi(EditLine->data);

 x1=(MyTListBox2->focused)/y; y1=(MyTListBox2->focused+1)-x1*y; x3=x1*4+y1;
 for(i=0;i<5;i++)
 {
  sprintf(str1,"OBJ_%d_%d",x3,i+1); BasaDBF->ModifiFieldIt(item,str1,Edit2[i]->data);
  sprintf(str1,"SH_%d_%d",x3,i+1);  BasaDBF->ModifiFieldIt(item,str1,Edit3[i]->data);
 }
 for(ii=0;ii<MyTListBox2->list()->getCount();ii++)
 {
  x1=(ii)/y; y1=(ii+1)-x1*y; x3=x1*4+y1;
  sprintf(str1,"NAMEW_%d",x3); BasaDBF->ModifiFieldIt(item,str1,(char *)MyTListBox2->list()->at(ii)+6);
 }
}

//==================================================
void TMyApp::LoadCompt(char* Name, TBasaDBF **BasaDBF)
{
 *BasaDBF = new TBasaDBF();
 if((*BasaDBF)->LoadFile(Name)== -1) (*BasaDBF)->LoadFields(Com_tabl,sizeof(Com_tabl)/sizeof(db_str_rec));
}