Thursday, May 16, 2019

Is Item Exist

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;

public class IsItemExist {

String msg="";
TCComponentQueryType qtype=null;
TCComponentQuery tcq=null;
JTextField text=new JTextField();
JFrame frame=new JFrame("Search Item");

AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();

public void Dialoge() throws TCException
{
text.setSize(100, 29);
frame.setSize(250, 130);

JPanel panel=new JPanel();
panel.setSize(250, 125);
panel.setLayout(null);

JLabel label1=new JLabel("Item Id");
JLabel label2=new JLabel("Enter Item Id to search");

JButton Search=new JButton("SEARCH");
label2.setBounds(50, 10, 150, 29);
label1.setBounds(30, 40, 80, 29);
text.setBounds(120,40, 100,29);
Search.setBounds(40, 70, 100, 29);

Search.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
isItemExist();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});

panel.add(label2);
panel.add(label1);
panel.add(text);
panel.add(Search);
frame.add(panel);

frame.setVisible(true);
frame.repaint();

}
public void isItemExist() throws TCException
{
String ItemId=text.getText();
qtype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
tcq=(TCComponentQuery) qtype.find("Item...");

String[] entry={"Item ID"};
String[] value={ItemId};

TCComponent[] result=tcq.execute(entry, value);

if(result==null || result.length==0)
{
JOptionPane.showMessageDialog(frame, "No such Item found with Item ID "+ItemId);
//System.out.println("No such Item found with Item ID "+ItemId);
}
else
{
JOptionPane.showMessageDialog(frame, ItemId+" Item Found");
//System.out.println("Item Found");
}
}

}

No comments:

Post a Comment