本文介绍了WPF C#Visual Studio 2013 SQL值在关闭后保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好我关闭表单后发生了一个疯狂的问题。以下是步骤。



1.打开MainWindow.xaml

2.从MainWindow.xaml打开NewWindow1.xaml

3.将NewWindow1.xaml作为新客户或编辑客户连接到SQL。

4.完成后关闭NewWindow1.xaml。

5.再次打开NewWindow1.xaml

6.如果用户在没有提供客户ID的情况下按下检索,表单将返回上次搜索的值...



如何关闭表格并销毁所有以前使用过的值,以便不再发生这种情况?



其他提示:

我在列表视图中使用双击事件来显示表单。在活动内部,我使用了一个开关(表格形式1开放表格1,表格2打开表格2等)





< pre lang =   c# >  
private void ListViewItem_PharmDoubleClick( object sender,MouseButtonEventArgs e)
{
var obj =(DependencyObject)e.OriginalSource;

while (obj!= null &&!Equals(obj) ,PharmacyLv))
{
if (obj.GetType()== typeof (ListViewItem))
{
var Item =(ListViewItem)sender;
var pf =(PharmForms)Item.Content;
var msgTitle = 表单请求 + pf.FormNamePharm;
var msgCaption = 您要求打开 + pf.FormCodePharm + - + pf.FormNamePharm +
。\ n按确定继续或取消再次选择。;
var result = MessageBox.Show(msgCaption,msgTitle,MessageBoxButton.OKCancel,
MessageBoxImage.Question);


开关(结果)
{
case MessageBoxResult.OK:
switch (pf.FormCodePharm)
{
case Form1
OpenForm1();
break ;
case Form2
OpenForm2();
break ;
case Form3
OpenForm3();
break ;
case Form4
OpenForm4();
break ;
// etc ...
case
;
}
break ;
case MessageBoxResult.No:
break ;
}
break ;
}
obj = VisualTreeHelper.GetParent(obj);
}
}
< / pre >
解决方案


Hey everyone. I have a crazy problem that occurs after I close a form. Here's are the steps.

1. Open MainWindow.xaml
2. Open NewWindow1.xaml from MainWindow.xaml
3. Connect NewWindow1.xaml to SQL as a new customer or edit customer.
4. Close NewWindow1.xaml when done.
5. Open NewWindow1.xaml again
6. If the user presses "Retrieve" without providing a customer ID, the form returns the value from the last search...

How do I close a form and destroy all prior used values so that this doesn't occur any more?

Additional hints:
I use a double click event inside a List View to show the forms. Inside the event, I use a switch (case form 1 open form 1, case form2 open form2, etc.)


<pre lang="c#">
        private void ListViewItem_PharmDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var obj = (DependencyObject) e.OriginalSource;

            while (obj != null && !Equals(obj, PharmacyLv))
            {
                if (obj.GetType() == typeof (ListViewItem))
                {
                    var Item = (ListViewItem) sender;
                    var pf = (PharmForms) Item.Content;
                    var msgTitle = "Form Request " + pf.FormNamePharm;
                    var msgCaption = "You requested to open " + pf.FormCodePharm + " - " + pf.FormNamePharm +
                                     ". \nPress OK to continue or CANCEL to select again.";
                    var result = MessageBox.Show(msgCaption, msgTitle, MessageBoxButton.OKCancel,
                        MessageBoxImage.Question);


                    switch (result)
                    {
                        case MessageBoxResult.OK:
                            switch (pf.FormCodePharm)
                            {
                                case "Form1":
                                    OpenForm1();
                                    break;
                                case "Form2":
                                    OpenForm2();
                                    break;
                                case "Form3":
                                    OpenForm3();
                                    break;
                                case "Form4":
                                    OpenForm4();
                                    break;
                               // etc...
                                case "":
                                    break;
                            }
                            break;
                        case MessageBoxResult.No:
                            break;
                    }
                    break;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
        }
</pre>
解决方案


这篇关于WPF C#Visual Studio 2013 SQL值在关闭后保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:39