private void LinkToControl(LinkAttribute attr, FieldInfo info) { var ctrlName = attr.ControlName; var ctrl = FindControl(_container, ctrlName); if (ctrl == null) return; var val = info.GetValue(_obj); if (ctrl is TextBox) { (ctrl as TextBox).TextChanged += TbxOnTextChanged; if (!attr.InitOnlyEmpty || string.IsNullOrEmpty((ctrl as TextBox).Text)) if (val != null) (ctrl as TextBox).Text = val.ToString(); } else if (ctrl is DateTimePicker) { (ctrl as DateTimePicker).ValueChanged += DtpOnValueChanged; if (val != null) (ctrl as DateTimePicker).Value = DateTimeConverter.ConvertStrToDateTime(val); } else if (ctrl is ComboBox) { (ctrl as ComboBox).TextChanged += CbbOnTextChanged; if ((ctrl as ComboBox).DropDownStyle == ComboBoxStyle.DropDown) { if (!attr.InitOnlyEmpty || string.IsNullOrEmpty((ctrl as ComboBox).Text)) if (val != null) (ctrl as ComboBox).Text = val.ToString(); } else { if (val != null) (ctrl as ComboBox).SelectedIndex = (ctrl as ComboBox).Items.IndexOf(val.ToString()); } } else if (ctrl is CheckBox) { (ctrl as CheckBox).CheckedChanged += ChbCheckedChanged; if (val != null) (ctrl as CheckBox).Checked = (bool) val; } else return; try { _links.Add(ctrl, new Tuple<FieldInfo, LinkAttribute>(info, attr)); DoLinkAction(ctrl, attr); } catch (Exception) { MessageBox.Show(ctrl.Name); } }
private void DoLinkAction(object sender, LinkAttribute attr) { if (string.IsNullOrEmpty(attr.LinkActionName)) return; var action = ActionFactory[attr.LinkActionName]; if (action != null) action(sender, _obj); }