C# 消息框问题与If有关
我的留言箱有奇怪的行为 代码如下:C# 消息框问题与If有关,c#,telerik,windows-phone,C#,Telerik,Windows Phone,我的留言箱有奇怪的行为 代码如下: private async void rate_Tap(object sender, System.Windows.Input.GestureEventArgs e) { string id = (string)((Image)sender).Tag; ignoreSelectionChanged = true; MobileServiceCollection<rating, rating> items; IMob
private async void rate_Tap(object sender, System.Windows.Input.GestureEventArgs e) {
string id = (string)((Image)sender).Tag;
ignoreSelectionChanged = true;
MobileServiceCollection<rating, rating> items;
IMobileServiceTable<rating> itemTable = App.MobileService.GetTable<rating>();
items = await itemTable
.Where(Table => Table.userid == userId)
.ToCollectionAsync();
if (id != null) {
for (int i = 0; i < items.Count; i++) {
if (items[i].itemid == id) {
MessageBox.Show("You already giving your rating.");
i = items.Count;
return;
}
else {
RadMessageBox.Show(
new string[] { "very accurate", "not accurate" },
"Acurate?",
"Is this information accurate?", closedHandler: (args) => {
int buttonIndex = args.ButtonIndex;
if (buttonIndex == 0) {
clearListBox();
ratingPlus(id);
saveRating(id);
mvm.LoadDetailData();
}
if (buttonIndex == 1) {
clearListBox();
ratingMinus(id);
saveRating(id);
mvm.LoadDetailData();
}
}
);
}
}
}
}
private async void rate\u点击(对象发送方,System.Windows.Input.GestureEventArgs e){
字符串id=(字符串)((图像)发送者).Tag;
ignoreSelectionChanged=true;
移动服务收集项目;
IMobileServiceTable itemTable=App.MobileService.GetTable();
items=等待itemTable
.Where(Table=>Table.userid==userid)
.ToCollectionAsync();
如果(id!=null){
对于(int i=0;i{
int buttonIndex=args.buttonIndex;
如果(按钮索引==0){
clearListBox();
ratingPlus(id);
储蓄率(id);
mvm.LoadDetailData();
}
如果(按钮索引==1){
clearListBox();
比率减(id);
储蓄率(id);
mvm.LoadDetailData();
}
}
);
}
}
}
}
我上面的代码是我从已经包含图像的列表框中触发的rate\u Tap()
,每次我点击它时,它都应该检查我的windows azure服务器,并检查是否有一个itemid
等于id
。然后我将显示messagebox,说明我已经对它进行了评级,如果没有任何itemid
等于id
,那么它将执行radmessagebox
但它不是这样工作的:当它检查是否有一个itemid
等于id
时,它显示messagebox,然后显示radmessagebox
我哪里出错了?您的“else”块包含在检查所有项目(而不是每个项目)后要执行的代码
我想你想要:
if (items.Any(item => item.itemid == id))
{
MessageBox.Show("You already giving your rating.");
return;
}
RadMessageBox.Show(...);
// etc
理想情况下,不要获取所有以前的评分-更改查询,使其包含您试图评分的项目的ID。毕竟,你只想知道你是否已经对它进行了评级——其余的信息都是毫无意义的,那么为什么要全部获取呢?你能把这个例子做得最简单,仍然能说明问题吗?