Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. cmd.CommandType = CommandType.Text;
  2. dr = cmd.ExecuteReader();
  3. while (dr.Read())
  4. {
  5. var table = new UITableView(this.retrieveData.Frame);
  6. string[] tableItems = new String[] {dr["admin_num"] + ", " + dr["name"]};
  7. table.Source = new TableSource(tableItems);
  8. Add (table);
  9. }
  10.  
  11. cmd.CommandType = CommandType.Text;
  12. dr = cmd.ExecuteReader();
  13.  
  14. // you will need a class mydata with Num and Name properties
  15. List<mydata> data = new List<mydata>();
  16.  
  17. while (dr.Read())
  18. {
  19. data.Add(new mydata { Num = dr["admin_num"], Name = dr["name"] });
  20. }
  21.  
  22. dr.Close();
  23.  
  24. var table = new UITableView(this.retrieveData.Frame);
  25. table.Source = new TableSource(data);
  26. Add (table);
  27.  
  28. public List<DemoClass> getDemoClassList()
  29. {
  30. List<DemoClass> lstDemoClass;
  31. DemoClass objDemoClass;
  32. try
  33. {
  34. String strCommandText;
  35.  
  36. strCommandText = "SELECT * FROM DemoClass ";
  37.  
  38. command = new SqliteCommand(strCommandText, connection);
  39. lstDemoClass = new List<DemoClass>();
  40. using (var reader = command.ExecuteReader())
  41. {
  42. while (reader.Read())
  43. {
  44. objDemoClass = new Homes(false);
  45. objDemoClass.ID = Convert.ToInt32(reader[0]);
  46. objDemoClass.Name = Convert.ToString(reader[1]);
  47. lstDemoClass.Add(objDemoClass);
  48.  
  49. }
  50. }
  51. return lstDemoClass;
  52. }
  53. catch (Exception ex)
  54. {
  55. throw ex;
  56. }
  57. finally
  58. {
  59. command.Dispose();
  60. command = null;
  61. lstDemoClass = null;
  62. objDemoClass = null;
  63. }
  64. }
  65. public void BindList()
  66. {
  67. List<DemoClass> lstDemoClass = new List<DemoClass>();
  68. DemoClass hm = new DemoClass();
  69. lstDemoClass = (List<DemoClass>)hm.getDemoClassList();
  70.  
  71. TableViewDataSource tdatasource = new TableViewDataSource(this, lstDemoClass);
  72. table.Hidden = false;
  73. table.DataSource = tdatasource;
  74. table.Delegate = new TableViewDelegate(this, table, lstDemoClass);
  75. table.ReloadData();
  76. }
  77.  
  78. #region TableDelegate
  79. public class TableViewDelegate : UITableViewDelegate
  80. {
  81. private DemoPageViewController _Controller;
  82. private List<DemoClass> lst;
  83.  
  84. public TableViewDelegate(DemoPageViewController controller ,UITableView tableView, List<DemoClass> tblList)
  85. {
  86. try
  87. {
  88. this._Controller = controller;
  89. this.lst = tblList;
  90. }
  91. catch(Exception ex)
  92. {
  93.  
  94. }
  95. }
  96.  
  97. public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
  98. {
  99. try
  100. {
  101. //This loads the activity spinner till the selection code is completed
  102. _Controller._loadPop = new LoadingOverlay (new System.Drawing.RectangleF(0,0,_Controller.View.Frame.Width,_Controller.View.Frame.Height),"Loading...");
  103. _Controller.View.Add ( _Controller._loadPop );
  104.  
  105. // spin up a new thread to do some long running work using StartNew
  106. Task.Factory.StartNew (
  107. // tasks allow you to use the lambda syntax to pass work
  108. () => {
  109. InvokeOnMainThread(delegate{
  110.  
  111. DemoClass f = lst[indexPath.Row];
  112.  
  113. //Add your code here, usually some navigation or showing a popup
  114. });
  115. }).ContinueWith(t => InvokeOnMainThread(() => {
  116. //Hide the activity spinner
  117. _Controller._loadPop.Hide();
  118. }));
  119.  
  120. }
  121. catch(Exception ex)
  122. {
  123.  
  124. }
  125. finally
  126. {
  127. }
  128. }
  129. }
  130.  
  131. #endregion
  132.  
  133. #region TableDataSource
  134.  
  135. private class TableViewDataSource : UITableViewDataSource
  136. {
  137. static NSString kCellIdentifier = new NSString("MyIdentifier");
  138. private List<DemoClass> lst;
  139. private DemoPageViewController controller;
  140.  
  141. public TableViewDataSource (DemoPageViewController controller ,List<DemoClass> tblLst)
  142. {
  143. this.controller = controller;
  144. this.lst = tblLst;
  145. }
  146.  
  147. public override int NumberOfSections (UITableView tableView)
  148. {
  149. return 1;
  150. }
  151.  
  152. public override int RowsInSection (UITableView tableView, int section)
  153. {
  154. return lst.Count;
  155. }
  156.  
  157. // Override to support conditional editing of the table view.
  158. public override bool CanEditRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
  159. {
  160. // Return false if you do not want the specified item to be editable.
  161. return false;
  162. }
  163.  
  164.  
  165. public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
  166. {
  167. try
  168. {
  169. UITableViewCell cell = tableView.DequeueReusableCell (kCellIdentifier);
  170. if (cell == null)
  171. {
  172. cell = new UITableViewCell (UITableViewCellStyle.Subtitle, kCellIdentifier);
  173. cell.Tag = Environment.TickCount;
  174. }
  175.  
  176. DemoClass objDemo = lst[indexPath.Row];
  177. cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
  178.  
  179. cell.ImageView.Image = UIImage.FromFile("Images/CameraImg.png");
  180. cell.DetailTextLabel.Text = "Show some detail: " + objDemo.DemoDescription.ToString();
  181. cell.TextLabel.Text = "Some Title: " + objDemo.DemoTitle.ToString();
  182. return cell;
  183. }
  184. catch(Exception ex)
  185. {
  186. return null;
  187. }
  188. finally
  189. {
  190.  
  191. }
  192. }
  193. }
  194.  
  195. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement