提交给服务器

//提交到服务器

-(void) addDishDataToServer:(BOOL)modify

{

    NSString *strurl =[NSStringstringWithFormat:@"%@/menus.php",HTTP_SERVER];

    NSURL *url = [NSURL URLWithString:strurl];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    

    NSData *imageData =UIImagePNGRepresentation(_dishImageBtn.currentBackgroundImage);

    NSString *imageName = [_dishName.text stringByAppendingString:@".png"];

    [request setData:imageData withFileName:imageNameandContentType:@"image/png" forKey:@"uploadImage"];

    //NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];

    

    //getUserList 请求数据

    

    if(modify)

    {

        [self.dishDic setObject:@"updateMenu" forKey:@"action"];

        [self.dishDic setObject:_dishID.text forKey:@"MID"];

        

        if(_isSellOutBtn.selected)

        {

            [self.dishDic setObject:@"1" forKey:@"MSellOut"];

        }

        else

        {

            [self.dishDic setObject:@"0" forKey:@"MSellOut"];

        }

    }

    else

    {

        [self.dishDic setObject:@"saveMenu" forKey:@"action"];

    }

    NSData *postData = [NSJSONSerialization dataWithJSONObject:self.dishDicoptions:NSJSONWritingPrettyPrinted error:nil]; //data是字符串

    

    NSString *postString = [[NSString allocinitWithData:postDataencoding:NSUTF8StringEncoding];//data格式的postdata转换成string格式

    

    [request setPostValue:postString forKey:@"data"];  //传值

    [request setCompletionBlock:^{

        

        [mainViewController showHintAlertView:NO withMsg:@"正在上传中,请稍后..."];


        //阻塞块可以吧整个函数作为变量,传到setCompletionBlock

        NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:request.responseDataoptions:NSJSONReadingMutableContainers error:nil];

        //把服务器返回的json字符串的data转化成dictionary

        

        if([[dic objectForKey:@"statusID"isEqualToString:@"0"])

        {

            NSString *msg = [dic objectForKey:@"msg"];

            UIAlertView *alertV = [[UIAlertView allocinitWithTitle:@"提示"message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];

            [alertV show];

            [alertV release];

        }

        else

        {

            NSString *msg = [dic objectForKey:@"msg"];

            UIAlertView *alertV = [[UIAlertView allocinitWithTitle:@"提示"message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];

            [alertV show];

            [alertV release];

        }

        NSLog(@"%@",request.responseString);

    }]; //返回数据

    

    [request setFailedBlock:^{

        

        [mainViewController showHintAlertView:NO withMsg:@"正在上传中,请稍后..."];

        

    }];

    

    [request startAsynchronous];

    [postString release];


}



//确认增加

-(IBAction) addBtnAction:(id)sender

{

    if(![self checkInput])

    {

        return;

    }


    [mainViewController showHintAlertView:YES withMsg:@"正在上传中,请稍后..."];


    self.dishDic = [[NSMutableDictionary allocinit];

//        [self.dishDic setObject:_dishImageBtn.currentBackgroundImage forKey:@"dishImage"];

    [self.dishDic setObject:_dishName.text forKey:@"MName"];

    

    NSString *mType = @"";

    if(_fastfoodBtn.selected)

        mType = _fastfoodBtn.titleLabel.text;

    if(_snackBtn.selected)

        mType = _snackBtn.titleLabel.text;

    if(_drinkBtn.selected)

        mType = _drinkBtn.titleLabel.text;

    

    [self.dishDic setObject:mType forKey:@"MType"];

    [self.dishDic setObject:_dishDescribe.text forKey:@"MDescription"];

    [self.dishDic setObject:_dishPrice.text forKey:@"MPrice"];

    

    if(_isSpecialBtn.selected)

    {

        [self.dishDic setObject:@"1" forKey:@"MSpecial"];

    }

    else

    {

        [self.dishDic setObject:@"0" forKey:@"MSpecial"];

    }

    if(self._dishID.text.length > 5)

    {

        [self addDishDataToServer:YES];

    }

    else

    {

        [self addDishDataToServer:NO];

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值