📄 currentdata.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CurrentData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TTCurrentData *TCurrentData;
//---------------------------------------------------------------------------
__fastcall TTCurrentData::TTCurrentData(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TTCurrentData::FormShow(TObject *Sender)
{
//联合站信息
StationGrid->Cells[0][0]="联合站名称";
StationGrid->ColWidths[0]=100;
StationGrid->Cells[1][0]="横坐标";
StationGrid->ColWidths[1]=60;
StationGrid->Cells[2][0]="纵坐标";
StationGrid->ColWidths[2]=60;
StationGrid->Cells[3][0]="最大处理量(吨/天)";
StationGrid->ColWidths[3]=130;
StationGrid->Cells[4][0]="当前处理量(吨/天)";
StationGrid->ColWidths[4]=130;
//转油站信息
ZhuanGrid->Cells[0][0]="编号";
ZhuanGrid->ColWidths[0]=60;
ZhuanGrid->Cells[1][0]="转油站名称";
ZhuanGrid->ColWidths[1]=100;
ZhuanGrid->Cells[2][0]="横坐标";
ZhuanGrid->ColWidths[2]=60;
ZhuanGrid->Cells[3][0]="纵坐标";
ZhuanGrid->ColWidths[3]=60;
ZhuanGrid->Cells[4][0]="最大处理量(吨/天)";
ZhuanGrid->ColWidths[4]=130;
ZhuanGrid->Cells[5][0]="当前处理量(吨/天)";
ZhuanGrid->ColWidths[5]=130;
//读取文件信息
TFileStream *File;
File=new TFileStream("CurrentData.dat",fmOpenRead|fmShareExclusive);
double TempDouble;
int TempInt,Flag,n=1;
AnsiString TempStr;
char *str;
__int64 Position;
//文件长度
Position=File->Size;
//标识位
while(File->Position<Position)
{
File->Read(&Flag,sizeof(int));
if(Flag==1)
{
//联合站
File->Read(&TempInt,sizeof(int));
str=new char[TempInt+1];
File->Read(str,TempInt);
str[TempInt]=0;
TempStr=(AnsiString)str;
delete str;
//名称
StationGrid->Cells[0][1]=TempStr;
//坐标
File->Read(&TempDouble,sizeof(double));
StationGrid->Cells[1][1]=FloatToStr(TempDouble);
File->Read(&TempDouble,sizeof(double));
StationGrid->Cells[2][1]=FloatToStr(TempDouble);
//处理量
File->Read(&TempDouble,sizeof(double));
StationGrid->Cells[3][1]=FloatToStr(TempDouble);
File->Read(&TempDouble,sizeof(double));
StationGrid->Cells[4][1]=FloatToStr(TempDouble);
}
else
{
ZhuanGrid->RowCount=n+1;
//转油站
ZhuanGrid->Cells[0][n]=FloatToStr(n);
File->Read(&TempInt,sizeof(int));
str=new char[TempInt+1];
File->Read(str,TempInt);
str[TempInt]=0;
TempStr=(AnsiString)str;
delete str;
//名称
ZhuanGrid->Cells[1][n]=TempStr;
//坐标
File->Read(&TempDouble,sizeof(double));
ZhuanGrid->Cells[2][n]=FloatToStr(TempDouble);
File->Read(&TempDouble,sizeof(double));
ZhuanGrid->Cells[3][n]=FloatToStr(TempDouble);
//处理量
File->Read(&TempDouble,sizeof(double));
ZhuanGrid->Cells[4][n]=FloatToStr(TempDouble);
File->Read(&TempDouble,sizeof(double));
ZhuanGrid->Cells[5][n]=FloatToStr(TempDouble);
n++;
}
}
ZhuanGrid->Cells[0][1]="1";
delete File;
}
//---------------------------------------------------------------------------
void __fastcall TTCurrentData::CancelClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TTCurrentData::OKClick(TObject *Sender)
{
int n,i;
AnsiString TempStr;
if(StationGrid->Cells[0][1]=="")
{
Application->MessageBox("'联合站名称'为空!","警告",MB_OK);
return;
}
if(StationGrid->Cells[1][1]=="")
{
Application->MessageBox("'联合站横坐标'为空!","警告",MB_OK);
return;
}
if(StationGrid->Cells[2][1]=="")
{
Application->MessageBox("'联合站纵坐标'为空!","警告",MB_OK);
return;
}
if(StationGrid->Cells[3][1]=="")
{
Application->MessageBox("'联合站最大处理量'为空!","警告",MB_OK);
return;
}
if(StationGrid->Cells[4][1]=="")
{
Application->MessageBox("'联合站当前处理量'为空!","警告",MB_OK);
return;
}
n=ZhuanGrid->RowCount;
for(i=1;i<n;i++)
{
if(ZhuanGrid->Cells[1][i]=="")
{
TempStr="'编号"+FloatToStr(i)+" 转油站名称'为空!";
Application->MessageBox(TempStr.c_str(),"警告",MB_OK);
return;
}
if(ZhuanGrid->Cells[2][i]=="")
{
TempStr="'编号"+FloatToStr(i)+" 转油站横坐标'为空!";
Application->MessageBox(TempStr.c_str(),"警告",MB_OK);
return;
}
if(ZhuanGrid->Cells[3][i]=="")
{
TempStr="'编号"+FloatToStr(i)+" 转油站纵坐标'为空!";
Application->MessageBox(TempStr.c_str(),"警告",MB_OK);
return;
}
if(ZhuanGrid->Cells[4][i]=="")
{
TempStr="'编号"+FloatToStr(i)+" 转油站最大处理量'为空!";
Application->MessageBoxA(TempStr.c_str(),"警告",MB_OK);
return;
}
if(ZhuanGrid->Cells[5][i]=="")
{
TempStr="'编号"+FloatToStr(i)+" 转油站当前处理量'为空!";
Application->MessageBox(TempStr.c_str(),"警告",MB_OK);
return;
}
}
TFileStream *File;
File=new TFileStream("CurrentData.dat",fmCreate|fmOpenWrite|fmShareExclusive);
double TempDouble;
int TempInt;
//联合站
//标识位
TempInt=1;
File->Write(&TempInt,sizeof(int));
TempStr=StationGrid->Cells[0][1];
TempInt=TempStr.Length();
File->Write(&TempInt,sizeof(int));
File->Write(TempStr.c_str(),TempInt);
//横坐标
TempDouble=StrToFloat(StationGrid->Cells[1][1]);
File->Write(&TempDouble,sizeof(double));
//纵坐标
TempDouble=StrToFloat(StationGrid->Cells[2][1]);
File->Write(&TempDouble,sizeof(double));
//最大处理量
TempDouble=StrToFloat(StationGrid->Cells[3][1]);
File->Write(&TempDouble,sizeof(double));
//当前处理量
TempDouble=StrToFloat(StationGrid->Cells[4][1]);
File->Write(&TempDouble,sizeof(double));
//转油站
n=ZhuanGrid->RowCount;
for(i=1;i<n;i++)
{
//标识位
TempInt=0;
File->Write(&TempInt,sizeof(int));
//名称
TempStr=ZhuanGrid->Cells[1][i];
TempInt=TempStr.Length();
File->Write(&TempInt,sizeof(int));
File->Write(TempStr.c_str(),TempInt);
//横坐标
TempDouble=StrToFloat(ZhuanGrid->Cells[2][i]);
File->Write(&TempDouble,sizeof(double));
//纵坐标
TempDouble=StrToFloat(ZhuanGrid->Cells[3][i]);
File->Write(&TempDouble,sizeof(double));
//最大处理量
TempDouble=StrToFloat(ZhuanGrid->Cells[4][i]);
File->Write(&TempDouble,sizeof(double));
//当前处理量
TempDouble=StrToFloat(ZhuanGrid->Cells[5][i]);
File->Write(&TempDouble,sizeof(double));
}
delete File;
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TTCurrentData::AddClick(TObject *Sender)
{
ZhuanGrid->RowCount++;
ZhuanGrid->Cells[0][ZhuanGrid->RowCount-1]=FloatToStr(ZhuanGrid->RowCount-1);
}
//---------------------------------------------------------------------------
void __fastcall TTCurrentData::DeleteClick(TObject *Sender)
{
int i,n=ZhuanGrid->RowCount;
for(i=ZhuanGrid->Row;i<n-1;i++)
{
ZhuanGrid->Rows[i]=ZhuanGrid->Rows[i+1];
ZhuanGrid->Cells[0][i]=FloatToStr(i);
}
ZhuanGrid->Rows[n-1]->Clear();
if(n>2)
{
ZhuanGrid->RowCount--;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -