diff --git "a/21451130\346\261\237\345\261\261/FinalProject/._.DS_Store" "b/21451130\346\261\237\345\261\261/FinalProject/._.DS_Store"
new file mode 100644
index 00000000..0b95af69
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/._.DS_Store" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/icon.png" "b/21451130\346\261\237\345\261\261/FinalProject/icon.png"
new file mode 100644
index 00000000..269032a7
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/icon.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount.sqlite" "b/21451130\346\261\237\345\261\261/FinalProject/mount.sqlite"
new file mode 100644
index 00000000..188b8dcf
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount.sqlite" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.h"
new file mode 100644
index 00000000..91dbb5c4
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.m"
new file mode 100644
index 00000000..97e3e842
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._ViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.h"
new file mode 100644
index 00000000..09ea74a5
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.m"
new file mode 100644
index 00000000..760f0942
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addPersonViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.h"
new file mode 100644
index 00000000..d2ad3a89
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.m"
new file mode 100644
index 00000000..0669ba07
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addSubtypeViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.h"
new file mode 100644
index 00000000..e6f31d6b
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.m"
new file mode 100644
index 00000000..87c50d33
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._addTypeViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.h"
new file mode 100644
index 00000000..5aa085df
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.m"
new file mode 100644
index 00000000..d1b0d453
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billManagement.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.h"
new file mode 100644
index 00000000..7aa3d16c
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.m"
new file mode 100644
index 00000000..b3c3cdae
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._billViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.h"
new file mode 100644
index 00000000..d9abbf58
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.m"
new file mode 100644
index 00000000..5c8be47f
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._budgetManagement.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.h"
new file mode 100644
index 00000000..5da001c5
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.m"
new file mode 100644
index 00000000..dfe01773
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._dateViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.h"
new file mode 100644
index 00000000..62c767d0
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.m"
new file mode 100644
index 00000000..ba452bc3
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayManagement.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.h"
new file mode 100644
index 00000000..75d07599
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.m"
new file mode 100644
index 00000000..f79450c8
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._displayViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.h"
new file mode 100644
index 00000000..009d3228
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.m"
new file mode 100644
index 00000000..8437d472
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._enterTheCategoryViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.h"
new file mode 100644
index 00000000..1bb946e4
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.m"
new file mode 100644
index 00000000..0c234470
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._payout.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.h"
new file mode 100644
index 00000000..bed0f86a
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.m"
new file mode 100644
index 00000000..03c4374b
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._personnelViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.h"
new file mode 100644
index 00000000..64c8e505
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.m"
new file mode 100644
index 00000000..2a5a98cd
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingManagement.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.h"
new file mode 100644
index 00000000..dff2a357
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.m"
new file mode 100644
index 00000000..3dc30cab
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._settingViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.h"
new file mode 100644
index 00000000..bef2f9d2
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.m"
new file mode 100644
index 00000000..9007ca56
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/._typeViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/404error.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/404error.png"
new file mode 100644
index 00000000..1d208bc4
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/404error.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModal.xib" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModal.xib"
new file mode 100644
index 00000000..5153a63e
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModal.xib"
@@ -0,0 +1,100 @@
+
+
+
+ 1552
+ 12C60
+ 3084
+ 1187.34
+ 625.00
+
+
+ IBProxyObject
+ IBUIView
+
+
+ com.apple.InterfaceBuilder.IBCocoaTouchPlugin
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ -1
+
+
+ File's Owner
+
+
+ -2
+
+
+
+
+ 3
+
+
+
+
+
+
+
+ com.apple.InterfaceBuilder.IBCocoaTouchPlugin
+ UIResponder
+ com.apple.InterfaceBuilder.IBCocoaTouchPlugin
+ com.apple.InterfaceBuilder.IBCocoaTouchPlugin
+
+
+
+
+
+ 33
+
+
+ 0
+ IBCocoaTouchFramework
+ YES
+ 3
+ 2083
+
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.h"
new file mode 100644
index 00000000..27519ab7
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.h"
@@ -0,0 +1,48 @@
+//
+// ASDepthModalViewController.h
+// ASDepthModal
+//
+// Created by Philippe Converset on 03/10/12.
+// Copyright (c) 2012 AutreSphere.
+//
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import
+
+typedef NS_OPTIONS(NSUInteger, ASDepthModalOptions) {
+ ASDepthModalOptionAnimationGrow = 0 << 0, //default
+ ASDepthModalOptionAnimationShrink = 1 << 0,
+ ASDepthModalOptionAnimationNone = 2 << 0,
+ ASDepthModalOptionBlur = 0 << 8, // default
+ ASDepthModalOptionBlurNone = 1 << 8,
+ ASDepthModalOptionTapOutsideToClose = 0 << 9, // default
+ ASDepthModalOptionTapOutsideInactive= 1 << 9
+};
+
+/*
+Mostly inspired by http://lab.hakim.se/avgrund/
+*/
+@interface ASDepthModalViewController : UIViewController
+
++ (void)presentView:(UIView *)view backgroundColor:(UIColor *)color options:(ASDepthModalOptions)options completionHandler:(void(^)())handler;
++ (void)presentView:(UIView *)view;
++ (void)dismiss;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.m"
new file mode 100644
index 00000000..0fb2e970
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ASDepthModalViewController.m"
@@ -0,0 +1,298 @@
+//
+// ASDepthModalViewController.m
+// ASDepthModal
+//
+// Created by Philippe Converset on 03/10/12.
+// Copyright (c) 2012 AutreSphere.
+//
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "ASDepthModalViewController.h"
+#import
+#import "UIImage+Blur.h"
+
+static NSTimeInterval const kModalViewAnimationDuration = 0.3;
+static CGFloat const kBlurValue = 0.2;
+static CGFloat const kDefaultiPhoneCornerRadius = 4;
+static CGFloat const kDefaultiPadCornerRadius = 6;
+
+static NSInteger const kDepthModalOptionAnimationMask = 3 << 0;
+static NSInteger const kDepthModalOptionBlurMask = 1 << 8;
+static NSInteger const kDepthModalOptionTapMask = 1 << 9;
+
+@interface ASDepthModalViewController ()
+@property (nonatomic, strong) UIViewController *rootViewController;
+@property (nonatomic, strong) UIView *coverView;
+@property (nonatomic, strong) UIView *popupView;
+@property (nonatomic, assign) CGAffineTransform initialPopupTransform;
+@property (nonatomic, strong) UIImageView *blurView;
+@property (nonatomic, strong) void(^completionHandler)();
+@end
+
+@implementation ASDepthModalViewController
+
+- (id)init
+{
+ self = [super init];
+ if (self)
+ {
+ self.view.backgroundColor = [UIColor blackColor];
+ self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
+ self.view.backgroundColor = [UIColor blackColor];
+ }
+ return self;
+}
+
+- (void)restoreRootViewController
+{
+ UIWindow *window;
+
+ window = [UIApplication sharedApplication].keyWindow;
+ [self.rootViewController.view removeFromSuperview];
+ self.rootViewController.view.transform = window.rootViewController.view.transform;
+ window.rootViewController = self.rootViewController;
+}
+
+- (void)dismiss
+{
+ [UIView animateWithDuration:kModalViewAnimationDuration
+ animations:^{
+ self.coverView.alpha = 0;
+ self.rootViewController.view.transform = CGAffineTransformIdentity;
+ self.popupView.transform = self.initialPopupTransform;
+ self.blurView.alpha = 0;
+ }
+ completion:^(BOOL finished) {
+ [self.rootViewController.view.layer setMasksToBounds:NO];
+ [self.blurView removeFromSuperview];
+ [self restoreRootViewController];
+ self.rootViewController.view.layer.cornerRadius = 0;
+
+ if (self.completionHandler) {
+ self.completionHandler();
+ }
+ }];
+}
+
+- (void)animatePopupWithStyle:(ASDepthModalOptions)options
+{
+ NSInteger style = (options & kDepthModalOptionAnimationMask);
+
+ switch (style) {
+ case ASDepthModalOptionAnimationGrow:
+ {
+ self.popupView.transform = CGAffineTransformMakeScale(0.8, 0.8);
+ self.initialPopupTransform = self.popupView.transform;
+ [UIView animateWithDuration:kModalViewAnimationDuration
+ animations:^{
+ self.popupView.transform = CGAffineTransformIdentity;
+ }];
+ }
+ break;
+
+ case ASDepthModalOptionAnimationShrink:
+ {
+ self.popupView.transform = CGAffineTransformMakeScale(1.5, 1.5);
+ self.initialPopupTransform = self.popupView.transform;
+ [UIView animateWithDuration:kModalViewAnimationDuration
+ animations:^{
+ self.popupView.transform = CGAffineTransformIdentity;
+ }];
+ }
+ break;
+
+ default:
+ self.initialPopupTransform = self.popupView.transform;
+ break;
+ }
+}
+
+- (void)presentView:(UIView *)view withBackgroundColor:(UIColor *)color options:(ASDepthModalOptions)options completionHandler:(void(^)())handler
+{
+ UIWindow *window;
+ CGRect frame;
+
+ if(color != nil)
+ {
+ self.view.backgroundColor = color;
+ }
+ self.completionHandler = handler;
+
+ window = [UIApplication sharedApplication].keyWindow;
+ self.rootViewController = window.rootViewController;
+ frame = self.rootViewController.view.frame;
+ if(![UIApplication sharedApplication].isStatusBarHidden)
+ {
+ self.rootViewController.view.layer.cornerRadius = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad?kDefaultiPadCornerRadius:kDefaultiPhoneCornerRadius);
+ // Take care of the status bar only if the frame is full screen, which depends on the View controller type.
+ // For example, frame is full screen with UINavigationController, but not with basic UIViewController.
+ if(UIInterfaceOrientationIsPortrait(self.rootViewController.interfaceOrientation))
+ {
+ if(frame.size.height == window.bounds.size.height)
+ {
+ frame.size.height -= [UIApplication sharedApplication].statusBarFrame.size.height;
+ }
+ }
+ else
+ {
+ if(frame.size.width == window.bounds.size.width)
+ {
+ frame.size.width -= [UIApplication sharedApplication].statusBarFrame.size.width;
+ }
+ }
+ }
+ self.view.transform = self.rootViewController.view.transform;
+ self.rootViewController.view.transform = CGAffineTransformIdentity;
+ frame.origin = CGPointZero;
+ self.rootViewController.view.frame = frame;
+ [self.view addSubview:self.rootViewController.view];
+ window.rootViewController = self;
+
+ self.popupView = [[UIView alloc] initWithFrame:view.frame];
+ self.popupView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;
+ [self.popupView addSubview:view];
+
+ self.coverView = [[UIView alloc] initWithFrame:self.rootViewController.view.bounds];
+ self.coverView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
+ self.coverView.backgroundColor = [UIColor colorWithRed:00/255.0 green:00/255.0 blue:00/255.0 alpha:0.5];
+ [self.view addSubview:self.coverView];
+
+ if ((options & kDepthModalOptionTapMask) == ASDepthModalOptionTapOutsideToClose)
+ {
+ UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCloseAction:)];
+ tapGesture.delegate = self;
+ [self.coverView addGestureRecognizer:tapGesture];
+ }
+
+ [self.coverView addSubview:self.popupView];
+ self.popupView.center = CGPointMake(self.coverView.bounds.size.width/2, self.coverView.bounds.size.height/2);
+
+ self.coverView.alpha = 0;
+
+ if ((options & kDepthModalOptionBlurMask) == ASDepthModalOptionBlur) {
+ UIImage *image;
+
+ image = [self screenshotForView:self.rootViewController.view];
+ image = [image boxblurImageWithBlur:kBlurValue];
+ self.blurView = [[UIImageView alloc] initWithImage:image];
+ self.blurView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
+ self.blurView.alpha = 0;
+ [self.rootViewController.view addSubview:self.blurView];
+ }
+
+ [self.rootViewController.view.layer setMasksToBounds:YES];
+ [UIView animateWithDuration:kModalViewAnimationDuration
+ animations:^{
+ self.rootViewController.view.transform = CGAffineTransformMakeScale(0.9, 0.9);
+ self.coverView.alpha = 1;
+ self.blurView.alpha = 1;
+ }];
+ [self animatePopupWithStyle:options];
+}
+
+- (UIImage*)screenshotForView:(UIView *)view
+{
+ UIGraphicsBeginImageContext(view.bounds.size);
+ [view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ // hack, helps w/ our colors when blurring
+ NSData *imageData = UIImageJPEGRepresentation(image, 1); // convert to jpeg
+ image = [UIImage imageWithData:imageData];
+
+ return image;
+}
+
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
+ if (touch.view == self.coverView)
+ return YES;
+ return NO;
+}
+
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
+{
+ self.rootViewController.view.transform = CGAffineTransformIdentity;
+ self.rootViewController.view.bounds = self.view.bounds;
+ if(self.blurView != nil)
+ {
+ UIImage *image;
+
+ self.blurView.hidden = YES;
+ image = [self screenshotForView:self.rootViewController.view];
+ self.blurView.hidden = NO;
+ self.blurView.image = [image boxblurImageWithBlur:kBlurValue];
+ }
+ self.rootViewController.view.transform = CGAffineTransformMakeScale(0.9, 0.9);
+}
+
++ (void)presentView:(UIView *)view
+{
+ [self presentView:view backgroundColor:nil options:0 completionHandler:nil];
+}
+
++ (void)presentView:(UIView *)view backgroundColor:(UIColor *)color options:(ASDepthModalOptions)options completionHandler:(void(^)())handler
+{
+ ASDepthModalViewController *modalViewController = [[ASDepthModalViewController alloc] init];
+
+ [modalViewController presentView:view withBackgroundColor:(UIColor *)color options:options completionHandler:handler];
+}
+
++ (NSInteger)optionsWithStyle:(ASDepthModalOptions)style blur:(BOOL)blur tapOutsideToClose:(BOOL)tapToClose
+{
+ NSInteger options;
+
+ options = (NSInteger)style;
+
+ if (blur)
+ options |= ASDepthModalOptionBlur;
+ else
+ options |= ASDepthModalOptionBlurNone;
+
+
+ if (tapToClose)
+ options |= ASDepthModalOptionTapOutsideToClose;
+ else
+ options |= ASDepthModalOptionTapOutsideInactive;
+
+ return options;
+}
+
++ (void)dismiss
+{
+ UIWindow *window;
+
+ window = [UIApplication sharedApplication].keyWindow;
+ if([window.rootViewController isKindOfClass:[ASDepthModalViewController class]])
+ {
+ ASDepthModalViewController *controller;
+
+ controller = (ASDepthModalViewController *)window.rootViewController;
+ [controller dismiss];
+ }
+}
+
+#pragma mark - Action
+- (void)handleCloseAction:(id)sender
+{
+ [self dismiss];
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.h"
new file mode 100644
index 00000000..42999933
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.h"
@@ -0,0 +1,15 @@
+//
+// AppDelegate.h
+// mount
+//
+// Created by zd2011 on 13-5-2.
+// Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
+//
+
+#import
+
+@interface AppDelegate : UIResponder
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.m"
new file mode 100644
index 00000000..1fd389a7
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/AppDelegate.m"
@@ -0,0 +1,48 @@
+//
+// AppDelegate.m
+// mount
+//
+// Created by zd2011 on 13-5-2.
+// Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ // Override point for customization after application launch.
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/BackgroundTexture@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/BackgroundTexture@2x.png"
new file mode 100644
index 00000000..59a73473
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/BackgroundTexture@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/Config.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/Config.h"
new file mode 100644
index 00000000..86405b39
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/Config.h"
@@ -0,0 +1,36 @@
+//
+// Config.h
+// Zhihu
+//
+// Created by Kevin Nick on 2012-10-28.
+// Copyright (c) 2012年 com.zen. All rights reserved.
+//
+
+#ifndef SysLog
+#if DEBUG
+#define SysLog(fmt, ...) NSLog((@"%s [Line: %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#else
+#define SysLog(fmt, ...)
+#define NSLog(fmt, ...)
+#endif
+#endif
+
+#define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
+#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
+
+#define kMaxNumber 100000
+
+#define kProductName @"Zhihu" // 匹配xxx.xcdatamodeld
+#define kCoreDataDBName @"Zhihu.sqlite"
+#define kCoreDataEntity_Feed @"Feed"
+
+#define FONT_SIZE_SMALL 12.0f
+#define FONT_SIZE_NORMAL 14.0f
+#define FONT_SIZE_MEDIUM 15.0f
+#define FONT_SIZE_LARGE 16.0f
+
+#define HEITI_SC_LIGHT @"STHeitiSC-Light"
+#define HEITI_SC_MEDIUM @"STHeitiSC-Medium"
+
+#define FONT_SIZE_NORMAL_HEIGHT 16.0f
+#define FONT_SIZE_MEDIUM_HEIGHT 17.0f
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/Default-568h@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default-568h@2x.png"
new file mode 100644
index 00000000..0891b7aa
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default-568h@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/Default.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default.png"
new file mode 100644
index 00000000..4c8ca6f6
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/Default@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default@2x.png"
new file mode 100644
index 00000000..35b84cff
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/Default@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/GenericSeparator@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/GenericSeparator@2x.png"
new file mode 100644
index 00000000..0745a367
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/GenericSeparator@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardBackgroundTextured@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardBackgroundTextured@2x.png"
new file mode 100644
index 00000000..157138d5
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardBackgroundTextured@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyBackspaceGlyphTextured@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyBackspaceGlyphTextured@2x.png"
new file mode 100644
index 00000000..145ac04b
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyBackspaceGlyphTextured@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyPressedTextured@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyPressedTextured@2x.png"
new file mode 100644
index 00000000..f37266a0
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyPressedTextured@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyTextured@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyTextured@2x.png"
new file mode 100644
index 00000000..2f367c9a
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryKeyTextured@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryViewGridLinesTextured@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryViewGridLinesTextured@2x.png"
new file mode 100644
index 00000000..6503bb38
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardNumericEntryViewGridLinesTextured@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardTopShadow@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardTopShadow@2x.png"
new file mode 100644
index 00000000..a8ce72cb
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/KeyboardTopShadow@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.h"
new file mode 100644
index 00000000..b4b7a6f2
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.h"
@@ -0,0 +1,124 @@
+//
+// UIButton+Effects.h
+// fwMeCard
+//
+// Created by Water Lou on 6/1/11.
+// Copyright 2011 First Water Tech Ltd. All rights reserved.
+//
+
+#import
+
+@interface UIButton(UIGlossyButton)
+
+- (void) useWhiteLabel : (BOOL) dimOnClickedOrDisabled;
+- (void) useBlackLabel : (BOOL) dimOnClickedOrDisabled;
+
+@end
+
+@interface UIColor(UIGlossyButton)
+
++ (UIColor*) doneButtonColor;
++ (UIColor*) navigationBarButtonColor;
+
+@end
+
+typedef enum _UIGlossyButtonGradientType {
+ kUIGlossyButtonGradientTypeLinearSmoothStandard = 0, // general vertical linear gradient, normal to little dark
+ kUIGlossyButtonGradientTypeLinearGlossyStandard, // iOS like glossy effect
+ kUIGlossyButtonGradientTypeLinearSmoothExtreme, // Very bright to very dim
+ kUIGlossyButtonGradientTypeLinearSmoothBrightToNormal, // very bright to normal
+ kUIGlossyButtonGradientTypeSolid, // plain solid
+} UIGlossyButtonGradientType;
+
+typedef enum _UIGlossyButtonStrokeType{
+ kUIGlossyButtonStrokeTypeNone = 0,
+ kUIGlossyButtonStrokeTypeSolid, // simple solid color
+ kUIGlossyButtonStrokeTypeInnerBevelDown, // draw bevel down effect (naivagation bar button)
+ kUIGlossyButtonStrokeTypeGradientFrame, // frame a 1 pixel b/w gradient (default delete button)
+ kUIGlossyButtonStrokeTypeBevelUp, // stroke bevel using button color
+} UIGlossyButtonStrokeType;
+
+typedef enum _UIGlossyButtonExtraShadingType {
+ kUIGlossyButtonExtraShadingTypeNone = 0, // no extra shading
+ kUIGlossyButtonExtraShadingTypeRounded, // rounded shading, shading radius = button corner radius
+ kUIGlossyButtonExtraShadingTypeAngleLeft,
+ kUIGlossyButtonExtraShadingTypeAngleRight,
+} UIGlossyButtonExtraShadingType;
+
+/**
+ Create color button without any images,
+ draw with different gradient, frame and glossy effect
+ **/
+
+@interface UIGlossyButton : UIButton {
+@private
+ // data to create gradient of the button
+ const CGFloat *background_gradient;
+ const CGFloat *locations;
+ NSInteger numberOfColorsInGradient;
+
+@protected
+ UIColor *_tintColor;
+ UIColor *_disabledColor;
+
+ UIColor *_borderColor;
+ UIColor *_disabledBorderColor;
+
+ CGFloat _buttonCornerRadius;
+ CGFloat _innerBorderWidth;
+ CGFloat _buttonBorderWidth;
+
+ BOOL _invertGraidentOnSelected;
+
+ CGFloat _backgroundOpacity;
+
+ UIEdgeInsets _buttonInsets;
+
+ UIGlossyButtonStrokeType _strokeType;
+ UIGlossyButtonExtraShadingType _extraShadingType;
+}
+
+@property (nonatomic, retain) UIColor *tintColor;
+@property (nonatomic, retain) UIColor *disabledColor; // color when disabled, can be nil for lightgray color when disabled
+@property (nonatomic, assign) CGFloat buttonCornerRadius; // outer button border
+@property (nonatomic, assign) UIEdgeInsets buttonInsets; // inset of the button face, default 0.0
+@property (nonatomic, retain) UIColor *borderColor; // button border color, default nil = dark gray
+@property (nonatomic, retain) UIColor *disabledBorderColor; // color when disabled, can be nil for lightgray color when disabled
+@property (nonatomic, assign) CGFloat buttonBorderWidth; // outer button border width, default 1.0
+@property (nonatomic, assign) CGFloat innerBorderWidth; // inner stroke that fill same color as the tint color, default = 1.0
+@property (nonatomic, assign) UIGlossyButtonStrokeType strokeType; // outer button border
+@property (nonatomic, assign) UIGlossyButtonExtraShadingType extraShadingType; // extra shading effect other than gradient
+@property (nonatomic, assign) BOOL invertGraidentOnSelected; // invert the gradient when button down for inner bevel effect, default = NO
+@property (nonatomic, assign) CGFloat backgroundOpacity; // default 1.0, set smaller to draw button in transparent
+
+/* path for the button, default is a round corner rectangle, we can subclass and customize it */
+- (UIBezierPath *) pathForButton : (CGFloat) inset;
+
+- (void) setGradientType : (UIGlossyButtonGradientType) type;
+
+- (void) setActionSheetButtonWithColor : (UIColor*) color;
+- (void) setNavigationButtonWithColor : (UIColor*) color; // navigation bar button, or store button
+
+@end
+
+
+/* subtype that with left and right navigation button shape */
+@interface UIGNavigationButton : UIGlossyButton {
+@private
+ BOOL _leftArrow;
+}
+
+@property (nonatomic, getter = isLeftArrow) BOOL leftArrow;
+
+@end
+
+@interface UIGBadgeButton : UIGlossyButton {
+@private
+ NSInteger numberOfEdges;
+ CGFloat innerRadiusRatio;
+}
+
+@property (nonatomic, assign) NSInteger numberOfEdges;
+@property (nonatomic, assign) CGFloat innerRadiusRatio;
+
+@end
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.m"
new file mode 100644
index 00000000..f62c2b5c
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIGlossyButton.m"
@@ -0,0 +1,555 @@
+//
+// UIButton+Effects.m
+// fwMeCard
+//
+// Created by Water Lou on 6/1/11.
+// Copyright 2011 First Water Tech Ltd. All rights reserved.
+//
+
+
+#import "UIGlossyButton.h"
+
+static void RetinaAwareUIGraphicsBeginImageContext(CGSize size) {
+ static CGFloat scale = -1.0;
+ if (scale<0.0) {
+ UIScreen *screen = [UIScreen mainScreen];
+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {
+ scale = [screen scale];
+ }
+ else {
+ scale = 0.0; // mean use old api
+ }
+ }
+ if (scale>0.0) {
+ UIGraphicsBeginImageContextWithOptions(size, NO, scale);
+ }
+ else {
+ UIGraphicsBeginImageContext(size);
+ }
+}
+
+
+
+@implementation UIButton(UIGlossyButton)
+
+- (void) useWhiteLabel : (BOOL) dimOnClickedOrDisabled {
+ [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
+ UIColor *dimColor = nil;
+ if (dimOnClickedOrDisabled) dimColor = [UIColor lightGrayColor];
+ [self setTitleColor:dimColor forState:UIControlStateDisabled];
+ [self setTitleColor:dimColor forState:UIControlStateHighlighted];
+}
+
+- (void) useBlackLabel : (BOOL) dimOnClickedOrDisabled {
+ [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+ UIColor *dimColor = nil;
+ if (dimOnClickedOrDisabled) dimColor = [UIColor darkGrayColor];
+ [self setTitleColor:dimColor forState:UIControlStateDisabled];
+ [self setTitleColor:dimColor forState:UIControlStateHighlighted];
+}
+
+@end
+
+
+@implementation UIColor(UIGlossyButton)
+
++ (UIColor*) doneButtonColor {
+ return [UIColor colorWithRed:34.0f/255.0f green:96.0f/255.0f blue:221.0f/255.0f alpha:1.0f]; // DONE
+}
+
++ (UIColor*) navigationBarButtonColor {
+ return [UIColor colorWithRed:72.0f/255.0f green:106.0f/255.0f blue:154.0f/255.0f alpha:1.0f];
+}
+
+@end
+
+
+#pragma =================================================
+#pragma =================================================
+#pragma =================================================
+
+
+@interface UIGlossyButton()
+
+// main draw routine, not including stroke the outer path
+- (void) drawTintColorButton : (CGContextRef)context tintColor : (UIColor *) tintColor isSelected : (BOOL) isSelected;
+- (void) strokeButton : (CGContextRef)context color : (UIColor *)color isSelected : (BOOL) isSelected;
+
+@end
+
+@implementation UIGlossyButton
+
+@synthesize tintColor = _tintColor, disabledColor = _disabledColor;
+@synthesize buttonCornerRadius = _buttonCornerRadius;
+@synthesize borderColor = _borderColor, disabledBorderColor = _disabledBorderColor;
+@synthesize buttonBorderWidth = _buttonBorderWidth;
+@synthesize innerBorderWidth = _innerBorderWidth;
+@synthesize strokeType = _strokeType, extraShadingType = _extraShadingType;
+@synthesize backgroundOpacity = _backgroundOpacity;
+@synthesize buttonInsets = _buttonInsets;
+@synthesize invertGraidentOnSelected = _invertGraidentOnSelected;
+
+
+#pragma lifecycle
+
+
+- (void) setupSelf {
+ _buttonCornerRadius = 4.0f;
+ _innerBorderWidth = 1.0;
+ _buttonBorderWidth = 1.0;
+ _backgroundOpacity = 1.0;
+ _buttonInsets = UIEdgeInsetsZero;
+ [self setGradientType: kUIGlossyButtonGradientTypeLinearSmoothStandard];
+ [self addObserver:self forKeyPath:@"highlighted" options:0 context:nil];
+ [self addObserver:self forKeyPath:@"enabled" options:0 context:nil];
+}
+
+- (id) initWithCoder:(NSCoder *)aDecoder {
+ if ((self = [super initWithCoder:aDecoder])) {
+ [self setupSelf];
+ }
+ return self;
+}
+
+- (id) initWithFrame:(CGRect)frame {
+ if ((self = [super initWithFrame:frame])) {
+ [self setupSelf];
+ }
+ return self;
+}
+
+-(void) dealloc {
+ [self removeObserver:self forKeyPath:@"highlighted"];
+ [self removeObserver:self forKeyPath:@"enabled"];
+
+#if !__has_feature(objc_arc)
+ self.tintColor = nil;
+ self.disabledColor = nil;
+ self.borderColor = nil;
+ self.disabledColor = nil;
+ [super dealloc];
+#endif
+}
+
+#pragma mark -
+
+/* graident that will be used to fill on top of the button for 3D effect */
+- (void) setGradientType : (UIGlossyButtonGradientType) type {
+ switch (type) {
+ case kUIGlossyButtonGradientTypeLinearSmoothStandard:
+ {
+ static const CGFloat g0[] = {0.5, 1.0, 0.35, 1.0};
+ background_gradient = g0;
+ locations = nil;
+ numberOfColorsInGradient = 2;
+ }
+ break;
+ case kUIGlossyButtonGradientTypeLinearSmoothExtreme:
+ {
+ static const CGFloat g0[] = {0.8, 1.0, 0.2, 1.0};
+ background_gradient = g0;
+ locations = nil;
+ numberOfColorsInGradient = 2;
+ }
+ break;
+ case kUIGlossyButtonGradientTypeLinearSmoothBrightToNormal:
+ {
+ static const CGFloat g0[] = {0.9, 1.0, 0.5, 1.0, 0.5, 1.0};
+ static const CGFloat l0[] = {0.0, 0.7, 1.0};
+ background_gradient = g0;
+ locations = l0;
+ numberOfColorsInGradient = 3;
+ }
+ break;
+ case kUIGlossyButtonGradientTypeLinearGlossyStandard:
+ {
+ static const CGFloat g0[] = {0.7, 1.0, 0.6, 1.0, 0.5, 1.0, 0.45, 1.0};
+ static const CGFloat l0[] = {0.0, 0.47, 0.53, 1.0};
+ background_gradient = g0;
+ locations = l0;
+ numberOfColorsInGradient = 4;
+ }
+ break;
+ case kUIGlossyButtonGradientTypeSolid:
+ {
+ // simplify the code, we create a gradient with one color
+ static const CGFloat g0[] = {0.5, 1.0, 0.5, 1.0};
+ background_gradient = g0;
+ locations = nil;
+ numberOfColorsInGradient = 2;
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+- (UIBezierPath *) pathForButton : (CGFloat) inset {
+ CGFloat radius = _buttonCornerRadius - inset;
+ if (radius<0.0) radius = 0.0;
+ CGRect rr = UIEdgeInsetsInsetRect(self.bounds, _buttonInsets);
+ return [UIBezierPath bezierPathWithRoundedRect:CGRectInset(rr, inset, inset) cornerRadius:radius];
+}
+
+- (void)drawRect:(CGRect)rect {
+ UIColor *color = _tintColor;
+ if (![self isEnabled]) {
+ if (_disabledColor) color = _disabledColor;
+ else color = [UIColor lightGrayColor];
+ }
+ if (color==nil) color = [UIColor whiteColor];
+
+ // if the background is transparent, we draw on a image
+ // and copy the image to the context with alpha
+ BOOL drawOnImage = _backgroundOpacity<1.0;
+
+ if (drawOnImage) {
+ RetinaAwareUIGraphicsBeginImageContext(self.bounds.size);
+ }
+
+ CGContextRef ref = UIGraphicsGetCurrentContext();
+
+ BOOL isSelected = [self isHighlighted];
+ CGContextSaveGState(ref);
+ if (_buttonBorderWidth>0.0) {
+ UIColor *color;
+ if ([self isEnabled]) color = _borderColor;
+ else {
+ color = _disabledBorderColor;
+ if (color==nil) color = _borderColor;
+ }
+ if (color == nil) color = [UIColor darkGrayColor];
+ [self strokeButton : ref color : color isSelected: isSelected];
+ }
+ [self drawTintColorButton : ref tintColor : color isSelected: isSelected];
+ CGContextRestoreGState(ref);
+
+ if (drawOnImage) {
+ UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ [i drawAtPoint:CGPointZero blendMode:kCGBlendModeNormal alpha:_backgroundOpacity];
+ }
+
+ [super drawRect: rect];
+}
+
+#pragma mark KVO
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if ([keyPath isEqualToString:@"highlighted"] || [keyPath isEqualToString:@"enabled"]) {
+ [self setNeedsDisplay];
+ }
+}
+
+
+#pragma -
+
+- (void) strokeButton : (CGContextRef)context color : (UIColor *)color isSelected : (BOOL) isSelected {
+ switch (_strokeType) {
+ case kUIGlossyButtonStrokeTypeNone:
+ break;
+ case kUIGlossyButtonStrokeTypeSolid:
+ // simple solid border
+ CGContextAddPath(context, [self pathForButton : 0.0f].CGPath);
+ [color setFill];
+ CGContextFillPath(context);
+ break;
+ case kUIGlossyButtonStrokeTypeGradientFrame:
+ // solid border with gradient outer frame
+ {
+ CGRect rect = self.bounds;
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
+ CGFloat strokeComponents[] = {
+ 0.25f, 1.0f, 1.0f, 1.0f
+ };
+
+ UIBezierPath *outerPath = [self pathForButton : 0.0f];
+ CGContextAddPath(context, outerPath.CGPath);
+ [color setFill];
+ CGContextFillPath(context);
+
+ // stroke the gradient in 1 pixels using overlay so that still keep the stroke color
+ CGContextSaveGState(context);
+ CGContextAddPath(context, outerPath.CGPath);
+ CGContextAddPath(context, [self pathForButton : 1.0f].CGPath);
+ CGContextEOClip(context);
+ CGContextSetBlendMode(context, kCGBlendModeOverlay);
+
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, NULL, 2);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(0, CGRectGetMinY(rect)), CGPointMake(0,CGRectGetMaxY(rect)), 0);
+ CGGradientRelease(strokeGradient);
+ CGColorSpaceRelease(colorSpace);
+
+ CGContextRestoreGState(context);
+ }
+ break;
+ case kUIGlossyButtonStrokeTypeInnerBevelDown:
+ {
+ CGContextSaveGState(context);
+ CGPathRef path = [self pathForButton: 0.0f].CGPath;
+ CGContextAddPath(context, path);
+ CGContextClip(context);
+ [[UIColor colorWithWhite:0.9f alpha:1.0f] setFill];
+ CGContextAddPath(context, path);
+ CGContextFillPath(context);
+
+ CGFloat highlightWidth = _buttonBorderWidth / 4.0f;
+ if (highlightWidth<0.5f) highlightWidth = 0.5f;
+ else if (highlightWidth>2.0f) highlightWidth = 2.0f;
+ CGPathRef innerPath = [self pathForButton: highlightWidth].CGPath;
+ CGContextTranslateCTM(context, 0.0f, -highlightWidth);
+ [color setFill];
+ CGContextAddPath(context, innerPath);
+ CGContextFillPath(context);
+
+ CGContextRestoreGState(context);
+ }
+ break;
+ case kUIGlossyButtonStrokeTypeBevelUp:
+ {
+ CGRect rect = self.bounds;
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
+ const CGFloat *strokeComponents;
+ const CGFloat *l0;
+ if (_invertGraidentOnSelected && isSelected) {
+ const CGFloat s[] = {0.2, 1, 0.5, 1, 0.6, 1};
+ const CGFloat l[] = {0.0, 0.1, 1.0};
+ strokeComponents = s; l0 = l;
+ }
+ else {
+ const CGFloat s[] = {0.9, 1, 0.5, 1, 0.2, 1};
+ const CGFloat l[] = {0.0, 0.1, 1.0};
+ strokeComponents = s; l0 = l;
+ }
+
+ CGContextAddPath(context, [self pathForButton : 0.0f].CGPath);
+ CGContextClip(context);
+
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, l0, 3);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(0, CGRectGetMinY(rect)), CGPointMake(0,CGRectGetMaxY(rect)), 0);
+ CGGradientRelease(strokeGradient);
+ CGColorSpaceRelease(colorSpace);
+
+ [color set];
+ UIRectFillUsingBlendMode(rect, kCGBlendModeOverlay);
+
+ CGContextFillPath(context);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+- (void) addShading : (CGContextRef) context type : (UIGlossyButtonExtraShadingType)type rect : (CGRect) rect colorSpace : (CGColorSpaceRef) colorSpace {
+ switch (type) {
+ case kUIGlossyButtonExtraShadingTypeRounded:
+ {
+
+ CGPathRef shade = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(rect.origin.x, rect.origin.y-_buttonCornerRadius, rect.size.width, _buttonCornerRadius+rect.size.height/2.0) cornerRadius:_buttonCornerRadius].CGPath;
+ CGContextAddPath(context, shade);
+ CGContextClip(context);
+ const CGFloat strokeComponents[4] = {0.80, 1, 0.55, 1};
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, NULL, 2);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(0, CGRectGetMinY(rect)), CGPointMake(0,rect.origin.y + rect.size.height * 0.7), 0);
+ CGGradientRelease(strokeGradient);
+ }
+ break;
+ case kUIGlossyButtonExtraShadingTypeAngleLeft:
+ {
+ CGRect roundRect = CGRectMake(rect.origin.x-rect.size.width * 2, rect.origin.y - rect.size.height * 3.33, rect.size.width*4.0f, rect.size.height*4.0f);
+ CGContextAddEllipseInRect(context, roundRect);
+ CGContextClip(context);
+ const CGFloat strokeComponents[4] = {0.80, 1, 0.55, 1};
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, NULL, 2);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(rect.origin.x, rect.origin.y), CGPointMake(rect.origin.x+rect.size.width / 2.0, rect.origin.y + rect.size.height * 0.7), 0);
+ CGGradientRelease(strokeGradient);
+ }
+ break;
+ case kUIGlossyButtonExtraShadingTypeAngleRight:
+ {
+ CGRect roundRect = CGRectMake(rect.origin.x-rect.size.width, rect.origin.y - rect.size.height * 3.33, rect.size.width*4.0f, rect.size.height*4.0f);
+ CGContextAddEllipseInRect(context, roundRect);
+ CGContextClip(context);
+ const CGFloat strokeComponents[4] = {0.80, 1, 0.55, 1};
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, NULL, 2);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(rect.origin.x+rect.size.width, rect.origin.y), CGPointMake(rect.origin.x+rect.size.width / 2.0, rect.origin.y + rect.size.height * 0.7), 0);
+ CGGradientRelease(strokeGradient);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+- (void) drawTintColorButton : (CGContextRef)context tintColor : (UIColor *) tintColor isSelected : (BOOL) isSelected {
+ CGRect rect = self.bounds;
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
+
+ if (_innerBorderWidth > 0.0) {
+ // STROKE GRADIENT
+ CGContextAddPath(context, [self pathForButton : _buttonBorderWidth].CGPath);
+ CGContextClip(context);
+
+ CGContextSaveGState(context);
+
+ const CGFloat strokeComponents[4] = {0.55, 1, 0.40, 1};
+ CGGradientRef strokeGradient = CGGradientCreateWithColorComponents(colorSpace, strokeComponents, NULL, 2);
+ CGContextDrawLinearGradient(context, strokeGradient, CGPointMake(0, CGRectGetMinY(rect)), CGPointMake(0,CGRectGetMaxY(rect)), 0);
+ CGGradientRelease(strokeGradient);
+ }
+
+ // FILL GRADIENT
+ CGRect fillRect = CGRectInset(rect,_buttonBorderWidth + _innerBorderWidth, _buttonBorderWidth + _innerBorderWidth);
+ CGContextAddPath(context, [self pathForButton : _buttonBorderWidth + _innerBorderWidth].CGPath);
+ CGContextClip(context);
+
+ CGGradientRef fillGradient = CGGradientCreateWithColorComponents(colorSpace, background_gradient, locations, numberOfColorsInGradient);
+ if (_invertGraidentOnSelected && isSelected) {
+ CGContextDrawLinearGradient(context, fillGradient, CGPointMake(0, CGRectGetMaxY(fillRect)), CGPointMake(0,CGRectGetMinY(fillRect)), 0);
+ }
+ else {
+ CGContextDrawLinearGradient(context, fillGradient, CGPointMake(0, CGRectGetMinY(fillRect)), CGPointMake(0,CGRectGetMaxY(fillRect)), 0);
+ }
+ CGGradientRelease(fillGradient);
+
+ if (_extraShadingType != kUIGlossyButtonExtraShadingTypeNone) {
+ // add additional glossy effect
+ CGContextSaveGState(context);
+ CGContextSetBlendMode(context, kCGBlendModeLighten);
+ [self addShading:context type:_extraShadingType rect:fillRect colorSpace:colorSpace];
+ CGContextRestoreGState(context);
+ }
+
+ CGColorSpaceRelease(colorSpace);
+
+ if (_innerBorderWidth > 0.0) {
+ CGContextRestoreGState(context);
+ }
+
+ [tintColor set];
+ UIRectFillUsingBlendMode(rect, kCGBlendModeOverlay);
+
+ if (isSelected) {
+ [[UIColor lightGrayColor] set];
+ UIRectFillUsingBlendMode(rect, kCGBlendModeMultiply);
+ }
+}
+
+#pragma pre-defined buttons
+
+- (void) setActionSheetButtonWithColor : (UIColor*) color {
+ self.tintColor = color;
+ [self setGradientType:kUIGlossyButtonGradientTypeLinearGlossyStandard];
+ [self.titleLabel setFont: [UIFont boldSystemFontOfSize: 17.0f]];
+ [self useWhiteLabel: NO];
+ self.buttonCornerRadius = 8.0f;
+ self.strokeType = kUIGlossyButtonStrokeTypeGradientFrame;
+ self.buttonBorderWidth = 3.0;
+ self.borderColor = [UIColor colorWithWhite:0.2f alpha:0.8f];
+ [self setNeedsDisplay];
+}
+
+- (void) setNavigationButtonWithColor : (UIColor*) color {
+ self.tintColor = color;
+ self.disabledBorderColor = [UIColor lightGrayColor];
+ [self setGradientType:kUIGlossyButtonGradientTypeLinearGlossyStandard];
+ [self.titleLabel setFont: [UIFont boldSystemFontOfSize: 12.0f]];
+ [self useWhiteLabel: NO];
+ [self setTitleColor:[UIColor colorWithWhite:0.5 alpha:1.0] forState:UIControlStateDisabled];
+ self.buttonCornerRadius = 4.0f;
+ self.strokeType = kUIGlossyButtonStrokeTypeInnerBevelDown;
+ self.buttonBorderWidth = 1.0;
+ self.innerBorderWidth = 0.0;
+ [self setNeedsDisplay];
+}
+
+@end
+
+
+
+
+
+@implementation UIGNavigationButton
+
+@synthesize leftArrow = _leftArrow;
+
+- (UIBezierPath *) pathForButton : (CGFloat) inset {
+ CGRect bounds = UIEdgeInsetsInsetRect(self.bounds, _buttonInsets);
+ CGRect rr = CGRectInset(bounds, inset, inset);
+ CGFloat radius = _buttonCornerRadius - inset;
+ if (radius<0.0) radius = 0.0;
+ CGFloat arrowWidth = round(bounds.size.height * 0.30);
+ CGFloat radiusOffset = 0.29289321 * radius;
+ CGFloat extraHeadInset = 0.01118742 * inset;
+ if (_leftArrow) {
+ CGRect rr1 = CGRectMake(arrowWidth+rr.origin.x+extraHeadInset, rr.origin.y, rr.size.width-arrowWidth-extraHeadInset, rr.size.height);
+ UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rr1 cornerRadius:radius];
+ [path moveToPoint: CGPointMake(rr.origin.x+extraHeadInset, rr.origin.y + rr.size.height / 2.0)];
+ [path addLineToPoint:CGPointMake(rr.origin.x+arrowWidth+radiusOffset+extraHeadInset, rr.origin.y+radiusOffset)];
+ [path addLineToPoint:CGPointMake(rr.origin.x+arrowWidth+radiusOffset+extraHeadInset, rr.origin.y+rr.size.height-radiusOffset)];
+ [path closePath];
+ return path;
+ }
+ else {
+ CGRect rr1 = CGRectMake(rr.origin.x, rr.origin.y, rr.size.width-arrowWidth-extraHeadInset, rr.size.height);
+ UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rr1 cornerRadius:radius];
+ [path moveToPoint: CGPointMake(rr.origin.x + rr.size.width - extraHeadInset, rr.origin.y + rr.size.height / 2.0)];
+ [path addLineToPoint:CGPointMake(rr.origin.x+ rr.size.width - arrowWidth - radiusOffset - extraHeadInset, rr.origin.y+rr.size.height-radiusOffset)];
+ [path addLineToPoint:CGPointMake(rr.origin.x+ rr.size.width - arrowWidth - radiusOffset - extraHeadInset, rr.origin.y+radiusOffset)];
+ [path closePath];
+ return path;
+ }
+}
+
+- (CGRect)titleRectForContentRect:(CGRect)contentRect {
+ CGFloat arrowWidth = round(self.bounds.size.height * 0.30);
+ if (_leftArrow) {
+ contentRect.origin.x += arrowWidth; contentRect.size.width -= arrowWidth;
+ }
+ else {
+ contentRect.size.width -= arrowWidth;
+ }
+ return [super titleRectForContentRect: contentRect];
+}
+
+@end
+
+@implementation UIGBadgeButton
+
+@synthesize numberOfEdges;
+@synthesize innerRadiusRatio;
+
+- (void) setupSelf {
+ [super setupSelf];
+ numberOfEdges = 24;
+ innerRadiusRatio = 0.75;
+}
+
+- (UIBezierPath *) pathForButton : (CGFloat) inset {
+ CGRect bounds = UIEdgeInsetsInsetRect(self.bounds, _buttonInsets);
+ CGPoint center = CGPointMake(bounds.size.width/2.0, bounds.size.height/2.0);
+ CGFloat outerRadius = MIN(bounds.size.width, bounds.size.height) / 2.0 - inset;
+ CGFloat innerRadius = outerRadius * innerRadiusRatio;
+ CGFloat angle = M_PI * 2.0 / (numberOfEdges * 2);
+ UIBezierPath *path = [UIBezierPath bezierPath];
+ for (NSInteger cc=0; cc
+
+@interface UIImage (Blur)
+-(UIImage *)boxblurImageWithBlur:(CGFloat)blur;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/UIImage+Blur.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIImage+Blur.m"
new file mode 100644
index 00000000..b4c6ab3e
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIImage+Blur.m"
@@ -0,0 +1,101 @@
+//
+// UIImage+Blur.m
+// ASDepthModal
+//
+// Created by Shady A. Elyaski on 3/20/13.
+// Copyright (c) 2013 Mash ltd. All rights reserved.
+// Code used from https://github.com/rnystrom/RNBlurModalView
+//
+
+#import "UIImage+Blur.h"
+#import
+#import
+
+@implementation UIImage (Blur)
+
+-(UIImage *)boxblurImageWithBlur:(CGFloat)blur {
+ if (blur < 0.f || blur > 1.f) {
+ blur = 0.5f;
+ }
+ int boxSize = (int)(blur * 40);
+ boxSize = boxSize - (boxSize % 2) + 1;
+
+ CGImageRef img = self.CGImage;
+
+ vImage_Buffer inBuffer, outBuffer;
+
+ vImage_Error error;
+
+ void *pixelBuffer;
+
+
+ //create vImage_Buffer with data from CGImageRef
+
+ CGDataProviderRef inProvider = CGImageGetDataProvider(img);
+ CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
+
+
+ inBuffer.width = CGImageGetWidth(img);
+ inBuffer.height = CGImageGetHeight(img);
+ inBuffer.rowBytes = CGImageGetBytesPerRow(img);
+
+ inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
+
+ //create vImage_Buffer for output
+
+ pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
+
+ if(pixelBuffer == NULL)
+ NSLog(@"No pixelbuffer");
+
+ outBuffer.data = pixelBuffer;
+ outBuffer.width = CGImageGetWidth(img);
+ outBuffer.height = CGImageGetHeight(img);
+ outBuffer.rowBytes = CGImageGetBytesPerRow(img);
+
+ // Create a third buffer for intermediate processing
+ void *pixelBuffer2 = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
+ vImage_Buffer outBuffer2;
+ outBuffer2.data = pixelBuffer2;
+ outBuffer2.width = CGImageGetWidth(img);
+ outBuffer2.height = CGImageGetHeight(img);
+ outBuffer2.rowBytes = CGImageGetBytesPerRow(img);
+
+ //perform convolution
+ error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer2, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
+ if (error) {
+ NSLog(@"error from convolution %ld", error);
+ }
+ error = vImageBoxConvolve_ARGB8888(&outBuffer2, &inBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
+ if (error) {
+ NSLog(@"error from convolution %ld", error);
+ }
+ error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
+ if (error) {
+ NSLog(@"error from convolution %ld", error);
+ }
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef ctx = CGBitmapContextCreate(outBuffer.data,
+ outBuffer.width,
+ outBuffer.height,
+ 8,
+ outBuffer.rowBytes,
+ colorSpace,
+ kCGImageAlphaNoneSkipLast);
+ CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
+ UIImage *returnImage = [UIImage imageWithCGImage:imageRef];
+
+ //clean up
+ CGContextRelease(ctx);
+ CGColorSpaceRelease(colorSpace);
+
+ free(pixelBuffer);
+ CFRelease(inBitmapData);
+
+ CGImageRelease(imageRef);
+
+ return returnImage;
+}
+
+@end
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.h"
new file mode 100644
index 00000000..c3effed3
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.h"
@@ -0,0 +1,22 @@
+//
+// UIView+ExtraAnimation.h
+//
+// Created by Water Lou on 15/09/2010.
+// Copyright 2010 First Water Tech Ltd. All rights reserved.
+//
+// many visual effects and animation effects create using CoreAnimation and CALayer
+//
+
+#import
+
+@interface UIView(LayerEffects)
+
+// set round corner
+- (void) setCornerRadius : (CGFloat) radius;
+// set inner border
+- (void) setBorder : (UIColor *) color width : (CGFloat) width;
+// set the shadow
+// Example: [view setShadow:[UIColor blackColor] opacity:0.5 offset:CGSizeMake(1.0, 1.0) blueRadius:3.0];
+- (void) setShadow : (UIColor *)color opacity:(CGFloat)opacity offset:(CGSize) offset blurRadius:(CGFloat)blurRadius;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.m"
new file mode 100644
index 00000000..b884518a
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/UIView+LayerEffects.m"
@@ -0,0 +1,32 @@
+//
+// UIView+LayerEffects.m
+//
+// Created by Water Lou on 15/09/2010.
+// Copyright 2010 First Water Tech Ltd. All rights reserved.
+//
+
+#import
+#import "UIView+LayerEffects.h"
+
+@implementation UIView(LayerEffects)
+
+/* simple setting using the layer */
+- (void) setCornerRadius : (CGFloat) radius {
+ self.layer.cornerRadius = radius;
+}
+
+- (void) setBorder : (UIColor *) color width : (CGFloat) width {
+ self.layer.borderColor = [color CGColor];
+ self.layer.borderWidth = width;
+}
+
+- (void) setShadow : (UIColor *)color opacity:(CGFloat)opacity offset:(CGSize)offset blurRadius:(CGFloat)blurRadius {
+ CALayer *l = self.layer;
+ l.shadowColor = [color CGColor];
+ l.shadowOpacity = opacity;
+ l.shadowOffset = offset;
+ l.shadowRadius = blurRadius;
+}
+
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.h"
new file mode 100644
index 00000000..f9cac17e
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.h"
@@ -0,0 +1,17 @@
+//
+// ViewController.h
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface ViewController : UIViewController
+- (IBAction)bill:(id)sender;
+@property (strong, nonatomic) IBOutlet UIImageView *myImage;
+@property (strong, nonatomic) IBOutlet UITableView *tableOutlet;
+
+@property (strong,nonatomic) NSArray*list;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.m"
new file mode 100644
index 00000000..fa1e6279
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ViewController.m"
@@ -0,0 +1,214 @@
+//
+// ViewController.m
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "ViewController.h"
+#import "settingViewController.h"
+#import "displayViewController.h"
+#import "billViewController.h"
+#import
+#import "UIGlossyButton.h"
+#import "UIView+LayerEffects.h"
+#import "billManagement.h"
+#import "settingManagement.h"
+#import "payout.h"
+@interface ViewController ()
+@property(strong,nonatomic)FMDatabase*Fdb;
+@property(strong,nonatomic)billManagement*billM;
+@property(strong,nonatomic)NSArray*BillArray;
+
+@end
+
+@implementation ViewController
+@synthesize myImage;
+@synthesize tableOutlet;
+
+@synthesize list,Fdb;
+@synthesize billM;
+@synthesize BillArray;
+
+- (void)viewDidLoad
+{
+
+ [super viewDidLoad];
+
+ billM=[[billManagement alloc]init];
+ self.tableOutlet.separatorStyle=UITableViewCellSeparatorStyleNone;
+ self.navigationItem.hidesBackButton=YES;
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+
+
+
+//-----------------自定义记一笔button-------------------------
+// UIGlossyButton *b;
+// b = (UIGlossyButton*) [self.view viewWithTag: 1018];
+// [b useWhiteLabel: YES]; b.tintColor = [UIColor whiteColor];
+// [b setShadow:[UIColor blackColor] opacity:0.8 offset:CGSizeMake(0, 1) blurRadius: 4];
+// [b setGradientType:kUIGlossyButtonGradientTypeLinearSmoothExtreme];
+//-------------------自定义记一笔button------------------------
+// self.navigationController.navigationBar.barStyle=UIBarStyleBlackOpaque;
+
+
+ UISwipeGestureRecognizer *recognizer;
+
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
+
+ [[self view] addGestureRecognizer:recognizer];
+
+
+
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
+
+ [[self view] addGestureRecognizer:recognizer];
+
+
+
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
+
+ [[self view] addGestureRecognizer:recognizer];
+
+
+
+
+ //UISwipeGestureRecognizer *recognizer;
+
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
+
+ [[self view] addGestureRecognizer:recognizer];
+
+
+ // Do any additional setup after loading the view, typically from a nib.
+}
+-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
+ UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+
+
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
+
+ displayViewController*svc=[storyboard instantiateViewControllerWithIdentifier:@"display"];
+ [self.navigationController pushViewController:svc animated:YES];
+ NSLog(@"swipe left");
+
+ }
+
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
+ settingViewController*svc=[storyboard instantiateViewControllerWithIdentifier:@"setting"];
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.3;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromLeft;
+
+ [self.navigationController.view setBackgroundColor:[UIColor colorWithRed:0.0 green:156.0/255 blue:181.0/255 alpha:1]];
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+
+ [self.navigationController pushViewController:svc animated:NO];
+ NSLog(@"swipe right");
+
+ //执行程序
+
+ }
+
+}
+- (void)viewDidUnload
+{
+ [self setMyImage:nil];
+
+ [self setTableOutlet:nil];
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
+}
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ //#warning Potentially incomplete method implementation.
+ // Return the number of sections.
+ return 1;
+}
+-(void)viewWillAppear:(BOOL)animated{
+ self.BillArray=[self.billM getRecentlyPayouDate];
+ [self.tableOutlet reloadData];
+
+
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ //#warning Incomplete method implementation.
+ // Return the number of rows in the section.
+ return [BillArray count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+
+ static NSString *CellIdentifier = @"Cell";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+
+ payout* _payout=[BillArray objectAtIndex:indexPath.row];
+ NSLog(@"%d",_payout.payout_ID);
+// NSLog(@"%d---%@",indexPath.row,_payout.type);
+ UILabel*label=(UILabel*)[cell viewWithTag:1];
+ label.text=[NSString stringWithFormat:@"%.2f",_payout.amount];
+ label=(UILabel*)[cell viewWithTag:2];
+ label.text=_payout.date;
+ label=(UILabel*)[cell viewWithTag:3];
+ label.text=_payout.type;
+ label=(UILabel*)[cell viewWithTag:4];
+ label.text=_payout.personnel;
+ return cell;
+}
+
+-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
+
+ payout* _payout=[BillArray objectAtIndex:indexPath.row];
+ NSLog(@"payout_id %d",_payout.payout_ID);
+
+ UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ billViewController*svc=[storyboard instantiateViewControllerWithIdentifier:@"bill"];
+ svc.billIndex=_payout.payout_ID;
+ svc.backTypeNSString=@"View";
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.5;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromTop;
+
+ [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+ [self.navigationController pushViewController:svc animated:NO];
+}
+
+- (IBAction)bill:(id)sender {
+ UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ billViewController*svc=[storyboard instantiateViewControllerWithIdentifier:@"bill"];
+ svc.billIndex=-1;
+ svc.backTypeNSString=@"View";
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.5;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromTop;
+
+ [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+ [self.navigationController pushViewController:svc animated:NO];
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.h"
new file mode 100644
index 00000000..0300ecb2
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.h"
@@ -0,0 +1,71 @@
+//
+// XYPieChart.h
+// XYPieChart
+//
+// Created by XY Feng on 2/24/12.
+// Copyright (c) 2012 Xiaoyang Feng. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import
+
+@class XYPieChart;
+@protocol XYPieChartDataSource
+@required
+- (NSUInteger)numberOfSlicesInPieChart:(XYPieChart *)pieChart;
+- (CGFloat)pieChart:(XYPieChart *)pieChart valueForSliceAtIndex:(NSUInteger)index;
+@optional
+- (UIColor *)pieChart:(XYPieChart *)pieChart colorForSliceAtIndex:(NSUInteger)index;
+- (NSString *)pieChart:(XYPieChart *)pieChart textForSliceAtIndex:(NSUInteger)index;
+@end
+
+@protocol XYPieChartDelegate
+@optional
+- (void)pieChart:(XYPieChart *)pieChart willSelectSliceAtIndex:(NSUInteger)index;
+- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index;
+- (void)pieChart:(XYPieChart *)pieChart willDeselectSliceAtIndex:(NSUInteger)index;
+- (void)pieChart:(XYPieChart *)pieChart didDeselectSliceAtIndex:(NSUInteger)index;
+@end
+
+@interface XYPieChart : UIView
+@property(nonatomic, weak) id dataSource;
+@property(nonatomic, weak) id delegate;
+@property(nonatomic, assign) CGFloat startPieAngle;
+@property(nonatomic, assign) CGFloat animationSpeed;
+@property(nonatomic, assign) CGPoint pieCenter;
+@property(nonatomic, assign) CGFloat pieRadius;
+@property(nonatomic, assign) BOOL showLabel;
+@property(nonatomic, strong) UIFont *labelFont;
+@property(nonatomic, strong) UIColor *labelColor;
+@property(nonatomic, strong) UIColor *labelShadowColor;
+@property(nonatomic, assign) CGFloat labelRadius;
+@property(nonatomic, assign) CGFloat selectedSliceStroke;
+@property(nonatomic, assign) CGFloat selectedSliceOffsetRadius;
+@property(nonatomic, assign) BOOL showPercentage;
+- (id)initWithFrame:(CGRect)frame Center:(CGPoint)center Radius:(CGFloat)radius;
+- (void)reloadData;
+- (void)setPieBackgroundColor:(UIColor *)color;
+
+- (void)setSliceSelectedAtIndex:(NSInteger)index;
+- (void)setSliceDeselectedAtIndex:(NSInteger)index;
+
+@end;
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.m"
new file mode 100644
index 00000000..57d03f41
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/XYPieChart.m"
@@ -0,0 +1,682 @@
+//
+// XYPieChart.m
+// XYPieChart
+//
+// Created by XY Feng on 2/24/12.
+// Copyright (c) 2012 Xiaoyang Feng. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+
+#import "XYPieChart.h"
+#import
+
+@interface SliceLayer : CAShapeLayer
+@property (nonatomic, assign) CGFloat value;
+@property (nonatomic, assign) CGFloat percentage;//%
+@property (nonatomic, assign) double startAngle;//起点角度
+@property (nonatomic, assign) double endAngle;//终点角度
+@property (nonatomic, assign) BOOL isSelected;//被选中
+@property (nonatomic, strong) NSString *text;
+- (void)createArcAnimationForKey:(NSString *)key fromValue:(NSNumber *)from toValue:(NSNumber *)to Delegate:(id)delegate;
+@end
+
+@implementation SliceLayer
+@synthesize text = _text;
+@synthesize value = _value;
+@synthesize percentage = _percentage;
+@synthesize startAngle = _startAngle;
+@synthesize endAngle = _endAngle;
+@synthesize isSelected = _isSelected;
+- (NSString*)description//描述
+{
+ return [NSString stringWithFormat:@"value:%f, percentage:%0.0f, start:%f, end:%f", _value, _percentage, _startAngle/M_PI*180, _endAngle/M_PI*180];
+}
++ (BOOL)needsDisplayForKey:(NSString *)key
+{
+ if ([key isEqualToString:@"startAngle"] || [key isEqualToString:@"endAngle"]) {
+ return YES;
+ }
+ else {
+ return [super needsDisplayForKey:key];
+ }
+}
+- (id)initWithLayer:(id)layer
+{
+ if (self = [super initWithLayer:layer])
+ {
+ if ([layer isKindOfClass:[SliceLayer class]]) {
+ self.startAngle = [(SliceLayer *)layer startAngle];
+ self.endAngle = [(SliceLayer *)layer endAngle];
+ }
+ }
+ return self;
+}
+- (void)createArcAnimationForKey:(NSString *)key fromValue:(NSNumber *)from toValue:(NSNumber *)to Delegate:(id)delegate
+{
+ CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:key];
+ NSNumber *currentAngle = [[self presentationLayer] valueForKey:key];
+ if(!currentAngle) currentAngle = from;
+ [arcAnimation setFromValue:currentAngle];
+ [arcAnimation setToValue:to];
+ [arcAnimation setDelegate:delegate];
+ [arcAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
+ [self addAnimation:arcAnimation forKey:key];
+ [self setValue:to forKey:key];
+}
+@end
+
+@interface XYPieChart (Private)
+- (void)updateTimerFired:(NSTimer *)timer;
+- (SliceLayer *)createSliceLayer;
+- (CGSize)sizeThatFitsString:(NSString *)string;
+- (void)updateLabelForLayer:(SliceLayer *)pieLayer value:(CGFloat)value;
+- (void)notifyDelegateOfSelectionChangeFrom:(NSUInteger)previousSelection to:(NSUInteger)newSelection;
+@end
+
+@implementation XYPieChart
+{
+ NSInteger _selectedSliceIndex;
+ //pie view, contains all slices
+ UIView *_pieView;
+
+ //animation control
+ NSTimer *_animationTimer;
+ NSMutableArray *_animations;
+}
+
+static NSUInteger kDefaultSliceZOrder = 100;
+
+@synthesize dataSource = _dataSource;
+@synthesize delegate = _delegate;
+@synthesize startPieAngle = _startPieAngle;
+@synthesize animationSpeed = _animationSpeed;
+@synthesize pieCenter = _pieCenter;
+@synthesize pieRadius = _pieRadius;
+@synthesize showLabel = _showLabel;
+@synthesize labelFont = _labelFont;
+@synthesize labelColor = _labelColor;
+@synthesize labelShadowColor = _labelShadowColor;
+@synthesize labelRadius = _labelRadius;
+@synthesize selectedSliceStroke = _selectedSliceStroke;
+@synthesize selectedSliceOffsetRadius = _selectedSliceOffsetRadius;
+@synthesize showPercentage = _showPercentage;
+
+static CGPathRef CGPathCreateArc(CGPoint center, CGFloat radius, CGFloat startAngle, CGFloat endAngle)
+{
+ CGMutablePathRef path = CGPathCreateMutable();
+ CGPathMoveToPoint(path, NULL, center.x, center.y);
+
+ CGPathAddArc(path, NULL, center.x, center.y, radius, startAngle, endAngle, 0);
+ CGPathCloseSubpath(path);
+
+ return path;
+}
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self)
+ {
+ self.backgroundColor = [UIColor clearColor];
+ _pieView = [[UIView alloc] initWithFrame:frame];
+ [_pieView setBackgroundColor:[UIColor clearColor]];
+ [self addSubview:_pieView];
+
+ _selectedSliceIndex = -1;
+ _animations = [[NSMutableArray alloc] init];
+
+ _animationSpeed = 0.5;
+ _startPieAngle = M_PI_2*3;
+ _selectedSliceStroke = 3.0;
+
+ self.pieRadius = MIN(frame.size.width/2, frame.size.height/2) - 10;
+ self.pieCenter = CGPointMake(frame.size.width/2, frame.size.height/2);
+ self.labelFont = [UIFont boldSystemFontOfSize:MAX((int)self.pieRadius/10, 5)];
+ _labelColor = [UIColor whiteColor];
+ _labelRadius = _pieRadius/2;
+ _selectedSliceOffsetRadius = MAX(10, _pieRadius/10);
+
+ _showLabel = YES;
+ _showPercentage = YES;
+ }
+ return self;
+}
+
+- (id)initWithFrame:(CGRect)frame Center:(CGPoint)center Radius:(CGFloat)radius
+{
+ self = [self initWithFrame:frame];
+ if (self)
+ {
+ self.pieCenter = center;
+ self.pieRadius = radius;
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder *)aDecoder
+{
+ self = [super initWithCoder:aDecoder];
+ if(self)
+ {
+ _pieView = [[UIView alloc] initWithFrame:self.bounds];
+ [_pieView setBackgroundColor:[UIColor clearColor]];
+ [self insertSubview:_pieView atIndex:0];
+
+ _selectedSliceIndex = -1;
+ _animations = [[NSMutableArray alloc] init];
+
+ _animationSpeed = 0.5;
+ _startPieAngle = M_PI_2*3;
+ _selectedSliceStroke = 3.0;
+
+ CGRect bounds = [[self layer] bounds];
+ self.pieRadius = MIN(bounds.size.width/2, bounds.size.height/2) - 10;
+ self.pieCenter = CGPointMake(bounds.size.width/2, bounds.size.height/2);
+ self.labelFont = [UIFont boldSystemFontOfSize:MAX((int)self.pieRadius/10, 5)];
+ _labelColor = [UIColor whiteColor];
+ _labelRadius = _pieRadius/2;
+ _selectedSliceOffsetRadius = MAX(10, _pieRadius/10);
+
+ _showLabel = YES;
+ _showPercentage = YES;
+ }
+ return self;
+}
+
+- (void)setPieCenter:(CGPoint)pieCenter
+{
+ [_pieView setCenter:pieCenter];
+ _pieCenter = CGPointMake(_pieView.frame.size.width/2, _pieView.frame.size.height/2);
+}
+
+- (void)setPieRadius:(CGFloat)pieRadius
+{
+ _pieRadius = pieRadius;
+ CGPoint origin = _pieView.frame.origin;
+ CGRect frame = CGRectMake(origin.x+_pieCenter.x-pieRadius, origin.y+_pieCenter.y-pieRadius, pieRadius*2, pieRadius*2);
+ _pieCenter = CGPointMake(frame.size.width/2, frame.size.height/2);
+ [_pieView setFrame:frame];
+ [_pieView.layer setCornerRadius:_pieRadius];
+}
+
+- (void)setPieBackgroundColor:(UIColor *)color
+{
+ [_pieView setBackgroundColor:color];
+}
+
+#pragma mark - manage settings
+
+- (void)setShowPercentage:(BOOL)showPercentage
+{
+ _showPercentage = showPercentage;
+ for(SliceLayer *layer in _pieView.layer.sublayers)
+ {
+ CATextLayer *textLayer = [[layer sublayers] objectAtIndex:0];
+ [textLayer setHidden:!_showLabel];
+ if(!_showLabel) return;
+ NSString *label;
+ if(_showPercentage)
+ label = [NSString stringWithFormat:@"%0.0f", layer.percentage*100];
+ else
+ label = (layer.text)?layer.text:[NSString stringWithFormat:@"%0.0f", layer.value];
+ CGSize size = [label sizeWithFont:self.labelFont];
+
+ if(M_PI*2*_labelRadius*layer.percentage < MAX(size.width,size.height))
+ {
+ [textLayer setString:@""];
+ }
+ else
+ {
+ [textLayer setString:label];
+ [textLayer setBounds:CGRectMake(0, 0, size.width, size.height)];
+ }
+ }
+}
+
+#pragma mark - Pie Reload Data With Animation
+
+- (void)reloadData
+{
+ if (_dataSource)
+ {
+ CALayer *parentLayer = [_pieView layer];
+ NSArray *slicelayers = [parentLayer sublayers];
+
+ _selectedSliceIndex = -1;
+ [slicelayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ SliceLayer *layer = (SliceLayer *)obj;
+ if(layer.isSelected)
+ [self setSliceDeselectedAtIndex:idx];
+ }];
+
+ double startToAngle = 0.0;
+ double endToAngle = startToAngle;
+
+ NSUInteger sliceCount = [_dataSource numberOfSlicesInPieChart:self];
+
+ double sum = 0.0;
+ double values[sliceCount];
+ for (int index = 0; index < sliceCount; index++) {
+ values[index] = [_dataSource pieChart:self valueForSliceAtIndex:index];
+ sum += values[index];
+ }
+
+ double angles[sliceCount];
+ for (int index = 0; index < sliceCount; index++) {
+ double div;
+ if (sum == 0)
+ div = 0;
+ else
+ div = values[index] / sum;
+ angles[index] = M_PI * 2 * div;
+ }
+
+ [CATransaction begin];
+ [CATransaction setAnimationDuration:_animationSpeed];
+
+ [_pieView setUserInteractionEnabled:NO];
+
+ __block NSMutableArray *layersToRemove = nil;
+ [CATransaction setCompletionBlock:^{
+
+ [layersToRemove enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ [obj removeFromSuperlayer];
+ }];
+
+ [layersToRemove removeAllObjects];
+
+ for(SliceLayer *layer in _pieView.layer.sublayers)
+ {
+ [layer setZPosition:kDefaultSliceZOrder];
+ }
+
+ [_pieView setUserInteractionEnabled:YES];
+ }];
+
+ BOOL isOnStart = ([slicelayers count] == 0 && sliceCount);
+ NSInteger diff = sliceCount - [slicelayers count];
+ layersToRemove = [NSMutableArray arrayWithArray:slicelayers];
+
+ BOOL isOnEnd = ([slicelayers count] && (sliceCount == 0 || sum <= 0));
+ if(isOnEnd)
+ {
+ for(SliceLayer *layer in _pieView.layer.sublayers){
+ [self updateLabelForLayer:layer value:0];
+ [layer createArcAnimationForKey:@"startAngle"
+ fromValue:[NSNumber numberWithDouble:_startPieAngle]
+ toValue:[NSNumber numberWithDouble:_startPieAngle]
+ Delegate:self];
+ [layer createArcAnimationForKey:@"endAngle"
+ fromValue:[NSNumber numberWithDouble:_startPieAngle]
+ toValue:[NSNumber numberWithDouble:_startPieAngle]
+ Delegate:self];
+ }
+ [CATransaction commit];
+ return;
+ }
+
+ for(int index = 0; index < sliceCount; index ++)
+ {
+ SliceLayer *layer;
+ double angle = angles[index];
+ endToAngle += angle;
+ double startFromAngle = _startPieAngle + startToAngle;
+ double endFromAngle = _startPieAngle + endToAngle;
+
+ if( index >= [slicelayers count] )
+ {
+ layer = [self createSliceLayer];
+ if (isOnStart)
+ startFromAngle = endFromAngle = _startPieAngle;
+ [parentLayer addSublayer:layer];
+ diff--;
+ }
+ else
+ {
+ SliceLayer *onelayer = [slicelayers objectAtIndex:index];
+ if(diff == 0 || onelayer.value == (CGFloat)values[index])
+ {
+ layer = onelayer;
+ [layersToRemove removeObject:layer];
+ }
+ else if(diff > 0)
+ {
+ layer = [self createSliceLayer];
+ [parentLayer insertSublayer:layer atIndex:index];
+ diff--;
+ }
+ else if(diff < 0)
+ {
+ while(diff < 0)
+ {
+ [onelayer removeFromSuperlayer];
+ [parentLayer addSublayer:onelayer];
+ diff++;
+ onelayer = [slicelayers objectAtIndex:index];
+ if(onelayer.value == (CGFloat)values[index] || diff == 0)
+ {
+ layer = onelayer;
+ [layersToRemove removeObject:layer];
+ break;
+ }
+ }
+ }
+ }
+
+ layer.value = values[index];
+ layer.percentage = (sum)?layer.value/sum:0;
+ UIColor *color = nil;
+ if([_dataSource respondsToSelector:@selector(pieChart:colorForSliceAtIndex:)])
+ {
+ color = [_dataSource pieChart:self colorForSliceAtIndex:index];
+ }
+
+ if(!color)
+ {
+ color = [UIColor colorWithHue:((index/8)%20)/20.0+0.02 saturation:(index%8+3)/10.0 brightness:91/100.0 alpha:1];
+ }
+
+ [layer setFillColor:color.CGColor];
+ if([_dataSource respondsToSelector:@selector(pieChart:textForSliceAtIndex:)])
+ {
+ layer.text = [_dataSource pieChart:self textForSliceAtIndex:index];
+ }
+
+ [self updateLabelForLayer:layer value:values[index]];
+ [layer createArcAnimationForKey:@"startAngle"
+ fromValue:[NSNumber numberWithDouble:startFromAngle]
+ toValue:[NSNumber numberWithDouble:startToAngle+_startPieAngle]
+ Delegate:self];
+ [layer createArcAnimationForKey:@"endAngle"
+ fromValue:[NSNumber numberWithDouble:endFromAngle]
+ toValue:[NSNumber numberWithDouble:endToAngle+_startPieAngle]
+ Delegate:self];
+ startToAngle = endToAngle;
+ }
+ [CATransaction setDisableActions:YES];
+ for(SliceLayer *layer in layersToRemove)
+ {
+ [layer setFillColor:[self backgroundColor].CGColor];
+ [layer setDelegate:nil];
+ [layer setZPosition:0];
+ CATextLayer *textLayer = [[layer sublayers] objectAtIndex:0];
+ [textLayer setHidden:YES];
+ }
+ [CATransaction setDisableActions:NO];
+ [CATransaction commit];
+ }
+}
+
+#pragma mark - Animation Delegate + Run Loop Timer
+
+- (void)updateTimerFired:(NSTimer *)timer;
+{
+ CALayer *parentLayer = [_pieView layer];
+ NSArray *pieLayers = [parentLayer sublayers];
+
+ [pieLayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+
+ NSNumber *presentationLayerStartAngle = [[obj presentationLayer] valueForKey:@"startAngle"];
+ CGFloat interpolatedStartAngle = [presentationLayerStartAngle doubleValue];
+
+ NSNumber *presentationLayerEndAngle = [[obj presentationLayer] valueForKey:@"endAngle"];
+ CGFloat interpolatedEndAngle = [presentationLayerEndAngle doubleValue];
+
+ CGPathRef path = CGPathCreateArc(_pieCenter, _pieRadius, interpolatedStartAngle, interpolatedEndAngle);
+ [obj setPath:path];
+ CFRelease(path);
+
+ {
+ CALayer *labelLayer = [[obj sublayers] objectAtIndex:0];
+ CGFloat interpolatedMidAngle = (interpolatedEndAngle + interpolatedStartAngle) / 2;
+ [CATransaction setDisableActions:YES];
+ [labelLayer setPosition:CGPointMake(_pieCenter.x + (_labelRadius * cos(interpolatedMidAngle)), _pieCenter.y + (_labelRadius * sin(interpolatedMidAngle)))];
+ [CATransaction setDisableActions:NO];
+ }
+ }];
+}
+
+- (void)animationDidStart:(CAAnimation *)anim
+{
+ if (_animationTimer == nil) {
+ static float timeInterval = 1.0/60.0;
+ // Run the animation timer on the main thread.
+ // We want to allow the user to interact with the UI while this timer is running.
+ // If we run it on this thread, the timer will be halted while the user is touching the screen (that's why the chart was disappearing in our collection view).
+ _animationTimer= [NSTimer timerWithTimeInterval:timeInterval target:self selector:@selector(updateTimerFired:) userInfo:nil repeats:YES];
+ [[NSRunLoop mainRunLoop] addTimer:_animationTimer forMode:NSRunLoopCommonModes];
+ }
+
+ [_animations addObject:anim];
+}
+
+- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)animationCompleted
+{
+ [_animations removeObject:anim];
+
+ if ([_animations count] == 0) {
+ [_animationTimer invalidate];
+ _animationTimer = nil;
+ }
+}
+
+#pragma mark - Touch Handing (Selection Notification)
+
+- (NSInteger)getCurrentSelectedOnTouch:(CGPoint)point
+{
+ __block NSUInteger selectedIndex = -1;
+
+ CGAffineTransform transform = CGAffineTransformIdentity;
+
+ CALayer *parentLayer = [_pieView layer];
+ NSArray *pieLayers = [parentLayer sublayers];
+
+ [pieLayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ SliceLayer *pieLayer = (SliceLayer *)obj;
+ CGPathRef path = [pieLayer path];
+
+ if (CGPathContainsPoint(path, &transform, point, 0)) {
+ [pieLayer setLineWidth:_selectedSliceStroke];
+ [pieLayer setStrokeColor:[UIColor whiteColor].CGColor];
+ [pieLayer setLineJoin:kCALineJoinBevel];
+ [pieLayer setZPosition:MAXFLOAT];
+ selectedIndex = idx;
+ } else {
+ [pieLayer setZPosition:kDefaultSliceZOrder];
+ [pieLayer setLineWidth:0.0];
+ }
+ }];
+ return selectedIndex;
+}
+
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self touchesMoved:touches withEvent:event];
+}
+
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ UITouch *touch = [touches anyObject];
+ CGPoint point = [touch locationInView:_pieView];
+ [self getCurrentSelectedOnTouch:point];
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ UITouch *touch = [touches anyObject];
+ CGPoint point = [touch locationInView:_pieView];
+ NSInteger selectedIndex = [self getCurrentSelectedOnTouch:point];
+ [self notifyDelegateOfSelectionChangeFrom:_selectedSliceIndex to:selectedIndex];
+ [self touchesCancelled:touches withEvent:event];
+}
+
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ CALayer *parentLayer = [_pieView layer];
+ NSArray *pieLayers = [parentLayer sublayers];
+
+ for (SliceLayer *pieLayer in pieLayers) {
+ [pieLayer setZPosition:kDefaultSliceZOrder];
+ [pieLayer setLineWidth:0.0];
+ }
+}
+
+#pragma mark - Selection Notification
+
+- (void)notifyDelegateOfSelectionChangeFrom:(NSUInteger)previousSelection to:(NSUInteger)newSelection
+{
+ if (previousSelection != newSelection)
+ {
+ if (previousSelection != -1 && [_delegate respondsToSelector:@selector(pieChart:willDeselectSliceAtIndex:)])
+ {
+ [_delegate pieChart:self willDeselectSliceAtIndex:previousSelection];
+ }
+
+ _selectedSliceIndex = newSelection;
+
+ if (newSelection != -1)
+ {
+ if([_delegate respondsToSelector:@selector(pieChart:willSelectSliceAtIndex:)])
+ [_delegate pieChart:self willSelectSliceAtIndex:newSelection];
+ if(previousSelection != -1 && [_delegate respondsToSelector:@selector(pieChart:didDeselectSliceAtIndex:)])
+ [_delegate pieChart:self didDeselectSliceAtIndex:previousSelection];
+ if([_delegate respondsToSelector:@selector(pieChart:didSelectSliceAtIndex:)])
+ [_delegate pieChart:self didSelectSliceAtIndex:newSelection];
+ [self setSliceSelectedAtIndex:newSelection];
+ }
+
+ if(previousSelection != -1)
+ {
+ [self setSliceDeselectedAtIndex:previousSelection];
+ if([_delegate respondsToSelector:@selector(pieChart:didDeselectSliceAtIndex:)])
+ [_delegate pieChart:self didDeselectSliceAtIndex:previousSelection];
+ }
+ }
+ else if (newSelection != -1)
+ {
+ SliceLayer *layer = [_pieView.layer.sublayers objectAtIndex:newSelection];
+ if(_selectedSliceOffsetRadius > 0 && layer){
+
+ if (layer.isSelected) {
+ if ([_delegate respondsToSelector:@selector(pieChart:willDeselectSliceAtIndex:)])
+ [_delegate pieChart:self willDeselectSliceAtIndex:newSelection];
+ [self setSliceDeselectedAtIndex:newSelection];
+ if (newSelection != -1 && [_delegate respondsToSelector:@selector(pieChart:didDeselectSliceAtIndex:)])
+ [_delegate pieChart:self didDeselectSliceAtIndex:newSelection];
+ }
+ else {
+ if ([_delegate respondsToSelector:@selector(pieChart:willSelectSliceAtIndex:)])
+ [_delegate pieChart:self willSelectSliceAtIndex:newSelection];
+ [self setSliceSelectedAtIndex:newSelection];
+ if (newSelection != -1 && [_delegate respondsToSelector:@selector(pieChart:didSelectSliceAtIndex:)])
+ [_delegate pieChart:self didSelectSliceAtIndex:newSelection];
+ }
+ }
+ }
+}
+
+#pragma mark - Selection Programmatically Without Notification
+
+- (void)setSliceSelectedAtIndex:(NSInteger)index
+{
+ if(_selectedSliceOffsetRadius <= 0)
+ return;
+ SliceLayer *layer = [_pieView.layer.sublayers objectAtIndex:index];
+ if (layer && !layer.isSelected) {
+ CGPoint currPos = layer.position;
+ double middleAngle = (layer.startAngle + layer.endAngle)/2.0;
+ CGPoint newPos = CGPointMake(currPos.x + _selectedSliceOffsetRadius*cos(middleAngle), currPos.y + _selectedSliceOffsetRadius*sin(middleAngle));
+ layer.position = newPos;
+ layer.isSelected = YES;
+ }
+}
+
+- (void)setSliceDeselectedAtIndex:(NSInteger)index
+{
+ if(_selectedSliceOffsetRadius <= 0)
+ return;
+ SliceLayer *layer = [_pieView.layer.sublayers objectAtIndex:index];
+ if (layer && layer.isSelected) {
+ layer.position = CGPointMake(0, 0);
+ layer.isSelected = NO;
+ }
+}
+
+#pragma mark - Pie Layer Creation Method
+
+- (SliceLayer *)createSliceLayer
+{
+ SliceLayer *pieLayer = [SliceLayer layer];
+ [pieLayer setZPosition:0];
+ [pieLayer setStrokeColor:NULL];
+ CATextLayer *textLayer = [CATextLayer layer];
+ textLayer.contentsScale = [[UIScreen mainScreen] scale];
+ CGFontRef font = CGFontCreateWithFontName((__bridge CFStringRef)[self.labelFont fontName]);
+ [textLayer setFont:font];
+ CFRelease(font);
+ [textLayer setFontSize:self.labelFont.pointSize];
+ [textLayer setAnchorPoint:CGPointMake(0.5, 0.5)];
+ [textLayer setAlignmentMode:kCAAlignmentCenter];
+ [textLayer setBackgroundColor:[UIColor clearColor].CGColor];
+ [textLayer setForegroundColor:self.labelColor.CGColor];
+ if (self.labelShadowColor) {
+ [textLayer setShadowColor:self.labelShadowColor.CGColor];
+ [textLayer setShadowOffset:CGSizeZero];
+ [textLayer setShadowOpacity:1.0f];
+ [textLayer setShadowRadius:2.0f];
+ }
+ CGSize size = [@"0" sizeWithFont:self.labelFont];
+ [CATransaction setDisableActions:YES];
+ [textLayer setFrame:CGRectMake(0, 0, size.width, size.height)];
+ [textLayer setPosition:CGPointMake(_pieCenter.x + (_labelRadius * cos(0)), _pieCenter.y + (_labelRadius * sin(0)))];
+ [CATransaction setDisableActions:NO];
+ [pieLayer addSublayer:textLayer];
+ return pieLayer;
+}
+
+- (void)updateLabelForLayer:(SliceLayer *)pieLayer value:(CGFloat)value
+{
+ CATextLayer *textLayer = [[pieLayer sublayers] objectAtIndex:0];
+ [textLayer setHidden:!_showLabel];
+ if(!_showLabel) return;
+ NSString *label;
+ if(_showPercentage)
+ label = [NSString stringWithFormat:@"%0.0f", pieLayer.percentage*100];
+ else
+ label = (pieLayer.text)?pieLayer.text:[NSString stringWithFormat:@"%0.0f", value];
+
+ CGSize size = [label sizeWithFont:self.labelFont];
+
+ [CATransaction setDisableActions:YES];
+ if(M_PI*2*_labelRadius*pieLayer.percentage < MAX(size.width,size.height) || value <= 0)
+ {
+ [textLayer setString:@""];
+ }
+ else
+ {
+ [textLayer setString:label];
+ [textLayer setBounds:CGRectMake(0, 0, size.width, size.height)];
+ }
+ [CATransaction setDisableActions:NO];
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.h"
new file mode 100644
index 00000000..e8edb8ef
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.h"
@@ -0,0 +1,25 @@
+//
+// ZenKeyboard.h
+// ZenKeyboard
+//
+// Created by Kevin Nick on 2012-11-9.
+// Copyright (c) 2012年 com.zen. All rights reserved.
+//
+
+#import
+
+#define KEYBOARD_NUMERIC_KEY_WIDTH 108
+#define KEYBOARD_NUMERIC_KEY_HEIGHT 53
+
+@protocol ZenKeyboardDelegate
+
+- (void)numericKeyDidPressed:(int)key;
+- (void)backspaceKeyDidPressed;
+
+@end
+
+@interface ZenKeyboard : UIView
+
+@property (nonatomic, assign) UITextField *textField;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.m"
new file mode 100644
index 00000000..cabbd4dc
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/ZenKeyboard.m"
@@ -0,0 +1,161 @@
+//
+// ZenKeyboard.m
+// ZenKeyboard
+//
+// Created by Kevin Nick on 2012-11-9.
+// Copyright (c) 2012年 com.zen. All rights reserved.
+//
+
+#import "ZenKeyboard.h"
+#import "Config.h"
+@interface ZenKeyboard()
+
+@property (nonatomic,assign) id textInputDelegate;
+
+@end;
+
+@implementation ZenKeyboard
+@synthesize textField=_textField;
+@synthesize textInputDelegate;
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ UIImageView *keyboardBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"KeyboardBackgroundTextured"]];
+ UIImageView *keyboardGridLines = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"KeyboardNumericEntryViewGridLinesTextured"]];
+ UIImageView *keyboardShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"KeyboardTopShadow"]];
+
+ [self addSubview:keyboardBackground];
+ [self addSubview:keyboardGridLines];
+ [self addSubview:[self addNumericKeyWithTitle:@"1" frame:CGRectMake(0, 1, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"2" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH - 2, 1, KEYBOARD_NUMERIC_KEY_WIDTH, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"3" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH * 2 - 1, 1, KEYBOARD_NUMERIC_KEY_WIDTH - 2, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+
+ [self addSubview:[self addNumericKeyWithTitle:@"4" frame:CGRectMake(0, KEYBOARD_NUMERIC_KEY_HEIGHT + 2, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"5" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH - 2, KEYBOARD_NUMERIC_KEY_HEIGHT + 2, KEYBOARD_NUMERIC_KEY_WIDTH, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"6" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH * 2 - 1, KEYBOARD_NUMERIC_KEY_HEIGHT + 2, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+
+ [self addSubview:[self addNumericKeyWithTitle:@"7" frame:CGRectMake(0, KEYBOARD_NUMERIC_KEY_HEIGHT * 2 + 3, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"8" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH - 2, KEYBOARD_NUMERIC_KEY_HEIGHT * 2 + 3, KEYBOARD_NUMERIC_KEY_WIDTH , KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"9" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH * 2 - 1, KEYBOARD_NUMERIC_KEY_HEIGHT * 2 + 3, KEYBOARD_NUMERIC_KEY_WIDTH, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+
+ [self addSubview:[self addNumericKeyWithTitle:@"." frame:CGRectMake(0, KEYBOARD_NUMERIC_KEY_HEIGHT * 3 + 4, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addNumericKeyWithTitle:@"0" frame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH - 2, KEYBOARD_NUMERIC_KEY_HEIGHT * 3 + 4, KEYBOARD_NUMERIC_KEY_WIDTH, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+ [self addSubview:[self addBackspaceKeyWithFrame:CGRectMake(KEYBOARD_NUMERIC_KEY_WIDTH * 2 - 1, KEYBOARD_NUMERIC_KEY_HEIGHT * 3 + 4, KEYBOARD_NUMERIC_KEY_WIDTH - 3, KEYBOARD_NUMERIC_KEY_HEIGHT)]];
+
+ [self addSubview:keyboardShadow];
+ }
+
+ return self;
+}
+
+- (UIButton *)addNumericKeyWithTitle:(NSString *)title frame:(CGRect)frame {
+ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
+ button.frame = frame;
+ [button setTitle:title forState:UIControlStateNormal];
+ [button.titleLabel setFont:[UIFont boldSystemFontOfSize:28.0]];
+
+ [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
+ [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
+ [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
+ [button setTitleShadowColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
+ [button.titleLabel setShadowOffset:CGSizeMake(0, -0.5)];
+
+ UIImage *buttonImage = [UIImage imageNamed:@"KeyboardNumericEntryKeyTextured"];
+ UIImage *buttonPressedImage = [UIImage imageNamed:@"KeyboardNumericEntryKeyPressedTextured"];
+ [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
+ [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
+ [button addTarget:self action:@selector(pressNumericKey:) forControlEvents:UIControlEventTouchUpInside];
+
+ return button;
+}
+
+- (UIButton *)addBackspaceKeyWithFrame:(CGRect)frame {
+ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
+ button.frame = frame;
+ UIImage *buttonImage = [UIImage imageNamed:@"KeyboardNumericEntryKeyTextured"];
+ UIImage *buttonPressedImage = [UIImage imageNamed:@"KeyboardNumericEntryKeyPressedTextured"];
+ UIImage *image = [UIImage imageNamed:@"KeyboardNumericEntryKeyBackspaceGlyphTextured"];
+ UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((buttonImage.size.width - image.size.width) / 2, (buttonImage.size.height - image.size.height) / 2, image.size.width, image.size.height)];
+ imgView.image = image;
+ [button addSubview:imgView];
+ [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
+ [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
+ [button addTarget:self action:@selector(pressBackspaceKey) forControlEvents:UIControlEventTouchUpInside];
+
+ return button;
+}
+
+- (void)setTextField:(UITextField *)textField {
+ _textField = textField;
+ _textField.inputView = self;
+ self.textInputDelegate = _textField;
+}
+
+- (void)pressNumericKey:(UIButton *)button {
+ NSString *keyText = button.titleLabel.text;
+ int key = -1;
+
+ if ([@"." isEqualToString:keyText]) {
+ key = 10;
+ } else {
+ key = [keyText intValue];
+ }
+
+ NSRange dot = [_textField.text rangeOfString:@"."];
+
+ switch (key) {
+ case 10:
+ if (dot.location == NSNotFound && _textField.text.length == 0) {
+ [self.textInputDelegate insertText:@"0."];
+ } else if (dot.location == NSNotFound) {
+ [self.textInputDelegate insertText:@"."];
+ }
+
+ break;
+ default:
+ if (kMaxNumber <= [[NSString stringWithFormat:@"%@%d", _textField.text, key] doubleValue]) {
+ _textField.text = [NSString stringWithFormat:@"%d", kMaxNumber];
+ } else if ([@"0.00" isEqualToString:_textField.text]) {
+ _textField.text = [NSString stringWithFormat:@"%d", key];
+ } else if (dot.location == NSNotFound || _textField.text.length <= dot.location + 2) {
+ [self.textInputDelegate insertText:[NSString stringWithFormat:@"%d", key]];
+ ///////////////
+ if (_textField.text.length>=2) {
+
+ NSString*str=[_textField.text substringToIndex:2];
+ NSString *first=[_textField.text substringToIndex:1];
+
+ if ((![str isEqualToString:@"0."])&&[first isEqualToString:@"0"]) {
+ _textField.text=[NSString stringWithFormat:@"%d",[_textField.text intValue]];
+
+ }
+ }
+ /////////////
+ }
+
+ break;
+ }
+}
+
+- (void)pressBackspaceKey {
+ if ([@"0." isEqualToString:_textField.text]) {
+ _textField.text = @"";
+
+ return;
+ } else {
+ [self.textInputDelegate deleteBackward];
+ }
+}
+
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect
+{
+ // Drawing code
+}
+*/
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/add.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/add.png"
new file mode 100644
index 00000000..6b698f15
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/add.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.h"
new file mode 100644
index 00000000..77652005
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.h"
@@ -0,0 +1,13 @@
+//
+// addPersonViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface addPersonViewController : UITableViewController
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.m"
new file mode 100644
index 00000000..861f30c9
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addPersonViewController.m"
@@ -0,0 +1,192 @@
+//
+// addPersonViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "addPersonViewController.h"
+#import "enterTheCategoryViewController.h"
+#import "settingManagement.h"
+@interface addPersonViewController (){
+ UISegmentedControl *segmentedController;
+}
+@property(nonatomic,strong)NSMutableDictionary*Listarray;
+@property(nonatomic,strong)settingManagement*settingM;
+@end
+
+@implementation addPersonViewController
+@synthesize Listarray,settingM;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ [self InitButton];
+ settingM=[[settingManagement alloc]init];
+ self.Listarray=[settingM selectTypeOfpersonnel:@"personnel"];
+ self.navigationItem.title=@"成员管理";
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+-(void)InitButton{
+ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(selectLeftAction:)];
+ self.navigationItem.leftBarButtonItem = leftButton;
+
+
+ NSArray *array = [NSArray arrayWithObjects:@"添加",@"删除", nil];
+ segmentedController = [[UISegmentedControl alloc]initWithItems:array ];
+ segmentedController.segmentedControlStyle = UISegmentedControlStyleBar;
+ [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
+
+ UIBarButtonItem*segButton=[[UIBarButtonItem alloc]initWithCustomView:segmentedController];
+ self.navigationItem.rightBarButtonItem = segButton;
+}
+-(void) selectLeftAction:(id)sender{
+ [self.navigationController popViewControllerAnimated:YES];
+}
+-(void) segmentAction:(id)sender
+{
+
+ switch ([sender selectedSegmentIndex]) {
+ case 0:
+ {
+ UIStoryboard*storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ enterTheCategoryViewController*enter=[storyboard instantiateViewControllerWithIdentifier:@"enter"];
+ [enter setValue:[NSNumber numberWithInt:3] forKey:@"number"];
+ [self.navigationController pushViewController:enter animated:YES];
+ }
+ break;
+ case 1:
+ {
+ segmentedController.selectedSegmentIndex=-1;
+ [self.tableView setEditing:!self.tableView.editing animated:YES];
+ if (self.tableView.editing) {
+ [self.navigationItem.rightBarButtonItem setTitle:@"done"];
+
+ }
+ else {
+ [self.navigationItem.rightBarButtonItem setTitle:@"删除"];
+ }
+ }
+ break;
+
+ }
+
+}
+-(void)viewWillAppear:(BOOL)animated{
+
+ self.Listarray=[self.settingM selectTypeOfpersonnel:@"personnel"];
+ [self.tableView reloadData];
+}
+-(void)viewDidDisappear:(BOOL)animated
+{
+
+ segmentedController.selectedSegmentIndex=-1;
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+
+ return [self.Listarray count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"personnel";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ int row=indexPath.row;
+ cell.textLabel.text=[self.Listarray objectForKey:[[self.Listarray allKeys] objectAtIndex:row]];
+ // Configure the cell...
+
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+
+ NSString* key=[[self.Listarray allKeys]objectAtIndex:indexPath.row];
+ [self.Listarray removeObjectForKey:key];
+ [self.settingM DeletePayoutTypeData:@"personnel" payout_ID:[NSNumber numberWithInt:[key intValue]]];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+ [self.tableView reloadData];
+}
+
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.h"
new file mode 100644
index 00000000..c4b0adc4
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.h"
@@ -0,0 +1,13 @@
+//
+// addSubtypeViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface addSubtypeViewController : UITableViewController
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.m"
new file mode 100644
index 00000000..deaf1f85
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addSubtypeViewController.m"
@@ -0,0 +1,196 @@
+//
+// addSubtypeViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "addSubtypeViewController.h"
+#import "settingManagement.h"
+#import "enterTheCategoryViewController.h"
+@interface addSubtypeViewController ()
+{
+ UISegmentedControl *segmentedController;
+}
+@property(nonatomic,strong)NSNumber*type_Id;
+@property(nonatomic,strong)settingManagement*settingM;
+@property(nonatomic,strong)NSMutableArray*SubArray;
+@end
+
+@implementation addSubtypeViewController
+@synthesize type_Id,settingM,SubArray;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+// NSLog(@"%@",type_Id);
+ self.navigationItem.title=@"子类别管理";
+ settingM=[[settingManagement alloc]init];
+ self.SubArray=[settingM selectSubType:self.type_Id];
+ [self InitButton];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+-(void)InitButton{
+ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(selectLeftAction:)];
+ self.navigationItem.leftBarButtonItem = leftButton;
+
+
+
+
+ NSArray *array = [NSArray arrayWithObjects:@"添加",@"删除", nil];
+ segmentedController = [[UISegmentedControl alloc]initWithItems:array ];
+ segmentedController.segmentedControlStyle = UISegmentedControlStyleBar;
+ [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
+
+ UIBarButtonItem*segButton=[[UIBarButtonItem alloc]initWithCustomView:segmentedController];
+ // [segmentedController selectedSegmentIndex];
+ self.navigationItem.rightBarButtonItem = segButton;
+}
+-(void) selectLeftAction:(id)sender{
+ [self.navigationController popViewControllerAnimated:YES];
+}
+-(void) segmentAction:(id)sender
+{
+
+ switch ([sender selectedSegmentIndex]) {
+ case 0:
+ {
+ UIStoryboard*storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ enterTheCategoryViewController*enter=[storyboard instantiateViewControllerWithIdentifier:@"enter"];
+
+ enter.number=[NSNumber numberWithInt:2];
+ [enter setValue:self.type_Id forKey:@"type_id"];
+ [self.navigationController pushViewController:enter animated:YES];
+ }
+ break;
+ case 1:
+ {
+ segmentedController.selectedSegmentIndex=-1;
+ [self.tableView setEditing:!self.tableView.editing animated:YES];
+ if (self.tableView.editing) {
+ [self.navigationItem.rightBarButtonItem setTitle:@"done"];
+ }
+ else {
+ [self.navigationItem.rightBarButtonItem setTitle:@"删除"];
+ }
+ }
+ break;
+
+ }
+}
+-(void)viewWillAppear:(BOOL)animated{
+ self.SubArray=[settingM selectSubType:self.type_Id];
+ [self.tableView reloadData];
+}
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+
+ return [self.SubArray count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"addsubtypecell";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+
+ // Configure the cell...
+ cell.textLabel.text=[self.SubArray objectAtIndex:indexPath.row];
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+
+ [settingM DeleteSubType:self.type_Id subtype:[self.SubArray objectAtIndex:indexPath.row]];
+ [self.SubArray removeObjectAtIndex:indexPath.row];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+ [tableView reloadData];
+
+}
+
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+-(void)viewDidDisappear:(BOOL)animated
+{
+
+ segmentedController.selectedSegmentIndex=-1;
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.h"
new file mode 100644
index 00000000..e1b145b8
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.h"
@@ -0,0 +1,13 @@
+//
+// addTypeViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface addTypeViewController : UITableViewController
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.m"
new file mode 100644
index 00000000..a449f8a0
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/addTypeViewController.m"
@@ -0,0 +1,207 @@
+//
+// addTypeViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "addTypeViewController.h"
+#import "enterTheCategoryViewController.h"
+#import "settingManagement.h"
+#import "addSubtypeViewController.h"
+
+@interface addTypeViewController (){
+ UISegmentedControl *segmentedController;
+}
+@property(nonatomic,strong)NSMutableDictionary*dic;
+@property(nonatomic,strong)settingManagement*settingM;
+@end
+
+@implementation addTypeViewController
+@synthesize dic,settingM;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ self.navigationItem.title=@"父类别管理";
+ [self InitButton];
+
+ settingM=[[settingManagement alloc]init];
+ self.dic=[settingM selectTypeOfpersonnel:@"type"];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+
+}
+
+-(void)InitButton{
+ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(selectLeftAction:)];
+ self.navigationItem.leftBarButtonItem = leftButton;
+
+
+
+
+ NSArray *array = [NSArray arrayWithObjects:@"添加",@"删除", nil];
+ segmentedController = [[UISegmentedControl alloc]initWithItems:array ];
+ segmentedController.segmentedControlStyle = UISegmentedControlStyleBar;
+ [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
+
+ UIBarButtonItem*segButton=[[UIBarButtonItem alloc]initWithCustomView:segmentedController];
+ // [segmentedController selectedSegmentIndex];
+ self.navigationItem.rightBarButtonItem = segButton;
+}
+-(void) selectLeftAction:(id)sender{
+ [self.navigationController popViewControllerAnimated:YES];
+
+}
+-(void) segmentAction:(id)sender
+{
+
+ switch ([sender selectedSegmentIndex]) {
+ case 0:
+ {
+ UIStoryboard*storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ enterTheCategoryViewController*enter=[storyboard instantiateViewControllerWithIdentifier:@"enter"];
+
+ enter.number=[NSNumber numberWithInt:1];
+ [enter setValue:[NSNumber numberWithInt:1] forKey:@"type_id"];
+ [self.navigationController pushViewController:enter animated:YES];
+ }
+ break;
+ case 1:
+ {
+ segmentedController.selectedSegmentIndex=-1;
+ [self.tableView setEditing:!self.tableView.editing animated:YES];
+ if (self.tableView.editing) {
+ [self.navigationItem.rightBarButtonItem setTitle:@"done"];
+
+ }
+ else {
+ [self.navigationItem.rightBarButtonItem setTitle:@"删除"];
+ }
+ }
+ break;
+
+ }
+
+
+}
+-(void)viewWillAppear:(BOOL)animated{
+
+ self.dic=[settingM selectTypeOfpersonnel:@"type"];
+ [self.tableView reloadData];
+}
+-(void)viewDidDisappear:(BOOL)animated
+{
+
+ segmentedController.selectedSegmentIndex=-1;
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+
+ return [self.dic count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"addtype";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ int row=indexPath.row;
+// NSString* key=[NSString stringWithFormat:@"%d",row+1];
+// for (NSString* key in dic) {
+// cell.textLabel.text=[dic objectForKey:key];
+//
+// }
+ cell.textLabel.text=[dic objectForKey:[[dic allKeys] objectAtIndex:row]];
+ // Configure the cell...
+
+ return cell;
+}
+
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+
+
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+
+ NSString* key=[[dic allKeys]objectAtIndex:indexPath.row];
+ [self.dic removeObjectForKey:key];
+ [self.settingM DeletePayoutTypeData:@"type" payout_ID:[NSNumber numberWithInt:[key intValue]]];
+
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+ [tableView reloadData];
+}
+
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+
+}
+
+*/
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ addSubtypeViewController*addsubtype=[storyboard instantiateViewControllerWithIdentifier:@"addsubtype"];
+
+ [addsubtype setValue:[[dic allKeys]objectAtIndex:indexPath.row] forKey:@"type_Id"];
+ [self.navigationController pushViewController:addsubtype animated:YES];
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/background.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/background.png"
new file mode 100644
index 00000000..e7a85303
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/background.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/background@2x.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/background@2x.png"
new file mode 100644
index 00000000..95c5b22b
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/background@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.h"
new file mode 100644
index 00000000..c1542ec1
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.h"
@@ -0,0 +1,43 @@
+//
+// billManagement.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+#import "FMDatabase.h"
+#import "payout.h"
+@interface billManagement : NSObject
+@property(strong,nonatomic)FMDatabase*Fdb;
+//得到最近几笔帐单日期,返回成一个数组
+-(NSMutableArray*)getRecentlyPayouDate;//yes
+//得到某月帐单数据,月份为参数
+-(NSDictionary*)getMonthPayout:(int)ThisMonth;//YES
+//得到所有的帐单数据
+-(NSMutableArray*)getAllPayout;//YES
+//给一个帐单id,查询出一笔帐的详细信息,
+-(payout*)selectPayout:(NSNumber*)payoutID;//YES
+//保存一笔帐
+-(void)savePayout:(payout*)payout;//YES
+//删除一笔帐
+-(void)deletePayout:(int)payout_ID;//YES
+//修改一笔帐
+-(void)alterPayout:(payout*)payout;//YES
+//查询返回类型数据库的数据
+-(NSArray*)selectType;//yes
+
+-(NSArray*)selectPersonnel;//yes
+
+-(NSArray*)selectSubType:(NSString*)type;//yes
+//判断保存的帐是否完整
+-(BOOL)checkingPayout:(payout*)payout;//yes
+//构建数据库
+-(void)InitSQLite;//yes
+//返回文件路径
+-(NSString*)FilePaths:(NSString*)fileName;//yes
+//单例模式
++(billManagement *)openCommentDatabase;//yes
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.m"
new file mode 100644
index 00000000..a76745de
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/billManagement.m"
@@ -0,0 +1,358 @@
+//
+// billManagement.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "billManagement.h"
+//#import "DatebaseManagement.h"
+#define kDatabaseName @"mount.sqlite"
+#define kTypeName @"type.plist"
+
+@implementation billManagement
+
+@synthesize Fdb;
+
++(billManagement *)openCommentDatabase
+{
+ static billManagement *aDatabase=nil;
+ static dispatch_once_t predicate;
+ dispatch_once(&predicate, ^{
+ aDatabase = [[self alloc] init];
+ });
+ return aDatabase;
+}
+- (id)init
+{
+ self = [super init];
+ if (self) {
+
+
+ [self InitSQLite];
+
+
+ }
+ return self;
+}
+-(void)InitSQLite{
+ Fdb=[FMDatabase databaseWithPath:[self FilePaths:kDatabaseName]];
+ if (![Fdb open]) {
+ NSLog(@"Could not open Fdb.");
+ }
+
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS PAYOUT(ID INTEGER PRIMARY KEY AUTOINCREMENT,amount double,date date,type text,subtype text,comment text,image blob,personnel text)"];
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS personnel(ID INTEGER PRIMARY KEY AUTOINCREMENT,personnel text)"];
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS type(ID INTEGER PRIMARY KEY AUTOINCREMENT,type text)"];
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS subtype(ID INTEGER PRIMARY KEY AUTOINCREMENT,type_id text,subtype text)"];
+// [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS subtype(ID INTEGER PRIMARY KEY AUTOINCREMENT,type_ID integer REFERENCES type(ID),subtype text)"];
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS budget(ID INTEGER PRIMARY KEY AUTOINCREMENT,budget text)"];
+ if ([[self getPayoutType] count]<1) {
+ [self InitPayoutType];
+ [self InitPersonnel];
+ }
+}
+
+
+-(void)InitPersonnel{
+ NSString*sql=[NSString stringWithFormat:@"insert into personnel(personnel) values ('老公')"];
+ NSString*sql1=[NSString stringWithFormat:@"insert into personnel(personnel) values ('老婆')"];
+ NSString*sql2=[NSString stringWithFormat:@"insert into personnel(personnel) values ('家庭')"];
+ NSString*sql3=[NSString stringWithFormat:@"insert into personnel(personnel) values ('女儿')"];
+ [Fdb executeUpdate:sql];
+ [Fdb executeUpdate:sql1];
+ [Fdb executeUpdate:sql2];
+ [Fdb executeUpdate:sql3];
+}
+
+-(void)InitPayoutType{
+ NSString *path=[[NSBundle mainBundle]pathForResource:@"type" ofType:@"plist"];
+ NSDictionary*dic=[NSDictionary dictionaryWithContentsOfFile:path];
+ [dic writeToFile:[self FilePaths:kTypeName] atomically:YES];
+ for (NSString*s in [dic allKeys]) {
+ [self intersectType:s];
+// NSLog(@"type %@",s);
+ }
+ for (int i=0; i<[[dic allKeys]count]; i++) {
+ for (id s in [dic objectForKey:[[dic allKeys]objectAtIndex:i]]) {
+ [self intersectSubType:i subtype:s];
+ }
+ }
+}
+-(void)intersectType:(NSString*)type{
+ NSString*sql=[NSString stringWithFormat:@"insert into type(type) values ('%@')",type];
+ [Fdb executeUpdate:sql];
+}
+-(void)intersectSubType:(int)type_id subtype:(NSString*)subtype{
+ NSString*sql=[NSString stringWithFormat:@"insert into subtype(type_ID,subtype) values ('%d','%@')",type_id+1,subtype];
+ [Fdb executeUpdate:sql];
+}
+-(NSMutableArray*)getPayoutType{
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ FMResultSet *rs =[Fdb executeQuery:@"SELECT * FROM type"];
+
+ while ([rs next]) {
+ NSString*str=[[NSString alloc]init];
+ str=[rs stringForColumn:@"type"];
+ [array addObject:str];
+ }
+ return array;
+}
+//设置数据库文件路径
+-(NSString*)FilePaths:(NSString*)fileName{
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentDirectory = [paths objectAtIndex:0];
+ NSString *dbPath = [documentDirectory stringByAppendingPathComponent:fileName];
+// self.Fdb = [FMDatabase databaseWithPath:dbPath] ;
+// if (![Fdb open]) {
+// NSLog(@"Could not open Fdb.");
+// }
+// NSLog(@"billM______\n%@",dbPath);
+ return dbPath;
+}
+//得到最近几笔帐单日期,返回成一个数组
+-(NSMutableArray*)getRecentlyPayouDate{
+
+ NSMutableArray*array=[self getAllPayout];
+ NSMutableArray*arrayto=[[NSMutableArray alloc]init];
+ for (int i=[array count]-1; i>=0; i--) {
+ [arrayto addObject:[array objectAtIndex:i]];
+ }
+ return arrayto;
+}
+//得到某月帐单数据,月份为参数
+-(NSDictionary*)getMonthPayout:(int)ThisMonth{
+
+
+ if (ThisMonth==0) {
+
+ NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
+ for (payout *p in [self getAllPayout]) {
+ NSNumber *moth=[NSNumber numberWithInt:[p getMonth]];
+
+ if ([dic objectForKey:moth]) {
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ array=[dic objectForKey:moth];
+ [array addObject:p];
+ }
+ else{
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ [array addObject:p];
+ [dic setObject:array forKey:moth];
+ }
+
+ }
+
+ return dic;
+ }
+
+
+ else {
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ NSString*sql;
+ if (ThisMonth>=10) {
+ sql=[NSString stringWithFormat:@"SELECT * from payout where strftime('%%m',date)=='%d'",ThisMonth];
+ }
+ else {
+ sql=[NSString stringWithFormat:@"SELECT * from payout where strftime('%%m',date)=='0%d'",ThisMonth];
+ }
+ FMResultSet *rs =[Fdb executeQuery:sql];
+
+ while ([rs next]) {
+ payout*_payout=[[payout alloc]init];
+ _payout.payout_ID=[rs intForColumn:@"ID"];
+ _payout.amount = [rs doubleForColumn:@"amount"];
+ _payout.date=[rs stringForColumn:@"date"];
+ _payout.type=[rs stringForColumn:@"type"];
+ _payout.subType=[rs stringForColumn:@"subType"];
+ _payout.comment=[rs stringForColumn:@"comment"];
+ _payout.image=[rs dataForColumn:@"image"];
+ _payout.personnel=[rs stringForColumn:@"personnel"];
+ [array addObject:_payout];
+ }
+
+ [rs close];
+ NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
+ for (payout *p in array) {
+ NSNumber *moth=[NSNumber numberWithInt:ThisMonth];
+
+ if ([dic objectForKey:moth]) {
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ array=[dic objectForKey:moth];
+ [array addObject:p];
+ }
+ else{
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ [array addObject:p];
+ [dic setObject:array forKey:moth];
+ }
+
+ }
+
+ return dic;
+ }
+}
+
+//给一个帐单id,查询出一笔帐的详细信息,
+-(payout*)selectPayout:(NSNumber*)payoutID{
+ NSString *sql=[NSString stringWithFormat:@"SELECT * FROM payout where id=%@",payoutID];
+
+ FMResultSet *rs =[Fdb executeQuery:sql];
+ payout*_payout=[[payout alloc]init];
+
+ while ([rs next]) {
+ _payout.payout_ID=[rs intForColumn:@"ID"];
+ _payout.amount = [rs doubleForColumn:@"amount"];
+ _payout.date=[rs stringForColumn:@"date"];
+ _payout.type=[rs stringForColumn:@"type"];
+ _payout.subType=[rs stringForColumn:@"subType"];
+ _payout.comment=[rs stringForColumn:@"comment"];
+ _payout.image=[rs dataForColumn:@"image"];
+ _payout.personnel=[rs stringForColumn:@"personnel"];
+
+ }
+
+ [rs close];
+ return _payout;
+}
+//保存一笔帐
+-(void)savePayout:(payout*)payout{
+ NSData*da=payout.image;
+
+ NSString*sql=[NSString stringWithFormat:@"insert into payout(amount,date,type,subtype,comment,image,personnel) values (%f,'%@','%@','%@','%@',?,'%@')",payout.amount,payout.date,payout.type,payout.subType,payout.comment,payout.personnel];
+ BOOL a=[Fdb executeUpdate:sql,da];
+ if (a) {
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"保存成功" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
+ [alert show];
+ }else {
+ NSLog(@"保存失败!");
+ }
+}
+
+//删除一笔帐
+-(void)deletePayout:(int)payout_ID{
+ NSString*delete=[NSString stringWithFormat:@"DELETE FROM payout WHERE ID = %d",payout_ID];
+ BOOL a=[Fdb executeUpdate:delete];
+ if (a) {
+ NSLog(@"%d,删除成功!",payout_ID);
+ }
+}
+-(NSArray*)selectPersonnel{
+ NSString *sql=[NSString stringWithFormat:@"SELECT * FROM personnel"];
+
+ FMResultSet *rs =[Fdb executeQuery:sql];
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+ NSString*str=[rs stringForColumn:@"personnel"];
+ [array addObject:str];
+
+ }
+
+ [rs close];
+ return array;
+}
+//修改一笔帐
+-(void)alterPayout:(payout*)payout{
+// payout.payout_ID=14;
+ NSString*amount=[NSString stringWithFormat:@"UPDATE payout SET amount = %f WHERE ID = %d",payout.amount,payout.payout_ID];
+ [Fdb executeUpdate:amount];
+ NSString*date=[NSString stringWithFormat:@"UPDATE payout SET date = '%@' WHERE ID = %d",payout.date,payout.payout_ID];
+ [Fdb executeUpdate:date];
+ NSString*type=[NSString stringWithFormat:@"UPDATE payout SET type = '%@' WHERE ID = %d",payout.type,payout.payout_ID];
+ [Fdb executeUpdate:type];
+ NSString*subtype=[NSString stringWithFormat:@"UPDATE payout SET subtype = '%@' WHERE ID = %d",payout.subType,payout.payout_ID];
+ [Fdb executeUpdate:subtype];
+ NSString*comment=[NSString stringWithFormat:@"UPDATE payout SET comment = '%@' WHERE ID = %d",payout.comment,payout.payout_ID];
+ [Fdb executeUpdate:comment];
+ NSString*image=[NSString stringWithFormat:@"UPDATE payout SET image = ? WHERE ID = %d",payout.payout_ID];
+ [Fdb executeUpdate:image,payout.image];
+ NSString*personnel=[NSString stringWithFormat:@"UPDATE payout SET personnel = '%@' WHERE ID = %d",payout.personnel,payout.payout_ID];
+ [Fdb executeUpdate:personnel];
+
+}
+-(NSArray *)selectType{
+ NSString *sql=[NSString stringWithFormat:@"SELECT * FROM type"];
+
+ FMResultSet *rs =[Fdb executeQuery:sql];
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+ NSString*str=[rs stringForColumn:@"type"];
+ [array addObject:str];
+
+ }
+
+ [rs close];
+ return array;
+}
+
+
+-(NSArray *)selectSubType:(NSString*)type{
+ NSString *sql=[NSString stringWithFormat:@"select*from subtype where type_id=(SELECT ID from type where type='%@')",type];
+
+ FMResultSet *rs =[Fdb executeQuery:sql];
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+ NSString*str=[rs stringForColumn:@"subtype"];
+ [array addObject:str];
+
+ }
+
+ [rs close];
+ return array;
+}
+
+
+-(NSMutableArray*)getAllPayout{
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ FMResultSet *rs =[Fdb executeQuery:@"SELECT * FROM payout"];
+
+ while ([rs next]) {
+ payout*_payout=[[payout alloc]init];
+ _payout.payout_ID=[rs intForColumn:@"ID"];
+ _payout.amount = [rs doubleForColumn:@"amount"];
+ _payout.date=[rs stringForColumn:@"date"];
+ _payout.type=[rs stringForColumn:@"type"];
+ _payout.subType=[rs stringForColumn:@"subType"];
+ _payout.comment=[rs stringForColumn:@"comment"];
+ _payout.image=[rs dataForColumn:@"image"];
+ _payout.personnel=[rs stringForColumn:@"personnel"];
+ NSLog(@"%d",_payout.payout_ID);
+ [array addObject:_payout];
+ }
+
+ [rs close];
+ return array;
+}
+-(BOOL)checkingPayout:(payout *)payout{
+
+// if (payout.amount>0&&[payout.type length]>1&&[payout.subType length]>1&&[payout.personnel length]>1&&[payout.date length]>1) {
+// return YES;
+// }
+ if (payout.amount<0.1) {
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"金额不能为空" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
+ [alert show];
+ return NO;
+ }else if([payout.type length]<1){
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"类别不能为空" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
+ [alert show];
+ return NO;
+
+ }else if ([payout.subType length]<1){
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"子类别不能为空" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
+ [alert show];
+ return NO;
+
+ }else if ([payout.date length]<1){
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"时间不能为空" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
+ [alert show];
+ return NO;
+ }else if ([payout.personnel length]<1){
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"成员不能为空" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
+ [alert show];
+ return NO;
+ }else{
+ return YES;
+ }
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.h"
new file mode 100644
index 00000000..a6adfbc9
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.h"
@@ -0,0 +1,102 @@
+//
+// billViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+#import "billManagement.h"
+#import "ZenKeyboard.h"
+@interface billViewController : UIViewController{
+ sqlite3 *db;
+ FMDatabase*Fdb;
+ UITextField *moneyTextField;
+ UITextField *typeTextField;
+ UITextField *subTypeTextField;
+ UITextField *dateTextField;
+ UITextField *personnelTextField;
+ UITextView *commentTextField;
+ UIButton *photoButton;
+
+ UILabel *typeLabel;
+ UILabel *subTypeLabel;
+ UILabel *dateLabel;
+ UILabel *personnelLabel;
+ UILabel *conmmentLabel;
+
+ UIToolbar *keyboardToolbar;
+ UIPickerView *typePicker;
+ UIPickerView *subTypePicker;
+ UIPickerView *personPickerView;
+ UIDatePicker *datePicker;
+
+ NSString *types;
+ NSString *subType;
+ NSDate *theDate;
+ NSString *person;
+ UIImage *photo;
+}
+
+//@property(nonatomic,retain)IBOutlet UIButton *photoButton;
+
+//-(IBAction)choosePhot:(id)sender;
+@property (strong, nonatomic) IBOutlet UITextField *moneyTextField;
+@property (strong, nonatomic) IBOutlet UITextField *typeTextField;
+@property (strong, nonatomic) IBOutlet UITextField *subTypeTxetField;
+@property (strong, nonatomic) IBOutlet UITextField *dateTextField;
+@property (strong, nonatomic) IBOutlet UITextField *personnelTextField;
+@property (strong, nonatomic) IBOutlet UITextView *commentTextField;
+
+@property (strong, nonatomic) IBOutlet UIButton *photoButton;
+@property(assign,nonatomic) NSInteger billIndex;
+
+@property (strong, nonatomic) IBOutlet UILabel *typeLabel;
+@property (strong, nonatomic) IBOutlet UILabel *subTypeLabel;
+@property (strong, nonatomic) IBOutlet UILabel *dateLabel;
+@property (strong, nonatomic) IBOutlet UILabel *personnelLabel;
+@property (strong, nonatomic) IBOutlet UILabel *commentLabel;
+
+@property(nonatomic,retain) UIToolbar *keyboardToolbar;
+@property(nonatomic,retain) UIPickerView *typePicker;
+@property(nonatomic,retain) UIPickerView*subTypePicker;
+@property(nonatomic,retain) UIPickerView*personPickerView;
+@property(nonatomic,retain) UIDatePicker*datePicker;
+
+@property(nonatomic,retain) NSString*types;
+@property(nonatomic,assign) int PickerIndex;
+@property(nonatomic,retain) NSDate*theDate;
+@property(nonatomic,retain) NSString*person;
+@property(nonatomic,retain) UIImage*photo;
+@property(nonatomic,strong) billManagement*billM;
+@property(nonatomic,strong) NSArray*PickerArray;
+
+
+- (IBAction)choosePhoto:(id)sender;
+
+- (void)resignKeyboard:(id)sender;//辞职键盘
+- (void)previousField:(id)sender;//之前的字段
+- (void)nextField:(id)sender;
+- (id)getFirstResponder;//得到第一个回答者
+- (void)animateView:(NSUInteger)tag;//动画视图
+- (void)checkBarButton:(NSUInteger)tag;//检查栏按钮
+- (void)checkSpecialFields:(NSUInteger)tag;//检查特殊字段
+- (void)setTypeData;
+- (void)setSubTypeData;
+- (void)setDateData;
+- (void)setPersonData;
+- (void)datePickerChanged:(id)sender;
+- (void)resetLabelsColors;//复位标签颜色
+
++ (UIColor *)labelNormalColor;
++ (UIColor *)labelSelectedColor;
+
+- (IBAction)saveApayout:(id)sender;
+- (IBAction)clearButton:(id)sender;
+@property (strong, nonatomic) IBOutlet UIButton *clearButtonOutlet;
+
+@property (nonatomic, strong) ZenKeyboard *keyboardView;
+@property(nonatomic,strong)NSString*backTypeNSString;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.m"
new file mode 100644
index 00000000..d3ecad6c
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/billViewController.m"
@@ -0,0 +1,735 @@
+//
+// billViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "billViewController.h"
+#import
+
+#import "Config.h"
+#import "payout.h"
+
+//#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
+
+#define FIELDS_COUNT 7
+#define TYPE_FIELD_TAG 3
+#define SUBTYPE_FIELD_TAG 4
+#define DATE_FIELD_TAG 5
+#define PERSON_FIELD_TAG 6
+#define COMMENT_FIELD_TAG 8
+@interface billViewController ()
+
+@end
+
+@implementation billViewController
+@synthesize clearButtonOutlet;
+@synthesize moneyTextField;
+@synthesize typeTextField;
+@synthesize subTypeTxetField;
+@synthesize dateTextField;
+@synthesize personnelTextField;
+@synthesize commentTextField;
+@synthesize photoButton;
+@synthesize typeLabel;
+@synthesize subTypeLabel;
+@synthesize dateLabel;
+@synthesize personnelLabel;
+@synthesize commentLabel;
+@synthesize keyboardToolbar;
+@synthesize typePicker;
+@synthesize subTypePicker;
+@synthesize personPickerView;
+@synthesize datePicker;
+@synthesize types,PickerArray;
+@synthesize theDate,PickerIndex;
+@synthesize person,billM,backTypeNSString;
+@synthesize photo,billIndex,keyboardView;
+
+//@synthesize photoButton;
+
+
+-(void)Init{
+ self.navigationItem.title= @"记一笔";
+ billM=[[billManagement alloc]init];
+ PickerArray=[[NSArray alloc]init];
+ //------------------手势------------------------
+ UISwipeGestureRecognizer *recognizer;
+ if ([self.backTypeNSString isEqualToString:@"Dtype"]) {
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
+
+ [[self view] addGestureRecognizer:recognizer];
+ }else if([self.backTypeNSString isEqualToString:@"View"]){
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
+
+ [[self view] addGestureRecognizer:recognizer];
+
+ }
+ //------------------手势------------------------
+
+}
+
+
+-(void)backButton{
+ //-----------------------返回-------------------
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];//UIBarButtonItem
+ //-----------------------返回-------------------
+}
+
+-(void)backBtnAction{
+ if ([self.backTypeNSString isEqualToString:@"Dtype"]) {
+ [self.navigationController popViewControllerAnimated:YES];
+ }
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.5;
+// transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.timingFunction= UIViewAnimationCurveEaseInOut;
+// transition.fillMode=kCAFillModeForwards;
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromBottom;//方向
+
+ [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];//
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+
+ [self.navigationController popViewControllerAnimated:NO];
+
+}
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+- (void)viewDidLoad
+{
+ NSLog(@"bill index -->%d",billIndex);
+ [super viewDidLoad];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"payout.png"]];
+ [self Init];
+
+ [self backButton];
+
+ [self initPicker];
+
+ if (billIndex>=0) {
+ self.clearButtonOutlet.titleLabel.text=@"删除";
+ [self aPayout];
+ }else {
+ self.clearButtonOutlet.titleLabel.text=@"清空";
+ }
+
+ // Do any additional setup after loading the view.
+}
+-(void)aPayout{
+
+ payout*_payout;
+ _payout=[billM selectPayout:[NSNumber numberWithInteger:billIndex]];
+ self.moneyTextField.text=[NSString stringWithFormat:@"%.2f",_payout.amount];
+ self.photo = [UIImage imageWithData:_payout.image];
+ [self.photoButton setImage:self.photo forState:UIControlStateNormal];
+ self.typeTextField.text=[NSString stringWithFormat:@"%@",_payout.type];
+ self.subTypeTxetField.text=_payout.subType;
+
+ self.dateTextField.text=_payout.date;
+ self.personnelTextField.text=_payout.personnel;
+ self.commentTextField.text=_payout.comment;
+
+}
+-(void)initPicker{
+ //type picker
+ if (self.typePicker == nil) {
+ self.typePicker = [[UIPickerView alloc] init];
+ self.typePicker.delegate = self;
+ self.typePicker.showsSelectionIndicator = YES;
+ }
+ //subtype picker
+ if (self.subTypePicker == nil) {
+ self.subTypePicker = [[UIPickerView alloc]init ];
+ self.subTypePicker.delegate = self;
+ self.subTypePicker.showsSelectionIndicator = YES;
+ }
+ //date picker
+ if (self.datePicker == nil) {
+ self.datePicker = [[UIDatePicker alloc]init ];
+ [self.datePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
+ self.datePicker.datePickerMode = UIDatePickerModeDate;
+ NSDate * currentDate = [NSDate date];
+ NSDateComponents *dateComponents = [[NSDateComponents alloc]init ];
+ [dateComponents setYear:-18];
+ NSDate *selectedDate = [[NSCalendar currentCalendar]dateByAddingComponents:dateComponents toDate:currentDate options:0 ];
+ [self.datePicker setDate:selectedDate animated:YES];
+ self.datePicker.date=[NSDate new];
+ [self.datePicker setMaximumDate:currentDate];
+
+ //
+ }
+ // person Picker
+ if (self.personPickerView == nil) {
+ self.personPickerView = [[UIPickerView alloc]init ];
+ self.personPickerView.delegate = self;
+ self.personPickerView.showsSelectionIndicator = YES;
+ }
+
+ //Keyboard toolbar
+ if (self.keyboardToolbar == nil) {
+ self.keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 38.0f)];
+ self.keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
+ UIBarButtonItem *previousBarItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"上一个", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(previousField:) ];
+ UIBarButtonItem * nextButtonItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"下一个", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(nextField:) ];
+ UIBarButtonItem *spaceBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
+ target:nil action:nil];
+ UIBarButtonItem *doneBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"确定", @"")style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard:)];
+ [self.keyboardToolbar setItems:[NSArray arrayWithObjects:previousBarItem,nextButtonItem,spaceBarItem,doneBarItem, nil]];
+ self.moneyTextField.inputAccessoryView = self.keyboardToolbar;
+ self.typeTextField.inputAccessoryView = self.keyboardToolbar;
+ self.subTypeTxetField.inputAccessoryView = self.keyboardToolbar;
+ self.dateTextField.inputAccessoryView = self.keyboardToolbar;
+ self.personnelTextField.inputAccessoryView = self.keyboardToolbar;
+ self.commentTextField.inputAccessoryView = self.keyboardToolbar;
+ self.typeTextField.inputView = self.typePicker;
+ self.subTypeTxetField.inputView = self.subTypePicker;
+ self.dateTextField.inputView = self.datePicker;
+ self.personnelTextField.inputView = self.personPickerView;
+ }
+ //set localization
+ self.moneyTextField.placeholder = NSLocalizedString(@"money", @"");
+ self.typeTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
+ self.subTypeTxetField.text = [NSLocalizedString(@"", @"")uppercaseString];
+ self.dateTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
+ self.personnelTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
+ self.commentTextField.text = [NSLocalizedString(@"", @"")uppercaseString];
+ self.commentTextField.text=@" ";
+ [self resetLabelsColors];
+}
+-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
+
+ [self.navigationController popViewControllerAnimated:YES];
+ NSLog(@"swipe left");
+
+ }
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionDown) {
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.5;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromBottom;//方向
+
+ [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];//
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+
+ [self.navigationController popViewControllerAnimated:NO];
+ NSLog(@"swipe Left");
+
+ //执行程序
+
+ }
+}
+- (void)viewDidUnload
+{
+
+
+ [[NSNotificationCenter defaultCenter] removeObserver:nil];
+
+ [self setMoneyTextField:nil];
+ [self setSubTypeTxetField:nil];
+ [self setDateTextField:nil];
+ [self setPersonnelTextField:nil];
+ [self setCommentTextField:nil];
+ [self setPhotoButton:nil];
+ [self setTypeLabel:nil];
+ [self setSubTypeLabel:nil];
+ [self setDateLabel:nil];
+ [self setPersonnelLabel:nil];
+ [self setCommentLabel:nil];
+ [self setClearButtonOutlet:nil];
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+}
+
+#pragma mark - Others
+
+
+-(void)resignKeyboard:(id)sender
+{
+ if ([self.types isEqualToString:@"type"]) {
+ [self setTypeData];
+ }
+ else if ([self.types isEqualToString:@"subtype"]){
+ [self setSubTypeData];
+ }
+ id firstResponder = [self getFirstResponder];
+ if ([firstResponder isKindOfClass:[UITextField class]]||[firstResponder isKindOfClass:[UITextView class]]) {
+ [firstResponder resignFirstResponder];
+ [self animateView:1];
+ [self resetLabelsColors];
+ }
+
+}
+-(void)previousField:(id)sender
+{
+ id firstResponder = [self getFirstResponder];
+ if ([firstResponder isKindOfClass:[UITextField class]]||[firstResponder isKindOfClass:[UITextView class]]) {
+ NSUInteger tag = [firstResponder tag];
+ NSUInteger previousTag = tag == 1 ? 1 :tag - 1;
+ [self checkBarButton:previousTag];
+ [self animateView:previousTag];
+ UITextField * previousField = (UITextField *)[self.view viewWithTag:previousTag];
+ [previousField becomeFirstResponder];
+ UILabel *nextLabel = (UILabel *)[self.view viewWithTag:previousTag + 10];
+ if (nextLabel) {
+ [self resetLabelsColors];
+ [nextLabel setTextColor:[billViewController labelSelectedColor]];
+ }
+ [self checkSpecialFields:previousTag];
+ }
+}
+- (void)nextField:(id)sender
+{
+ id firstResponder = [self getFirstResponder];
+ if ([firstResponder isKindOfClass:[UITextField class]]) {
+ NSUInteger tag = [firstResponder tag];
+ NSUInteger nextTag = tag == FIELDS_COUNT ? FIELDS_COUNT : tag + 1;
+ [self checkBarButton:nextTag];
+ [self animateView:nextTag];
+ UITextField *nextField = (UITextField *)[self.view viewWithTag:nextTag];
+ [nextField becomeFirstResponder];
+ UILabel *nextLabel = (UILabel *)[self.view viewWithTag:nextTag + 10];
+ if (nextLabel) {
+ [self resetLabelsColors];
+ [nextLabel setTextColor:[billViewController labelSelectedColor]];
+ }
+ [self checkSpecialFields:nextTag];
+ }
+}
+- (id)getFirstResponder
+{
+ NSUInteger index = 0 ;
+ while (index <= FIELDS_COUNT) {
+ UITextField *textField = (UITextField *)[self.view viewWithTag:index];
+ if ([textField isFirstResponder]) {
+ return textField;
+ }
+ index++;
+ }
+
+ return nil;
+}
+
+- (void)animateView:(NSUInteger)tag
+{
+ CGRect rect = self.view.frame;
+ [UIView beginAnimations:nil context:NULL];
+ [UIView setAnimationDuration:0.3];
+
+ if (tag > 3) {
+ rect.origin.y = -44.0f * (tag - 3);
+ } else {
+ rect.origin.y = 0;
+ }
+ self.view.frame = rect;
+ [UIView commitAnimations];
+}
+
+- (void)checkBarButton:(NSUInteger)tag
+{
+ UIBarButtonItem *previousBarItem = (UIBarButtonItem *)[[self.keyboardToolbar items] objectAtIndex:0];
+ UIBarButtonItem *nextBarItem = (UIBarButtonItem *)[[self.keyboardToolbar items] objectAtIndex:1];
+
+ [previousBarItem setEnabled:tag == 1 ? NO : YES];
+ [nextBarItem setEnabled:tag == FIELDS_COUNT ? NO : YES];
+}
+
+- (void)checkSpecialFields:(NSUInteger)tag
+{
+ if (tag == DATE_FIELD_TAG && [self.dateTextField.text isEqualToString:@""]) {
+ [self setDateData];
+ } else if (tag == PERSON_FIELD_TAG && [self.personnelTextField.text isEqualToString:@""]) {
+ [self setPersonData];
+ }else if (tag == TYPE_FIELD_TAG && [self.typeTextField.text isEqualToString:@""]) {
+ [self setTypeData];
+ }else if (tag == SUBTYPE_FIELD_TAG && [self.subTypeTxetField.text isEqualToString:@""]) {
+ [self setSubTypeData];
+ }else if (tag == COMMENT_FIELD_TAG && [self.commentTextField.text isEqualToString:@""]) {
+ [self setComment];
+ }
+}
+-(void)setComment
+{
+ self.commentTextField.text = @"aaaaaaaaaac";
+ //self.types = @"S";
+
+}
+-(void)setTypeData
+{
+
+ self.typeTextField.text = [PickerArray objectAtIndex:[self.typePicker selectedRowInComponent:0]];
+
+ //self.types = @"S";
+
+}
+-(void)setSubTypeData
+{
+
+ self.subTypeTxetField.text=[PickerArray objectAtIndex:[self.subTypePicker selectedRowInComponent:0]];
+
+
+ //self.subType = @"Z";
+ }
+-(void)setDateData
+{
+
+ NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init ];
+ [dateFormatter setDateFormat:@"yyyy-MM-dd"];
+ [self.datePicker setAccessibilityLanguage:@"Chinese"];
+
+ self.theDate = self.datePicker.date;
+ [dateFormatter setLocale:[NSLocale currentLocale]];
+ self.dateTextField.text = [dateFormatter stringFromDate:self.theDate];
+
+}
+-(void)setPersonData
+{
+// if ([self.personPickerView selectedRowInComponent:0] == 0) {
+// self.personnelTextField.text = NSLocalizedString(@"本人1", @"");
+// self.person = @"B";
+// }else {
+
+ self.personnelTextField.text =[PickerArray objectAtIndex:[self.personPickerView selectedRowInComponent:0]];
+ self.person = @"N";
+// }
+}
+-(void)datePickerChanged:(id)sender
+{
+ [self setDateData];
+}
+-(void)resetLabelsColors
+{
+ self.typeLabel.textColor = [billViewController labelNormalColor];
+ self.subTypeLabel.textColor = [billViewController labelNormalColor];
+ self.dateLabel.textColor = [billViewController labelNormalColor];
+ self.personnelLabel.textColor = [billViewController labelNormalColor];
+ self.commentLabel.textColor = [billViewController labelNormalColor];
+}
+
++(UIColor *)labelNormalColor
+{
+ return [UIColor colorWithRed:0.016 green:0.216 blue:0.286 alpha:1.000];
+}
++(UIColor *)labelSelectedColor
+{
+ return [UIColor colorWithRed:0.114 green:0.600 blue:0.737 alpha:1.000];
+}
+#pragma mark - saveApayout
+- (IBAction)saveApayout:(id)sender {
+ if (billIndex>=0) {
+ payout*apayout=[[payout alloc]init];
+ apayout.amount=[self.moneyTextField.text floatValue];
+ apayout.payout_ID=billIndex;
+ apayout.type=self.typeTextField.text;
+ apayout.subType=self.subTypeTxetField.text;
+ apayout.personnel=self.personnelTextField.text;
+ apayout.comment=self.commentTextField.text;
+ apayout.date=self.dateTextField.text;
+ apayout.image=UIImagePNGRepresentation(self.photo);
+ [billM alterPayout:apayout];
+// [self.navigationController popViewControllerAnimated:NO];
+ [self backBtnAction];
+ }
+ else {
+
+
+ payout*p=[[payout alloc]init];
+ p.amount=[self.moneyTextField.text floatValue];
+ p.type=self.typeTextField.text;
+ p.subType=self.subTypeTxetField.text;
+ p.date=self.dateTextField.text;
+ p.personnel=self.personnelTextField.text;
+ p.comment=self.commentTextField.text;
+ p.image=UIImagePNGRepresentation(self.photo);
+ if ([billM checkingPayout:p]) {
+ [billM savePayout:p];
+
+ [self clearBill];
+ }else {
+// UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"不能为空!" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
+// [alert show];
+ }
+
+ }
+}
+
+
+#pragma mark - clear
+-(void)clearBill{
+ self.moneyTextField.text=@"";
+ self.typeTextField.text=@"";
+ self.subTypeTxetField.text=@"";
+ self.dateTextField.text=@"";
+ self.commentTextField.text=@"";
+ self.personnelTextField.text=@"";
+ self.types=@"";
+ [self.photoButton setImage:nil forState:UIControlStateNormal];
+}
+- (IBAction)clearButton:(id)sender {
+ if (billIndex>=0) {
+
+ [billM deletePayout:billIndex];
+ UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"删除成功!" message:nil delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil];
+ [alert show];
+ [self clearBill];
+ }else {
+ [self clearBill];
+ }
+
+}
+
+#pragma mark - ZenKeyboard
+//- (void)viewDidAppear:(BOOL)animated {
+// [super viewDidAppear:animated];
+// [moneyTextField becomeFirstResponder];
+//}
+//
+//- (void)didReceiveMemoryWarning
+//{
+// [super didReceiveMemoryWarning];
+// // Dispose of any resources that can be recreated.
+//}
+- (void)setZenKeyboard {
+
+ moneyTextField.textColor = RGB(104, 114, 121);
+ // _tfIncome.backgroundColor = [UIColor lightGrayColor];
+ moneyTextField.textAlignment = UITextAlignmentLeft;
+ moneyTextField.adjustsFontSizeToFitWidth = YES;
+ // _tfIncome.clearButtonMode = UITpextFieldViewModeWhileEditing;
+ // _tfIncome.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TotalAmount"]];
+ // _tfIncome.leftViewMode = UITextFieldViewModeAlways;
+// moneyTextField.text = @"0.00";
+ // _tfIncome.keyboardType = UIKeyboardTypeDecimalPad;
+
+
+ keyboardView = [[ZenKeyboard alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
+ keyboardView.textField = moneyTextField;
+ [self.view addSubview:moneyTextField];
+
+}
+
+
+#pragma mark - UITextFieldDelegate
+-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
+// [moneyTextField resignFirstResponder];
+ return YES;
+
+}
+-(void)textFieldDidBeginEditing:(UITextField *)textField
+{
+ if (textField.tag==2) {
+ [self setZenKeyboard];
+ }
+ if (textField.tag==3) {
+ self.PickerArray=nil;
+ self.types=@"type";
+ self.PickerArray=[billM selectType];
+ [self.subTypePicker selectedRowInComponent:0];
+
+ }
+ else if(textField.tag==4){
+// [self.typePicker selectedRowInComponent:0];
+// [self.subTypePicker selectedRowInComponent:0];
+ self.types=@"subtype";
+
+ if ([self.typeTextField.text length]>1) {
+ [self.subTypePicker reloadComponent:0];
+ self.PickerArray=[billM selectSubType:self.typeTextField.text];
+ }
+ else {
+ self.PickerArray=[billM selectType];
+ [self.subTypePicker selectedRowInComponent:0];
+ self.typeTextField.text=[PickerArray objectAtIndex:0];
+
+ self.PickerArray=[billM selectSubType:self.typeTextField.text];
+
+ }
+
+ }
+ else if (textField.tag==6) {
+ self.types=@"personnel";
+ self.PickerArray=nil;
+ self.PickerArray=[billM selectPersonnel];
+ }
+
+ NSUInteger tag = [textField tag];
+ [self animateView:tag];
+ [self checkBarButton:tag];
+ [self checkSpecialFields:tag];
+ UILabel * label = (UILabel *)[self.view viewWithTag:tag + 10];
+ if (label) {
+ [self resetLabelsColors];
+ [label setTextColor:[billViewController labelSelectedColor]];
+ }
+}
+
+-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
+{
+ NSUInteger tag = [textField tag];
+ if (tag == DATE_FIELD_TAG || tag == PERSON_FIELD_TAG || tag == TYPE_FIELD_TAG || tag == SUBTYPE_FIELD_TAG) {
+ return NO;
+ }
+ return YES;
+
+}
+
+ - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
+ NSUInteger tag = [textView tag];
+ [self animateView:tag];
+ [self checkBarButton:tag];
+ [self checkSpecialFields:tag];
+ UILabel * label = (UILabel *)[self.view viewWithTag:tag + 10];
+ if (label) {
+ [self resetLabelsColors];
+ [label setTextColor:[billViewController labelSelectedColor]];
+ }
+
+ return YES;
+ }
+
+#pragma mark -selectedRowInComponent
+
+
+-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
+{
+ return 1;
+}
+-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
+{
+
+ return [self.PickerArray count];
+
+}
+
+#pragma mark - UIPickerViewDelegate
+
+-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
+{
+ if (row >= [self.PickerArray count]) {
+ return nil;
+ }
+ if ([self.types isEqualToString:@"subtype"]) {
+ NSLog(@"subtype row %d",row);
+ }
+ UIImage *image = row ==0 ? [UIImage imageNamed:@"male.png"] : [UIImage imageNamed:@"female.png"];
+ UIImageView * imageView = [[UIImageView alloc]initWithImage:image ];
+ imageView.frame = CGRectMake(0, 0, 32, 32);
+ UILabel *typesLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, 100, 32) ];
+
+ UILabel *personLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, 100, 32) ];
+
+ typesLabel.text=[self.PickerArray objectAtIndex:row];
+
+
+ typesLabel.textAlignment = UITextAlignmentLeft;
+ typesLabel.backgroundColor = [UIColor clearColor];
+
+ personLabel.textAlignment = UITextAlignmentLeft;
+ personLabel.backgroundColor = [UIColor clearColor];
+
+ UIView *rowView = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 100, 32)] ;
+ [rowView insertSubview:imageView atIndex:0];
+
+ [rowView insertSubview:typesLabel atIndex:1];
+
+ [rowView insertSubview:personLabel atIndex:3];
+
+ return rowView;
+}
+
+-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
+{
+
+ [self.subTypePicker reloadComponent:0];
+ if ([self.types isEqualToString:@"type"]) {
+ [self setTypeData];
+ self.PickerIndex=[self.typePicker selectedRowInComponent:0];
+ }else if ([self.types isEqualToString:@"subtype"]) {
+ //[self.typePicker reloadComponent:0];
+
+ [self setSubTypeData];
+ }else if ([self.types isEqualToString:@"personnel"]) {
+ [self setPersonData];
+ }
+
+}
+
+
+#pragma mark - UIActionSheetDelegate
+
+
+-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ NSUInteger sourceType = 0;
+ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
+ switch (buttonIndex) {
+ case 0:
+ sourceType = UIImagePickerControllerSourceTypeCamera;
+ break;
+ case 1:
+ sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
+ break;
+ case 2:
+ return;
+ }
+ }else {
+ if (buttonIndex == 1) {
+ return;
+ }else {
+ sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
+ }
+ }
+ UIImagePickerController * imagePickerController = [[UIImagePickerController alloc] init];
+ imagePickerController.delegate = self;
+ imagePickerController.allowsEditing = YES;
+ imagePickerController.sourceType = sourceType;
+ [self presentModalViewController:imagePickerController animated:YES];
+}
+
+#pragma mark - UIImagePickerControllerDelegate
+
+
+-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
+{
+ [picker dismissModalViewControllerAnimated:YES];
+ self.photo = [info objectForKey:UIImagePickerControllerEditedImage];
+ [self.photoButton setImage:self.photo forState:UIControlStateNormal];
+}
+-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
+{
+ [self dismissModalViewControllerAnimated:YES];
+}
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+
+#pragma mark - IBActions
+- (IBAction)choosePhoto:(id)sender {
+ UIActionSheet * choosePhotoActionSheet;
+ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
+ choosePhotoActionSheet = [[UIActionSheet alloc]initWithTitle:NSLocalizedString(@"图片选取方式", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"取消", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"从相机", @""),NSLocalizedString(@"从相机", @""), nil ];
+
+ }else {
+ choosePhotoActionSheet = [[UIActionSheet alloc]initWithTitle:NSLocalizedString(@"图片选取方式", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"取消", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"从相册中选择", @""), nil ];
+
+// take_photo_from_library Replace 从相册中选择
+ }
+ [choosePhotoActionSheet showInView:self.view];
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.h"
new file mode 100644
index 00000000..6940b5e3
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.h"
@@ -0,0 +1,17 @@
+//
+// budgetManagement.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface budgetManagement : NSObject
+
+//给一个预算数,插入预算数据
+-(BOOL)insertIntoBudgetTable:(NSString*)BudgetData;
+//返回总支出金额
+-(NSNumber*)backPayAmount;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.m"
new file mode 100644
index 00000000..c985a117
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/budgetManagement.m"
@@ -0,0 +1,18 @@
+//
+// budgetManagement.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "budgetManagement.h"
+
+@implementation budgetManagement
+-(BOOL)insertIntoBudgetTable:(NSString*)BudgetData{
+ return YES;
+}
+//返回总支出金额
+-(NSNumber*)backPayAmount{
+ return [NSNumber numberWithInt:3];
+}@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.h"
new file mode 100644
index 00000000..f56718db
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.h"
@@ -0,0 +1,13 @@
+//
+// dateViewController.h
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface dateViewController : UITableViewController
+@property(nonatomic,assign)int Month;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.m"
new file mode 100644
index 00000000..8f0381ed
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/dateViewController.m"
@@ -0,0 +1,186 @@
+//
+// dateViewController.m
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "dateViewController.h"
+#import "displayManagement.h"
+#import "displayViewController.h"
+@interface dateViewController ()
+@property(nonatomic,strong)NSMutableDictionary*dic;
+
+@end
+
+@implementation dateViewController
+@synthesize dic,Month;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"date" Month:self.Month];
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+-(void)viewWillAppear:(BOOL)animated{
+
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"date" Month:self.Month];
+ [self.tableView reloadData];
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
+ NSComparator cmptr = ^(id obj1, id obj2){
+ if ([obj1 integerValue] > [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedDescending;
+ }
+
+ if ([obj1 integerValue] < [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedAscending;
+ }
+ return (NSComparisonResult)NSOrderedSame;
+ };
+ NSArray *moth=[[dic allKeys] sortedArrayUsingComparator:cmptr];
+ NSString*title=[NSString stringWithFormat:@"%@ 月 份",[moth objectAtIndex:section]];
+ return title;
+}
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+
+ return [[self.dic allKeys]count];
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ NSComparator cmptr = ^(id obj1, id obj2){
+ if ([obj1 integerValue] > [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedDescending;
+ }
+
+ if ([obj1 integerValue] < [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedAscending;
+ }
+ return (NSComparisonResult)NSOrderedSame;
+ };
+ NSArray *moth=[[dic allKeys] sortedArrayUsingComparator:cmptr];
+
+ NSArray *number=[self.dic objectForKey:[moth objectAtIndex:section]];
+//
+
+ return [number count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"dCell";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ NSComparator cmptr = ^(id obj1, id obj2){
+ if ([obj1 integerValue] > [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedDescending;
+ }
+
+ if ([obj1 integerValue] < [obj2 integerValue]) {
+ return (NSComparisonResult)NSOrderedAscending;
+ }
+ return (NSComparisonResult)NSOrderedSame;
+ };
+ NSArray *moth=[[dic allKeys] sortedArrayUsingComparator:cmptr];
+
+
+ NSNumber*number=[moth objectAtIndex:indexPath.section];
+ NSArray*str=[dic objectForKey:number];
+ payout*str1=[str objectAtIndex:indexPath.row];
+ UILabel *cellLabel=(UILabel *)[cell viewWithTag:1];
+ cellLabel.text=[NSString stringWithFormat:@"%.1f",str1.amount];
+ cellLabel=(UILabel *)[cell viewWithTag:2];
+ cellLabel.text=str1.subType;
+ cellLabel=(UILabel *)[cell viewWithTag:3];
+ cellLabel.text=str1.date;
+ cellLabel=(UILabel *)[cell viewWithTag:4];
+ cellLabel.text=str1.personnel;
+ // Configure the cell...
+
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+}
+*/
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/deposit.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/deposit.png"
new file mode 100644
index 00000000..69b913fb
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/deposit.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/display.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/display.png"
new file mode 100644
index 00000000..132b1fd3
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/display.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.h"
new file mode 100644
index 00000000..d1aa03c4
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.h"
@@ -0,0 +1,23 @@
+//
+// displayManagement.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+#import "billManagement.h"
+@interface displayManagement : NSObject
+@property(nonatomic,strong)billManagement*billM;
+//按月份显示饼图
+-(NSMutableArray*)XYPieChart:(int)Month;
+//用类型为参数,返回以参数为key的字典
+-(NSMutableDictionary*)getClassPayout:(NSString*)TypeOrPersonnel Month:(int)theMonth;//YES
+//查询所有类别
+-(NSArray*)selectType;
+//查询预算
+-(NSNumber*)selectBudget;//YES
+//根据类别查询子类别
+-(NSArray*)selectSubType:(NSString*)Type;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.m"
new file mode 100644
index 00000000..e38dce41
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayManagement.m"
@@ -0,0 +1,103 @@
+//
+// displayManagement.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "displayManagement.h"
+#import "payout.h"
+
+
+@implementation displayManagement
+@synthesize billM;
+-(NSArray*)selectType{
+ NSString *sql=[NSString stringWithFormat:@"SELECT * FROM type"];
+
+ FMResultSet *rs =[billM.Fdb executeQuery:sql];
+
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+ payout*_payout=[[payout alloc]init];
+ _payout.payout_ID=[rs intForColumn:@"ID"];
+ _payout.type=[rs stringForColumn:@"type"];
+ [array addObject:_payout];
+ }
+
+ [rs close];
+
+ return array;
+}
+//根据类别查询子类别
+-(NSArray*)selectSubType:(NSString*)Type{
+ return 0;
+}
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ billM=[[billManagement alloc]init];
+ }
+ return self;
+}
+//按月份显示饼图
+-(NSMutableArray*)XYPieChart:(int)Month{
+
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+
+ NSDictionary*dic=[billM getMonthPayout:Month];
+ if ([[dic allKeys] count]==0) {
+ return nil;
+ }
+
+ NSNumber*key=[[dic allKeys]objectAtIndex:0];
+ for (payout*p in [dic objectForKey:key]) {
+ [array addObject:p];
+ }
+
+
+ return array;
+}
+//查询预算
+-(NSNumber*)selectBudget{
+ FMResultSet *rs =[billM.Fdb executeQuery:@"SELECT * FROM budget"];
+ NSString*str=[[NSString alloc]init];
+ while ([rs next]) {
+
+ str=[rs stringForColumn:@"type"];
+ }
+ return [NSNumber numberWithInt:[str intValue]];
+}
+//用类型为参数,返回以参数为key的字典
+-(NSMutableDictionary*)getClassPayout:(NSString *)TypeOrPersonnel Month:(int)theMonth{
+ int i;
+ if ([TypeOrPersonnel isEqualToString:@"Type"]) {
+ i=1;
+ }else if([TypeOrPersonnel isEqualToString:@"Personnel"]){
+ i=0;
+ }else if ([TypeOrPersonnel isEqualToString:@"date"]){
+ i=2;
+ }
+ NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
+ for (payout *p in [self XYPieChart:theMonth]) {
+ NSString *moth=[NSString stringWithFormat:@"%@",[p getType:i]];
+
+ if ([dic objectForKey:moth]) {
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ array=[dic objectForKey:moth];
+ [array addObject:p];
+ }
+ else{
+ NSMutableArray *array=[[NSMutableArray alloc]init];
+ [array addObject:p];
+ [dic setObject:array forKey:moth];
+ }
+
+ }
+
+ return dic;
+}
+
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.h"
new file mode 100644
index 00000000..340aad30
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.h"
@@ -0,0 +1,35 @@
+//
+// displayViewController.h
+// mount
+//
+// Created by 江山 on 1/6/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+#import "typeViewController.h"
+#import "XYPieChart.h"
+#import "displayManagement.h"
+@interface displayViewController : UIViewController
+
+@property(strong,nonatomic)typeViewController *typeViewController;
+@property (strong, nonatomic) UISegmentedControl *SegmentedControl;
+@property(nonatomic, strong) NSMutableArray *slices;
+@property (strong, nonatomic) IBOutlet UILabel *selectedSliceLabel;
+@property (strong, nonatomic) IBOutlet UILabel *selectedTypeLabel;
+
+@property (strong, nonatomic) IBOutlet UILabel *BudgetLabel;
+@property (strong, nonatomic) IBOutlet XYPieChart *piceChart;
+@property(nonatomic, strong) NSArray *sliceColors;
+@property(nonatomic,strong)UIViewController*typev;
+@property(nonatomic,strong)UIViewController*persv;
+@property(nonatomic,strong)UIViewController*datev;
+@property(nonatomic,strong)displayManagement*displayM;
+
+
+@property(nonatomic,assign)int pickMonth;
+- (IBAction)pickMonth:(id)sender;
+@property (strong, nonatomic) IBOutlet UILabel *MonthLabel;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.m"
new file mode 100644
index 00000000..86f5bdc9
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/displayViewController.m"
@@ -0,0 +1,381 @@
+//
+// displayViewController.m
+// mount
+//
+// Created by 江山 on 1/6/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "displayViewController.h"
+#import "ASDepthModalViewController.h"
+#import
+#import "payout.h"
+#import "personnelViewController.h"
+#import "dateViewController.h"
+@interface displayViewController ()
+
+@end
+
+@implementation displayViewController
+@synthesize selectedSliceLabel;
+@synthesize piceChart,BudgetLabel;
+@synthesize slices,sliceColors;
+@synthesize typeViewController,SegmentedControl;
+@synthesize typev,persv,datev,displayM,pickMonth,MonthLabel,selectedTypeLabel;
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ [self getMoth];
+ [self Init];//
+ [self InitXYPieChart];//初始化饼图
+ [self backButton];//navigation上的返回按钮
+ [self NavigationButtons];//navigation上的分段按钮
+ [self SwipeGestureRecognizer];//滑动代码
+
+
+ [self InitSubView];//初始化子视图
+
+ // Do any additional setup after loading the view.
+}
+-(void)getMoth{
+ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
+ NSDate *now;
+ NSDateComponents *comps = [[NSDateComponents alloc] init];
+ NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
+ NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
+ now=[NSDate date];
+ comps = [calendar components:unitFlags fromDate:now];
+
+ self.pickMonth = [comps month];
+}
+-(void)Init{
+
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"display.png"]];
+ self.displayM=[[displayManagement alloc]init];
+ self.MonthLabel.text=[NSString stringWithFormat:@"%d",self.pickMonth];
+}
+-(void)InitXYPieChart{
+ //-----------------------饼图-------------------
+ self.slices=[[NSMutableArray alloc]init];
+ for (payout* p in [displayM XYPieChart:self.pickMonth] ) {
+
+ [self.slices addObject:[NSNumber numberWithFloat:p.amount]];
+ }
+
+
+
+
+ [self.piceChart setDelegate:self];
+ [self.piceChart setDataSource:self];
+ [self.piceChart setPieCenter:CGPointMake(140, 100)];
+ [self.piceChart setShowPercentage:NO];
+ [self.piceChart setLabelFont:[UIFont fontWithName:@"DBLCDTempBlack" size:24]];
+ self.sliceColors =[NSArray arrayWithObjects:
+ [UIColor colorWithRed:246/255.0 green:155/255.0 blue:0/255.0 alpha:1],
+ [UIColor colorWithRed:129/255.0 green:195/255.0 blue:29/255.0 alpha:1],
+ [UIColor colorWithRed:62/255.0 green:173/255.0 blue:219/255.0 alpha:1],
+ [UIColor colorWithRed:229/255.0 green:66/255.0 blue:115/255.0 alpha:1],
+ [UIColor colorWithRed:148/255.0 green:141/255.0 blue:139/255.0 alpha:1],
+ [UIColor colorWithRed:220/255.0 green:20/255.0 blue:60/255.0 alpha:1],
+ [UIColor colorWithRed:123/255.0 green:104/255.0 blue:238/255.0 alpha:1],
+ [UIColor colorWithRed:95/255.0 green:158/255.0 blue:160/255.0 alpha:1],
+ [UIColor colorWithRed:0/255.0 green:206/255.0 blue:209/255.0 alpha:1],
+ [UIColor colorWithRed:0/255.0 green:255/255.0 blue:255/255.0 alpha:1],
+ [UIColor colorWithRed:0/255.0 green:0/255.0 blue:205/255.0 alpha:1],
+ [UIColor colorWithRed:75/255.0 green:0/255.0 blue:130/255.0 alpha:1],
+ [UIColor colorWithRed:72/255.0 green:61/255.0 blue:139/255.0 alpha:1],
+ [UIColor colorWithRed:176/255.0 green:196/255.0 blue:222/255.0 alpha:1],
+ [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1],
+ [UIColor colorWithRed:95/255.0 green:158/255.0 blue:160/255.0 alpha:1],nil];
+ //-----------------------饼图-------------------
+
+
+}
+-(void)InitSubView{
+ UIStoryboard*storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+
+// self.typev=[storyboard instantiateViewControllerWithIdentifier:@"typeView"];//类型显示
+ typeViewController*type=[storyboard instantiateViewControllerWithIdentifier:@"typeView"];
+ type.Month=self.pickMonth;
+ typev=type;
+ self.typev.view.hidden=YES;
+
+ [self addChildViewController:self.typev];
+ [self.view addSubview:self.typev.view];
+
+ personnelViewController*pers=[storyboard instantiateViewControllerWithIdentifier:@"personnelView"];//成员显示
+ pers.Month=self.pickMonth;
+ persv=pers;
+ self.persv.view.hidden=YES;
+ [self addChildViewController:self.persv];
+ [self.view addSubview:self.persv.view];
+
+ dateViewController*date=[storyboard instantiateViewControllerWithIdentifier:@"dateView"];//时间显示
+ date.Month=self.pickMonth;
+ datev=date;
+ self.datev.view.hidden=YES;
+ [self addChildViewController:self.datev];
+ [self.view addSubview:self.datev.view];
+
+
+}
+
+-(void)SwipeGestureRecognizer{
+ //滑动代码
+
+ UISwipeGestureRecognizer *recognizer;
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
+ [[self view] addGestureRecognizer:recognizer];
+}
+-(void)NavigationButtons{
+ NSArray *Items = [[NSArray alloc] initWithObjects:@"图表查看",@"类型查看",@"人员查看",@"时间查看", nil];
+ self.SegmentedControl = [[UISegmentedControl alloc] initWithItems:Items];
+ self.SegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
+ //SegmentedControl.frame = CGRectMake(90, 30, 180, 30);
+ // 根据索引值,表示mapSegmentedControl默认响应哪个
+ self.SegmentedControl.selectedSegmentIndex = 0;
+ // SegmentedControl.momentary=YES;
+ // 给mapSegmentedContol添加响应方法
+ [self.SegmentedControl addTarget:self action:@selector(selectedMapType:) forControlEvents:UIControlEventValueChanged];
+ UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:self.SegmentedControl];
+
+ self.navigationItem.rightBarButtonItem = segButton;
+}
+-(void)backButton{
+ //-----------------------返回-------------------
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];//UIBarButtonItem
+ //-----------------------返回-------------------
+}
+//-----------------------饼图-------------------
+- (void)viewWillAppear:(BOOL)animated
+{
+ int bg=0;
+ for (NSNumber *number in self.slices) {
+ bg+=[number intValue];
+ }
+ bg=bg-[[displayM selectBudget] intValue];
+ NSString*Budgetstr=[NSString stringWithFormat:@"%d",bg];
+ self.BudgetLabel.text=Budgetstr;
+ [super viewWillAppear:animated];
+}
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+ [self.piceChart reloadData];
+
+}
+- (void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+}
+- (void)viewDidDisappear:(BOOL)animated
+{
+ [super viewDidDisappear:animated];
+}
+#pragma mark - XYPieChart DataSource
+- (NSUInteger)numberOfSlicesInPieChart:(XYPieChart *)pieChart
+{
+ return [self.slices count];
+}
+- (CGFloat)pieChart:(XYPieChart *)pieChart valueForSliceAtIndex:(NSUInteger)index
+{
+ return [[self.slices objectAtIndex:index] intValue];
+}
+
+- (UIColor *)pieChart:(XYPieChart *)pieChart colorForSliceAtIndex:(NSUInteger)index
+{
+
+ return [self.sliceColors objectAtIndex:(index % self.sliceColors.count)];
+}
+#pragma mark - XYPieChart Delegate
+- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index
+{
+ [self performSelector:@selector(ASDepthModalAtIndex:) withObject:[NSNumber numberWithInteger:index] afterDelay:0.3];
+}
+-(void)ASDepthModalAtIndex:(NSNumber *)index{
+ UIColor *color = nil;
+ ASDepthModalOptions style = ASDepthModalOptionAnimationGrow;
+ ASDepthModalOptions options;
+
+
+ UIImage *image;
+
+
+ image = [UIImage imageNamed:@"pattern1.jpg"];
+ color = [UIColor colorWithPatternImage:image];
+
+
+ style = ASDepthModalOptionAnimationShrink;
+
+ options =ASDepthModalOptionBlur;
+
+ UIView *Nib=[[[UINib nibWithNibName:@"ASDepthModal" bundle:nil] instantiateWithOwner:nil options:nil] objectAtIndex:0];
+
+ Nib.layer.cornerRadius = 12;
+ Nib.layer.shadowOpacity = 0.7;
+ Nib.layer.shadowOffset = CGSizeMake(6, 6);
+ Nib.layer.shouldRasterize = YES;
+ Nib.layer.rasterizationScale = [[UIScreen mainScreen] scale];
+ [Nib setAlpha:0.7];
+ UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
+ [button setFrame:Nib.frame];
+ [button addTarget:self action:@selector(ASDepthModalViewDismiss) forControlEvents:UIControlEventTouchUpInside];
+ [Nib addSubview:button];
+ [self InitASDepthModalLable:Nib LabelStr:index];
+ [ASDepthModalViewController presentView:Nib
+ backgroundColor:color
+ options:options
+ completionHandler:^{
+ NSLog(@"Modal view closed.");
+ }];
+}
+-(void)ASDepthModalViewDismiss{
+ [ASDepthModalViewController dismiss];
+}
+-(void)InitASDepthModalLable:(UIView*)view LabelStr:(NSNumber*)index{
+ UILabel*money=[[UILabel alloc]initWithFrame:CGRectMake(10, 10,100, 50)];
+ UILabel*per=[[UILabel alloc]initWithFrame:CGRectMake(10, 50,100, 50)];
+ UILabel*type=[[UILabel alloc]initWithFrame:CGRectMake(10, 90,100, 50)];
+ UILabel*subType=[[UILabel alloc]initWithFrame:CGRectMake(10, 130,100, 50)];
+ UILabel*date=[[UILabel alloc]initWithFrame:CGRectMake(10, 150,100, 80)];
+ UIImage*image=[UIImage imageNamed:@"404error.png"];
+
+ UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(view.frame.size.width/2-30, view.frame.size.height/2-110,150, 150)];
+
+ NSMutableArray*array=[displayM XYPieChart:self.pickMonth];
+ payout*p=[array objectAtIndex:[index integerValue]];
+ type.text=p.type;
+ subType.text=p.subType;
+ date.text=p.date;
+ per.text=p.personnel;
+ money.text=[NSString stringWithFormat:@"¥%.0f",p.amount];
+ if (p.image!=nil) {
+ image=[UIImage imageWithData:p.image];
+ }
+ [imageView setImage:image];
+ [view addSubview:per];
+ [view addSubview:date];
+ [view addSubview:subType];
+ [view addSubview:imageView];
+ [view addSubview:money];
+ [view addSubview:type];
+}
+//-----------------------饼图-------------------
+
+-(void)backBtnAction{
+ [self.navigationController popViewControllerAnimated:YES];
+}
+
+-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
+
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
+
+
+ [self.navigationController popViewControllerAnimated:YES];
+// NSLog(@"swipe Right");
+
+ //执行程序
+
+ }
+}
+-(void)selectedMapType:(id)sender
+{
+ UISegmentedControl *control = (UISegmentedControl *)sender;
+ if (SegmentedControl) {
+
+
+ if (control.selectedSegmentIndex == 0) {
+
+ self.typev.view.hidden=YES;
+ self.persv.view.hidden=YES;
+ self.datev.view.hidden=YES;
+ [self InitXYPieChart];
+ [self.piceChart reloadData];
+ }
+ else if (control.selectedSegmentIndex == 1) {
+ self.typev.view.hidden=NO;
+
+ self.persv.view.hidden=YES;
+ self.datev.view.hidden=YES;
+
+ }
+ else if (control.selectedSegmentIndex == 2) {
+
+ self.typev.view.hidden=YES;
+ self.persv.view.hidden=NO;
+ self.datev.view.hidden=YES;
+ }
+ else if (control.selectedSegmentIndex == 3) {
+ self.typev.view.hidden=YES;
+ self.persv.view.hidden=YES;
+ self.datev.view.hidden=NO;
+
+
+ }
+ }
+}
+- (void)viewDidUnload
+{
+ [self setPiceChart:nil];
+ [self setSelectedSliceLabel:nil];
+ [self setSelectedTypeLabel:nil];
+ [self setMonthLabel:nil];
+ [self setBudgetLabel:nil];
+ [super viewDidUnload];
+
+ // Release any retained subviews of the main view.
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+- (IBAction)pickMonth:(id)sender {
+ int bg=0;
+ for (NSNumber *number in self.slices) {
+ bg+=[number intValue];
+ }
+ bg=bg-[[displayM selectBudget] intValue];
+ NSString*Budgetstr=[NSString stringWithFormat:@"%d",bg];
+ self.BudgetLabel.text=Budgetstr;
+
+
+ if ([sender tag]==11) {
+ if (self.pickMonth<=1) {
+ self.pickMonth=13;
+ }
+
+ self.pickMonth-=1;
+ [self InitSubView];
+ self.MonthLabel.text=[NSString stringWithFormat:@"%d",self.pickMonth];
+ [self InitXYPieChart];
+ [[self piceChart] reloadData];
+ self.selectedSliceLabel.text=@"";
+ self.selectedTypeLabel.text=@"";
+
+ }else{
+ if (self.pickMonth>=12) {
+ self.pickMonth=0;
+ }
+ self.pickMonth+=1;
+ [self InitSubView];
+ self.MonthLabel.text=[NSString stringWithFormat:@"%d",self.pickMonth];
+ [self InitXYPieChart];
+ [[self piceChart] reloadData];
+ self.selectedSliceLabel.text=@"";
+ self.selectedTypeLabel.text=@"";
+
+ }
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/InfoPlist.strings" "b/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/InfoPlist.strings"
new file mode 100644
index 00000000..477b28ff
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/InfoPlist.strings"
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/MainStoryboard.storyboard" "b/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/MainStoryboard.storyboard"
new file mode 100644
index 00000000..6bee80b5
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/en.lproj/MainStoryboard.storyboard"
@@ -0,0 +1,955 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.h"
new file mode 100644
index 00000000..6e6b1eaf
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.h"
@@ -0,0 +1,17 @@
+//
+// enterTheCategoryViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface enterTheCategoryViewController : UIViewController
+@property (weak, nonatomic) IBOutlet UILabel *TitleLabel;
+@property (strong, nonatomic) IBOutlet UITextField *TextFieldStr;
+@property (strong, nonatomic) IBOutlet UILabel *TextFieldName;
+- (IBAction)addButton:(id)sender;
+@property(nonatomic,strong)NSNumber*number;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.m"
new file mode 100644
index 00000000..519576d0
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/enterTheCategoryViewController.m"
@@ -0,0 +1,88 @@
+//
+// enterTheCategoryViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "enterTheCategoryViewController.h"
+#import "settingManagement.h"
+#import "addSubtypeViewController.h"
+#define kTypeTable @"type"
+#define kSubTypeTable @"subtype"
+#define kPersonnel @"personnel"
+
+@interface enterTheCategoryViewController ()
+@property(nonatomic,strong)settingManagement*settingM;
+@property(nonatomic,strong)NSNumber*type_id;
+@end
+
+@implementation enterTheCategoryViewController
+@synthesize number,settingM,TextFieldStr,type_id;
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+
+ [super viewDidLoad];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"add.png"]];
+ [self InitTitle];
+ self.settingM=[[settingManagement alloc]init];
+ if ([self.number intValue]==4) {
+ self.TextFieldStr.keyboardType=UIKeyboardTypeNumberPad;
+ }
+ // Do any additional setup after loading the view.
+}
+-(void)InitTitle{
+ if ([self.number intValue]==1) {
+ self.TitleLabel.text=@"欢迎进入类别添加!";
+ self.TextFieldName.text=@"请输入类别:";
+ }else if ([self.number intValue]==2){
+ self.TitleLabel.text=@"欢迎进入子类别添加!";
+ self.TextFieldName.text=@"请输入子类别:";
+ }else if ([self.number intValue]==3){
+ self.TitleLabel.text=@"欢迎进入成员添加!";
+ self.TextFieldName.text=@"请输入成员:";
+ }else if ([self.number intValue]==4){
+
+ self.TitleLabel.text=@"欢迎进预算添加!";
+ self.TextFieldName.text=@"请输入预算金额:";
+ }
+}
+
+- (void)viewDidUnload
+{
+ [self setTextFieldStr:nil];
+ [self setTitleLabel:nil];
+ [self setTextFieldName:nil];
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+- (IBAction)addButton:(id)sender {
+ if ([self.number intValue]==1) {
+ [self.settingM AddPayoutTypeData:kTypeTable str:self.TextFieldStr.text];
+ }else if ([self.number intValue]==2){
+ [self.settingM AddSubType:self.type_id subtype:self.TextFieldStr.text];
+
+ }else if ([self.number intValue]==3){
+ [self.settingM AddPayoutTypeData:kPersonnel str:self.TextFieldStr.text];
+ }else if ([self.number intValue]==4){
+
+ [self.settingM insertIntoBudgetTable:[NSNumber numberWithInt:[self.TextFieldStr.text intValue]]];
+ }
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/female.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/female.png"
new file mode 100644
index 00000000..f2b1bc9a
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/female.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/icon.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/icon.png"
new file mode 100644
index 00000000..269032a7
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/icon.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/left-direction.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/left-direction.png"
new file mode 100644
index 00000000..30ada09c
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/left-direction.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/long.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/long.png"
new file mode 100644
index 00000000..43ef18e7
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/long.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/main.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/main.m"
new file mode 100644
index 00000000..d72172cb
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/main.m"
@@ -0,0 +1,18 @@
+//
+// main.m
+// mount
+//
+// Created by zd2011 on 13-5-2.
+// Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
+//
+
+#import
+
+#import "AppDelegate.h"
+
+int main(int argc, char *argv[])
+{
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/male.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/male.png"
new file mode 100644
index 00000000..44d11644
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/male.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Info.plist" "b/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Info.plist"
new file mode 100644
index 00000000..5d8260f2
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Info.plist"
@@ -0,0 +1,50 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleDisplayName
+ ${PRODUCT_NAME}
+ CFBundleExecutable
+ ${EXECUTABLE_NAME}
+ CFBundleIcons
+
+ CFBundlePrimaryIcon
+
+ CFBundleIconFiles
+
+ icon.png
+
+
+
+ CFBundleIdentifier
+ com.zdsoft.${PRODUCT_NAME:rfc1034identifier}
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ ${PRODUCT_NAME}
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1.0
+ LSRequiresIPhoneOS
+
+ UIMainStoryboardFile
+ MainStoryboard
+ UIRequiredDeviceCapabilities
+
+ armv7
+
+ UISupportedInterfaceOrientations
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Prefix.pch" "b/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Prefix.pch"
new file mode 100644
index 00000000..ea45b358
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/mount-Prefix.pch"
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'mount' target in the 'mount' project
+//
+
+#import
+
+#ifndef __IPHONE_5_0
+#warning "This project uses features only available in iOS SDK 5.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import
+ #import
+#endif
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/pattern1.jpg" "b/21451130\346\261\237\345\261\261/FinalProject/mount/pattern1.jpg"
new file mode 100644
index 00000000..bc849f87
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/pattern1.jpg" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/payout.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.h"
new file mode 100644
index 00000000..1c0d4d30
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.h"
@@ -0,0 +1,22 @@
+//
+// payout.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface payout : NSObject
+@property(assign,nonatomic) int payout_ID;//帐单ID
+@property (assign,nonatomic) float amount;//金额
+@property (copy,nonatomic) NSString *date;//时间
+@property (copy,nonatomic) NSString *type;//类型
+@property (copy,nonatomic) NSString *subType;//子类型
+@property (copy,nonatomic) NSString *comment;//备注
+@property (copy,nonatomic) NSData *image;//照片
+@property (copy,nonatomic) NSString *personnel;//成员
+-(int)getMonth;
+-(NSString*)getType:(int)typeOrPersonnel;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/payout.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.m"
new file mode 100644
index 00000000..29315018
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.m"
@@ -0,0 +1,80 @@
+//
+// payout.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "payout.h"
+#define kAmount @"amount"
+#define kDate @"date"
+#define kType @"type"
+#define kSuType @"suType"
+#define kComment @"comment"
+#define kPersonnel @"personnel"
+#define kPayout_ID @"ID"
+
+@implementation payout
+@synthesize payout_ID,amount,date,type,subType,comment,image,personnel;
+
+-(NSString *)description{
+ NSString *str=[[NSString alloc]initWithFormat:@"id:%d; amount:%f; date:%@; type:%@; subType:%@; comment:%@; image:%@; personnel:%@", payout_ID,amount,date,type,subType,comment,image,personnel];
+ return str;
+}
+
+
+-(void)encodeWithCoder:(NSCoder *)aCoder{
+ [aCoder encodeInt:payout_ID forKey:kPayout_ID];
+ [aCoder encodeFloat:amount forKey:kAmount];
+ [aCoder encodeObject:type forKey:kType];
+ [aCoder encodeDataObject:image];
+ [aCoder encodeObject:date forKey:kDate];
+ [aCoder encodeObject:subType forKey:kSuType];
+ [aCoder encodeObject:comment forKey:kComment];
+ [aCoder encodeObject:personnel forKey:kPersonnel];
+
+}
+
+-(id)initWithCoder:(NSCoder *)aDecoder{
+ if (self=[super init]) {
+ payout_ID=[aDecoder decodeIntForKey:kPayout_ID];
+ amount=[aDecoder decodeFloatForKey:kAmount];
+ date=[aDecoder decodeObjectForKey:kDate];
+ type=[aDecoder decodeObjectForKey:kType];
+ subType=[aDecoder decodeObjectForKey:kSuType];
+ comment=[aDecoder decodeObjectForKey:kComment];
+ image=[aDecoder decodeDataObject];
+ personnel=[aDecoder decodeObjectForKey:kPersonnel];
+
+ }
+ return self;
+}
+-(int)getMonth{
+ //转换日期格式
+ NSDateFormatter *Formatter = [[NSDateFormatter alloc] init];
+ [Formatter setDateFormat:@"yyyy-MM-dd"];// HH:mm:ss
+ NSDate*da=[Formatter dateFromString:self.date];
+ //取出月份
+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
+ [dateFormatter setDateFormat:@"MM"];
+ NSString *destDateString = [dateFormatter stringFromDate:da];
+
+ return [destDateString intValue];
+
+}
+-(NSString*)getType:(int)typeOrPersonnel{
+ //为1返回类型,为其它数返回人员
+ if (typeOrPersonnel==1) {
+
+ return self.type;
+
+ }else if (typeOrPersonnel==2){
+ NSString*str=[NSString stringWithFormat:@"%d",[self getMonth]];
+ return str;
+ }
+ return self.personnel;
+}
+
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/payout.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.png"
new file mode 100644
index 00000000..c4ff1bb3
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/payout.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.h"
new file mode 100644
index 00000000..7e660454
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.h"
@@ -0,0 +1,13 @@
+//
+// personnelViewController.h
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface personnelViewController : UITableViewController
+@property(nonatomic,assign)int Month;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.m"
new file mode 100644
index 00000000..aec26d39
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/personnelViewController.m"
@@ -0,0 +1,152 @@
+//
+// personnelViewController.m
+// mount
+//
+// Created by 江山 on 12/3/14.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "personnelViewController.h"
+#import "displayManagement.h"
+#import "displayViewController.h"
+@interface personnelViewController ()
+@property(nonatomic,strong)NSMutableDictionary*dic;
+
+@end
+
+@implementation personnelViewController
+@synthesize dic,Month;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+
+// UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+// displayViewController*displayV=[storyboard instantiateViewControllerWithIdentifier:@"display"];
+// self.Month=displayV.pickMonth;
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"personnel" Month:self.Month];
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+-(void)viewWillAppear:(BOOL)animated{
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"personnel" Month:self.Month];
+ [self.tableView reloadData];
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return [[self.dic allKeys] count];
+}
+-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
+ NSArray *moth=[[dic allKeys]sortedArrayUsingSelector:@selector(compare:)];
+ return [moth objectAtIndex:section];
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ NSArray *moth=[[self.dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSArray *number=[self.dic objectForKey:[moth objectAtIndex:section]];
+
+ return [number count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"pcell";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ NSArray *moth=[[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSNumber*number=[moth objectAtIndex:indexPath.section];
+ NSArray*str=[dic objectForKey:number];
+ payout*str1=[str objectAtIndex:indexPath.row];
+ UILabel *cellLabel=(UILabel *)[cell viewWithTag:1];
+ cellLabel.text=[NSString stringWithFormat:@"%.1f",str1.amount];
+ cellLabel=(UILabel *)[cell viewWithTag:2];
+ cellLabel.text=str1.subType;
+ cellLabel=(UILabel *)[cell viewWithTag:3];
+ cellLabel.text=str1.date;
+ cellLabel=(UILabel *)[cell viewWithTag:4];
+ cellLabel.text=str1.personnel;
+ // Configure the cell...
+
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+}
+*/
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/right-direction.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/right-direction.png"
new file mode 100644
index 00000000..e361f12d
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/right-direction.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/setting.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/setting.png"
new file mode 100644
index 00000000..f6c0e656
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/setting.png" differ
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.h"
new file mode 100644
index 00000000..94fb8fa3
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.h"
@@ -0,0 +1,36 @@
+//
+// typeManagement.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+#import "FMDatabase.h"
+@interface settingManagement : NSObject
++(settingManagement *)openCommentDatabase;//YES
+//查询预算
+-(NSNumber*)selectBudget;//YES
+//查询所有类别
+-(NSMutableDictionary*)selectTypeOfpersonnel:(NSString*)TableName;//YES
+//查询子类别
+-(NSMutableArray*)selectSubType:(NSNumber*)type_id;
+//查询所有人员
+//-(NSMutableArray*)selectPersonnel;
+//添加账单类型数据,人员数据,带入表名和要添加的数据即可添加
+-(void)AddPayoutTypeData:(NSString*)TableName str:(NSString*)str;//YES
+//代入父类别id 添加子类别
+-(void)AddSubType:(NSNumber*)type_id subtype:(NSString*)subtypeStr;
+//代入父类别id 删除子类别
+-(void)DeleteSubType:(NSNumber*)type_id subtype:(NSString*)subtypeStr;
+//删除账单类型数据,人员数据,带入表名和要删除的数据即可删除
+-(void)DeletePayoutTypeData:(NSString*)TableName payout_ID:(NSNumber*)payout_ID;//YES
+//给一个预算数,插入预算数据
+-(void)insertIntoBudgetTable:(NSNumber*)BudgetNumber;//YES
+//备份账单数据库
+-(void)backupsPayoutDataBase;
+//还原账单数据库
+-(void)restorePayoutDataBase;
+-(void)DeleteSQLiteData;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.m"
new file mode 100644
index 00000000..ea651d42
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingManagement.m"
@@ -0,0 +1,180 @@
+//
+// typeManagement.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "settingManagement.h"
+#define kDatabaseName @"mount.sqlite"
+
+@implementation settingManagement
+{
+ FMDatabase*Fdb;
+}
++(settingManagement *)openCommentDatabase
+{
+ static settingManagement *aDatabase=nil;
+ static dispatch_once_t predicate;
+ dispatch_once(&predicate, ^{
+ aDatabase = [[self alloc] init];
+ });
+ return aDatabase;
+}
+//设置数据库文件路径
+-(NSString*)FilePaths{
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentDirectory = [paths objectAtIndex:0];
+ NSString *dbPath = [documentDirectory stringByAppendingPathComponent:kDatabaseName];
+ if (![Fdb open]) {
+ NSLog(@"Could not open Fdb.");
+ }
+// NSLog(@"%@",dbPath);
+ return dbPath;
+}
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ Fdb=[FMDatabase databaseWithPath:[self FilePaths]];
+ if (![Fdb open]) {
+ NSLog(@"OPEN FAIL");
+ }
+ }
+ return self;
+}
+//查询预算
+-(NSNumber *)selectBudget{
+ float budget;
+ FMResultSet *rs =[Fdb executeQuery:@"SELECT * FROM budget"];
+
+ while ([rs next]) {
+
+ budget = [rs doubleForColumn:@"budget"];
+
+ }
+
+ [rs close];
+
+ return [NSNumber numberWithFloat:budget];
+
+}
+//添加账单类型数据,人员数据,带入表名和要添加的数据即可添加
+-(void)AddPayoutTypeData:(NSString*)TableName str:(NSString*)str{
+
+ if ([TableName isEqualToString:@"type"]) {
+ NSString*sql=[NSString stringWithFormat:@"insert into %@(type) values ('%@')",TableName,str];
+ [Fdb executeUpdate:sql];
+ }else if ([TableName isEqualToString:@"personnel"]) {
+ NSString*sql=[NSString stringWithFormat:@"insert into %@(personnel) values ('%@')",TableName,str];
+ [Fdb executeUpdate:sql];
+ }
+
+}
+//代入父类别id 添加子类别
+-(void)AddSubType:(NSNumber*)type_id subtype:(NSString*)subtypeStr{
+ NSString*sql=[NSString stringWithFormat:@"insert into subtype(type_id,subtype) values ('%@','%@')",type_id,subtypeStr];
+ [Fdb executeUpdate:sql];
+}
+//删除账单类型数据,人员数据,带入表名和要删除的数据即可删除
+-(void)DeletePayoutTypeData:(NSString*)TableName payout_ID:(NSNumber*)payout_ID{
+ BOOL a;
+
+// if ([TableName isEqualToString:@"type"]) {
+ NSString*sql=[NSString stringWithFormat:@"DELETE FROM %@ WHERE ID = ?",TableName];
+ a=[Fdb executeUpdate:sql,payout_ID];
+// }else if ([TableName isEqualToString:@"subtype"]) {
+// NSString*sql=[NSString stringWithFormat:@"DELETE FROM %@ WHERE ID = ?",TableName];
+// a=[Fdb executeUpdate:sql,payout_ID];
+// }else if ([TableName isEqualToString:@"personnel"]) {
+// NSString*sql=[NSString stringWithFormat:@"DELETE FROM %@ WHERE ID = ?",TableName];
+// a=[Fdb executeUpdate:sql,payout_ID];
+// }
+ if (a) {
+ NSLog(@"%@ %@ 删除成功!",TableName,payout_ID);
+ }else {
+ NSLog(@"%@ %@ 删除失败!",TableName,payout_ID);
+ }
+
+}
+//给一个预算数,插入预算数据
+-(void)insertIntoBudgetTable:(NSNumber*)BudgetNumber{
+
+ [Fdb executeUpdate:@"delete from budget"];
+ [Fdb executeUpdate:@"insert into budget(budget) values (?)",BudgetNumber];
+}
+//代入父类别id 删除子类别
+-(void)DeleteSubType:(NSNumber*)type_id subtype:(NSString*)subtypeStr{
+ NSString*sql=[NSString stringWithFormat:@"DELETE FROM subtype where type_id= %@ and subtype='%@'",type_id,subtypeStr];
+ [Fdb executeUpdate:sql];
+}
+//查询所有类别
+-(NSMutableDictionary*)selectTypeOfpersonnel:(NSString *)TableName{
+ NSString*sql=[NSString stringWithFormat:@"SELECT * FROM %@",TableName];
+ FMResultSet *rs =[Fdb executeQuery:sql];
+ NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
+ while ([rs next]) {
+
+// dic= [rs doubleForColumn:@"type"];
+ [dic setObject:[rs stringForColumn:TableName] forKey:[rs stringForColumn:@"ID"]];
+ }
+
+ [rs close];
+
+ return dic;
+}
+//查询所有人员
+/*
+-(NSMutableArray*)selectPersonnel{
+ FMResultSet *rs =[Fdb executeQuery:@"SELECT * FROM personnel"];
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+
+ NSString*str= [rs stringForColumn:@"personnel"];
+ [array addObject:str];
+ }
+
+ [rs close];
+
+
+ return array;
+}*/
+//备份账单数据库
+-(void)backupsPayoutDataBase{
+
+}
+//还原账单数据库
+-(void)restorePayoutDataBase{
+
+}
+-(void)DeleteSQLiteData{
+// NSFileManager *fileManager = [NSFileManager defaultManager];
+// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+// NSString *documentsDirectory = [paths objectAtIndex:0];
+// //更改到待操作的目录下
+// [fileManager changeCurrentDirectoryPath:[documentsDirectory stringByExpandingTildeInPath]];
+// //创建文件fileName文件名称,contents文件的内容,如果开始没有内容可以设置为nil,attributes文件的属性,初始为nil
+// NSString * fileName = @"mount.sqlite";
+// [fileManager removeItemAtPath:fileName error:nil];
+//
+// NSLog(@"settingManagement_Delete!!!!!");
+ [Fdb executeUpdate:@"DROP TABLE payout"];
+ [Fdb executeUpdate:@"CREATE TABLE IF NOT EXISTS PAYOUT(ID INTEGER PRIMARY KEY AUTOINCREMENT,amount double,date date,type text,subtype text,comment text,image blob,personnel text)"];
+}
+//查询子类别
+-(NSMutableArray*)selectSubType:(NSNumber*)type_id{
+ FMResultSet *rs =[Fdb executeQuery:@"SELECT * FROM subtype where type_id =?",type_id];
+ NSMutableArray*array=[[NSMutableArray alloc]init];
+ while ([rs next]) {
+
+ NSString*str= [rs stringForColumn:@"subtype"];
+ [array addObject:str];
+ }
+
+ [rs close];
+
+
+ return array;
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.h"
new file mode 100644
index 00000000..441a4e7d
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.h"
@@ -0,0 +1,15 @@
+//
+// settingViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface settingViewController : UIViewController
+- (IBAction)DeleteData:(id)sender;
+- (IBAction)BudgetAction:(id)sender;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.m"
new file mode 100644
index 00000000..5a7ba03a
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/settingViewController.m"
@@ -0,0 +1,145 @@
+//
+// settingViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "settingViewController.h"
+#import
+#import "UIGlossyButton.h"
+#import "UIView+LayerEffects.h"
+#import "settingManagement.h"
+#import "enterTheCategoryViewController.h"
+@interface settingViewController ()
+@property(nonatomic,strong)settingManagement*settingM;
+@end
+
+@implementation settingViewController
+@synthesize settingM;
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"setting.png"]];
+ settingM=[[settingManagement alloc]init];
+ //-----------------------返回-------------------
+ self.navigationItem.hidesBackButton=YES;
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];//UIBarButtonItem
+ //-----------------------返回-------------------
+
+//-----------------------自定义button-------------------
+ UIGlossyButton *b;
+ b = (UIGlossyButton*) [self.view viewWithTag: 1001];
+ [b setActionSheetButtonWithColor: [UIColor redColor]];
+
+// b = (UIGlossyButton*) [self.view viewWithTag: 1003];
+// [b useWhiteLabel: YES]; b.tintColor = [UIColor clearColor];
+// [b setShadow:[UIColor blackColor] opacity:0.8 offset:CGSizeMake(0, 1) blurRadius: 4];
+//
+// b = (UIGlossyButton*) [self.view viewWithTag: 1004];
+// [b useWhiteLabel: YES]; b.tintColor = [UIColor clearColor];
+// [b setShadow:[UIColor blackColor] opacity:0.8 offset:CGSizeMake(0, 1) blurRadius: 4];
+
+// b = (UIGlossyButton*) [self.view viewWithTag: 1005];
+// [b useWhiteLabel: YES]; b.tintColor = [UIColor clearColor];
+// [b setShadow:[UIColor blackColor] opacity:0.8 offset:CGSizeMake(0, 1) blurRadius: 4];
+
+// b = (UIGlossyButton*) [self.view viewWithTag: 1002];
+// [b useWhiteLabel: YES]; b.tintColor = [UIColor darkGrayColor];
+// [b setShadow:[UIColor blackColor] opacity:0.8 offset:CGSizeMake(0, 1) blurRadius: 4];
+// b.invertGraidentOnSelected = YES;
+//-----------------------自定义button-------------------
+
+ UISwipeGestureRecognizer *recognizer;
+
+ recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
+
+ [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
+
+ [[self view] addGestureRecognizer:recognizer];
+ // Do any additional setup after loading the view.
+}
+
+-(void)backBtnAction{
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.5;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromRight;//方向
+
+ [self.navigationController.view setBackgroundColor:[UIColor whiteColor]];//
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+
+ [self.navigationController popViewControllerAnimated:NO];
+ [self.navigationController.view removeFromSuperview];
+}
+
+-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
+
+ if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
+ CATransition*transition=[CATransition animation];
+ transition.duration=0.3;
+ transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ transition.type=kCATransitionPush;
+ transition.subtype=kCATransitionFromRight;//方向
+
+ [self.navigationController.view setBackgroundColor:[UIColor colorWithRed:0.0 green:156.0/255 blue:181.0/255 alpha:1]];
+ [self.navigationController.view.layer addAnimation:transition forKey:nil];
+
+ [self.navigationController popViewControllerAnimated:NO];
+ NSLog(@"swipe Left");
+
+ //执行程序
+
+ }
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+- (IBAction)DeleteData:(id)sender {
+ UIActionSheet *actionSheet = [[UIActionSheet alloc]
+ initWithTitle:@"你确定要删除吗?"
+ delegate:self
+ cancelButtonTitle:@"取消"
+ destructiveButtonTitle:@"删除"
+ otherButtonTitles:nil];
+ actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
+ [actionSheet showInView:self.view];
+
+
+
+}
+-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ if (buttonIndex == 0) {
+ [settingM DeleteSQLiteData];
+ }
+
+}
+- (IBAction)BudgetAction:(id)sender {
+ UIStoryboard*storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ enterTheCategoryViewController*enter=[storyboard instantiateViewControllerWithIdentifier:@"enter"];
+ // [enter setValue:[NSNumber numberWithInt:1] forKey:@"number"];
+ enter.number=[NSNumber numberWithInt:4];
+
+ [self.navigationController pushViewController:enter animated:YES];
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.h"
new file mode 100644
index 00000000..843e5ae5
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.h"
@@ -0,0 +1,155 @@
+#import
+#import "sqlite3.h"
+#import "FMResultSet.h"
+#import "FMDatabasePool.h"
+
+
+#if ! __has_feature(objc_arc)
+ #define FMDBAutorelease(__v) ([__v autorelease]);
+ #define FMDBReturnAutoreleased FMDBAutorelease
+
+ #define FMDBRetain(__v) ([__v retain]);
+ #define FMDBReturnRetained FMDBRetain
+
+ #define FMDBRelease(__v) ([__v release]);
+
+ #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v));
+#else
+ // -fobjc-arc
+ #define FMDBAutorelease(__v)
+ #define FMDBReturnAutoreleased(__v) (__v)
+
+ #define FMDBRetain(__v)
+ #define FMDBReturnRetained(__v) (__v)
+
+ #define FMDBRelease(__v)
+
+ #if TARGET_OS_IPHONE
+ // Compiling for iOS
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
+ // iOS 6.0 or later
+ #define FMDBDispatchQueueRelease(__v)
+ #else
+ // iOS 5.X or earlier
+ #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v));
+ #endif
+ #else
+ // Compiling for Mac OS X
+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
+ // Mac OS X 10.8 or later
+ #define FMDBDispatchQueueRelease(__v)
+ #else
+ // Mac OS X 10.7 or earlier
+ #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v));
+ #endif
+ #endif
+#endif
+
+
+@interface FMDatabase : NSObject {
+
+ sqlite3* _db;
+ NSString* _databasePath;
+ BOOL _logsErrors;
+ BOOL _crashOnErrors;
+ BOOL _traceExecution;
+ BOOL _checkedOut;
+ BOOL _shouldCacheStatements;
+ BOOL _isExecutingStatement;
+ BOOL _inTransaction;
+ int _busyRetryTimeout;
+
+ NSMutableDictionary *_cachedStatements;
+ NSMutableSet *_openResultSets;
+ NSMutableSet *_openFunctions;
+
+}
+
+
+@property (atomic, assign) BOOL traceExecution;
+@property (atomic, assign) BOOL checkedOut;
+@property (atomic, assign) int busyRetryTimeout;
+@property (atomic, assign) BOOL crashOnErrors;
+@property (atomic, assign) BOOL logsErrors;
+@property (atomic, retain) NSMutableDictionary *cachedStatements;
+
+
++ (id)databaseWithPath:(NSString*)inPath;
+- (id)initWithPath:(NSString*)inPath;
+
+- (BOOL)open;
+#if SQLITE_VERSION_NUMBER >= 3005000
+- (BOOL)openWithFlags:(int)flags;
+#endif
+- (BOOL)close;
+- (BOOL)goodConnection;
+- (void)clearCachedStatements;
+- (void)closeOpenResultSets;
+- (BOOL)hasOpenResultSets;
+
+// encryption methods. You need to have purchased the sqlite encryption extensions for these to work.
+- (BOOL)setKey:(NSString*)key;
+- (BOOL)rekey:(NSString*)key;
+
+- (NSString *)databasePath;
+
+- (NSString*)lastErrorMessage;
+
+- (int)lastErrorCode;
+- (BOOL)hadError;
+- (NSError*)lastError;
+
+- (sqlite_int64)lastInsertRowId;
+
+- (sqlite3*)sqliteHandle;
+
+- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ...;
+- (BOOL)executeUpdate:(NSString*)sql, ...;
+- (BOOL)executeUpdateWithFormat:(NSString *)format, ...;
+- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;
+- (BOOL)executeUpdate:(NSString*)sql withParameterDictionary:(NSDictionary *)arguments;
+
+- (FMResultSet *)executeQuery:(NSString*)sql, ...;
+- (FMResultSet *)executeQueryWithFormat:(NSString*)format, ...;
+- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
+- (FMResultSet *)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary *)arguments;
+
+- (BOOL)rollback;
+- (BOOL)commit;
+- (BOOL)beginTransaction;
+- (BOOL)beginDeferredTransaction;
+- (BOOL)inTransaction;
+- (BOOL)shouldCacheStatements;
+- (void)setShouldCacheStatements:(BOOL)value;
+
+#if SQLITE_VERSION_NUMBER >= 3007000
+- (BOOL)startSavePointWithName:(NSString*)name error:(NSError**)outErr;
+- (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError**)outErr;
+- (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError**)outErr;
+- (NSError*)inSavePoint:(void (^)(BOOL *rollback))block;
+#endif
+
++ (BOOL)isSQLiteThreadSafe;
++ (NSString*)sqliteLibVersion;
+
+- (int)changes;
+
+- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block;
+
+@end
+
+@interface FMStatement : NSObject {
+ sqlite3_stmt *_statement;
+ NSString *_query;
+ long _useCount;
+}
+
+@property (atomic, assign) long useCount;
+@property (atomic, retain) NSString *query;
+@property (atomic, assign) sqlite3_stmt *statement;
+
+- (void)close;
+- (void)reset;
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.m"
new file mode 100644
index 00000000..5f8b51a3
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabase.m"
@@ -0,0 +1,1162 @@
+#import "FMDatabase.h"
+#import "unistd.h"
+#import
+
+@interface FMDatabase ()
+
+- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
+- (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
+@end
+
+@implementation FMDatabase
+@synthesize cachedStatements=_cachedStatements;
+@synthesize logsErrors=_logsErrors;
+@synthesize crashOnErrors=_crashOnErrors;
+@synthesize busyRetryTimeout=_busyRetryTimeout;
+@synthesize checkedOut=_checkedOut;
+@synthesize traceExecution=_traceExecution;
+
++ (id)databaseWithPath:(NSString*)aPath {
+ return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath]);
+}
+
++ (NSString*)sqliteLibVersion {
+ return [NSString stringWithFormat:@"%s", sqlite3_libversion()];
+}
+
++ (BOOL)isSQLiteThreadSafe {
+ // make sure to read the sqlite headers on this guy!
+ return sqlite3_threadsafe() != 0;
+}
+
+- (id)initWithPath:(NSString*)aPath {
+
+ assert(sqlite3_threadsafe()); // whoa there big boy- gotta make sure sqlite it happy with what we're going to do.
+
+ self = [super init];
+
+ if (self) {
+ _databasePath = [aPath copy];
+ _openResultSets = [[NSMutableSet alloc] init];
+ _db = 0x00;
+ _logsErrors = 0x00;
+ _crashOnErrors = 0x00;
+ _busyRetryTimeout = 0x00;
+ }
+
+ return self;
+}
+
+- (void)finalize {
+ [self close];
+ [super finalize];
+}
+
+- (void)dealloc {
+ [self close];
+ FMDBRelease(_openResultSets);
+ FMDBRelease(_cachedStatements);
+ FMDBRelease(_databasePath);
+ FMDBRelease(_openFunctions);
+
+#if ! __has_feature(objc_arc)
+ [super dealloc];
+#endif
+}
+
+- (NSString *)databasePath {
+ return _databasePath;
+}
+
+- (sqlite3*)sqliteHandle {
+ return _db;
+}
+
+- (const char*)sqlitePath {
+
+ if (!_databasePath) {
+ return ":memory:";
+ }
+
+ if ([_databasePath length] == 0) {
+ return ""; // this creates a temporary database (it's an sqlite thing).
+ }
+
+ return [_databasePath fileSystemRepresentation];
+
+}
+
+- (BOOL)open {
+ if (_db) {
+ return YES;
+ }
+
+ int err = sqlite3_open([self sqlitePath], &_db );
+ if(err != SQLITE_OK) {
+ NSLog(@"error opening!: %d", err);
+ return NO;
+ }
+
+ return YES;
+}
+
+#if SQLITE_VERSION_NUMBER >= 3005000
+- (BOOL)openWithFlags:(int)flags {
+ int err = sqlite3_open_v2([self sqlitePath], &_db, flags, NULL /* Name of VFS module to use */);
+ if(err != SQLITE_OK) {
+ NSLog(@"error opening!: %d", err);
+ return NO;
+ }
+ return YES;
+}
+#endif
+
+
+- (BOOL)close {
+
+ [self clearCachedStatements];
+ [self closeOpenResultSets];
+
+ if (!_db) {
+ return YES;
+ }
+
+ int rc;
+ BOOL retry;
+ int numberOfRetries = 0;
+ BOOL triedFinalizingOpenStatements = NO;
+
+ do {
+ retry = NO;
+ rc = sqlite3_close(_db);
+
+ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+
+ retry = YES;
+ usleep(20);
+
+ if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
+ NSLog(@"%s:%d", __FUNCTION__, __LINE__);
+ NSLog(@"Database busy, unable to close");
+ return NO;
+ }
+
+ if (!triedFinalizingOpenStatements) {
+ triedFinalizingOpenStatements = YES;
+ sqlite3_stmt *pStmt;
+ while ((pStmt = sqlite3_next_stmt(_db, 0x00)) !=0) {
+ NSLog(@"Closing leaked statement");
+ sqlite3_finalize(pStmt);
+ }
+ }
+ }
+ else if (SQLITE_OK != rc) {
+ NSLog(@"error closing!: %d", rc);
+ }
+ }
+ while (retry);
+
+ _db = nil;
+ return YES;
+}
+
+- (void)clearCachedStatements {
+
+ for (FMStatement *cachedStmt in [_cachedStatements objectEnumerator]) {
+ [cachedStmt close];
+ }
+
+ [_cachedStatements removeAllObjects];
+}
+
+- (BOOL)hasOpenResultSets {
+ return [_openResultSets count] > 0;
+}
+
+- (void)closeOpenResultSets {
+
+ //Copy the set so we don't get mutation errors
+ NSSet *openSetCopy = FMDBReturnAutoreleased([_openResultSets copy]);
+ for (NSValue *rsInWrappedInATastyValueMeal in openSetCopy) {
+ FMResultSet *rs = (FMResultSet *)[rsInWrappedInATastyValueMeal pointerValue];
+
+ [rs setParentDB:nil];
+ [rs close];
+
+ [_openResultSets removeObject:rsInWrappedInATastyValueMeal];
+ }
+}
+
+- (void)resultSetDidClose:(FMResultSet *)resultSet {
+ NSValue *setValue = [NSValue valueWithNonretainedObject:resultSet];
+
+ [_openResultSets removeObject:setValue];
+}
+
+- (FMStatement*)cachedStatementForQuery:(NSString*)query {
+ return [_cachedStatements objectForKey:query];
+}
+
+- (void)setCachedStatement:(FMStatement*)statement forQuery:(NSString*)query {
+
+ query = [query copy]; // in case we got handed in a mutable string...
+
+ [statement setQuery:query];
+
+ [_cachedStatements setObject:statement forKey:query];
+
+ FMDBRelease(query);
+}
+
+
+- (BOOL)rekey:(NSString*)key {
+#ifdef SQLITE_HAS_CODEC
+ if (!key) {
+ return NO;
+ }
+
+ int rc = sqlite3_rekey(_db, [key UTF8String], (int)strlen([key UTF8String]));
+
+ if (rc != SQLITE_OK) {
+ NSLog(@"error on rekey: %d", rc);
+ NSLog(@"%@", [self lastErrorMessage]);
+ }
+
+ return (rc == SQLITE_OK);
+#else
+ return NO;
+#endif
+}
+
+- (BOOL)setKey:(NSString*)key {
+#ifdef SQLITE_HAS_CODEC
+ if (!key) {
+ return NO;
+ }
+
+ int rc = sqlite3_key(_db, [key UTF8String], (int)strlen([key UTF8String]));
+
+ return (rc == SQLITE_OK);
+#else
+ return NO;
+#endif
+}
+
+- (BOOL)goodConnection {
+
+ if (!_db) {
+ return NO;
+ }
+
+ FMResultSet *rs = [self executeQuery:@"select name from sqlite_master where type='table'"];
+
+ if (rs) {
+ [rs close];
+ return YES;
+ }
+
+ return NO;
+}
+
+- (void)warnInUse {
+ NSLog(@"The FMDatabase %@ is currently in use.", self);
+
+#ifndef NS_BLOCK_ASSERTIONS
+ if (_crashOnErrors) {
+ NSAssert1(false, @"The FMDatabase %@ is currently in use.", self);
+ abort();
+ }
+#endif
+}
+
+- (BOOL)databaseExists {
+
+ if (!_db) {
+
+ NSLog(@"The FMDatabase %@ is not open.", self);
+
+ #ifndef NS_BLOCK_ASSERTIONS
+ if (_crashOnErrors) {
+ NSAssert1(false, @"The FMDatabase %@ is not open.", self);
+ abort();
+ }
+ #endif
+
+ return NO;
+ }
+
+ return YES;
+}
+
+- (NSString*)lastErrorMessage {
+ return [NSString stringWithUTF8String:sqlite3_errmsg(_db)];
+}
+
+- (BOOL)hadError {
+ int lastErrCode = [self lastErrorCode];
+
+ return (lastErrCode > SQLITE_OK && lastErrCode < SQLITE_ROW);
+}
+
+- (int)lastErrorCode {
+ return sqlite3_errcode(_db);
+}
+
+
+- (NSError*)errorWithMessage:(NSString*)message {
+ NSDictionary* errorMessage = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
+
+ return [NSError errorWithDomain:@"FMDatabase" code:sqlite3_errcode(_db) userInfo:errorMessage];
+}
+
+- (NSError*)lastError {
+ return [self errorWithMessage:[self lastErrorMessage]];
+}
+
+- (sqlite_int64)lastInsertRowId {
+
+ if (_isExecutingStatement) {
+ [self warnInUse];
+ return NO;
+ }
+
+ _isExecutingStatement = YES;
+
+ sqlite_int64 ret = sqlite3_last_insert_rowid(_db);
+
+ _isExecutingStatement = NO;
+
+ return ret;
+}
+
+- (int)changes {
+ if (_isExecutingStatement) {
+ [self warnInUse];
+ return 0;
+ }
+
+ _isExecutingStatement = YES;
+
+ int ret = sqlite3_changes(_db);
+
+ _isExecutingStatement = NO;
+
+ return ret;
+}
+
+- (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt {
+
+ if ((!obj) || ((NSNull *)obj == [NSNull null])) {
+ sqlite3_bind_null(pStmt, idx);
+ }
+
+ // FIXME - someday check the return codes on these binds.
+ else if ([obj isKindOfClass:[NSData class]]) {
+ const void *bytes = [obj bytes];
+ if (!bytes) {
+ // it's an empty NSData object, aka [NSData data].
+ // Don't pass a NULL pointer, or sqlite will bind a SQL null instead of a blob.
+ bytes = "";
+ }
+ sqlite3_bind_blob(pStmt, idx, bytes, (int)[obj length], SQLITE_STATIC);
+ }
+ else if ([obj isKindOfClass:[NSDate class]]) {
+ sqlite3_bind_double(pStmt, idx, [obj timeIntervalSince1970]);
+ }
+ else if ([obj isKindOfClass:[NSNumber class]]) {
+
+ if (strcmp([obj objCType], @encode(BOOL)) == 0) {
+ sqlite3_bind_int(pStmt, idx, ([obj boolValue] ? 1 : 0));
+ }
+ else if (strcmp([obj objCType], @encode(int)) == 0) {
+ sqlite3_bind_int64(pStmt, idx, [obj longValue]);
+ }
+ else if (strcmp([obj objCType], @encode(long)) == 0) {
+ sqlite3_bind_int64(pStmt, idx, [obj longValue]);
+ }
+ else if (strcmp([obj objCType], @encode(long long)) == 0) {
+ sqlite3_bind_int64(pStmt, idx, [obj longLongValue]);
+ }
+ else if (strcmp([obj objCType], @encode(unsigned long long)) == 0) {
+ sqlite3_bind_int64(pStmt, idx, (long long)[obj unsignedLongLongValue]);
+ }
+ else if (strcmp([obj objCType], @encode(float)) == 0) {
+ sqlite3_bind_double(pStmt, idx, [obj floatValue]);
+ }
+ else if (strcmp([obj objCType], @encode(double)) == 0) {
+ sqlite3_bind_double(pStmt, idx, [obj doubleValue]);
+ }
+ else {
+ sqlite3_bind_text(pStmt, idx, [[obj description] UTF8String], -1, SQLITE_STATIC);
+ }
+ }
+ else {
+ sqlite3_bind_text(pStmt, idx, [[obj description] UTF8String], -1, SQLITE_STATIC);
+ }
+}
+
+- (void)extractSQL:(NSString *)sql argumentsList:(va_list)args intoString:(NSMutableString *)cleanedSQL arguments:(NSMutableArray *)arguments {
+
+ NSUInteger length = [sql length];
+ unichar last = '\0';
+ for (NSUInteger i = 0; i < length; ++i) {
+ id arg = nil;
+ unichar current = [sql characterAtIndex:i];
+ unichar add = current;
+ if (last == '%') {
+ switch (current) {
+ case '@':
+ arg = va_arg(args, id);
+ break;
+ case 'c':
+ // warning: second argument to 'va_arg' is of promotable type 'char'; this va_arg has undefined behavior because arguments will be promoted to 'int'
+ arg = [NSString stringWithFormat:@"%c", va_arg(args, int)];
+ break;
+ case 's':
+ arg = [NSString stringWithUTF8String:va_arg(args, char*)];
+ break;
+ case 'd':
+ case 'D':
+ case 'i':
+ arg = [NSNumber numberWithInt:va_arg(args, int)];
+ break;
+ case 'u':
+ case 'U':
+ arg = [NSNumber numberWithUnsignedInt:va_arg(args, unsigned int)];
+ break;
+ case 'h':
+ i++;
+ if (i < length && [sql characterAtIndex:i] == 'i') {
+ // warning: second argument to 'va_arg' is of promotable type 'short'; this va_arg has undefined behavior because arguments will be promoted to 'int'
+ arg = [NSNumber numberWithShort:(short)(va_arg(args, int))];
+ }
+ else if (i < length && [sql characterAtIndex:i] == 'u') {
+ // warning: second argument to 'va_arg' is of promotable type 'unsigned short'; this va_arg has undefined behavior because arguments will be promoted to 'int'
+ arg = [NSNumber numberWithUnsignedShort:(unsigned short)(va_arg(args, uint))];
+ }
+ else {
+ i--;
+ }
+ break;
+ case 'q':
+ i++;
+ if (i < length && [sql characterAtIndex:i] == 'i') {
+ arg = [NSNumber numberWithLongLong:va_arg(args, long long)];
+ }
+ else if (i < length && [sql characterAtIndex:i] == 'u') {
+ arg = [NSNumber numberWithUnsignedLongLong:va_arg(args, unsigned long long)];
+ }
+ else {
+ i--;
+ }
+ break;
+ case 'f':
+ arg = [NSNumber numberWithDouble:va_arg(args, double)];
+ break;
+ case 'g':
+ // warning: second argument to 'va_arg' is of promotable type 'float'; this va_arg has undefined behavior because arguments will be promoted to 'double'
+ arg = [NSNumber numberWithFloat:(float)(va_arg(args, double))];
+ break;
+ case 'l':
+ i++;
+ if (i < length) {
+ unichar next = [sql characterAtIndex:i];
+ if (next == 'l') {
+ i++;
+ if (i < length && [sql characterAtIndex:i] == 'd') {
+ //%lld
+ arg = [NSNumber numberWithLongLong:va_arg(args, long long)];
+ }
+ else if (i < length && [sql characterAtIndex:i] == 'u') {
+ //%llu
+ arg = [NSNumber numberWithUnsignedLongLong:va_arg(args, unsigned long long)];
+ }
+ else {
+ i--;
+ }
+ }
+ else if (next == 'd') {
+ //%ld
+ arg = [NSNumber numberWithLong:va_arg(args, long)];
+ }
+ else if (next == 'u') {
+ //%lu
+ arg = [NSNumber numberWithUnsignedLong:va_arg(args, unsigned long)];
+ }
+ else {
+ i--;
+ }
+ }
+ else {
+ i--;
+ }
+ break;
+ default:
+ // something else that we can't interpret. just pass it on through like normal
+ break;
+ }
+ }
+ else if (current == '%') {
+ // percent sign; skip this character
+ add = '\0';
+ }
+
+ if (arg != nil) {
+ [cleanedSQL appendString:@"?"];
+ [arguments addObject:arg];
+ }
+ else if (add != '\0') {
+ [cleanedSQL appendFormat:@"%C", add];
+ }
+ last = current;
+ }
+}
+
+- (FMResultSet *)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary *)arguments {
+ return [self executeQuery:sql withArgumentsInArray:nil orDictionary:arguments orVAList:nil];
+}
+
+- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args {
+
+ if (![self databaseExists]) {
+ return 0x00;
+ }
+
+ if (_isExecutingStatement) {
+ [self warnInUse];
+ return 0x00;
+ }
+
+ _isExecutingStatement = YES;
+
+ int rc = 0x00;
+ sqlite3_stmt *pStmt = 0x00;
+ FMStatement *statement = 0x00;
+ FMResultSet *rs = 0x00;
+
+ if (_traceExecution && sql) {
+ NSLog(@"%@ executeQuery: %@", self, sql);
+ }
+
+ if (_shouldCacheStatements) {
+ statement = [self cachedStatementForQuery:sql];
+ pStmt = statement ? [statement statement] : 0x00;
+ [statement reset];
+ }
+
+ int numberOfRetries = 0;
+ BOOL retry = NO;
+
+ if (!pStmt) {
+ do {
+ retry = NO;
+ rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
+
+ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+ retry = YES;
+ usleep(20);
+
+ if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
+ NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]);
+ NSLog(@"Database busy");
+ sqlite3_finalize(pStmt);
+ _isExecutingStatement = NO;
+ return nil;
+ }
+ }
+ else if (SQLITE_OK != rc) {
+
+ if (_logsErrors) {
+ NSLog(@"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
+ NSLog(@"DB Query: %@", sql);
+ NSLog(@"DB Path: %@", _databasePath);
+#ifndef NS_BLOCK_ASSERTIONS
+ if (_crashOnErrors) {
+ abort();
+ NSAssert2(false, @"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
+ }
+#endif
+ }
+
+ sqlite3_finalize(pStmt);
+ _isExecutingStatement = NO;
+ return nil;
+ }
+ }
+ while (retry);
+ }
+
+ id obj;
+ int idx = 0;
+ int queryCount = sqlite3_bind_parameter_count(pStmt); // pointed out by Dominic Yu (thanks!)
+
+ // If dictionaryArgs is passed in, that means we are using sqlite's named parameter support
+ if (dictionaryArgs) {
+
+ for (NSString *dictionaryKey in [dictionaryArgs allKeys]) {
+
+ // Prefix the key with a colon.
+ NSString *parameterName = [[NSString alloc] initWithFormat:@":%@", dictionaryKey];
+
+ // Get the index for the parameter name.
+ int namedIdx = sqlite3_bind_parameter_index(pStmt, [parameterName UTF8String]);
+
+ FMDBRelease(parameterName);
+
+ if (namedIdx > 0) {
+ // Standard binding from here.
+ [self bindObject:[dictionaryArgs objectForKey:dictionaryKey] toColumn:namedIdx inStatement:pStmt];
+ // increment the binding count, so our check below works out
+ idx++;
+ }
+ else {
+ NSLog(@"Could not find index for %@", dictionaryKey);
+ }
+ }
+ }
+ else {
+
+ while (idx < queryCount) {
+
+ if (arrayArgs) {
+ obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
+ }
+ else {
+ obj = va_arg(args, id);
+ }
+
+ if (_traceExecution) {
+ NSLog(@"obj: %@", obj);
+ }
+
+ idx++;
+
+ [self bindObject:obj toColumn:idx inStatement:pStmt];
+ }
+ }
+
+ if (idx != queryCount) {
+ NSLog(@"Error: the bind count is not correct for the # of variables (executeQuery)");
+ sqlite3_finalize(pStmt);
+ _isExecutingStatement = NO;
+ return nil;
+ }
+
+ FMDBRetain(statement); // to balance the release below
+
+ if (!statement) {
+ statement = [[FMStatement alloc] init];
+ [statement setStatement:pStmt];
+
+ if (_shouldCacheStatements) {
+ [self setCachedStatement:statement forQuery:sql];
+ }
+ }
+
+ // the statement gets closed in rs's dealloc or [rs close];
+ rs = [FMResultSet resultSetWithStatement:statement usingParentDatabase:self];
+ [rs setQuery:sql];
+
+ NSValue *openResultSet = [NSValue valueWithNonretainedObject:rs];
+ [_openResultSets addObject:openResultSet];
+
+ [statement setUseCount:[statement useCount] + 1];
+
+ FMDBRelease(statement);
+
+ _isExecutingStatement = NO;
+
+ return rs;
+}
+
+- (FMResultSet *)executeQuery:(NSString*)sql, ... {
+ va_list args;
+ va_start(args, sql);
+
+ id result = [self executeQuery:sql withArgumentsInArray:nil orDictionary:nil orVAList:args];
+
+ va_end(args);
+ return result;
+}
+
+- (FMResultSet *)executeQueryWithFormat:(NSString*)format, ... {
+ va_list args;
+ va_start(args, format);
+
+ NSMutableString *sql = [NSMutableString stringWithCapacity:[format length]];
+ NSMutableArray *arguments = [NSMutableArray array];
+ [self extractSQL:format argumentsList:args intoString:sql arguments:arguments];
+
+ va_end(args);
+
+ return [self executeQuery:sql withArgumentsInArray:arguments];
+}
+
+- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments {
+ return [self executeQuery:sql withArgumentsInArray:arguments orDictionary:nil orVAList:nil];
+}
+
+- (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args {
+
+ if (![self databaseExists]) {
+ return NO;
+ }
+
+ if (_isExecutingStatement) {
+ [self warnInUse];
+ return NO;
+ }
+
+ _isExecutingStatement = YES;
+
+ int rc = 0x00;
+ sqlite3_stmt *pStmt = 0x00;
+ FMStatement *cachedStmt = 0x00;
+
+ if (_traceExecution && sql) {
+ NSLog(@"%@ executeUpdate: %@", self, sql);
+ }
+
+ if (_shouldCacheStatements) {
+ cachedStmt = [self cachedStatementForQuery:sql];
+ pStmt = cachedStmt ? [cachedStmt statement] : 0x00;
+ [cachedStmt reset];
+ }
+
+ int numberOfRetries = 0;
+ BOOL retry = NO;
+
+ if (!pStmt) {
+
+ do {
+ retry = NO;
+ rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
+ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+ retry = YES;
+ usleep(20);
+
+ if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
+ NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]);
+ NSLog(@"Database busy");
+ sqlite3_finalize(pStmt);
+ _isExecutingStatement = NO;
+ return NO;
+ }
+ }
+ else if (SQLITE_OK != rc) {
+
+ if (_logsErrors) {
+ NSLog(@"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
+ NSLog(@"DB Query: %@", sql);
+ NSLog(@"DB Path: %@", _databasePath);
+#ifndef NS_BLOCK_ASSERTIONS
+ if (_crashOnErrors) {
+ abort();
+ NSAssert2(false, @"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
+ }
+#endif
+ }
+
+ sqlite3_finalize(pStmt);
+
+ if (outErr) {
+ *outErr = [self errorWithMessage:[NSString stringWithUTF8String:sqlite3_errmsg(_db)]];
+ }
+
+ _isExecutingStatement = NO;
+ return NO;
+ }
+ }
+ while (retry);
+ }
+
+ id obj;
+ int idx = 0;
+ int queryCount = sqlite3_bind_parameter_count(pStmt);
+
+ // If dictionaryArgs is passed in, that means we are using sqlite's named parameter support
+ if (dictionaryArgs) {
+
+ for (NSString *dictionaryKey in [dictionaryArgs allKeys]) {
+
+ // Prefix the key with a colon.
+ NSString *parameterName = [[NSString alloc] initWithFormat:@":%@", dictionaryKey];
+
+ // Get the index for the parameter name.
+ int namedIdx = sqlite3_bind_parameter_index(pStmt, [parameterName UTF8String]);
+
+ FMDBRelease(parameterName);
+
+ if (namedIdx > 0) {
+ // Standard binding from here.
+ [self bindObject:[dictionaryArgs objectForKey:dictionaryKey] toColumn:namedIdx inStatement:pStmt];
+
+ // increment the binding count, so our check below works out
+ idx++;
+ }
+ else {
+ NSLog(@"Could not find index for %@", dictionaryKey);
+ }
+ }
+ }
+ else {
+
+ while (idx < queryCount) {
+
+ if (arrayArgs) {
+ obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
+ }
+ else {
+ obj = va_arg(args, id);
+ }
+
+ if (_traceExecution) {
+ NSLog(@"obj: %@", obj);
+ }
+
+ idx++;
+
+ [self bindObject:obj toColumn:idx inStatement:pStmt];
+ }
+ }
+
+
+ if (idx != queryCount) {
+ NSLog(@"Error: the bind count (%d) is not correct for the # of variables in the query (%d) (%@) (executeUpdate)", idx, queryCount, sql);
+ sqlite3_finalize(pStmt);
+ _isExecutingStatement = NO;
+ return NO;
+ }
+
+ /* Call sqlite3_step() to run the virtual machine. Since the SQL being
+ ** executed is not a SELECT statement, we assume no data will be returned.
+ */
+ numberOfRetries = 0;
+
+ do {
+ rc = sqlite3_step(pStmt);
+ retry = NO;
+
+ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+ // this will happen if the db is locked, like if we are doing an update or insert.
+ // in that case, retry the step... and maybe wait just 10 milliseconds.
+ retry = YES;
+ if (SQLITE_LOCKED == rc) {
+ rc = sqlite3_reset(pStmt);
+ if (rc != SQLITE_LOCKED) {
+ NSLog(@"Unexpected result from sqlite3_reset (%d) eu", rc);
+ }
+ }
+ usleep(20);
+
+ if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
+ NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]);
+ NSLog(@"Database busy");
+ retry = NO;
+ }
+ }
+ else if (SQLITE_DONE == rc) {
+ // all is well, let's return.
+ }
+ else if (SQLITE_ERROR == rc) {
+ NSLog(@"Error calling sqlite3_step (%d: %s) SQLITE_ERROR", rc, sqlite3_errmsg(_db));
+ NSLog(@"DB Query: %@", sql);
+ }
+ else if (SQLITE_MISUSE == rc) {
+ // uh oh.
+ NSLog(@"Error calling sqlite3_step (%d: %s) SQLITE_MISUSE", rc, sqlite3_errmsg(_db));
+ NSLog(@"DB Query: %@", sql);
+ }
+ else {
+ // wtf?
+ NSLog(@"Unknown error calling sqlite3_step (%d: %s) eu", rc, sqlite3_errmsg(_db));
+ NSLog(@"DB Query: %@", sql);
+ }
+
+ } while (retry);
+
+ if (rc == SQLITE_ROW) {
+ NSAssert1(NO, @"A executeUpdate is being called with a query string '%@'", sql);
+ }
+
+ if (_shouldCacheStatements && !cachedStmt) {
+ cachedStmt = [[FMStatement alloc] init];
+
+ [cachedStmt setStatement:pStmt];
+
+ [self setCachedStatement:cachedStmt forQuery:sql];
+
+ FMDBRelease(cachedStmt);
+ }
+
+ int closeErrorCode;
+
+ if (cachedStmt) {
+ [cachedStmt setUseCount:[cachedStmt useCount] + 1];
+ closeErrorCode = sqlite3_reset(pStmt);
+ }
+ else {
+ /* Finalize the virtual machine. This releases all memory and other
+ ** resources allocated by the sqlite3_prepare() call above.
+ */
+ closeErrorCode = sqlite3_finalize(pStmt);
+ }
+
+ if (closeErrorCode != SQLITE_OK) {
+ NSLog(@"Unknown error finalizing or resetting statement (%d: %s)", closeErrorCode, sqlite3_errmsg(_db));
+ NSLog(@"DB Query: %@", sql);
+ }
+
+ _isExecutingStatement = NO;
+ return (rc == SQLITE_DONE || rc == SQLITE_OK);
+}
+
+
+- (BOOL)executeUpdate:(NSString*)sql, ... {
+ va_list args;
+ va_start(args, sql);
+
+ BOOL result = [self executeUpdate:sql error:nil withArgumentsInArray:nil orDictionary:nil orVAList:args];
+
+ va_end(args);
+ return result;
+}
+
+- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments {
+ return [self executeUpdate:sql error:nil withArgumentsInArray:arguments orDictionary:nil orVAList:nil];
+}
+
+- (BOOL)executeUpdate:(NSString*)sql withParameterDictionary:(NSDictionary *)arguments {
+ return [self executeUpdate:sql error:nil withArgumentsInArray:nil orDictionary:arguments orVAList:nil];
+}
+
+- (BOOL)executeUpdateWithFormat:(NSString*)format, ... {
+ va_list args;
+ va_start(args, format);
+
+ NSMutableString *sql = [NSMutableString stringWithCapacity:[format length]];
+ NSMutableArray *arguments = [NSMutableArray array];
+
+ [self extractSQL:format argumentsList:args intoString:sql arguments:arguments];
+
+ va_end(args);
+
+ return [self executeUpdate:sql withArgumentsInArray:arguments];
+}
+
+- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ... {
+ va_list args;
+ va_start(args, outErr);
+
+ BOOL result = [self executeUpdate:sql error:outErr withArgumentsInArray:nil orDictionary:nil orVAList:args];
+
+ va_end(args);
+ return result;
+}
+
+- (BOOL)rollback {
+ BOOL b = [self executeUpdate:@"rollback transaction"];
+
+ if (b) {
+ _inTransaction = NO;
+ }
+
+ return b;
+}
+
+- (BOOL)commit {
+ BOOL b = [self executeUpdate:@"commit transaction"];
+
+ if (b) {
+ _inTransaction = NO;
+ }
+
+ return b;
+}
+
+- (BOOL)beginDeferredTransaction {
+
+ BOOL b = [self executeUpdate:@"begin deferred transaction"];
+ if (b) {
+ _inTransaction = YES;
+ }
+
+ return b;
+}
+
+- (BOOL)beginTransaction {
+
+ BOOL b = [self executeUpdate:@"begin exclusive transaction"];
+ if (b) {
+ _inTransaction = YES;
+ }
+
+ return b;
+}
+
+- (BOOL)inTransaction {
+ return _inTransaction;
+}
+
+#if SQLITE_VERSION_NUMBER >= 3007000
+
+- (BOOL)startSavePointWithName:(NSString*)name error:(NSError**)outErr {
+
+ // FIXME: make sure the savepoint name doesn't have a ' in it.
+
+ NSParameterAssert(name);
+
+ if (![self executeUpdate:[NSString stringWithFormat:@"savepoint '%@';", name]]) {
+
+ if (outErr) {
+ *outErr = [self lastError];
+ }
+
+ return NO;
+ }
+
+ return YES;
+}
+
+- (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError**)outErr {
+
+ NSParameterAssert(name);
+
+ BOOL worked = [self executeUpdate:[NSString stringWithFormat:@"release savepoint '%@';", name]];
+
+ if (!worked && outErr) {
+ *outErr = [self lastError];
+ }
+
+ return worked;
+}
+
+- (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError**)outErr {
+
+ NSParameterAssert(name);
+
+ BOOL worked = [self executeUpdate:[NSString stringWithFormat:@"rollback transaction to savepoint '%@';", name]];
+
+ if (!worked && *outErr) {
+ *outErr = [self lastError];
+ }
+
+ return worked;
+}
+
+- (NSError*)inSavePoint:(void (^)(BOOL *rollback))block {
+ static unsigned long savePointIdx = 0;
+
+ NSString *name = [NSString stringWithFormat:@"dbSavePoint%ld", savePointIdx++];
+
+ BOOL shouldRollback = NO;
+
+ NSError *err = 0x00;
+
+ if (![self startSavePointWithName:name error:&err]) {
+ return err;
+ }
+
+ block(&shouldRollback);
+
+ if (shouldRollback) {
+ [self rollbackToSavePointWithName:name error:&err];
+ }
+ else {
+ [self releaseSavePointWithName:name error:&err];
+ }
+
+ return err;
+}
+
+#endif
+
+
+- (BOOL)shouldCacheStatements {
+ return _shouldCacheStatements;
+}
+
+- (void)setShouldCacheStatements:(BOOL)value {
+
+ _shouldCacheStatements = value;
+
+ if (_shouldCacheStatements && !_cachedStatements) {
+ [self setCachedStatements:[NSMutableDictionary dictionary]];
+ }
+
+ if (!_shouldCacheStatements) {
+ [self setCachedStatements:nil];
+ }
+}
+
+void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv);
+void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv) {
+#if ! __has_feature(objc_arc)
+ void (^block)(sqlite3_context *context, int argc, sqlite3_value **argv) = (id)sqlite3_user_data(context);
+#else
+ void (^block)(sqlite3_context *context, int argc, sqlite3_value **argv) = (__bridge id)sqlite3_user_data(context);
+#endif
+ block(context, argc, argv);
+}
+
+
+- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block {
+
+ if (!_openFunctions) {
+ _openFunctions = [NSMutableSet new];
+ }
+
+ id b = FMDBReturnAutoreleased([block copy]);
+
+ [_openFunctions addObject:b];
+
+ /* I tried adding custom functions to release the block when the connection is destroyed- but they seemed to never be called, so we use _openFunctions to store the values instead. */
+#if ! __has_feature(objc_arc)
+ sqlite3_create_function([self sqliteHandle], [name UTF8String], count, SQLITE_UTF8, (void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
+#else
+ sqlite3_create_function([self sqliteHandle], [name UTF8String], count, SQLITE_UTF8, (__bridge void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
+#endif
+}
+
+@end
+
+
+
+@implementation FMStatement
+@synthesize statement=_statement;
+@synthesize query=_query;
+@synthesize useCount=_useCount;
+
+- (void)finalize {
+ [self close];
+ [super finalize];
+}
+
+- (void)dealloc {
+ [self close];
+ FMDBRelease(_query);
+#if ! __has_feature(objc_arc)
+ [super dealloc];
+#endif
+}
+
+- (void)close {
+ if (_statement) {
+ sqlite3_finalize(_statement);
+ _statement = 0x00;
+ }
+}
+
+- (void)reset {
+ if (_statement) {
+ sqlite3_reset(_statement);
+ }
+}
+
+- (NSString*)description {
+ return [NSString stringWithFormat:@"%@ %ld hit(s) for query %@", [super description], _useCount, _query];
+}
+
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.h"
new file mode 100644
index 00000000..3b5264fc
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.h"
@@ -0,0 +1,37 @@
+//
+// FMDatabaseAdditions.h
+// fmkit
+//
+// Created by August Mueller on 10/30/05.
+// Copyright 2005 Flying Meat Inc.. All rights reserved.
+//
+
+#import
+@interface FMDatabase (FMDatabaseAdditions)
+
+
+- (int)intForQuery:(NSString*)objs, ...;
+- (long)longForQuery:(NSString*)objs, ...;
+- (BOOL)boolForQuery:(NSString*)objs, ...;
+- (double)doubleForQuery:(NSString*)objs, ...;
+- (NSString*)stringForQuery:(NSString*)objs, ...;
+- (NSData*)dataForQuery:(NSString*)objs, ...;
+- (NSDate*)dateForQuery:(NSString*)objs, ...;
+
+// Notice that there's no dataNoCopyForQuery:.
+// That would be a bad idea, because we close out the result set, and then what
+// happens to the data that we just didn't copy? Who knows, not I.
+
+
+- (BOOL)tableExists:(NSString*)tableName;
+- (FMResultSet*)getSchema;
+- (FMResultSet*)getTableSchema:(NSString*)tableName;
+
+- (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName;
+
+- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error;
+
+// deprecated - use columnExists:inTableWithName: instead.
+- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated));
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.m"
new file mode 100644
index 00000000..60c94ac1
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseAdditions.m"
@@ -0,0 +1,163 @@
+//
+// FMDatabaseAdditions.m
+// fmkit
+//
+// Created by August Mueller on 10/30/05.
+// Copyright 2005 Flying Meat Inc.. All rights reserved.
+//
+
+#import "FMDatabase.h"
+#import "FMDatabaseAdditions.h"
+
+@interface FMDatabase (PrivateStuff)
+- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
+@end
+
+@implementation FMDatabase (FMDatabaseAdditions)
+
+#define RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(type, sel) \
+va_list args; \
+va_start(args, query); \
+FMResultSet *resultSet = [self executeQuery:query withArgumentsInArray:0x00 orDictionary:0x00 orVAList:args]; \
+va_end(args); \
+if (![resultSet next]) { return (type)0; } \
+type ret = [resultSet sel:0]; \
+[resultSet close]; \
+[resultSet setParentDB:nil]; \
+return ret;
+
+
+- (NSString*)stringForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSString *, stringForColumnIndex);
+}
+
+- (int)intForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(int, intForColumnIndex);
+}
+
+- (long)longForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(long, longForColumnIndex);
+}
+
+- (BOOL)boolForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(BOOL, boolForColumnIndex);
+}
+
+- (double)doubleForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(double, doubleForColumnIndex);
+}
+
+- (NSData*)dataForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSData *, dataForColumnIndex);
+}
+
+- (NSDate*)dateForQuery:(NSString*)query, ... {
+ RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSDate *, dateForColumnIndex);
+}
+
+
+- (BOOL)tableExists:(NSString*)tableName {
+
+ tableName = [tableName lowercaseString];
+
+ FMResultSet *rs = [self executeQuery:@"select [sql] from sqlite_master where [type] = 'table' and lower(name) = ?", tableName];
+
+ //if at least one next exists, table exists
+ BOOL returnBool = [rs next];
+
+ //close and free object
+ [rs close];
+
+ return returnBool;
+}
+
+/*
+ get table with list of tables: result colums: type[STRING], name[STRING],tbl_name[STRING],rootpage[INTEGER],sql[STRING]
+ check if table exist in database (patch from OZLB)
+*/
+- (FMResultSet*)getSchema {
+
+ //result colums: type[STRING], name[STRING],tbl_name[STRING],rootpage[INTEGER],sql[STRING]
+ FMResultSet *rs = [self executeQuery:@"SELECT type, name, tbl_name, rootpage, sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type != 'meta' AND name NOT LIKE 'sqlite_%' ORDER BY tbl_name, type DESC, name"];
+
+ return rs;
+}
+
+/*
+ get table schema: result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER]
+*/
+- (FMResultSet*)getTableSchema:(NSString*)tableName {
+
+ //result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER]
+ FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"PRAGMA table_info('%@')", tableName]];
+
+ return rs;
+}
+
+- (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName {
+
+ BOOL returnBool = NO;
+
+ tableName = [tableName lowercaseString];
+ columnName = [columnName lowercaseString];
+
+ FMResultSet *rs = [self getTableSchema:tableName];
+
+ //check if column is present in table schema
+ while ([rs next]) {
+ if ([[[rs stringForColumn:@"name"] lowercaseString] isEqualToString:columnName]) {
+ returnBool = YES;
+ break;
+ }
+ }
+
+ //If this is not done FMDatabase instance stays out of pool
+ [rs close];
+
+ return returnBool;
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
+
+- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated)) {
+ return [self columnExists:columnName inTableWithName:tableName];
+}
+
+#pragma clang diagnostic pop
+
+- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error {
+ sqlite3_stmt *pStmt = NULL;
+ BOOL validationSucceeded = YES;
+ BOOL keepTrying = YES;
+ int numberOfRetries = 0;
+
+ while (keepTrying == YES) {
+ keepTrying = NO;
+ int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
+ if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
+ keepTrying = YES;
+ usleep(20);
+
+ if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
+ NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]);
+ NSLog(@"Database busy");
+ }
+ }
+ else if (rc != SQLITE_OK) {
+ validationSucceeded = NO;
+ if (error) {
+ *error = [NSError errorWithDomain:NSCocoaErrorDomain
+ code:[self lastErrorCode]
+ userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage]
+ forKey:NSLocalizedDescriptionKey]];
+ }
+ }
+ }
+
+ sqlite3_finalize(pStmt);
+
+ return validationSucceeded;
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.h"
new file mode 100644
index 00000000..8fe0c3e6
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.h"
@@ -0,0 +1,75 @@
+//
+// FMDatabasePool.h
+// fmdb
+//
+// Created by August Mueller on 6/22/11.
+// Copyright 2011 Flying Meat Inc. All rights reserved.
+//
+
+#import
+#import "sqlite3.h"
+
+/*
+
+ ***README OR SUFFER***
+Before using FMDatabasePool, please consider using FMDatabaseQueue instead.
+
+If you really really really know what you're doing and FMDatabasePool is what
+you really really need (ie, you're using a read only database), OK you can use
+it. But just be careful not to deadlock!
+
+For an example on deadlocking, search for:
+ONLY_USE_THE_POOL_IF_YOU_ARE_DOING_READS_OTHERWISE_YOULL_DEADLOCK_USE_FMDATABASEQUEUE_INSTEAD
+in the main.m file.
+
+*/
+
+
+
+@class FMDatabase;
+
+@interface FMDatabasePool : NSObject {
+ NSString *_path;
+
+ dispatch_queue_t _lockQueue;
+
+ NSMutableArray *_databaseInPool;
+ NSMutableArray *_databaseOutPool;
+
+ __unsafe_unretained id _delegate;
+
+ NSUInteger _maximumNumberOfDatabasesToCreate;
+}
+
+@property (atomic, retain) NSString *path;
+@property (atomic, assign) id delegate;
+@property (atomic, assign) NSUInteger maximumNumberOfDatabasesToCreate;
+
++ (id)databasePoolWithPath:(NSString*)aPath;
+- (id)initWithPath:(NSString*)aPath;
+
+- (NSUInteger)countOfCheckedInDatabases;
+- (NSUInteger)countOfCheckedOutDatabases;
+- (NSUInteger)countOfOpenDatabases;
+- (void)releaseAllDatabases;
+
+- (void)inDatabase:(void (^)(FMDatabase *db))block;
+
+- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
+- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
+
+#if SQLITE_VERSION_NUMBER >= 3007000
+// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
+// If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
+- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
+#endif
+
+@end
+
+
+@interface NSObject (FMDatabasePoolDelegate)
+
+- (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database;
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.m"
new file mode 100644
index 00000000..4cad6cb4
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabasePool.m"
@@ -0,0 +1,244 @@
+//
+// FMDatabasePool.m
+// fmdb
+//
+// Created by August Mueller on 6/22/11.
+// Copyright 2011 Flying Meat Inc. All rights reserved.
+//
+
+#import "FMDatabasePool.h"
+#import "FMDatabase.h"
+
+@interface FMDatabasePool()
+
+- (void)pushDatabaseBackInPool:(FMDatabase*)db;
+- (FMDatabase*)db;
+
+@end
+
+
+@implementation FMDatabasePool
+@synthesize path=_path;
+@synthesize delegate=_delegate;
+@synthesize maximumNumberOfDatabasesToCreate=_maximumNumberOfDatabasesToCreate;
+
+
++ (id)databasePoolWithPath:(NSString*)aPath {
+ return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath]);
+}
+
+- (id)initWithPath:(NSString*)aPath {
+
+ self = [super init];
+
+ if (self != nil) {
+ _path = [aPath copy];
+ _lockQueue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
+ _databaseInPool = FMDBReturnRetained([NSMutableArray array]);
+ _databaseOutPool = FMDBReturnRetained([NSMutableArray array]);
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+
+ _delegate = 0x00;
+ FMDBRelease(_path);
+ FMDBRelease(_databaseInPool);
+ FMDBRelease(_databaseOutPool);
+
+ if (_lockQueue) {
+ FMDBDispatchQueueRelease(_lockQueue);
+ _lockQueue = 0x00;
+ }
+#if ! __has_feature(objc_arc)
+ [super dealloc];
+#endif
+}
+
+
+- (void)executeLocked:(void (^)(void))aBlock {
+ dispatch_sync(_lockQueue, aBlock);
+}
+
+- (void)pushDatabaseBackInPool:(FMDatabase*)db {
+
+ if (!db) { // db can be null if we set an upper bound on the # of databases to create.
+ return;
+ }
+
+ [self executeLocked:^() {
+
+ if ([_databaseInPool containsObject:db]) {
+ [[NSException exceptionWithName:@"Database already in pool" reason:@"The FMDatabase being put back into the pool is already present in the pool" userInfo:nil] raise];
+ }
+
+ [_databaseInPool addObject:db];
+ [_databaseOutPool removeObject:db];
+
+ }];
+}
+
+- (FMDatabase*)db {
+
+ __block FMDatabase *db;
+
+ [self executeLocked:^() {
+ db = [_databaseInPool lastObject];
+
+ if (db) {
+ [_databaseOutPool addObject:db];
+ [_databaseInPool removeLastObject];
+ }
+ else {
+
+ if (_maximumNumberOfDatabasesToCreate) {
+ NSUInteger currentCount = [_databaseOutPool count] + [_databaseInPool count];
+
+ if (currentCount >= _maximumNumberOfDatabasesToCreate) {
+ NSLog(@"Maximum number of databases (%ld) has already been reached!", (long)currentCount);
+ return;
+ }
+ }
+
+ db = [FMDatabase databaseWithPath:_path];
+ }
+
+ //This ensures that the db is opened before returning
+ if ([db open]) {
+ if ([_delegate respondsToSelector:@selector(databasePool:shouldAddDatabaseToPool:)] && ![_delegate databasePool:self shouldAddDatabaseToPool:db]) {
+ [db close];
+ db = 0x00;
+ }
+ else {
+ //It should not get added in the pool twice if lastObject was found
+ if (![_databaseOutPool containsObject:db]) {
+ [_databaseOutPool addObject:db];
+ }
+ }
+ }
+ else {
+ NSLog(@"Could not open up the database at path %@", _path);
+ db = 0x00;
+ }
+ }];
+
+ return db;
+}
+
+- (NSUInteger)countOfCheckedInDatabases {
+
+ __block NSUInteger count;
+
+ [self executeLocked:^() {
+ count = [_databaseInPool count];
+ }];
+
+ return count;
+}
+
+- (NSUInteger)countOfCheckedOutDatabases {
+
+ __block NSUInteger count;
+
+ [self executeLocked:^() {
+ count = [_databaseOutPool count];
+ }];
+
+ return count;
+}
+
+- (NSUInteger)countOfOpenDatabases {
+ __block NSUInteger count;
+
+ [self executeLocked:^() {
+ count = [_databaseOutPool count] + [_databaseInPool count];
+ }];
+
+ return count;
+}
+
+- (void)releaseAllDatabases {
+ [self executeLocked:^() {
+ [_databaseOutPool removeAllObjects];
+ [_databaseInPool removeAllObjects];
+ }];
+}
+
+- (void)inDatabase:(void (^)(FMDatabase *db))block {
+
+ FMDatabase *db = [self db];
+
+ block(db);
+
+ [self pushDatabaseBackInPool:db];
+}
+
+- (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block {
+
+ BOOL shouldRollback = NO;
+
+ FMDatabase *db = [self db];
+
+ if (useDeferred) {
+ [db beginDeferredTransaction];
+ }
+ else {
+ [db beginTransaction];
+ }
+
+
+ block(db, &shouldRollback);
+
+ if (shouldRollback) {
+ [db rollback];
+ }
+ else {
+ [db commit];
+ }
+
+ [self pushDatabaseBackInPool:db];
+}
+
+- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
+ [self beginTransaction:YES withBlock:block];
+}
+
+- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
+ [self beginTransaction:NO withBlock:block];
+}
+#if SQLITE_VERSION_NUMBER >= 3007000
+- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
+
+ static unsigned long savePointIdx = 0;
+
+ NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++];
+
+ BOOL shouldRollback = NO;
+
+ FMDatabase *db = [self db];
+
+ NSError *err = 0x00;
+
+ if (![db startSavePointWithName:name error:&err]) {
+ [self pushDatabaseBackInPool:db];
+ return err;
+ }
+
+ block(db, &shouldRollback);
+
+ if (shouldRollback) {
+ [db rollbackToSavePointWithName:name error:&err];
+ }
+ else {
+ [db releaseSavePointWithName:name error:&err];
+ }
+
+ [self pushDatabaseBackInPool:db];
+
+ return err;
+}
+#endif
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.h"
new file mode 100644
index 00000000..d51452c7
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.h"
@@ -0,0 +1,38 @@
+//
+// FMDatabaseQueue.h
+// fmdb
+//
+// Created by August Mueller on 6/22/11.
+// Copyright 2011 Flying Meat Inc. All rights reserved.
+//
+
+#import
+#import "sqlite3.h"
+
+@class FMDatabase;
+
+@interface FMDatabaseQueue : NSObject {
+ NSString *_path;
+ dispatch_queue_t _queue;
+ FMDatabase *_db;
+}
+
+@property (atomic, retain) NSString *path;
+
++ (id)databaseQueueWithPath:(NSString*)aPath;
+- (id)initWithPath:(NSString*)aPath;
+- (void)close;
+
+- (void)inDatabase:(void (^)(FMDatabase *db))block;
+
+- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
+- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
+
+#if SQLITE_VERSION_NUMBER >= 3007000
+// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
+// If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
+- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
+#endif
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.m"
new file mode 100644
index 00000000..10fabf5a
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMDatabaseQueue.m"
@@ -0,0 +1,176 @@
+//
+// FMDatabaseQueue.m
+// fmdb
+//
+// Created by August Mueller on 6/22/11.
+// Copyright 2011 Flying Meat Inc. All rights reserved.
+//
+
+#import "FMDatabaseQueue.h"
+#import "FMDatabase.h"
+
+/*
+
+ Note: we call [self retain]; before using dispatch_sync, just incase
+ FMDatabaseQueue is released on another thread and we're in the middle of doing
+ something in dispatch_sync
+
+ */
+
+@implementation FMDatabaseQueue
+
+@synthesize path = _path;
+
++ (id)databaseQueueWithPath:(NSString*)aPath {
+
+ FMDatabaseQueue *q = [[self alloc] initWithPath:aPath];
+
+ FMDBAutorelease(q);
+
+ return q;
+}
+
+- (id)initWithPath:(NSString*)aPath {
+
+ self = [super init];
+
+ if (self != nil) {
+
+ _db = [FMDatabase databaseWithPath:aPath];
+ FMDBRetain(_db);
+
+ if (![_db open]) {
+ NSLog(@"Could not create database queue for path %@", aPath);
+ FMDBRelease(self);
+ return 0x00;
+ }
+
+ _path = FMDBReturnRetained(aPath);
+
+ _queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+
+ FMDBRelease(_db);
+ FMDBRelease(_path);
+
+ if (_queue) {
+ FMDBDispatchQueueRelease(_queue);
+ _queue = 0x00;
+ }
+#if ! __has_feature(objc_arc)
+ [super dealloc];
+#endif
+}
+
+- (void)close {
+ FMDBRetain(self);
+ dispatch_sync(_queue, ^() {
+ [_db close];
+ FMDBRelease(_db);
+ _db = 0x00;
+ });
+ FMDBRelease(self);
+}
+
+- (FMDatabase*)database {
+ if (!_db) {
+ _db = FMDBReturnRetained([FMDatabase databaseWithPath:_path]);
+
+ if (![_db open]) {
+ NSLog(@"FMDatabaseQueue could not reopen database for path %@", _path);
+ FMDBRelease(_db);
+ _db = 0x00;
+ return 0x00;
+ }
+ }
+
+ return _db;
+}
+
+- (void)inDatabase:(void (^)(FMDatabase *db))block {
+ FMDBRetain(self);
+
+ dispatch_sync(_queue, ^() {
+
+ FMDatabase *db = [self database];
+ block(db);
+
+ if ([db hasOpenResultSets]) {
+ NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]");
+ }
+ });
+
+ FMDBRelease(self);
+}
+
+
+- (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block {
+ FMDBRetain(self);
+ dispatch_sync(_queue, ^() {
+
+ BOOL shouldRollback = NO;
+
+ if (useDeferred) {
+ [[self database] beginDeferredTransaction];
+ }
+ else {
+ [[self database] beginTransaction];
+ }
+
+ block([self database], &shouldRollback);
+
+ if (shouldRollback) {
+ [[self database] rollback];
+ }
+ else {
+ [[self database] commit];
+ }
+ });
+
+ FMDBRelease(self);
+}
+
+- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
+ [self beginTransaction:YES withBlock:block];
+}
+
+- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
+ [self beginTransaction:NO withBlock:block];
+}
+
+#if SQLITE_VERSION_NUMBER >= 3007000
+- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
+
+ static unsigned long savePointIdx = 0;
+ __block NSError *err = 0x00;
+ FMDBRetain(self);
+ dispatch_sync(_queue, ^() {
+
+ NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++];
+
+ BOOL shouldRollback = NO;
+
+ if ([[self database] startSavePointWithName:name error:&err]) {
+
+ block([self database], &shouldRollback);
+
+ if (shouldRollback) {
+ [[self database] rollbackToSavePointWithName:name error:&err];
+ }
+ else {
+ [[self database] releaseSavePointWithName:name error:&err];
+ }
+
+ }
+ });
+ FMDBRelease(self);
+ return err;
+}
+#endif
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.h"
new file mode 100644
index 00000000..42dd0004
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.h"
@@ -0,0 +1,104 @@
+#import
+#import "sqlite3.h"
+
+#ifndef __has_feature // Optional.
+#define __has_feature(x) 0 // Compatibility with non-clang compilers.
+#endif
+
+#ifndef NS_RETURNS_NOT_RETAINED
+#if __has_feature(attribute_ns_returns_not_retained)
+#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
+#else
+#define NS_RETURNS_NOT_RETAINED
+#endif
+#endif
+
+@class FMDatabase;
+@class FMStatement;
+
+@interface FMResultSet : NSObject {
+ FMDatabase *_parentDB;
+ FMStatement *_statement;
+
+ NSString *_query;
+ NSMutableDictionary *_columnNameToIndexMap;
+}
+
+@property (atomic, retain) NSString *query;
+@property (readonly) NSMutableDictionary *columnNameToIndexMap;
+@property (atomic, retain) FMStatement *statement;
+
++ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB;
+
+- (void)close;
+
+- (void)setParentDB:(FMDatabase *)newDb;
+
+- (BOOL)next;
+- (BOOL)hasAnotherRow;
+
+- (int)columnCount;
+
+- (int)columnIndexForName:(NSString*)columnName;
+- (NSString*)columnNameForIndex:(int)columnIdx;
+
+- (int)intForColumn:(NSString*)columnName;
+- (int)intForColumnIndex:(int)columnIdx;
+
+- (long)longForColumn:(NSString*)columnName;
+- (long)longForColumnIndex:(int)columnIdx;
+
+- (long long int)longLongIntForColumn:(NSString*)columnName;
+- (long long int)longLongIntForColumnIndex:(int)columnIdx;
+
+- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName;
+- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx;
+
+- (BOOL)boolForColumn:(NSString*)columnName;
+- (BOOL)boolForColumnIndex:(int)columnIdx;
+
+- (double)doubleForColumn:(NSString*)columnName;
+- (double)doubleForColumnIndex:(int)columnIdx;
+
+- (NSString*)stringForColumn:(NSString*)columnName;
+- (NSString*)stringForColumnIndex:(int)columnIdx;
+
+- (NSDate*)dateForColumn:(NSString*)columnName;
+- (NSDate*)dateForColumnIndex:(int)columnIdx;
+
+- (NSData*)dataForColumn:(NSString*)columnName;
+- (NSData*)dataForColumnIndex:(int)columnIdx;
+
+- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx;
+- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName;
+
+// returns one of NSNumber, NSString, NSData, or NSNull
+- (id)objectForColumnName:(NSString*)columnName;
+- (id)objectForColumnIndex:(int)columnIdx;
+
+- (id)objectForKeyedSubscript:(NSString *)columnName;
+- (id)objectAtIndexedSubscript:(int)columnIdx;
+
+/*
+If you are going to use this data after you iterate over the next row, or after you close the
+result set, make sure to make a copy of the data first (or just use dataForColumn:/dataForColumnIndex:)
+If you don't, you're going to be in a world of hurt when you try and use the data.
+*/
+- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED;
+- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
+
+- (BOOL)columnIndexIsNull:(int)columnIdx;
+- (BOOL)columnIsNull:(NSString*)columnName;
+
+
+/* Returns a dictionary of the row results mapped to case sensitive keys of the column names. */
+- (NSDictionary*)resultDictionary;
+
+/* Please use resultDictionary instead. Also, beware that resultDictionary is case sensitive! */
+- (NSDictionary*)resultDict __attribute__ ((deprecated));
+
+- (void)kvcMagic:(id)object;
+
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.m"
new file mode 100644
index 00000000..6d8fdff8
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/src/FMResultSet.m"
@@ -0,0 +1,413 @@
+#import "FMResultSet.h"
+#import "FMDatabase.h"
+#import "unistd.h"
+
+@interface FMDatabase ()
+- (void)resultSetDidClose:(FMResultSet *)resultSet;
+@end
+
+
+@implementation FMResultSet
+@synthesize query=_query;
+@synthesize statement=_statement;
+
++ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB {
+
+ FMResultSet *rs = [[FMResultSet alloc] init];
+
+ [rs setStatement:statement];
+ [rs setParentDB:aDB];
+
+ return FMDBReturnAutoreleased(rs);
+}
+
+- (void)finalize {
+ [self close];
+ [super finalize];
+}
+
+- (void)dealloc {
+ [self close];
+
+ FMDBRelease(_query);
+ _query = nil;
+
+ FMDBRelease(_columnNameToIndexMap);
+ _columnNameToIndexMap = nil;
+
+#if ! __has_feature(objc_arc)
+ [super dealloc];
+#endif
+}
+
+- (void)close {
+ [_statement reset];
+ FMDBRelease(_statement);
+ _statement = nil;
+
+ // we don't need this anymore... (i think)
+ //[_parentDB setInUse:NO];
+ [_parentDB resultSetDidClose:self];
+ _parentDB = nil;
+}
+
+- (int)columnCount {
+ return sqlite3_column_count([_statement statement]);
+}
+
+- (NSMutableDictionary *)columnNameToIndexMap {
+ if (!_columnNameToIndexMap) {
+ int columnCount = sqlite3_column_count([_statement statement]);
+ _columnNameToIndexMap = [[NSMutableDictionary alloc] initWithCapacity:(NSUInteger)columnCount];
+ int columnIdx = 0;
+ for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
+ [_columnNameToIndexMap setObject:[NSNumber numberWithInt:columnIdx]
+ forKey:[[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)] lowercaseString]];
+ }
+ }
+ return _columnNameToIndexMap;
+}
+
+- (void)kvcMagic:(id)object {
+
+ int columnCount = sqlite3_column_count([_statement statement]);
+
+ int columnIdx = 0;
+ for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
+
+ const char *c = (const char *)sqlite3_column_text([_statement statement], columnIdx);
+
+ // check for a null row
+ if (c) {
+ NSString *s = [NSString stringWithUTF8String:c];
+
+ [object setValue:s forKey:[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)]];
+ }
+ }
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
+
+- (NSDictionary*)resultDict {
+
+ NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
+
+ if (num_cols > 0) {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
+
+ NSEnumerator *columnNames = [[self columnNameToIndexMap] keyEnumerator];
+ NSString *columnName = nil;
+ while ((columnName = [columnNames nextObject])) {
+ id objectValue = [self objectForColumnName:columnName];
+ [dict setObject:objectValue forKey:columnName];
+ }
+
+ return FMDBReturnAutoreleased([dict copy]);
+ }
+ else {
+ NSLog(@"Warning: There seem to be no columns in this set.");
+ }
+
+ return nil;
+}
+
+#pragma clang diagnostic pop
+
+- (NSDictionary*)resultDictionary {
+
+ NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
+
+ if (num_cols > 0) {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
+
+ int columnCount = sqlite3_column_count([_statement statement]);
+
+ int columnIdx = 0;
+ for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
+
+ NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)];
+ id objectValue = [self objectForColumnIndex:columnIdx];
+ [dict setObject:objectValue forKey:columnName];
+ }
+
+ return dict;
+ }
+ else {
+ NSLog(@"Warning: There seem to be no columns in this set.");
+ }
+
+ return nil;
+}
+
+
+
+
+
+- (BOOL)next {
+
+ int rc;
+ BOOL retry;
+ int numberOfRetries = 0;
+ do {
+ retry = NO;
+
+ rc = sqlite3_step([_statement statement]);
+
+ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+ // this will happen if the db is locked, like if we are doing an update or insert.
+ // in that case, retry the step... and maybe wait just 10 milliseconds.
+ retry = YES;
+ if (SQLITE_LOCKED == rc) {
+ rc = sqlite3_reset([_statement statement]);
+ if (rc != SQLITE_LOCKED) {
+ NSLog(@"Unexpected result from sqlite3_reset (%d) rs", rc);
+ }
+ }
+ usleep(20);
+
+ if ([_parentDB busyRetryTimeout] && (numberOfRetries++ > [_parentDB busyRetryTimeout])) {
+
+ NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [_parentDB databasePath]);
+ NSLog(@"Database busy");
+ break;
+ }
+ }
+ else if (SQLITE_DONE == rc || SQLITE_ROW == rc) {
+ // all is well, let's return.
+ }
+ else if (SQLITE_ERROR == rc) {
+ NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
+ break;
+ }
+ else if (SQLITE_MISUSE == rc) {
+ // uh oh.
+ NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
+ break;
+ }
+ else {
+ // wtf?
+ NSLog(@"Unknown error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
+ break;
+ }
+
+ } while (retry);
+
+
+ if (rc != SQLITE_ROW) {
+ [self close];
+ }
+
+ return (rc == SQLITE_ROW);
+}
+
+- (BOOL)hasAnotherRow {
+ return sqlite3_errcode([_parentDB sqliteHandle]) == SQLITE_ROW;
+}
+
+- (int)columnIndexForName:(NSString*)columnName {
+ columnName = [columnName lowercaseString];
+
+ NSNumber *n = [[self columnNameToIndexMap] objectForKey:columnName];
+
+ if (n) {
+ return [n intValue];
+ }
+
+ NSLog(@"Warning: I could not find the column named '%@'.", columnName);
+
+ return -1;
+}
+
+
+
+- (int)intForColumn:(NSString*)columnName {
+ return [self intForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (int)intForColumnIndex:(int)columnIdx {
+ return sqlite3_column_int([_statement statement], columnIdx);
+}
+
+- (long)longForColumn:(NSString*)columnName {
+ return [self longForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (long)longForColumnIndex:(int)columnIdx {
+ return (long)sqlite3_column_int64([_statement statement], columnIdx);
+}
+
+- (long long int)longLongIntForColumn:(NSString*)columnName {
+ return [self longLongIntForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (long long int)longLongIntForColumnIndex:(int)columnIdx {
+ return sqlite3_column_int64([_statement statement], columnIdx);
+}
+
+- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName {
+ return [self unsignedLongLongIntForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx {
+ return (unsigned long long int)[self longLongIntForColumnIndex:columnIdx];
+}
+
+- (BOOL)boolForColumn:(NSString*)columnName {
+ return [self boolForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (BOOL)boolForColumnIndex:(int)columnIdx {
+ return ([self intForColumnIndex:columnIdx] != 0);
+}
+
+- (double)doubleForColumn:(NSString*)columnName {
+ return [self doubleForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (double)doubleForColumnIndex:(int)columnIdx {
+ return sqlite3_column_double([_statement statement], columnIdx);
+}
+
+- (NSString*)stringForColumnIndex:(int)columnIdx {
+
+ if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
+ return nil;
+ }
+
+ const char *c = (const char *)sqlite3_column_text([_statement statement], columnIdx);
+
+ if (!c) {
+ // null row.
+ return nil;
+ }
+
+ return [NSString stringWithUTF8String:c];
+}
+
+- (NSString*)stringForColumn:(NSString*)columnName {
+ return [self stringForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (NSDate*)dateForColumn:(NSString*)columnName {
+ return [self dateForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (NSDate*)dateForColumnIndex:(int)columnIdx {
+
+ if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
+ return nil;
+ }
+
+ return [NSDate dateWithTimeIntervalSince1970:[self doubleForColumnIndex:columnIdx]];
+}
+
+
+- (NSData*)dataForColumn:(NSString*)columnName {
+ return [self dataForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (NSData*)dataForColumnIndex:(int)columnIdx {
+
+ if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
+ return nil;
+ }
+
+ int dataSize = sqlite3_column_bytes([_statement statement], columnIdx);
+
+ NSMutableData *data = [NSMutableData dataWithLength:(NSUInteger)dataSize];
+
+ memcpy([data mutableBytes], sqlite3_column_blob([_statement statement], columnIdx), dataSize);
+
+ return data;
+}
+
+
+- (NSData*)dataNoCopyForColumn:(NSString*)columnName {
+ return [self dataNoCopyForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx {
+
+ if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
+ return nil;
+ }
+
+ int dataSize = sqlite3_column_bytes([_statement statement], columnIdx);
+
+ NSData *data = [NSData dataWithBytesNoCopy:(void *)sqlite3_column_blob([_statement statement], columnIdx) length:(NSUInteger)dataSize freeWhenDone:NO];
+
+ return data;
+}
+
+
+- (BOOL)columnIndexIsNull:(int)columnIdx {
+ return sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL;
+}
+
+- (BOOL)columnIsNull:(NSString*)columnName {
+ return [self columnIndexIsNull:[self columnIndexForName:columnName]];
+}
+
+- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx {
+
+ if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
+ return nil;
+ }
+
+ return sqlite3_column_text([_statement statement], columnIdx);
+}
+
+- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName {
+ return [self UTF8StringForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+- (id)objectForColumnIndex:(int)columnIdx {
+ int columnType = sqlite3_column_type([_statement statement], columnIdx);
+
+ id returnValue = nil;
+
+ if (columnType == SQLITE_INTEGER) {
+ returnValue = [NSNumber numberWithLongLong:[self longLongIntForColumnIndex:columnIdx]];
+ }
+ else if (columnType == SQLITE_FLOAT) {
+ returnValue = [NSNumber numberWithDouble:[self doubleForColumnIndex:columnIdx]];
+ }
+ else if (columnType == SQLITE_BLOB) {
+ returnValue = [self dataForColumnIndex:columnIdx];
+ }
+ else {
+ //default to a string for everything else
+ returnValue = [self stringForColumnIndex:columnIdx];
+ }
+
+ if (returnValue == nil) {
+ returnValue = [NSNull null];
+ }
+
+ return returnValue;
+}
+
+- (id)objectForColumnName:(NSString*)columnName {
+ return [self objectForColumnIndex:[self columnIndexForName:columnName]];
+}
+
+// returns autoreleased NSString containing the name of the column in the result set
+- (NSString*)columnNameForIndex:(int)columnIdx {
+ return [NSString stringWithUTF8String: sqlite3_column_name([_statement statement], columnIdx)];
+}
+
+- (void)setParentDB:(FMDatabase *)newDb {
+ _parentDB = newDb;
+}
+
+- (id)objectAtIndexedSubscript:(int)columnIdx {
+ return [self objectForColumnIndex:columnIdx];
+}
+
+- (id)objectForKeyedSubscript:(NSString *)columnName {
+ return [self objectForColumnName:columnName];
+}
+
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/type.plist" "b/21451130\346\261\237\345\261\261/FinalProject/mount/type.plist"
new file mode 100644
index 00000000..61de4a05
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/type.plist"
@@ -0,0 +1,76 @@
+
+
+
+
+ 衣服饰品
+
+ 衣服裤子
+ 鞋帽包包
+
+ 其他杂项
+
+ 其它支出
+ 意外丢失
+ 烂账损失
+
+ 食品酒水
+
+ 早午晚餐
+ 烟酒茶
+ 水果零食
+
+ 居家物业
+
+ 日常用品
+ 水电煤气
+ 房租
+ 物业管理
+ 维修保养
+
+ 通讯交流
+
+ 座机费
+ 手机费
+ 上网费
+ 邮寄费
+
+ 休闲娱乐
+
+ 运动健身
+ 腐败聚会
+ 休闲玩乐
+ 宠物宝贝
+ 旅游度假
+
+ 学习进修
+
+ 书报杂志
+ 培训进修
+ 数码装备
+
+ 人情往来
+
+ 送礼请客
+ 孝敬家长
+
+ 还人钱物
+ 慈善捐助
+
+ 医疗保健
+
+ 药品费
+ 补品费
+ 美容费
+ 治疗费
+
+ 金融保险
+
+ 银行手续
+ 投资亏损
+ 按揭还款
+ 消费税收
+ 利息支出
+ 赔偿罚款
+
+
+
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.h" "b/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.h"
new file mode 100644
index 00000000..3ab7cfcd
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.h"
@@ -0,0 +1,14 @@
+//
+// typeViewController.h
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface typeViewController : UITableViewController
+@property(strong,nonatomic)NSMutableDictionary*dic;
+@property(nonatomic,assign)int Month;
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.m" "b/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.m"
new file mode 100644
index 00000000..b130140e
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/FinalProject/mount/typeViewController.m"
@@ -0,0 +1,174 @@
+//
+// typeViewController.m
+// mount
+//
+// Created by 江山 on 1/3/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "typeViewController.h"
+#import "displayManagement.h"
+#import "billViewController.h"
+#import "displayViewController.h"
+@interface typeViewController ()
+
+@end
+
+@implementation typeViewController
+@synthesize dic,Month;
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+-(void)getMoth{
+ NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
+ NSDate *now;
+ NSDateComponents *comps = [[NSDateComponents alloc] init];
+ NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
+ NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
+ now=[NSDate date];
+ comps = [calendar components:unitFlags fromDate:now];
+
+ self.Month = [comps month];
+}
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ NSUInteger index = 10 ;
+ [self.tableView viewWithTag:index];
+ self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"view.png"]];
+// [self getMoth];
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"Type" Month:self.Month];
+ NSLog(@"display type ^");
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+-(void)viewWillAppear:(BOOL)animated{
+
+ displayManagement*displayM=[[displayManagement alloc]init];
+ dic=[displayM getClassPayout:@"Type" Month:self.Month];
+ [self.tableView reloadData];
+}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+
+ return [[self.dic allKeys] count];
+}
+-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
+ NSArray *moth=[[dic allKeys]sortedArrayUsingSelector:@selector(compare:)];
+ return [moth objectAtIndex:section];
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ NSArray *moth=[[self.dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSArray *number=[self.dic objectForKey:[moth objectAtIndex:section]];
+
+ return [number count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"Cell";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ NSArray *moth=[[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSNumber*number=[moth objectAtIndex:indexPath.section];
+ NSArray*str=[dic objectForKey:number];
+ payout*str1=[str objectAtIndex:indexPath.row];
+ UILabel *cellLabel=(UILabel *)[cell viewWithTag:1];
+ cellLabel.text=[NSString stringWithFormat:@"%.1f",str1.amount];
+ cellLabel=(UILabel *)[cell viewWithTag:2];
+ cellLabel.text=str1.subType;
+ cellLabel=(UILabel *)[cell viewWithTag:3];
+ cellLabel.text=str1.date;
+ cellLabel=(UILabel *)[cell viewWithTag:4];
+ cellLabel.text=str1.personnel;
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+ NSArray *moth=[[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSNumber*number=[moth objectAtIndex:indexPath.section];
+ NSArray*str=[dic objectForKey:number];
+ payout*str1=[str objectAtIndex:indexPath.row];
+
+ [[dic objectForKey:number] removeObjectAtIndex:indexPath.row];
+
+ billManagement*billM=[[billManagement alloc]init];
+ [billM deletePayout:str1.payout_ID];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+ [tableView reloadData];
+}
+
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
+ NSArray *moth=[[dic allKeys] sortedArrayUsingSelector:@selector(compare:)];
+ NSNumber*number=[moth objectAtIndex:indexPath.section];
+ NSArray*str=[dic objectForKey:number];
+ payout* _payout=[str objectAtIndex:indexPath.row];
+// NSLog(@"payout_id %d",_payout.payout_ID);
+
+ UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
+ billViewController*svc=[storyboard instantiateViewControllerWithIdentifier:@"bill"];
+ svc.billIndex=_payout.payout_ID;
+ svc.backTypeNSString=@"Dtype";
+ [self.navigationController pushViewController:svc animated:YES];
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/FinalProject/mount/view.png" "b/21451130\346\261\237\345\261\261/FinalProject/mount/view.png"
new file mode 100644
index 00000000..e17576cf
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/FinalProject/mount/view.png" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/._.DS_Store" "b/21451130\346\261\237\345\261\261/Project4/._.DS_Store"
new file mode 100644
index 00000000..e469dc78
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/._.DS_Store" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._.DS_Store" "b/21451130\346\261\237\345\261\261/Project4/Project4/._.DS_Store"
new file mode 100644
index 00000000..7cf600d7
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._.DS_Store" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.h"
new file mode 100644
index 00000000..38f050d0
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.m"
new file mode 100644
index 00000000..1a9830fd
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._AppDelegate.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.h"
new file mode 100644
index 00000000..e8262167
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.m"
new file mode 100644
index 00000000..21ee746d
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._HandDrawView.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.h"
new file mode 100644
index 00000000..18831fac
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.m"
new file mode 100644
index 00000000..3b1a0a01
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._MainCDTVC.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.h"
new file mode 100644
index 00000000..1b144376
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.m"
new file mode 100644
index 00000000..d8fcb36f
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._MyViewController.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.h"
new file mode 100644
index 00000000..a1b1cf67
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.m"
new file mode 100644
index 00000000..af3947e3
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note+Create.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Note.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note.h"
new file mode 100644
index 00000000..5f7c0003
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Note.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note.m"
new file mode 100644
index 00000000..65ca9b25
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Note.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.h"
new file mode 100644
index 00000000..fe39e2ac
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.h" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.m"
new file mode 100644
index 00000000..f5fdb8fb
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Pictures.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._Project4-Prefix.pch" "b/21451130\346\261\237\345\261\261/Project4/Project4/._Project4-Prefix.pch"
new file mode 100644
index 00000000..f64b0027
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._Project4-Prefix.pch" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/._main.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/._main.m"
new file mode 100644
index 00000000..87aa04f9
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/._main.m" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.h"
new file mode 100644
index 00000000..c90a2eef
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.h"
@@ -0,0 +1,15 @@
+//
+// AppDelegate.h
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface AppDelegate : UIResponder
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.m"
new file mode 100644
index 00000000..1d9cccb1
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/AppDelegate.m"
@@ -0,0 +1,52 @@
+//
+// AppDelegate.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+@implementation AppDelegate
+
+- (void)dealloc
+{
+ [_window release];
+ [super dealloc];
+}
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ // Override point for customization after application launch.
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.h"
new file mode 100644
index 00000000..d37f1bc8
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.h"
@@ -0,0 +1,53 @@
+//
+// CoreDataTableViewController.h
+//
+// Created for Stanford CS193p Winter 2013.
+// Copyright 2013 Stanford University. All rights reserved.
+//
+// This class mostly just copies the code from NSFetchedResultsController's documentation page
+// into a subclass of UITableViewController.
+//
+// Just subclass this and set the fetchedResultsController.
+// The only UITableViewDataSource method you'll HAVE to implement is tableView:cellForRowAtIndexPath:.
+// And you can use the NSFetchedResultsController method objectAtIndexPath: to do it.
+//
+// Remember that once you create an NSFetchedResultsController, you CANNOT modify its @propertys.
+// If you want new fetch parameters (predicate, sorting, etc.),
+// create a NEW NSFetchedResultsController and set this class's fetchedResultsController @property again.
+//
+
+#import
+#import
+
+@interface CoreDataTableViewController : UITableViewController
+
+// The controller (this class fetches nothing if this is not set).
+@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
+
+// Causes the fetchedResultsController to refetch the data.
+// You almost certainly never need to call this.
+// The NSFetchedResultsController class observes the context
+// (so if the objects in the context change, you do not need to call performFetch
+// since the NSFetchedResultsController will notice and update the table automatically).
+// This will also automatically be called if you change the fetchedResultsController @property.
+- (void)performFetch;
+
+// Turn this on before making any changes in the managed object context that
+// are a one-for-one result of the user manipulating rows directly in the table view.
+// Such changes cause the context to report them (after a brief delay),
+// and normally our fetchedResultsController would then try to update the table,
+// but that is unnecessary because the changes were made in the table already (by the user)
+// so the fetchedResultsController has nothing to do and needs to ignore those reports.
+// Turn this back off after the user has finished the change.
+// Note that the effect of setting this to NO actually gets delayed slightly
+// so as to ignore previously-posted, but not-yet-processed context-changed notifications,
+// therefore it is fine to set this to YES at the beginning of, e.g., tableView:moveRowAtIndexPath:toIndexPath:,
+// and then set it back to NO at the end of your implementation of that method.
+// It is not necessary (in fact, not desirable) to set this during row deletion or insertion
+// (but definitely for row moves).
+@property (nonatomic) BOOL suspendAutomaticTrackingOfChangesInManagedObjectContext;
+
+// Set to YES to get some debugging output in the console.
+@property BOOL debug;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.m"
new file mode 100644
index 00000000..a5e76041
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/CoreDataTableViewController.m"
@@ -0,0 +1,174 @@
+//
+// CoreDataTableViewController.m
+//
+// Created for Stanford CS193p Winter 2013.
+// Copyright 2013 Stanford University. All rights reserved.
+//
+
+#import "CoreDataTableViewController.h"
+
+@interface CoreDataTableViewController()
+@property (nonatomic) BOOL beganUpdates;
+@end
+
+@implementation CoreDataTableViewController
+
+#pragma mark - Properties
+
+@synthesize fetchedResultsController = _fetchedResultsController;
+@synthesize suspendAutomaticTrackingOfChangesInManagedObjectContext = _suspendAutomaticTrackingOfChangesInManagedObjectContext;
+@synthesize debug = _debug;
+@synthesize beganUpdates = _beganUpdates;
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return YES;
+}
+
+#pragma mark - Fetching
+
+- (void)performFetch
+{
+ if (self.fetchedResultsController) {
+ if (self.fetchedResultsController.fetchRequest.predicate) {
+ if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
+ } else {
+ if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
+ }
+ NSError *error;
+ [self.fetchedResultsController performFetch:&error];
+ if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
+ } else {
+ if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
+ }
+ [self.tableView reloadData];
+}
+
+- (void)setFetchedResultsController:(NSFetchedResultsController *)newfrc
+{
+ NSFetchedResultsController *oldfrc = _fetchedResultsController;
+ if (newfrc != oldfrc) {
+ _fetchedResultsController = newfrc;
+ newfrc.delegate = self;
+ if ((!self.title || [self.title isEqualToString:oldfrc.fetchRequest.entity.name]) && (!self.navigationController || !self.navigationItem.title)) {
+ self.title = newfrc.fetchRequest.entity.name;
+ }
+ if (newfrc) {
+ if (self.debug) NSLog(@"[%@ %@] %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), oldfrc ? @"updated" : @"set");
+ [self performFetch];
+ } else {
+ if (self.debug) NSLog(@"[%@ %@] reset to nil", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
+ [self.tableView reloadData];
+ }
+ }
+}
+
+#pragma mark - UITableViewDataSource
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return [[self.fetchedResultsController sections] count];
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
+}
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+ return [[[self.fetchedResultsController sections] objectAtIndex:section] name];
+}
+
+- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
+{
+ return [self.fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
+}
+
+- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
+{
+ return [self.fetchedResultsController sectionIndexTitles];
+}
+
+#pragma mark - NSFetchedResultsControllerDelegate
+
+- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
+{
+ if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext) {
+ [self.tableView beginUpdates];
+ self.beganUpdates = YES;
+ }
+}
+
+- (void)controller:(NSFetchedResultsController *)controller
+ didChangeSection:(id )sectionInfo
+ atIndex:(NSUInteger)sectionIndex
+ forChangeType:(NSFetchedResultsChangeType)type
+{
+ if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
+ {
+ switch(type)
+ {
+ case NSFetchedResultsChangeInsert:
+ [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+
+ case NSFetchedResultsChangeDelete:
+ [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+ }
+ }
+}
+
+
+- (void)controller:(NSFetchedResultsController *)controller
+ didChangeObject:(id)anObject
+ atIndexPath:(NSIndexPath *)indexPath
+ forChangeType:(NSFetchedResultsChangeType)type
+ newIndexPath:(NSIndexPath *)newIndexPath
+{
+ if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
+ {
+ switch(type)
+ {
+ case NSFetchedResultsChangeInsert:
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+
+ case NSFetchedResultsChangeDelete:
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+
+ case NSFetchedResultsChangeUpdate:
+ [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+
+ case NSFetchedResultsChangeMove:
+ [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
+ break;
+ }
+ }
+}
+
+- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
+{
+ if (self.beganUpdates) [self.tableView endUpdates];
+}
+
+- (void)endSuspensionOfUpdatesDueToContextChanges
+{
+ _suspendAutomaticTrackingOfChangesInManagedObjectContext = NO;
+}
+
+- (void)setSuspendAutomaticTrackingOfChangesInManagedObjectContext:(BOOL)suspend
+{
+ if (suspend) {
+ _suspendAutomaticTrackingOfChangesInManagedObjectContext = YES;
+ } else {
+ [self performSelector:@selector(endSuspensionOfUpdatesDueToContextChanges) withObject:0 afterDelay:0];
+ }
+}
+
+@end
+
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Default-568h@2x.png" "b/21451130\346\261\237\345\261\261/Project4/Project4/Default-568h@2x.png"
new file mode 100644
index 00000000..0891b7aa
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/Default-568h@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Default.png" "b/21451130\346\261\237\345\261\261/Project4/Project4/Default.png"
new file mode 100644
index 00000000..4c8ca6f6
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/Default.png" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Default@2x.png" "b/21451130\346\261\237\345\261\261/Project4/Project4/Default@2x.png"
new file mode 100644
index 00000000..35b84cff
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/Default@2x.png" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.h"
new file mode 100644
index 00000000..9f6706e8
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.h"
@@ -0,0 +1,13 @@
+//
+// HandDrawView.h
+// Project4
+//
+// Created by 江山 on 1/9/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface HandDrawView : UIView
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.m"
new file mode 100644
index 00000000..62fd18c6
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/HandDrawView.m"
@@ -0,0 +1,121 @@
+//
+// HandDrawView.m
+// Project4
+//
+// Created by 江山 on 1/9/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "HandDrawView.h"
+
+@implementation HandDrawView
+{
+ UIBezierPath *beizerPath;
+ UIImage *incrImage;
+ CGPoint points[5];
+ uint control;
+}
+
+// Create a View which contains Signature Label
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+
+ if (self) {
+
+ self.backgroundColor = [UIColor whiteColor];
+ [self setMultipleTouchEnabled:NO];
+ beizerPath = [UIBezierPath bezierPath];
+ [beizerPath setLineWidth:2.0];
+
+ }
+ return self;
+}
+
+
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect
+{
+ [incrImage drawInRect:rect];
+ [beizerPath stroke];
+
+ // Set initial color for drawing
+
+ UIColor *fillColor = [UIColor whiteColor];
+ [fillColor setFill];
+ UIColor *strokeColor = [UIColor blackColor];
+ [strokeColor setStroke];
+ [beizerPath stroke];
+}
+
+#pragma mark - UIView Touch Methods
+
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ control = 0;
+ UITouch *touch = [touches anyObject];
+ points[0] = [touch locationInView:self];
+
+ CGPoint startPoint = points[0];
+ CGPoint endPoint = CGPointMake(startPoint.x + 1.5, startPoint.y
+ + 2);
+
+ [beizerPath moveToPoint:startPoint];
+ [beizerPath addLineToPoint:endPoint];
+
+}
+
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ UITouch *touch = [touches anyObject];
+ CGPoint touchPoint = [touch locationInView:self];
+ control++;
+ points[control] = touchPoint;
+
+ if (control == 4)
+ {
+ points[3] = CGPointMake((points[2].x + points[4].x)/2.0, (points[2].y + points[4].y)/2.0);
+
+ [beizerPath moveToPoint:points[0]];
+ [beizerPath addCurveToPoint:points[3] controlPoint1:points[1] controlPoint2:points[2]];
+
+ [self setNeedsDisplay];
+
+ points[0] = points[3];
+ points[1] = points[4];
+ control = 1;
+ }
+
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self drawBitmapImage];
+ [self setNeedsDisplay];
+ [beizerPath removeAllPoints];
+ control = 0;
+}
+
+- (void)drawBitmapImage
+{
+ UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);
+
+ if (!incrImage)
+ {
+ UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds];
+ [[UIColor whiteColor] setFill];
+ [rectpath fill];
+ }
+ [incrImage drawAtPoint:CGPointZero];
+
+ //Set final color for drawing
+ UIColor *strokeColor = [UIColor redColor];
+ [strokeColor setStroke];
+ [beizerPath stroke];
+ incrImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.h"
new file mode 100644
index 00000000..271f60c5
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.h"
@@ -0,0 +1,15 @@
+//
+// MainCDTVC.h
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "CoreDataTableViewController.h"
+
+@interface MainCDTVC : CoreDataTableViewController
+
+@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.m"
new file mode 100644
index 00000000..75728f8f
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/MainCDTVC.m"
@@ -0,0 +1,52 @@
+//
+// MainCDTVC.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "MainCDTVC.h"
+#import "Note.h"
+
+@interface MainCDTVC ()
+
+@end
+
+@implementation MainCDTVC
+
+- (void)setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
+{
+ _managedObjectContext = managedObjectContext;
+ if (managedObjectContext) {
+ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Note"];
+ request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
+ request.predicate = nil;
+ self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
+ } else {
+ self.fetchedResultsController = nil;
+ }
+}
+
+#pragma mark - UITableViewDataSource
+
+// Uses NSFetchedResultsController's objectAtIndexPath: to find the Photographer for this row in the table.
+// Then uses that Photographer to set the cell up.
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Note"];
+
+ Note *note = [self.fetchedResultsController objectAtIndexPath:indexPath];
+ cell.textLabel.text = note.title;
+ NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
+ cell.detailTextLabel.text = [dateFormatter stringFromDate: note.date];
+
+ return cell;
+}
+
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+ NSLog(@"main segue");
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Model.xcdatamodeld/Model.xcdatamodel/contents" "b/21451130\346\261\237\345\261\261/Project4/Project4/Model.xcdatamodeld/Model.xcdatamodel/contents"
new file mode 100644
index 00000000..18b4a557
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Model.xcdatamodeld/Model.xcdatamodel/contents"
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.h"
new file mode 100644
index 00000000..5389055a
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.h"
@@ -0,0 +1,19 @@
+//
+// MyViewController.h
+// Project4
+//
+// Created by 江山 on 1/8/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+@interface MyViewController : UIViewController
+
+- (IBAction)takephoto:(id)sender;
+- (IBAction)save:(id)sender;
+@property (retain, nonatomic) IBOutlet UITextField *textfield;
+@property (retain, nonatomic) IBOutlet UITextView *textview;
+
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.m"
new file mode 100644
index 00000000..5da3550a
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/MyViewController.m"
@@ -0,0 +1,84 @@
+//
+// MyViewController.m
+// Project4
+//
+// Created by 江山 on 1/8/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "MyViewController.h"
+
+@interface MyViewController ()
+
+@end
+
+@implementation MyViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ // Do any additional setup after loading the view.
+}
+
+- (void)setTextfield:(UITextField *)textfield
+{
+ if(!textfield) {
+ _textfield = [[UITextField alloc] init];
+ }
+ else {
+ _textfield = textfield;
+ }
+}
+
+- (void)setTextview:(UITextView *)textview
+{
+ if(!textview) {
+ _textview = [[UITextView alloc] init];
+ }
+ else {
+ _textview = textview;
+ }
+}
+
+
+- (void)didReceiveMemoryWarning
+{
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+- (void)dealloc {
+ [_textfield release];
+ [_textview release];
+ [super dealloc];
+}
+
+- (IBAction)takephoto:(id)sender {
+ //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库
+ UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
+ if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
+ sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
+ }
+ //sourceType = UIImagePickerControllerSourceTypeCamera; //照相机
+ //sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
+ //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
+ UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
+ picker.allowsEditing = YES;//设置可编辑
+ picker.sourceType = sourceType;
+ [self presentModalViewController:picker animated:YES];//进入照相界面
+ [picker release];
+}
+
+- (IBAction)save:(id)sender {
+ NSLog(@"save the new note");
+}
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.h"
new file mode 100644
index 00000000..9cc84f84
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.h"
@@ -0,0 +1,16 @@
+//
+// Note+Create.h
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "Note.h"
+
+@interface Note (Create)
+
++ (Note *)NoteWithTitle:(NSString *)title andContent:(NSString *)content
+ inManagedObjectContext:(NSManagedObjectContext *)context;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.m"
new file mode 100644
index 00000000..ac725162
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Note+Create.m"
@@ -0,0 +1,45 @@
+//
+// Note+Create.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "Note+Create.h"
+#import "Note.h"
+
+@implementation Note (Create)
+
++ (Note *)NoteWithTitle:(NSString *)title andContent:(NSString *)content
+ inManagedObjectContext:(NSManagedObjectContext *)context
+{
+ Note *note = nil;
+
+ // This is just like Photo(Flickr)'s method. Look there for commentary.
+
+ if (title.length) {
+ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Note"];
+ request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date"
+ ascending:NO
+ selector:@selector(localizedCaseInsensitiveCompare:)]];
+ request.predicate = [NSPredicate predicateWithFormat:@"title = %@", title];
+
+ NSError *error;
+ NSArray *matches = [context executeFetchRequest:request error:&error];
+
+ if (!matches || ([matches count] > 1)) {
+ // handle error
+ } else if (![matches count]) {
+ note = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:context];
+ note.title = title;
+ note.content = content;
+ } else {
+ note = [matches lastObject];
+ }
+ }
+
+ return note;
+}
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Note.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/Note.h"
new file mode 100644
index 00000000..214b0f59
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Note.h"
@@ -0,0 +1,21 @@
+//
+// Note.h
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+#import
+
+@class Pictures;
+
+@interface Note : NSManagedObject
+
+@property (nonatomic, retain) NSString * title;
+@property (nonatomic, retain) NSString * content;
+@property (nonatomic, retain) NSDate * date;
+@property (nonatomic, retain) Pictures *have;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Note.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/Note.m"
new file mode 100644
index 00000000..25c9718c
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Note.m"
@@ -0,0 +1,20 @@
+//
+// Note.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "Note.h"
+#import "Pictures.h"
+
+
+@implementation Note
+
+@dynamic title;
+@dynamic content;
+@dynamic date;
+@dynamic have;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.h" "b/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.h"
new file mode 100644
index 00000000..77f87969
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.h"
@@ -0,0 +1,19 @@
+//
+// Pictures.h
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+#import
+
+@class Note;
+
+@interface Pictures : NSManagedObject
+
+@property (nonatomic, retain) NSString * id;
+@property (nonatomic, retain) Note *belongto;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.m"
new file mode 100644
index 00000000..df7c2885
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Pictures.m"
@@ -0,0 +1,18 @@
+//
+// Pictures.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import "Pictures.h"
+#import "Note.h"
+
+
+@implementation Pictures
+
+@dynamic id;
+@dynamic belongto;
+
+@end
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Info.plist" "b/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Info.plist"
new file mode 100644
index 00000000..63941d2f
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Info.plist"
@@ -0,0 +1,49 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleDisplayName
+ ${PRODUCT_NAME}
+ CFBundleExecutable
+ ${EXECUTABLE_NAME}
+ CFBundleIdentifier
+ js.${PRODUCT_NAME:rfc1034identifier}
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ ${PRODUCT_NAME}
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1.0
+ LSRequiresIPhoneOS
+
+ UIMainStoryboardFile
+ MainStoryboard_iPhone
+ UIMainStoryboardFile~ipad
+ MainStoryboard_iPad
+ UIRequiredDeviceCapabilities
+
+ armv7
+
+ UISupportedInterfaceOrientations
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+ UISupportedInterfaceOrientations~ipad
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+
+
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Prefix.pch" "b/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Prefix.pch"
new file mode 100644
index 00000000..1c8c3a57
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/Project4-Prefix.pch"
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'Project4' target in the 'Project4' project
+//
+
+#import
+
+#ifndef __IPHONE_5_0
+#warning "This project uses features only available in iOS SDK 5.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import
+ #import
+#endif
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._InfoPlist.strings" "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._InfoPlist.strings"
new file mode 100644
index 00000000..10c2170c
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._InfoPlist.strings" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._MainStoryboard_iPad.storyboard" "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._MainStoryboard_iPad.storyboard"
new file mode 100644
index 00000000..3a48f2f4
Binary files /dev/null and "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/._MainStoryboard_iPad.storyboard" differ
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/InfoPlist.strings" "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/InfoPlist.strings"
new file mode 100644
index 00000000..477b28ff
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/InfoPlist.strings"
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPad.storyboard" "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPad.storyboard"
new file mode 100644
index 00000000..9fbe23e4
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPad.storyboard"
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPhone.storyboard" "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPhone.storyboard"
new file mode 100644
index 00000000..0c8abbdb
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/en.lproj/MainStoryboard_iPhone.storyboard"
@@ -0,0 +1,225 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/21451130\346\261\237\345\261\261/Project4/Project4/main.m" "b/21451130\346\261\237\345\261\261/Project4/Project4/main.m"
new file mode 100644
index 00000000..8504f84d
--- /dev/null
+++ "b/21451130\346\261\237\345\261\261/Project4/Project4/main.m"
@@ -0,0 +1,18 @@
+//
+// main.m
+// Project4
+//
+// Created by 江山 on 1/7/15.
+// Copyright (c) 2015 jiangshan. All rights reserved.
+//
+
+#import
+
+#import "AppDelegate.h"
+
+int main(int argc, char *argv[])
+{
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}