www.pudn.com > mfcdraw.zip > Unit2.cpp
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "Unit2.h" #include "Unit3.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "cspin" #pragma link "AdvGrid" #pragma resource "*.dfm" TSetupForm *SetupForm; const AnsiString ItemName[39]= { // "mark", // "bitnum", // "tdate", // "ttime", // "depth", // "lagdepth", // "lagtime", "rop", // "footage", "hookload", "wob", "rpm", "torque", "standpres", "caspres", "spm1", "spm2", "flowin", "flowout", "weightin", "weightout", "tempin", "tempout", "condin", "condout", "pit1", "pit2", "pit3", "pit4", "pit5", "pit6", "totalpit", "overflow", "c1", "c2", "c3", "ic4", "nc4", "ic5", "nc5", "tg", "co2", "h2", "he", "dc", "sigma", "ecd", // "totaltime", // "cost", // "hf", // "bf" }; const AnsiString GridHead[9]={"字段名","名称","单位","最大值","最小值","线型","线宽","栏宽","颜色"}; //--------------------------------------------------------------------------- __fastcall TSetupForm::TSetupForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TSetupForm::RDSelectClick(TObject *Sender) { rdindex=RDSelect->ItemIndex; switch(rdindex) { case 0: DepthFrom->Enabled=true; DepthTo->Enabled=true; TimeFrom->Enabled=false; TimeTo->Enabled=false; break; case 1: TimeFrom->Enabled=false; TimeTo->Enabled=false; DepthFrom->Enabled=true; DepthTo->Enabled=true; break; case 2: DepthFrom->Enabled=false; DepthTo->Enabled=false; TimeFrom->Enabled=true; TimeTo->Enabled=true; break; } // DepthFrom->Enabled=true; // DepthTo->Enabled=true; } //--------------------------------------------------------------------------- void __fastcall TSetupForm::FormActivate(TObject *Sender) { /* TRegistry *regkey= new TRegistry(); bool keygood=regkey->OpenKey("software\\odbc\\odbc.ini\\visual foxpro tables",false); if(keygood) { DBName=regkey->ReadString("SoureDB"); } delete regkey; */ for(int i=0;i<39;i++) { AnsiString fieldname=ItemName[i]; DefineItem->Items->Add(fieldname); } for(int i=0;i<9;i++) StringGrid1->Cells[i][0]=GridHead[i]; /* AnsiString stringtemp; stringtemp="select tdate,ttime,depth,lagdepth from realtime "; // DataModule3->SQL->Clear(); DataModule3->selectreal->Active=false; DataModule3->selectreal->SQL->Clear(); DataModule3->selectreal->SQL->Add(stringtemp); DataModule3->selectreal->ExecSQL(); DataModule3->selectreal->Active=true; DataModule3->selectreal->First(); DFInReal=DataModule3->selectreal->Fields[2]->AsFloat; LFInReal=DataModule3->selectreal->Fields[3]->AsFloat; /* DataModule3->selectreal->Last(); DTInReal=DataModule3->selectreal->Fields[2]->AsFloat; LTInReal=DataModule3->selectreal->Fields[3]->AsFloat; AnsiString timestring; do { stringdate=DataModule3->selectreal->Fields[0]->AsString; stringtime=DataModule3->selectreal->Fields[1]->AsString; timestring =stringdate+" "+stringtime; TimeFrom->Items->Add(timestring); TimeTo->Items->Add(timestring); DataModule3->selectreal->Next(); }while(!DataModule3->selectreal->Eof) ; DTInReal=DataModule3->selectreal->Fields[2]->AsFloat; LTInReal=DataModule3->selectreal->Fields[3]->AsFloat; // AnsiString string1,string2; // string1.FormatFloat("0.00", // LbRealDepth->Caption=AnsiString(DFInReal).FormatFloat("0.00",DFInReal)+"~"+AnsiString(DTInReal).FormatFloat("0.00",DTInReal); // LbLagDepth->Caption=AnsiString(LFInReal).FormatFloat("0.00",LFInReal)+"~"+AnsiString(LTInReal).FormatFloat("0.00",LTInReal); // DataModule3->selectreal->Active=false; */ TimeFrom->Enabled=false; TimeTo->Enabled=false; TimeFrom->ItemIndex=0; TimeTo->ItemIndex=0; CBblc->ItemIndex=0; LineStyle->ItemIndex=0; } //--------------------------------------------------------------------------- /* void __fastcall TSetupForm::BitBtn3Click(TObject *Sender) { StringGrid1->RowCount= StringGrid1->RowCount+1; } */ //--------------------------------------------------------------------------- void __fastcall TSetupForm::BtnAddContentClick(TObject *Sender) { bool iniset=true; if(atof((EdMin->Text.c_str()))>=atof((EdMax->Text.c_str())) ) { ShowMessage("最大,最小值设置错误!"); iniset=false; } if(iniset) { tracknum=StringGrid1->Row; for(int i=1;i Cells[0][i]; if(StringGrid1->Cells[0][i].IsEmpty()) { StringGrid1->Row=i; tracknum=i; break; } } if(tracknum!=0) { bool adddata=false; if(StringGrid1->Cells[0][tracknum].IsEmpty()) { adddata=true; } else if(Application->MessageBox("要替换此行数据吗?", "提示", MB_OKCANCEL)==IDOK) adddata=true; if(adddata) { StringGrid1->Cells[0][tracknum]=DefineItem->Text; StringGrid1->Cells[1][tracknum]=EdName->Text; StringGrid1->Cells[2][tracknum]=EdUnit->Text; StringGrid1->Cells[3][tracknum]=EdMax->Text; StringGrid1->Cells[4][tracknum]=EdMin->Text; StringGrid1->Cells[5][tracknum]=AnsiString(LineStyle->ItemIndex); StringGrid1->Cells[6][tracknum]=AnsiString(EdLineWidth->Value); StringGrid1->Cells[7][tracknum]=AnsiString(EdTrackWidth->Value); StringGrid1->Cells[8][tracknum]=AnsiString(Lab_Color->Color); } } } } //--------------------------------------------------------------------------- void __fastcall TSetupForm::sta_BlackClick(TObject *Sender) { TStaticText *pText= static_cast (Sender); // curindex=CheckListBox1->ItemIndex; Lab_Color->Color=pText->Color; Lab_Color->Repaint(); ColorPanel->Visible=false; } //--------------------------------------------------------------------------- void __fastcall TSetupForm::ysClick(TObject *Sender) { ColorPanel->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TSetupForm::BitBtn1Click(TObject *Sender) { SetupSuccess=true; if(RDSelect->ItemIndex!=2) { if(atof(DepthFrom->Text.c_str()) Text.c_str())>DTInReal) { // ShowMessage("井深设置有错误!"); DepthFrom->SetFocus(); return; } if(atof(DepthTo->Text.c_str()) Text.c_str())>DTInReal) { // ShowMessage("井深设置有错误!"); DepthTo->SetFocus(); return; } if(atof(DepthTo->Text.c_str()) Text.c_str())) { DepthTo->SetFocus(); // ShowMessage("井深设置有错误!"); return; } } DataModule3->selectreal->Active=true; DataModule3->selectreal->First(); DataModule3->selectreal->MoveBy(TimeFrom->ItemIndex); depthfrom=DataModule3->selectreal->Fields[2]->AsFloat; DataModule3->selectreal->MoveBy(TimeTo->ItemIndex-TimeFrom->ItemIndex); depthto=DataModule3->selectreal->Fields[2]->AsFloat; DataModule3->selectreal->Close(); } //--------------------------------------------------------------------------- void __fastcall TSetupForm::BitBtn2Click(TObject *Sender) { SetupSuccess=false; } //--------------------------------------------------------------------------- void __fastcall TSetupForm::BtSaveClick(TObject *Sender) { char szFileName[255]; int iFileHandle; int iLength; if (SaveDialog1->Execute()) { if (FileExists(SaveDialog1->FileName)) { fnsplit(SaveDialog1->FileName.c_str(), 0, 0, szFileName, 0); strcat(szFileName, ".BAK"); RenameFile(SaveDialog1->FileName, szFileName); } StringGrid1->SaveToFile(SaveDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TSetupForm::BtOpenClick(TObject *Sender) { char szFileName[MAXFILE+4]; int iFileHandle; int iLength; if (OpenDialog1->Execute()) { if (!FileExists(OpenDialog1->FileName)) { int button; button = Application->MessageBox("Cannot find this file", "Message Box", MB_OK); } StringGrid1->LoadFromFile(OpenDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TSetupForm::AddRowClick(TObject *Sender) { tracknum=StringGrid1->Row; StringGrid1->InsertRows(tracknum,1); } //--------------------------------------------------------------------------- void __fastcall TSetupForm::DeleteRowClick(TObject *Sender) { tracknum=StringGrid1->Row; StringGrid1->RemoveRows(tracknum,1); } //--------------------------------------------------------------------------- void __fastcall TSetupForm::ClearContentClick(TObject *Sender) { StringGrid1->Clear(); } //--------------------------------------------------------------------------- void __fastcall TSetupForm::DepthFromExit(TObject *Sender) { if(atof(DepthFrom->Text.c_str()) Text.c_str())>DTInReal) { // ShowMessage("井深设置有错误!"); DepthFrom->SetFocus(); // return; } } //--------------------------------------------------------------------------- void __fastcall TSetupForm::DepthToExit(TObject *Sender) { if(atof(DepthTo->Text.c_str()) Text.c_str())>DTInReal) { // ShowMessage("井深设置有错误!"); DepthTo->SetFocus(); // return; } } //--------------------------------------------------------------------------- void __fastcall TSetupForm::BitBtn3Click(TObject *Sender) { SaveDialog1->DefaultExt = "dbf"; SaveDialog1->FileName = "*.dbf"; SaveDialog1->Title="选择实时数据库"; if (SaveDialog1->Execute()) { MasDbf->Text = SaveDialog1->FileName; MasDbf->Repaint(); DbPath=ExtractFilePath(SaveDialog1->FileName); MainDBFNameExt= ExtractFileName(SaveDialog1->FileName); MainDBFName=ChangeFileExt(MainDBFNameExt,EmptyStr); AnsiString stringtemp; stringtemp="select tdate,ttime,depth,lagdepth from "+MainDBFName; // DataModule3->SQL->Clear(); try { DataModule3->selectreal->Active=false; DataModule3->selectreal->SQL->Clear(); DataModule3->selectreal->SQL->Add(stringtemp); DataModule3->selectreal->ExecSQL(); DataModule3->selectreal->Active=true; DataModule3->selectreal->First(); DFInReal=DataModule3->selectreal->Fields[2]->AsFloat; LFInReal=DataModule3->selectreal->Fields[3]->AsFloat; /* DataModule3->selectreal->Last(); DTInReal=DataModule3->selectreal->Fields[2]->AsFloat; LTInReal=DataModule3->selectreal->Fields[3]->AsFloat; */ AnsiString timestring; do { stringdate=DataModule3->selectreal->Fields[0]->AsString; stringtime=DataModule3->selectreal->Fields[1]->AsString; timestring =stringdate+" "+stringtime; TimeFrom->Items->Add(timestring); TimeTo->Items->Add(timestring); DataModule3->selectreal->Next(); }while(!DataModule3->selectreal->Eof) ; DTInReal=DataModule3->selectreal->Fields[2]->AsFloat; LTInReal=DataModule3->selectreal->Fields[3]->AsFloat; // AnsiString string1,string2; // string1.FormatFloat("0.00", LbRealDepth->Caption=AnsiString(DFInReal).FormatFloat("0.00",DFInReal)+"~"+AnsiString(DTInReal).FormatFloat("0.00",DTInReal); LbLagDepth->Caption=AnsiString(LFInReal).FormatFloat("0.00",LFInReal)+"~"+AnsiString(LTInReal).FormatFloat("0.00",LTInReal); DataModule3->selectreal->Active=false; } catch(...) { ShowMessage("数据库打开错误!"); } } } //---------------------------------------------------------------------------