Skip to content

Commit ad7312b

Browse files
committed
replace Realm by FMDB
1 parent 0b2afcc commit ad7312b

File tree

321 files changed

+10041
-75810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+10041
-75810
lines changed

12306ForMac.xcodeproj/project.pbxproj

+7-19
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@
6262
F12746721D50345D00975DFA /* ClickableDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12746711D50345D00975DFA /* ClickableDatePicker.swift */; };
6363
F12746751D50784100975DFA /* TrainFilterWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12746731D50784100975DFA /* TrainFilterWindowController.swift */; };
6464
F12746761D50784100975DFA /* TrainFilterWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F12746741D50784100975DFA /* TrainFilterWindowController.xib */; };
65-
F13B6FC71C98241B0095B196 /* TicketTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B6FC61C98241B0095B196 /* TicketTask.swift */; };
66-
F13B6FC91C9829BD0095B196 /* Passenger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B6FC81C9829BD0095B196 /* Passenger.swift */; };
67-
F13B6FCB1C982A130095B196 /* Train.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B6FCA1C982A130095B196 /* Train.swift */; };
68-
F13B6FCD1C982A1D0095B196 /* Seat.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13B6FCC1C982A1D0095B196 /* Seat.swift */; };
6965
F13E9C981D0AA9760011F7E2 /* TrainInfoTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13E9C971D0AA9760011F7E2 /* TrainInfoTableCellView.swift */; };
7066
F13E9C9A1D0AB3310011F7E2 /* TrainTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13E9C991D0AB3310011F7E2 /* TrainTableRowView.swift */; };
7167
F147763E1D6B2B2E002FD6AF /* InfoButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = F147763D1D6B2B2E002FD6AF /* InfoButton.swift */; };
7268
F14D6BE41D86E91C00CBD36C /* FilterTrainCodeTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14D6BE31D86E91C00CBD36C /* FilterTrainCodeTransformer.swift */; };
7369
F16CB2291D312A6D0055D39D /* LoadingTipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16CB2271D312A6D0055D39D /* LoadingTipViewController.swift */; };
7470
F16CB22A1D312A6D0055D39D /* LoadingTipViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F16CB2281D312A6D0055D39D /* LoadingTipViewController.xib */; };
7571
F17AB1CC1C95630E00FEB221 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = F17AB1CB1C95630E00FEB221 /* Credits.rtf */; };
72+
F1AF72B81DAA24FB0047486B /* DataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1AF72B71DAA24FB0047486B /* DataManager.swift */; };
7673
F1C075211D83F97A006EFABB /* TicketConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C075201D83F97A006EFABB /* TicketConstants.swift */; };
7774
F1C075231D855EE5006EFABB /* Direction.png in Resources */ = {isa = PBXBuildFile; fileRef = F1C075221D855EE5006EFABB /* Direction.png */; };
7875
F1CA12051D10F546003EFD0B /* TrainCodeDetailHeaderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1CA12041D10F546003EFD0B /* TrainCodeDetailHeaderCell.swift */; };
@@ -167,17 +164,14 @@
167164
F12746711D50345D00975DFA /* ClickableDatePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClickableDatePicker.swift; sourceTree = "<group>"; };
168165
F12746731D50784100975DFA /* TrainFilterWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainFilterWindowController.swift; sourceTree = "<group>"; };
169166
F12746741D50784100975DFA /* TrainFilterWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TrainFilterWindowController.xib; sourceTree = "<group>"; };
170-
F13B6FC61C98241B0095B196 /* TicketTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketTask.swift; sourceTree = "<group>"; };
171-
F13B6FC81C9829BD0095B196 /* Passenger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Passenger.swift; sourceTree = "<group>"; };
172-
F13B6FCA1C982A130095B196 /* Train.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Train.swift; sourceTree = "<group>"; };
173-
F13B6FCC1C982A1D0095B196 /* Seat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Seat.swift; sourceTree = "<group>"; };
174167
F13E9C971D0AA9760011F7E2 /* TrainInfoTableCellView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainInfoTableCellView.swift; sourceTree = "<group>"; };
175168
F13E9C991D0AB3310011F7E2 /* TrainTableRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainTableRowView.swift; sourceTree = "<group>"; };
176169
F147763D1D6B2B2E002FD6AF /* InfoButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfoButton.swift; sourceTree = "<group>"; };
177170
F14D6BE31D86E91C00CBD36C /* FilterTrainCodeTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterTrainCodeTransformer.swift; sourceTree = "<group>"; };
178171
F16CB2271D312A6D0055D39D /* LoadingTipViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingTipViewController.swift; sourceTree = "<group>"; };
179172
F16CB2281D312A6D0055D39D /* LoadingTipViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LoadingTipViewController.xib; sourceTree = "<group>"; };
180173
F17AB1CB1C95630E00FEB221 /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; name = Credits.rtf; path = 12306ForMac/Resources/Credits.rtf; sourceTree = SOURCE_ROOT; };
174+
F1AF72B71DAA24FB0047486B /* DataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataManager.swift; sourceTree = "<group>"; };
181175
F1C075201D83F97A006EFABB /* TicketConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketConstants.swift; sourceTree = "<group>"; };
182176
F1C075221D855EE5006EFABB /* Direction.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Direction.png; path = 12306ForMac/images/Direction.png; sourceTree = SOURCE_ROOT; };
183177
F1CA12041D10F546003EFD0B /* TrainCodeDetailHeaderCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrainCodeDetailHeaderCell.swift; sourceTree = "<group>"; };
@@ -260,7 +254,7 @@
260254
F11154831C8D925200FA6059 /* UserControls */,
261255
F111547A1C8D923C00FA6059 /* Utilities */,
262256
F11154691C8D921400FA6059 /* Model */,
263-
F11154661C8D920600FA6059 /* RealmModel */,
257+
F11154661C8D920600FA6059 /* SqlModel */,
264258
F11154D11C8D936300FA6059 /* MainMenu.xib */,
265259
F11154C71C8D92FC00FA6059 /* AppDelegate.swift */,
266260
F11154CB1C8D931500FA6059 /* MainWindowController.swift */,
@@ -274,16 +268,13 @@
274268
name = 12306ForMac;
275269
sourceTree = "<group>";
276270
};
277-
F11154661C8D920600FA6059 /* RealmModel */ = {
271+
F11154661C8D920600FA6059 /* SqlModel */ = {
278272
isa = PBXGroup;
279273
children = (
280-
F13B6FC61C98241B0095B196 /* TicketTask.swift */,
281274
F11154671C8D920600FA6059 /* User.swift */,
282-
F13B6FC81C9829BD0095B196 /* Passenger.swift */,
283-
F13B6FCA1C982A130095B196 /* Train.swift */,
284-
F13B6FCC1C982A1D0095B196 /* Seat.swift */,
275+
F1AF72B71DAA24FB0047486B /* DataManager.swift */,
285276
);
286-
name = RealmModel;
277+
name = SqlModel;
287278
path = 12306ForMac/RealmModel;
288279
sourceTree = "<group>";
289280
};
@@ -710,12 +701,9 @@
710701
F11154931C8D925200FA6059 /* LunarCalendarView.swift in Sources */,
711702
F1E7EA2F1C5A2E7B007715C1 /* NSDocument+INAppStoreWindowFixes.m in Sources */,
712703
F1E7EA2D1C5A2E7B007715C1 /* INAppStoreWindowSwizzling.c in Sources */,
713-
F13B6FC71C98241B0095B196 /* TicketTask.swift in Sources */,
714704
F11154911C8D925200FA6059 /* ItemCellView.swift in Sources */,
715-
F13B6FCD1C982A1D0095B196 /* Seat.swift in Sources */,
716705
F11154AB1C8D92A700FA6059 /* SubmitWindowController.swift in Sources */,
717706
F1F2F2D41D5B0C0C00EA7786 /* AdvancedPreferenceManager.swift in Sources */,
718-
F13B6FC91C9829BD0095B196 /* Passenger.swift in Sources */,
719707
F11154901C8D925200FA6059 /* GlassView.swift in Sources */,
720708
F11154961C8D925200FA6059 /* RandCodeImageView.swift in Sources */,
721709
F12746721D50345D00975DFA /* ClickableDatePicker.swift in Sources */,
@@ -735,6 +723,7 @@
735723
F11154761C8D921400FA6059 /* PassengerDTO.swift in Sources */,
736724
F1F2F2B01D598AB700EA7786 /* MASPreferencesWindowController.m in Sources */,
737725
F1F2F2C01D59AFB100EA7786 /* GeneralPreferenceViewController.swift in Sources */,
726+
F1AF72B81DAA24FB0047486B /* DataManager.swift in Sources */,
738727
F11154A31C8D929200FA6059 /* Service.swift in Sources */,
739728
F11154951C8D925200FA6059 /* LunarSolarConverter.swift in Sources */,
740729
F11154721C8D921400FA6059 /* LeftTicketParam.swift in Sources */,
@@ -753,7 +742,6 @@
753742
F1F5CE0F1CA9431D005C33BD /* SeatTypeModel.swift in Sources */,
754743
F11154821C8D923C00FA6059 /* XCGLogger.swift in Sources */,
755744
F1CCA2D81D0D3DFA00B6853E /* TrainCodeDetailViewController.swift in Sources */,
756-
F13B6FCB1C982A130095B196 /* Train.swift in Sources */,
757745
F1F2F2C41D59BEE800EA7786 /* AdvancedPreferenceViewController.swift in Sources */,
758746
F1F2F2D01D5AB8F700EA7786 /* Dama.swift in Sources */,
759747
F16CB2291D312A6D0055D39D /* LoadingTipViewController.swift in Sources */,

12306ForMac.xcworkspace/xcuserdata/lindahai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+59-13
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@
138138
ignoreCount = "0"
139139
continueAfterRunningActions = "No"
140140
filePath = "12306ForMac/UserControls/FlashLabel.swift"
141-
timestampString = "491363012.184382"
141+
timestampString = "496241746.797398"
142142
startingColumnNumber = "9223372036854775807"
143143
endingColumnNumber = "9223372036854775807"
144-
startingLineNumber = "78"
145-
endingLineNumber = "78"
144+
startingLineNumber = "77"
145+
endingLineNumber = "77"
146146
landmarkName = "flashNotify()"
147147
landmarkType = "5">
148148
</BreakpointContent>
@@ -431,14 +431,14 @@
431431
endingColumnNumber = "9223372036854775807"
432432
startingLineNumber = "496"
433433
endingLineNumber = "496"
434-
landmarkName = "submit(_:)"
434+
landmarkName = "clickSubmit(_:)"
435435
landmarkType = "5">
436436
</BreakpointContent>
437437
</BreakpointProxy>
438438
<BreakpointProxy
439439
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
440440
<BreakpointContent
441-
shouldBeEnabled = "Yes"
441+
shouldBeEnabled = "No"
442442
ignoreCount = "0"
443443
continueAfterRunningActions = "No"
444444
filePath = "12306ForMac/MainWindowController.swift"
@@ -451,59 +451,59 @@
451451
landmarkType = "3">
452452
<Locations>
453453
<Location
454-
shouldBeEnabled = "Yes"
454+
shouldBeEnabled = "No"
455455
ignoreCount = "0"
456456
continueAfterRunningActions = "No"
457457
symbolName = "_2306ForMac.MainWindowController.orderQueryViewController.getter : _2306ForMac.OrderViewController"
458458
moduleName = "12306ForMac"
459459
usesParentBreakpointCondition = "Yes"
460460
urlString = "file:///Users/lindahai/Desktop/develop/12306ForMac/12306ForMac/MainWindowController.swift"
461-
timestampString = "495733103.991258"
461+
timestampString = "496287091.608722"
462462
startingColumnNumber = "9223372036854775807"
463463
endingColumnNumber = "9223372036854775807"
464464
startingLineNumber = "16"
465465
endingLineNumber = "16"
466466
offsetFromSymbolStart = "35">
467467
</Location>
468468
<Location
469-
shouldBeEnabled = "Yes"
469+
shouldBeEnabled = "No"
470470
ignoreCount = "0"
471471
continueAfterRunningActions = "No"
472472
symbolName = "_2306ForMac.MainWindowController.orderQueryViewController.setter : _2306ForMac.OrderViewController"
473473
moduleName = "12306ForMac"
474474
usesParentBreakpointCondition = "Yes"
475475
urlString = "file:///Users/lindahai/Desktop/develop/12306ForMac/12306ForMac/MainWindowController.swift"
476-
timestampString = "495733103.991417"
476+
timestampString = "496287091.608849"
477477
startingColumnNumber = "9223372036854775807"
478478
endingColumnNumber = "9223372036854775807"
479479
startingLineNumber = "16"
480480
endingLineNumber = "16"
481481
offsetFromSymbolStart = "65">
482482
</Location>
483483
<Location
484-
shouldBeEnabled = "Yes"
484+
shouldBeEnabled = "No"
485485
ignoreCount = "0"
486486
continueAfterRunningActions = "No"
487487
symbolName = "_2306ForMac.MainWindowController.init (window : Swift.Optional&lt;__ObjC.NSWindow&gt;) -&gt; _2306ForMac.MainWindowController"
488488
moduleName = "12306ForMac"
489489
usesParentBreakpointCondition = "Yes"
490490
urlString = "file:///Users/lindahai/Desktop/develop/12306ForMac/12306ForMac/MainWindowController.swift"
491-
timestampString = "495733103.991558"
491+
timestampString = "496287091.608979"
492492
startingColumnNumber = "9223372036854775807"
493493
endingColumnNumber = "9223372036854775807"
494494
startingLineNumber = "16"
495495
endingLineNumber = "16"
496496
offsetFromSymbolStart = "126">
497497
</Location>
498498
<Location
499-
shouldBeEnabled = "Yes"
499+
shouldBeEnabled = "No"
500500
ignoreCount = "0"
501501
continueAfterRunningActions = "No"
502502
symbolName = "_2306ForMac.MainWindowController.init (coder : __ObjC.NSCoder) -&gt; Swift.Optional&lt;_2306ForMac.MainWindowController&gt;"
503503
moduleName = "12306ForMac"
504504
usesParentBreakpointCondition = "Yes"
505505
urlString = "file:///Users/lindahai/Desktop/develop/12306ForMac/12306ForMac/MainWindowController.swift"
506-
timestampString = "495733103.99168"
506+
timestampString = "496287091.609089"
507507
startingColumnNumber = "9223372036854775807"
508508
endingColumnNumber = "9223372036854775807"
509509
startingLineNumber = "16"
@@ -513,5 +513,51 @@
513513
</Locations>
514514
</BreakpointContent>
515515
</BreakpointProxy>
516+
<BreakpointProxy
517+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
518+
<BreakpointContent
519+
shouldBeEnabled = "No"
520+
ignoreCount = "0"
521+
continueAfterRunningActions = "No"
522+
filePath = "12306ForMac/AppDelegate.swift"
523+
timestampString = "496291106.66709"
524+
startingColumnNumber = "9223372036854775807"
525+
endingColumnNumber = "9223372036854775807"
526+
startingLineNumber = "24"
527+
endingLineNumber = "24">
528+
</BreakpointContent>
529+
</BreakpointProxy>
530+
<BreakpointProxy
531+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
532+
<BreakpointContent
533+
shouldBeEnabled = "No"
534+
ignoreCount = "0"
535+
continueAfterRunningActions = "No"
536+
filePath = "12306ForMac/Service/Service+QueryTicket.swift"
537+
timestampString = "496301773.550712"
538+
startingColumnNumber = "9223372036854775807"
539+
endingColumnNumber = "9223372036854775807"
540+
startingLineNumber = "124"
541+
endingLineNumber = "124"
542+
landmarkName = "queryTicketWith(_:queryUrl:)"
543+
landmarkType = "5">
544+
</BreakpointContent>
545+
</BreakpointProxy>
546+
<BreakpointProxy
547+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
548+
<BreakpointContent
549+
shouldBeEnabled = "No"
550+
ignoreCount = "0"
551+
continueAfterRunningActions = "No"
552+
filePath = "12306ForMac/Service/Service+QueryTicket.swift"
553+
timestampString = "496301820.980419"
554+
startingColumnNumber = "9223372036854775807"
555+
endingColumnNumber = "9223372036854775807"
556+
startingLineNumber = "129"
557+
endingLineNumber = "129"
558+
landmarkName = "queryTicketWith(_:queryUrl:)"
559+
landmarkType = "5">
560+
</BreakpointContent>
561+
</BreakpointProxy>
516562
</Breakpoints>
517563
</Bucket>

12306ForMac/Model/OrderQueueResult.swift

-28
This file was deleted.
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// DataManager.swift
3+
// 12306ForMac
4+
//
5+
// Created by fancymax on 16/10/9.
6+
// Copyright © 2016年 fancy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import FMDB
11+
12+
let DATA_DIRECTORY = "\(NSHomeDirectory())/Library/Application Support/\(NSBundle.mainBundle().bundleIdentifier!)"
13+
let DATA_PATH = "\(DATA_DIRECTORY)/12306ForMac.db"
14+
15+
class DataManger {
16+
static let sharedInstance = DataManger()
17+
18+
private init() {
19+
let isExistDirectory:Bool = NSFileManager.defaultManager().fileExistsAtPath(DATA_DIRECTORY, isDirectory: nil)
20+
if !isExistDirectory {
21+
do{
22+
try NSFileManager.defaultManager().createDirectoryAtPath(DATA_DIRECTORY, withIntermediateDirectories: true, attributes: nil)
23+
}
24+
catch {
25+
logger.error("Creat \(DATA_DIRECTORY) fail")
26+
}
27+
}
28+
}
29+
30+
func queryAllUsers() -> [UserX] {
31+
var users=[UserX]()
32+
let db = FMDatabase(path: DATA_PATH)
33+
34+
if !db.open() {
35+
logger.error("Could not open db")
36+
return users
37+
}
38+
39+
db.executeStatements("create table if not exists 'User' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,user varchar, password varchar)")
40+
41+
let rs = try! db.executeQuery("select * from User", values: nil)
42+
//if rs.counto
43+
while(rs.next()){
44+
let newUser = UserX()
45+
newUser.id = rs.longForColumn("id")
46+
newUser.name = rs.stringForColumn("user")
47+
newUser.password = rs.stringForColumn("password")
48+
49+
users.append(newUser)
50+
}
51+
db.close()
52+
53+
return users
54+
}
55+
56+
func updateUser(newUser:UserX) {
57+
let db = FMDatabase(path: DATA_PATH)
58+
59+
if !db.open() {
60+
logger.error("Could not open db")
61+
return
62+
}
63+
64+
do {
65+
try db.executeUpdate("update User set password=? where id=?", values: [newUser.password, newUser.id])
66+
}
67+
catch{
68+
logger.error("updateUser error:\(error)")
69+
}
70+
71+
defer{
72+
db.close()
73+
}
74+
}
75+
76+
func inserUser(newUser:UserX) {
77+
let db = FMDatabase(path: DATA_PATH)
78+
79+
if !db.open() {
80+
logger.error("Could not open db")
81+
return
82+
}
83+
84+
do {
85+
try db.executeUpdate("insert into User (user,password) values (?, ?)", values: [newUser.name, newUser.password])
86+
}
87+
catch {
88+
logger.error("insertUser error:\(error)")
89+
}
90+
91+
defer{
92+
print("db close")
93+
db.close()
94+
}
95+
}
96+
97+
}

0 commit comments

Comments
 (0)