2011-08-18 3 views
1

Je suis en train de créer un bouton de recherche où un ID de client ou son NOM DE FAMILLE peuvent être utilisés pour rechercher les détails des clients. lorsque le nom est utilisé pour la recherche, les clients ID, Nom et otherName suolud être affichés sur un autre form1 L'ID fonctionne correctement mais le PRÉNOM est dis jouer « enregistrement not found » pls me aidentRecherche ne fonctionnant pas

private void lklSearch_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
     { 



      SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); 
      conn.ConnectionString = "Data Source=pc101;Initial Catalog=REMITTANCE;User ID=sa;Password=mike"; 
      conn.Open(); 


      try 
      { 
       Personal person = new Personal(); 
       Remittances Remitt = new Remittances(); 

       if (person.searchpersonDetails(txtClientid.Text, txtSurname.Text)) 
       { 
        var 
        _with3 = this; 
        _with3.txtClientid.Text = person.ID.ToString(); 
        _with3.txtSurname.Text = person.Sname.ToString(); 
        _with3.txtOthername.Text = person.Oname.ToString(); 



        if (person.sex.ToString() == "Male") 
        { 
         optMale.Checked = true; 
        } 
        else 
        { 
         optFemale.Checked = true; 
        } 

        _with3.dtpDob.Value = person.BirthDate; 
        _with3.txtNationality.Text = person.country.ToString(); 
        _with3.txtResidentialaddress.Text = person.addressResidential.ToString(); 
        _with3.txtPostaladdress.Text = person.AddressPostal.ToString(); 
        _with3.txtContactnumber.Text = person.NumberContact.ToString(); 

        string mstatus = person.statusMarital.ToString(); 
        switch (mstatus) 
        { 
         case "Single": 
          this.cboMaritalstatus.Text = "Single"; 
          break; 
         case "Married": 
          _with3.cboMaritalstatus.Text = "Married"; 
          break; 
         case "Widow(er)": 
          _with3.cboMaritalstatus.Text = "Widow(er)"; 
          break; 
         case "Divorce": 
          _with3.cboMaritalstatus.Text = "Divorce"; 
          break; 
        } 

        _with3.txtSpousename.Text = person.nameSpouse.ToString(); 
        _with3.txtEmail.Text = person.mail.ToString(); 
        _with3.txtOccupation.Text = person.Work.ToString(); 

        string iType = person.idtype.ToString(); 
        switch (iType) 
        { 
         case "Bank ID Card": 
          _with3.cboIdtype.Text = "Bank ID Card"; 
          break; 
         case "Driver Licence": 
          _with3.cboIdtype.Text = "Driver Licence"; 
          break; 
         case "Passport": 
          _with3.cboIdtype.Text = "Passport"; 
          break; 
         case "National Identification": 
          _with3.cboIdtype.Text = "National Identification"; 
          break; 
         case "NHIS": 
          _with3.cboIdtype.Text = "NHIS"; 
          break; 
         case "SSNIT": 
          _with3.cboIdtype.Text = "SSNIT"; 
          break; 
         case "Voters ID": 
          _with3.cboIdtype.Text = "Voters ID"; 
          break; 
        } 

        _with3.txtIdnumber.Text = person.numberID.ToString(); 
        _with3.dtpExpiringdate.Value = person.expirydateID; 
        _with3.txtRemarks.Text = person.myremarks.ToString(); 



        btnPUpdate.Enabled = true; 
        this.txtSclientid.Text = this.txtClientid.Text; 
        this.txtSclientid.ReadOnly = true; 

       } 
       else 
       { 
        MessageBox.Show("Record not found"); 
       } 




       if (Remitt.searchremitDetails(txtClientid.Text)) 
       { 

        var _with4 = this; 
        txtClientid.Text = Remitt.ID.ToString(); 
        _with4.txtSecretcode.Text = Remitt.Scode.ToString(); 

        string sendCountry = cboSendingcountry.Text; 
        switch (sendCountry) 
        { 
         case "Germany": 
          _with4.cboSendingcountry.Text = "Germany"; 
          break; 
         case "Ghana": 
          _with4.cboSendingcountry.Text = "Ghana"; 
          break; 
        } 

        string sendBranch = cboSendingbranch.Text; 
        switch (sendBranch) 
        { 
         case "Accra": 
          _with4.cboSendingbranch.Text = "Accra"; 
          break; 
         case "Dotmond": 
          _with4.cboSendingbranch.Text = "Dotmond"; 
          break; 
         case "Dusseldurf": 
          _with4.cboSendingbranch.Text = "Dusseldurf"; 
          break; 
         case "Koln": 
          _with4.cboSendingbranch.Text = "Koln"; 
          break; 
         case "Kumasi": 
          _with4.cboSendingbranch.Text = "Kumasi"; 
          break; 
        } 

        string sendCurrency = cboScurrency.Text; 
        switch (sendCurrency) 
        { 
         case "Cedis": 
          _with4.cboScurrency.Text = "Cedis"; 
          break; 
         case "Euros": 
          _with4.cboScurrency.Text = "Euros"; 
          break; 
        } 

        _with4.txtAmountsent.Text = Remitt.Totalamount.ToString(); 
        _with4.txtCommission.Text = Remitt.Tax.ToString(); 

        string remitStatus = cboStatus.Text; 
        switch (remitStatus) 
        { 
         case "Not Sent": 
          _with4.cboStatus.Text = "Not Sent"; 
          break; 
         case "Sent": 
          _with4.cboStatus.Text = "Sent"; 
          break; 
        } 

        _with4.dtpDatesent.Value = Remitt.Sentdate; 
        _with4.txtReceiversname.Text = Remitt.Nameofreceiver.ToString(); 

        string receiveCountry = cboReceivingcountry.Text; 
        switch (receiveCountry) 
        { 
         case "Germany": 
          _with4.cboReceivingcountry.Text = "Germany"; 
          break; 
         case "Ghana": 
          _with4.cboReceivingcountry.Text = "Ghana"; 
          break; 
        } 

        string receiveBranch = cboReceivingbranch.Text; 
        switch (receiveBranch) 
        { 

         case "Accra": 
          _with4.cboReceivingbranch.Text = "Accra"; 
          break; 
         case "Dotmond": 
          _with4.cboReceivingbranch.Text = "Dotmond"; 
          break; 
         case "Dusseldurf": 
          _with4.cboReceivingbranch.Text = "Dusseldurf"; 
          break; 
         case "Koln": 
          _with4.cboReceivingbranch.Text = "Koln"; 
          break; 
         case "Kumasi": 
          _with4.cboReceivingbranch.Text = "Kumasi"; 
          break; 
        } 


        string receiveCurrency = cboRcurrency.Text; 
        switch (receiveCurrency) 
        { 
         case "Cedis": 
          _with4.cboRcurrency.Text = "Cedis"; 
          break; 
         case "Euros": 
          _with4.cboRcurrency.Text = "Euros"; 
          break; 
        } 


        _with4.txtSremarks.Text = Remitt.Remarksremit.ToString(); 

        lklRsearch.Enabled = false; 
        txtSclientid.ReadOnly = true; 
        btnRUpdate.Enabled = true; 

       } 

       else 
       { 
        MessageBox.Show("Record not found"); 
       } 

       } 

      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 

      finally 
      { 
       // Close data reader object and database connection 


       if (conn.State == ConnectionState.Open) 
        conn.Close(); 
      } 

     } 




codes in the class 

public bool searchpersonDetails(string personid, string personname) 
     { 

      SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); 
      conn.ConnectionString = "Data Source=pc101;Initial Catalog=REMITTANCE;User ID=sa;Password=mike"; 
      conn.Open(); 


     if (personid == null) 
      { 
       Module1 clientid = new Module1(); 

       Fom1 frm = new Fom1(personname); 
       frm.ShowDialog(); 
       personid = clientid.ToString(); 
      } 

     SqlCommand cmd = new SqlCommand(); 
     string sqlQuery = null; 
     sqlQuery = "select *,floor(datediff(getdate(),date_ofbirth)/365) AS AGE from tblspersonaldetails where client_id='" + personid + "'"; 

     sqlQuery = "select * from tblspersonaldetails where client_id='" + personid + "'"; 

     cmd.Connection = conn; 
     cmd.CommandText = sqlQuery; 
     cmd.CommandType = System.Data.CommandType.Text; 

     SqlDataReader dr = null; 
     dr = cmd.ExecuteReader(); 
     if (dr.Read()) 
     { 
      client_id = dr["client_id"].ToString(); 
      surname = dr["surname"].ToString(); 
      othername = dr["othername"].ToString(); 
      gender = dr["gender"].ToString(); 
      date_ofbirth = (DateTime) dr["date_ofbirth"]; 
      nationality = dr["nationality"].ToString(); 
      age = dr["age"].ToString(); 
      residential_address = dr["residential_address"].ToString(); 
      postal_address = dr["postal_address"].ToString(); 
      contact_number = dr["contact_number"].ToString(); 
      marital_status = dr["marital_status"].ToString(); 
      spouse_name = dr["spouse_name"].ToString(); 
      email = dr["email"].ToString(); 
      occupation = dr["occupation"].ToString(); 
      typeof_id = dr["typeof_id"].ToString(); 
      id_number = dr["id_number"].ToString(); 
      id_expirydate = (DateTime) dr["id_expirydate"]; 
      remarks = dr["remarks"].ToString(); 
      picture = dr["picture"].ToString(); 
      return true; 
      //cmd.CommandText = null; 
     } 

     else 
     { 
      return false; 
     } 

      conn.Close(); 



    } 

Répondre

2

dans la mesure où je peux voir que vous ne traduisez pas le personnage en clientid (ou est-ce fait dans l'inconnu-à-nous Module1?).

Vous avez donc besoin d'un moyen de traduire le nom de famille en un personnage ou vous devez utiliser différentes requêtes pour ces cas.

Et: pourquoi y a-t-il deux requêtes où la seconde remplace la première? En dehors de cela: s'il vous plaît ne créez pas de requêtes SQL avec concaténation de chaînes (recherche d'injection SQL)

Questions connexes