import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
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.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.iTextField;
public class SearchDateItem {
JFrame frame=new JFrame();
JPanel panel=new JPanel();
JLabel label1=new JLabel("Start Date");
JLabel label2=new JLabel("End Date");
JButton button1=new JButton("Search");
iTextField textfield1=new iTextField();
iTextField textfield2=new iTextField();
String s1;
String s2;
TCProperty Object_Name;
TCProperty Type;
TCProperty Owner;
TCProperty GropupID;
TCProperty DateModified;
public void search() throws InvalidFormatException, IOException
{
s1=textfield1.getText();
s2=textfield2.getText();
FileInputStream input=new FileInputStream(new File("C:\\Temp\\ExcelWorksheet.xlsx"));
Workbook workbook=WorkbookFactory.create(input);
Sheet sheet=(Sheet) workbook.getSheetAt(0);
AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
try
{
TCComponentQueryType querytype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query=(TCComponentQuery) querytype.find("Item...");
String[] EntryName={"Created After","Created Before"};
String[] EntryValue={s1,s2};
//Date formate
//dd-mmm-yyyy
//e.g- 19-may-2000
TCComponent[] comp=query.execute(EntryName, EntryValue);
int rowincr=1;
int colincr=0;
for(int i=0;i<comp.length;i++)
{
TCComponent taskcomp=(TCComponent) comp[i];
Object_Name=taskcomp.getTCProperty("object_name");
Type=taskcomp.getTCProperty("object_type");
Owner=taskcomp.getTCProperty("owning_user");
GropupID=taskcomp.getTCProperty("owning_group");
DateModified=taskcomp.getTCProperty("last_mod_date");
Cell cell1=sheet.getRow(rowincr).getCell(colincr);
cell1.setCellValue(Object_Name.toString());
colincr++;
Cell cell2=sheet.getRow(rowincr).getCell(colincr);
cell2.setCellValue(Type.toString());
colincr++;
Cell cell3=sheet.getRow(rowincr).getCell(colincr);
cell3.setCellValue(Owner.toString());
colincr++;
Cell cell4=sheet.getRow(rowincr).getCell(colincr);
cell4.setCellValue(GropupID.toString());
colincr++;
Cell cell5=sheet.getRow(rowincr).getCell(colincr);
cell5.setCellValue(DateModified.toString());
colincr++;
colincr=0;
rowincr++;
}
} catch (Exception e) {
}
FileOutputStream fos = new FileOutputStream("C:\\Temp\\ExcelWorksheet.xlsx");
workbook.write(fos);
fos.close();
}
public void createDialoge()
{
frame.setTitle("Report Generation");
frame.getContentPane().setBackground(Color.WHITE);
frame.setResizable(true);
frame.setSize(400, 150);
panel.setBounds(0, 0, 400, 150);
panel.setBackground(Color.white);
panel.setLayout(null);
panel.add(label1);
label1.setBounds(20, 20, 100, 29);
panel.add(label2);
label2.setBounds(20, 50, 100, 29);
panel.add(button1);
button1.setBounds(150, 80, 150, 25);
panel.add(textfield1);
textfield1.setBounds(150, 20, 100, 25);
panel.add(textfield2);
textfield2.setBounds(150, 50, 100, 25);
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SearchDateItem sdi=new SearchDateItem();
try {
sdi.search();
System.out.println("hi");
} catch (InvalidFormatException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
frame.add(panel);
frame.setLayout(null);
frame.setVisible(true);
frame.revalidate();
frame.repaint();
frame.setVisible(true);
}
}