简体   繁体   English

将所有数据从一个用户控件复制到相同类型的另一用户控件

[英]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.

相关问题 将用户控件从一个项目复制到同一解决方案中的另一个项目 - Copy User Control from one project to another within same solution 如何将数据从一个用户控件发送到另一个用户控件? - How to send data from one User Control to another User Control? 从一个用户控件重定向到另一个用户控件 - redirection from one user control to another user control 从一个用户控件调用另一个用户控件 - Calling Another user control from one user control 一个用户控件对另一用户控件的可见性 - Visibility of one user control to another user control 如何将数据从一个用户控件传递到另一个用户控件都放置在default.aspx中 - how to pass the data from one user control to another user Control both are placed in default.aspx 试图在单独的用户控件中将数据从一个变量传递到另一个变量 - Attemping to pass data from one variable to another in a separate user control 将值从一个用户控件传递到另一个用户控件 - Pass Values from one user control to another 从同一页面中的另一个用户控件中查找用户控件的控件 - Find user-control's control from another user-control in same page 将CSS从一个控件复制到另一个控件 - Copy css from one control to another control
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM