1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353. 354. 355. 356. 357. 358. 359. 360. 361. 362. 363. 364. 365. 366. 367. 368. 369. 370. 371. 372. 373. 374. 375. 376. 377. 378. 379. 380. 381. 382. 383. 384. 385. 386. 387. 388. 389. 390. 391. 392. 393. 394. 395. 396. 397. 398. 399. 400. 401. 402. 403. 404. 405. 406. 407. 408. 409. 410. 411. 412. 413. 414. 415. 416. 417. 418. 419. 420. 421. 422. 423. 424. 425. 426. 427. 428. 429. 430. 431. 432. 433. 434. 435. 436. 437. 438. 439. 440. 441. 442. 443. 444. 445. 446. 447. 448. 449. 450. 451. 452. 453. 454. 455. 456. 457. 458. 459. 460. 461. 462. 463. 464. 465. 466. 467. 468. 469. 470. 471. 472. 473. 474. 475. 476. 477. 478. 479. 480. 481. 482. 483. 484. 485. 486. 487. 488. 489. 490. 491. 492. 493. 494. 495. 496. 497. 498. 499. 500. 501. 502. 503. 504. 505. 506. 507. 508. 509. 510. 511. 512. 513. 514. 515. 516. 517. 518. 519. 520. 521. 522. 523. 524. 525. 526. 527. 528. 529. 530. 531. 532. 533. 534. 535. 536. 537. 538. 539. 540. 541. 542. 543. 544. 545. 546. 547. 548. 549. 550. 551. 552. 553. 554. 555. 556. 557. 558. 559. 560. 561. 562. 563. 564. 565. 566. 567. 568. 569. 570. 571. 572. 573. 574. 575. 576. 577. 578. 579. 580. 581. 582. 583. 584. 585. 586. 587. 588. 589. 590. 591. 592. 593. 594. 595. 596. 597. 598. 599. 600. 601. 602. 603. 604. 605. 606. 607. 608. 609. 610. 611. 612. 613. 614. 615. 616. 617. 618. 619. 620. 621. 622. 623. 624. 625. 626. 627. 628. 629. 630. 631. 632. 633. 634. 635. 636. 637. 638. 639. 640. 641. 642. 643. 644. 645. 646. 647. 648. 649. 650. 651. 652. 653. 654. 655. 656. 657. 658. 659. 660. 661. 662. 663. 664. 665. 666. 667. 668. 669. 670. 671. 672. 673. 674. 675. 676. 677. 678. 679. 680. 681. 682. 683. 684. 685. 686. 687. 688. 689. 690. 691. 692. 693. 694. 695. 696. 697. 698. 699. 700. 701. 702. 703. 704. 705. 706. 707. 708. 709. 710. 711. 712. 713. 714. 715. 716. 717. 718. 719. 720. 721. 722. 723. 724. 725. 726. 727. 728. 729. 730. 731. 732. 733. 734. 735. 736. 737. 738. 739. 740.
/*
* SJFrame.java
*
* Created on 9 Июнь 2007 г., 16:41
*/
package smssend;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TimerTask;
import java.util.Vector;
import javax.mail.MessagingException;
import javax.mail.internet.ParseException;
import javax.swing.JTable;
import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
/**
*
* @author DmitriyMG
*/
public class SJFrame extends javax.swing.JFrame {
DBTableModel model;
private String[] defCols = {"Время","К1(ном)","К1(кол)","К1(руб)","К2(ном)","К2(кол)"
,"К2(руб)","К3(ном)","К3(кол)","К3(руб)","К4(ном)","К4(кол)","К4(руб)","Итог(руб)"
,"Error","Банкомат","Наименование","Филиал"};
private Object[] defData = {" "," "," "," "," "," " ," "," "," "," "," "," "," "," "," "," "," "," "};
DateFormat df = new SimpleDateFormat("dd MMM HH:mm:ss", new Locale("en"));
DateFormat dff = new SimpleDateFormat("dd MMM ", new Locale("en"));
public Vector tdat = new Vector();
Vector bankomat = new Vector();
Date dt = new Date();
Date dt1 = new Date();
String sfic = null ;
String sficn = null ;
protected StringBuffer messageBody = new StringBuffer();
protected boolean trig = false;
Vector er1 = new Vector();
/** Creates new form SJFrame */
public SJFrame() {
model = new DBTableModel(defCols,defData, 0 );
initComponents();
setVisible(true);
this .setTitle("Start");
long minutes = 30 ;
java.util.Timer timer = new java.util.Timer();
timer.schedule( new tR(),minutes * 60 * 1000 , minutes * 60 * 1000 );
try {
dt = df.parse(dff.format(dt1)+"00:00:00");
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
model.clearTable();
sfic = new String("pos16trm.")+( new SimpleDateFormat("yyMMdd").format( new Date())).toString();
sficn = sfic;
logGet(sfic);
model.insertFromDB(tdat, defCols );
colorSizeCol();
start();
System.out.println("Server run");
// System.out.println(fileGet("mail",1));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane5 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextArea1.setColumns( 20 );
jTextArea1.setRows( 5 );
jScrollPane2.setViewportView(jTextArea1);
jTextArea2.setColumns( 20 );
jTextArea2.setRows( 5 );
jScrollPane4.setViewportView(jTextArea2);
jTextArea3.setColumns( 20 );
jTextArea3.setRows( 5 );
jScrollPane5.setViewportView(jTextArea3);
jButton1.setText("Запрос");
jButton1.addActionListener( new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTable1.setModel(model);
jScrollPane1.setViewportView(jTable1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add( 0 , 1168 , Short .MAX_VALUE)
.add(jButton1)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(layout.createSequentialGroup()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 270 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short .MAX_VALUE)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 388 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 450 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 1049 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 352 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short .MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
model.clearTable();
sfic = new String("pos16trm.")+( new SimpleDateFormat("yyMMdd").format( new Date())).toString();
sficn = sfic;
logGet(sfic);
model.insertFromDB(tdat, defCols );
colorSizeCol();
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTable jTable1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
// End of variables declaration
//*****************************Задание выполняемое таймером
class tR extends TimerTask {
public void run() {
model.clearTable();
sfic = new String("pos16trm.")+( new SimpleDateFormat("yyMMdd").format( new Date())).toString();
System.out.println("Timer ");
if (!sficn.equals(sfic)){
trig = false;
er1.clear();
}
sficn = sfic;
logGet(sfic);
model.insertFromDB(tdat, defCols );
colorSizeCol();
}
}
//*********************************************Server******************
public void start() {
ServerSocket ss = null ;
try {
ss = new ServerSocket( 65000 );
} catch (Exception e) {e.printStackTrace();System.exit( 0 );}
while (true) {
try {
new ServerTask(ss.accept()).start();
} catch (Exception e) { e.printStackTrace(); System.exit( 0 ); }
}
}
///*************************************************
private class ServerTask implements Runnable {
private Socket s;
private Thread self;
public ServerTask(Socket s) {
this .s = s;
self = new Thread( this );
}
public void start() {
this .self.start();
}
public void run() {
try {
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
String obj = (String) ois.readObject();
System.out.println("Thread connect " + obj);
if (obj.equals("ok")){
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(tdat);
oos.flush();
s.close();}
} catch (Exception e) {
e.printStackTrace();
if (!s.isClosed()) {
try {
s.close();
} catch (Exception ee) {
e.printStackTrace();
}
}
}
}
}
//******************************************************************
public void colorSizeCol(){
cCSet(jTable1, 0 ,Color.CYAN);
cCSet(jTable1, 3 ,Color.BLUE);
cCSet(jTable1, 6 ,Color.BLUE);
cCSet(jTable1, 9 ,Color.BLUE);
cCSet(jTable1, 12 ,Color.BLUE);
cCSet(jTable1, 13 ,Color.MAGENTA);
jTable1.getColumnModel().getColumn( 0 ).setMinWidth( 100 );
jTable1.getColumnModel().getColumn( 16 ).setMinWidth( 120 );
jTable1.getColumnModel().getColumn( 14 ).setMaxWidth( 2 );
jTable1.getColumnModel().getColumn( 15 ).setMinWidth( 20 );
jTable1.getColumnModel().getColumn( 17 ).setMaxWidth( 8 );
jTable1.getColumnModel().getColumn( 17 ).setMaxWidth( 8 );
}
//**************Color Column set********************************
public void cCSet(JTable jTable2 , int numberColum, Color colorColum) {
TableColumn tc = null ;
DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
tc = jTable2.getColumnModel().getColumn(numberColum);
dtcr.setForeground(colorColum);
//dtcr.setFont(new Font("Times New Roman", 1, 18));
tc.setCellRenderer(dtcr);
}
//*****выбираем значение из ячейки*******vector Value Get**********************************
public Object vVGet(Vector rows, int aRow, int aColumn) {
Vector row1 = (Vector)rows.elementAt(aRow);
return row1.elementAt(aColumn);
}
//***********************Read in file ****************************************
public void logGet(String namefile) {
bankGet();
Date d2 = new Date();
System.out.println("Log read");
// tdat.removeAllElements();
BufferedReader rf = null ;
File srcFile = null ;
try {
progr(" закачки...");
new FtpW(namefile);
} catch (ParseException ex) {ex.printStackTrace();}
catch (InterruptedException ex) { ex.printStackTrace();}
catch (java.text.ParseException ex) {ex.printStackTrace();}
catch (IOException ex) {ex.printStackTrace();}
srcFile = new File("c:\\"+ namefile );
FileInputStream is;
//////////////////////Файлы открываем для чтения и записи
try{
is = new FileInputStream(srcFile);
rf = new BufferedReader(new InputStreamReader(
new ProgressMonitorInputStream(this,"Обработка файла...",
new FileInputStream(srcFile))));
String sr ;
StringBuffer s;
while((sr = rf.readLine())!= null)
{
s = new StringBuffer(sr);
try {
d2 = df.parse(s.substring(0,15));
} catch (java.text.ParseException ex) {ex.printStackTrace();}
/*
if(s.substring(31,36).equals("INF11")){
//System.out.println(s);
if(s.substring(37,41).equals("Stop")&&(s.length()>43)&&dt.before(d2)){
System.out.println(s);
//inf11(s);
}
}
*/
// System.out.println(df.format(dt));
// System.out.println(df.format(d2));
if(s.substring(31,36).equals("WARNG")){
if(s.substring(42,45).equals("006")&&dt.before(d2)){ msg006(s); }
if(s.substring(42,45).equals("003")&&dt.before(d2)){ msg003(s); }
} //if
}//while
//System.out.println(dt.toString());
try {
Thread.sleep(200);is.close(); // slow it down a bit.
} catch(InterruptedException e) { }
} catch (IOException e) {System.out.println("Read and Write in file Err: " );}
finally { try{ rf.close(); System.out.println("read end"); }catch(IOException e){};}
setTitle(df.format(dt)+"<-- LOG. Timer--> "+df.format(new Date()));
System.out.println(df.format(dt)+" Time last record ");
trig = true;
srcFile.delete();
}
private String toTranslit(String src) {
if (src == null) {
return "";
}
String[] f = {"А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ч", "Ц", "Ш", "Щ", "Э", "Ю", "Я", "Ы", "Ъ", "Ь", "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ч", "ц", "ш", "щ", "э", "ю", "я", "ы", "ъ", "ь"};
String[] t = {"A", "B", "V", "G", "D", "E", "Jo", "Zh", "Z", "I", "J", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "F", "H", "Ch", "C", "Sh", "Csh", "E", "Ju", "Ja", "Y", "`", "'", "a", "b", "v", "g", "d", "e", "jo", "zh", "z", "i", "j", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "ch", "c", "sh", "csh", "e", "ju", "ja", "y", "`", "'"};
StringBuffer res = new StringBuffer();
for (int i = 0; i < src.length(); ++i) {
char add = src.charAt(i);
for (int j = 0; j < f.length; j++) {
if (f[j].length() == 1 && f[j].charAt(0) == add) {
res.append(t[j]);
break;
} else {
if (j == f.length - 1) {
res.append(add); //unknown input char found - insert as is.
}
}
}
}
return res.toString();
}
//********************msg006***************
public void msg006(StringBuffer s) {
StringBuffer s1c = new StringBuffer();
StringBuffer s2c = new StringBuffer();
String [] z = new String [4];
s1c = new StringBuffer(tok(s,"][",3));//error in bankomat Выбираем подстроку [] с ошибками
s2c = new StringBuffer(s.substring(s.lastIndexOf("[")+1,s.lastIndexOf("]"))); //Выбираем подстроку с [J.....] банкомата
for(int k = 0;k<bankomat.size();k++) // Проходим по всему Вектору с выборкой банкоматов
{
if(s2c.toString().equals(vVGet(bankomat,k,1))) //Если нашли подобие то вытаскиваем в Массив данные по банкомату
{
Vector row1 = (Vector)bankomat.elementAt(k); //Из вектора берем нужную строку []
z = (String[]) row1.toArray(new String[row1.size()]); // Перобразуем Вектор к массиву
System.out.println(toTranslit(z[0])+" "+z[1]+" "+z[2]+" "+toTranslit(z[3]));//Печатаем данные в консоли
}//z[0] name, z[1] J, z[2] fillial, z[3] Address
}
//df.toArray(new String[df.size()]);
//*****Загнать 16ричные данные в Вектор табличка в четыре
//поля дата наименование банкомата и два поля с кодами s.substring(61,69) s.substring(70,82)
//добавить поле Текст Ареа для вывода расшифровки кода и табличку с событиями по времени для выбранного
//банкомата
String sd0 = new String(s.substring(0,15));//Дата события из лога
String sd1 = new String(s.substring(61,69));//Первая часть из ошибки
String sd2 = new String(s.substring(70,82));//Вторая часть
String [] e1 = new String [4];
e1[0] = z[1];
e1[1] = sd0;
e1[2] = sd1;
e1[3] = sd2;
er1.add(rVSet(e1));
//System.out.println(s);
//System.out.println(s.substring(61,69));
//System.out.println(s.substring(70,82));
RazborOshibok rz = new RazborOshibok();
System.out.println(toTranslit(rz.descriptorToAnomalies(sd1)));
System.out.println(toTranslit(rz.dopMask(sd2)));
if(dateRun()){
if(trig&&rz.mailed){
messageBody = new StringBuffer(s.substring(0,15)+" "+s1c+" "+toTranslit(z[0])+" "+z[1]+" "+toTranslit(z[3]));
if(z[2].equals("342")){
try {
mp("mailt",1);System.out.println("****Send mail Nch "+messageBody);
} catch (FileNotFoundException ex) { ex.printStackTrace();} catch (IOException ex) { ex.printStackTrace();}
}
if(z[2].equals("2666")){
try {
mp("mailt",2);System.out.println("****Send mail Bua "+messageBody);
} catch (FileNotFoundException ex) {ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace();}
}
}
}
System.out.println(s.substring(0,15)+" "+s1c+" "+toTranslit(z[0].toString()));
}
//********************msg003***************
public void msg003(StringBuffer s) {
StringBuffer sb = new StringBuffer(tok(s,"[]",4));
if(!(sb.substring(sb.lastIndexOf(">"))).equals("> Cash period not opened"))
{
Boolean mailing = true;
String [] b = new String[8] ;
b = bGet(s);
int [] c = new int [3] ;
c = cassetGet(b);
int c1 = (c[0]), c2 = (c[1]), c3 = (c[2]), c4 = (c[3]), s5 = (c1+c2+c3+c4);
StringBuffer sts = new StringBuffer(s.substring(s.lastIndexOf("[")+1,s.lastIndexOf("]")));
String [] s1f = new String [4];
for(int k = 0;k<bankomat.size();k++)
{
if(sts.toString().equals(vVGet(bankomat,k,1)))
{
Vector row1 = (Vector)bankomat.elementAt(k);
s1f = (String[]) row1.toArray(new String[row1.size()]);
}
}
String [] sdr = new String [18];
sdr[0] = s.substring(0,15);
sdr[1] = b[0];
sdr[2] = b[1];
sdr[3] = (c1+"").trim();
sdr[4] = b[2];
sdr[5] = b[3];
sdr[6] = (c2+"").trim();
sdr[7] = b[4];
sdr[8] = b[5];
sdr[9] = (c3+"").trim();
sdr[10] = b[6];
sdr[11] = b[7];
sdr[12] = (c4+"").trim();
sdr[13] = (s5+"").trim();
sdr[14] = b[8];
sdr[15] = sts.toString();
sdr[16] = s1f[0];
sdr[17] = s1f[2];
try {
dt = df.parse(sdr[0]);
} catch (java.text.ParseException ex) {ex.printStackTrace();}
boolean tr = false;
for(int k = 0;k<tdat.size();k++)
{
if(sdr[15].equals(vVGet(tdat,k,15)))
{
// System.out.println(sdr[15]+"="+vVGet(tdat,k,15));
if(sdr[3].equals(vVGet(tdat,k,3))&&sdr[6].equals(vVGet(tdat,k,6)) &&
sdr[9].equals(vVGet(tdat,k,9)) &&sdr[12].equals(vVGet(tdat,k,12)))
{mailing = false;}else{mailing = true;}
//System.out.println(mailing);
//System.out.println(sdr[3]+"="+vVGet(tdat,k,3)+" "+sdr[6]+"="+vVGet(tdat,k,6)+" "+sdr[9]+"="+vVGet(tdat,k,9)+" "+sdr[12]+"="+vVGet(tdat,k,12) );
tdat.set(k,(rVSet(sdr)));
tr = true;
///Тут будет проверка на колво бабок в банкомате
//и если уже мало то отправляет чувакам месагу
//работаем с массивами
if(trig){
//проверка на количество денег каждого банкомата если мало то мылим
// System.out.println(s5+" "+s1f[0]);
if(((s5)<100000)&&(((c[0])<10000)||
((c[1])<10000)||((c[2])<10000)||((c[3])<10000))) {
//создаем строку для записи в файл
System.out.println(sdr[0]+" little old womans "+toTranslit(sdr[16]));
StringBuffer messageBody0 = new StringBuffer();
messageBody0.append(sdr[0]);
if((c[0])<10000){messageBody0.append(" c1:"+c[0]);}
if((c[1])<10000){messageBody0.append(" c2:"+c[1]);}
if((c[2])<10000){messageBody0.append(" c3:"+c[2]);}
if((c[3])<10000){messageBody0.append(" c4:"+c[3]);}
messageBody0.append(" I:"+sdr[13]+" "+sdr[15]+" "+sdr[16]+" "+s1f[3]);
messageBody = new StringBuffer(toTranslit(messageBody0.toString()));
//тут нужно еще выставить проверку на время если время позднее то не мылить на телефон. только на мыло.
System.out.println("min money");
try { //message go
if(dateRun()){
if(s1f[2].equals("342") ){if(mailing){mp("mail",1);System.out.println("****Send mail Nch "+messageBody);} }
if(s1f[2].equals("2666") ){if(mailing){mp("mail",2);System.out.println("****Send mail Bua "+messageBody);} }
}
} catch (FileNotFoundException ex) { ex.printStackTrace();}
catch (IOException ex) { ex.printStackTrace(); }
}
}
}
}
if(!tr) {
tdat.add(rVSet(sdr)); //Vector tdat add
}
}
}
//*********************************время в диапазоне которого будут отсылаться смс
private boolean dateRun(){
boolean tt = false;
Date dbeg = new Date();
Date dstop = new Date();
Date dt1 = new Date();
try {
dt1 = df.parse(df.format(dt));
dbeg = df.parse(dff.format(dbeg)+"06: 00 : 00 ");
dstop = df.parse(dff.format(dstop)+"20: 00 : 00 ");
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
if(dt1.after(dbeg)&&dt1.before(dstop)){
tt = true;
}
return tt;
}
//***********************StringTokenizer******************************
public StringBuffer tok(StringBuffer value,String token,int numTok) {
StringTokenizer st = new StringTokenizer(value.toString(), token);
String [] sd =new String [st.countTokens()];
String sf;
int i = 0;
while (st.hasMoreTokens()) { sd[i++] = st.nextToken(); }
//System.out.println(sd[numTok]);
sf = new String(sd[numTok]);
StringBuffer blok5 = new StringBuffer(sf.equals("")?"0":sf);
return blok5;
}
//********************Выборка блока для обработки********************bGet****************************
public String [] bGet(StringBuffer sc){
sc = sc;
String [] b = new String[9] ;
sc = new StringBuffer(tok(sc,"][",4));
int i = 0;
for(int j = 0 ; j < 7 ; j=j+2){
StringBuffer ex = new StringBuffer(tok(sc,"<>",j));
for(int k = 2 ; k < 6 ; k=k+2) {
b[i] = tok(ex,":,",k).toString();
if(k<6){++i;}
}
}
/*003 *123 *243 *363 *415 *535 *655 *775*/
b[8] = " "+((sc.substring(sc.indexOf("Total:"),sc.lastIndexOf(":")).equals("Total"))?"I":"E");
return b ;
}
//***********************************cassetGet******************************
public int [] cassetGet(String [] sc){
sc = sc;
int [] summc = new int [4] ;
for(int j=0,i=0;i<4;i++,j=j+2){
try{
summc [i] = ((Integer.parseInt(sc[j]) * Integer.parseInt(sc[j+1])));
} catch (StringIndexOutOfBoundsException e){ System.out.println("cassetGet Summ Err: " + e.toString()); }
}
return summc;
}
//************Row Value Set*************************
public Object rVSet(String [] mst){
Vector row = new Vector();
for(int i= 0;i<mst.length;++i){
row.add(mst[i]);
}
return row;
}
//******************Array Банкомат,j,filial
public void bankGet() {
bankomat.clear();
String[] s = new String [4];
StringBuffer querry = new StringBuffer("select name_b,name_c,id_filial, place from term where type ='54' and name_c is not null " );
try{//name_b = Наименование Банкомата, name_c = его J , id_filial = число филиала , place = Адрес местоположение
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:rbs","gc","gc");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(querry.toString());
while(rs.next()){
s[0] = rs.getString(1);
s[1] = rs.getString(2);
s[2] = rs.getString(3);
s[3] = rs.getString(4);
if(s[3] == null){s[3]="-";}
bankomat.add(rVSet(s));
}
st.close();
con.close();
} catch(Exception e) { e.printStackTrace(); }
}catch(Exception e){System.out.println("File with adjustment does not contain necessary adjustment"); }
}
//**********Проверка и формирование текста для отправки
public void mp(String filename,int i) throws FileNotFoundException, IOException{
//мылим
/**/ Mailer mlb = new Mailer();
mlb.setServer("x.x.x.x");
mlb.setFrom("a@b.c");
mlb.setToList(fileGet(filename,i));
mlb.setSubject(" ");
mlb.setBody(messageBody.toString());
try {
mlb.doSend();
} catch (MessagingException ex) { ex.printStackTrace(); }
}
//Чтение нужной строки файла
public String fileGet(String filename,int i) throws FileNotFoundException, IOException{
String sc = new String();
BufferedReader ref = null;
StringBuffer s;
StringBuffer s1 = new StringBuffer();
ref = new BufferedReader(new FileReader(filename));
while((sc = ref.readLine())!= null){
s = new StringBuffer(sc);
System.out.println(s.toString());
switch (i){
case 1:
if(tok(s,";",2).toString().equals("1"))
s1.append(tok(s,";",1).toString()+",");
System.out.println(s1.toString());
break;
case 2:
if(tok(s,";",2).toString().equals("2"))
s1.append(tok(s,";",1).toString()+",");
System.out.println(s1.toString());
break;
}
}
return s1.substring(0,s1.length()-1);
}
//*****************Чтение нужной строки файла
public void fileGetBuh(String filename) throws FileNotFoundException, IOException{
String sc = new String();
BufferedReader ref = null;
StringBuffer s;
Vector data = new Vector();
ref = new BufferedReader(new FileReader(filename));
while((sc = ref.readLine())!= null){
s = new StringBuffer(sc);
String [] jd = new String [3];
jd[0] = tok(s,";",0).toString();
jd[1] = tok(s,";",1).toString();
jd[2] = tok(s,";",2).toString();
data.add(rVSet(jd));
}
}
//***************Запись 1 строки в Файл*************************************************
public void fileSet(StringBuffer sc,String filename){
BufferedWriter bytesOut = null;
try{
bytesOut = new BufferedWriter(new FileWriter(filename));
bytesOut.write(sc.toString());
bytesOut.newLine();
} catch (IOException e) {System.out.println("Open File or Write in File does not manage: " );} finally {
try{
bytesOut.close();
}catch(IOException e){};
}
}
//************************************************
public void progr(String op){
final ProgressMonitor mon = new ProgressMonitor(this,"Идет процесс."+op,"Осталось ",0,100);
Runnable runnable = new Runnable() {
public void run() {
for(int i = 1; i<100;i++){
try{
mon.setNote("Осталось"+(100-i)+"%");
mon.setProgress(i);
if (mon.isCanceled()){
mon.setProgress( 100 );
break ;
}
Thread.sleep( 100 );
} catch (InterruptedException e){}
}
mon.close();
}
};
Thread thread = new Thread(runnable);
thread.start();
setVisible(true);
}
}
+
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123.
/*
* DBTableModel.java
*
* Created on 4 Июнь 2007 г., 8:47
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package smssend;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
/**
*
* @author DmitriyMG
*/
public class DBTableModel extends AbstractTableModel {
int cols;
Vector data;
String [] colNames;
/** Creates a new instance of DBTableModel */
public DBTableModel(String [] colNames,Object[] values, int rows) {
cols = colNames.length;
this .colNames = new String[cols];
for ( int i = 0 ; i<cols;i++)
this .colNames[i] = colNames[i];
data = new Vector();
for ( int i = 0 ; i < rows;i++){
Vector v = new Vector();
for ( int j = 0 ; j < cols;j++)
v.addElement(values[j]);
data.addElement(v);
}
}
//************************************
public int getRowCount() {
return data.size();
}
//************************************
public int getColumnCount() {
return cols;
}
//************************************
public Object getValueAt(int rowIndex, int columnIndex) {
Vector v =(Vector) data.elementAt(rowIndex);
return v.elementAt(columnIndex);
}
//************************************
public void setValueAt(Object obj,int rowIndex, int columnIndex){
Vector v = (Vector) data.elementAt(rowIndex);
v.setElementAt(obj,columnIndex);
}
//************************************
public void insertRow(Vector row){
data.addElement(row);
super.fireTableDataChanged();
}
//************************************
public void deleteRow(int row){
data.removeElementAt(row);
super.fireTableDataChanged();
}
//************************************
public Vector getRow(int row ){
return (Vector)data.elementAt(row);
}
//************************************
public void updateRow(Vector updateRow,int row){
data.setElementAt(updateRow,row);
super.fireTableDataChanged();
}
//************************************
public void insertFromDB(Vector tdat,String [] defCols){
//try{
cols = defCols.length;
colNames = new String [cols];
colNames = defCols;
data = new Vector();
/* while (rs.next()){
Vector col = new Vector();
for(int i = 1;i <= cols;i++)
col.addElement(rs.getObject(i));
data.addElement(col);
}
rs.close();*/
data = tdat;
//}catch (SQLException e){e.printStackTrace();}
fireTableChanged( null );
}
//************************************
public String getColumnName( int col){
return colNames[col];
}
//************************************
public Class getColumnClass( int col){
return getValueAt( 0 ,col).getClass();
}
//************************************
public void clearTable(){
cols = 0 ;
data = new Vector();
colNames = null ;
super .fireTableDataChanged();
}
}
что то не так с табличкой видимо не могу найти причины
Выходит пустая форма ни таблички ни кнопок
Что не так сделал?
|