Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Firestore检查字段是否存在_Java_Android_Google Cloud Firestore - Fatal编程技术网

Java Android Firestore检查字段是否存在

Java Android Firestore检查字段是否存在,java,android,google-cloud-firestore,Java,Android,Google Cloud Firestore,我需要帮助解决一个问题。 我是Firestore的新手,我来自MySQL。 我有一个用户注册(餐馆老板)的登记表,应用程序工作,数据保存得很好。 但问题是,当用户注册时,如果该餐厅的名称与数据库中已存在的另一家餐厅的名称相同,则我无法阻止注册 在代码中,首先检查是否有相同的文档,如果它不存在,我想检查餐厅的名称,如果它与另一个名称相同,则阻止所有内容并停止录制 我试图通过插入dbristoratore.collection(“餐馆老板”)来实现这一点。其中,Equalto(“名称餐厅”,名称餐厅

我需要帮助解决一个问题。 我是Firestore的新手,我来自MySQL。 我有一个用户注册(餐馆老板)的登记表,应用程序工作,数据保存得很好。 但问题是,当用户注册时,如果该餐厅的名称与数据库中已存在的另一家餐厅的名称相同,则我无法阻止注册

在代码中,首先检查是否有相同的文档,如果它不存在,我想检查餐厅的名称,如果它与另一个名称相同,则阻止所有内容并停止录制

我试图通过插入
dbristoratore.collection(“餐馆老板”)来实现这一点。其中,Equalto(“名称餐厅”,名称餐厅)在IF但无的情况下。
但是,如果我用一种方法回忆起来,它是有效的,但问题是,如果餐厅的名称是免费的,我不知道如何切换到注册。
代码是这样的

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_r_r_start);

        nomeristoratore =(EditText)findViewById(R.id.editText7);
        cognomeristoratore =(EditText)findViewById(R.id.editText8);
        nomeristorante = (EditText)findViewById(R.id.editText10);
        data_nascitaristoratore =(EditText)findViewById(R.id.editText9);
        id_fkristoratore =(EditText)findViewById(R.id.editText11);
        numero_telefonoristoratore =(EditText)findViewById(R.id.editText12);

        rGroupristoratore = (RadioGroup)findViewById(R.id.radiogroup2);

        registraristoratore = (Button)findViewById(R.id.button4);

        registraristoratore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                registrazioneRistoratore();
            }

            private void registrazioneRistoratore() {
                final String nomeR = nomeristoratore.getText().toString();
                final String cognomeR = cognomeristoratore.getText().toString();
                final String nomeRistoranteR = nomeristorante.getText().toString();
                final String dataR = data_nascitaristoratore.getText().toString();
                final String id_fk_R = id_fkristoratore.getText().toString();
                final String numero_telefono_R = numero_telefonoristoratore.getText().toString();
                final String sessoR = ((RadioButton) findViewById(rGroupristoratore.getCheckedRadioButtonId())).getText().toString();








                if (nomeR.isEmpty()){
                    nomeristoratore.setError("Inserisci il tuo nome");
                    nomeristoratore.requestFocus();
                    return;
                }
                if (cognomeR.isEmpty()){
                    cognomeristoratore.setError("Inserisci il tuo cognome");
                    cognomeristoratore.requestFocus();
                    return;
                }
                if (dataR.isEmpty()){
                    data_nascitaristoratore.setError("Inserisci la tua data di nascita");
                    data_nascitaristoratore.requestFocus();
                    return;
                }
                if (dataR.length() != 10){
                    data_nascitaristoratore.setError("Formato data errato");
                    data_nascitaristoratore.requestFocus();
                    return;
                }
                if (nomeRistoranteR.isEmpty()){
                    nomeristorante.setError("Inserisci il nome del ristorante");
                    nomeristorante.requestFocus();
                    return;

                }

                dbristoratore.collection("Ristoratori").document(id_fk_R).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                        if (task.getResult().exists()) {
                            Toast.makeText(getApplicationContext(), "Sei già registrato", Toast.LENGTH_LONG).show();


                            // cognome.setError("Team with same name already exists");
                            //cognome.requestFocus();


                        } else if(("nome_ristoranteR".equals(nomeRistoranteR))
                        ) {
                            dbristoratore.collection("Ristoratori").whereEqualTo("nome_ristoranteR", nomeRistoranteR);
                            Toast.makeText(getApplicationContext(), "Use another Name restaurant", Toast.LENGTH_LONG).show();                        }

                            else {

                        //If team with same name doesn't exist, save it
                        dbristoratore.collection("Ristoratori").document(id_fk_R).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                            @Override
                            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                                DocumentSnapshot documentSnapshot = task.getResult();


                                //Check if user is already in a team
                                //TeamMap data1 = new TeamMap(teamNameText, teamCountryText, Username);
                                RistoratoreMap data2 = new RistoratoreMap(nomeR, cognomeR, dataR, nomeRistoranteR, numero_telefono_R, id_fk_R, sessoR);
                                dbristoratore.collection("Ristoratori").document(id_fk_R).set(data2).addOnCompleteListener(new OnCompleteListener<Void>() {

                                    // Map<String, Object> data = new HashMap<>();
                                    // data.put("username", Username);
                                    //  db.collection("TeamUsers").document(teamNameText).set(data);
                                    //  Map<String, Object> data2 = new HashMap<>();
                                    //  data2.put("User's team", teamNameText);

                                    //  db.collection("Users").document(teamNameText).set(data2).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if (task.isSuccessful()) {
                                            startActivity(new Intent(R_r_start.this, onboarding_r.class));

                                            Toast.makeText(getApplicationContext(), "Registrato con successo", Toast.LENGTH_LONG).show();
                                        } else {
                                            Toast.makeText(getApplicationContext(), "Errore, prova a disinstallare l'app e installarla di nuovo", Toast.LENGTH_LONG).show();

                                        }
                                    }
                                });

                            }
                        });
                    }



                }


                    });}});}}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\R\u启动);
nomeristoratore=(EditText)findViewById(R.id.editText7);
cognomeristoratore=(EditText)findViewById(R.id.editText8);
nomeristorante=(EditText)findViewById(R.id.editText10);
data_Nascitaristore=(EditText)findViewById(R.id.editText9);
idfkristoratore=(EditText)findViewById(R.id.editText11);
numero_Telefonitoratorore=(EditText)findViewById(R.id.editText12);
rGroupristoratore=(放射组)findViewById(R.id.RadioGroup 2);
注册器地址=(按钮)findViewById(R.id.button4);
registristorAtore.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
注册机构名称:();
}
私人无效登记处{
最终字符串nomeR=nomeristatore.getText().toString();
最后一个字符串cognomeR=cognomeristoratore.getText().toString();
最终字符串nomeRistoranteR=nomeristorante.getText().toString();
最后一个字符串dataR=data_nascitaristore.getText().toString();
最终字符串id_fk_R=id_fkristatorore.getText().toString();
最后一个字符串numero_telefono_R=numero_telefonoristoratore.getText().toString();
最后一个字符串sessoR=((RadioButton)findViewById(rgroupRistorore.getCheckedRadioButtonId()).getText().toString();
if(nomeR.isEmpty()){
命名器设置错误(“Inserisci il tuo nome”);
nomeristoratore.requestFocus();
返回;
}
if(cognomeR.isEmpty()){
setError(“Inserisci il tuo cognome”);
cognomeristoratore.requestFocus();
返回;
}
if(dataR.isEmpty()){
数据_nascitaristorore.setError(“在nascita的数据”);
data_nascitaristoratore.requestFocus();
返回;
}
如果(数据长度()!=10){
数据集错误(“格式数据勘误表”);
data_nascitaristoratore.requestFocus();
返回;
}
if(nomeRistoranteR.isEmpty()){
nomeristorante.setError(“nomeristorante-il-nome del ristorante”);
nomeristorante.requestFocus();
返回;
}
dbristoratore.collection(“Ristoratori”).document(id_fk_R).get().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
如果(task.getResult().exists()){
Toast.makeText(getApplicationContext(),“Sei giáregisto”,Toast.LENGTH_LONG.show();
//setError(“已经存在同名团队”);
//cognome.requestFocus();
}else if((“nome_ristoranteR.”等于(nomeRistoranteR))
) {
b馆藏(以下简称“馆藏”)。馆藏名称(以下简称“馆藏名称”);
Toast.makeText(getApplicationContext(),“使用另一个名字的餐厅”,Toast.LENGTH_LONG.show();}
否则{
//如果同名团队不存在,请保存它
dbristoratore.collection(“Ristoratori”).document(id_fk_R).get().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
DocumentSnapshot DocumentSnapshot=task.getResult();
//检查用户是否已在团队中
//TeamMap data1=新的TeamMap(teamNameText、teamCountryText、用户名);
RistoraroReMap data2=新RistoraroReMap(命名者、认知者、数据者、命名者、电话号码、id、sessoR);
dbristoratore.collection(“Ristoratori”).document(id_fk_R).set(data2).addOnCompleteListener(新的OnCompleteListener(){
//映射数据=新的HashMap();
//data.put(“用户名”,username);
//db.collection(“TeamUsers”).document(teamNameText).set(数据);
//Map data2=新的HashMap();
//数据2.put(“用户团队”,teamNameText);
//数据库集合(“用户”).docu