⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~cpp

📁 使用borland C++寫成的簡單小程式
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <IniFiles.hpp>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
int foodcount;
int tablecount;
bool recheck=false;
int clock;
TForm1 *Form1;
HANDLE hComm;
bool blink;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
     String  path;
     TIniFile *pIniFile;
     path.SetLength(MAX_PATH);
     path.SetLength(GetCurrentDirectory(path.Length(), path.c_str()));
     path = path + '\\' + String("垫虫砞﹚.mp");
     pIniFile = new TIniFile(path);
     String foodname,item;
     int value;
     foodcount = pIniFile->ReadInteger("setup","count",0);
     tablecount = pIniFile->ReadInteger("setup","tables",0);
     StringGrid2->RowCount = foodcount+1;
     foodindex->RowCount = foodcount+1;
     table->Clear();
     for(int i =1;i<=tablecount;i++)
     {
       table->Items->Add(IntToStr(i));
       ComboBox1->Items->Add(IntToStr(i));
     }
     table->ItemIndex=0;
     ComboBox1->ItemIndex=0;
     for(int i =0;i<foodcount;i++)
     {
       item = "File"+IntToStr(i);
       foodname = pIniFile->ReadString("FileList",item,"");
       value = pIniFile->ReadInteger("money",item,0);
       StringGrid2->Cells[1][i+1]=foodname;
       foodindex->Cells[1][i+1]=foodname;
       foodindex->Cells[2][i+1]=value;
     }
     delete pIniFile;

}
void __fastcall TForm1::countfood()
{
  int count[255];
  if(!StringGrid1->Enabled)
  {
  for(int i =1;i<=foodcount;i++)
  {
    StringGrid2->Cells[2][i]=0;
  }
  }
  else
  {
  for(int i =1;i<=foodcount;i++)
  {
    count[i] =0;
  }
  for(int j=1;j<StringGrid1->RowCount;j++)
  {
    count[StrToInt(StringGrid1->Cells[4][j])]+=StrToInt(StringGrid1->Cells[3][j]);
  }
  for(int i =1;i<=foodcount;i++)
  {
    StringGrid2->Cells[2][i]=count[i];
  }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Datafix(BYTE *data)
{
  int table;
  table = data[6];
  for(int i =0;i<10;i++)
  {
    if(data[10+(i*2)] ==0)
      break;
    if(data[11+(i*2)] !=0)
    {
      if(StringGrid1->Enabled)
      {
        StringGrid1->RowCount ++;
      }
      else
      {
        StringGrid1->Enabled = true;
      }
      if(StringGrid4->Enabled)
      {
        StringGrid4->RowCount ++;
      }
      else
      {
        StringGrid4->Enabled = true;
      }
      StringGrid1->Cells[1][StringGrid1->RowCount -1] = table;
      StringGrid1->Cells[2][StringGrid1->RowCount -1] =  foodindex->Cells[1][data[10+(i*2)]];
      StringGrid1->Cells[4][StringGrid1->RowCount -1] =data[10+(i*2)];
      StringGrid1->Cells[3][StringGrid1->RowCount -1] = data[11+(i*2)];
      StringGrid4->Cells[1][StringGrid4->RowCount -1] = table;
      StringGrid4->Cells[2][StringGrid4->RowCount -1] =  foodindex->Cells[1][data[10+(i*2)]];
      StringGrid4->Cells[4][StringGrid4->RowCount -1] =data[10+(i*2)];
      StringGrid4->Cells[3][StringGrid4->RowCount -1] = data[11+(i*2)];
    }
  }
  countfood();
  tableChange(ComboBox1);
}

void __fastcall TForm1::datachange(String indata)
{
  BYTE data[32];
  for(int i=0;i<31;i++)
  {
      data[i]=StrToInt("0x"+indata.SubString(i+1,1));
  }
  Datafix(data);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  BYTE data[32];
  data[0] = 1;
  data[1] = 1;
  data[2] = 1;
  data[3] = 1;
  data[4] = 1;
  data[5] = 1;
  data[6] = ComboBox1->ItemIndex+1;
  data[7] = 1;
  data[8] = 1;
  data[9] = 1;
  data[10]=1;
  data[11]=3;
  data[12]=2;
  data[13]=3;
  data[14]=3;
  data[15]=3;
  data[16]=4;
  data[17]=3;
  data[18]=5;
  data[19]=3;
  data[20]=6;
  data[21]=3;
  data[22]=7;
  data[23]=3;
  data[24]=8;
  data[25]=3;
  data[26]=9;
  data[27]=3;
  data[28]=10;
  data[29]=3;
  data[30]=1;
  data[31]=0xf;
  Datafix(data);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::tableChange(TObject *Sender)
{
  double pay;
  pay =0;
  if(!StringGrid4->Enabled)
    return;
  for(int i=1;i<StringGrid3->RowCount;i++)
    StringGrid3->Rows[i]->Clear();
  StringGrid3->Enabled =false;
  StringGrid3->RowCount =2;
  for(int i=1;i<StringGrid4->RowCount;i++)
  {
    if(StrToInt(StringGrid4->Cells[1][i]) ==table->ItemIndex +1)
    {
      if(StringGrid3->Enabled)
        StringGrid3->RowCount ++;
      else
        StringGrid3->Enabled = true;
      StringGrid3->Cells[1][StringGrid3->RowCount -1] =StringGrid4->Cells[2][i];
      StringGrid3->Cells[2][StringGrid3->RowCount -1] =StrToInt(StringGrid4->Cells[3][i]) *StrToInt(foodindex->Cells[2][StrToInt(StringGrid4->Cells[4][i])]);
      pay = pay + StrToInt(StringGrid4->Cells[3][i]) *StrToInt(foodindex->Cells[2][StrToInt(StringGrid4->Cells[4][i])]);
    }
  }
  Panel1->Font->Color = clWindowText;
  if(StringGrid3->Enabled)
  {
    blink = false;
    Panel1->Caption = "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -