美文网首页
转化时间戳、改变图片颜色、项目中数据库sql语句

转化时间戳、改变图片颜色、项目中数据库sql语句

作者: J_HX | 来源:发表于2017-03-31 16:46 被阅读14次

+(NSInteger)timeSwitchTimestamp:(NSString *)formatTime andFormatter:(NSString *)format{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

[formatter setTimeStyle:NSDateFormatterShortStyle];

[formatter setDateFormat:format]; //(@"YYYY-MM-dd hh:mm:ss") ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制



NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];

[formatter setTimeZone:timeZone];



NSDate* date = [formatter dateFromString:formatTime]; //------------将字符串按formatter转成nsdate

//时间转时间戳的方法:

NSInteger timeSp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];



NSLog(@"将某个时间转化成 时间戳&&&&&&&timeSp:%ld",(long)timeSp); //时间戳的值



return timeSp;

}

  • (UIImage *)imageMaskWithColor:(UIColor *)maskColor {
    if (!maskColor) {
    return nil;
    }
    UIImage *newImage = nil;

    CGRect imageRect = (CGRect){CGPointZero,self.size};
    UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, self.scale);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -(imageRect.size.height));

    CGContextClipToMask(context, imageRect, self.CGImage);//选中选区 获取不透明区域路径
    CGContextSetFillColorWithColor(context, maskColor.CGColor);//设置颜色
    CGContextFillRect(context, imageRect);//绘制
    newImage = UIGraphicsGetImageFromCurrentImageContext();//提取图片

    UIGraphicsEndImageContext();
    return newImage;
    }

/**

  • 打开数据库
    */
  • (BOOL)openDb {
    NSString path = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject];
    NSString pathName = [path stringByAppendingString:@"LTGreenDB.sqlite"];
    NSLog(@"%@", pathName);
    db = [FMDatabase databaseWithPath:pathName];
    int result = [db open];
    if (result) {
    NSLog(@"打开成功");
    } else {
    NSLog(@"打开失败");
    }
    return result;
    }
    /
  • 创建表格
    */
  • (void)creatShopGreenChildTable {
    if ([self openDb]) {
    BOOL result = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS LTGreenTableView (ltId integer PRIMARY KEY AUTOINCREMENT, dataId integer NOT NULL, typeId integer NOT NULL, tpyeDicID integer NOT NULL, LTDic TEXT NOT NULL);"];
    if (result) {
    NSLog(@"创建表格成功");
    } else {
    NSLog(@"创建表格失败");
    }
    [db close];
    }
    }
    /**
  • 插入了数据
    */
  • (void)insertDataSource:(NSArray *)modelArray WithString:(NSString *)string {

    if ([db open]) {
    int p = 0;
    int q = 0;
    for (int i = 0; i < modelArray.count; i++) {
    NSMutableDictionary *dic = [modelArray[i] mutableCopy];
    NSString dicString = [dic mj_JSONString];
    NSString insertSqlite = nil;
    int typeDicID = 0;
    int forId = 0;
    if ([string isEqualToString:@"3"]) {
    typeDicID = [dic[@"type"] intValue];
    if (typeDicID == 3) {
    forId = p;
    p++;
    } else {
    forId = q;
    q++;
    }
    } else {
    forId = i;
    }
    insertSqlite = [NSString stringWithFormat:@"INSERT INTO LTGreenTableView (dataId, tpyeDicID, typeId, LTDic) VALUES ('%d','%d', '%d', '%@')", forId,typeDicID , [string intValue], dicString];
    BOOL res = [db executeUpdate:insertSqlite];
    if (res) {
    // NSLog(@"插入数据成功");
    } else {
    // NSLog(@"插入数据失败");
    }
    }
    [db close];
    }
    }
    /

  • 删除的全部数据
    */
  • (void)deleteAllData {
    if ([db open]) {
    //清空数据表并将自增字段清零
    NSString *deleteSql = @"DELETE FROM LTGreenTableView where 1=1";
    [db executeUpdate:@"UPDATE sqlite_sequence set seq = 0 where name = 'LTGreenTableView'"];
    BOOL res = [db executeUpdate:deleteSql];
    if (res) {
    NSLog(@"清空shopCar表数据成功");
    } else {
    NSLog(@"清空shopCar表数据失败");
    }

      [db close];
    

    }

}
/**

  • 查找方法
    */
  • (NSArray<NSMutableDictionary *> *)selectTypeData:(NSString *)type tpyeDicID:(int)tpyeDicID {
    NSMutableArray *arr = [NSMutableArray array];
    if ([db open]) {
    NSString * sql = [NSString stringWithFormat:@"SELECT * FROM LTGreenTableView WHERE typeId = '%d' and tpyeDicID = '%d'", [type intValue], tpyeDicID];
    FMResultSet * rs = [db executeQuery:sql];
    while ([rs next]) {
    NSString *dic = [rs stringForColumn:@"LTDic"];
        NSData *dat = [dic dataUsingEncoding:NSUTF8StringEncoding];
        NSMutableDictionary *d = [[NSJSONSerialization JSONObjectWithData:dat options:0 error:nil] mutableCopy];
        if ([type isEqualToString:@"3"]) {
            int sd = [rs intForColumn:@"dataId"];
            [d setObject:[NSString stringWithFormat:@"%d", sd] forKey:@"dataId"];
        }
        [arr addObject:d];
    }
    [db close];
}
return arr;

}
/**

  • 修改资料的查询方法
    */
  • (NSMutableDictionary *)selectType:(NSString *)type tpyeDicID:(int)tpyeDicID dataId:(NSString *)dataId {
    NSMutableDictionary *d = [NSMutableDictionary dictionary];
    if ([db open]) {
    NSString * sql = [NSString stringWithFormat:@"SELECT * FROM LTGreenTableView WHERE typeId = '%d' and tpyeDicID = '%d' and dataId = '%d'", [type intValue], tpyeDicID, [dataId intValue]];
    FMResultSet * rs = [db executeQuery:sql];
    while ([rs next]) {
    NSString *dic = [rs stringForColumn:@"LTDic"];
    NSLog(@"%@", dic);
    NSData *dat = [dic dataUsingEncoding:NSUTF8StringEncoding];
    d = [[NSJSONSerialization JSONObjectWithData:dat options:0 error:nil] mutableCopy];
    }
    [db close];
    }
    return d;
    }

/**

  • 修改数据方法
    */
  • (BOOL)updataDbidData:(NSString *)updata Dictype:(int)Dictype seleDataID:(NSString *)seleDataId btnSelect:(BOOL)btnSelect
    {
    BOOL res = nil;
    NSMutableDictionary *dic = [self selectType:updata tpyeDicID:Dictype dataId:seleDataId];
    if (btnSelect) {
    [dic setObject:@"1" forKey:@"FLAG"];
    NSLog(@"/开%d", btnSelect);
    } else {
    [dic setObject:@"0" forKey:@"FLAG"];
    NSLog(@"、关%d", btnSelect);
    }
    NSString *stringDic = [dic mj_JSONString];
    if ([db open]) {
    NSLog(@" updata === %@, dictype = %d , seleddataid = %d", updata, Dictype, [seleDataId intValue]);
    NSString *updateSql = [NSString stringWithFormat:@"update LTGreenTableView set LTDic = '%@' where typeId = '%d' and tpyeDicID = '%d' and dataId = '%d'", stringDic, [updata intValue], Dictype, [seleDataId intValue]];
    res = [db executeUpdate:updateSql];
    [db close];
    }
    return res;
    }

相关文章

  • 转化时间戳、改变图片颜色、项目中数据库sql语句

    +(NSInteger)timeSwitchTimestamp:(NSString *)formatTime an...

  • mysql数据库文章

    MySQL指南之SQL语句基础sql语法--菜鸟教程 mysql数据库中字符串格式的13位时间戳转换为日期格式 S...

  • iOS数据库优化

    1.改变sql语句,做分表查询,内存组合数据 2.不改变sql语句,添加索引,加快查询速度。 3.区分对待数据库串...

  • DbUtils使用与源码分析

    DbUtils 1 准备工作 建立数据库demo 运行示例项目中的demo.sql文件里面的sql语句 往dep...

  • 12.1KOA mysql 数据库

    mysql 数据库 安装 mysql 模块 使用数据库连接执行 SQL 语句 使用数据库连接池执行 SQL 语句

  • SQL分类

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • SQL语句的分类

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • 第2章 SQL语句的分类和DML语句

    1.SQL语句的分类 DDL语句(数据定义语句)主要用于定义数据库对象的SQL语句数据库对象:表(table),列...

  • SQL预编译

    1.数据库预编译起源 (1)数据库SQL语句编译特性:数据库接受到sql语句之后,需要词法和语义解析,优化sql语...

  • 数据库SQL语言入门(二)

    系列文章: 数据库SQL语言入门(一)数据库SQL语言入门(三) DDL语句 常用的SQL语句关键字有 creat...

网友评论

      本文标题:转化时间戳、改变图片颜色、项目中数据库sql语句

      本文链接:https://www.haomeiwen.com/subject/bnyvottx.html