[2] | 1 | //--------------------------------------------------------------------------- |
---|
| 2 | |
---|
| 3 | #include <vcl.h> |
---|
| 4 | #pragma hdrstop |
---|
| 5 | |
---|
| 6 | #include "dbcedit.h" |
---|
| 7 | #include "stdio.h" |
---|
| 8 | #include "IdGlobal.hpp" |
---|
| 9 | #include <inifiles.hpp> |
---|
| 10 | #include "TitleFrm.h" |
---|
| 11 | #include <dir.h> |
---|
| 12 | #include "thOpenSource.h" |
---|
| 13 | #include "SearchFrm.h" |
---|
| 14 | //#include "SysUtils.hpp" |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | //--------------------------------------------------------------------------- |
---|
| 18 | #pragma package(smart_init) |
---|
| 19 | #pragma resource "*.dfm" |
---|
| 20 | TFrmMain *FrmMain; |
---|
| 21 | //--------------------------------------------------------------------------- |
---|
| 22 | __fastcall TFrmMain::TFrmMain(TComponent* Owner) |
---|
| 23 | : TForm(Owner) |
---|
| 24 | { |
---|
| 25 | OpenOk=false; |
---|
| 26 | Term=false; |
---|
| 27 | } |
---|
| 28 | //--------------------------------------------------------------------------- |
---|
| 29 | |
---|
| 30 | void __fastcall TFrmMain::btOpenClick(TObject *Sender) |
---|
| 31 | { |
---|
| 32 | if(OpenDialog1->Execute()){ |
---|
| 33 | if (FileExists(OpenDialog1->FileName)){ |
---|
| 34 | OpenOk=false; |
---|
| 35 | if(thOpen){ |
---|
| 36 | thOpen->Terminate(); |
---|
| 37 | } |
---|
| 38 | thOpen = new thOpenFile(false); |
---|
| 39 | //thOpen->Priority = tpTimeCritical; |
---|
| 40 | pnFileName->Caption = OpenDialog1->FileName; |
---|
| 41 | }else{ |
---|
| 42 | OpenOk=false; |
---|
| 43 | pnFileName->Caption = ""; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | //--------------------------------------------------------------------------- |
---|
| 48 | void __fastcall TFrmMain::btSaveClick(TObject *Sender) |
---|
| 49 | { |
---|
| 50 | //CurrentOpenFile; |
---|
| 51 | if(OpenOk){ |
---|
| 52 | SaveToFile(CurrentOpenFile.c_str()); |
---|
| 53 | }else{ |
---|
| 54 | ShowMessage("ÎÄŒþÎŽŽò¿ªÍê³É£¡"); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | //--------------------------------------------------------------------------- |
---|
| 58 | |
---|
| 59 | void TFrmMain::SaveToFile(const char * pszFileName) |
---|
| 60 | { |
---|
| 61 | char szFileName[255]; |
---|
| 62 | FILE *stream; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | fnsplit(pszFileName, 0, 0, szFileName, 0); |
---|
| 68 | strcat(szFileName, "_new.dbc"); |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | AnsiString NewFileName=ExtractFilePath(Application->ExeName)+szFileName;//=pszFileName; |
---|
| 72 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 73 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 74 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 75 | |
---|
| 76 | DWORD w; |
---|
| 77 | |
---|
| 78 | CopyFileTo(pszFileName,NewFileName); |
---|
| 79 | |
---|
| 80 | iFileHandle = FileOpen(NewFileName, fmOpenRead|fmOpenWrite);//Žò¿ªÎÄŒþ |
---|
| 81 | |
---|
| 82 | if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 83 | == NULL) |
---|
| 84 | { |
---|
| 85 | ShowMessage("Žò¿ªÎÄŒþ³öŽí"); |
---|
| 86 | return; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | int iVal; |
---|
| 91 | float fVal; |
---|
| 92 | bool isFloat; |
---|
| 93 | int ColType; |
---|
| 94 | |
---|
| 95 | FileSeek(iFileHandle,0x14,0); |
---|
| 96 | TIniFile *ini; |
---|
| 97 | ini = new TIniFile( iniSetFile ); |
---|
| 98 | |
---|
| 99 | for(int i=1; i<sgEdit->RowCount; i++) |
---|
| 100 | { |
---|
| 101 | for(int j=1; j<sgEdit->ColCount; j++) |
---|
| 102 | { |
---|
| 103 | if(j==1){ //ID |
---|
| 104 | iVal=StrToInt(sgEdit->Cells[j][i]); |
---|
| 105 | FileWrite(iFileHandle, &iVal, 4); |
---|
| 106 | }else{ |
---|
| 107 | |
---|
| 108 | //ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j-1),0); |
---|
| 109 | //thOpen->ColType[10000]; |
---|
| 110 | |
---|
| 111 | switch (thOpen->ColType[j]) |
---|
| 112 | { |
---|
| 113 | case 0: //ÕûÐÍ |
---|
| 114 | iVal=StrToFloat(sgEdit->Cells[j][i]); |
---|
| 115 | FileWrite(iFileHandle, &iVal, 4); |
---|
| 116 | break; |
---|
| 117 | case 1: //ž¡µã |
---|
| 118 | fVal=StrToFloat(sgEdit->Cells[j][i]); |
---|
| 119 | FileWrite(iFileHandle, &fVal, 4); |
---|
| 120 | break; |
---|
| 121 | case 2: //ÎıŸ |
---|
| 122 | fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(j-1))*4, 0); |
---|
| 123 | fread(&iVal, 4, 1, stream); |
---|
| 124 | FileWrite(iFileHandle, &iVal, 4); |
---|
| 125 | break; |
---|
| 126 | default: //ÕûÐÍ |
---|
| 127 | iVal=StrToFloat(sgEdit->Cells[j][i]); |
---|
| 128 | FileWrite(iFileHandle, &iVal, 4); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | FileClose(iFileHandle); |
---|
| 134 | fclose(stream); |
---|
| 135 | |
---|
| 136 | delete ini; |
---|
| 137 | ShowMessage("Save To File:"+NewFileName); |
---|
| 138 | } |
---|
| 139 | void __fastcall TFrmMain::btIntTypeClick(TObject *Sender) |
---|
| 140 | { |
---|
| 141 | if(OpenOk==true){ |
---|
| 142 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 143 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 144 | TIniFile *ini; |
---|
| 145 | ini = new TIniFile( iniSetFile ); |
---|
| 146 | ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),0); |
---|
| 147 | delete ini; |
---|
| 148 | thOpen->ColType[sgEdit->Col]=0; |
---|
| 149 | //ÖØÐÂŽò¿ª¶ÔÓŠÁеÄÖµ |
---|
| 150 | //OpenFileCol(AnsiString FileName,int ColType); |
---|
| 151 | OpenFileCol(CurrentOpenFile,sgEdit->Col,0); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | //--------------------------------------------------------------------------- |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | void __fastcall TFrmMain::btFloatTypeClick(TObject *Sender) |
---|
| 158 | { |
---|
| 159 | if(OpenOk==true){ |
---|
| 160 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 161 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 162 | TIniFile *ini; |
---|
| 163 | ini = new TIniFile( iniSetFile ); |
---|
| 164 | ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),1); |
---|
| 165 | delete ini; |
---|
| 166 | thOpen->ColType[sgEdit->Col]=1; |
---|
| 167 | OpenFileCol(CurrentOpenFile,sgEdit->Col,1); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | //--------------------------------------------------------------------------- |
---|
| 171 | |
---|
| 172 | void __fastcall TFrmMain::PopupMenu1Popup(TObject *Sender) |
---|
| 173 | { |
---|
| 174 | if(OpenOk==true){ |
---|
| 175 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 176 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 177 | int ColType; |
---|
| 178 | TIniFile *ini; |
---|
| 179 | ini = new TIniFile( iniSetFile ); |
---|
| 180 | ColType=ini->ReadInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),0); |
---|
| 181 | delete ini; |
---|
| 182 | switch (ColType) |
---|
| 183 | { |
---|
| 184 | case 0: |
---|
| 185 | btIntType->Checked=true; |
---|
| 186 | btFloatType->Checked=false; |
---|
| 187 | btTxtType->Checked=false; |
---|
| 188 | break; |
---|
| 189 | case 1: |
---|
| 190 | btIntType->Checked=false; |
---|
| 191 | btFloatType->Checked=true; |
---|
| 192 | btTxtType->Checked=false; |
---|
| 193 | break; |
---|
| 194 | case 2: |
---|
| 195 | btIntType->Checked=false; |
---|
| 196 | btFloatType->Checked=false; |
---|
| 197 | btTxtType->Checked=true; |
---|
| 198 | break; |
---|
| 199 | default: |
---|
| 200 | btIntType->Checked=true; |
---|
| 201 | btFloatType->Checked=false; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | //--------------------------------------------------------------------------- |
---|
| 206 | |
---|
| 207 | void __fastcall TFrmMain::N1Click(TObject *Sender) |
---|
| 208 | { |
---|
| 209 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 210 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 211 | int ColType; |
---|
| 212 | FrmTitle->edTitle->Text=sgEdit->Cells[sgEdit->Col][0]; |
---|
| 213 | if(FrmTitle->ShowModal()==mrOk){ |
---|
| 214 | TIniFile *ini; |
---|
| 215 | ini = new TIniFile( iniSetFile ); |
---|
| 216 | ini->WriteString(SectionName,"ColTitle"+IntToStr(sgEdit->Col),FrmTitle->edTitle->Text); |
---|
| 217 | delete ini; |
---|
| 218 | sgEdit->Cells[sgEdit->Col][0]=FrmTitle->edTitle->Text; |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | //--------------------------------------------------------------------------- |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | void __fastcall TFrmMain::FormDestroy(TObject *Sender) |
---|
| 226 | { |
---|
| 227 | if(thOpen){ |
---|
| 228 | thOpen->Terminate(); |
---|
| 229 | SleepEx(200,0); |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | //--------------------------------------------------------------------------- |
---|
| 233 | |
---|
| 234 | void __fastcall TFrmMain::ToolButton1Click(TObject *Sender) |
---|
| 235 | { |
---|
| 236 | bool SeFlag=true; |
---|
| 237 | if(FrmSearch->ShowModal()==mrOk){ |
---|
| 238 | switch (FrmSearch->rgSI->ItemIndex) |
---|
| 239 | { |
---|
| 240 | case 0: //ÏòÉÏÕÒ; |
---|
| 241 | for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col-1;i>sgEdit->ColCount;i--){ |
---|
| 242 | if(i%sgEdit->ColCount!=0){ |
---|
| 243 | if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount], |
---|
| 244 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 245 | sgEdit->Col=i-sgEdit->ColCount*i/sgEdit->ColCount; |
---|
| 246 | sgEdit->Row=i/sgEdit->ColCount; |
---|
| 247 | SeFlag=false; |
---|
| 248 | break; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | if(SeFlag) ShowMessage("Seach Top£¬Find Nothing."); |
---|
| 253 | break; |
---|
| 254 | case 1: //ÏòÏÂÕÒ; |
---|
| 255 | for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col+1;i<sgEdit->ColCount*sgEdit->RowCount;i++){ |
---|
| 256 | if(i%sgEdit->ColCount!=0){ |
---|
| 257 | if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount], |
---|
| 258 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 259 | sgEdit->Col=i-sgEdit->ColCount*(i/sgEdit->ColCount); |
---|
| 260 | sgEdit->Row=i/sgEdit->ColCount; |
---|
| 261 | SeFlag=false; |
---|
| 262 | break; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | if(SeFlag) ShowMessage("Seach End£¬Find Nothing"); |
---|
| 267 | break; |
---|
| 268 | case 2: //µ±Ç°ÁÐÏòÉÏÕÒ; |
---|
| 269 | for(int i=sgEdit->Row;i>1;i--){ |
---|
| 270 | if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i], |
---|
| 271 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 272 | sgEdit->Row=i; |
---|
| 273 | SeFlag=false; |
---|
| 274 | break; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | if(SeFlag) ShowMessage("Seach col top£¬Find Nothing"); |
---|
| 278 | break; |
---|
| 279 | case 3: //µ±Ç°ÁÐÏòÏÂÕÒ; |
---|
| 280 | for(int i=sgEdit->Row;i<sgEdit->RowCount;i++){ |
---|
| 281 | if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i], |
---|
| 282 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 283 | sgEdit->Row=i; |
---|
| 284 | SeFlag=false; |
---|
| 285 | break; |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | if(SeFlag) ShowMessage("Seach col end£¬Find Nothing."); |
---|
| 289 | break; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | //--------------------------------------------------------------------------- |
---|
| 294 | |
---|
| 295 | void __fastcall TFrmMain::sgEditKeyDown(TObject *Sender, WORD &Key, |
---|
| 296 | TShiftState Shift) |
---|
| 297 | { |
---|
| 298 | |
---|
| 299 | bool SeFlag=true; |
---|
| 300 | if(Key==VK_F3){ |
---|
| 301 | switch (FrmSearch->rgSI->ItemIndex) |
---|
| 302 | { |
---|
| 303 | case 0: //ÏòÉÏÕÒ; |
---|
| 304 | for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col-1;i>sgEdit->ColCount;i--){ |
---|
| 305 | if(i%sgEdit->ColCount!=0){ |
---|
| 306 | if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount], |
---|
| 307 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 308 | sgEdit->Col=i-sgEdit->ColCount*i/sgEdit->ColCount; |
---|
| 309 | sgEdit->Row=i/sgEdit->ColCount; |
---|
| 310 | SeFlag=false; |
---|
| 311 | break; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | if(SeFlag) ShowMessage("Seach Top£¬Find Nothing."); |
---|
| 316 | break; |
---|
| 317 | case 1: //ÏòÏÂÕÒ; |
---|
| 318 | for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col+1;i<sgEdit->ColCount*sgEdit->RowCount;i++){ |
---|
| 319 | if(i%sgEdit->ColCount!=0){ |
---|
| 320 | if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount], |
---|
| 321 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 322 | sgEdit->Col=i-sgEdit->ColCount*(i/sgEdit->ColCount); |
---|
| 323 | sgEdit->Row=i/sgEdit->ColCount; |
---|
| 324 | SeFlag=false; |
---|
| 325 | break; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | } |
---|
| 329 | if(SeFlag) ShowMessage("Seach End£¬Find Nothing."); |
---|
| 330 | break; |
---|
| 331 | case 2: //µ±Ç°ÁÐÏòÉÏÕÒ; |
---|
| 332 | for(int i=sgEdit->Row;i>1;i--){ |
---|
| 333 | if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i], |
---|
| 334 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 335 | sgEdit->Row=i; |
---|
| 336 | SeFlag=false; |
---|
| 337 | break; |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | if(SeFlag) ShowMessage("Seach col Top£¬Find Nothing."); |
---|
| 341 | break; |
---|
| 342 | case 3: //µ±Ç°ÁÐÏòÏÂÕÒ; |
---|
| 343 | for(int i=sgEdit->Row;i<sgEdit->RowCount;i++){ |
---|
| 344 | if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i], |
---|
| 345 | FrmSearch->edSeach->Text)){ //ÕÒµœÁË |
---|
| 346 | sgEdit->Row=i; |
---|
| 347 | SeFlag=false; |
---|
| 348 | break; |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | if(SeFlag) ShowMessage("Seach col end£¬Find Nothing."); |
---|
| 352 | break; |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | //--------------------------------------------------------------------------- |
---|
| 357 | |
---|
| 358 | void __fastcall TFrmMain::sgEditSelectCell(TObject *Sender, int ACol, |
---|
| 359 | int ARow, bool &CanSelect) |
---|
| 360 | { |
---|
| 361 | // |
---|
| 362 | } |
---|
| 363 | //--------------------------------------------------------------------------- |
---|
| 364 | void __fastcall TFrmMain::OpenFileCol(AnsiString FileName,int ColIndex,int ColType) |
---|
| 365 | { |
---|
| 366 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 367 | char Txtbuf[255]; |
---|
| 368 | int iVal; |
---|
| 369 | float fVal; |
---|
| 370 | FILE *stream; |
---|
| 371 | long curpos, length; |
---|
| 372 | DWORD dwRows, dwCols, dwRowLen, dwTextLen; |
---|
| 373 | |
---|
| 374 | DWORD dwTextStartPos; |
---|
| 375 | char* pTextPtr ; |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | if ((stream = fopen(FileName.c_str(), "r+")) |
---|
| 379 | == NULL) |
---|
| 380 | { |
---|
| 381 | ShowMessage("Open File Error"); |
---|
| 382 | return; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | curpos = ftell(stream); |
---|
| 386 | fseek(stream, 0L, SEEK_END); |
---|
| 387 | length = ftell(stream); |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | switch (ColType) |
---|
| 391 | { |
---|
| 392 | case 0: //ÕûÐÍÖµ Int |
---|
| 393 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 394 | fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0); |
---|
| 395 | fread(&iVal, 4, 1, stream); |
---|
| 396 | sgEdit->Cells[ColIndex][i+1]=IntToStr(iVal); |
---|
| 397 | } |
---|
| 398 | break; |
---|
| 399 | case 1: //ž¡µãÖµ Float |
---|
| 400 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 401 | fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0); |
---|
| 402 | fread(&fVal, 4, 1, stream); |
---|
| 403 | sgEdit->Cells[ColIndex][i+1]=FloatToStr(fVal); |
---|
| 404 | } |
---|
| 405 | break; |
---|
| 406 | case 2: //ÎıŸ Text |
---|
| 407 | fseek(stream,0x4,0); |
---|
| 408 | fread(&iVal, 4, 1, stream); |
---|
| 409 | dwRows= iVal; |
---|
| 410 | fread(&iVal, 4, 1, stream); |
---|
| 411 | dwCols = iVal; |
---|
| 412 | fread(&iVal, 4, 1, stream); |
---|
| 413 | dwRowLen = iVal; |
---|
| 414 | fread(&iVal, 4, 1, stream); |
---|
| 415 | dwTextLen = iVal; |
---|
| 416 | |
---|
| 417 | dwTextStartPos = dwRows*dwRowLen+20; |
---|
| 418 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 419 | fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0); |
---|
| 420 | fread(&iVal, 4, 1, stream); |
---|
| 421 | sgEdit->Cells[ColIndex][i+1]=IntToStr(iVal); |
---|
| 422 | if(dwTextStartPos + iVal < length){ |
---|
| 423 | fseek(stream,dwTextStartPos + iVal,0); |
---|
| 424 | fread(Txtbuf, 1, 255, stream); |
---|
| 425 | //pTextPtr = pBuff + dwTextStartPos + lTemp; |
---|
| 426 | sgEdit->Cells[ColIndex][i+1]=Txtbuf; |
---|
| 427 | }else{ |
---|
| 428 | sgEdit->Cells[ColIndex][i+1]="This Col Not Text!"; |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | break; |
---|
| 432 | } |
---|
| 433 | fclose(stream); |
---|
| 434 | } |
---|
| 435 | void __fastcall TFrmMain::Timer1Timer(TObject *Sender) |
---|
| 436 | { |
---|
| 437 | if(OpenOk){ |
---|
| 438 | lbOpState->Caption = "Open File Ok."; |
---|
| 439 | }else{ |
---|
| 440 | lbOpState->Caption = "Open Now....."; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | //--------------------------------------------------------------------------- |
---|
| 444 | //µ±Ç°žñ×ÓÐŽÈëÐÞžÄÎÄŒþÖÐ |
---|
| 445 | void __fastcall TFrmMain::N4Click(TObject *Sender) |
---|
| 446 | { |
---|
| 447 | if(!thOpen) return; |
---|
| 448 | |
---|
| 449 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 450 | char buf[4]; |
---|
| 451 | int iVal; |
---|
| 452 | float fVal; |
---|
| 453 | FILE *stream; |
---|
| 454 | /* |
---|
| 455 | if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 456 | == NULL) |
---|
| 457 | { |
---|
| 458 | ShowMessage("Žò¿ªÎÄŒþ³öŽí"); |
---|
| 459 | return; |
---|
| 460 | } |
---|
| 461 | */ |
---|
| 462 | iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//Žò¿ªÎÄŒþ |
---|
| 463 | |
---|
| 464 | switch (thOpen->ColType[sgEdit->Col]) |
---|
| 465 | { |
---|
| 466 | case 0: //ÕûÐÍÖµ |
---|
| 467 | //for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 468 | /* |
---|
| 469 | fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0); |
---|
| 470 | iVal=StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]); |
---|
| 471 | memcpy(buf, &iVal, 4); |
---|
| 472 | for(int i=0;i<4;i++) |
---|
| 473 | fwrite(buf+i, 1, 1, stream); |
---|
| 474 | */ |
---|
| 475 | iVal=StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]); |
---|
| 476 | memcpy(buf, &iVal, 4); |
---|
| 477 | FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0); |
---|
| 478 | FileWrite(iFileHandle,buf,4); |
---|
| 479 | //} |
---|
| 480 | break; |
---|
| 481 | case 1: //ž¡µãÖµ |
---|
| 482 | //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0); |
---|
| 483 | //fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]); |
---|
| 484 | //fwrite(&fVal, 4, 1, stream); |
---|
| 485 | fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]); |
---|
| 486 | memcpy(buf, &fVal, 4); |
---|
| 487 | FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0); |
---|
| 488 | FileWrite(iFileHandle,buf,4); |
---|
| 489 | break; |
---|
| 490 | case 2: //ÎıŸ²»ÐŽÈë |
---|
| 491 | break; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | // fclose(stream); |
---|
| 495 | FileClose(iFileHandle); |
---|
| 496 | } |
---|
| 497 | //--------------------------------------------------------------------------- |
---|
| 498 | |
---|
| 499 | void __fastcall TFrmMain::btTxtTypeClick(TObject *Sender) |
---|
| 500 | { |
---|
| 501 | if(OpenOk==true){ |
---|
| 502 | AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini"; |
---|
| 503 | AnsiString SectionName=ExtractFileName(CurrentOpenFile); |
---|
| 504 | TIniFile *ini; |
---|
| 505 | ini = new TIniFile( iniSetFile ); |
---|
| 506 | ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),2); |
---|
| 507 | delete ini; |
---|
| 508 | thOpen->ColType[sgEdit->Col]=2; |
---|
| 509 | OpenFileCol(CurrentOpenFile,sgEdit->Col,2); |
---|
| 510 | } |
---|
| 511 | } |
---|
| 512 | //--------------------------------------------------------------------------- |
---|
| 513 | |
---|
| 514 | void __fastcall TFrmMain::ToolButton3Click(TObject *Sender) |
---|
| 515 | { |
---|
| 516 | int OldCol; |
---|
| 517 | int OldRow; |
---|
| 518 | OldRow=sgEdit->Row; |
---|
| 519 | OldCol=sgEdit->Col; |
---|
| 520 | if(sgEdit->FixedCols==1){ |
---|
| 521 | sgEdit->FixedCols =2; |
---|
| 522 | if(OldCol!=1) |
---|
| 523 | sgEdit->Col=OldCol; |
---|
| 524 | sgEdit->Row=OldRow; |
---|
| 525 | }else{ |
---|
| 526 | sgEdit->FixedCols =1; |
---|
| 527 | sgEdit->Row=OldRow; |
---|
| 528 | if(OldCol!=2) |
---|
| 529 | sgEdit->Col=OldCol; |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | //--------------------------------------------------------------------------- |
---|
| 533 | |
---|
| 534 | void __fastcall TFrmMain::btRowSaveClick(TObject *Sender) |
---|
| 535 | { |
---|
| 536 | if(OpenOk==false) return; |
---|
| 537 | |
---|
| 538 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 539 | char Txtbuf[255]; |
---|
| 540 | int iVal; |
---|
| 541 | char buf[4]; |
---|
| 542 | float fVal; |
---|
| 543 | FILE *stream; |
---|
| 544 | long curpos, length; |
---|
| 545 | DWORD dwRows, dwCols, dwRowLen, dwTextLen; |
---|
| 546 | |
---|
| 547 | DWORD dwTextStartPos; |
---|
| 548 | char* pTextPtr ; |
---|
| 549 | |
---|
| 550 | |
---|
| 551 | //if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 552 | // == NULL) |
---|
| 553 | //{ |
---|
| 554 | // ShowMessage("Žò¿ªÎÄŒþ³öŽí"); |
---|
| 555 | // return; |
---|
| 556 | //} |
---|
| 557 | |
---|
| 558 | //curpos = ftell(stream); |
---|
| 559 | //fseek(stream, 0L, SEEK_END); |
---|
| 560 | //length = ftell(stream); |
---|
| 561 | iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//Žò¿ªÎÄŒþ |
---|
| 562 | |
---|
| 563 | for(int i=0;i<sgEdit->ColCount-1;i++){ |
---|
| 564 | switch (thOpen->ColType[i]) |
---|
| 565 | { |
---|
| 566 | case 0: //ÕûÐÍÖµ sgEdit->Row |
---|
| 567 | //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0); |
---|
| 568 | //iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 569 | //fwrite(&iVal, 4, 1, stream); |
---|
| 570 | iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 571 | memcpy(buf, &iVal, 4); |
---|
| 572 | FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4,0); |
---|
| 573 | FileWrite(iFileHandle,buf,4); |
---|
| 574 | break; |
---|
| 575 | case 1: //ž¡µãÖµ |
---|
| 576 | //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0); |
---|
| 577 | //fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 578 | //fwrite(&fVal, 4, 1, stream); |
---|
| 579 | fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 580 | memcpy(buf, &fVal, 4); |
---|
| 581 | FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4,0); |
---|
| 582 | FileWrite(iFileHandle,buf,4); |
---|
| 583 | break; |
---|
| 584 | case 2: //ÎıŸ ²»Žæ |
---|
| 585 | break; |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | //fclose(stream); |
---|
| 589 | FileClose(iFileHandle); |
---|
| 590 | ShowMessage("The "+IntToStr(sgEdit->Row)+" Row Write Ok!"); |
---|
| 591 | } |
---|
| 592 | //--------------------------------------------------------------------------- |
---|
| 593 | |
---|
| 594 | void __fastcall TFrmMain::btColSaveClick(TObject *Sender) |
---|
| 595 | { |
---|
| 596 | if(OpenOk==false) return; |
---|
| 597 | |
---|
| 598 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 599 | char Txtbuf[255]; |
---|
| 600 | int iVal; |
---|
| 601 | char buf[4]; |
---|
| 602 | float fVal; |
---|
| 603 | FILE *stream; |
---|
| 604 | long curpos, length; |
---|
| 605 | DWORD dwRows, dwCols, dwRowLen, dwTextLen; |
---|
| 606 | |
---|
| 607 | DWORD dwTextStartPos; |
---|
| 608 | char* pTextPtr ; |
---|
| 609 | |
---|
| 610 | iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//Žò¿ªÎÄŒþ |
---|
| 611 | |
---|
| 612 | //if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 613 | // == NULL) |
---|
| 614 | //{ |
---|
| 615 | // ShowMessage("Žò¿ªÎÄŒþ³öŽí"); |
---|
| 616 | // return; |
---|
| 617 | //} |
---|
| 618 | |
---|
| 619 | //curpos = ftell(stream); |
---|
| 620 | //fseek(stream, 0L, SEEK_END); |
---|
| 621 | //length = ftell(stream); |
---|
| 622 | |
---|
| 623 | |
---|
| 624 | switch (thOpen->ColType[sgEdit->Col]) |
---|
| 625 | { |
---|
| 626 | case 0: //ÕûÐÍÖµ |
---|
| 627 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 628 | //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0); |
---|
| 629 | //iVal=StrToInt(sgEdit->Cells[sgEdit->Col][i+1]); |
---|
| 630 | //fwrite(&iVal, 4, 1, stream); |
---|
| 631 | iVal=StrToInt(sgEdit->Cells[sgEdit->Col][i+1]); |
---|
| 632 | memcpy(buf, &iVal, 4); |
---|
| 633 | FileSeek(iFileHandle,0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0); |
---|
| 634 | FileWrite(iFileHandle,buf,4); |
---|
| 635 | } |
---|
| 636 | break; |
---|
| 637 | case 1: //ž¡µãÖµ |
---|
| 638 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 639 | //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0); |
---|
| 640 | //fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][i+1]); |
---|
| 641 | //fwrite(&fVal, 4, 1, stream); |
---|
| 642 | fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][i+1]); |
---|
| 643 | memcpy(buf, &fVal, 4); |
---|
| 644 | FileSeek(iFileHandle,0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0); |
---|
| 645 | FileWrite(iFileHandle,buf,4); |
---|
| 646 | } |
---|
| 647 | break; |
---|
| 648 | case 2: //ÎıŸ ²»Žæ |
---|
| 649 | break; |
---|
| 650 | } |
---|
| 651 | //fclose(stream); |
---|
| 652 | |
---|
| 653 | FileClose(iFileHandle); |
---|
| 654 | ShowMessage("The "+IntToStr(sgEdit->Col)+"Col Write Ok!"); |
---|
| 655 | } |
---|
| 656 | //--------------------------------------------------------------------------- |
---|
| 657 | |
---|
| 658 | void __fastcall TFrmMain::btRowClearClick(TObject *Sender) |
---|
| 659 | { |
---|
| 660 | if(OpenOk==false) return; |
---|
| 661 | |
---|
| 662 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 663 | char Txtbuf[255]; |
---|
| 664 | int iVal; |
---|
| 665 | float fVal; |
---|
| 666 | FILE *stream; |
---|
| 667 | long curpos, length; |
---|
| 668 | DWORD dwRows, dwCols, dwRowLen, dwTextLen; |
---|
| 669 | |
---|
| 670 | DWORD dwTextStartPos; |
---|
| 671 | char* pTextPtr ; |
---|
| 672 | |
---|
| 673 | |
---|
| 674 | if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 675 | == NULL) |
---|
| 676 | { |
---|
| 677 | ShowMessage("Open File Error!"); |
---|
| 678 | return; |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | curpos = ftell(stream); |
---|
| 682 | fseek(stream, 0L, SEEK_END); |
---|
| 683 | length = ftell(stream); |
---|
| 684 | |
---|
| 685 | for(int i=1;i<sgEdit->ColCount-1;i++){ |
---|
| 686 | switch (thOpen->ColType[i]) |
---|
| 687 | { |
---|
| 688 | case 0: //ÕûÐÍÖµ sgEdit->Row |
---|
| 689 | //fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0); |
---|
| 690 | //iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 691 | //fwrite(&iVal, 4, 1, stream); |
---|
| 692 | sgEdit->Cells[i+1][sgEdit->Row]="0"; |
---|
| 693 | break; |
---|
| 694 | case 1: //ž¡µãÖµ |
---|
| 695 | //fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0); |
---|
| 696 | //fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]); |
---|
| 697 | //fwrite(&fVal, 4, 1, stream); |
---|
| 698 | sgEdit->Cells[i+1][sgEdit->Row]="0"; |
---|
| 699 | break; |
---|
| 700 | case 2: //ÎıŸ ²»Žæ |
---|
| 701 | break; |
---|
| 702 | } |
---|
| 703 | } |
---|
| 704 | fclose(stream); |
---|
| 705 | } |
---|
| 706 | //--------------------------------------------------------------------------- |
---|
| 707 | |
---|
| 708 | void __fastcall TFrmMain::btColClearClick(TObject *Sender) |
---|
| 709 | { |
---|
| 710 | if(OpenOk==false) return; |
---|
| 711 | |
---|
| 712 | int iFileHandle; //ÎÄŒþŸä±ú |
---|
| 713 | char Txtbuf[255]; |
---|
| 714 | int iVal; |
---|
| 715 | float fVal; |
---|
| 716 | FILE *stream; |
---|
| 717 | long curpos, length; |
---|
| 718 | DWORD dwRows, dwCols, dwRowLen, dwTextLen; |
---|
| 719 | |
---|
| 720 | DWORD dwTextStartPos; |
---|
| 721 | char* pTextPtr ; |
---|
| 722 | |
---|
| 723 | |
---|
| 724 | if ((stream = fopen(CurrentOpenFile.c_str(), "r+")) |
---|
| 725 | == NULL) |
---|
| 726 | { |
---|
| 727 | ShowMessage("Open File Error!"); |
---|
| 728 | return; |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | curpos = ftell(stream); |
---|
| 732 | fseek(stream, 0L, SEEK_END); |
---|
| 733 | length = ftell(stream); |
---|
| 734 | |
---|
| 735 | |
---|
| 736 | switch (thOpen->ColType[sgEdit->Col]) |
---|
| 737 | { |
---|
| 738 | case 0: //ÕûÐÍÖµ |
---|
| 739 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 740 | //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0); |
---|
| 741 | //iVal=StrToInt(sgEdit->Cells[ColIndex][i+1]); |
---|
| 742 | //fwrite(&iVal, 4, 1, stream); |
---|
| 743 | sgEdit->Cells[sgEdit->Col][i+1]="0"; |
---|
| 744 | } |
---|
| 745 | break; |
---|
| 746 | case 1: //ž¡µãÖµ |
---|
| 747 | for(int i=0;i<sgEdit->RowCount-1;i++){ |
---|
| 748 | //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0); |
---|
| 749 | //fVal=StrToFloat(sgEdit->Cells[ColIndex][i+1]); |
---|
| 750 | //fwrite(&fVal, 4, 1, stream); |
---|
| 751 | sgEdit->Cells[sgEdit->Col][i+1]="0"; |
---|
| 752 | } |
---|
| 753 | break; |
---|
| 754 | case 2: //ÎıŸ ²»Žæ |
---|
| 755 | break; |
---|
| 756 | } |
---|
| 757 | fclose(stream); |
---|
| 758 | } |
---|
| 759 | //--------------------------------------------------------------------------- |
---|
| 760 | |
---|
| 761 | void __fastcall TFrmMain::ToolButton4Click(TObject *Sender) |
---|
| 762 | { |
---|
| 763 | AnsiString Cmd; |
---|
| 764 | Cmd = "calc.exe"; |
---|
| 765 | WinExec(Cmd.c_str(), SW_SHOWNORMAL); |
---|
| 766 | } |
---|
| 767 | //--------------------------------------------------------------------------- |
---|
| 768 | |
---|
| 769 | |
---|