Advertisement
alishaik786

LoadingScreen

Oct 6th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. public class LoadingScreen extends MainScreen implements FieldChangeListener
  2. {
  3.  
  4. public static Database database;
  5. public static String dbLocation;
  6. public static URI uri;
  7.  
  8. VerticalFieldManager ver1,ver2,ver3;
  9. HorizontalFieldManager hor;
  10. Font font;
  11. BasicEditField Name,DateOfBirth,Address,Description;
  12. ButtonField save,add,show,orderByName,orderByDate;;
  13.  
  14. public LoadingScreen()
  15. {
  16. font=Font.getDefault().derive(Font.BOLD, 18);
  17. createDatabase();
  18. createGUI();
  19. }
  20.  
  21. private void createGUI()
  22. {
  23. ver1=new VerticalFieldManager(VerticalFieldManager.FIELD_VCENTER);
  24.  
  25. Name=new BasicEditField("Enter Name: ", "", 100, BasicEditField.USE_ALL_WIDTH);
  26. Name.setFont(font);
  27. ver1.add(Name);
  28. DateOfBirth=new BasicEditField("Date of Birth(YYYY-MM-DD): ", "", 60, BasicEditField.USE_ALL_WIDTH);
  29. DateOfBirth.setFont(font);
  30. ver1.add(DateOfBirth);
  31. Address=new BasicEditField("Address: ", "", 100, BasicEditField.USE_ALL_WIDTH);
  32. Address.setFont(font);
  33. ver1.add(Address);
  34. Description=new BasicEditField("Description: ", "", 100, BasicEditField.USE_ALL_WIDTH);
  35. Description.setFont(font);
  36. ver1.add(Description);
  37.  
  38. save=new ButtonField("Save",ButtonField.FIELD_HCENTER);
  39. save.setChangeListener(this);
  40. ver1.add(save);
  41.  
  42. ver2=new VerticalFieldManager(Field.FIELD_HCENTER);
  43. hor=new HorizontalFieldManager();
  44. add=new ButtonField("ADD");
  45. add.setChangeListener(this);
  46. hor.add(add);
  47.  
  48. show=new ButtonField("SHOW");
  49. show.setChangeListener(this);
  50. hor.add(show);
  51. hor.setPadding(20, 0, 0, 0);
  52. ver2.add(hor);
  53. add(ver2);
  54.  
  55. ver3=new VerticalFieldManager(Field.FIELD_HCENTER);
  56.  
  57. orderByName=new ButtonField("Sort By Name");
  58. orderByName.setChangeListener(this);
  59. ver3.add(orderByName);
  60.  
  61. orderByDate=new ButtonField("Sort By Date");
  62. orderByDate.setChangeListener(this);
  63. ver3.add(orderByDate);
  64.  
  65. add(ver3);
  66.  
  67. }
  68.  
  69. private void createDatabase()
  70. {
  71. dbLocation="/SDCard/Database/";
  72. try
  73. {
  74. uri=URI.create(dbLocation+"ManualRecords.db");
  75. String str="create table if not exists Employee(Name text,DOB date,Address text,Description text)";
  76. QueryExecution.queryObj.excuteQuery(str,1);
  77. }
  78. catch (Exception e)
  79. {
  80. e.printStackTrace();
  81. System.out.println("Exception:======================"+e.getMessage()+"\n");
  82. }
  83. }
  84.  
  85. public void fieldChanged(Field field, int context)
  86. {
  87. if(field==save)
  88. {
  89. if(Name.getText().equals("")&&DateOfBirth.getText().equals("")&& Address.getText().equals("")&&Description.getText().equals(""))
  90. {
  91. UiApplication.getUiApplication().invokeLater(new Runnable()
  92. {
  93. public void run()
  94. {
  95. Dialog.alert("Enter All Fields");
  96. }
  97. });
  98. }
  99. else
  100. {
  101. String str="insert into Employee values('"+Name.getText()+"','"+DateOfBirth.getText()+"','"+Address.getText()+"','"+Description.getText()+"')";
  102. QueryExecution.queryObj.excuteQuery(str,2);
  103. deleteAll();
  104. createGUI();
  105. invalidate();
  106. }
  107. }
  108. else if(field==add)
  109. {
  110. add(ver1);
  111. }
  112. else if(field==show)
  113. {
  114. boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee");
  115. if(bool==true)
  116. {
  117. UiApplication.getUiApplication().pushScreen(new ShowTableData());
  118. }
  119. else
  120. {
  121. UiApplication.getUiApplication().invokeLater(new Runnable()
  122. {
  123. public void run()
  124. {
  125. Dialog.alert("No Records are Found");
  126. }
  127. });
  128. }
  129. }
  130. else if(field==orderByName)
  131. {
  132. boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee order by Name ASC");
  133. if(bool==true)
  134. {
  135. UiApplication.getUiApplication().pushScreen(new ShowTableData());
  136. }
  137. else
  138. {
  139. UiApplication.getUiApplication().invokeLater(new Runnable()
  140. {
  141. public void run()
  142. {
  143. Dialog.alert("No Records are Found");
  144. }
  145. });
  146. }
  147. }
  148. else if(field==orderByDate)
  149. {
  150. boolean bool=SelectDataFromTable.staticTablaDataObject.TableSelection("Select * from Employee order by DOB ASC");
  151. if(bool==true)
  152. {
  153. UiApplication.getUiApplication().pushScreen(new ShowTableData());
  154. }
  155. else
  156. {
  157. UiApplication.getUiApplication().invokeLater(new Runnable()
  158. {
  159. public void run()
  160. {
  161. Dialog.alert("No Records are Found");
  162. }
  163. });
  164. }
  165. }
  166. }
  167. }
  168.  
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement