Я занимаюсь разработкой этого приложения для школьного проекта. Я новичок и не имею большого опыта в Xamarin и C#. В моем заявлении я могу получить сообщение как владелец приложения после отправки формы. Мне также нужно добавить функциональность, которую пользователь или клиент получает после подтверждения формы текстом подтверждения и по электронной почте. Любая помощь будет оценена.
Вот Xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ICC.RequestServicesPage">
<ScrollView>
<StackLayout Padding="50,50,50,50">
<Entry x:Name="EntryFName"
Placeholder="First Name"
Keyboard="Text" />
<Entry x:Name="EntryLName"
Placeholder="Last Name"
Keyboard="Text" />
<Entry x:Name="EntryEmail"
Placeholder="Email address"
Keyboard="Email" />
<Entry x:Name="EntryPhone"
Placeholder="Phone number"
Keyboard="Telephone" />
<Button Text="Submit"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
FontSize="Large"
Clicked="OnClickSubmit" />
</StackLayout>
</ScrollView>
</ContentPage>
, а вот страница C#
namespace COOP
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class RequestServicesPage : ContentPage
{
public RequestServiceFormPage(string service, DateTime date)
{
InitializeComponent();
}
async void OnClickSubmit(object sender, EventArgs e)
{
//build the message body from the form entries
//Phone and Address2 are optional, so only add if they are not null
bool isValid = true;
string fName = EntryFName.Text;
string lName = EntryLName.Text;
string email = EntryEmail.Text;
string phone = EntryPhone.Text;
if (email == null || email == "")
{
isValid = false;
EntryEmail.Placeholder = "Email address *";
EntryEmail.PlaceholderColor = Red;
}
else if (!IsValidEmail(email))
{
isValid = false;
EntryEmail.Placeholder = "Enter a valid Email";
EntryEmail.PlaceholderColor = Red;
EntryEmail.Text = "";
}
if (phone == null || phone == "")
{
isValid = false;
EntryPhone.Placeholder = EntryPhone.Placeholder + " *";
EntryPhone.PlaceholderColor = Red;
}
else if (!IsValidPhone(phone) && phone != null && phone != "")
{
isValid = false;
EntryPhone.Placeholder = "Enter a Valid Phone Number";
EntryPhone.PlaceholderColor = Red;
EntryPhone.Text = "";
}
//build the message body from the form entries
if (isValid)
{
//add the email address and text address to send the email to
List<string> address = new List<string>();
address.Add("test@gmail.com");
address.Add("9999999999@vtext.com");
//build the message body from the form entries
string message = "";
message += "New " + requestService + " Request from: \n";
message += EntryFName.Text + " " + EntryLName.Text + "\n";
message += EntryEmail.Text + "\n";
message += EntryPhone.Text + "\n";
message += EntryAddress1.Text + "\n";
//call send email function. function body is below.
await SendEmail("Test", message);
}
}
public static bool IsValidPhone(string phoneNumber)
{
string numbersOnly = RemoveNonNumeric(phoneNumber);
if (numbersOnly.Length == 7 || numbersOnly.Length == 10)
{
return true;
}
else
{
return false;
}
}
public static string RemoveNonNumeric(string phone)
{
return Regex.Replace(phone, @"[^0-9]+", "");
}
public static bool IsValidEmail(string email)
{
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)" + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
return regex.IsMatch(email);
}
public async Task SendEmail(string subject, string body, List<string> recipients)
{
try
{
var message = new EmailMessage
{
Subject = subject,
Body = body,
To = recipients,
};
await Email.ComposeAsync(message);
}
}
}
}