flex单选按钮添加记录

test.mxml

<?xml version="1.0" encoding="utf-8"?>
<!--http://blog.csdn.net/lionFromAsia/archive/2008/11/27/3393067.aspx-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onInit()" xmlns="*" fontSize="14" layout="absolute" backgroundGradientColors="[#ffffff, #c0c0c0]">
   <mx:Script>
           <![CDATA[
                     public function onInit():void
                   {
                           userRequest.send();
                   }

   import mx.controls.Alert;                                 //引入Alert完整组件类
            import mx.events.CloseEvent;
                  
   private function alertPopup(event:Event):void{
   if(userid.text!=""){
       Alert.okLabel="确定";                                    //修改OK按钮上的文字
       Alert.cancelLabel="取消";                                //修改Cancel按钮上的文字
              //调用Alert.show()弹出对话框,对话框上有确定和取消按钮
   //Alert.show("您确定要删除吗?", "警告", 3, this, alertClickHandler);
   Alert.show("您确定要删除吗?", "警告", Alert.OK|Alert.CANCEL, this, alertClickHandler);
   }
   else{
   Alert.okLabel="确定";                                    //修改OK按钮上的文字
              //调用Alert.show()弹出对话框,对话框上有确定和取消按钮
   Alert.show("请选择要删除的记录!!","警告",Alert.OK);
     }
  } 
  
         private function alertClickHandler(event:CloseEvent):void {
                if (event.detail==Alert.OK){
                   userRequest.send();
       showAndHide(1000);
                }
                else{
                }
            }

            import mx.controls.Alert;
            import mx.managers.PopUpManager;
 
            private var alert:Alert;
 
            private function showAndHide(delay:Number):void {
                var alertText:String = "成功删除!";
                var alertTitle:String = "恭喜";
                alert = Alert.show(alertText, alertTitle);
                setTimeout(hideAlert, delay);
            }
 
            private function hideAlert():void {
                PopUpManager.removePopUp(alert);
            }
        ]]>
    </mx:Script> 
 
    <mx:Script>
        <![CDATA[
            import mx.events.ItemClickEvent;
 
            private function radioGroup_itemClick(evt:ItemClickEvent):void {
                var now:String = new Date().toTimeString();
                lbl.text = evt.label + " (" + now + ")";
                //useredit.send();
            }
           
           
                public function add():void
                     {
                      if(lbl.text==""){
                      Alert.show("请选择选项!!","警告",Alert.OK);  
                      }
                      else{
                     useredit.send();
                     Alert.show("添加成功!!","警告",Alert.OK);
                     userRequest.send();
                      }
                     }  
                    
        ]]>
    </mx:Script>
   
   
   
   <mx:Label id="label1" text="Datagrid实例" x="74" y="113" fontSize="20"></mx:Label>
       <mx:HTTPService id="useredit" url="datagrid.php" useProxy="false" method="POST">
       <mx:request xmlns="">
         <lbl>{lbl.text}</lbl>
       </mx:request>
   </mx:HTTPService>
  
   <mx:HTTPService id="userRequest" url="datagrid.php" useProxy="false" method="POST">
       <mx:request xmlns="">
         <userid>{userid.text}</userid>
       </mx:request>
   </mx:HTTPService>
<mx:ApplicationControlBar id="duck" width="1008" y="24" height="59">
 <mx:Label id="lbl" fontWeight="bold"  width="100%" visible="false"/>
</mx:ApplicationControlBar>
       
   <mx:DataGrid id="dgUserRequest" x="74" y="152" dataProvider="{userRequest.lastResult.users.user}" width="581" textAlign="center" height="212">
       <mx:columns>
         <mx:DataGridColumn headerText="用户ID" dataField="userid"/>
         <mx:DataGridColumn headerText="用户名" dataField="username"/>
         <mx:DataGridColumn headerText="Email" dataField="emailaddress"/>
       </mx:columns>
   </mx:DataGrid>
   <mx:Button  label="删除" click="alertPopup(event)" x="74" y="387"/>
     <mx:TextInput x="230" y="102" id="userid" text="{dgUserRequest.selectedItem.userid}" visible="false" width="48"/>
    
    <mx:RadioButtonGroup id="radioGroup"
            itemClick="radioGroup_itemClick(event);" />

    <mx:VBox x="771" y="152">
        <mx:RadioButton id="radioButton1"
                label="Red"
                group="{radioGroup}" />
        <mx:RadioButton id="radioButton2"
                label="Orange"
                group="{radioGroup}" />
        <mx:RadioButton id="radioButton3"
                label="Yellow"
                group="{radioGroup}" />
        <mx:RadioButton id="radioButton4"
                label="Green"
                group="{radioGroup}" />
        <mx:RadioButton id="radioButton5"
                label="Blue"
                group="{radioGroup}" />
                 <mx:Button x="191" y="152" label="Add" click="add()" color="#0A15F8"/>
    </mx:VBox>
    
</mx:Application>
datagrid.php
<?php
header("content-type:text/html;charset=utf-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include "conn.php";
if (!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST') {
 if($_POST["userid"]!=""){
$sql="delete from login where id=".$_POST["userid"]."";
echo $sql;
$result=mysql_query($sql);
}
if($_POST["countryname"]!=""){
$sql="insert into login(name,mail,content) values('".$_POST["countryname"]."','a','a')";
echo $sql;
$result=mysql_query($sql);
}
if($_POST["lbl"]!=""){
$sql="insert into login(name,mail,content) values('".$_POST["lbl"]."','a','a')";
echo $sql;
$result=mysql_query($sql);
}
}
$sql="select * from login";
$result=mysql_query($sql);
$xml_return = "<users>";
while ($user = mysql_fetch_array($result)){
 $xml_return .="<user><userid>".$user['id']."</userid><username>".$user['name']."</username><emailaddress>".$user['mail']."</emailaddress></user>
";
}
$xml_return.= "</users>";
echo $xml_return;
?>

    A+
发布日期:2009年12月13日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: