import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.GroupLayout.Alignment;
import problema080915.Produs;
import problema080922.DepozitApp;
import problema081017.ProdusDao;
public class FindEntryDlg extends JDialog implements ActionListener {
JLabel label;
ProdusDao produsDao;
JTable table;
List list;
public FindEntryDlg(JFrame owner){
super(owner, "Whatever", true);
label = new JLabel();
produsDao = ((DepozitApp)owner).getProdusDao();
JButton ok = new JButton("OK");
ok.setActionCommand("ok");
ok.addActionListener(this);
JButton cancel = new JButton("Cancel");
cancel.setActionCommand("cancel");
cancel.addActionListener(this);
Dimension size = ok.getPreferredSize();
ok.setBounds(25, 40, size.width, size.height);
size = cancel.getPreferredSize();
cancel.setBounds(25, 80, size.width, size.height);
JScrollPane scrollPane = null;
try{
list = produsDao.gasesteProduse();
// initializare tabel cu rezultate:
Object[][] data = new Object[list.size()][5];
String[] columnNames = {"Cod",
"Data",
"Denumire",
"Cantitate",
"Valoare unitara"};
int contor = 0;
for(Iterator it = list.iterator(); it.hasNext(); ){
Produs pr = (Produs)it.next();
data[contor][0] = pr.getCod();
data[contor][1] = pr.getData();
data[contor][2] = pr.getDenumire();
data[contor][3] = pr.getCantitatea();
data[contor][4] = pr.getValoarea_unitara();
contor++;
}
table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
scrollPane = new JScrollPane(table);
}catch (SQLException e){
System.out.println("Exceptie.");
e.printStackTrace();
}
GroupLayout layout = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
hGroup.addGroup(layout.createParallelGroup().
addComponent(ok).addComponent(scrollPane));
hGroup.addGroup(layout.createParallelGroup().
addComponent(cancel));
layout.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
addComponent(scrollPane));
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
addComponent(ok).addComponent(cancel));
layout.setVerticalGroup(vGroup);
this.setSize(600, 300);
}
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if("ok".equals(cmd)) {
label.setText("Butonul ok a fost apasat");
try{
list = produsDao.gasesteProduse();
MetodeUtilitare.afiseazaRezultateInterogare(list);
}catch (SQLException e){
System.out.println("Exceptie.");
e.printStackTrace();
}
} else if ("cancel".equals(cmd)) {
label.setText("Butonul cancel a fost apasat");
}
this.setVisible(false);
}
}
joi, 13 noiembrie 2008
miercuri, 12 noiembrie 2008
Dialog Cautare Produs dupa Cod
package dialogDemo;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.table.DefaultTableModel;
import problema080915.Produs;
import problema080922.DepozitApp;
import problema081017.ProdusDao;
public class SearchByCodDlg extends JDialog implements ActionListener {
JLabel label;
JLabel label1 ;
JTextField tf1;
JTable table;
Produs produs;
JButton ok;
JButton cancel;
ProdusDao produsDao;
DefaultTableModel model;
String[] columnNames = {"Cod",
"Data",
"Denumire",
"Cantitate",
"Valoare unitara"};
public SearchByCodDlg(JFrame owner){
super(owner, "Whatever", true);
label = new JLabel();
label1 = new JLabel("Denumirea");
Dimension size = label1.getPreferredSize();
label1.setBounds(25, 40, size.width, size.height);
tf1 = new JTextField();
size = tf1.getPreferredSize();
//tf1.setBounds(25, 40, size.width, size.height);
//tf1.setColumns(20);
//tf1.setSize(20, 30);
produsDao = ((DepozitApp)owner).getProdusDao();
JScrollPane scrollPane = null;
try {
produs = produsDao.gasesteDupaCod(tf1.getText());
Object[][] data = initModelData(produs);
model = new DefaultTableModel(data, columnNames);
table = new JTable(model);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
scrollPane = new JScrollPane(table);
} catch (SQLException e) {
e.printStackTrace();
}
ok = new JButton("OK");
ok.setActionCommand("ok");
ok.addActionListener(this);
cancel = new JButton("Cancel");
cancel.setActionCommand("cancel");
cancel.addActionListener(this);
size = ok.getPreferredSize();
ok.setBounds(25, 40, size.width, size.height);
size = cancel.getPreferredSize();
cancel.setBounds(25, 80, size.width, size.height);
GroupLayout layout = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
GroupLayout.ParallelGroup hGroup = layout.createParallelGroup(Alignment.LEADING);
hGroup.addGroup(layout.createSequentialGroup().
addComponent(label1).
addComponent(tf1))
.addGroup(layout.createSequentialGroup().
addComponent(scrollPane))
.addGroup(layout.createSequentialGroup().
addComponent(ok).
addComponent(cancel));
layout.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(label1).
addComponent(tf1));
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(scrollPane));
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(ok).
addComponent(cancel));
layout.setVerticalGroup(vGroup);
this.setSize(500, 300);
}
private Object[][] initModelData(Produs pr) {
// initializare tabel cu rezultate:
Object[][] data = new Object[1][5];
data[0][0] = pr.getCod();
data[0][1] = pr.getData();
data[0][2] = pr.getDenumire();
data[0][3] = pr.getCantitatea();
data[0][4] = pr.getValoarea_unitara();
return data;
}
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if("ok".equals(cmd)) {
label.setText("Butonul ok a fost apasat");
try{
Produs produs = produsDao.gasesteDupaCod(tf1.getText());
Object[][] data = initModelData(produs);
//MetodeUtilitare.afiseazaRezultateInterogare(list);
//se schimba datele din modelul tabelului:
model.setDataVector(data, columnNames);
}catch (SQLException e){
System.out.println("Exceptie.");
e.printStackTrace();
}
} else if ("cancel".equals(cmd)) {
label.setText("Butonul cancel a fost apasat");
this.setVisible(false);
}
}
}
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.table.DefaultTableModel;
import problema080915.Produs;
import problema080922.DepozitApp;
import problema081017.ProdusDao;
public class SearchByCodDlg extends JDialog implements ActionListener {
JLabel label;
JLabel label1 ;
JTextField tf1;
JTable table;
Produs produs;
JButton ok;
JButton cancel;
ProdusDao produsDao;
DefaultTableModel model;
String[] columnNames = {"Cod",
"Data",
"Denumire",
"Cantitate",
"Valoare unitara"};
public SearchByCodDlg(JFrame owner){
super(owner, "Whatever", true);
label = new JLabel();
label1 = new JLabel("Denumirea");
Dimension size = label1.getPreferredSize();
label1.setBounds(25, 40, size.width, size.height);
tf1 = new JTextField();
size = tf1.getPreferredSize();
//tf1.setBounds(25, 40, size.width, size.height);
//tf1.setColumns(20);
//tf1.setSize(20, 30);
produsDao = ((DepozitApp)owner).getProdusDao();
JScrollPane scrollPane = null;
try {
produs = produsDao.gasesteDupaCod(tf1.getText());
Object[][] data = initModelData(produs);
model = new DefaultTableModel(data, columnNames);
table = new JTable(model);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
// Create the scroll pane and add the table to it.
scrollPane = new JScrollPane(table);
} catch (SQLException e) {
e.printStackTrace();
}
ok = new JButton("OK");
ok.setActionCommand("ok");
ok.addActionListener(this);
cancel = new JButton("Cancel");
cancel.setActionCommand("cancel");
cancel.addActionListener(this);
size = ok.getPreferredSize();
ok.setBounds(25, 40, size.width, size.height);
size = cancel.getPreferredSize();
cancel.setBounds(25, 80, size.width, size.height);
GroupLayout layout = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
GroupLayout.ParallelGroup hGroup = layout.createParallelGroup(Alignment.LEADING);
hGroup.addGroup(layout.createSequentialGroup().
addComponent(label1).
addComponent(tf1))
.addGroup(layout.createSequentialGroup().
addComponent(scrollPane))
.addGroup(layout.createSequentialGroup().
addComponent(ok).
addComponent(cancel));
layout.setHorizontalGroup(hGroup);
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(label1).
addComponent(tf1));
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(scrollPane));
vGroup.addGroup(layout.createParallelGroup(Alignment.LEADING).
addComponent(ok).
addComponent(cancel));
layout.setVerticalGroup(vGroup);
this.setSize(500, 300);
}
private Object[][] initModelData(Produs pr) {
// initializare tabel cu rezultate:
Object[][] data = new Object[1][5];
data[0][0] = pr.getCod();
data[0][1] = pr.getData();
data[0][2] = pr.getDenumire();
data[0][3] = pr.getCantitatea();
data[0][4] = pr.getValoarea_unitara();
return data;
}
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if("ok".equals(cmd)) {
label.setText("Butonul ok a fost apasat");
try{
Produs produs = produsDao.gasesteDupaCod(tf1.getText());
Object[][] data = initModelData(produs);
//MetodeUtilitare.afiseazaRezultateInterogare(list);
//se schimba datele din modelul tabelului:
model.setDataVector(data, columnNames);
}catch (SQLException e){
System.out.println("Exceptie.");
e.printStackTrace();
}
} else if ("cancel".equals(cmd)) {
label.setText("Butonul cancel a fost apasat");
this.setVisible(false);
}
}
}
joi, 6 noiembrie 2008
Aplicatie pentru lucru cu intrari din Depozit
Clasa Produs:
import java.util.Date;
public class Produs implements Comparable{
private String cod;
private String denumire;
private Date data;
private Integer valoarea_unitara;
private Integer cantitatea;
public String getCod() {
return cod;
}
public void setCod(String cod) {
this.cod = cod;
}
public String getDenumire() {
return denumire;
}
public void setDenumire(String denumire) {
this.denumire = denumire;
}
public Integer getCantitatea() {
return cantitatea;
}
public void setCantitatea(Integer cantitatea) {
this.cantitatea = cantitatea;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
public Integer getValoarea_unitara() {
return valoarea_unitara;
}
public void setValoarea_unitara(Integer valoarea_unitara) {
this.valoarea_unitara = valoarea_unitara;
}
public int compareTo(Object arg0) {
if(arg0 instanceof Produs){
Produs produs = (Produs)arg0;
return -produs.getDenumire().compareTo(denumire);//produs.getDenumire().compareTo(this.getDenumire())
}
return 1;
}
}
import java.util.Date;
public class Produs implements Comparable{
private String cod;
private String denumire;
private Date data;
private Integer valoarea_unitara;
private Integer cantitatea;
public String getCod() {
return cod;
}
public void setCod(String cod) {
this.cod = cod;
}
public String getDenumire() {
return denumire;
}
public void setDenumire(String denumire) {
this.denumire = denumire;
}
public Integer getCantitatea() {
return cantitatea;
}
public void setCantitatea(Integer cantitatea) {
this.cantitatea = cantitatea;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
public Integer getValoarea_unitara() {
return valoarea_unitara;
}
public void setValoarea_unitara(Integer valoarea_unitara) {
this.valoarea_unitara = valoarea_unitara;
}
public int compareTo(Object arg0) {
if(arg0 instanceof Produs){
Produs produs = (Produs)arg0;
return -produs.getDenumire().compareTo(denumire);//produs.getDenumire().compareTo(this.getDenumire())
}
return 1;
}
}
miercuri, 29 octombrie 2008
How to change Shortcuts in Eclipse
English:
To change Shortcuts in Eclipse(3.2.2), you have to go to:
Window -> Preferences -> General -> Keys
In the View Window select the shortcut you want to change and click Edit. You have to Remove the old shortcut and to Add the new one.
Apply -> OK. Return to your project and the shortcut is already effective.
________________
Romanian:
Pentru a schimba o scurtatura in Eclipse(3.2.2), trebuie sa parcurgeti urmatoarele etape:
Window -> Preferences -> General -> Keys
In fereastra View selectati scurtatura pe care doriti sa o modificati si dati click pe Edit. Trebuie sa dati Remove la vechea combinatie de taste si sa dati Add pentru a o adauga pe cea noua.
Apply -> OK. Cand va intoarceti in proiectul dvs., puteti deja utiliza noua combinatie de taste.
To change Shortcuts in Eclipse(3.2.2), you have to go to:
Window -> Preferences -> General -> Keys
In the View Window select the shortcut you want to change and click Edit. You have to Remove the old shortcut and to Add the new one.
Apply -> OK. Return to your project and the shortcut is already effective.
________________
Romanian:
Pentru a schimba o scurtatura in Eclipse(3.2.2), trebuie sa parcurgeti urmatoarele etape:
Window -> Preferences -> General -> Keys
In fereastra View selectati scurtatura pe care doriti sa o modificati si dati click pe Edit. Trebuie sa dati Remove la vechea combinatie de taste si sa dati Add pentru a o adauga pe cea noua.
Apply -> OK. Cand va intoarceti in proiectul dvs., puteti deja utiliza noua combinatie de taste.
luni, 27 octombrie 2008
Primele mele aplicatii in Java
O a doua versiune de DepozitApp arata asa:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
public class DepozitApp {
private Depozit depozit;
public DepozitApp(Depozit depFile){
this.depozit = depFile;
}
private void afiseazaMarfa(List depozit){
System.out.println("Depozitul contine: ");
for(Iterator it = depozit.iterator(); it.hasNext();){
Marfa mr = (Marfa)it.next();
System.out.println("codul "+mr.getCodMarfa()+" numele "+mr.getNume());
}
}
public void run () throws IOException {
int nr=0;
System.out.println("Selectati dintre optiunile existente: ");
System.out.println("1. In cazul in care datele din depozit se vor salva in memorie: ");
System.out.println("2. In cazul in care datele din depozit se vor salva intr-un fisier: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();
try{
nr = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
}
if(nr == 1){
this.depozit = new DepozitMemory();
meniu();
}else if(nr == 2){
this.depozit = new DepozitFile();
meniu();
}else{
System.out.println("Optiunea nu este valida. Alegeti o optiune valida.");
}
}
public void meniu () throws IOException {
int nr1 = 0;
do{
System.out.println("=========== Meniu: =============");
System.out.println("Selectati dintre optiunile existente: ");
System.out.println("1. Adauga marfa");
System.out.println("2. Sterge marfa");
System.out.println("3. Cauta dupa cod");
System.out.println("4. Cauta dupa producator");
System.out.println("5. Cauta dupa nume");
System.out.println("6. Cauta produsele care contin un anumit grup de litere");
System.out.println("7. Afiseaza marfa din depozit");
System.out.println("8. Exit");
System.out.println("Selectati o optiune din cele existente: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();
try{
nr1 = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
continue;
}
switch(nr1){
case 1:
{
System.out.println("1. Adauga marfa: ");
// FileOutputStream fout = null;
// fout = new FileOutputStream("/home/raluca/workspace/problema/src/problema080911/out.txt");
//
// OutputStreamWriter out = new OutputStreamWriter(fout);
// BufferedReader br1 = new BufferedReader(out);
System.out.println("Dati codul produsului: ");
int cod = Integer.parseInt(br.readLine());
System.out.println("Dati numele produsului: ");
String nume = br.readLine();
System.out.println("Dati producatorul: ");
String producator = br.readLine();
Marfa mrf = new Marfa();
mrf.setCodMarfa(cod);
mrf.setNume(nume);
mrf.setProducator(producator);
depozit.adauga(mrf);
// try{
// // Create file
// Writer fstream = new FileWriter("/home/raluca/workspace/problema/src/problema080911/out.txt");
// Writer out = new BufferedWriter(fstream);
//
// out.write(cod);
// out.write(", ");
// out.write(nume);
// out.write(", ");
// out.write(producator);
//
// //Close the output stream
// out.close();
//
// }catch (Exception e){//Catch exception if any
// System.err.println("Error: " + e.getMessage());
// }
break;
}
case 2:
{
System.out.println("2. Sterge marfa. Dati codul: ");
int cod = Integer.parseInt(br.readLine());
depozit.sterge(cod);
break;
}
case 3:
{
System.out.println("3. Cauta dupa cod");
int cod = Integer.parseInt(br.readLine());
// System.out.println((depMem.cautaDupaCod(cod)).getNume());
// if(depMem.cautaDupaCod(cod) == null){
// System.out.println("Produsul nu a fost gasit.");
// }else if(depMem.cautaDupaCod(cod) != null){
// System.out.println("Produsul are numele "+depMem.cautaDupaCod(cod).getNume());
// } static
Marfa mrf = depozit.cautaDupaCod(cod);
if(mrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
System.out.println("Produsul are numele "+mrf.getNume());
}
break;
}
case 4:
{
System.out.println("4. Cauta dupa producator");
String producator = br.readLine();
List listMrf = depozit.cautaDupaProducator(producator);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
afiseazaMarfa(listMrf);
}
break;
}
case 5:
{
System.out.println("5. Cauta dupa nume");
String nume = br.readLine();
List listMrf = depozit.cautaListaDeNume(nume);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}
break;
}
case 6:
{
System.out.println("6. Cauta produse ce contin");
String nume = br.readLine();
List listMrf = depozit.cautaNumeCeContin(nume);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}
break;
}
case 7:
{
System.out.println("7. Afiseaza marfa din depozit");
afiseazaMarfa(depozit.getAll());
break;
}
case 8:
{
System.out.println("8. Exit");
break;
}
default:
System.out.println("Operatie imposibila.");
}
}while(nr1 != 8);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
public class DepozitApp {
private Depozit depozit;
public DepozitApp(Depozit depFile){
this.depozit = depFile;
}
private void afiseazaMarfa(List depozit){
System.out.println("Depozitul contine: ");
for(Iterator it = depozit.iterator(); it.hasNext();){
Marfa mr = (Marfa)it.next();
System.out.println("codul "+mr.getCodMarfa()+" numele "+mr.getNume());
}
}
public void run () throws IOException {
int nr=0;
System.out.println("Selectati dintre optiunile existente: ");
System.out.println("1. In cazul in care datele din depozit se vor salva in memorie: ");
System.out.println("2. In cazul in care datele din depozit se vor salva intr-un fisier: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();
try{
nr = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
}
if(nr == 1){
this.depozit = new DepozitMemory();
meniu();
}else if(nr == 2){
this.depozit = new DepozitFile();
meniu();
}else{
System.out.println("Optiunea nu este valida. Alegeti o optiune valida.");
}
}
public void meniu () throws IOException {
int nr1 = 0;
do{
System.out.println("=========== Meniu: =============");
System.out.println("Selectati dintre optiunile existente: ");
System.out.println("1. Adauga marfa");
System.out.println("2. Sterge marfa");
System.out.println("3. Cauta dupa cod");
System.out.println("4. Cauta dupa producator");
System.out.println("5. Cauta dupa nume");
System.out.println("6. Cauta produsele care contin un anumit grup de litere");
System.out.println("7. Afiseaza marfa din depozit");
System.out.println("8. Exit");
System.out.println("Selectati o optiune din cele existente: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();
try{
nr1 = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
continue;
}
switch(nr1){
case 1:
{
System.out.println("1. Adauga marfa: ");
// FileOutputStream fout = null;
// fout = new FileOutputStream("/home/raluca/workspace/problema/src/problema080911/out.txt");
//
// OutputStreamWriter out = new OutputStreamWriter(fout);
// BufferedReader br1 = new BufferedReader(out);
System.out.println("Dati codul produsului: ");
int cod = Integer.parseInt(br.readLine());
System.out.println("Dati numele produsului: ");
String nume = br.readLine();
System.out.println("Dati producatorul: ");
String producator = br.readLine();
Marfa mrf = new Marfa();
mrf.setCodMarfa(cod);
mrf.setNume(nume);
mrf.setProducator(producator);
depozit.adauga(mrf);
// try{
// // Create file
// Writer fstream = new FileWriter("/home/raluca/workspace/problema/src/problema080911/out.txt");
// Writer out = new BufferedWriter(fstream);
//
// out.write(cod);
// out.write(", ");
// out.write(nume);
// out.write(", ");
// out.write(producator);
//
// //Close the output stream
// out.close();
//
// }catch (Exception e){//Catch exception if any
// System.err.println("Error: " + e.getMessage());
// }
break;
}
case 2:
{
System.out.println("2. Sterge marfa. Dati codul: ");
int cod = Integer.parseInt(br.readLine());
depozit.sterge(cod);
break;
}
case 3:
{
System.out.println("3. Cauta dupa cod");
int cod = Integer.parseInt(br.readLine());
// System.out.println((depMem.cautaDupaCod(cod)).getNume());
// if(depMem.cautaDupaCod(cod) == null){
// System.out.println("Produsul nu a fost gasit.");
// }else if(depMem.cautaDupaCod(cod) != null){
// System.out.println("Produsul are numele "+depMem.cautaDupaCod(cod).getNume());
// } static
Marfa mrf = depozit.cautaDupaCod(cod);
if(mrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
System.out.println("Produsul are numele "+mrf.getNume());
}
break;
}
case 4:
{
System.out.println("4. Cauta dupa producator");
String producator = br.readLine();
List listMrf = depozit.cautaDupaProducator(producator);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
afiseazaMarfa(listMrf);
}
break;
}
case 5:
{
System.out.println("5. Cauta dupa nume");
String nume = br.readLine();
List listMrf = depozit.cautaListaDeNume(nume);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}
break;
}
case 6:
{
System.out.println("6. Cauta produse ce contin");
String nume = br.readLine();
List listMrf = depozit.cautaNumeCeContin(nume);
if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}
break;
}
case 7:
{
System.out.println("7. Afiseaza marfa din depozit");
afiseazaMarfa(depozit.getAll());
break;
}
case 8:
{
System.out.println("8. Exit");
break;
}
default:
System.out.println("Operatie imposibila.");
}
}while(nr1 != 8);
}
}
Abonați-vă la:
Postări (Atom)