在类之间共享数据 [英] Sharing data between classes

查看:64
本文介绍了在类之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#很陌生,但是使用VB.net完成了一些非常酷的项目,还有一个MVC3网站用于工作,这是我为有人为我构建架构后发展起来的。我的部分主要是构建模型并使用Jquery | json来填充数据表。虽然我理解了C#的一些基础知识,但我缺少一些核心知识,这些知识阻止我为我公司使用的某些软件创建一个插件。它不是高优先级,我宁愿在.net但它不能。



我的插件工作但它只是一个公共类单击按钮并启动表单。



我不明白有两个使用相同名称的指令:

使用EllieMae.Encompass.Forms;

使用System.Windows.Forms;



Test1.cs

Hi, I'm pretty new to C# but have done some very cool projects using VB.net and also have an MVC3 website for work that I evolved after someone laid down the architecture for me. My part was mostly building models and using Jquery|json to fill data tables. While I understand some basics of C# I'm missing some core knowledge that's preventing me from creating a plugin for some software my company uses. It's not high priority and I'd rather make it in .net but can't.

I got my plugin "working" but it's just 1 public class that has a button click and launches a form.

What I don't understand is there are two using directives that have the same name:
using EllieMae.Encompass.Forms;
using System.Windows.Forms;

Test1.cs

using System;
using System.Collections.Generic;
using System.Text;
using EllieMae.Encompass.ComponentModel;
using EllieMae.Encompass.Forms;
using EllieMae.Encompass.BusinessObjects;
namespace TestCodeBase1
{
    [Plugin]
    public class Test1 : EllieMae.Encompass.Forms.Form
    {
        private EllieMae.Encompass.Forms.Button btnTest = null;
 
        public Test1()
        {
            string sLoanNum = Loan.LoanNumber;
        }

        private void LinkButton(ref EllieMae.Encompass.Forms.Button btn, string name, EventHandler click_func)
        {
            btn = (EllieMae.Encompass.Forms.Button)FindControl(name);
            if (btn != null)
            {
                btn.Click += new EventHandler(click_func);
            }
        }

        public override void CreateControls()
        {
            LinkButton(ref btnTest, "btnTest", btnTest_Click);
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
           
           new Form1().Show();
        }

    }
}







这是我弹出的连接到SQL的表单




This is the form I have pop up that connects to SQL

using System.Text;
using System.Windows.Forms;

using EllieMae.Encompass.Forms;
using EllieMae.Encompass.BusinessObjects.Loans;
using EllieMae.Encompass.Automation;
using EllieMae.Encompass.ComponentModel;



namespace TestCodeBase1
{

    public class Test2 : EllieMae.Encompass.Forms.Form
    {
        //This is the only way I can get to loan fields
        public string TestLoanNum()
        {
            string sLoanNum = Loan.LoanNumber;
            return sLoanNum;
        }
    }
    
    
    public partial class Form1 : System.Windows.Forms.Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.opportunityTableAdapter.Fill(this.sfCRM_BackupsDataSet.Opportunity);
        }

        
    }
    
}





我不明白如何在我的system.windows表单上访问我的贷款字段(Loan.LoanNumber)。如果我使用EllieMae.Encompass.Forms添加;我的设计模式将不再有效,这很好。 我无法掌握的是我是否会同时使用它们并在两者之间传递数据。我愿意研究我不知道从哪里开始。显然我有一点需要学习,但希望有人能指出我正确的方向。



I don't understand how to access my loan fields (Loan.LoanNumber) on my system.windows form. If I add using EllieMae.Encompass.Forms; my design mode will no longer work, which is fine. What I can't grasp is would I use them both and pass data between the two. I'm willing to research I'm just not sure where to start. Obviously I have a bit to learn but was hoping someone could point me in the right direction.

推荐答案

如果您的表单派生自System.Windows.Forms.Form然后它无法访问在EllieMae.Encompass.Forms.Form中定义的成员 - 它们不是同一个类,后者不是从前者派生的,无论它们具有相同的类名。如果EllieMae.Encompass.Forms.Form派生自System.Windows.Forms.Form,那么您可以将Form1声明为基于EllieMae.Encompass.Forms.Form,然后访问Loan及其属性LoanNumber - 但是您无法在反向!



如果EllieMae.Encompass.Forms.Form是你自己的类,那么请更改它的名字。不要将类调用与现有.NET类相同的名称 - 它只会导致混淆并使事情变得更加繁琐。 EncompassForm甚至EllieMaeForm要好得多 - 当你查看你正在处理的代码时很明显,而不必明确使用全名。
If your form is derived from System.Windows.Forms.Form then it can't access members defined in EllieMae.Encompass.Forms.Form - they are not the same class, and the latter is not derived from the former, no matter that they have the same class name. If EllieMae.Encompass.Forms.Form is derived from System.Windows.Forms.Form then you could declare Form1 as based on EllieMae.Encompass.Forms.Form and then access Loan and it's property LoanNumber - but you can't do it in reverse!

If EllieMae.Encompass.Forms.Form is your own class, then please, change it's name. Don't call classes the same names as existing .NET classes - it just causes confusion and makes things more cumbersome. EncompassForm or even EllieMaeForm is a lot better - it obvious when you look at the code which you are dealing with, without having to explicitly use the full name.


你好,



我不确定这个问题有多久,但如果你还有问题,我对这个问题非常了解。



作为起点,EllieMae.Encompass.Forms.Form表示Encompass中的输入表单。您不希望从插件继承该类。插件会启动你的WinForm(继承自System.Windows.Forms。
Hello,

I'm not sure how old this question is but if you are still having trouble I am very knowledgeable on this subject.

Just as a starting point EllieMae.Encompass.Forms.Form represents an input form from within Encompass. You would NOT want to inherit from that class for a Plugin. A plugin would launch your WinForm(inherited from System.Windows.Forms.


这篇关于在类之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆