18 Replies Latest reply on Jan 11, 2011 8:31 PM by BhaskerChari

    How to get the zero of phone number eg. 0612345678

    Buxsnl

      Dear Adobe Flex Builder Professionals,

       

      I've got a problem with getting the zero of a phone number eg. 0612345678

       

      If I enter the folowing phone number as input:

       

      0612345678

       

      I will get the phone number as output:

       

      612345678

       

      The application has been written in Adobe Flex Builder 3.

       

       

       

      The code of the MXML file is:

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
      creationComplete="init()"
      horizontalScrollPolicy="off" verticalScrollPolicy="off">

      <mx:Metadata>
        [Event(name="customerSaveEvent", type="events.CustomerEvent")]
        [Event(name="customerCancelEvent", type="flash.events.Event")]
      </mx:Metadata>

      <mx:Script>
        <![CDATA[
         import util.ComboBoxUtil;
         import mx.controls.Alert;
         import events.CustomerEvent;
         import mx.collections.ArrayCollection;
         import mx.core.Application;
         import valueObject.Customer;
         import mx.validators.Validator;
         import mx.validators.PhoneNumberValidator;
        
         private var phoneCheck:PhoneNumberValidator;
           
         [Bindable]
         public var selectedCustomer:Customer;
        
         private function init():void{
          //this.cretePhoneValidator();
          if(this.selectedCustomer == null){
           this.clearForm(null);
          }
         }
        
         private function cretePhoneValidator():void{
          phoneCheck = new PhoneNumberValidator();
          phoneCheck.source = phoneNumber;
          phoneCheck.property = "text";
         } 
        
         private function validateForm():void {
          //var validatorList:Array = new Array(emailCheck, phoneCheck);
          //Validator.validateAll(validatorList);
         }
        
         private function cancelClickHandler():void{
          var cancelManageCustomerObj:Event = new Event("customerCancelEvent");
          dispatchEvent(cancelManageCustomerObj);
         }
           
         private function saveCustomer():void {
          //validateForm();
         
           var c:Customer = null;
           var selCust:Customer = Application.application.selectedCustomer;
          
           if(selCust != null){
            c = selCust;
           } else {
            c = new Customer();          
           }
           c.setLastName(lastName.text);
           c.setFirstName(firstName.text);
           c.setStreet(street.text);
           c.setPostal(postal.text);
           c.setCity(city.text);
           c.setEmail(email.text);
           c.setPhoneNumber(new Number(phoneNumber.text));
           c.setMailing(mailing.selectedItem.data);
           c.setComment(comment.text);
           var modified: Customer = Application.application.customerService.createOrUpdate(c);
               
          var customerEventObj:CustomerEvent = new CustomerEvent("customerSaveEvent", modified);
          dispatchEvent(customerEventObj);
         
          this.clearForm(selCust);
          }
         
          private function clearForm(selCust:Customer):void{
           if(selCust == null){
            this.lastName.text = "";
            this.firstName.text = "";
            this.street.text = "";
            this.postal.text = "";
            this.city.text  = "";
            this.phoneNumber.text = "";
            this.email.text = "";
            this.mailing.selectedIndex = 0;
            this.comment.text  = "";
           }    
           focusManager.setFocus(lastName);
          }
        ]]>
      </mx:Script>

      <!--mx:EmailValidator id="emailCheck" source="{email}" property="text"
        trigger="{save}" triggerEvent="click"/-->
       
      <mx:Form id="manageCustomerForm">
        <mx:FormItem label="Achternaam:">
         <mx:TextInput id="lastName" text="{selectedCustomer.getLastName()}"/>
        </mx:FormItem>
        <mx:FormItem label="Voorletters:">
         <mx:TextInput id="firstName" text="{selectedCustomer.getFirstName()}"/>
        </mx:FormItem>
        <mx:FormItem label="Straat:">
         <mx:TextInput id="street" text="{selectedCustomer.getStreet()}"/>
        </mx:FormItem>
        <mx:FormItem label="Postcode:">
         <mx:TextInput id="postal" text="{selectedCustomer.getPostal()}"/>
        </mx:FormItem>
        <mx:FormItem label="Stad:">
         <mx:TextInput id="city" text="{selectedCustomer.getCity()}"/>
        </mx:FormItem>
        <mx:FormItem label="Telefoonnummer:">
         <mx:TextInput id="phoneNumber" text="{selectedCustomer.getPhoneNumber()}"/>
        </mx:FormItem>
        <mx:FormItem label="E-mail:">
         <mx:TextInput id="email" text="{selectedCustomer.getEmail()}"/>
        </mx:FormItem>
        <mx:FormItem label="Opmerkingen:" >
         <mx:TextArea id="comment" text="{selectedCustomer.getComment()}"
           width="447" height="144"/>
        </mx:FormItem>
        <mx:FormItem label="Mailing:">
         <mx:ComboBox id="mailing" dataProvider="{Application.application.comboBoxUtil.yesNo}"
          selectedIndex="{ComboBoxUtil.getIndex(selectedCustomer.getMailing())}"/>
        </mx:FormItem>
        <mx:HBox id="manageButtonBox">  
         <mx:Button id="save" label="Opslaan" click="saveCustomer()" />  
         <mx:Button id="resetButton" label="Wis" click="clearForm(null)" />  
         <mx:Button id="cancelButton" label="Annuleer" click="cancelClickHandler()" />
         
        </mx:HBox> 
      </mx:Form>
      </mx:Canvas>

       

       

       

      The code of the SQL file is:

       

       

       

      create table customer (
      id integer not null primary key autoincrement,
      lastName VARCHAR(50),
      firstName VARCHAR(50),
      street VARCHAR(50),
      city VARCHAR(50),
      postal VARCHAR(10),
      phoneNumber INT(10),
      email VARCHAR(50),
      mailing boolean default false,
      comment VARCHAR(255)
      );

      create table treatment (
      id integer not null primary key autoincrement,
      date Date,
      treatment varchar(255),
      customerId integer not null,
      constraint fk_customer foreign key(customerId) references customer(id)
      );

      create table user (
      id integer not null primary key autoincrement,
      loginName varchar(50) not null,
      lastName varchar(50) not null,
      firstName varchar(50) not null,
      password varchar(50) not null,
      active boolean not null default true,
      accessright varchar(10) not null
      );

      create table agenda (
      id integer not null primary key autoincrement,
      userId integer not null,
      date Date,
      hour integer,
      minute integer,
      description varchar(50),
      constraint fk_user foreign key(userId) references user(id)
      );

      create table license (
      id integer not null primary key autoincrement,
      key varchar(50),
      val varchar(50)
      );

       

       

       

      I hope someone can help me with this problem.

        • 1. Re: How to get the zero of phone number eg. 0612345678
          Gregory Lafrance Level 6

          I think you need to boil down your code to a minimal code sample. Your posted code is mostly irrelevant to the problem, and includes dependencies (main app and other classes/components) making it impossible to run your code.

           

          Boiling it down may reveal the issue, or at least it makes it easier for us to help you.

          • 2. Re: How to get the zero of phone number eg. 0612345678
            Buxsnl Level 1

            What would you like to have that solve the problem?

            • 3. Re: How to get the zero of phone number eg. 0612345678
              Buxsnl Level 1

              Maybe the Application file?

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
              xmlns:comp="components.*"
              xmlns:user="components.user.*"
              xmlns:customer="components.customer.*"
              xmlns:treatment="components.treatment.*"
              xmlns:agenda="components.agenda.*"
              horizontalGap="15"
              layout="absolute"
              backgroundColor="#6D98AB"
              width="1024"
              height="768"
              title=""
              initialize="init()" currentState="loginState">
               
              <mx:states>
                <mx:State name="listState">
                 <mx:RemoveChild target="{editBox}"/>
                 <mx:RemoveChild target="{customerDetails}"/>
                 <mx:RemoveChild target="{loginBox}"/>
                </mx:State>
                <mx:State name="detailState">
                 <mx:RemoveChild target="{editBox}"/>
                 <mx:RemoveChild target="{loginBox}"/>
                </mx:State>
                <mx:State name="editState">
                 <mx:RemoveChild target="{customerDetails}"/>
                 <mx:RemoveChild target="{loginBox}"/>
                </mx:State>
                <mx:State name="loginState">
                 <mx:RemoveChild target="{searchBox}"/>
                 <mx:RemoveChild target="{customerList}"/>
                 <mx:RemoveChild target="{editBox}"/>
                 <mx:RemoveChild target="{customerDetails}"/>
                 <mx:RemoveChild target="{tabNav}"/>
                 <mx:RemoveChild target="{dateLabel}"/>
                 <mx:RemoveChild target="{welcomeUserLabel}"/>
                 <mx:RemoveChild target="{logOutLink}"/>
                </mx:State>
                <mx:State name="userState">
                 <mx:RemoveChild target="{loginBox}"/>
                 <mx:RemoveChild target="{customerDetails}"/>
                 <mx:RemoveChild target="{editBox}"/>
                </mx:State>
                <mx:State name="userDetailState" basedOn="userState">
                 <mx:AddChild relativeTo="{usersTab}" position="lastChild">
                  <user:userDetails id="userDetails" width="334"
                    selectedUser="{selectedUser}" includeInLayout="false" top="82" x="377"/>
                 </mx:AddChild>
                </mx:State>
                <mx:State name="userEditState" basedOn="userState">
                 <mx:AddChild relativeTo="{usersTab}" position="lastChild">
                  <user:userManagement id="userManagement" x="377" y="80"
                    userSaveEvent="userSaveEventHandler(event)" 
                    userCancelEvent="currentState='userState'" height="305"/>
                 </mx:AddChild>
                </mx:State>
              </mx:states>

               

              <mx:transitions>
                <mx:Transition fromState="loginState" toState="listState">
                 <mx:Sequence>
                  <mx:WipeLeft target="{loginBox}" showTarget="false" />
                  <mx:RemoveChildAction target="{loginBox}"/>
                  <mx:AddChildAction target="{tabNav}"/>
                  <mx:WipeRight target="{tabNav}"/>
                  <mx:AddChildAction targets="{[customerList, searchBox]}"/>
                  <mx:WipeRight targets="{[customerList, searchBox]}"/>  
                 </mx:Sequence>  
                </mx:Transition>
                <mx:Transition fromState="listState" toState="detailState">
                 <mx:WipeRight target="{customerDetails}"/>
                </mx:Transition>
                <mx:Transition fromState="listState" toState="editState">
                 <mx:WipeRight target="{editBox}"/>
                </mx:Transition>
                <mx:Transition fromState="detailState" toState="editState">
                 <mx:WipeRight target="{editBox}"/>
                </mx:Transition>
                <mx:Transition fromState="editState" toState="detailState">
                 <mx:WipeRight target="{customerDetails}"/>
                </mx:Transition>
                <mx:Transition fromState="editState" toState="listState">
                 <mx:Sequence>
                  <mx:WipeLeft target="{editBox}" showTarget="false"/>
                  <mx:RemoveChildAction target="{editBox}" />
                 </mx:Sequence>  
                </mx:Transition>
                <mx:Transition fromState="detailState" toState="listState">
                 <mx:Sequence>
                  <mx:WipeLeft target="{customerDetails}" showTarget="false"/>
                  <mx:RemoveChildAction target="{customerDetails}" />
                 </mx:Sequence>  
                </mx:Transition>
                <mx:Transition fromState="*" toState="userEditState">
                 <mx:WipeRight target="{userManagement}"/>
                </mx:Transition>
                <mx:Transition fromState="userEditState" toState="userState">
                 <mx:Sequence>
                  <mx:WipeLeft target="{userManagement}" showTarget="false"/>
                  <mx:RemoveChildAction target="{userManagement}" />
                 </mx:Sequence>
                </mx:Transition>
                <mx:Transition fromState="usertState" toState="userDetailState">
                 <mx:Sequence>
                  <mx:WipeLeft target="{userManagement}" showTarget="false"/>
                  <mx:RemoveChildAction target="{userDetails}" />
                 </mx:Sequence>
                </mx:Transition>
              </mx:transitions>

               

              <mx:Style source="css/cis.css"/>

               

              <mx:Script>
                <![CDATA[
                 import mx.utils.ObjectUtil;
                 import manager.InstallationManager;
                 import manager.LicenseManager;
                 import manager.SecurityManager;
                 import mx.resources.ResourceBundle;
                 import util.ComboBoxUtil;
                 import enum.States;
                 import valueObject.Treatment;
                 import mx.controls.Alert;
                 import valueObject.User;
                 import service.UserService;
                 import util.DbUtil;
                 import events.UserEvent;
                 import air.update.events.UpdateEvent;
                 import mx.events.CollectionEvent;
                 import mx.core.Application;
                 import service.CustomerService;
                 import service.CisService;
                 import mx.collections.XMLListCollection;
                 import events.CustomerEvent;
                 import valueObject.Customer;
                 import mx.binding.utils.BindingUtils;
                 import mx.collections.ArrayCollection;
                 import mx.rpc.events.ResultEvent;
                
                 [Bindable]
                 private var todayDate:Date = new Date();
                
                 [Bindable]
                 private var treatmentData:ArrayCollection;
                
                 [Bindable]
                 private var userData:ArrayCollection;
                
                 [Bindable]
                 public var selectedCustomer:Customer;
                
                 [Bindable]
                 public var selectedTreatment:Treatment;
                
                
                 [Bindable]
                 public var selectedUser:User;
                
                 public var loggedInUser:User;
                 public var connection:SQLConnection;
                 public var customerService:CustomerService;
                 public var userService:UserService;
                 public var cisService:CisService;
                 public var comboBoxUtil:ComboBoxUtil = new ComboBoxUtil();
                 public var secMgr:SecurityManager;
                
                 private function init():void { 
                  var dbUtil:DbUtil = new DbUtil();
                  this.connection = dbUtil.getConnection();
                 
                  this.customerService = new CustomerService();
                  this.userService = new UserService();
                  this.cisService = new CisService();
                  var instMgr:InstallationManager = new InstallationManager(dbUtil, this);
                 
                  if(!dbUtil.isNewDB()){
                   this.userData = this.userService.getUsers();
                  }   
                 
                  if(this.userData == null){
                   this.userData = new ArrayCollection();
                  }
                 }   
                
                 private function userLoginEventHandler(event:UserEvent):void{
                  currentState = "listState";
                  this.loggedInUser = event.user;   
                 
                  if(this.loggedInUser != null){
                   var txt:String = "Welkom" + loggedInUser.getFirstName() + " " +
                    loggedInUser.getLastName();
                   this.welcomeUserLabel.text = txt;
                   this.logOutLink.visible = true;
                   this.secMgr = new SecurityManager(this.loggedInUser);
                  }
                 }
                
                 private function userLogout():void{
                  currentState = "loginState";
                  this.loggedInUser = null;
                  this.welcomeUserLabel.text = "";
                  this.logOutLink.visible = false;
                  this.loginBox.loginName.text = "";
                  this.loginBox.password.text = "";
                 }
                 
                  private function selectCustomerEventHandler(event:CustomerEvent):void {
                   this.selectedCustomer = event.customer;
                   this.updateCustomer();
                  }
                 
                  private function selectedUserEventHandler(event:UserEvent):void{
                   this.selectedUser = event.user;
                   currentState = "userDetailState";
                   this.updateUserButton.visible = true;
                   this.deleteUsertButton.visible = true;
                  }
                 
                  private function customerSaveEventHandler(event:CustomerEvent):void{
                   if(this.selectedCustomer == null){
                    this.customerList.customerData.addItem(event.customer);
                   } else {
                    this.customerList.customerData = this.customerService.getCustomers();
                   }
                   currentState="listState";   
                  }
                 
                  public function userSaveEventHandler(event:UserEvent):void{
                   if(this.selectedUser == null){
                    this.userData.addItem(event.user);
                   } else {
                    this.userData = this.userService.getUsers();
                   }
                  }
                 
                  public function newCustomer():void{
                   this.editBox.selectedCustomer = null;
                   this.selectedCustomer = null;
                   currentState = "editState";
                  }
                 
                  public function newUser():void{
                   currentState = "userEditState";
                   this.selectedUser = null;
                   this.userManagement.selectedUser = null;   
                  }
                 
                  public function updateCustomer():void{
                   editBox.selectedCustomer = this.selectedCustomer;
                   currentState="editState";
                  }
                 
                  public function updateUser():void{    
                   currentState = "userEditState";
                   userManagement.selectedUser = this.selectedUser;
                  }
                 
                  public function deleteUser():void{
                   this.userData.removeItemAt(this.userList.usergrid.selectedIndex);
                   this.userService.deleteUser(this.selectedUser);
                   this.updateUserButton.visible = false;
                   this.deleteUsertButton.visible = false;
                   this.selectedUser = null;
                   currentState = "userState";
                  }
                ]]>
              </mx:Script>

               

              <comp:login id="loginBox" x="20" y="82" userLoginEvent="userLoginEventHandler(event)"/>
              <mx:DateFormatter id="dateDisplay" formatString="EEEE DD MMMM YYYY" />
              <mx:Label id="nameLabel" text="" bottom="20" right="20"/>

               

              <mx:Label text="C" styleName="logoMainText" top="20" left="20"/>
              <mx:Label text="ustomer" id="label2" top="34" x="43"/>
              <mx:Label text="I" styleName="logoMainText" top="20" x="98"/>
              <mx:Label text="nformation" top="34" x="106"/>
              <mx:Label text="S" styleName="logoMainText" top="20" x="175"/>
              <mx:Label text="ystem" top="34" x="196"/>
                
              <mx:Label id="dateLabel" text="{dateDisplay.format(todayDate)}"  top="10" right="20"/>
              <mx:Label id="welcomeUserLabel" right="20" top="40"/>
              <mx:LinkButton id="logOutLink" label="Uitloggen" visible="false"  click="{userLogout()}"
                right="20" top="70"/>
               
              <mx:TabNavigator id="tabNav" width="98%" height="80%" top="80" left="10"> 
               
                <mx:Canvas id="customersTab" label="Klanten" width="100%" height="100%">
                 <comp:search id="searchBox" customerData="{customerList.customerData}" top="40" left="20"/>
                 <customer:customerList id="customerList"
                  selectCustomerEvent="selectCustomerEventHandler(event) " top="80" left="20" bottom="60"/> 
                
                 <mx:HBox id="buttonBox" width="40%" bottom="20" left="20">
                  <mx:Button id="newCustomerButton" label="Nieuw"  click="newCustomer()"/>
                  <mx:Button id="updateCustomerButton" label="Wijzig" visible="false"
                   click="updateCustomer()"/>
                 </mx:HBox>
                 
                 <customer:customerManagement  id="editBox"
                  customerSaveEvent="customerSaveEventHandler(event)"
                  customerCancelEvent="currentState='listState'" includeInLayout="false" top="82" x="377"/>
                 <customer:customerDetails id="customerDetails" width="357"
                  selectedCustomer="{selectedCustomer}" includeInLayout="false" top="82" x="377" height="209"/>  
                </mx:Canvas>
                 
                <mx:Canvas id="usersTab" label="Gebruikers" width="100%" height="100%">
                 <user:searchUser id="searchUserBox" userData="{userData}" top="40" left="20"/>
                 <user:userList id="userList" gridData="{userData}"
                  selectUserEvent="selectedUserEventHandler(event)" top="80" left="20" bottom="60"/>    
                 
                 <mx:HBox id="userButtonBox" width="40%" bottom="20" left="20">
                  <mx:Button id="newUserButton" label="Nieuw" click="newUser()"/>
                  <mx:Button id="updateUserButton" label="Wijzig" visible="false"
                   click="updateUser()"/>
                  <mx:Button id="deleteUsertButton" label="Verwijder" visible="false"
                   click="deleteUser()"/>
                 </mx:HBox>
                </mx:Canvas>

               

                <mx:Canvas id="adminTab" label="Admin" width="100%" height="100%">
                 <comp:cisAdmin id="admin"/>
                </mx:Canvas>
              </mx:TabNavigator>
              <mx:Label x="285" text="DigiTiko" top="20" fontSize="40" color="#000000"/>

               

              </mx:WindowedApplication>

              • 4. Re: How to get the zero of phone number eg. 0612345678
                Buxsnl Level 1

                Customer Details?

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

                 

                <mx:Script>
                  <![CDATA[
                   import valueObject.Customer;
                  
                   [Bindable]
                   public var selectedCustomer:Customer; 
                  ]]>
                </mx:Script>
                <mx:Label id="idLabel" text="{selectedCustomer.getId()}" left="138" y="36"/>
                <mx:Label text="Voornaam: " top="46" left="10"/>
                <mx:Label id="firstNameLabel" text="{selectedCustomer.getFirstName()}" left="138" y="46"/>
                <mx:Label text="Achternaam: " top="66" left="10"/>
                <mx:Label id="lastNameLabel" text="{selectedCustomer.getLastName()}" left="138" y="66"/>
                <mx:Label text="Straat: " top="86" left="10"/>
                <mx:Label id="StreetLabel" text="{selectedCustomer.getStreet()}" left="138" y="86"/>
                <mx:Label text="Postcode: " top="106" left="10"/>
                <mx:Label id="PostalLabel" text="{selectedCustomer.getPostal()}" left="138" y="106"/>
                <mx:Label text="Stad: " top="126" left="10"/>
                <mx:Label id="CityLabel" text="{selectedCustomer.getCity()}" left="138" y="126"/>
                <mx:Label text="Telefoonnummer: " top="146" left="10"/>
                <mx:Label id="phoneNumberLabel" text="{selectedCustomer.getPhoneNumber()}" left="138" y="146"/>
                <mx:Label text="E-mail: " top="166" left="10"/>
                <mx:Label id="emailLabel" text="{selectedCustomer.getEmail()}" left="138" y="166"/>
                <mx:Label text="Mailing: " top="186" left="10"/>
                <mx:Label id="mailingLabel" text="{selectedCustomer.getMailing()}" left="138" y="186"/>
                <mx:Label text="Commentaar: " top="206" left="10"/>
                <mx:Text id="commentLabel" text="{selectedCustomer.getComment()}" left="138" y="206"/>
                </mx:Canvas>

                • 5. Re: How to get the zero of phone number eg. 0612345678
                  Buxsnl Level 1

                  Customer List?

                   

                  <?xml version="1.0" encoding="utf-8"?>

                   

                  <mx:Canvas xmlns:mx="

                  http://www.adobe.com/2006/mxml

                  "

                  initialize="init()">

                   

                  <mx:Metadata>

                   

                    [Event(name="selectCustomerEvent", type="events.CustomerEvent")]

                   

                  </mx:Metadata>

                   

                  <mx:Script>

                   

                    <![CDATA[

                   

                     import mx.core.Application;

                   

                   

                     import service.CustomerService;


                     import events.CustomerEvent;


                     import valueObject.Customer;


                     import mx.events.ListEvent;


                     import mx.collections.ArrayCollection;


                    


                     [Bindable]


                     public var customerData:ArrayCollection;


                    


                     private var customerService:CustomerService;


                    


                     private function init():void{


                      this.customerService = new CustomerService();


                      this.customerData = this.customerService.getCustomers();


                     


                      if(this.customerData == null){


                       this.customerData = new ArrayCollection();


                      }


                     }


                    


                     private function itemClickHandler(event:ListEvent):void {


                      if(event.columnIndex != 0){


                       var customerData:Customer;


                       customerData = event.itemRenderer.data as Customer;


                       var customerEventObj:CustomerEvent = new CustomerEvent("selectCustomerEvent", customerData);


                       dispatchEvent(customerEventObj);


                      } 


                     }


                    


                     public function deleteCustomer(id:int):void{


                      var cust:Customer = new Customer();


                      cust.setId(id);


                      this.customerService.deleteCustomer(cust);


                      this.customerData.removeItemAt(customerGrid.selectedIndex);


                     }


                    ]]>


                  </mx:Script>



                  <mx:DataGrid id="customerGrid" dataProvider="{customerData}" height="100%"


                    itemClick="itemClickHandler(event)" width="340">


                    <mx:columns>


                     <mx:DataGridColumn deactivate="true" dataField="id" headerText=" " width="15">


                            <mx:itemRenderer>


                              <mx:Component>


                                <mx:Image source="images/delete.jpg" click="outerDocument.deleteCustomer(data.id)"


                                 buttonMode="true" height="15" width="15"/>


                              </mx:Component>


                            </mx:itemRenderer>


                          </mx:DataGridColumn>


                     <mx:DataGridColumn dataField="lastName" headerText="Achternaam" />


                     <mx:DataGridColumn dataField="firstName" headerText="Voorletters" />


                    </mx:columns>


                  </mx:DataGrid>


                  </mx:Canvas>


                  • 6. Re: How to get the zero of phone number eg. 0612345678
                    Flex Rock Level 1

                    Hi,

                             Actually your problem is not able to retreive zero from the textinput where you entered the phone number, am i correct or if not please explain little more specific about your problem instead of giving so many mxml files.

                     

                    Thanks,

                    Jayagopal.

                    • 7. Re: How to get the zero of phone number eg. 0612345678
                      BhaskerChari Level 4

                      Hi Buxsnl,

                       

                      I suggest you it's better to take phone number field as string datatype instead of int datatype. So change your datatype from int to string so that you can save the 0 as well.

                       

                      So problem with what now you are using is that you are typecasting the text entered in your phone number text input to Number datatype and there your 0 gets truncated in your Phone Number. Its always better to take a number with large digits as a String(Varchar) datatype.

                       

                      Thanks,

                      Bhasker

                      • 8. Re: How to get the zero of phone number eg. 0612345678
                        Buxsnl Level 1

                        Could you give me an example how to make a string (VARCHAR) datatype?

                         

                        Like?

                         

                        phoneNumber VARCHAR(10)

                        • 9. Re: How to get the zero of phone number eg. 0612345678
                          Buxsnl Level 1

                          If I change the string datatype to VARCHAR, it won't help. Does someone knows if there is an another function to solve the problem?

                          • 10. Re: How to get the zero of phone number eg. 0612345678
                            BhaskerChari Level 4

                            I am not asking you to change string datatype to varchar...In your SQL table change the datatype PHONENUMBER datatype to Varchar(10) instead of INT

                             

                            Observe below the text in bold I have changed the datatype to VARCHAR(10)

                             

                            create table customer (
                            id integer not null primary key autoincrement,
                            lastName VARCHAR(50),
                            firstName VARCHAR(50),
                            street VARCHAR(50),
                            city VARCHAR(50),
                            postal VARCHAR(10),
                            phoneNumber VARCHAR(10),
                            email VARCHAR(50),
                            mailing boolean default false,
                            comment VARCHAR(255)
                            );

                             

                            Also in your Flex code where you are using any type conversions or variable declarations related to phonenumber change it to String conversion  or String datatype.

                             

                            In your saveCustomer() function change the line of code to below

                            c.setPhoneNumber(phoneNumber.text);


                            In getPhoneNumber() function return the phone number as a String datatype but not typecast to Number datatype
                            <mx:TextInput id="phoneNumber" text="{selectedCustomer.getPhoneNumber()}"/>

                             

                             

                             

                            Thanks,

                            Bhasker

                            • 11. Re: How to get the zero of phone number eg. 0612345678
                              Buxsnl Level 1

                              While changing the following:

                               

                              c.setPhoneNumber(new Number(phoneNumber.text));

                               

                              to

                               

                              c.setPhoneNumber(phoneNumber.text);

                               

                              I get the following error:

                               

                              1067: Implicit coercion of a value of type String to an unrelated type Number

                               

                              Do I something wrong?

                              • 12. Re: How to get the zero of phone number eg. 0612345678
                                Flex Rock Level 1

                                Actually setPhoneNumber() expects the argumnet in datatype 'number'. So it throws error while passing a string data to that function.

                                You can do on thing

                                 

                                c.setPhoneNumber(new Number(phoneNumber.text)).toString();

                                 

                                 

                                Thanks,

                                Jayagopal.

                                • 13. Re: How to get the zero of phone number eg. 0612345678
                                  BhaskerChari Level 4

                                  What code do you have exactly in your setPhoneNumber() function ..??

                                   

                                  Can you post code for that function..??

                                   

                                  You need to convert the accepting parameter type also to be of String datatype...

                                   

                                   

                                  public function setPhoneNumber(phoneNumber:String)

                                  {

                                       //Here is your Logic

                                  }

                                   

                                  and you will call as c.setPhoneNumber(phoneNumber.text);

                                   

                                  Thanks,

                                  Bhasker

                                  • 14. Re: How to get the zero of phone number eg. 0612345678
                                    Buxsnl Level 1

                                    Jayagopal,

                                     

                                    When I replace:

                                     

                                    c.setPhoneNumber(new Number(phoneNumber.text));

                                     

                                    To:

                                     

                                    c.setPhoneNumber(new Number(phoneNumber.text)).toString();

                                     

                                    I'll get the following error:

                                     

                                    1061: call to a possibly undefined method to String through a reference with static type

                                     

                                    Can someone help me with that?

                                    • 15. Re: How to get the zero of phone number eg. 0612345678
                                      Buxsnl Level 1

                                      Bhasker,

                                       

                                      This is the full code:

                                       

                                      <?xml version="1.0" encoding="utf-8"?>
                                      <!--
                                      Customer Information System (CIS)
                                      Copyright © 2010 Thushani Software Foundation (TSF) - Suresh van Rookhuizen
                                      See license agreement which comes with this software.
                                      All rights reserved.
                                      -->
                                      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                                      creationComplete="init()"
                                      horizontalScrollPolicy="off" verticalScrollPolicy="off">

                                      <mx:Metadata>
                                        [Event(name="customerSaveEvent", type="events.CustomerEvent")]
                                        [Event(name="customerCancelEvent", type="flash.events.Event")]
                                      </mx:Metadata>

                                      <mx:Script>
                                        <![CDATA[
                                         import util.ComboBoxUtil;
                                         import mx.controls.Alert;
                                         import events.CustomerEvent;
                                         import mx.collections.ArrayCollection;
                                         import mx.core.Application;
                                         import valueObject.Customer;
                                         import mx.validators.Validator;
                                         import mx.validators.PhoneNumberValidator;
                                        
                                         private var phoneCheck:PhoneNumberValidator;
                                           
                                         [Bindable]
                                         public var selectedCustomer:Customer;
                                        
                                         private function init():void{
                                          //this.cretePhoneValidator();
                                          if(this.selectedCustomer == null){
                                           this.clearForm(null);
                                          }
                                         }
                                        
                                         private function cretePhoneValidator():void{
                                          phoneCheck = new PhoneNumberValidator();
                                          phoneCheck.source = phoneNumber;
                                          phoneCheck.property = "text";
                                         } 
                                        
                                         private function validateForm():void {
                                          //var validatorList:Array = new Array(emailCheck, phoneCheck);
                                          //Validator.validateAll(validatorList);
                                         }
                                        
                                         private function cancelClickHandler():void{
                                          var cancelManageCustomerObj:Event = new Event("customerCancelEvent");
                                          dispatchEvent(cancelManageCustomerObj);
                                         }
                                           
                                         private function saveCustomer():void {
                                          //validateForm();
                                         
                                           var c:Customer = null;
                                           var selCust:Customer = Application.application.selectedCustomer;
                                          
                                           if(selCust != null){
                                            c = selCust;
                                           } else {
                                            c = new Customer();          
                                           }
                                           c.setLastName(lastName.text);
                                           c.setFirstName(firstName.text);
                                           c.setStreet(street.text);
                                           c.setPostal(postal.text);
                                           c.setCity(city.text);
                                           c.setEmail(email.text);
                                           c.setPhoneNumber(new Number(phoneNumber.text)).toString();
                                           c.setMailing(mailing.selectedItem.data);
                                           c.setComment(comment.text);
                                           var modified: Customer = Application.application.customerService.createOrUpdate(c);
                                               
                                          var customerEventObj:CustomerEvent = new CustomerEvent("customerSaveEvent", modified);
                                          dispatchEvent(customerEventObj);
                                         
                                          this.clearForm(selCust);
                                          }
                                         
                                          private function clearForm(selCust:Customer):void{
                                           if(selCust == null){
                                            this.lastName.text = "";
                                            this.firstName.text = "";
                                            this.street.text = "";
                                            this.postal.text = "";
                                            this.city.text  = "";
                                            this.phoneNumber.text = "";
                                            this.email.text = "";
                                            this.mailing.selectedIndex = 0;
                                            this.comment.text  = "";
                                           }    
                                           focusManager.setFocus(lastName);
                                          }
                                        ]]>
                                      </mx:Script>

                                      <!--mx:EmailValidator id="emailCheck" source="{email}" property="text"
                                        trigger="{save}" triggerEvent="click"/-->
                                       
                                      <mx:Form id="manageCustomerForm">
                                        <mx:FormItem label="Achternaam:">
                                         <mx:TextInput id="lastName" text="{selectedCustomer.getLastName()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Voorletters:">
                                         <mx:TextInput id="firstName" text="{selectedCustomer.getFirstName()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Straat:">
                                         <mx:TextInput id="street" text="{selectedCustomer.getStreet()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Postcode:">
                                         <mx:TextInput id="postal" text="{selectedCustomer.getPostal()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Stad:">
                                         <mx:TextInput id="city" text="{selectedCustomer.getCity()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Telefoonnummer:">
                                         <mx:TextInput id="phoneNumber" text="{selectedCustomer.getPhoneNumber()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="E-mail:">
                                         <mx:TextInput id="email" text="{selectedCustomer.getEmail()}"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Opmerkingen:" >
                                         <mx:TextArea id="comment" text="{selectedCustomer.getComment()}"
                                           width="447" height="144"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Mailing:">
                                         <mx:ComboBox id="mailing" dataProvider="{Application.application.comboBoxUtil.yesNo}"
                                          selectedIndex="{ComboBoxUtil.getIndex(selectedCustomer.getMailing())}"/>
                                        </mx:FormItem>
                                        <mx:HBox id="manageButtonBox">  
                                         <mx:Button id="save" label="Opslaan" click="saveCustomer()" />  
                                         <mx:Button id="resetButton" label="Wis" click="clearForm(null)" />  
                                         <mx:Button id="cancelButton" label="Annuleer" click="cancelClickHandler()" />
                                         
                                        </mx:HBox> 
                                      </mx:Form>
                                      </mx:Canvas>

                                       

                                      I hope you can help me.

                                      • 16. Re: How to get the zero of phone number eg. 0612345678
                                        BhaskerChari Level 4

                                        Hi Buxsnl,

                                         

                                        I think I already gave the answer in my previous post. But think you did not implement it..

                                         

                                        The below line of code is unnecessary ...

                                        c.setPhoneNumber(new Number(phoneNumber.text)).toString();

                                        Instead you can replace it with the below one...

                                        c.setPhoneNumber(phoneNumber.text);

                                         

                                        and the setPhoneNumber() function in your Customer class should be below:

                                        public function setPhoneNumber(phoneNumber:String):void

                                        {

                                             //

                                        }

                                         

                                        Can you post the code of your Customer class..??

                                         

                                         

                                        Thanks,

                                        Bhasker

                                        • 17. Re: How to get the zero of phone number eg. 0612345678
                                          Buxsnl Level 1

                                          Bhasker,

                                           

                                          I don't have a setPhoneNumber() function in my Customer class.

                                           

                                          Can you help me with making a setPhoneNumber() function in my the Customer class?

                                           

                                          I can also send my project to you, so you can see what I did wrong?

                                          • 18. Re: How to get the zero of phone number eg. 0612345678
                                            BhaskerChari Level 4

                                            Hi Buxsnl,

                                             

                                            I wonder how you are calling setPhoneNumber() function when you are not having that function in the Customer Class.

                                             

                                            However if you need can email me the project at bhaskerchari903@gmail.com

                                             

                                            Thanks,

                                            Bhasker