Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoadingScreen extends MainScreen implements FieldChangeListener
- {
- public static Database database;
- public static String dbLocation;
- public static URI uri;
- VerticalFieldManager ver1,ver2,ver3;
- HorizontalFieldManager hor;
- Font font;
- BasicEditField Name,DateOfBirth,Address,Description;
- ButtonField save,add,show,orderByName,orderByDate;;
- public LoadingScreen()
- {
- font=Font.getDefault().derive(Font.BOLD, 18);
- createDatabase();
- createGUI();
- }
- private void createGUI()
- {
- ver1=new VerticalFieldManager(VerticalFieldManager.FIELD_VCENTER);
- Name=new BasicEditField("Enter Name: ", "", 100, BasicEditField.USE_ALL_WIDTH);
- Name.setFont(font);
- ver1.add(Name);
- DateOfBirth=new BasicEditField("Date of Birth(YYYY-MM-DD): ", "", 60, BasicEditField.USE_ALL_WIDTH);
- DateOfBirth.setFont(font);
- ver1.add(DateOfBirth);
- Address=new BasicEditField("Address: ", "", 100, BasicEditField.USE_ALL_WIDTH);
- Address.setFont(font);
- ver1.add(Address);
- Description=new BasicEditField("Description: ", "", 100, BasicEditField.USE_ALL_WIDTH);
- Description.setFont(font);
- ver1.add(Description);
- save=new ButtonField("Save",ButtonField.FIELD_HCENTER);
- save.setChangeListener(this);
- ver1.add(save);
- ver2=new VerticalFieldManager(Field.FIELD_HCENTER);
- hor=new HorizontalFieldManager();
- add=new ButtonField("ADD");
- add.setChangeListener(this);
- hor.add(add);
- show=new ButtonField("SHOW");
- show.setChangeListener(this);
- hor.add(show);
- hor.setPadding(20, 0, 0, 0);
- ver2.add(hor);
- add(ver2);
- ver3=new VerticalFieldManager(Field.FIELD_HCENTER);
- orderByName=new ButtonField("Sort By Name");
- orderByName.setChangeListener(this);
- ver3.add(orderByName);
- orderByDate=new ButtonField("Sort By Date");
- orderByDate.setChangeListener(this);
- ver3.add(orderByDate);
- add(ver3);
- }
- private void createDatabase()
- {
- dbLocation="/SDCard/Database/";
- try
- {
- uri=URI.create(dbLocation+"ManualRecords.db");
- String str="create table if not exists Employee(Name text,DOB date,Address text,Description text)";
- QueryExecution.queryObj.excuteQuery(str,1);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.out.println("Exception:======================"+e.getMessage()+"\n");
- }
- }
- public void fieldChanged(Field field, int context)
- {
- if(field==save)
- {
- if(Name.getText().equals("")&&DateOfBirth.getText().equals("")&& Address.getText().equals("")&&Description.getText().equals(""))
- {
- UiApplication.getUiApplication().invokeLater(new Runnable()
- {
- public void run()
- {
- Dialog.alert("Enter All Fields");
- }
- });
- }
- else
- {
- String str="insert into Employee values('"+Name.getText()+"','"+DateOfBirth.getText()+"','"+Address.getText()+"','"+Description.getText()+"')";
- QueryExecution.queryObj.excuteQuery(str,2);
- deleteAll();
- createGUI();
- invalidate();
- }
- }
- else if(field==add)
- {
- add(ver1);
- }
- else if(field==show)
- {
- boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee");
- if(bool==true)
- {
- UiApplication.getUiApplication().pushScreen(new ShowTableData());
- }
- else
- {
- UiApplication.getUiApplication().invokeLater(new Runnable()
- {
- public void run()
- {
- Dialog.alert("No Records are Found");
- }
- });
- }
- }
- else if(field==orderByName)
- {
- boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee order by Name ASC");
- if(bool==true)
- {
- UiApplication.getUiApplication().pushScreen(new ShowTableData());
- }
- else
- {
- UiApplication.getUiApplication().invokeLater(new Runnable()
- {
- public void run()
- {
- Dialog.alert("No Records are Found");
- }
- });
- }
- }
- else if(field==orderByDate)
- {
- boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee order by DOB ASC");
- if(bool==true)
- {
- UiApplication.getUiApplication().pushScreen(new ShowTableData());
- }
- else
- {
- UiApplication.getUiApplication().invokeLater(new Runnable()
- {
- public void run()
- {
- Dialog.alert("No Records are Found");
- }
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement