/*******************************************************************************
* Copyright(c) 2016 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:dkGoodsTypeCodeSearchBox.cs
* 2.功能描述:产品类别编码选择控件
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2016/06/24 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
{
public partial class dkGoodsTypeCodeSearchBox : UserControl
{
#region 成员变量
private S_CMN_002 _frmGoodsType;
private Label lblGoodsTypeName; // 项目名称标签
private TextBox txtGoodsTypeName; // 输入文本框
private Button btnSearch; // 查询按钮
private bool _isEnabled = true; // 控件是否可用
private DataTable _dataSource = null; // 数据源
private int? _goodsTypeID; // 产品类别ID
private string _goodsTypeIDS; //id集
private string _goodsTypeCode; // 产品类别Code
private string _goodsTypeName; // 产品类别名称
private bool _isOnlyDisplayEnd; // 只显示末端产品类别标识
private bool _isMustInput; // 控件是否是必须输入项目
private bool _IsOnlyShowValid = true; // 是否只显示有效数据
#endregion
#region 构造函数
public dkGoodsTypeCodeSearchBox()
{
InitializeComponent();
this.IsOnlyDisplayEnd = false;
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.lblGoodsTypeName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
}
else
{
this.lblGoodsTypeName.ForeColor = System.Drawing.SystemColors.ControlText;
}
}
}
[DefaultValue("产品类别")]
[Description("获取或者设定Lable标签字符。")]
public string Title
{
get
{
return this.lblGoodsTypeName.Text;
}
set
{
this.lblGoodsTypeName.Text = value;
AdjustControl();
}
}
///
/// 获取和设置是否只显示末端产品类别。
///
[DefaultValue(true)]
[Description("获取和设置是否只显示末端产品类别。")]
public bool IsOnlyDisplayEnd
{
get
{
return _isOnlyDisplayEnd;
}
set
{
_isOnlyDisplayEnd = 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.txtGoodsTypeName.Text;
}
set
{
this.txtGoodsTypeName.Text = value;
}
}
///
/// 获取或者设定控件的文本框的背景颜色。
///
[Description("获取或者设定控件的文本框的背景颜色。")]
public Color TxtGoodsTypeBackColor
{
get
{
return this.txtGoodsTypeName.BackColor;
}
set
{
this.txtGoodsTypeName.BackColor = value;
}
}
///
/// 获取或者设定控件的产品类别ID。
///
[Description("获取或者设定控件的产品类别D。")]
public int? GoodsTypeID
{
get
{
return _goodsTypeID;
}
set
{
_goodsTypeID = value;
if (_goodsTypeID != null && _goodsTypeID != 0 && this.DataSource != null)
{
DataTable goodsTypeTable = this.DataSource.Copy();
DataRow[] dataRows = goodsTypeTable.Select("GoodsTypeID = " + this._goodsTypeID);
if (dataRows.Length == 1)
{
this.Text = dataRows[0]["GoodsTypeName"] as string;
this.GoodsTypeCode = dataRows[0]["GoodsTypeCode"] as string;
}
}
if (_goodsTypeID == null)
{
this.Text = string.Empty;
GoodsTypeCode = string.Empty;
GoodsTypeName = string.Empty;
}
}
}
///
/// 获取或者设定控件的产品类别CodeId集
///
[Description("获取或者设定控件的产品类别CodeId集。")]
public string GoodsTypeIDS
{
get
{
return _goodsTypeIDS;
}
set
{
_goodsTypeIDS = value;
}
}
///
/// 获取或者设定控件的产品类别Code
///
[Description("获取或者设定控件的产品类别Code。")]
public string GoodsTypeCode
{
get
{
return _goodsTypeCode;
}
set
{
_goodsTypeCode = value;
}
}
///
/// 获取或者设定控件的产品类别名称
///
[Description("获取或者设定控件的产品类别名称。")]
public string GoodsTypeName
{
get
{
return _goodsTypeName;
}
set
{
_goodsTypeName = value;
}
}
///
/// 获取或者设定控件是否可用。
///
[System.ComponentModel.DefaultValue(null)]
[Description("获取或者设定控件是否可用。")]
public new bool Enabled
{
get
{
return _isEnabled;
}
set
{
_isEnabled = value;
this.txtGoodsTypeName.Enabled = _isEnabled;
//this.btnSearch.Enabled = _isEnabled;
this.TabStop = _isEnabled;
}
}
///
/// 获取或者设定控件是否只读。
///
[System.ComponentModel.DefaultValue(null)]
[Description("获取或者设定控件是否只读。")]
public bool ReadOnly
{
set
{
this.txtGoodsTypeName.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 GoodsTypeValueChanged;
#endregion
#region 控件事件
[Description("控件光标点击按钮事件。")]
public new event EventHandler Click
{
add
{
this.btnSearch.Click += value;
}
remove
{
this.btnSearch.Click -= value;
}
}
///
/// 控件尺寸大小改变事件
///
///
///
private void dkGoodsTypeSearchBox_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.GetGoodsType(1, _isOnlyDisplayEnd ? 1 : 0);
}
// 释放窗体资源
if (null != _frmGoodsType)
{
_frmGoodsType.Dispose();
_frmGoodsType = null;
}
// 打开查询窗体
if (this.SelectMore)
{
_frmGoodsType = new S_CMN_002(1);
}
else
{
_frmGoodsType = new S_CMN_002(this.txtGoodsTypeName.Text);
}
_frmGoodsType.DataSource = this.DataSource;
DialogResult dialogResult = _frmGoodsType.ShowDialog();
// 查询窗体返回值给控件赋值
if (dialogResult.Equals(DialogResult.OK))
{
if (this.SelectMore)
{
_goodsTypeCode = string.Empty;
_goodsTypeName = string.Empty;
this._goodsTypeIDS = string.Empty;
if (_frmGoodsType.GoodsTypeRow != null || _frmGoodsType.dataDT.Rows.Count > 0)
{
for (int i = 0; i < _frmGoodsType.dataDT.Rows.Count; i++)
{
if (_frmGoodsType.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
{
if (string.IsNullOrEmpty(_goodsTypeCode))
{
_goodsTypeCode = _frmGoodsType.dataDT.Rows[i]["GoodsTypeCode"].ToString();
_goodsTypeName = _frmGoodsType.dataDT.Rows[i]["GoodsTypeName"].ToString();
_goodsTypeIDS = _frmGoodsType.dataDT.Rows[i]["GoodsTypeID"].ToString();
}
else
{
_goodsTypeCode += "," + _frmGoodsType.dataDT.Rows[i]["GoodsTypeCode"].ToString();
_goodsTypeName += "," + _frmGoodsType.dataDT.Rows[i]["GoodsTypeName"].ToString();
_goodsTypeIDS += "," + _frmGoodsType.dataDT.Rows[i]["GoodsTypeID"].ToString();
}
}
}
this.Text = _goodsTypeName;
}
}
else
{
if (_frmGoodsType.GoodsTypeRow != null)
{
_goodsTypeID = Convert.ToInt32(_frmGoodsType.GoodsTypeRow["GoodsTypeID"]);
_goodsTypeCode = _frmGoodsType.GoodsTypeRow["GoodsTypeCode"].ToString();
_goodsTypeName = _frmGoodsType.GoodsTypeRow["GoodsTypeName"].ToString();
this.Text = _frmGoodsType.GoodsTypeRow["GoodsTypeName"].ToString();
}
}
}
}
///
/// 清除控件的值
///
///
///
private void txtGoodsType_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
{
ClearControl();
}
}
private void txtGoodsType_TextChanged(object sender, EventArgs e)
{
this.OnTextChanged(e);
if (GoodsTypeValueChanged != null)
{
GoodsTypeValueChanged(this, new TextChangeEventArgs(this.txtGoodsTypeName.Text));
}
}
public class TextChangeEventArgs : EventArgs
{
public TextChangeEventArgs(string message)
{
}
}
#endregion
#region 私有方法/函数
///
/// 初始化控件界面控件内容
///
private void InitializeComponent()
{
this.lblGoodsTypeName = new System.Windows.Forms.Label();
this.txtGoodsTypeName = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblGoodsTypeName
//
this.lblGoodsTypeName.AutoSize = true;
this.lblGoodsTypeName.BackColor = System.Drawing.Color.Transparent;
this.lblGoodsTypeName.Location = new System.Drawing.Point(3, 4);
this.lblGoodsTypeName.Name = "lblGoodsTypeName";
this.lblGoodsTypeName.Size = new System.Drawing.Size(53, 12);
this.lblGoodsTypeName.TabIndex = 0;
this.lblGoodsTypeName.Text = "产品类别";
//
// txtGoodsTypeName
//
this.txtGoodsTypeName.Font = new System.Drawing.Font("宋体", 9F);
this.txtGoodsTypeName.Location = new System.Drawing.Point(62, 0);
this.txtGoodsTypeName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtGoodsTypeName.Name = "txtGoodsTypeName";
this.txtGoodsTypeName.ReadOnly = true;
this.txtGoodsTypeName.Size = new System.Drawing.Size(155, 21);
this.txtGoodsTypeName.TabIndex = 1;
this.txtGoodsTypeName.TextChanged += new System.EventHandler(this.txtGoodsType_TextChanged);
this.txtGoodsTypeName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtGoodsType_KeyDown);
//
// btnSearch
//
this.btnSearch.Image = global::Dongke.IBOSS.PRD.Client.Controls.Properties.Resources.searchButton;
this.btnSearch.Location = new System.Drawing.Point(223, 0);
this.btnSearch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(21, 21);
this.btnSearch.TabIndex = 2;
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// dkGoodsTypeSearchBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.txtGoodsTypeName);
this.Controls.Add(this.lblGoodsTypeName);
this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "dkGoodsTypeSearchBox";
this.Size = new System.Drawing.Size(244, 22);
this.SizeChanged += new System.EventHandler(this.dkGoodsTypeSearchBox_SizeChanged);
this.ResumeLayout(false);
this.PerformLayout();
}
///
/// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
///
protected void AdjustControl()
{
// 取得按钮控件的宽度和高度
int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
this.Height = this.btnSearch.Height;
// 设置控件的尺寸和位置。
this.txtGoodsTypeName.Location = new System.Drawing.Point(this.lblGoodsTypeName.Width +
ControlsConst.CONTROLSPACE, (this.Height - this.txtGoodsTypeName.Height) / 2);
this.txtGoodsTypeName.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
(this.lblGoodsTypeName.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.lblGoodsTypeName.Location =
new System.Drawing.Point(0, (this.Height - this.lblGoodsTypeName.Height) / 2);
this.lblGoodsTypeName.Size = new System.Drawing.Size(this.lblGoodsTypeName.Width, this.lblGoodsTypeName.Height);
}
///
/// 清空控件的值
///
///
///
public void ClearControl()
{
this.txtGoodsTypeName.Text = "";
this._goodsTypeID = null;
this._goodsTypeCode = string.Empty;
this._goodsTypeName = string.Empty;
this._goodsTypeIDS = 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
}
}