/******************************************************************************* * Copyright(c) 2014 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:dkGroutingLineSearchBox.cs * 2.功能描述:成型线选择控件 * 编辑履历: * 作者 日期 版本 修改内容 * 庄天威 2014/09/17 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.PCModuleService; namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox { /// /// 成型线选择控件 /// public partial class dkGroutingLineSearchBox : UserControl { #region 成员变量 private S_CMN_009 _frmGroutingLine; private bool _isEnabled = true; // 控件是否可用 private DataTable _dataSource = null; // 数据源 private int? _groutingLineID; // 成型线类型ID private string _groutingLineIDS; //id集 private string _groutingLineCode; // 成型线类型Code private string _groutingLineName; // 成型线类型名称 private int? _userId; private string _userCode; private string _userName; private int _mouldQuantity; //模具个数 private int _mouldTypeID; //成型线类型 private int _mouldStatus; //成型线状态 private int _isCanmanytimes; //是否可多次注浆 private DateTime? _groutingDate; //注浆日期 private bool _isMustInput; // 控件是否是必须输入项目 private bool _IsOnlyShowValid = true; // 是否只显示有效数据 private bool _noGroutingFlag = false; //是否启用未注浆原因列 private string _NoGroutLineId; //未注浆线Id组 private string _NoGroutingRreasons; //未注浆原因值组 private DateTime _opTimeStamp; private string _purview; public List _plList = new List(); #endregion #region 构造函数 public dkGroutingLineSearchBox() { 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.lblGroutingLine.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39))))); } else { this.lblGroutingLine.ForeColor = System.Drawing.SystemColors.ControlText; } } } [Description("获取或者设定Lable标签字符。")] public string Title { get { return this.lblGroutingLine.Text; } set { this.lblGroutingLine.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.txtGroutingLine.Text; } set { this.txtGroutingLine.Text = value; } } /// /// 获取或者设定控件的文本框的背景颜色。 /// [Description("获取或者设定控件的文本框的背景颜色。")] public Color TxtMouldTypeBackColor { get { return this.txtGroutingLine.BackColor; } set { this.txtGroutingLine.BackColor = value; } } /// /// 获取或者设定控件的成型线ID。 /// [Description("获取或者设定控件的成型线ID。")] public int? GroutingLineID { get { return _groutingLineID; } set { _groutingLineID = value; if (_groutingLineID != null && _groutingLineID != 0 && this.DataSource != null) { DataTable mouldTypeTable = this.DataSource.Copy(); DataRow[] dataRows = mouldTypeTable.Select("GroutingLineID = " + this._groutingLineID); if (dataRows.Length == 1) { this.GroutingLineCode = dataRows[0]["GroutingLineCode"] as string; this.Text = dataRows[0]["GroutingLineName"] as string; } } if (_groutingLineID == null) { this.Text = string.Empty; GroutingLineCode = string.Empty; GroutingLineName = string.Empty; } } } /// /// 获取或者设定控件的成型线id集 /// [Description("获取或者设定控件的成型线id集。")] public string GroutingLineIDS { get { return _groutingLineIDS; } set { _groutingLineIDS = value; } } /// /// 获取或者设定控件的成型线Code /// [Description("获取或者设定控件的成型线Code。")] public string GroutingLineCode { get { return _groutingLineCode; } set { _groutingLineCode = value; } } /// /// 获取或者设定控件的成型线名称 /// [Description("获取或者设定控件的成型线名称。")] public string GroutingLineName { get { return _groutingLineName; } set { _groutingLineName = value; } } /// /// 获取或者设定控件的是否可多次注浆 /// [Description("获取或者设定控件的是否可多次注浆。")] public int IsCanmanytimes { get { return _isCanmanytimes; } set { _isCanmanytimes = value; } } /// /// 获取或者设定该成型线的工号ID /// [Description("获取或者设定该成型线的工号ID。")] public int? UserId { get { return _userId; } set { _userId = value; } } /// /// 获取或者设定该成型线的工号编码 /// [Description("获取或者设定该成型线的工号编码。")] public string UserCode { get { return _userCode; } set { _userCode = value; } } /// /// 获取或者设定该成型线的工号名称 /// [Description("获取或者设定该成型线的工号名称。")] public string UserName { get { return _userName; } set { _userName = value; } } /// /// 获取或者设定控件是否可用。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否可用。")] public new bool Enabled { get { return _isEnabled; } set { _isEnabled = value; this.txtGroutingLine.Enabled = _isEnabled; this.TabStop = _isEnabled; } } /// /// 获取或者设定控件是否只读。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否只读。")] public bool ReadOnly { set { this.txtGroutingLine.ReadOnly = value; } } /// /// 获取或者设定成型线模具个数。 /// [Description("获取或者设定成型线模具个数。")] public int MouldQuantity { get { return _mouldQuantity; } set { _mouldQuantity = value; } } /// /// 获取或者设定成型线类别。 /// [Description("获取或者设定成型线类别。")] public int GMouldTypeID { get { return _mouldTypeID; } set { _mouldTypeID = value; } } /// /// 范围权限 /// public string Purview { get { return _purview; } set { _purview = value; } } public bool NoGroutingFlag { get { return _noGroutingFlag; } set { _noGroutingFlag = value; } } public string NoGroutingId { get { return _NoGroutLineId; } } public string NoGroutingRreasons { get { return _NoGroutingRreasons; } } /// /// 注浆日期 /// public DateTime? GroutingDate { get { return _groutingDate; } set { _groutingDate = value; } } public int GMouldStatus { get { return _mouldStatus; } set { _mouldStatus = value; } } public DateTime OPTimeStamp { get { return _opTimeStamp; } set { _opTimeStamp = value; } } /// /// 多选。 /// [System.ComponentModel.DefaultValue(false)] [Description("多选。")] public bool SelectMore { get; set; } /// /// 查看权限属性 /// [System.ComponentModel.DefaultValue(false)] [Description("查看权限属性")] public bool Ispurview { get; set; } public int? BindBarCode { get; set; } /// /// 是否启用权限功能 /// [System.ComponentModel.DefaultValue(true)] [Description("是否启用权限功能")] public bool IsEnablePurview { get; set; } public DateTime? BindBarCodeTime { get; set; } public DateTime? BindBarCodeTimeEnd { 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 dkGroutingLineSearchBox_SizeChanged(object sender, System.EventArgs e) { AdjustControl(); } /// /// 查询按钮按下事件 /// /// /// private void btnSearch_Click(object sender, System.EventArgs e) { // 如果属性是不可用,是不能进行点击事件的 if (!Enabled) { return; } // 当数据源为null时,查询数据源 if (DataSource == null) { GroutingLineEntity GLEntity = new GroutingLineEntity(); if (IsEnablePurview) { if (_purview == null) { if (this.Ispurview) { MessageBox.Show(Messages.MSG_CMN_W025, this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1); return; } else { MessageBox.Show(Messages.MSG_PM_W009, this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1); return; } } //赋值权限 GLEntity.GROUTINGLINEIDS = "-999";// _purview; } GLEntity.BEGINUSEDDATEEND = _groutingDate; if (_groutingDate != null) { GLEntity.DailyTime = Convert.ToDateTime(_groutingDate); } if(BindBarCode != null) { GLEntity.isYZJ = 1; GLEntity.BindBarCodeTime = BindBarCodeTime; GLEntity.BindBarCodeTimeEnd = BindBarCodeTimeEnd; } // 查询数据源 DataSource = PCModuleProxy.Service.GetGroutingLine(GLEntity).Tables[0]; } // 释放窗体资源 if (null != _frmGroutingLine) { _frmGroutingLine.Dispose(); _frmGroutingLine = null; } // 打开查询窗体 if (this.SelectMore) { if (this.NoGroutingFlag == false) { _frmGroutingLine = new S_CMN_009(1); } else { _frmGroutingLine = new S_CMN_009(1, 1); } } else { _frmGroutingLine = new S_CMN_009(); } _frmGroutingLine.DataSource = this.DataSource; DialogResult dialogResult = _frmGroutingLine.ShowDialog(); // 查询窗体返回值给控件赋值 if (dialogResult.Equals(DialogResult.OK)) { if (this.SelectMore) { _groutingLineCode = string.Empty; _groutingLineName = string.Empty; _groutingLineIDS = string.Empty; _NoGroutLineId = string.Empty; _NoGroutingRreasons = string.Empty; if (_frmGroutingLine.dataDT.Rows.Count > 0 || _frmGroutingLine.DataRow != null) { for (int i = 0; i < _frmGroutingLine.dataDT.Rows.Count; i++) { if (_frmGroutingLine.dataDT.Rows[i]["sel"].ToString().Equals("1")) { if (string.IsNullOrEmpty(_groutingLineCode)) { _groutingLineCode = _frmGroutingLine.dataDT.Rows[i]["GroutingLineCode"].ToString(); _groutingLineName = _frmGroutingLine.dataDT.Rows[i]["GroutingLineName"].ToString(); _groutingLineIDS = _frmGroutingLine.dataDT.Rows[i]["GroutingLineID"].ToString(); } else { _groutingLineCode += "," + _frmGroutingLine.dataDT.Rows[i]["GroutingLineCode"].ToString(); _groutingLineName += "," + _frmGroutingLine.dataDT.Rows[i]["GroutingLineName"].ToString(); _groutingLineIDS += "," + _frmGroutingLine.dataDT.Rows[i]["GroutingLineID"].ToString(); } if (_frmGroutingLine.dataDT.Rows[i]["NoGroutingRreason"].ToString() != "-1") { _NoGroutLineId += _frmGroutingLine.dataDT.Rows[i]["GroutingLineID"].ToString() + ","; _NoGroutingRreasons += _frmGroutingLine.dataDT.Rows[i]["NoGroutingRreason"].ToString() + ","; } } } this.Text = _groutingLineCode; if(_NoGroutLineId.Length != 0) { _NoGroutLineId = _NoGroutLineId.Substring(0, _NoGroutLineId.Length - 1); _NoGroutingRreasons = _NoGroutingRreasons.Substring(0, _NoGroutingRreasons.Length - 1); } } } else { if (_frmGroutingLine.DataRow != null) { _groutingLineID = Convert.ToInt32(_frmGroutingLine.DataRow["GroutingLineID"]); _groutingLineCode = _frmGroutingLine.DataRow["GroutingLineCode"].ToString(); _groutingLineName = _frmGroutingLine.DataRow["GroutingLineName"].ToString(); _isCanmanytimes = Convert.ToInt32(_frmGroutingLine.DataRow["CANMANYTIMES"]); _mouldQuantity = Convert.ToInt32(_frmGroutingLine.DataRow["MouldQuantity"]); _mouldTypeID = Convert.ToInt32(_frmGroutingLine.DataRow["GMouldTypeID"]); _userId = Convert.ToInt32(_frmGroutingLine.DataRow["UserId"]); _userName = _frmGroutingLine.DataRow["UserName"].ToString(); _userCode = _frmGroutingLine.DataRow["UserCode"].ToString(); _mouldStatus = Convert.ToInt32(_frmGroutingLine.DataRow["GMouldStatus"]); _opTimeStamp = Convert.ToDateTime(_frmGroutingLine.DataRow["OPTimeStamp"]); this.Text = _frmGroutingLine.DataRow["GroutingLineCode"].ToString(); } } } } /// /// 清除控件的值 /// /// /// private void txtGroutingLine_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { ClearControl(); } } private void txtGroutingLine_TextChanged(object sender, EventArgs e) { if (MouldTypeValueChanged != null) { MouldTypeValueChanged(this, new TextChangeEventArgs(this.txtGroutingLine.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.txtGroutingLine.Location = new System.Drawing.Point(this.lblGroutingLine.Width + ControlsConst.CONTROLSPACE, (this.Height - this.txtGroutingLine.Height) / 2); this.txtGroutingLine.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width - (this.lblGroutingLine.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.lblGroutingLine.Location = new System.Drawing.Point(0, (this.Height - this.lblGroutingLine.Height) / 2); this.lblGroutingLine.Size = new System.Drawing.Size(this.lblGroutingLine.Width, this.lblGroutingLine.Height); } /// /// 清空控件的值 /// /// /// public void ClearControl() { this.txtGroutingLine.Text = ""; this._groutingLineID = null; this._groutingLineIDS = string.Empty; this._groutingLineCode = string.Empty; this._groutingLineName = 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; } public void DataSourseBind() { GroutingLineEntity GLEntity = new GroutingLineEntity(); GLEntity.GROUTINGLINEIDS = _purview; // 查询数据源 DataSource = PCModuleProxy.Service.GetGroutingLine(GLEntity).Tables[0]; } #endregion } }