【Telerik】弹出对话框RadWindow,确认删除信息
要做一个删除功能,但是删除前正常都要弹出对话框确认一下是否删除信息,防止误删信息。
点击确定按钮,删除信息;点击取消按钮,就关闭对话框,不进行删除操作。
1.Xaml页面,删除对照按钮代码。
1 <telerik:RadButton BorderThickness="1" x:Name="But_Del" Click="But_Del_Click"> 2 <Grid Height="Auto"> 3 <Grid.ColumnDefinitions> 4 <ColumnDefinition Width="Auto"/> 5 <ColumnDefinition Width="Auto"/> 6 </Grid.ColumnDefinitions> 7 <Image Grid.Row="0" Stretch="Uniform" Margin="3" Source="/DRGS;Component/Images/edit_remove.png" /> 8 <TextBlock Grid.Column="1" TextAlignment="Center" Text="删除对照" FontSize="12" VerticalAlignment="Center"/> 9 </Grid> 10 </telerik:RadButton>
2.后台代码
1 /// <summary> 2 /// 删除已对照关系(可批量删除) 3 /// </summary> 4 private void But_Del_Click(object sender, RoutedEventArgs e) 5 { 6 if (mdc_icd10List.Count() == 0) 7 { 8 RadWindow.Alert("请选择要删除的信息!"); 9 return; 10 } 11 12 DialogParameters dp = new DialogParameters(); 13 dp.Header = "删除"; 14 dp.Content = "确定删除此条信息吗?"; 15 dp.OkButtonContent = "确定"; 16 dp.CancelButtonContent = "取消"; 17 dp.Closed += new EventHandler<WindowClosedEventArgs>(OnConfirmClosed); 18 RadWindow.Confirm(dp); 19 20 } 21 /// <summary> 22 /// 确认删除 23 /// </summary> 24 private void OnConfirmClosed(object sender, WindowClosedEventArgs e) 25 { 26 if (e.DialogResult == true) 27 { 28 InterFace.IniService(); 29 InterFace.Service.DeleteMdcIcdListControlCompleted += Service_DeleteMdcIcdListControlCompleted; 30 InterFace.Service.DeleteMdcIcdListControlAsync(mdc_icd10List); 31 } 32 } 33 void Service_DeleteMdcIcdListControlCompleted(object sender, WcfService.DeleteMdcIcdListControlCompletedEventArgs e) 34 { 35 try 36 { 37 if (e.Result > 0) 38 { 39 RadWindow.Alert("删除成功!"); 40 GridDataBinding(); 41 } 42 } 43 catch (Exception) 44 { 45 RadWindow.Alert(e.Error.Message); 46 } 47 finally { MyRadBusy.IsBusy = false; } 48 }
3.数据库操作(以PostgreSQL数据库为例)
1 /// <summary> 2 /// 批量删除 3 /// </summary> 4 [OperationContract(Name = "DeleteMdcIcdListControl")] 5 public int DeleteMdcIcdControl(List<mdc_icd10> mdc_icd10List) 6 { 7 int i = 0; 8 foreach (var mdc_icd10 in mdc_icd10List) 9 { 10 string sqlStr = string.Format(@"Delete from mdc_icd10 where id={0} ", mdc_icd10.Id); 11 i += pgSqlService.ExecuteSql(sqlStr); 12 } 13 return i == mdc_icd10List.Count ? 1 : 0; 14 }
记录完成。。。