/******************************************************************************* * Copyright(c) 2014 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:dkGoodsCodeSearchBox.cs * 2.功能描述:产品编码选择控件 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2015/06/19 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.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox { public partial class dkGoodsCodeSearchBox : UserControl { #region 成员变量 private S_CMN_006 _frmGoods; private bool _isEnabled = true; // 控件是否可用 private DataTable _dataSource = null; // 数据源 private int? _goodsID; // 产品ID private string _goodsIDS; //id集 private string _goodsCode; // 产品Code private string _goodsName; // 产品名称 private string _goodsSpecification; //产品规格 private bool _isMustInput; // 控件是否是必须输入项目 private bool _IsOnlyShowValid = true; // 是否只显示有效数据 #endregion #region 构造函数 public dkGoodsCodeSearchBox() { 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.lblGoods.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39))))); } else { this.lblGoods.ForeColor = System.Drawing.SystemColors.ControlText; } } } [DefaultValue("产品")] [Description("获取或者设定Lable标签字符。")] public string Title { get { return this.lblGoods.Text; } set { this.lblGoods.Text = value; AdjustControl(); } } [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.txtGoods.Text; } set { this.txtGoods.Text = value; } } /// /// 获取或者设定控件的文本框的背景颜色。 /// [Description("获取或者设定控件的文本框的背景颜色。")] public Color TxtGoodsBackColor { get { return this.txtGoods.BackColor; } set { this.txtGoods.BackColor = value; } } /// /// 获取或者设定控件的产品ID。 /// [Description("获取或者设定控件的产品D。")] public int? GoodsID { get { return _goodsID; } set { _goodsID = value; if (_goodsID != null && _goodsID != 0 && this.DataSource != null) { DataTable GoodsTable = this.DataSource.Copy(); DataRow[] dataRows = GoodsTable.Select("GGoodsID = " + this._goodsID); if (dataRows.Length == 1) { this.GoodsCode = dataRows[0]["GGoodsCode"] as string; //this.Text = dataRows[0]["GGoodsName"] as string; this.Text = dataRows[0]["GGoodsCode"] as string; } } if (_goodsID == null) { this.Text = string.Empty; GoodsCode = string.Empty; GoodsName = string.Empty; } } } /// /// 获取或者设定控件的产品Codeid集 /// [Description("获取或者设定控件的产品Codeid集。")] public string GoodsIDS { get { return _goodsIDS; } set { _goodsIDS = value; } } /// /// 获取或者设定控件的产品Code /// [Description("获取或者设定控件的产品Code。")] public string GoodsCode { get { return _goodsCode; } set { _goodsCode = value; } } /// /// 获取或者设定控件的产品名称 /// [Description("获取或者设定控件的产品名称。")] public string GoodsName { get { return _goodsName; } set { _goodsName = value; } } public string GoodsSpecification { get { return _goodsSpecification; } set { _goodsSpecification = value; } } /// /// 获取或者设定控件是否可用。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否可用。")] public new bool Enabled { get { return _isEnabled; } set { _isEnabled = value; this.txtGoods.Enabled = _isEnabled; this.TabStop = _isEnabled; } } /// /// 获取或者设定控件是否只读。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否只读。")] public bool ReadOnly { set { this.txtGoods.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 GoodsValueChanged; #endregion #region 控件事件 [Description("控件光标点击按钮事件。")] public new event EventHandler Click { add { this.btnSearch.Click += value; } remove { this.btnSearch.Click -= value; } } /// /// 控件尺寸大小改变事件 /// /// /// private void dkGoodsSearchBox_SizeChanged(object sender, System.EventArgs e) { AdjustControl(); } /// /// 查询按钮按下事件 /// /// /// private void btnSearch_Click(object sender, System.EventArgs e) { // 如果属性是不可用,是不能进行点击事件的 if (!Enabled) { return; } // 当数据源为null时,查询数据源 if (DataSource == null) { // 查询数据源 GoodsEntity ge = new GoodsEntity(); ge.CeaseFlag = 1; ge.ValueFlag = 1; DataSource = SystemModuleProxy.Service.SerachGoods(ge).Tables[0]; } // 释放窗体资源 if (null != _frmGoods) { _frmGoods.Dispose(); _frmGoods = null; } // 打开查询窗体 if (this.SelectMore) { _frmGoods = new S_CMN_006(1); } else { _frmGoods = new S_CMN_006(0); } _frmGoods.DataSource = this.DataSource; DialogResult dialogResult = _frmGoods.ShowDialog(); // 查询窗体返回值给控件赋值 if (dialogResult.Equals(DialogResult.OK)) { if (this.SelectMore) { _goodsCode = string.Empty; _goodsName = string.Empty; _goodsIDS = string.Empty; if (_frmGoods.dataDT.Rows.Count > 0 || _frmGoods.DataRow != null) { for (int i = 0; i < _frmGoods.dataDT.Rows.Count; i++) { if (_frmGoods.dataDT.Rows[i]["sel"].ToString().Equals("1")) { if (string.IsNullOrEmpty(_goodsIDS)) { _goodsCode = _frmGoods.dataDT.Rows[i]["GoodsCODE"].ToString(); _goodsName = _frmGoods.dataDT.Rows[i]["GoodsNAME"].ToString(); _goodsIDS = _frmGoods.dataDT.Rows[i]["GoodsID"].ToString(); } else { _goodsCode += "," + _frmGoods.dataDT.Rows[i]["GoodsCODE"].ToString(); _goodsName += "," + _frmGoods.dataDT.Rows[i]["GoodsNAME"].ToString(); _goodsIDS += "," + _frmGoods.dataDT.Rows[i]["GoodsID"].ToString(); } } } this.Text = _goodsCode; } } else { if (_frmGoods.DataRow != null) { _goodsID = Convert.ToInt32(_frmGoods.DataRow["GoodsID"]); _goodsCode = _frmGoods.DataRow["GoodsCODE"].ToString(); _goodsName = _frmGoods.DataRow["GoodsNAME"].ToString(); _goodsSpecification = _frmGoods.DataRow["GoodsSpecification"].ToString(); this.Text = _frmGoods.DataRow["GoodsCODE"].ToString(); } } } } /// /// 清除控件的值 /// /// /// private void txtGoods_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { ClearControl(); } } private void txtGoodsType_TextChanged(object sender, EventArgs e) { if (GoodsValueChanged != null) { GoodsValueChanged(this, new TextChangeEventArgs(this.txtGoods.Text)); } this.OnTextChanged(e); } 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.txtGoods.Location = new System.Drawing.Point(this.lblGoods.Width + ControlsConst.CONTROLSPACE, (this.Height - this.txtGoods.Height) / 2); this.txtGoods.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width - (this.lblGoods.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.lblGoods.Location = new System.Drawing.Point(0, (this.Height - this.lblGoods.Height) / 2); this.lblGoods.Size = new System.Drawing.Size(this.lblGoods.Width, this.lblGoods.Height); } /// /// 清空控件的值 /// /// /// public void ClearControl() { this.txtGoods.Text = ""; this._goodsID = null; this._goodsCode = string.Empty; this._goodsName = string.Empty; this._goodsIDS = 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 } }