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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mbom_2bn;
/**
*
* @author bneveux
*/
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
public class ReadFileLineMoPm {
public static void main(String[] args) throws IOException {
//public ReadFileLineMoPm() throws IOException {
int countNoLines = 0;
int countNoLinesMo = 0;
String ligne = "";
String fichierSource = "";
Date maDateAvecFormat=new Date();
SimpleDateFormat dateStandard = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateStandard.format(maDateAvecFormat));
//File fichierDestination = new File("D:/NB_YPPCS12E_NoArticle.txt");
File fichierDestination = new File("/Users/Brice/NetBeansProjects/MBOM_2BN/RAPPORT_MBOM_MO_PM.txt");
//Q Source file name
BufferedReader clavier = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("REG2N_F_FR01_MODL_20111024_1900.txt");
System.out.println("Source file name ?");
fichierSource = clavier.readLine();
BufferedReader ficTexte;
//Q Destination file name
BufferedWriter output = new BufferedWriter(new FileWriter(fichierDestination)) ;
//fichierDestination = clavier2.readLine();
//BufferedWriter desTexte
//desTexte = new BufferedWriter(new FileWriter File(fichierDestination));
//Write file
try {
ficTexte = new BufferedReader(new FileReader(new File(fichierSource)));
if (ficTexte == null) {
throw new FileNotFoundException("File not found "
+ fichierSource);
}
String ligneNoModl = "";
do {
ligne = ficTexte.readLine();
if (ligne != null)
{
countNoLines = countNoLines + 1;
String ligneNoArt = ligne.substring(38, 56);
//Enregistre le numéro de modl à chaque saut de ****
if ( ligne.startsWith(" ; ;******")) {
ligneNoModl = ligneNoArt;
}
int lgLigne = ligne.length();
//if ( ligneNoArt.startsWith("083M") ) {
String ligneNoArtPM = ligne.substring(112, 118);
String siteName = "Crespin";
String projectName = "C083";
String authorMo = "JAVA";
String dateTransport = dateStandard.format(maDateAvecFormat);
String moNumOc = "1";
String moRev = "1";
String textMo = "";
String noMoCritTri = ligne.substring(136,143);
String niveauMoPm = ligne.substring(135,136);
String noMoShort = ligneNoArt.substring(0, ligneNoArt.indexOf(" "));
String noModlShort = ligneNoModl.substring(0, ligneNoModl.indexOf(" "));
String noArtQte = ligne.substring(57,70);
if ( lgLigne > 120 ) {
textMo = ligne.substring(71, 111);
}
else
{
textMo = "";
}
//EXECUTE [Bomfact].[bomfact].[ImportTask] 'Villeneuve', 'Station 3 NDW', '1887ZZ21M005', 'isolation zone 6 (paroi montagne inf. WE1)', 'NDW' , 1 , 'AZ + CP' , '1' , 'KAVLAK Turan' , '10/21/2010'
//String sqlInstructie = "EXECUTE [Bomfact].[bomfact].[ImportTask] '" + siteName + "', '" + ligneNoArtPM + "', '"+ noMoShort + "', '" + textMo + "', '" + projectName + "' , '" + moNumOc + "' , '" + noModlShort + "' , '" + moRev + "' , '" + authorMo + "' , '" + dateTransport + "';";
textMo = ligne.substring(71, 111);
if (ligneNoArtPM.startsWith("PM") && noMoCritTri.startsWith("M"))
{
countNoLinesMo = countNoLinesMo + 1;
System.out.println(ligneNoArtPM + " " + niveauMoPm + " " + noMoCritTri);
//Write in output txt
output.write(ligneNoArtPM + ";" + niveauMoPm + ";" + noMoCritTri);
output.newLine();
}
//}
}
if (ligne == null) {
break;
}
} while (ficTexte != null);
//termine ecriture
output.close();
//termine lecture
ficTexte.close();
System.out.println("\n");
System.out.println(""+countNoLines+ " ligne(s) de BOM scannée(s)");
System.out.println(""+countNoLinesMo+ " ligne(s) de MO impriméee(s)");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
} |
Partager