Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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
C# 什么;“验证逻辑”;我应该在If-else语句中测试吗_C#_Xamarin_Xamarin.android - Fatal编程技术网

C# 什么;“验证逻辑”;我应该在If-else语句中测试吗

C# 什么;“验证逻辑”;我应该在If-else语句中测试吗,c#,xamarin,xamarin.android,C#,Xamarin,Xamarin.android,我不懂逻辑。在发送(response.StatusCode==System.Net.HttpStatusCode.Accepted) 这是我的代码: if(TextUtils.IsEmpty(edtPurpose.Text)) { edtPurpose.SetError(“填写此目的字段”,null); 返回; } if(TextUtils.IsEmpty(txtAppointmentDate.Text.ToString()) { txtAppointmentDate.SetError(“填写此

我不懂逻辑。在发送
(response.StatusCode==System.Net.HttpStatusCode.Accepted)

这是我的代码:

if(TextUtils.IsEmpty(edtPurpose.Text))
{
edtPurpose.SetError(“填写此目的字段”,null);
返回;
}
if(TextUtils.IsEmpty(txtAppointmentDate.Text.ToString())
{
txtAppointmentDate.SetError(“填写此约会日期字段”,null);
返回;
}
if(TextUtils.IsEmpty(edtAppointmentTimeFirst.Text))
{
edtAppointmentTimeFirst.SetError(“填写此开始约会时间字段”,null);
返回;
}
if(TextUtils.IsEmpty(edtappointTimeSecond.Text))
{
edtappointTimeSecond.SetError(“填写此结束约会时间字段”,null);
返回;
}
其他的
{
if(response.StatusCode==System.Net.HttpStatusCode.Accepted)
{
Toast.MakeText(这是“您的约会已保存”,ToastLength.Short).Show();
}
其他的
{
Toast.MakeText(这是“您的约会未保存”,ToastLength.Short).Show();
}
}
我的全部代码:

Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
        Android.App.AlertDialog alert = dialog.Create();
        alert.SetTitle("Reminder:");
        alert.SetMessage("Before you send this appointment, you have to be sure that the date and time you chose is aligned with the teacher's consultation hours." + "THIS APPOINTMENT CANNOT BE CANCELLED");
        alert.SetButton("Send", (c, ev) =>
        {
            
            StudentAppoint appointment = new StudentAppoint();
            appointment.Purpose = edtPurpose.Text;
            appointment.AppointmentDate = txtAppointmentDate.Text.ToString();
            appointment.AppointmentTimeFirst = edtAppointmentTimeFirst.Text;
            appointment.AppointmentTimeSecond = edtAppointmentTimeSecond.Text;

            HttpClient client = new HttpClient();
            string url = $"";
            var uri = new Uri(url);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response;
            var json = JsonConvert.SerializeObject(appointment);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            response = client.PostAsync(uri, content).Result;

                if (TextUtils.IsEmpty(edtPurpose.Text))
                {
                    edtPurpose.SetError("Fill This Purpose Field", null);
                    return;
                }
                if (TextUtils.IsEmpty(txtAppointmentDate.Text.ToString()))
                {
                    txtAppointmentDate.SetError("Fill This Appointment Date Field", null);
                    return;
                }
                if (TextUtils.IsEmpty(edtAppointmentTimeFirst.Text))
                {
                    edtAppointmentTimeFirst.SetError("Fill This Start Appointment Time Field", null);
                    return;
                }
                if (TextUtils.IsEmpty(edtAppointmentTimeSecond.Text))
                {
                    edtAppointmentTimeSecond.SetError("Fill This End Appointment Time Field", null);
                    return;
                }
                else
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {

                        Toast.MakeText(this, "Your Appointment is Saved ", ToastLength.Short).Show();
                    }
                    else
                    {
                        Toast.MakeText(this, "Your Appointment is not Saved", ToastLength.Short).Show();
                    }
                }
        });
        alert.SetButton2("Cancel", (c, ev) => { });
        alert.Show();
    }

请不要在您的问题中添加随机的无关标签。这里甚至没有与SQL远程相关的内容。似乎您应该在完成所有验证之后发出请求。考虑到您已经有了一个
响应
,似乎您提出了请求,进行了验证,然后最终决定检查响应状态代码。@Llama您能帮我实现逻辑吗,我还是不知道understand@Llama在上面检查我的全部代码。我想知道在logic
response=client.PostAsync(uri,content.Result)中验证是如何工作的-此行发出web请求并存储结果。然后,验证已经发送的数据,最后检查请求是否成功。我猜您可能希望先验证,然后再提出请求。