/******************************************************************************* * Copyright(c) 2014 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:dkGMouldTypeSearchBox.cs * 2.功能描述:成型线类型选择控件 * 编辑履历: * 作者 日期 版本 修改内容 * 庄天威 2014/09/15 1.00 新建 *******************************************************************************/ using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox { /// /// 成型线类型选择控件 /// public partial class dkGMouldTypeSearchBox : UserControl { #region 成员变量 private S_CMN_005 _frmMouldType; private Label lblGMouldType; // 项目名称标签 private TextBox txtGMouldType; // 输入文本框 private bool _isEnabled = true; // 控件是否可用 private DataTable _dataSource = null; // 数据源 private int? _mouldTypeID; // 成型线类型ID private string _mouldTypeIDS; //id集 private string _mouldTypeCode; // 成型线类型Code private string _mouldTypeName; // 成型线类型名称 private int _isCanManyTimes; // 能否多次注浆 private bool _isMustInput; // 控件是否是必须输入项目 private bool _IsOnlyShowValid = true; // 是否只显示有效数据 #endregion #region 构造函数 public dkGMouldTypeSearchBox() { InitializeComponent(); this.ReadOnly = true; } #endregion #region 属性 /// /// 是否只显示有效数据 /// [Description("设置控件是否只显示有效数据。")] [DefaultValue(true)] public bool IsOnlyShowValid { get { return _IsOnlyShowValid; } set { _IsOnlyShowValid = value; } } /// /// 获取或者设定控件是否是必须输入项目 /// [DefaultValue("False")] [Description("获取或者设定控件是否是必须输入项目。")] public bool IsMustInput { get { return _isMustInput; } set { _isMustInput = value; // 项目为必须输入项时,需要修改字体颜色 if (_isMustInput) { this.lblGMouldType.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39))))); } else { this.lblGMouldType.ForeColor = System.Drawing.SystemColors.ControlText; } } } [Description("获取或者设定Lable标签字符。")] public string Title { get { return this.lblGMouldType.Text; } set { this.lblGMouldType.Text = value; AdjustControl(); } } /// /// 获取和设置是否只显示多次注浆类别。 /// [DefaultValue(true)] [Description("获取和设置是否只显示多次注浆类别。")] public int IsCanManyTimes { get { return _isCanManyTimes; } set { _isCanManyTimes = value; } } [DefaultValue(false)] public bool IsDeleteSelf { get; set; } /// /// 获取或者设定控件的数据源。 /// [Description("获取或者设定控件的数据源。")] public DataTable DataSource { get { return _dataSource; } set { _dataSource = value; } } /// /// 获取或者设定控件的尺寸大小。 /// [Description("获取或者设定控件的尺寸大小。")] public new Size Size { get { return base.Size; } set { base.Size = value; AdjustControl(); } } /// /// 获取或者设定控件的文本框的文本字符串。 /// [Description("获取或者设定控件的文本框的文本字符串。")] public override string Text { get { return this.txtGMouldType.Text; } set { this.txtGMouldType.Text = value; } } /// /// 获取或者设定控件的文本框的背景颜色。 /// [Description("获取或者设定控件的文本框的背景颜色。")] public Color TxtMouldTypeBackColor { get { return this.txtGMouldType.BackColor; } set { this.txtGMouldType.BackColor = value; } } /// /// 获取或者设定控件的类别ID。 /// [Description("获取或者设定控件的类别ID。")] public int? MouldTypeID { get { return _mouldTypeID; } set { _mouldTypeID = value; if (_mouldTypeID != null && _mouldTypeID != 0 && this.DataSource != null) { DataTable mouldTypeTable = this.DataSource.Copy(); DataRow[] dataRows = mouldTypeTable.Select("GMouldTypeID = " + this._mouldTypeID); if (dataRows.Length == 1) { this.MouldTypeCode = dataRows[0]["GMouldTypeCode"] as string; this.Text = dataRows[0]["GMouldTypeName"] as string; } } if (_mouldTypeID == null) { this.Text = string.Empty; MouldTypeCode = string.Empty; MouldTypeName = string.Empty; } } } /// /// 获取或者设定控件的类别Code /// [Description("获取或者设定控件的类别Code。")] public string MouldTypeIDS { get { return _mouldTypeIDS; } set { _mouldTypeIDS = value; } } /// /// 获取或者设定控件的类别id集 /// [Description("获取或者设定控件的类别id集。")] public string MouldTypeCode { get { return _mouldTypeCode; } set { _mouldTypeCode = value; } } /// /// 获取或者设定控件的类别名称 /// [Description("获取或者设定控件的类别名称。")] public string MouldTypeName { get { return _mouldTypeName; } set { _mouldTypeName = value; } } /// /// 获取或者设定控件是否可用。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否可用。")] public new bool Enabled { get { return _isEnabled; } set { _isEnabled = value; this.txtGMouldType.Enabled = _isEnabled; this.TabStop = _isEnabled; } } /// /// 获取或者设定控件是否只读。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否只读。")] public bool ReadOnly { set { this.txtGMouldType.ReadOnly = value; } } /// /// 范围权限 /// public byte PurviewType { get; set; } /// /// 多选。 /// [System.ComponentModel.DefaultValue(false)] [Description("多选。")] public bool SelectMore { get; set; } #endregion #region 定义委托事件 public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e); public event TextBoxChangedHandle MouldTypeValueChanged; #endregion #region 控件事件 [Description("控件光标点击按钮事件。")] public new event EventHandler Click { add { this.btnSearch.Click += value; } remove { this.btnSearch.Click -= value; } } /// /// 控件尺寸大小改变事件 /// /// /// private void dkGMouldTypeSearchBox_SizeChanged(object sender, System.EventArgs e) { AdjustControl(); } /// /// 查询按钮按下事件 /// /// /// private void btnSearch_Click(object sender, System.EventArgs e) { // 如果属性是不可用,是不能进行点击事件的 if (!Enabled) { return; } // 当数据源为null时,查询数据源 if (DataSource == null) { // 查询数据源 DataSource = SystemModuleProxy.Service.GetGMouldType().Tables[0]; } // 释放窗体资源 if (null != _frmMouldType) { _frmMouldType.Dispose(); _frmMouldType = null; } // 打开查询窗体 if (this.SelectMore) { _frmMouldType = new S_CMN_005(1); } else { _frmMouldType = new S_CMN_005(); } _frmMouldType.DataSource = this.DataSource; DialogResult dialogResult = _frmMouldType.ShowDialog(); // 查询窗体返回值给控件赋值 if (dialogResult.Equals(DialogResult.OK)) { //判断是多选否是 if (this.SelectMore) { _mouldTypeCode = string.Empty; _mouldTypeName = string.Empty; _mouldTypeIDS = string.Empty; //赋值多选值 if (_frmMouldType.dataDT.Rows.Count > 0 || _frmMouldType.MouldTypeRow != null) { for (int i = 0; i < _frmMouldType.dataDT.Rows.Count; i++) { if (_frmMouldType.dataDT.Rows[i]["sel"].ToString().Equals("1")) { if (string.IsNullOrEmpty(_mouldTypeCode)) { _mouldTypeCode = _frmMouldType.dataDT.Rows[i]["GMOULDTYPECODE"].ToString(); _mouldTypeName = _frmMouldType.dataDT.Rows[i]["GMOULDTYPENAME"].ToString(); _mouldTypeIDS = _frmMouldType.dataDT.Rows[i]["GMOULDTYPEID"].ToString(); } else { _mouldTypeCode += "," + _frmMouldType.dataDT.Rows[i]["GMOULDTYPECODE"].ToString(); _mouldTypeName += "," + _frmMouldType.dataDT.Rows[i]["GMOULDTYPENAME"].ToString(); _mouldTypeIDS += "," + _frmMouldType.dataDT.Rows[i]["GMOULDTYPEID"].ToString(); } } } this.Text = _mouldTypeName; } } else { if (_frmMouldType.MouldTypeRow != null) { _mouldTypeID = Convert.ToInt32(_frmMouldType.MouldTypeRow["GMOULDTYPEID"]); _mouldTypeCode = _frmMouldType.MouldTypeRow["GMOULDTYPECODE"].ToString(); _mouldTypeName = _frmMouldType.MouldTypeRow["GMOULDTYPENAME"].ToString(); _isCanManyTimes = Convert.ToInt32(_frmMouldType.MouldTypeRow["CanManyTimes"].ToString()); this.Text = _frmMouldType.MouldTypeRow["GMOULDTYPENAME"].ToString(); } } } } /// /// 清除控件的值 /// /// /// private void txtGMouldType_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { ClearControl(); } } private void txtGMouldType_TextChanged(object sender, EventArgs e) { if (MouldTypeValueChanged != null) { MouldTypeValueChanged(this, new TextChangeEventArgs(this.txtGMouldType.Text)); } } public class TextChangeEventArgs : EventArgs { public TextChangeEventArgs(string message) { } } #endregion #region 私有方法/函数 /// /// 根据控件的尺寸变化,改变控件内部控件的尺寸大小 /// protected void AdjustControl() { // 取得按钮控件的宽度和高度 int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0; this.Height = this.btnSearch.Height; // 设置控件的尺寸和位置。 this.txtGMouldType.Location = new System.Drawing.Point(this.lblGMouldType.Width + ControlsConst.CONTROLSPACE, (this.Height - this.txtGMouldType.Height) / 2); this.txtGMouldType.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width - (this.lblGMouldType.Width + ControlsConst.CONTROLSPACE * 2), this.Height); this.btnSearch.Location = new System.Drawing.Point(this.Width - this.btnSearch.Width, (this.Height - this.btnSearch.Height) / 2); // 设置标签的尺寸和位置。 this.lblGMouldType.Location = new System.Drawing.Point(0, (this.Height - this.lblGMouldType.Height) / 2); this.lblGMouldType.Size = new System.Drawing.Size(this.lblGMouldType.Width, this.lblGMouldType.Height); } /// /// 清空控件 /// /// public void ClearControl() { this.txtGMouldType.Text = ""; this._mouldTypeID = null; this._mouldTypeCode = string.Empty; this._mouldTypeName = string.Empty; this._mouldTypeIDS = string.Empty; } /// /// 过滤数据源 /// /// /// protected DataTable SetFilter(DataTable dataSource) { //string filter = "ValueFlag = 1"; //if (dataSource is DataTable) //{ // DataTable dtbl = (DataTable)dataSource; // // 若设置了只显示有效数据 // if (this._IsOnlyShowValid == true) // { // dtbl.DefaultView.RowFilter = filter; // } // dataSource = dtbl.DefaultView.ToTable(); //} return dataSource; } #endregion } }