Skip to content

Commit f92abc8

Browse files
Updated the example StocksTouch to allow you to add stocks
git-svn-id: http://sqlite-net.googlecode.com/svn/trunk@19 fb26c452-ae10-11de-9734-99f05f10ca21
1 parent 7c845f8 commit f92abc8

9 files changed

+579
-38
lines changed

examples/Stocks/Main.cs

+1-24
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,7 @@ void DisplayStock (string stockSymbol)
4343

4444
void UpdateStock (string stockSymbol)
4545
{
46-
//
47-
// Ensure that there is a valid Stock in the DB
48-
//
49-
var stock = _db.QueryStock (stockSymbol);
50-
if (stock == null) {
51-
stock = new Stock { Symbol = stockSymbol };
52-
_db.Insert (stock);
53-
}
54-
55-
//
56-
// When was it last valued?
57-
//
58-
var latest = _db.QueryLatestValuation (stock);
59-
var latestDate = latest != null ? latest.Time : new DateTime (1950, 1, 1);
60-
61-
//
62-
// Get the latest valuations
63-
//
64-
var newVals = new YahooScraper ().GetValuations (stock, latestDate + TimeSpan.FromHours (23), DateTime.Now);
65-
foreach (var v in newVals) {
66-
Console.Write(".");
67-
_db.Insert (v);
68-
}
69-
Console.WriteLine();
46+
_db.UpdateStock(stockSymbol);
7047
}
7148

7249
void ListStocks ()

examples/Stocks/Stocks.cs

+32
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ public IEnumerable<Stock> QueryAllStocks ()
5858
{
5959
return Query<Stock> ("select * from Stock order by Symbol");
6060
}
61+
62+
public void UpdateStock (string stockSymbol)
63+
{
64+
//
65+
// Ensure that there is a valid Stock in the DB
66+
//
67+
var stock = QueryStock (stockSymbol);
68+
if (stock == null) {
69+
stock = new Stock { Symbol = stockSymbol };
70+
Insert (stock);
71+
}
72+
73+
//
74+
// When was it last valued?
75+
//
76+
var latest = QueryLatestValuation (stock);
77+
var latestDate = latest != null ? latest.Time : new DateTime (1950, 1, 1);
78+
79+
//
80+
// Get the latest valuations
81+
//
82+
try {
83+
var newVals = new YahooScraper ().GetValuations (stock, latestDate + TimeSpan.FromHours (23), DateTime.Now);
84+
foreach (var v in newVals) {
85+
Insert (v);
86+
}
87+
}
88+
catch (System.Net.WebException ex) {
89+
Console.WriteLine (ex);
90+
}
91+
}
6192
}
6293

6394
public class YahooScraper
@@ -66,6 +97,7 @@ public IEnumerable<Valuation> GetValuations (Stock stock, DateTime start, DateTi
6697
{
6798
var t = "http://ichart.finance.yahoo.com/table.csv?s={0}&d={1}&e={2}&f={3}&g=d&a={4}&b={5}&c={6}&ignore=.csv";
6899
var url = string.Format (t, stock.Symbol, end.Month - 1, end.Day, end.Year, start.Month - 1, start.Day, start.Year);
100+
Console.WriteLine ("GET {0}", url);
69101
var req = System.Net.WebRequest.Create (url);
70102
using (var resp = new System.IO.StreamReader (req.GetResponse ().GetResponseStream ())) {
71103
var first = true;

examples/StocksTouch/AddStockView.xib

+286
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03">
3+
<data>
4+
<int key="IBDocument.SystemTarget">768</int>
5+
<string key="IBDocument.SystemVersion">9L30</string>
6+
<string key="IBDocument.InterfaceBuilderVersion">680</string>
7+
<string key="IBDocument.AppKitVersion">949.54</string>
8+
<string key="IBDocument.HIToolboxVersion">353.00</string>
9+
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
10+
<bool key="EncodedWithXMLCoder">YES</bool>
11+
<integer value="1"/>
12+
</object>
13+
<object class="NSArray" key="IBDocument.PluginDependencies">
14+
<bool key="EncodedWithXMLCoder">YES</bool>
15+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
16+
</object>
17+
<object class="NSMutableDictionary" key="IBDocument.Metadata">
18+
<bool key="EncodedWithXMLCoder">YES</bool>
19+
<object class="NSArray" key="dict.sortedKeys">
20+
<bool key="EncodedWithXMLCoder">YES</bool>
21+
</object>
22+
<object class="NSMutableArray" key="dict.values">
23+
<bool key="EncodedWithXMLCoder">YES</bool>
24+
</object>
25+
</object>
26+
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
27+
<bool key="EncodedWithXMLCoder">YES</bool>
28+
<object class="IBProxyObject" id="372490531">
29+
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
30+
</object>
31+
<object class="IBProxyObject" id="711762367">
32+
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
33+
</object>
34+
<object class="IBUIView" id="191373211">
35+
<reference key="NSNextResponder"/>
36+
<int key="NSvFlags">292</int>
37+
<object class="NSMutableArray" key="NSSubviews">
38+
<bool key="EncodedWithXMLCoder">YES</bool>
39+
<object class="IBUITextField" id="441631138">
40+
<reference key="NSNextResponder" ref="191373211"/>
41+
<int key="NSvFlags">292</int>
42+
<string key="NSFrame">{{114, 54}, {186, 64}}</string>
43+
<reference key="NSSuperview" ref="191373211"/>
44+
<bool key="IBUIOpaque">NO</bool>
45+
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
46+
<int key="IBUIContentVerticalAlignment">0</int>
47+
<string key="IBUIText">MSFT</string>
48+
<object class="NSColor" key="IBUITextColor">
49+
<int key="NSColorSpace">3</int>
50+
<bytes key="NSWhite">MAA</bytes>
51+
<object class="NSColorSpace" key="NSCustomColorSpace" id="179399361">
52+
<int key="NSID">2</int>
53+
</object>
54+
</object>
55+
<object class="NSFont" key="IBUIFont">
56+
<string key="NSName">Helvetica</string>
57+
<double key="NSSize">3.600000e+01</double>
58+
<int key="NSfFlags">16</int>
59+
</object>
60+
<bool key="IBUIClearsOnBeginEditing">YES</bool>
61+
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
62+
<float key="IBUIMinimumFontSize">1.700000e+01</float>
63+
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
64+
<int key="IBUIAutocapitalizationType">3</int>
65+
<int key="IBUIAutocorrectionType">1</int>
66+
<int key="IBUIReturnKeyType">9</int>
67+
</object>
68+
<int key="IBUIClearButtonMode">1</int>
69+
</object>
70+
<object class="IBUILabel" id="27104494">
71+
<reference key="NSNextResponder" ref="191373211"/>
72+
<int key="NSvFlags">292</int>
73+
<string key="NSFrame">{{20, 76}, {97, 32}}</string>
74+
<reference key="NSSuperview" ref="191373211"/>
75+
<bool key="IBUIOpaque">NO</bool>
76+
<bool key="IBUIClipsSubviews">YES</bool>
77+
<bool key="IBUIUserInteractionEnabled">NO</bool>
78+
<string key="IBUIText">SYMBOL</string>
79+
<object class="NSColor" key="IBUITextColor">
80+
<int key="NSColorSpace">3</int>
81+
<bytes key="NSWhite">MC41AA</bytes>
82+
<reference key="NSCustomColorSpace" ref="179399361"/>
83+
</object>
84+
<nil key="IBUIHighlightedColor"/>
85+
<int key="IBUIBaselineAdjustment">1</int>
86+
<float key="IBUIMinimumFontSize">1.000000e+01</float>
87+
</object>
88+
<object class="IBUIButton" id="857342587">
89+
<reference key="NSNextResponder" ref="191373211"/>
90+
<int key="NSvFlags">292</int>
91+
<string key="NSFrame">{{228, 132}, {72, 37}}</string>
92+
<reference key="NSSuperview" ref="191373211"/>
93+
<bool key="IBUIOpaque">NO</bool>
94+
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
95+
<int key="IBUIContentHorizontalAlignment">0</int>
96+
<int key="IBUIContentVerticalAlignment">0</int>
97+
<object class="NSFont" key="IBUIFont">
98+
<string key="NSName">Helvetica-Bold</string>
99+
<double key="NSSize">1.500000e+01</double>
100+
<int key="NSfFlags">16</int>
101+
</object>
102+
<int key="IBUIButtonType">1</int>
103+
<string key="IBUINormalTitle">Add</string>
104+
<object class="NSColor" key="IBUIHighlightedTitleColor">
105+
<int key="NSColorSpace">3</int>
106+
<bytes key="NSWhite">MQA</bytes>
107+
</object>
108+
<object class="NSColor" key="IBUINormalTitleColor">
109+
<int key="NSColorSpace">1</int>
110+
<bytes key="NSRGB">MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA</bytes>
111+
</object>
112+
<object class="NSColor" key="IBUINormalTitleShadowColor">
113+
<int key="NSColorSpace">3</int>
114+
<bytes key="NSWhite">MC41AA</bytes>
115+
</object>
116+
</object>
117+
</object>
118+
<string key="NSFrameSize">{320, 416}</string>
119+
<reference key="NSSuperview"/>
120+
<object class="NSColor" key="IBUIBackgroundColor">
121+
<int key="NSColorSpace">3</int>
122+
<bytes key="NSWhite">MQA</bytes>
123+
<reference key="NSCustomColorSpace" ref="179399361"/>
124+
</object>
125+
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
126+
<object class="IBUISimulatedNavigationBarMetrics" key="IBUISimulatedTopBarMetrics">
127+
<bool key="IBUIPrompted">NO</bool>
128+
</object>
129+
</object>
130+
</object>
131+
<object class="IBObjectContainer" key="IBDocument.Objects">
132+
<object class="NSMutableArray" key="connectionRecords">
133+
<bool key="EncodedWithXMLCoder">YES</bool>
134+
<object class="IBConnectionRecord">
135+
<object class="IBCocoaTouchOutletConnection" key="connection">
136+
<string key="label">view</string>
137+
<reference key="source" ref="372490531"/>
138+
<reference key="destination" ref="191373211"/>
139+
</object>
140+
<int key="connectionID">7</int>
141+
</object>
142+
<object class="IBConnectionRecord">
143+
<object class="IBCocoaTouchOutletConnection" key="connection">
144+
<string key="label">symbolName</string>
145+
<reference key="source" ref="372490531"/>
146+
<reference key="destination" ref="441631138"/>
147+
</object>
148+
<int key="connectionID">11</int>
149+
</object>
150+
<object class="IBConnectionRecord">
151+
<object class="IBCocoaTouchOutletConnection" key="connection">
152+
<string key="label">addBtn</string>
153+
<reference key="source" ref="372490531"/>
154+
<reference key="destination" ref="857342587"/>
155+
</object>
156+
<int key="connectionID">13</int>
157+
</object>
158+
</object>
159+
<object class="IBMutableOrderedSet" key="objectRecords">
160+
<object class="NSArray" key="orderedObjects">
161+
<bool key="EncodedWithXMLCoder">YES</bool>
162+
<object class="IBObjectRecord">
163+
<int key="objectID">0</int>
164+
<object class="NSArray" key="object" id="279384305">
165+
<bool key="EncodedWithXMLCoder">YES</bool>
166+
</object>
167+
<reference key="children" ref="1000"/>
168+
<nil key="parent"/>
169+
</object>
170+
<object class="IBObjectRecord">
171+
<int key="objectID">1</int>
172+
<reference key="object" ref="191373211"/>
173+
<object class="NSMutableArray" key="children">
174+
<bool key="EncodedWithXMLCoder">YES</bool>
175+
<reference ref="441631138"/>
176+
<reference ref="27104494"/>
177+
<reference ref="857342587"/>
178+
</object>
179+
<reference key="parent" ref="279384305"/>
180+
</object>
181+
<object class="IBObjectRecord">
182+
<int key="objectID">-1</int>
183+
<reference key="object" ref="372490531"/>
184+
<reference key="parent" ref="279384305"/>
185+
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
186+
</object>
187+
<object class="IBObjectRecord">
188+
<int key="objectID">-2</int>
189+
<reference key="object" ref="711762367"/>
190+
<reference key="parent" ref="279384305"/>
191+
</object>
192+
<object class="IBObjectRecord">
193+
<int key="objectID">9</int>
194+
<reference key="object" ref="441631138"/>
195+
<reference key="parent" ref="191373211"/>
196+
</object>
197+
<object class="IBObjectRecord">
198+
<int key="objectID">10</int>
199+
<reference key="object" ref="27104494"/>
200+
<reference key="parent" ref="191373211"/>
201+
</object>
202+
<object class="IBObjectRecord">
203+
<int key="objectID">12</int>
204+
<reference key="object" ref="857342587"/>
205+
<reference key="parent" ref="191373211"/>
206+
</object>
207+
</object>
208+
</object>
209+
<object class="NSMutableDictionary" key="flattenedProperties">
210+
<bool key="EncodedWithXMLCoder">YES</bool>
211+
<object class="NSMutableArray" key="dict.sortedKeys">
212+
<bool key="EncodedWithXMLCoder">YES</bool>
213+
<string>-1.CustomClassName</string>
214+
<string>-2.CustomClassName</string>
215+
<string>1.IBEditorWindowLastContentRect</string>
216+
<string>1.IBPluginDependency</string>
217+
<string>10.IBPluginDependency</string>
218+
<string>12.IBPluginDependency</string>
219+
<string>9.IBPluginDependency</string>
220+
</object>
221+
<object class="NSMutableArray" key="dict.values">
222+
<bool key="EncodedWithXMLCoder">YES</bool>
223+
<string>AddStockView</string>
224+
<string>UIResponder</string>
225+
<string>{{357, 275}, {320, 480}}</string>
226+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
227+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
228+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
229+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
230+
</object>
231+
</object>
232+
<object class="NSMutableDictionary" key="unlocalizedProperties">
233+
<bool key="EncodedWithXMLCoder">YES</bool>
234+
<object class="NSArray" key="dict.sortedKeys">
235+
<bool key="EncodedWithXMLCoder">YES</bool>
236+
</object>
237+
<object class="NSMutableArray" key="dict.values">
238+
<bool key="EncodedWithXMLCoder">YES</bool>
239+
</object>
240+
</object>
241+
<nil key="activeLocalization"/>
242+
<object class="NSMutableDictionary" key="localizations">
243+
<bool key="EncodedWithXMLCoder">YES</bool>
244+
<object class="NSArray" key="dict.sortedKeys">
245+
<bool key="EncodedWithXMLCoder">YES</bool>
246+
</object>
247+
<object class="NSMutableArray" key="dict.values">
248+
<bool key="EncodedWithXMLCoder">YES</bool>
249+
</object>
250+
</object>
251+
<nil key="sourceID"/>
252+
<int key="maxID">13</int>
253+
</object>
254+
<object class="IBClassDescriber" key="IBDocument.Classes">
255+
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
256+
<bool key="EncodedWithXMLCoder">YES</bool>
257+
<object class="IBPartialClassDescription">
258+
<string key="className">AddStockView</string>
259+
<object class="NSMutableDictionary" key="outlets">
260+
<bool key="EncodedWithXMLCoder">YES</bool>
261+
<object class="NSMutableArray" key="dict.sortedKeys">
262+
<bool key="EncodedWithXMLCoder">YES</bool>
263+
<string>addBtn</string>
264+
<string>symbolName</string>
265+
<string>view</string>
266+
</object>
267+
<object class="NSMutableArray" key="dict.values">
268+
<bool key="EncodedWithXMLCoder">YES</bool>
269+
<string>id</string>
270+
<string>id</string>
271+
<string>id</string>
272+
</object>
273+
</object>
274+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
275+
<string key="majorKey">IBUserSource</string>
276+
<string key="minorKey"/>
277+
</object>
278+
</object>
279+
</object>
280+
</object>
281+
<int key="IBDocument.localizationMode">0</int>
282+
<nil key="IBDocument.LastKnownRelativeProjectPath"/>
283+
<int key="IBDocument.defaultPropertyAccessControl">3</int>
284+
<string key="IBCocoaTouchPluginVersion">3.1</string>
285+
</data>
286+
</archive>

0 commit comments

Comments
 (0)