/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:dkProcedureSearchBox.cs
* 2.功能描述:工序选择控件
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2014/11/29 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;
using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.WCF.DataModels;
namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox
{
///
/// 工序选择控件
///
public partial class dkProcedureSearchBox : UserControl
{
#region 成员变量
private S_CMN_016 _frmProcedure;
private bool _isEnabled = true; // 控件是否可用
private DataTable _dataSource = null; // 数据源
private int? _procedureID; // 工序ID
private string _procedureIDS; //id集
private string _procedureCode; // 工序Code
private string _procedureName; // 工序Name
private bool _isMustInput; // 控件是否是必须输入项目
private bool _IsOnlyShowValid = true; // 是否只显示有效数据
private string _purview; // 是否有权限
private string _modelType; //id集
#endregion
#region 构造函数
public dkProcedureSearchBox()
{
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.lblProcedureName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
}
else
{
this.lblProcedureName.ForeColor = System.Drawing.SystemColors.ControlText;
}
}
}
[DefaultValue("产品类别")]
[Description("获取或者设定Lable标签字符。")]
public string Title
{
get
{
return this.lblProcedureName.Text;
}
set
{
this.lblProcedureName.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.txtProcedureName.Text;
}
set
{
this.txtProcedureName.Text = value;
}
}
///
/// 获取或者设定控件的文本框的背景颜色。
///
[Description("获取或者设定控件的文本框的背景颜色。")]
public Color TxtGoodsTypeBackColor
{
get
{
return this.txtProcedureName.BackColor;
}
set
{
this.txtProcedureName.BackColor = value;
}
}
///
/// 获取或者设定控件的工序id集
///
[Description("获取或者设定控件的工序id集。")]
public string ProcedureIDS
{
get
{
return _procedureIDS;
}
set
{
_procedureIDS = value;
}
}
///
/// 获取或者设定控件的工序Code
///
[Description("获取或者设定控件的工序Code。")]
public string ProcedureCode
{
get
{
return _procedureCode;
}
set
{
_procedureCode = value;
}
}
///
/// 获取或者设定控件的工序Name
///
[Description("获取或者设定控件的工序Name。")]
public string ProcedureName
{
get
{
return _procedureName;
}
set
{
_procedureName = value;
}
}
///
/// 获取或者设定控件的工序ID。
///
[Description("获取或者设定控件的工序ID。")]
public int? ProcedureID
{
get
{
return _procedureID;
}
set
{
_procedureID = value;
if (_procedureID != null && _procedureID != 0 && this.DataSource != null)
{
DataTable productionLineTable = this.DataSource.Copy();
DataRow[] dataRows = productionLineTable.Select("procedureID = " + this._procedureID);
if (dataRows.Length == 1)
{
this.Text = dataRows[0]["ProcedureCode"] as string;
this.ProcedureName = dataRows[0]["ProcedureName"] as string;
}
}
if (_procedureID == null)
{
this.Text = string.Empty;
ProcedureCode = string.Empty;
ProcedureName = string.Empty;
}
}
}
///
/// 获取或者设定控件是否可用。
///
[System.ComponentModel.DefaultValue(null)]
[Description("获取或者设定控件是否可用。")]
public new bool Enabled
{
get
{
return _isEnabled;
}
set
{
_isEnabled = value;
this.txtProcedureName.Enabled = _isEnabled;
//this.btnSearch.Enabled = _isEnabled;
this.TabStop = _isEnabled;
}
}
///
/// 获取或者设定控件是否只读。
///
[System.ComponentModel.DefaultValue(null)]
[Description("获取或者设定控件是否只读。")]
public bool ReadOnly
{
set
{
this.txtProcedureName.ReadOnly = value;
}
}
///
/// 范围权限
///
[Description("判断是否有权限")]
public string Purview
{
get
{
return _purview;
}
set
{
_purview = value;
}
}
///
/// 查看权限属性
///
[System.ComponentModel.DefaultValue(false)]
[Description("查看权限属性")]
public bool Ispurview
{
get;
set;
}
///
/// 范围权限
///
public byte PurviewType
{
get;
set;
}
///
/// 多选。
///
[System.ComponentModel.DefaultValue(false)]
[Description("多选。")]
public bool SelectMore
{
get;
set;
}
///
/// 是否启用权限功能
///
[System.ComponentModel.DefaultValue(true)]
[Description("是否启用权限功能")]
public bool IsEnablePurview
{
get;
set;
}
///
/// 获取或者工序类别
///
[Description("获取或者设定控件的工序类别。")]
public string ModelType
{
get
{
return _modelType;
}
set
{
_modelType = value;
}
}
#endregion
#region 事件
[Description("控件光标点击按钮事件。")]
public new event EventHandler Click
{
add
{
this.btnSearch.Click += value;
}
remove
{
this.btnSearch.Click -= value;
}
}
///
/// 控件尺寸大小改变事件
///
///
///
private void dkProcedureSearchBox_SizeChanged(object sender, EventArgs e)
{
AdjustControl();
}
///
/// 清除控件的值
///
///
///
private void txtProcedureName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
{
ClearControl();
}
}
///
/// 查询按钮按下事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
// 如果属性是不可用,是不能进行点击事件的
if (!Enabled)
{
return;
}
// 当数据源为null时,查询数据源
if (DataSource == null)
{
SearchProductionLineEntity line = new SearchProductionLineEntity();
if (IsEnablePurview)
{
if (_purview == null)
{
if (this.Ispurview)
{
MessageBox.Show(Messages.MSG_CMN_W028,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
return;
}
else
{
MessageBox.Show(Messages.MSG_CMN_W027,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
return;
}
}
line.ProcuteLineIDS = _purview;
}
// 查询数据源
DataSource = SystemModuleProxy.Service.GetProdureList(line).Tables[0];
// add wangx 2016/01/07
if (!string.IsNullOrEmpty(this.ModelType))
{
DataView dv = DataSource.DefaultView;
dv.RowFilter = "ModelType in (" + this.ModelType + ")";
DataSource = dv.ToTable();
}
}
// 释放窗体资源
if (null != _frmProcedure)
{
_frmProcedure.Dispose();
_frmProcedure = null;
}
// 打开查询窗体
if (this.SelectMore)
{
_frmProcedure = new S_CMN_016(1);
}
else
{
_frmProcedure = new S_CMN_016(0);
}
_frmProcedure.DataSource = this.DataSource;
DialogResult dialogResult = _frmProcedure.ShowDialog();
// 查询窗体返回值给控件赋值
if (dialogResult.Equals(DialogResult.OK))
{
if (this.SelectMore)
{
_procedureCode = string.Empty;
_procedureName = string.Empty;
_procedureIDS = string.Empty;
if (_frmProcedure.ProductionLineRow != null || _frmProcedure.dataDT.Rows.Count > 0)
{
for (int i = 0; i < _frmProcedure.dataDT.Rows.Count; i++)
{
if (_frmProcedure.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
{
if (string.IsNullOrEmpty(_procedureCode))
{
_procedureCode = _frmProcedure.dataDT.Rows[i]["procedureCode"].ToString();
_procedureName = _frmProcedure.dataDT.Rows[i]["procedureName"].ToString();
_procedureIDS = _frmProcedure.dataDT.Rows[i]["procedureID"].ToString();
}
else
{
_procedureCode += "," + _frmProcedure.dataDT.Rows[i]["procedureCode"].ToString();
_procedureName += "," + _frmProcedure.dataDT.Rows[i]["procedureName"].ToString();
_procedureIDS += "," + _frmProcedure.dataDT.Rows[i]["procedureID"].ToString();
}
}
}
this.Text = _procedureName;
}
}
else
{
if (_frmProcedure.ProductionLineRow != null)
{
_procedureID = Convert.ToInt32(_frmProcedure.ProductionLineRow["procedureID"]);
_procedureCode = _frmProcedure.ProductionLineRow["procedureCode"].ToString();
_procedureName = _frmProcedure.ProductionLineRow["procedureName"].ToString();
this.Text = _frmProcedure.ProductionLineRow["procedureName"].ToString();
}
}
}
}
private void txtProductionLineName_TextChanged(object sender, EventArgs e)
{
if (ProcedureValueChanged != null)
{
ProcedureValueChanged(this, new TextChangeEventArgs(this.txtProcedureName.Text));
}
}
public class TextChangeEventArgs : EventArgs
{
public TextChangeEventArgs(string message)
{
}
}
#endregion
#region 定义委托事件
public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
public event TextBoxChangedHandle ProcedureValueChanged;
#endregion
#region 私有方法
///
/// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
///
protected void AdjustControl()
{
// 取得按钮控件的宽度和高度
int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
this.Height = this.btnSearch.Height;
// 设置控件的尺寸和位置。
this.txtProcedureName.Location = new System.Drawing.Point(this.lblProcedureName.Width +
ControlsConst.CONTROLSPACE, (this.Height - this.txtProcedureName.Height) / 2);
this.txtProcedureName.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
(this.lblProcedureName.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.lblProcedureName.Location =
new System.Drawing.Point(0, (this.Height - this.lblProcedureName.Height) / 2);
this.lblProcedureName.Size = new System.Drawing.Size(this.lblProcedureName.Width, this.lblProcedureName.Height);
}
///
/// 清空控件的值
///
///
///
public void ClearControl()
{
this.txtProcedureName.Text = string.Empty;
this._procedureID = null;
this._procedureName = string.Empty;
this._procedureCode = string.Empty;
this._procedureIDS = string.Empty;
}
#endregion
private void txtProcedureName_TextChanged(object sender, EventArgs e)
{
this.OnTextChanged(e);
}
}
}