[英]Copy all the data from one user control to another user control of Same Type
I want to transfer all data from HomeAddressUC to PermanentAddressUC with checkBox SameAsPrevious 我想使用复选框SameAsPrevious将所有数据从HomeAddressUC传输到PermanentAddressUC
Each UserControl has same Type(AddressUserControl) 每个UserControl具有相同的Type(AddressUserControl)
DataSource to Fill HomeAddressUC is code is like this 数据源填充HomeAddressUC的代码是这样的
private void SetTabPageDetails(string tabPageName, CustomerDetails customerDetailsCache)
{
customerDetailsCache = // calling stored procedure
PermanentAddressUC.SetDetails(customerDetailsCache.Addresses[0]);
}
Scope of that DataSource is upto it method SetTabPageDetails()
only logic I was trying to implement is on checkbox changed event is 该DataSource的范围SetTabPageDetails()
方法SetTabPageDetails()
我尝试实现的唯一逻辑是复选框更改后的事件是
if (chkSameAsPervious.Checked)
{
foreach (var addressCtl in from Control ctl in this.ADDRESS_TAB.Controls select ctl as BankSys24.UI.UserControls.AddressUserControl)
{
if (addressCtl.GroupBoxText == "Mailing Address")
{
// want to do something here
}
}
}
I try to follow the relevant link 我尝试点击相关链接
Best practice when you need two user controls (winforms) to communicate 需要两个用户控件(winforms)进行通信时的最佳实践
it says to use the Third Common User Control a Container or interface 它说使用第三个通用用户控件的容器或接口
What is the optimized way to do it? 什么是优化的方法?
Why you need to different user controls for home and mailing address if all the fields same? 如果所有字段都相同,为什么需要对家庭住址和邮寄地址使用不同的用户控件?
you can use one user control for both and create property for set the group name as "Home address" or "Mailing address" 您可以同时使用一个用户控件并创建属性以将组名称设置为“家庭住址”或“邮寄地址”
You can have two public methods to set address fields by passing address object and get address object by reading fields of the form. 您可以有两个公共方法来通过传递地址对象来设置地址字段,以及通过读取表单的字段来获取地址对象。
On check change event of the checkbox you can get address object by calling home address user control instant get address method and then you can set that details on mailing address user control instant by calling set address method by passing address object. 在复选框的支票更改事件中,可以通过调用家庭地址用户控件即时获取地址方法来获取地址对象,然后可以通过传递地址对象来调用设置地址方法来设置有关邮寄地址用户控件即时的详细信息。
hope this helps 希望这可以帮助
ok , Thnaks for Help 好的,谢谢
Possible Shortest Solution i Found is like this : 我发现的可能的最短解决方案是这样的:
if (chkSameAsPervious.Checked)
{
MailingAddressUC.SetDetails(PermanentAddressUC.GetDetails() as BankSys24.DTO.Customer.Address);
}
where 哪里
public object GetDetails()
{
return new BankSys24.DTO.Customer.Address { //data };
}
and 和
public void SetDetails(object input)
{
//intermediate Object
if (details != null)
{
//Mapping
}
Getdetails maps the all data as Container Class Object which can be Directly pass to SetDetails() ... Getdetails将所有数据映射为容器类对象,可以直接传递给SetDetails()...
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.