2014-01-21 32 views
0
public bool getsetClientes(ClassClientes cli, string id) 
{ 
    Dictionary<string, string> parametros = new Dictionary<string, string>(); 
    parametros.Add("@p1", id); 

    DataRow registo = this.GetRow("SELECT * FROM clientes WHERE id_cliente = @p1", parametros); 
    if (this.isEmptyRow(registo)) 
    { 
     cli.id = ""; 
     cli.nome = ""; 
     cli.dt_nasc = ""; 
     cli.sexo = ""; 
     cli.morada = ""; 
     cli.telefone = ""; 
     cli.contacto_emergencia = ""; 
     cli.parentesco = ""; 
     return false; 
    } 
    else 
    { 
     cli.id = registo[0].ToString(); 
     cli.nome = registo[1].ToString(); 
     cli.dt_nasc = registo[2].ToString(); 
     cli.sexo = registo[3].ToString(); 
     cli.morada = registo[4].ToString(); 
     cli.telefone = registo[5].ToString(); 
     cli.contacto_emergencia = registo[6].ToString(); 
     cli.parentesco = registo[7].ToString(); 
     return true; 
    } 

public class ClassClientes 
{ 
    //Variaveis 
    string _id; 
    string _nome; 
    string _dt_nasc; 
    string _sexo; 
    string _morada; 
    string _telefone; 
    string _contacto_emergencia; 
    string _parentesco; 

    //Constructores 
    public ClassClientes() 
    { 
     _id = ""; 
     _nome = ""; 
     _dt_nasc = ""; 
     _sexo = ""; 
     _morada = ""; 
     _telefone = ""; 
     _contacto_emergencia = ""; 
     _parentesco = ""; 

    } 

    public ClassClientes(string i, string n, string d, string s, string m, string t, string c,string p) 
    { 
     _id = i; 
     _nome = n; 
     _dt_nasc = d; 
     _sexo = s; 
     _morada = m; 
     _telefone = t; 
     _contacto_emergencia = c; 
     _parentesco = p; 
    } 

    //Propriedades 
    public string id { get { return _id; } set { _id = value; } } 
    public string nome { get { return _nome; } set { _nome = value; } } 
    public string dt_nasc { get { return _dt_nasc; } set { _dt_nasc = value; } } 
    public string sexo { get { return _sexo; } set { _sexo = value; } } 
    public string morada { get { return _morada; } set { _morada = value; } } 
    public string telefone { get { return _telefone; } set { _telefone = value; } } 
    public string contacto_emergencia { get { return _contacto_emergencia; } set { _contacto_emergencia = value; } } 
    public string parentesco { get { return _parentesco; } set { _parentesco = value; } } 

    //Metodos 
    public bool VerificaCampos(string crud, TextBox[] tbs) 
    { 
     string erros = ""; 
     int a; 

     if (crud == "CREATE") 
     { 
      if (tbs[1].Text == "") erros += "Inserir Nome!"; 
      if (tbs[2].Text == "") erros += "Inserir Data de Nascimento!"; 
      if (tbs[3].Text == "") erros += "Inserir Sexo!"; 
      if (tbs[4].Text == "") erros += "Inserir Morada!"; 
      if (tbs[5].Text == "") erros += "Inserir Telefone!"; 
      if (tbs[6].Text == "") erros += "Inserir Contacto de Emergencia"; 
      if (tbs[7].Text == "") erros += "Inserir Contacto de Parentesco do contacto de Emergencia"; 
      else if (tbs[3].Text.Length != 1) erros += "Inserir M ou F no Sexo!"; 
      else if (tbs[5].Text.Length != 9) erros += "Inserir Telefone com 9 digitos!"; 
      else if (tbs[6].Text.Length != 9) erros += "Inserir Contacto de Emergencia com 9 digitos!"; 
     } 
     else if (crud == "READ") 
     { 
      if (tbs[0].Text == "") erros += "O id nao pode ser vazio!"; 
      else if (!int.TryParse(tbs[0].Text, out a)) erros += "O id tem que ser numerico!"; 
     } 
     else if (crud == "UPDATE") 
     { 
      if (tbs[1].Text == "") erros += "Inserir Nome!"; 
      if (tbs[2].Text == "") erros += "Inserir Data de Nascimento!"; 
      if (tbs[3].Text == "") erros += "Inserir Sexo!"; 
      if (tbs[4].Text == "") erros += "Inserir Morada!"; 
      if (tbs[5].Text == "") erros += "Inserir Telefone!"; 
      if (tbs[6].Text == "") erros += "Inserir Contacto de Emergencia"; 
      if (tbs[7].Text == "") erros += "Inserir Contacto de Parentesco do contacto de Emergencia"; 
      else if (tbs[3].Text.Length != 1) erros += "Inserir M ou F no Sexo!"; 
      else if (tbs[5].Text.Length != 9) erros += "Inserir Telefone com 9 digitos!"; 
      else if (tbs[6].Text.Length != 9) erros += "Inserir Contacto de Emergencia com 9 digitos!"; 
     } 
     else if (crud == "DELETE") 
     { 
      if (tbs[0].Text == "") erros += "O id nao pode ser vazio!"; 
      else if (!int.TryParse(tbs[0].Text, out a)) erros += "O id tem que ser numerico!"; 
     } 

     if (erros == "") 
     { 
      return true; 
     } 
     else 
     { 
      MessageBox.Show(erros); 
      return false; 
     } 
    } 

    public void preencherCampos(ClassClientes cli, TextBox[] tbs) 
    { 
     tbs[0].Text = cli.id.ToString(); 
     tbs[1].Text = cli.nome.ToString(); 
     tbs[2].Text = cli.dt_nasc.ToString(); 
     tbs[3].Text = cli.sexo.ToString(); 
     tbs[4].Text = cli.morada.ToString(); 
     tbs[5].Text = cli.telefone.ToString(); 
     tbs[6].Text = cli.contacto_emergencia.ToString(); 
     tbs[7].Text = cli.parentesco.ToString(); 
    } 

    public void limpar(TextBox[] tbs) 
    { 
     _id = ""; 
     _nome = ""; 
     _dt_nasc = ""; 
     _sexo = ""; 
     _morada = ""; 
     _telefone = ""; 
     _contacto_emergencia = ""; 
     _parentesco = ""; 

     foreach (TextBox tb in tbs) 
     { 
      tb.Text = ""; 
     } 
    } 
} 

有較少acessible,ClassClientes都在那裏;我有所有類public不一致的可訪問性;參數類型比方法

錯誤消息:

錯誤1可訪問性不一致:參數類型 'WindowsFormsApplication1.ClassClientes' 比方法 'AAR_CLASSES.aar_mysql.getsetClientes(WindowsFormsApplication1.ClassClientes,字符串)' 不易接近C:\用戶\ JOAO \桌面\ PAP \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ AAR_mysql.cs 469 21 WindowsFormsApplication1

+2

你確定'ClassClients'類設置爲'public'嗎? – MarcinJuraszek

+0

是的,那將是我要檢查的第一件事。 –

+0

是的,我在這裏尋找解決方案,這是我做的第一件事 – user3221369

回答

0

這裏有一個簡單的例子:

internal class ThisActsAsAParameter 
{ 
} 

public class ThisIsAPublicClass 
{ 
    public void PublicMethod(ThisActsAsAParameter theParameter) 
    { 
    } 
} 

如果在一個單獨的編譯單元中的客戶端是調用PublicMethod,客戶端將需要創建ThisActsAsAParameter類型的對象中,以作爲一個參數傳遞。這是不可能的,因爲ThisActsAsAParameter在編譯單元之外是不可見的。

只要確保這兩個WindowsFormsApplication1ClassClientes也是公開的。

+0

ClassClientes是公開的 – user3221369

+0

@ user3221369 - WindowsFormsApplication1是公開的嗎? –

+0

WindowsFormsApplication1是項目的名稱我該如何公開它? – user3221369

0

的問題是你有2類是沒有足夠的權限查看對方。

  1. 您可以將它們都移動到同一個位置。
  2. 您可以將相應的訪問修飾符設置爲public。
  3. 您可以更改您的設計。

解決方案一:
使用重建來看看它的編譯。
重建是Visual Studio中的一個命令,用於清除舊的可執行文件並生成新的可執行文件。

解決方法二:
檢查ClassClientes是以其他類名WindowsFormsApplication1private/internal改性劑。
如果是,則將其更改爲public

+0

我在1日和2日xD失去了你 – user3221369

相關問題