i have a range of weekly dates like example
1-5-2010 to 7-5-2010
i want the only records which are between two dates how can i compare dates?
and how can i get current week dates.. from current dates...?
thnx in advance..
i have a range of weekly dates like example
1-5-2010 to 7-5-2010
i want the only records which are between two dates how can i compare dates?
and how can i get current week dates.. from current dates...?
thnx in advance..
// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; }
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"%i-%i",indexPath.row,indexPath.section]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleBlue;
if (cell == nil && tmpDic!=nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.detailTextLabel.textAlignment=UITextAlignmentRight;
switch (indexPath.row) {
case 0:
cell.textLabel.text=@"Photos";
cell.detailTextLabel.textColor=[UIColor grayColor];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@ Photos ",[tmpDic valueForKey:@"photos"]];
img1=[[UIImageView alloc] initWithFrame:CGRectMake(288, 16, 9, 13)];
img1.image=[UIImage imageNamed:@"blue-arrow.png"];
[cell addSubview:img1];
[img1 release];
break;
case 1: cell.textLabel.text=@"Comments";
cell.detailTextLabel.textColor=[UIColor grayColor];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@ Comments ",[tmpDic valueForKey:@"comments"]];
img1=[[UIImageView alloc] initWithFrame:CGRectMake(288, 16, 9, 13)];
img1.image=[UIImage imageNamed:@"blue-arrow.png"];
[cell addSubview:img1];
[img1 release];
break;
case 2: cell.textLabel.text=@"Videos";
cell.detailTextLabel.textColor=[UIColor grayColor];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@ Videos ",[tmpDic valueForKey:@"videos"]];
img1=[[UIImageView alloc] initWithFrame:CGRectMake(288, 16, 9, 13)];
img1.image=[UIImage imageNamed:@"blue-arrow.png"];
[cell addSubview:img1];
[img1 release];
break;
default: break;
}
}
return cell;
}
// Override to support row selection in the table view. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if(indexPath.row == 0) { nxtImageDtl = [[ImageDetail alloc] initWithNibName:@"ImageDetail" bundle:nil]; NSString *s = [tmpDic valueForKey:@"id"]; nxtImageDtl.CourtID = [s intValue]; [self.navigationController pushViewController:nxtImageDtl animated:YES]; [nxtImageDtl release]; }
if(indexPath.row == 1)
{
cmt = [[comments alloc] initWithNibName:@"comments" bundle:nil];
NSString *s = [tmpDic valueForKey:@"id"];
cmt.CourtID = [s intValue];
[self.navigationController pushViewController:cmt animated:YES];
}
if(indexPath.row == 2)
{
vd = [[video alloc] initWithNibName:@"video" bundle:nil];
NSString *s = [tmpDic valueForKey:@"id"];
vd.CourtID = [s intValue];
[self.navigationController pushViewController:vd animated:YES];
}
}
// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [myTblArray count]; }
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"%i-%i",indexPath.section,indexPath.row]; tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) { cell=[self myCustomCell:CellIdentifier dic:[myTblArray objectAtIndex:indexPath.row] alterNate:(indexPath.row%2==0)?YES:NO]; }
return cell;
}
-(UITableViewCell*)myCustomCell:(NSString*)CellIdentifier dic:(NSDictionary*)dic alterNate:(BOOL)alterNate{ UITableViewCell *c=[[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 80) reuseIdentifier:CellIdentifier] autorelease];
UIView *aView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)] autorelease];
aView.backgroundColor=(alterNate)?[UIColor colorWithWhite:0.9 alpha:1.0]:[UIColor whiteColor];
[c addSubview:aView];
c.selectionStyle=UITableViewCellSelectionStyleBlue;
//UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 7, 88, 66)];
UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 110, 80)];
ASIHTTPRequest *request=[[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:[[dic valueForKey:@"image"]
stringByAddingPercentEscapesUsingEncoding:NSStringEncodingConversionExternalRepresentation]]] autorelease];
// set image tag for accessing this image view from tableView
[imgV setTag:1000+[[dic valueForKey:@"id"] intValue]];
// set request tag for accessing the same
[request setUserInfo:[NSString stringWithFormat:@"%i",1000+[[dic valueForKey:@"id"] intValue]]];
[request setUsername:CellIdentifier];
[networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)];
[networkQueue setDelegate:self];
[networkQueue addOperation:request];
[networkQueue go];
// imgV.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dic valueForKey:@"image"]]]];
[c addSubview:imgV];
[imgV release];
imgV=[[UIImageView alloc] initWithFrame:CGRectMake(300, 36, 9, 13)];
imgV.image=[UIImage imageNamed:@"blue-arrow.png"];
[c addSubview:imgV];
[imgV release];
NSString *imgName=([[dic valueForKey:@"rating"] isEqualToString:@"0"])?@"0-star.png":(([[dic valueForKey:@"rating"] isEqualToString:@"1"])?@"1-star.png":(([[dic valueForKey:@"rating"] isEqualToString:@"2"])?@"2-star.png":(([[dic valueForKey:@"rating"] isEqualToString:@"3"])?@"3-star.png":(([[dic valueForKey:@"rating"] isEqualToString:@"4"])?@"4-star.png":@"5-star.png"))));
//NSString *imgName=([[dic valueForKey:@"rating"] isEqualToString:@"1"])?@"star-1.png":(([[dic valueForKey:@"rating"] isEqualToString:@"2"])?@"star-2.png":(([[dic valueForKey:@"rating"] isEqualToString:@"3"])?@"star-3.png":(([[dic valueForKey:@"rating"] isEqualToString:@"4"])?@"star-4.png":@"star-5.png")));
imgV=[[UIImageView alloc] initWithFrame:CGRectMake(120, 20, 94, 23)];
imgV.image=[UIImage imageNamed:imgName];
[imgV setContentMode:UIViewContentModeLeft];
[c addSubview:imgV];
[imgV release];
UILabel *l=[[UILabel alloc] initWithFrame:CGRectMake(120, 3, 180, 20)];
[l setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
[l setText:[dic valueForKey:@"name"]];
[l setBackgroundColor:[UIColor clearColor]];
[l setAdjustsFontSizeToFitWidth:NO];
[c addSubview:l];
[l release];
l=[[UILabel alloc] initWithFrame:CGRectMake(120, 41, 180, 20)];
[l setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[l setText:[dic valueForKey:@"street"]];
[l setBackgroundColor:[UIColor clearColor]];
[c addSubview:l];
[l release];
l=[[UILabel alloc] initWithFrame:CGRectMake(120, 59, 180, 20)];
[l setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[l setText:[NSString stringWithFormat:@"%@, %@",[dic valueForKey:@"city"],[dic valueForKey:@"country"]]];
[l setBackgroundColor:[UIColor clearColor]];
[c addSubview:l];
[l release];
l=[[UILabel alloc] initWithFrame:CGRectMake(210, 23, 180, 20)];
[l setFont:[UIFont fontWithName:@"Arial" size:11]];
[l setText:[NSString stringWithFormat:@"%@ Votes",[dic valueForKey:@"votes"]]];
[l setBackgroundColor:[UIColor clearColor]];
[c addSubview:l];
[l release];
return c;
}
// Override to support row selection in the table view. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[mytblView deselectRowAtIndexPath:indexPath animated:YES];
nxtCourtdtl = [[CourtDetails alloc] initWithNibName:@"CourtDetails" bundle:nil];
dic1=[[NSDictionary alloc] initWithDictionary:[myTblArray objectAtIndex:indexPath.row]];
NSString *s = [dic1 valueForKey:@"id"];
nxtCourtdtl.CourtID = [s intValue];
[self.navigationController pushViewController:nxtCourtdtl animated:YES];
[nxtCourtdtl release];
}
///Sample of webservice..
-(void)callWebServiceForSignUp{ [AlertHandler showAlertForProcess]; if([gender.text isEqualToString: @"Male"]){ gen=[NSString stringWithFormat:@"1"]; } else{ gen=[NSString stringWithFormat:@"0"]; } NSString *soapMsg = [NSString stringWithFormat:@"\n" "\n" "\n" "\n" "%@\n" "%@\n" "%@\n" "%@\n" "%@\n" "\n" "\n" "\n",username.text,email.text,firstname.text,lastname.text,gen]; NSURL *myURL=[NSURL URLWithString:[WebService getLoginURL]];
NSMutableURLRequest *connectionReq=[NSMutableURLRequest requestWithURL:myURL];
[connectionReq addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[connectionReq addValue:@ "http://tempuri.org/AddUser" forHTTPHeaderField:@"SOAPAction"];
[connectionReq setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[connectionReq addValue:[NSString stringWithFormat:@"%i",[soapMsg length]] forHTTPHeaderField:@"Content-Length"];
[connectionReq setHTTPMethod:@"POST"];
NSURLConnection *myConnection=[[NSURLConnection alloc] initWithRequest:connectionReq delegate:self];
if(myConnection){
myWebData=[[NSMutableData alloc] initWithLength:0];
}else{
UIAlertView *ConnectionNullAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
ConnectionNullAlert.message=@" can't able to connect to Server!";
ConnectionNullAlert.title=@"Message";
[ConnectionNullAlert addButtonWithTitle:@"OK"];
[ConnectionNullAlert show];
[ConnectionNullAlert release];
}
}
(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
UIAlertView *ConnectionFailAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)]; ConnectionFailAlert.message=@" can't able to connect to Server!"; ConnectionFailAlert.title=@"Message"; [ConnectionFailAlert addButtonWithTitle:@"OK"]; [ConnectionFailAlert show]; [ConnectionFailAlert release];
} - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ [myWebData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [myWebData appendData:data]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSString *str=[[NSString alloc] initWithBytes:[myWebData bytes] length:[myWebData length] encoding:NSStringEncodingConversionAllowLossy]; NSLog(@"%@",str); [str release]; if(myXMLParser!=nil && [myXMLParser retainCount]>0){ myXMLParser.delegate=nil; [myXMLParser release]; myXMLParser=nil; } myXMLParser=[[NSXMLParser alloc] initWithData:myWebData]; myXMLParser.delegate=self; [myXMLParser parse]; [myWebData release]; }
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{ if([elementName isEqualToString:@"AddUserResult"]){ tempDic=[[NSMutableDictionary alloc] init]; } }
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if(tmpStr!=nil && [tmpStr retainCount]>0){ [tmpStr release]; tmpStr=nil; } tmpStr=[[NSString alloc] initWithString:string]; }
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if([elementName isEqualToString:@"AddUserResult"] || [elementName isEqualToString:@"User_Id"]){ [tempDic setValue:tmpStr forKey:elementName]; NSLog([tempDic description]); } }
-(void)parserDidEndDocument:(NSXMLParser *)parser{ [AlertHandler hideAlert]; NSString *errorDesc; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *DataPath = [documentsDirectory stringByAppendingPathComponent:@"Login.plist"]; NSDictionary *plistDict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [tempDic valueForKey:@"User_Id"], nil] forKeys:[NSArray arrayWithObjects:@"userid", nil]]; NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc]; if (plistData) { [plistData writeToFile:DataPath atomically:YES]; }
nxthomeview = [[HomeView alloc]initWithNibName:@"HomeView" bundle:nil];
[self.navigationController pushViewController:nxthomeview animated:YES];
[nxthomeview release];
}
//alert handler
@interface AlertHandler : NSObject {
} +(void)showAlertForProcess; +(void)hideAlert; @end
@implementation AlertHandler UIAlertView *av; UIActivityIndicatorView *actInd;
+(void)showAlertForProcess{ if(av!=nil && [av retainCount]>0){ [av release]; av=nil; } if(actInd!=nil && [actInd retainCount]>0){ [actInd removeFromSuperview];[actInd release]; actInd=nil; } av=[[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; actInd=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [actInd setFrame:CGRectMake(120, 50, 37, 37)]; [actInd startAnimating]; [av addSubview:actInd]; [av show]; } +(void)hideAlert{ [av dismissWithClickedButtonIndex:0 animated:YES]; if(av!=nil && [av retainCount]>0){ [av release]; av=nil; } if(actInd!=nil && [actInd retainCount]>0){ [actInd removeFromSuperview];[actInd release]; actInd=nil; } } @end
NSMutableDictionary *GlobalInfo;
(void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[TableOperation check_Create_DB];
[window addSubview:[navigationController view]];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
tabBarController.view.hidden = YES;
tabBarController.selectedIndex=1;
GlobalInfo = [[NSMutableDictionary alloc]init];
[GlobalInfo setObject:tabBarController forKey:@"MainTabBar"];
//[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tabBarControllerView) userInfo:nil repeats:NO];
}
+(NSMutableDictionary*)getGlobalInfo{ return GlobalInfo; }
@end
[[CardsAppDelegate getGlobalInfo]setObject:[NSString stringWithFormat:@"%i",i] forKey:@"Folderid"];
if([[CardsAppDelegate getGlobalInfo] objectForKey:@"Folderid"] == nil){
@interface TableOperation : NSObject {
} +(int)getFolderRecordCount:(NSString*)iFolderName; +(void)check_Create_DB; +(BOOL)InsertFolder : (NSString )iFolderName; +(int)getFolderid:(NSString)iFolderName; +(NSMutableArray*)getallFolder;+(NSMutableArray*)getallFolder; +(BOOL)deleteByFid:(NSString*)fid;
static NSString *dbPath; static NSString *databaseName=@"Card.rsd";
@implementation TableOperation
//------------Create & Load database into application resource path when user launch first time this application--------- +(void)check_Create_DB { NSArray *docPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *docDir=[docPaths objectAtIndex:0]; dbPath =[[docDir stringByAppendingPathComponent:databaseName] retain]; BOOL success; NSFileManager *fm=[NSFileManager defaultManager]; success=[fm fileExistsAtPath:dbPath]; if(success){
return;
}
NSString *dbPathFromApp=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[fm copyItemAtPath:dbPathFromApp toPath:dbPath error:nil];
}
+(int)getFolderRecordCount:(NSString*)iFolderName{
sqlite3 *database = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
documentsDir = [documentsDir stringByAppendingPathComponent:databaseName];
sqlite3_stmt *selectstmt;
int RecordCount=0;
@try
{
if (sqlite3_open([documentsDir UTF8String], &database) == SQLITE_OK){
NSString *query = [NSString stringWithFormat:@"select * from tblFolder where FolderName='%@'",iFolderName];
const char *sqlStmt=[query UTF8String];
int i =sqlite3_prepare_v2(database,sqlStmt, -1,&selectstmt,NULL);
if(i == SQLITE_OK)
{
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
RecordCount++;
}
}
}
}
@catch (NSException *e) {
NSLog(@"%@",e);
}
return RecordCount;
}
+(BOOL)InsertFolder : (NSString *)iFolderName{ BOOL SuccessFullyInserted=NO; sqlite3 *database; if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { NSString *sqlTmp=[NSString stringWithFormat: @"insert into tblFolder values(NULL,'%@')",iFolderName]; const char *sqlStmt=[sqlTmp UTF8String]; sqlite3_stmt *cmp_sqlStmt; int returnValue = sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL); SuccessFullyInserted=((returnValue==SQLITE_OK) ? YES : NO ); sqlite3_step(cmp_sqlStmt); sqlite3_finalize(cmp_sqlStmt); } sqlite3_close(database); return SuccessFullyInserted; }
+(int)getFolderid:(NSString*)iFolderName{ sqlite3 *database = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
documentsDir = [documentsDir stringByAppendingPathComponent:databaseName];
int RecordCount=0;
@try
{
if (sqlite3_open([documentsDir UTF8String], &database) == SQLITE_OK){
NSString *query = [NSString stringWithFormat:@"select Folderid from tblFolder where FolderName='%@'",iFolderName];
const char *sqlStmt=[query UTF8String];
sqlite3_stmt *cmp_sqlStmt;
if(sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL)==SQLITE_OK) {
RecordCount=(int)sqlite3_column_int(cmp_sqlStmt, 0);
}
}
}
@catch (NSException *e) {
NSLog(@"%@",e);
}
return RecordCount; }
+(NSMutableArray*)getallFolder{ sqlite3 *database; NSMutableArray *ArrSecQ=[[NSMutableArray alloc] init]; if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { const char *sqlStmt="select Folderid,FolderName from tblFolder"; sqlite3_stmt *cmp_sqlStmt; if(sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL)==SQLITE_OK) { while(sqlite3_step(cmp_sqlStmt)==SQLITE_ROW) { int ID=(int)sqlite3_column_int(cmp_sqlStmt, 0); NSString fname=[NSString stringWithUTF8String:(char)sqlite3_column_text(cmp_sqlStmt, 1)];
NSMutableDictionary *dicObj=[[NSMutableDictionary alloc] init];
[dicObj setValue:[NSString stringWithFormat:@"%i",ID] forKey:@"Fid"];
[dicObj setValue:[NSString stringWithFormat:@"%@",fname] forKey:@"FName"];
NSDictionary *dic=[NSDictionary dictionaryWithDictionary:dicObj];
[ArrSecQ addObject:dic];
[dicObj release];
}
}
sqlite3_finalize(cmp_sqlStmt);
}
sqlite3_close(database);
return ArrSecQ;
}
+(BOOL)deleteByFid:(NSString*)fid{ sqlite3 *database; BOOL rtn=NO; if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { NSString *sqlTmp=[NSString stringWithFormat:@"delete from tblFolder WHERE Folderid=%@",fid]; const char *sqlStmt=[sqlTmp UTF8String]; sqlite3_stmt *cmp_sqlStmt; int returnValue = sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL); rtn=((returnValue==SQLITE_OK) ? YES : NO ); sqlite3_step(cmp_sqlStmt); sqlite3_finalize(cmp_sqlStmt); } sqlite3_close(database); return rtn; }
-(IBAction) Btnback:(id)sender{ [self.navigationController popViewControllerAnimated:YES]; }
(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; self.navigationController.navigationBarHidden = YES;
CATransition *animation = [[CATransition alloc] init]; animation.duration = 1.0; //animation.timingFunction = [CAMediaTimingFunction // functionWithName: kCAMediaTimingFunctionLinear ]; animation.type = kCATransitionPush; animation.subtype = kCATransitionFade; [self.view.layer addAnimation: animation forKey: @"" ]; [animation release];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(LoadMainMenuView) userInfo:NO repeats:NO]; }
-(void)LoadMainMenuView{
if(nxtMainMenu!=nil && [nxtMainMenu retainCount]>0){
[nxtMainMenu release];
nxtMainMenu = nil;
}
nxtMainMenu = [[MainMenuView alloc]
initWithNibName:@"MainMenuView" bundle:nil];
[self.navigationController pushViewController:nxtMainMenu animated:YES];
}