01.
-(
void
)SaveRecvInvoice
02.
{
03.
NSString
*docDIR;
04.
NSArray
*dirPath;
05.
06.
dirPath =
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
);
07.
docDIR = dirPath[0];
08.
09.
_databasePath = [[
NSString
alloc] initWithString:[docDIR stringByAppendingPathComponent:@
"consign.db"
]];
10.
11.
sqlite3_stmt *statement =
NULL
;
12.
const
char
*dbpath = [_databasePath UTF8String];
13.
14.
if
(sqlite3_open(dbpath, &_DB) == SQLITE_OK)
15.
{
16.
17.
NSDateFormatter
*DateFormatter = [[
NSDateFormatter
alloc]init];
18.
[DateFormatter setDateFormat:@
"yyyy-MM-dd"
];
19.
NSString
*nowDate = [
NSString
stringWithFormat:@
"%@"
,[DateFormatter stringFromDate:[
NSDate
date]]];
20.
21.
for
(
id
obj in myObject)
22.
{
23.
NSString
*invoice_id = [obj objectForKey:@
"Inv"
];
24.
NSString
*strBar = [obj objectForKey:@
"Bar"
];
25.
NSString
*strModel = [obj objectForKey:@
"Procode"
];
26.
NSString
*strSize = [obj objectForKey:@
"Size"
];
27.
NSString
*color_id = [obj objectForKey:@
"Colorcode"
];
28.
NSString
*color = [obj objectForKey:@
"Desc"
];
29.
NSString
*strPrice = [obj objectForKey:@
"Price"
];
30.
NSString
*strQtys = [obj objectForKey:@
"Qty"
];
31.
NSString
*strDisc = [obj objectForKey:@
"Disc"
];
32.
NSString
*strAmt = [obj objectForKey:@
"Amt"
];
33.
NSString
*us = [
self
QueryUser];
34.
35.
NSString
*insertSQL = [
NSString
stringWithFormat:@
"INSERT INTO recivedInv (user, docno, recvdate, barcode, prodcode, colorcode, desc, size, qty, price, dicper, amt, last_date) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\",\"%@\",\"%@\", \"%@\",\"%@\", \"%@\", \"%@\", \"%@\")"
,us, invoice_id, nowDate, strBar, strModel, color_id, color, strSize, strQtys, strPrice, strDisc, strAmt, nowDate];
36.
37.
const
char
*insert_statement = [insertSQL UTF8String];
38.
sqlite3_prepare_v2(_DB, insert_statement, -1, &statement,
NULL
);
39.
40.
if
(sqlite3_step(statement) != SQLITE_DONE)
41.
{
42.
[
self
showUIAlertWithMessage:@
"Failed to add sqlite database"
andTitle:@
"Error"
];
43.
NSLog
( @
"Failed from sqlite3_step. Error is: %s"
, sqlite3_errmsg(_DB));
44.
}
45.
}
46.
47.
sqlite3_finalize(statement);
48.
sqlite3_close(_DB);
49.
}
50.
}