UserControl未更新到表

时间:2014-01-08 14:10:32

标签: c# winforms user-controls oracle9i

问题

只有在我尝试插入时才出现问题。但是我可以浏览记录。当我插入新记录时,UserControl不会考虑我输入的值,而是存储为null。我基本上认为新记录,它不同步。

表单布局

enter image description here

UserControl的目的

DB以JKB-932340094VN00的形式存储Field值,其中我使用我的UserControl按-分割值并将其显示在其中的2 TextBox中。因此,一个TextBox的值为JKB,其他的将具有932340094VN00

UserControl如下:

public partial class ucClientAccountIDParser : UserControl, INotifyPropertyChanged
{
    public ucClientAccountIDParser()
    {
        InitializeComponent();
        id = "JKB-821230063VN00";

        txtClientAccountID.TextChanged += new EventHandler(clientaccountIDChanged);
        txtCustodyID.TextChanged += new EventHandler(custodyIDChanged);
    }

    private string _clientaccountID = string.Empty;

    public string ClientaccountID
    {
        get { return _clientaccountID; }
        set 
        { 
            _clientaccountID = value;
            txtClientAccountID.Text = this._clientaccountID;
        }
    }
    private string _custodyID = string.Empty;

    public string CustodyID
    {
        get { return _custodyID; }
        set 
        { 
            _custodyID = value;
            txtCustodyID.Text = this._custodyID;
        }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

    public string id = string.Empty;

    [System.ComponentModel.Bindable(true)]
    public string Text
    {
        get
        {
            return id;
        }
        set
        {
            id = value;

            if (id != null)
            {
                string[] aVal = id.Split('-');

                if (aVal.Length > 1)
                {
                    this.CustodyID = aVal[0];
                    this.ClientaccountID = aVal[1];
                }
                else
                {
                    this.ClientaccountID = id;
                }
            }
            else
            {
                this.CustodyID = string.Empty;
                this.ClientaccountID = string.Empty;   
            }

            NotifyPropertyChanged(id);
        }
    }

    public void NotifyPropertyChanged(string info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs("Text"));
        }
    }

    private void clientaccountIDChanged(object sender, EventArgs e)
    {
        this.id = string.Format("{0}-{1}", txtCustodyID.Text, (sender as TextBox).Text);
        NotifyPropertyChanged(this.id);
    }

    private void custodyIDChanged(object sender, EventArgs e)
    {
        this.id = string.Format("{0}-{1}", (sender as TextBox).Text, txtClientAccountID.Text);
        NotifyPropertyChanged(this.id);
    } 
}

这就是我绑定它的方式:

try
            {
                this.Init(null);
                this.Text = "General Account Add/Change";

                objTable = new ClientAccountBusinessTable();
                this.PrimaryDataAdapters = new ClientAccountBusinessTable[1] { objTable };
                this.PrimaryDataGridView = null;

                objTable.KeyDBField = "CLIENTID";
                PrimaryBindingSource = new BindingSource[1] { bindingSource1 };
                PrimaryDataSet.Tables.Add(objTable.GetBusinessTable());

                SetKeyDBControl(new Control[1] { ucClientAccountIDParser1 }, new string[1] { "CLIENTID" });

                ucClientAccountIDParser1.DataBindings.Clear();
                ucClientAccountIDParser1.DataBindings.Add(new Binding("Text", this.bindingSource1, "CLIENTID"));

                bindingSource1.DataMember = this.PrimaryDataSet.Tables[0].TableName;
                bindingSource1.DataSource = this.PrimaryDataSet;
            }
            catch (Exception ex)
            {
                objTable = null;
                throw ex;
            }

我无法弄清楚为什么它会为空。如果我以适当的方式进行UserControl的设计,请告诉我。

我希望有人可以帮助我。

0 个答案:

没有答案