private void UpdateDataset() { string _FieldName = null; string _TableName = null; List <ZColumn> _ColumnList = null; PropertyInfo propTableName = null; PropertyInfo propFieldName = null; foreach (Control c in ControlsList(this)) { propTableName = c.GetType().GetProperty("TableName"); propFieldName = c.GetType().GetProperty("FieldName"); if (propTableName != null) { _TableName = propTableName.GetValue(c).ToString(); if (propFieldName != null) { _FieldName = propFieldName.GetValue(c).ToString(); } _ColumnList = SourceTables.FirstOrDefault(x => x.TableName == _TableName).ColumnList; ZColumn _CurrCol = _ColumnList.FirstOrDefault(x => x.FieldName == _FieldName); DataTable _Rec = SourceDataSet.Tables[_TableName]; //GetValue PropertyInfo propText = c.GetType().GetProperty("Text"); PropertyInfo propSelectedValue = c.GetType().GetProperty("SelectedValue"); PropertyInfo propChecked = c.GetType().GetProperty("Checked"); if (_Rec.Columns.Contains(_FieldName)) { if (c is ComboBox) { if ((_ColumnList.FirstOrDefault(x => x.FieldName == _FieldName).Required) && (propSelectedValue.GetValue(c) == null)) { throw new Exception("Please fill up all required fields"); } _Rec.Rows[0][_FieldName] = propSelectedValue.GetValue(c) ?? DBNull.Value; } else if (c is CheckBox) { _Rec.Rows[0][_FieldName] = propChecked.GetValue(c); } else { if ((_ColumnList.FirstOrDefault(x => x.FieldName == _FieldName).Required) && (propText.GetValue(c).ToString().Trim() == "" || propText.GetValue(c) == null)) { throw new Exception("Please fill up all required fields"); } _Rec.Rows[0][_FieldName] = propText.GetValue(c).ToString().Trim(); } } } } }
public void TLoadRecord() { PropertyInfo propTableName = null; PropertyInfo propFieldName = null; string TableName_ = null; string FieldName_ = null; List <ZColumn> ColumnList_ = null; ZColumn CurrCol_ = null; DataSourcesBLL _DataSourcesBLL = new DataSourcesBLL(); foreach (Control c_ in ControlsList(this)) { propTableName = c_.GetType().GetProperty("TableName"); propFieldName = c_.GetType().GetProperty("FieldName"); if (propTableName != null) { TableName_ = propTableName.GetValue(c_).ToString(); if (SourceDataSet.Tables.Contains(TableName_)) { if (c_ is DataGridView) { } else { FieldName_ = propFieldName.GetValue(c_).ToString(); ColumnList_ = SourceTables.FirstOrDefault(x => x.TableName == TableName_).ColumnList; CurrCol_ = ColumnList_.FirstOrDefault(x => x.FieldName == FieldName_); DataRow CurrRec_ = SourceDataSet.Tables[TableName_].Rows[0];//GetValue PropertyInfo propText = c_.GetType().GetProperty("Text"); PropertyInfo propEnabled = c_.GetType().GetProperty("Enabled"); PropertyInfo propSelectedValue = c_.GetType().GetProperty("SelectedValue"); PropertyInfo propChecked = c_.GetType().GetProperty("Checked"); PropertyInfo propDataSource = c_.GetType().GetProperty("DataSource"); PropertyInfo propDisplayMember = c_.GetType().GetProperty("DisplayMember"); PropertyInfo propValueMember = c_.GetType().GetProperty("ValueMember"); if (c_ is TextBox) { if (CurrRec_ != null) { propText.SetValue(c_, CurrRec_[FieldName_].ToString()); } else { propText.SetValue(c_, ""); } } else if (c_ is CheckBox) { if (CurrRec_ != null) { propChecked.SetValue(c_, CurrRec_[FieldName_]); } else { propChecked.SetValue(c_, Convert.ToBoolean(CurrCol_.DefaultValue)); } } else if (propSelectedValue != null && propSelectedValue.CanWrite) { DataTable _DataSource = _DataSourcesBLL.GetRecord(CurrCol_.DataSource); propDataSource.SetValue(c_, _DataSource); propDisplayMember.SetValue(c_, CurrCol_.DisplayMember.ToString()); propValueMember.SetValue(c_, CurrCol_.ValueMember.ToString()); if (CurrRec_ != null) { propSelectedValue.SetValue(c_, CurrRec_[FieldName_]); } else if (CurrCol_.DefaultValue != "" && CurrCol_.DefaultValue != null) { propSelectedValue.SetValue(c_, CurrCol_.DefaultValue); } } } } } } }
public void TUpdateControls() { string _TableName = null; string _FieldName = null; List <ZColumn> _ColumnList = null; PropertyInfo propTableName = null; PropertyInfo propFieldName = null; rbNew.Visible = IsView(); rbEdit.Visible = IsView(); rbSave.Visible = !IsView(); rbCancel.Visible = !IsView(); //Loop thought all controls if (SourceTables == null) { return; } if (SourceTables.Count == 0) { return; } foreach (Control c in ControlsList(this)) { propTableName = c.GetType().GetProperty("TableName"); propFieldName = c.GetType().GetProperty("FieldName"); if (propTableName != null) { if (c is DataGridView) { //(DataGridView)c.DataSource = _SourceDataset.Tables[_TableName]; DataGridView gv = c as DataGridView; // gv.AllowUserToAddRows = !_FormMode.IsView; gv.AllowUserToDeleteRows = !IsView(); gv.ReadOnly = IsView(); foreach (DataGridViewColumn gvc in gv.Columns) { if (gvc is DataGridViewComboBoxColumn) { PropertyInfo propDisplayStyle = gvc.GetType().GetProperty("DisplayStyle"); //Set DropdownStyle if (propDisplayStyle != null && IsView()) { propDisplayStyle.SetValue(gvc, DataGridViewComboBoxDisplayStyle.Nothing); } else if (propDisplayStyle != null) { propDisplayStyle.SetValue(gvc, DataGridViewComboBoxDisplayStyle.DropDownButton); } } } } else { _TableName = propTableName.GetValue(c).ToString(); _FieldName = propFieldName.GetValue(c).ToString(); _ColumnList = SourceTables.FirstOrDefault(x => x.TableName == _TableName).ColumnList; ZColumn _CurrCol = _ColumnList.FirstOrDefault(x => x.FieldName == _FieldName); PropertyInfo propReadOnly = c.GetType().GetProperty("ReadOnly"); PropertyInfo propBackColor = c.GetType().GetProperty("BackColor"); PropertyInfo propBorderColor = c.GetType().GetProperty("BorderColor"); PropertyInfo propEnabled = c.GetType().GetProperty("Enabled"); PropertyInfo propSelectedValue = c.GetType().GetProperty("SelectedValue"); PropertyInfo propDropDownStyle = c.GetType().GetProperty("DropDownStyle"); PropertyInfo propAutoCheck = c.GetType().GetProperty("AutoCheck"); //Set ReadOnly if (propReadOnly != null && propReadOnly.CanWrite) { propReadOnly.SetValue(c, IsView()); } else if (c is ComboBox) { c.KeyPress += new KeyPressEventHandler(comboBox_DisableKeyPress); //propEnabled.SetValue(c, !_FormMode.IsView); } //Set BGColor if (_CurrCol.Required && !IsView()) { propBackColor.SetValue(c, Color.Orange); } else { propBackColor.SetValue(c, Color.White); } //Set BorderColor if (propBorderColor != null && _CurrCol.Required && !IsView()) { propBorderColor.SetValue(c, Color.Orange); } else if (propBorderColor != null) { propBorderColor.SetValue(c, Color.White); } //Set DropdownStyle if (propDropDownStyle != null && IsView()) { propDropDownStyle.SetValue(c, ComboBoxStyle.Simple); } else if (propDropDownStyle != null) { propDropDownStyle.SetValue(c, ComboBoxStyle.DropDownList); } //Set Enabled ( for checkbox ) if (c is CheckBox) { propAutoCheck.SetValue(c, !IsView()); } } } } }