Пример #1
0
        private async void groupButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            ContentDialog content_dialog = new ContentDialog()
            {
                Title               = "删除",
                Content             = "确认删除这条数据?",
                PrimaryButtonText   = "确定",
                SecondaryButtonText = "取消",
                FullSizeDesired     = false,
            };

            content_dialog.PrimaryButtonClick += (_s, _e) => { };

            ContentDialogResult dialogResult = await content_dialog.ShowAsync();

            if (dialogResult == ContentDialogResult.Primary)
            {
                TabName tabName = dataGrid.SelectedItem as TabName;

                MySQL_Helper mysqlConnector = new MySQL_Helper();

                mysqlConnector.setConnection("root", "root", "windows_programmng");
                string condition = "学号='" + tabName.student_id.ToString() + "';";
                int    x         = mysqlConnector.deleteSql("studentinfo", condition);
                if (x == 1)
                {
                    // 删除成功后更新数据
                    DataSet        ds    = mysqlConnector.Query("studentinfo");
                    List <TabName> mlist = DataSetToList <TabName>(ds, 0);
                    dataGrid.ItemsSource = mlist;
                }
                else
                {
                    ContentDialog deleteFailed = new ContentDialog()
                    {
                        Title             = "删除失败",
                        Content           = "出现未知错误,请在控制台查看错误信息。",
                        PrimaryButtonText = "确定",
                        FullSizeDesired   = false,
                    };

                    deleteFailed.PrimaryButtonClick += (_s, _e) => { };
                    await deleteFailed.ShowAsync();
                }
            }
        }
Пример #2
0
        private void Page_Loading(FrameworkElement sender, object args)
        {
            MySQL_Helper mysqlConnector = new MySQL_Helper();

            // 测试连接
            if (mysqlConnector.setConnection("root", "root", "windows_programmng"))
            {
                Console.WriteLine("<!---------------连接成功!--------------->");
            }
            else
            {
                Console.WriteLine("<!---------------连接失败!--------------->");
                return;
            }
            // 查询数据
            DataSet        ds    = mysqlConnector.Query("studentinfo");
            List <TabName> mlist = DataSetToList <TabName>(ds, 0);

            dataGrid.ItemsSource = mlist;
        }