Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于GridView数据显示新表单_C#_.net_Winforms_Gridview_Currencymanager - Fatal编程技术网

C# 基于GridView数据显示新表单

C# 基于GridView数据显示新表单,c#,.net,winforms,gridview,currencymanager,C#,.net,Winforms,Gridview,Currencymanager,在我的主窗体MainForm上有一个GridView,radGvA133s。我希望能够双击GridView的一行,并打开一个新表单A133Form,以允许编辑所选行 以下是双击代码: private void radGvA133s_DoubleClick(object sender, EventArgs e) { A133 oA133 = (A133)A133BindingSource.CurrencyManager.List[A133BindingSource.

在我的主窗体MainForm上有一个GridView,radGvA133s。我希望能够双击GridView的一行,并打开一个新表单A133Form,以允许编辑所选行

以下是双击代码:

    private void radGvA133s_DoubleClick(object sender, EventArgs e)
    {
        A133 oA133 = (A133)A133BindingSource.CurrencyManager.List[A133BindingSource.CurrencyManager.Position];
        A133Form oA133Form = new A133Form();
        oA133Form.NewA133 = oA133;
        oA133Form.IsNew = false;
        oA133Form.ShowDialog(this);
        //On return - if not cancelled, then continue
        if (oA133Form.Cancelled != true)
        {
            this.radGvA133s.Refresh();
        }
        oA133Form.Dispose();
        oA133Form = null;
    }
以下是A133表格代码:

    public partial class A133Form : Form
{   
    public A133Form()
    {
        InitializeComponent();
    }

    private bool _IsNew;
    public bool IsNew
    {
        get
        {
            return _IsNew;
        }
        set
        {
            _IsNew = value;
        }
    }

    private bool _Cancelled;
    public bool Cancelled
    {
        get
        {
            return _Cancelled;
        }
        set
        {
            _Cancelled = value;
        }
    }

    private A133 _newA133 = new A133();
    public A133 NewA133
    {
        get
        {
            return _newA133;
        }
        set
        {
            _newA133 = value;
        }
    }

    private void A133Form_Load(object sender, EventArgs e)
    {
        A133DB A133DB = new A133DB();

        DataTable dtRSNs = A133DB.GetRSNList();
        DataRow drFirstItem = dtRSNs.NewRow();

        radComboRSN.DataSource = dtRSNs;
        drFirstItem["rsn_id"] = "0";
        drFirstItem["rsn_name"] = "";
        dtRSNs.Rows.InsertAt(drFirstItem, 0);
        radComboRSN.ValueMember = "rsn_id";
        radComboRSN.DisplayMember = "rsn_name";

        //Set databindings
        radComboRSN.DataBindings.Add(new Binding("Text", NewA133, "RSN", true, DataSourceUpdateMode.OnPropertyChanged));
        radTxtSubcontractor.DataBindings.Add(new Binding("Text", NewA133, "Subcontractor", true, DataSourceUpdateMode.OnPropertyChanged));
        radMTxtCFDANumber.DataBindings.Add(new Binding("Text", NewA133, "CFDANumber", true, DataSourceUpdateMode.OnPropertyChanged));
        radCbIncludeCFDA.DataBindings.Add(new Binding("Checked", NewA133, "IncludeCFDA", true, DataSourceUpdateMode.OnPropertyChanged));
        radMTxtYear.DataBindings.Add(new Binding("Text", NewA133, "sYear", true, DataSourceUpdateMode.OnPropertyChanged));
        radTxtFedAward.DataBindings.Add(new Binding("Text", NewA133, "FedAward", true, DataSourceUpdateMode.OnPropertyChanged));
        radCbExceeds.DataBindings.Add(new Binding("Checked", NewA133, "Exceeds", true, DataSourceUpdateMode.OnPropertyChanged));
        radDTPDateMHDReceived.DataBindings.Add(new Binding("Value", NewA133, "DateMHDReceived", true, DataSourceUpdateMode.OnPropertyChanged));
        radDTPPeriodEnding.DataBindings.Add(new Binding("Value", NewA133, "PeriodEnding", true, DataSourceUpdateMode.OnPropertyChanged));
        radDTPDateAudited.DataBindings.Add(new Binding("Value", NewA133, "DateAudited", true, DataSourceUpdateMode.OnPropertyChanged));
        radDTPForwardDate.DataBindings.Add(new Binding("Value", NewA133, "ForwardDate", true, DataSourceUpdateMode.OnPropertyChanged));
        radTxtSAOPerson.DataBindings.Add(new Binding("Text", NewA133, "SAOPerson", true, DataSourceUpdateMode.OnPropertyChanged));
    }

    private void radBtnCancel_Click(object sender, EventArgs e)
    {
        this.Cancelled = true;
        this.Close();
    }

    private void radBtnSave_Click(object sender, EventArgs e)
    {
        this.Cancelled = false;
        bool bValid = true;

        foreach(Control control in this.Controls)
        {
            if (Convert.ToString(control.Tag) == "Required")
            {
                bool bMissingInfo = false;
                if (control is RadDateTimePicker)
                {
                    RadDateTimePicker dtp = control as RadDateTimePicker;

                    if (dtp.Value.ToString() == "1/1/0001 12:00:00 AM")
                    {
                        bMissingInfo = true;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(control.Text))
                    {
                        bMissingInfo = true;
                    }
                }
                if (bMissingInfo == true)
                {
                    errorProvider1.SetError(control, "* Required Field");
                    bValid = false;
                }
                else
                {
                    errorProvider1.SetError(control, "");
                }
            }
        }
        if (bValid == true)
        {
            bool bSaved = NewA133.SaveData();
            if (bSaved == true)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("There was an error saving the data!  If this continues, please contact technical assistance.",
                                "Error Saving Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        else
        {
            MessageBox.Show("The information you have entered is incomplete.  Please fill out all required fields.", 
                            "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }
}
最后,这里是A133类代码:

#region A133 Collection

public class A133Collection : BindingListView<A133>
{
    public A133Collection() : base()
    {
    }

    public A133Collection(List<A133> a133s) : base(a133s)
    {
    }

    public A133Collection(DataTable dt)
    {
        foreach(DataRow oRow in dt.Rows)
        {
            A133 a = new A133(oRow);
            this.Add(a);
        }
    }

    private int FindMaxId()
    {
        int maxId = -1;
        foreach(A133 a in this)
        {
            if (a.A133Id > maxId)
            {
                maxId = a.A133Id;
            }
        }
        return maxId;
    }
}

#endregion

#region A133 Class

///<summary>
///Class:   A133
///Desc:    Manages a single A133 business object
///         Note - 4 states for the object: Unchanged, Added, Deleted, Modified
///             Added flags that a brand new object was added; set prior to db insert
///             Deleted flags that the object was deleted; set after db delete
///             Unchanged is default state
///             Modified flags that props have changed
///             >> The IsDirty indicator looks to see if the object is "modified" or "added"
///             since these are pre-database flags
///</summary>

public class A133 : INotifyPropertyChanged, IEditableObject, IDataErrorInfo
{
    //Declare internal class collection object
    private A133Collection _A133s = new A133Collection();

    //Declare internal class objects
    private MHDFMS.BusinessLogic.A133DB _DB = new A133DB();

    //Declare internal class props
    private int _A133Id;
    private string _RSN;
    private string _Subcontractor;
    private string _CFDANumber;
    private string _IncludeCFDA;
    private string _Year;
    private string _FedAward;
    private string _Exceeds;
    private string _DateMHDReceived;
    private string _PeriodEnding;
    private string _DateAudited;
    private string _ForwardDate;
    private string _SAOPerson;
    private int _OldA133Id;
    private string _OldRSN;
    private string _OldSubcontractor;
    private string _OldCFDANumber;
    private string _OldIncludeCFDA;
    private string _OldYear;
    private string _OldFedAward;
    private string _OldExceeds;
    private string _OldDateMHDReceived;
    private string _OldPeriodEnding;
    private string _OldDateAudited;
    private string _OldForwardDate;
    private string _OldSAOPerson;
    private bool _Editing;
    private string _Error = string.Empty;
    private EntityStateEnum _EntityState;
    private Hashtable _PropErrors = new Hashtable();

    private void FirePropertyChangeNotification(string propName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

    public A133()
    {
        this.EntityState = EntityStateEnum.Unchanged;
    }

    public A133(DataRow dr)
    {
        //Populates the business object item from a data row
        this.A133Id = Convert.ToInt32(dr["a133_id"]);
        this.RSN = dr["rsn"].ToString();
        this.Subcontractor = dr["subcontractor"].ToString();
        this.CFDANumber = dr["cfda_no"].ToString();
        this.IncludeCFDA = dr["include_cfda"].ToString();
        this.sYear = dr["year"].ToString();
        this.FedAward = dr["fed_award"].ToString();
        this.Exceeds = dr["exceeds"].ToString();
        if (dr["date_mhd_received"] != null)
        {
            this.DateMHDReceived = Convert.ToDateTime(dr["date_mhd_received"]).ToShortDateString();
        }
        if (dr["period_ending"] != null)
        {
            this.PeriodEnding = Convert.ToDateTime(dr["period_ending"]).ToShortDateString();
        }
        if (dr["date_audited"] != null)
        {
            this.DateAudited = Convert.ToDateTime(dr["date_audited"]).ToShortDateString();
        }
        if (dr["forward_date"] != null)
        {
            this.ForwardDate = Convert.ToDateTime(dr["forward_date"]).ToShortDateString();
        }
        this.SAOPerson = dr["sao_person"].ToString();
        this.EntityState = EntityStateEnum.Unchanged;
    }

    #region Public Methods/Constructors

    public bool SaveData()
    {
        bool bSaved = false;
        if (this.A133Id == 0)
            {
            bSaved = _DB.SaveA133Data(this);
        }
        else
        {
            bSaved = _DB.SaveA133Data(this);
        }
        if (bSaved == true)
        {
            this.EntityState = EntityStateEnum.Unchanged;
        }
        return bSaved;
    }

    public bool Delete()
    {
        bool bSaved = _DB.SaveA133AsInactive(this);
        if (bSaved == true)
        {
            this.EntityState = EntityStateEnum.Deleted;
        }
        return bSaved;
    }

    public Int32 A133Id
    {
        get
        {
            return _A133Id;
        }
        set
        {
            _A133Id = value;
        }
    }

    public string RSN
    {
        get
        {
            return _RSN;
        }
        set
        {
            _RSN = value;
            FirePropertyChangeNotification("RSN");
        }
    }

    public string Subcontractor
    {
        get
        {
            return _Subcontractor;
        }
        set
        {
            _Subcontractor = value;
            FirePropertyChangeNotification("Subcontractor");
        }
    }

    public string CFDANumber
    {
        get
        {
            return _CFDANumber;
        }
        set
        {
            _CFDANumber = value;
            FirePropertyChangeNotification("CFDANumber");
        }
    }

    public string IncludeCFDA
    {
        get
        {
            return _IncludeCFDA;
        }
        set
        {
            _IncludeCFDA = value;
            FirePropertyChangeNotification("IncludeCFDA");
        }
    }

    public string sYear
    {
        get
        {
            return _Year;
        }
        set
        {
            _Year = value;
            FirePropertyChangeNotification("sYear");
        }
    }

    public string FedAward
    {
        get
        {
            return _FedAward;
        }
        set
        {
            _FedAward = value;
            FirePropertyChangeNotification("FedAward");
        }
    }

    public string Exceeds
    {
        get
        {
            return _Exceeds;
        }
        set
        {
            _Exceeds = value;
            FirePropertyChangeNotification("Exceeds");
        }
    }

    public string DateMHDReceived
    {
        get
        {
            return _DateMHDReceived;
        }
        set
        {
            _DateMHDReceived = value;
            FirePropertyChangeNotification("DateMHDReceived");
        }
    }

    public string PeriodEnding
    {
        get
        {
            return _PeriodEnding;
        }
        set
        {
            _PeriodEnding = value;
            FirePropertyChangeNotification("PeriodEnding");
        }
    }

    public string DateAudited
    {
        get
        {
            return _DateAudited;
        }
        set
        {
            _DateAudited = value;
            FirePropertyChangeNotification("DateAudited");
        }
    }

    public string ForwardDate
    {
        get
        {
            return _ForwardDate;
        }
        set
        {
            _ForwardDate = value;
            FirePropertyChangeNotification("ForwardDate");
        }
    }

    public string SAOPerson
    {
        get
        {
            return _SAOPerson;
        }
        set
        {
            _SAOPerson = value;
            FirePropertyChangeNotification("SAOPerson");
        }
    }

    public Boolean IsDirty
    {
        get
        {
            return ((this.EntityState != EntityStateEnum.Unchanged) || (this.EntityState != EntityStateEnum.Deleted));
        }
    }

    public enum EntityStateEnum
    {
        Unchanged,
        Added,
        Deleted,
        Modified
    }

    public A133Collection A133s
    {
        get
        {
            return _A133s;
        }
    }

    void IEditableObject.BeginEdit()
    {
        if (!_Editing)
        {
            _OldA133Id = _A133Id;
            _OldRSN = _RSN;
            _OldSubcontractor = _Subcontractor;
            _OldCFDANumber = _CFDANumber;
            _OldIncludeCFDA = _IncludeCFDA;
            _OldYear = _Year;
            _OldFedAward = _FedAward;
            _OldExceeds = _Exceeds;
            _OldDateMHDReceived = _DateMHDReceived;
            _OldPeriodEnding = _PeriodEnding;
            _OldDateAudited = _DateAudited;
            _OldForwardDate = _ForwardDate;
            _OldSAOPerson = _SAOPerson;
        }
        this.EntityState = EntityStateEnum.Modified;
        _Editing = true;
    }

    void IEditableObject.CancelEdit()
    {
        if (_Editing)
        {
            _A133Id = _OldA133Id;
            _RSN = _OldRSN;
            _Subcontractor = _OldSubcontractor;
            _CFDANumber = _OldCFDANumber;
            _IncludeCFDA = _OldIncludeCFDA;
            _Year = _OldYear;
            _FedAward = _OldFedAward;
            _Exceeds = _OldExceeds;
            _DateMHDReceived = _OldDateMHDReceived;
            _PeriodEnding = _OldPeriodEnding;
            _DateAudited = _OldDateAudited;
            _ForwardDate = _OldForwardDate;
            _SAOPerson = _OldSAOPerson;
        }
        this.EntityState = EntityStateEnum.Unchanged;
        _Editing = false;
    }

    void IEditableObject.EndEdit()
    {
        _Editing = false;
    }

    public EntityStateEnum EntityState
    {
        get
        {
            return _EntityState;
        }
        set
        {
            _EntityState = value;
        }
    }

    string IDataErrorInfo.Error
    {
        get
        {
            return _Error;
        }
    }

    string IDataErrorInfo.this[string columnName]
    {
        get
        {
            return (string)_PropErrors[columnName];
        }
    }

    private void DataStateChanged(EntityStateEnum dataState, string propertyName)
    {
        //Raise the event
        if (PropertyChanged != null && propertyName != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        //If the state is deleted, mark it as deleted
        if (dataState == EntityStateEnum.Deleted)
        {
            this.EntityState = dataState;
        }
        if (this.EntityState == EntityStateEnum.Unchanged)
        {
            this.EntityState = dataState;
        }
    }

    #endregion
}

#endregion
#区域A133集合
公共类A133集合:BindingListView
{
公共A133Collection():base()
{
}
公共a133s集合(列表a133s):基础(a133s)
{
}
公共A133Collection(数据表dt)
{
foreach(数据行或数据行中的OW)
{
A133 a=新A133(oRow);
本条增补(a);
}
}
私有int FindMaxId()
{
int maxId=-1;
foreach(本规范中为A133 a)
{
如果(a.A133Id>maxId)
{
maxId=a.A133Id;
}
}
返回maxId;
}
}
#端区
#A133类区域
///
///类别:A133
///描述:管理单个A133业务对象
///注-对象的4种状态:未更改、添加、删除、修改
///添加了标志,表明添加了全新的对象;在数据库插入之前设置
///已删除对象已删除的标记;数据库删除后设置
///未更改是默认状态
///修改了道具已更改的标志
///>>IsDirty指示器查看对象是“已修改”还是“已添加”
///因为这些是预数据库标志
///
公开类A133:INotifyPropertyChanged,IEditableObject,IDataErrorInfo
{
//声明内部类集合对象
私人A133Collection_A133s=新A133Collection();
//声明内部类对象
私有MHDFMS.BusinessLogic.a13db_DB=new a13db();
//声明内部类道具
私人int_A133Id;
私有字符串_RSN;
私人分包商;
私有字符串CFDANumber;
私有字符串_包括fda;
私人字符串(u年),;
私有字符串_FedAward;
私有字符串_超过;
私有字符串_DateMHDReceived;
私有字符串PeriodEnding;
私有字符串DateAudited;
私有字符串_ForwardDate;
私有字符串_SAOPerson;
私人国际电话号码;
私有字符串_OldRSN;
私有字符串_;
私有字符串_OldCFDANumber;
私有字符串_OldIncludeCFDA;
私人字符串(旧年),;
私有字符串_OldFedAward;
私有字符串_;
私有字符串_OldDateMHDReceived;
私有字符串OldPeriodEnding;
私有字符串_OldDateAudited;
私有字符串_OldForwardDate;
私有字符串_OldSAOPerson;
私人编辑;
私有字符串_Error=string.Empty;
私有EntityState枚举_EntityState;
私有哈希表_PropErrors=新哈希表();
私有void FirePropertyChangeNotification(字符串propName)
{
if(PropertyChanged!=null)
{
PropertyChanged(这是新PropertyChangedEventArgs(propName));
}
}
#区域INotifyProperty更改成员
公共事件属性更改事件处理程序属性更改;
#端区
公共A133()
{
this.EntityState=EntityStateEnum.Unchanged;
}
公共A133(数据行dr)
{
//从数据行填充业务对象项
this.A133Id=Convert.ToInt32(dr[“a133_id”);
this.RSN=dr[“RSN”].ToString();
this.subscriber=dr[“subscriber”].ToString();
this.CFDANumber=dr[“cfda_no”].ToString();
this.IncludeCFDA=dr[“IncludeCFDA”].ToString();
this.sYear=dr[“year”].ToString();
this.FedAward=dr[“fed_award”].ToString();
this.overses=dr[“overses”].ToString();
如果(dr[“mhd接收日期”]!=null)
{
this.DateMHDReceived=Convert.ToDateTime(dr[“date_mhd_received”]).ToSortDateString();
}
如果(dr[“期间结束”!=null)
{
this.PeriodEnding=Convert.ToDateTime(dr[“period_ending”])。ToSortDateString();
}
如果(dr[“审计日期”!=null)
{
this.DateAudited=Convert.ToDateTime(dr[“date_audited”]).ToSortDateString();
}
如果(dr[“转发日期”!=null)
{
this.ForwardDate=Convert.ToDateTime(dr[“forward_date”]).ToSortDateString();
}
this.SAOPerson=dr[“sao_person”].ToString();
this.EntityState=EntityStateEnum.Unchanged;
}
#区域公共方法/构造函数
公共bool SaveData()
{
bool bSaved=false;
如果(this.A133Id==0)
{
bSaved=_DB.savea133数据(此);
}
其他的
{
bSaved=_DB.savea133数据(此);
}
如果(b保存==真)
{
this.EntityState=EntityStateEnum.Unchanged;
}
返回b保存;
}
公共布尔删除()
{
bool bSaved=_DB.SaveA133AsInactive(此);
如果(b保存==真)
{
this.EntityState=EntityStateEnum.Deleted;
}
返回b保存;
}
公共Int32 A133Id
{
得到
{
返回_A133Id;
}
设置
{
_A133Id=值;
}
}
公共字符串
{
得到
{
返回(RSN);
}
设置
{
_RSN=数值;
FireProperty变更通知(“RSN”);
}
}
公共字符串分包商
{
得到
{
退回分包商;
}
设置
{
_分包商=价值;
耐火材料变更通知(“分包商”);
}
}
公共字符串cfdNumber
{
得到
{
返回CFDANumber;
}
设置
{
_CFDANumber=数值;
FireProperty变更通知(“CFD编号”);
}
DataRowView currentRow = A133BindingSource.CurrencyManager.List[A133BindingSource.CurrencyManager.Position] as DataRowView;
A133Form oA133Form = new A133Form();
oA133Form.NewA133 = new A133(currentRow.Row);