为什么我的数据没有发布到列表框中?

时间:2018-12-30 08:04:45

标签: c# .net string winforms

我正在从表单上的文本框中获取信息,然后通过一种方法将其传递给类(仍在学习中)。我发送的信息可以很好地传递。在我的代码下面,我按它们的工作顺序列出了它们。

第一步是获取传递的数字(第一组代码。),然后使用方法将其传递给类,该方法被设置为用户控件(第二组代码)。它经历了步骤,然后将其带到另一个类(第三组代码)以返回框内所需的值。然后它返回并应该将其张贴在框中,但是事实并非如此。

我在这方面还很陌生,需要一些帮助。

谢谢

吉米·迪恩

Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InformationBookFinal
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            accountInformation.Visible = false;
            accountStatus.Visible = false;
        }


        private void exitBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void b0_Click(object sender, EventArgs e)
        {
            accountInformation.Visible = true;
            accountStatus.Visible = false;
        }

        private void b1_Click(object sender, EventArgs e)
        {

            accountInformation.Visible = false;
            accountStatus.Visible = true;

        }
    }
}

UserControl1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InformationBookFinal.User_Control
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        List<Information> status = new List<Information>();
        List<Information> notes = new List<Information>();
        List<Information> info = new List<Information>();

        private void searchBtn_Click(object sender, EventArgs e)
        {
            firstNameRich.Text = string.Empty;
            lastNameRich.Text = string.Empty;
            dateOFBirthRich.Text = string.Empty;
            socialSecurityRich.Text = string.Empty;
            statusRich.Text = string.Empty;
            invalidLabel.Text = string.Empty;


            var invalidMessage = "Please enter a valid account number!";

            dataAccess db = new dataAccess();
            docRetrieval dr = new docRetrieval();
            UserControl2 lb = new UserControl2();



            int accountNum;
            if (!int.TryParse(accountNumber.Text, out accountNum))
            {
                invalidLabel.Text = invalidMessage;

            }
            else
            {
                status = db.GetStatus(accountNumber.Text);
                notes = db.GetNotes(accountNumber.Text);
                info = db.GetInfo(accountNumber.Text);

                listBox1.DataSource = status;
                listBox1.DisplayMember = "FullInfo";

                 lb.listSet(accountNumber.Text);
                //noteDisplay.DataSource = notes;
                //noteDisplay.DisplayMember = "Field17";






                if (info.Count == 0)
                {
                    invalidLabel.Text = invalidMessage;

                }
                else
                {
                    firstNameRich.Text = info[0].Field1;
                    lastNameRich.Text = info[0].Field2;
                    dateOFBirthRich.Text = info[0].Field3;
                    socialSecurityRich.Text = info[0].Field4;
                    addressText.Text = info[0].Field5;
                    cityText.Text = info[0].Field6;
                    stateText.Text = info[0].Field7;
                    zipText.Text = info[0].Field8;

                    //string path = docRetrieval.doc(accountNumber.Text);

                    //if (path == "No Document has been found!")
                    //{
                        //MessageBox.Show(path);
                    //}
                    //else
                    //{

                    //    string adjustedPath = path.Replace(@"C:\", @"\\EOJ-SOL-DEMO\c$\");
                        // pdfViewer1.src = adjustedPath;
                    //}






                }
                /*if (status.Count == 0)
                {
                    statusRich.Text = "No Status.";
                    /* No status means documents are not populating out of document management software 
                     * or the field has no number matching account number. */

                /*}
                else
                {
                    if (status[0].Field9 == "Approved")
                    {
                        statusRich.BackColor = Color.LightGreen;
                        statusRich.Text = status[0].Field9;
                    }
                    else if (status[0].Field9 == "Past Due")
                    {
                        statusRich.BackColor = Color.Red;
                        statusRich.Text = status[0].Field9;
                    }
                    else if (status[0].Field9 == "Pending")
                    {
                        statusRich.BackColor = Color.LightCyan;
                        statusRich.Text = status[0].Field9;
                    }
                    else if (status[0].Field9 == "Denied")
                    {
                        statusRich.BackColor = Color.Gray;
                        statusRich.Text = status[0].Field9;
                    }

                }*/


            }
        }
    }
}

UserControl2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InformationBookFinal.User_Control
{
    public partial class UserControl2 : UserControl
    {
        public UserControl2()
        {
            InitializeComponent();
        }

        public void listSet(string test)
        {
            List<Information> status = new List<Information>();
            dataAccess db = new dataAccess();

            status = db.GetStatus(test);
            ListBoxPeople.DataSource = status;
            ListBoxPeople.DisplayMember = "FullInfo";

        }


    }
}

列表信息:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace InformationBookFinal
{

    public class Information
    {


        public int id { get; set; }

        public string Field1 { get; set; }

        public string Field2 { get; set; }

        public string Field3 { get; set; }

        public string Field4 { get; set; }

        public string Field5 { get; set; }

        public string Field6 { get; set; }

        public string Field7 { get; set; }

        public string Field8 { get; set; }

        public string Field9 { get; set; }

        public string Field16 { get; set; }

        public string Field17 { get; set; }

        public string errormessage { get; set; }

        public string FullInfo
        {
            get
            {

                // "John Doe (jdoe@test.com)
                return $"{Field16} {Field1} {Field2} ({Field4}) {Field9}";

            }
        }
    }

1 个答案:

答案 0 :(得分:0)

最终的结果是我刚制造的“用户控制”,我已制成,所以我可以隐藏起来,当我点击按钮的参考。

因此,当我单击按钮时,它将引用我在AccountStatus用户控件中设置的功能。

accountStatus.grabStatus(accountInformation.accountNumber.Text); 

引用了

  grabStatus(string accountNum)
  {
    dataAccess da = new dataAccess(); 
    List<Information> status = new List<Information>(); 
    status = da.GetStatus(accountNum); 
    ListBoxPeople.DataSource = status; 
    ListBoxPeople.DisplayMember = "FullInfo";
  }