| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:dkInChecked.cs
- * 2.功能描述:盘点选择控件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2014/09/15 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.Client.Controls.FormCommon;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox
- {
- public partial class dkInChecked : UserControl
- {
- #region 成员变量
- /// <summary>
- /// 数据选择窗体
- /// </summary>
- private S_CMN_021 _frmInChecked;
- /// <summary>
- /// 控件是否可用
- /// </summary>
- private bool _isEnabled = true;
- /// <summary>
- /// 数据源
- /// </summary>
- private DataTable _dataSource = null;
- /// <summary>
- /// 盘点单ID
- /// </summary>
- private int? _inCheckedID;
- /// <summary>
- /// 盘点单号
- /// </summary>
- private string _inCheckedNo;
- /// <summary>
- /// 控件是否是必须输入项目
- /// </summary>
- private bool _isMustInput;
- /// <summary>
- /// 是否只显示有效数据
- /// </summary>
- private bool _IsOnlyShowValid = true;
- #endregion
- #region 构造函数
- public dkInChecked()
- {
- 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.lblPost.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
- }
- else
- {
- this.lblPost.ForeColor = System.Drawing.SystemColors.ControlText;
- }
- }
- }
- /// <summary>
- /// Lable标签文本
- /// </summary>
- [DefaultValue("工种名称")]
- [Description("获取或者设定Lable标签字符。")]
- public string Title
- {
- get
- {
- return this.lblPost.Text;
- }
- set
- {
- this.lblPost.Text = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定控件的数据源。
- /// </summary>
- [Description("获取或者设定控件的数据源。")]
- public DataTable DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- DataTable dataSource = SetFilter(value);
- _dataSource = dataSource;
- }
- }
- /// <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.txtJobs.Text;
- }
- set
- {
- this.txtJobs.Text = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的文本框的背景颜色。
- /// </summary>
- [Description("获取或者设定控件的文本框的背景颜色。")]
- public Color TxtUserBackColor
- {
- get
- {
- return this.txtJobs.BackColor;
- }
- set
- {
- this.txtJobs.BackColor = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的职务ID。
- /// </summary>
- [Description("获取或者设定控件的职务ID。")]
- [DefaultValue(null)]
- public int? InCheckedID
- {
- get
- {
- return _inCheckedID;
- }
- set
- {
- this._inCheckedID = null;
- this._inCheckedNo = string.Empty;
- this.Text = string.Empty;
- if (value != null)
- {
- // 当数据源为null时,查询数据源
- if (DataSource == null)
- {
- // 查询数据源
- DataSource = GetInChecked();
- }
- if (value != null && value != 0 && this.DataSource != null)
- {
- DataTable userTable = this.DataSource.Copy();
- DataRow[] dataRows = userTable.Select("InCheckedID = " + value);
- if (dataRows.Length == 1)
- {
- this._inCheckedID = value;
- this._inCheckedNo = dataRows[0]["InCheckedNo"] as string;
- this.Text = dataRows[0]["InCheckedNo"] as string;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或者设定控件的盘点单号
- /// </summary>
- [Description("获取或者设定控件的盘点单号。")]
- public string InCheckedNo
- {
- get
- {
- return _inCheckedNo;
- }
- set
- {
- _inCheckedNo = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否可用。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否可用。")]
- public new bool Enabled
- {
- get
- {
- return _isEnabled;
- }
- set
- {
- _isEnabled = value;
- this.txtJobs.Enabled = _isEnabled;
- this.TabStop = _isEnabled;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否只读。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否只读。")]
- public bool ReadOnly
- {
- set
- {
- this.txtJobs.ReadOnly = value;
- }
- }
- /// <summary>
- /// 范围权限
- /// </summary>
- public byte PurviewType
- {
- get;
- set;
- }
- /// <summary>
- /// 盘点类型 0:在产盘点 1:注浆盘点 2:模具盘点
- /// </summary>
- [System.ComponentModel.DefaultValue(0)]
- public int CheckType
- {
- get;
- set;
- }
- #endregion
- #region 定义委托事件
- public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
- public event TextBoxChangedHandle UserValueChanged;
- #endregion
- #region 控件事件
- public class TextChangeEventArgs : EventArgs
- {
- public TextChangeEventArgs(string message)
- {
- }
- }
- /// <summary>
- /// 控件尺寸大小改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dkJobsSearchBox_SizeChanged(object sender, EventArgs e)
- {
- AdjustControl();
- }
- /// <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)
- {
- // 查询数据源
- DataSource = GetInChecked();
- }
- // 释放窗体资源
- if (null != _frmInChecked)
- {
- _frmInChecked.Dispose();
- _frmInChecked = null;
- }
- // 打开查询窗体
- _frmInChecked = new S_CMN_021();
- _frmInChecked.DataSource = this.DataSource;
- DialogResult dialogResult = _frmInChecked.ShowDialog();
- // 查询窗体返回值给控件赋值
- if (dialogResult.Equals(DialogResult.OK))
- {
- if (_frmInChecked.DataRow != null)
- {
- _inCheckedID = Convert.ToInt32(_frmInChecked.DataRow["InCheckedID"]);
- _inCheckedNo = _frmInChecked.DataRow["InCheckedNo"].ToString();
- this.Text = _frmInChecked.DataRow["InCheckedNo"].ToString();
- }
- }
- }
- /// <summary>
- /// 清除控件的值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtJobs_KeyDown(object sender, KeyEventArgs e)
- {
- this.txtJobs.Text = "";
- this._inCheckedID = null;
- this._inCheckedNo = string.Empty;
- }
- /// <summary>
- /// 文本框文本改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtJobs_TextChanged(object sender, EventArgs e)
- {
- if (UserValueChanged != null)
- {
- UserValueChanged(this, new TextChangeEventArgs(this.txtJobs.Text));
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 设置控件的样式
- /// </summary>
- protected void AdjustControl()
- {
- // 取得按钮控件的宽度和高度
- int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
- this.Height = this.btnSearch.Height;
- // 设置控件的尺寸和位置。
- this.txtJobs.Location = new System.Drawing.Point(this.lblPost.Width +
- ControlsConst.CONTROLSPACE, (this.Height - this.txtJobs.Height) / 2);
- this.txtJobs.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
- (this.lblPost.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.lblPost.Location =
- new System.Drawing.Point(0, (this.Height - this.lblPost.Height) / 2);
- this.lblPost.Size = new System.Drawing.Size(this.lblPost.Width, this.lblPost.Height);
- }
- /// <summary>
- /// 过滤数据源
- /// </summary>
- /// <param name="dataSource"></param>
- /// <returns></returns>
- protected DataTable SetFilter(DataTable dataSource)
- {
- return dataSource;
- }
- /// <summary>
- /// 调用服务方法获取用户信息
- /// </summary>
- /// <returns></returns>
- private DataTable GetInChecked()
- {
- DataSet userDataSet = null;
- if (CheckType == 0)
- {
- userDataSet = PMModuleProxy.Service.GetInCheckedList();
- }
- else if (CheckType == 1)
- {
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "GBChecked";
- cre.Name = "seachbox_GetList";
- ServiceResultEntity sre = PMModuleProxyNew.Service.HandleRequest(cre);
- if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
- {
- userDataSet = sre.Data;
- }
- }
- else if (CheckType == 2)
- {
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "FPC1101";
- cre.Name = "seachbox_GetList";
- ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
- if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
- {
- userDataSet = sre.Data;
- }
- }
- if (userDataSet == null)
- {
- return new DataTable();
- }
- if (userDataSet.Tables.Count <= 0)
- {
- return new DataTable();
- }
- return userDataSet.Tables[0];
- }
- #endregion
- }
- }
|