using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using Lskj.Control.Model; using Lskj.Business.Impl; namespace Lskj.Control { public partial class LabelComboxPopupEdit : BaseUserControl { public string editValue; public MyControl ControlObj; /// /// 文本控件 /// public TextEdit TextEdit { get { return txtEdit; } } /// /// 数据源 /// public DataTable table = new DataTable(); /// /// 弹出框中字体大小 /// public int ListBoxFontSize = 0; public LabelComboxPopupEdit() { InitializeComponent(); if (Business.Impl.LanguageTranslation.Translatable) { simpleButton1.Text = Business.Impl.LanguageTranslation.GetTranslatedText(simpleButton1.Text); simpleButton4.Text = Business.Impl.LanguageTranslation.GetTranslatedText(simpleButton4.Text); } } /// /// 隐藏值 /// /// The value. public new string EditValue { get { BaseUserControl control = null; if (this.Model != null) control = ControlObj.FindControl(this.Model.FieldName); if (this.Model != null && (this.Model.FieldType == ControlType.LabComboxPopupValue || this.Model.FieldType == ControlType.LabComboxPopupMutilValue)) { this.table = BaseImpl.GetDataTableResult(ControlObj.ReplaceControlValue(this.Model.SourceSql)); if (!string.IsNullOrEmpty(editValue)) { return editValue; } else { // 存在名称并且没有value值则 if (control != null && !string.IsNullOrEmpty(control.EditText)) { if (table != null && table is DataTable) { DataRow rowItem = table.Select("1=1").FirstOrDefault(x => control.EditText == x[this.Model.TextMember] + ""); DataRow rowValueItem = table.Select("1=1").FirstOrDefault(x => control.EditText == x[this.Model.ValueMember] + ""); if (rowItem != null) { this.txtEdit.Text = rowItem[this.Model.TextMember] + ""; return rowItem[this.Model.ValueMember] + ""; } else if (rowValueItem != null) { this.txtEdit.Text = rowValueItem[this.Model.TextMember] + ""; return rowValueItem[this.Model.ValueMember] + ""; } } } } } return null; } } /// /// 说明:设置控件显示文本 /// 创建人:龚宇超 /// 创建日期:2017-08-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 显示Lebel文本 public override string LabelText { get { return this.lblText.Text; } set { this.lblText.Text = value; if (FontSize > 0) { this.plLeft.Dock = DockStyle.Left; this.plLeft.AutoSize = false; this.lblText.AutoSize = false; this.lblText.Dock = System.Windows.Forms.DockStyle.Fill; this.lblText.Location = new System.Drawing.Point(0, 0); this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.txtEdit.Properties.AutoHeight = false; this.plLeft.Width = value.Length * GetCharWidth(); this.simpleButton4.Width = this.simpleButton1.Width = this.Model.Size.Height + 10; GetCharWidthMultilingual(this.lblText, this.lblText.Text, this.plLeft); } else { this.plLeft.Width = this.lblText.Width + PaddingLeft; } } } /// /// 字体大小 /// /// The size of the control. public override float FontSize { get { return base.FontSize; } set { base.FontSize = value; if (value > 0) { this.lblText.Font = new Font(this.lblText.Font.FontFamily, value); this.TextEdit.Font = new Font(this.TextEdit.Font.FontFamily, value); } } } /// /// 说明:设置控件值 /// 创建人:龚宇超 /// 创建日期:2017-08-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public override string EditText { get { return this.txtEdit.Text; } set { this.txtEdit.Text = value; } } /// /// 说明:设置控件提示文本 /// 创建人:龚宇超 /// 创建日期:2017-08-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 返回控件值 public override string NullText { get { return this.txtEdit.Properties.NullValuePrompt; } set { if (!string.IsNullOrEmpty(value)) { this.TextEdit.Properties.NullValuePromptShowForEmptyValue = true; this.TextEdit.Properties.NullValuePrompt = value; } base.NullText = value; } } /// /// 只读文本颜色 /// /// The color of the read only label. public override bool ReadOnly { get { return base.ReadOnly; } set { base.ReadOnly = value; this.txtEdit.Properties.ReadOnly = value; this.simpleButton1.Enabled = this.simpleButton4.Enabled = !value; this.lblText.ForeColor = value ? base.ReadOnlyLabelForceColor : Required ? base.RequiredLabelForceColor : base.DefaultLabelForceColor; } } /// /// 必填文本颜色 /// /// The color of the required label. public override bool Required { get { return base.Required; } set { base.Required = value; if (value) { this.lblText.ForeColor = base.RequiredLabelForceColor; } } } /// /// 说明:弹出框 /// 创建人:龚宇超 /// 创建日期:2019-01-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void ShowPopup() { FrmComboxPopup popup = new FrmComboxPopup(this.Model, this.ControlObj, ListBoxFontSize); DialogResult result = popup.ShowDialog(); if (result == DialogResult.OK) { this.EditText = popup.ShowText; this.editValue = popup.ShowValue; } else { this.editValue = this.EditText = ""; } } /// /// 说明: /// 创建人:龚宇超 /// 创建日期:2017-08-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void txtEdit_Click(object sender, EventArgs e) { try { this.ShowPopup(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } private void simpleButton1_Click(object sender, EventArgs e) { try { this.ShowPopup(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } private void simpleButton4_Click(object sender, EventArgs e) { try { this.editValue = this.EditText = ""; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 背景颜色 /// /// The color of the required label. public override Color BackgroundColor { get { return TextEdit.Properties.Appearance.BackColor; } set { TextEdit.Properties.Appearance.BackColor = value;