| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:dkproductionLineSearchBox.cs
- * 2.功能描述:生产线选择控件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 宋扬 2014/11/18 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
- {
- /// <summary>
- /// 生产线选择控件
- /// </summary>
- public partial class dkproductionLineSearchBox : UserControl
- {
- #region 成员变量
- private S_CMN_015 _frmProductionLine;
- private bool _isEnabled = true; // 控件是否可用
- private DataTable _dataSource = null; // 数据源
- private int? _productionLineID; // 生产线ID
- private string _productionLineIDS; //id集
- private string _productionLineCode; // 生产线Code
- private string _productionLineName; // 产生产线名称
- private bool _isMustInput; // 控件是否是必须输入项目
- private bool _IsOnlyShowValid = true; // 是否只显示有效数据
- private string _purview; //是否有权限
- #endregion
- #region 构造函数
- public dkproductionLineSearchBox()
- {
- InitializeComponent();
- this.ReadOnly = true;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 是否只显示有效数据
- /// </summary>
- [Description("设置控件是否只显示有效数据。")]
- [DefaultValue(true)]
- public bool IsOnlyShowValid
- {
- get
- {
- return _IsOnlyShowValid;
- }
- set
- {
- _IsOnlyShowValid = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否是必须输入项目
- /// </summary>
- [DefaultValue("False")]
- [Description("获取或者设定控件是否是必须输入项目。")]
- public bool IsMustInput
- {
- get
- {
- return _isMustInput;
- }
- set
- {
- _isMustInput = value;
- // 项目为必须输入项时,需要修改字体颜色
- if (_isMustInput)
- {
- this.lblProductionLineName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
- }
- else
- {
- this.lblProductionLineName.ForeColor = System.Drawing.SystemColors.ControlText;
- }
- }
- }
- [DefaultValue("产品类别")]
- [Description("获取或者设定Lable标签字符。")]
- public string Title
- {
- get
- {
- return this.lblProductionLineName.Text;
- }
- set
- {
- this.lblProductionLineName.Text = value;
- AdjustControl();
- }
- }
- [DefaultValue(false)]
- public bool IsDeleteSelf
- {
- get;
- set;
- }
- /// <summary>
- /// 获取或者设定控件的数据源。
- /// </summary>
- [Description("获取或者设定控件的数据源。")]
- public DataTable DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- _dataSource = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的尺寸大小。
- /// </summary>
- [Description("获取或者设定控件的尺寸大小。")]
- public new Size Size
- {
- get
- {
- return base.Size;
- }
- set
- {
- base.Size = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定控件的文本框的文本字符串。
- /// </summary>
- [Description("获取或者设定控件的文本框的文本字符串。")]
- public override string Text
- {
- get
- {
- return this.txtProductionLineName.Text;
- }
- set
- {
- this.txtProductionLineName.Text = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的文本框的背景颜色。
- /// </summary>
- [Description("获取或者设定控件的文本框的背景颜色。")]
- public Color TxtGoodsTypeBackColor
- {
- get
- {
- return this.txtProductionLineName.BackColor;
- }
- set
- {
- this.txtProductionLineName.BackColor = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的生产线ID。
- /// </summary>
- [Description("获取或者设定控件的生产线ID。")]
- public int? ProductionLineID
- {
- get
- {
- return _productionLineID;
- }
- set
- {
- _productionLineID = value;
- if (_productionLineID != null && _productionLineID != 0 && this.DataSource != null)
- {
- DataTable productionLineTable = this.DataSource.Copy();
- DataRow[] dataRows = productionLineTable.Select("ProductionLineID = " + this._productionLineID);
- if (dataRows.Length == 1)
- {
- this.Text = dataRows[0]["ProductionLineCode"] as string;
- this.ProductionLineName = dataRows[0]["ProductionLineName"] as string;
- }
- }
- if (_productionLineID == null)
- {
- this.Text = string.Empty;
- ProductionLineCode = string.Empty;
- ProductionLineName = string.Empty;
- }
- }
- }
- /// <summary>
- /// 获取或者设定控件的生产线id集
- /// </summary>
- [Description("获取或者设定控件的生产线id集。")]
- public string ProductionLineIDS
- {
- get
- {
- return _productionLineIDS;
- }
- set
- {
- _productionLineIDS = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的生产线Code
- /// </summary>
- [Description("获取或者设定控件的生产线Code。")]
- public string ProductionLineCode
- {
- get
- {
- return _productionLineCode;
- }
- set
- {
- _productionLineCode = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的生产线名称
- /// </summary>
- [Description("获取或者设定控件的生产线名称。")]
- public string ProductionLineName
- {
- get
- {
- return _productionLineName;
- }
- set
- {
- _productionLineName = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否可用。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否可用。")]
- public new bool Enabled
- {
- get
- {
- return _isEnabled;
- }
- set
- {
- _isEnabled = value;
- this.txtProductionLineName.Enabled = _isEnabled;
- //this.btnSearch.Enabled = _isEnabled;
- this.TabStop = _isEnabled;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否只读。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否只读。")]
- public bool ReadOnly
- {
- set
- {
- this.txtProductionLineName.ReadOnly = value;
- }
- }
- /// <summary>
- /// 范围权限
- /// </summary>
- [Description("判断是否有权限")]
- public string Purview
- {
- get
- {
- return _purview;
- }
- set
- {
- _purview = value;
- }
- }
- /// <summary>
- /// 查看权限属性
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("查看权限属性")]
- public bool Ispurview
- {
- get;
- set;
- }
- /// <summary>
- /// 范围权限
- /// </summary>
- public byte PurviewType
- {
- get;
- set;
- }
- /// <summary>
- /// 多选。
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("多选。")]
- public bool SelectMore
- {
- get;
- set;
- }
- /// <summary>
- /// 是否启用权限功能
- /// </summary>
- [System.ComponentModel.DefaultValue(true)]
- [Description("是否启用权限功能")]
- public bool IsEnablePurview
- {
- get;
- set;
- }
- #endregion
- #region 定义委托事件
- public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
- public event TextBoxChangedHandle ProductionLineValueChanged;
- #endregion
- #region 事件
- [Description("控件光标点击按钮事件。")]
- public new event EventHandler Click
- {
- add
- {
- this.btnSearch.Click += value;
- }
- remove
- {
- this.btnSearch.Click -= value;
- }
- }
- /// <summary>
- /// 控件尺寸大小改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dkproductionLineSearchBox_SizeChanged(object sender, EventArgs e)
- {
- AdjustControl();
- }
- /// <summary>
- /// 清除控件的值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtProductionLineName_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
- {
- ClearControl();
- }
- }
- /// <summary>
- /// 查询按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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_W026,
- 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.GetProductionLine(line).Tables[0];
- }
- // 释放窗体资源
- if (null != _frmProductionLine)
- {
- _frmProductionLine.Dispose();
- _frmProductionLine = null;
- }
- // 打开查询窗体
- if (this.SelectMore)
- {
- _frmProductionLine = new S_CMN_015(1);
- }
- else
- {
- _frmProductionLine = new S_CMN_015(0);
- }
- _frmProductionLine.DataSource = this.DataSource;
- DialogResult dialogResult = _frmProductionLine.ShowDialog();
- // 查询窗体返回值给控件赋值
- if (dialogResult.Equals(DialogResult.OK))
- {
- if (this.SelectMore)
- {
- _productionLineCode = string.Empty;
- _productionLineName = string.Empty;
- _productionLineIDS = string.Empty;
- if (_frmProductionLine.ProductionLineRow != null || _frmProductionLine.dataDT.Rows.Count > 0)
- {
- for (int i = 0; i < _frmProductionLine.dataDT.Rows.Count; i++)
- {
- if (_frmProductionLine.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
- {
- if (string.IsNullOrEmpty(_productionLineCode))
- {
- _productionLineCode = _frmProductionLine.dataDT.Rows[i]["ProductionLineCode"].ToString();
- _productionLineName = _frmProductionLine.dataDT.Rows[i]["ProductionLineName"].ToString();
- _productionLineIDS = _frmProductionLine.dataDT.Rows[i]["ProductionLineID"].ToString();
- }
- else
- {
- _productionLineCode += "," + _frmProductionLine.dataDT.Rows[i]["ProductionLineCode"].ToString();
- _productionLineName += "," + _frmProductionLine.dataDT.Rows[i]["ProductionLineName"].ToString();
- _productionLineIDS += "," + _frmProductionLine.dataDT.Rows[i]["ProductionLineID"].ToString();
- }
- }
- }
- this.Text = _productionLineName;
- }
- }
- else
- {
- if (_frmProductionLine.ProductionLineRow != null)
- {
- _productionLineID = Convert.ToInt32(_frmProductionLine.ProductionLineRow["ProductionLineID"]);
- _productionLineCode = _frmProductionLine.ProductionLineRow["ProductionLineCode"].ToString();
- _productionLineName = _frmProductionLine.ProductionLineRow["ProductionLineName"].ToString();
- this.Text = _frmProductionLine.ProductionLineRow["ProductionLineName"].ToString();
- }
- }
- }
- }
- private void txtProductionLineName_TextChanged(object sender, EventArgs e)
- {
- if (ProductionLineValueChanged != null)
- {
- ProductionLineValueChanged(this, new TextChangeEventArgs(this.txtProductionLineName.Text));
- }
- }
- public class TextChangeEventArgs : EventArgs
- {
- public TextChangeEventArgs(string message)
- {
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
- /// </summary>
- protected void AdjustControl()
- {
- // 取得按钮控件的宽度和高度
- int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
- this.Height = this.btnSearch.Height;
- // 设置控件的尺寸和位置。
- this.txtProductionLineName.Location = new System.Drawing.Point(this.lblProductionLineName.Width +
- ControlsConst.CONTROLSPACE, (this.Height - this.txtProductionLineName.Height) / 2);
- this.txtProductionLineName.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
- (this.lblProductionLineName.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.lblProductionLineName.Location =
- new System.Drawing.Point(0, (this.Height - this.lblProductionLineName.Height) / 2);
- this.lblProductionLineName.Size = new System.Drawing.Size(this.lblProductionLineName.Width, this.lblProductionLineName.Height);
- }
- /// <summary>
- /// 清空控件的值
- /// </summary>
- /// <param name="dataSource"></param>
- /// <returns></returns>
- public void ClearControl()
- {
- this.txtProductionLineName.Text = string.Empty;
- this._productionLineID = null;
- this._productionLineName = string.Empty;
- this._productionLineCode = string.Empty;
- this._productionLineIDS = string.Empty;
- }
- #endregion
- }
- }
|