WPF C#Visual Studio 2013 SQL值在关闭后保留 [英] WPF C# Visual Studio 2013 SQL Values retained after close
问题描述
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 >
谢谢RossMW,你让我在正确的位置。
我编辑了XAML以使用本文方式2中的步骤。当我不想要它时,它帮助我避免用户按下按钮...(http://www.codeproject.com/Tips/215457/How-to-make-Button-Enable-Disable-depends-on- a-Tex)
我也实现了这篇文章的概念:
https://msdn.microsoft.com/ en-us / library / system.idisposable.dispose%28v = vs.110%29.aspx
如果您有关于上述IDisposable的更多信息应用于示例的方法或提示,我将不胜感激。在大多数情况下,在此代码中实现Dispose()似乎是这样做的......
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>
Thank you RossMW, you got me in the right location.
I edited the XAML to use the steps in "Way 2" in this article. It helped me avoid the the user pressing the button when I dont want them too... (http://www.codeproject.com/Tips/215457/How-to-make-Button-Enable-Disable-depends-on-a-Tex)
I also implemented this articles concept as well:
https://msdn.microsoft.com/en-us/library/system.idisposable.dispose%28v=vs.110%29.aspx
If you any more information on the above IDisposable method or hints to apply to the examples, I would appreciate it. For the most part, implementing the Dispose() in this code seems to do it...
这篇关于WPF C#Visual Studio 2013 SQL值在关闭后保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!