代码库当前以天蓝色添加症状反馈评分。一旦添加了一个“症状”并为其添加了分数,一切都将正常工作,第二个“症状”条目也将正常运行,一旦我添加了一个第三“症状”并为此评分,则在数据库中将FIRST分数添加两次我添加了第四个“症状”,第一个分数被添加了3次,其余的重复不断。有办法阻止这种情况吗?
public AddSymptom(Symptoms symptom, bool isFeedback)
{
InitializeComponent();
manager = SymptomsManager.DefaultManager; //intiialise the Azure Symptom class
weathermanager = WeatherManager.DefaultManager;
remedymanager = RemedyManager.DefaultManager;
imagemanager = ImagesManager.DefaultManager;
usersymptommanager = UserSymptomManager.DefaultManager;
//RemedyPicker.SelectedIndexChanged += RemedyPicker_SelectedIndexChanged;
symptomfeedbackmanager = SymptomFeedbackManager.DefaultManager;
GetCorrectiveActions();
Device.BeginInvokeOnMainThread(action: async () =>
{
Uri ImgSource = await App.GetImage("sym");
img.Source = ImgSource;
});
GetUserSymptoms();
if (isFeedback == true)
{
this.Title = "Enter Symptom Feedback";
lblTitle.Text = "Enter Symptom Feedback";
lblSubtutle.Text = "Please enter your feedback";
//SymptomLabel.IsVisible = false;
//txtSymptom.IsVisible = false;
SymptomFeedbackToAdd.Usersymptomid = symptom.Id;
symptomToAdd.Id = symptom.Id;
SymptomFeedbackToAdd.Description = symptom.Description;
//txtSymptom.Text = symptom.Description;
btnAdd.Text = "Add Symptom Feedback";
ProvidingFeedback = true;
//CommunitySwitch.IsVisible = true;
}
PopulateSymptomAutoComplete();
}
public AddSymptom(UserSymptomView symptom, bool isFeedback)
{
InitializeComponent();
manager = SymptomsManager.DefaultManager; //intiialise the Azure Symptom class
weathermanager = WeatherManager.DefaultManager;
remedymanager = RemedyManager.DefaultManager;
imagemanager = ImagesManager.DefaultManager;
usersymptommanager = UserSymptomManager.DefaultManager;
//RemedyPicker.SelectedIndexChanged += RemedyPicker_SelectedIndexChanged;
symptomfeedbackmanager = SymptomFeedbackManager.DefaultManager;
autoComplete.IsVisible = false;
lblSearchForaSymptom.IsVisible = false;
GetCorrectiveActions();
Device.BeginInvokeOnMainThread(action: async () =>
{
Uri ImgSource = await App.GetImage("sym");
img.Source = ImgSource;
});
GetUserSymptoms();
if (isFeedback == true)
{
this.Title = "Enter Symptom Feedback";
lblTitle.Text = "Enter Symptom Feedback";
lblSubtutle.Text = "Please enter your feedback";
// SymptomLabel.IsVisible = false;
// txtSymptom.IsVisible = false;
SymptomFeedbackToAdd.Usersymptomid = symptom.Usersymptomid;
SymptomFeedbackToAdd.Description = symptom.Description;
// txtSymptom.Text = symptom.Description;
btnAdd.Text = "Add Symptom Feedback";
ProvidingFeedback = true;
//CommunitySwitch.IsVisible = true;
}
PopulateSymptomAutoComplete();
autoComplete.IsVisible = false;
//SymptomLabel.Text = symptom.Description;
// txtSymptom.IsVisible = false;
var userSymptomToEdit = UserSymptoms.Where(Item => Item.Id == symptom.Usersymptomid);
}
async void btnAdd_Clicked(object sender, EventArgs e)
{
CheckSymptomInHistory(AutoCompleteSymptomToAdd.Id);
//If the autocomplete is not empty - add that symptom to the user symptom table
if (AutoCompleteSymptomToAdd != null)
{
//If the user already has symptoms, loop through them to make sure that they are not adding a duplicate
if (UserSymptoms.Count > 0)
{
foreach (usersymptom item in UserSymptoms)
{
if (item.Symptomid == AutoCompleteSymptomToAdd.Id)
{
await DisplayAlert("Duplicate Symptom", "You already have recorded this symptom - please log feedback against it if needed", "OK");
return;
}
//Check if it is not active (i.e in SYmptom History)
else
{
UserSymptomToAdd.Symptomid = AutoCompleteSymptomToAdd.Id;
UserSymptomToAdd.UserID = Helpers.Settings.UserKey;
UserSymptomToAdd.Datetimeadded = DateTime.Now.ToString();
UserSymptomToAdd.IsActive = true;
try
{
await usersymptommanager.AddUserSymptom(UserSymptomToAdd);
await AddInitialFeedback(UserSymptomToAdd.Id);
//await DisplayAlert("Symptom Added", "Your Symptom has been added", "OK");
}
catch (Exception ex)
{
Analytics.TrackEvent("App Screen: " + Title + ": " + ex);
//await DisplayAlert("Error", ex.ToString(), "OK");
}
}
}
}
//if no symptoms are present (i.e the collection has a count of 0,just add the new usersymptom)
else
{
usersymptom UserSymptomToAdd = new usersymptom();
UserSymptomToAdd.Symptomid = AutoCompleteSymptomToAdd.Id;
UserSymptomToAdd.UserID = Helpers.Settings.UserKey;
UserSymptomToAdd.Datetimeadded = DateTime.Now.ToString();
UserSymptomToAdd.IsActive = true;
try
{
await usersymptommanager.AddUserSymptom(UserSymptomToAdd);
await AddInitialFeedback(UserSymptomToAdd.Id);
//await DisplayAlert("Symptom Added", "Your Symptom has been added", "OK");
}
catch (Exception ex)
{
Analytics.TrackEvent("App Screen: " + Title + ": " + ex);
//await DisplayAlert("Error", ex.ToString(), "OK");
}
}
}