/*******************************************************************************
* Copyright(c) 2012 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:S_CMN_022.cs
* 2.功能描述:缺陷类别控件查询界面
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/06/13 1.00 新建
*******************************************************************************/
using System;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Client.CommonModule;
namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
{
public partial class S_CMN_022 : FormBase
{
#region 成员变量
private DataTable _dataSource; // 画面的数据源
private DataRow _productionLineRow; // 返回类别的DataRow
private DataTable _dataDT; //返回选择数据源
#endregion
#region 构造函数
///
/// 构造函数
///
/// 多选标记
public S_CMN_022(int flag)
{
InitializeComponent();
if (flag == 1)
{
this.Sel.Visible = true;
}
else
{
this.Sel.Visible = false;
}
// 按钮
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnOK.Text = ButtonText.BTN_OK;
this.btnClose.Text = ButtonText.BTN_CANCEL;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
}
#endregion
#region 属性
///
/// 获取或者设定画面的数据源。
///
[Description("获取或者设定画面的数据源。")]
public new DataTable DataSource
{
get
{
return _dataSource;
}
set
{
_dataSource = value;
}
}
///
/// 传入的类别名称
///
public string SetDefectTypeName
{
get;
set;
}
///
/// 选择的数据
///
public DataTable SelTable
{
get;
set;
}
///
/// 返回选择的组织行
///
public DataRow ProductionLineRow
{
get
{
return _productionLineRow;
}
set
{
_productionLineRow = value;
}
}
///
/// 返回选择的组织多行
///
public DataTable dataDT
{
get
{
return _dataDT;
}
set
{
_dataDT = value;
}
}
#endregion
#region 事件
///
/// 窗体加载
///
///
///
private void S_CMN_022_Load(object sender, EventArgs e)
{
try
{
this.dgvDefectTypeName.AutoGenerateColumns = false;
this.txtDefectTypeName.Text = SetDefectTypeName;
if (!string.IsNullOrEmpty(this.txtDefectTypeName.Text))
{
Search();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查询按钮按下事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
Search();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 确定按钮按下事件
///
///
///
private void btnOK_Click(object sender, EventArgs e)
{
try
{
Commit();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 关闭按钮按下事件
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
///
/// KeyDown事件
///
///
///
private void dgvProductionLine_KeyDown(object sender, KeyEventArgs e)
{
try
{
// 拷贝单元格文本到剪切板
if (e.KeyData == (Keys.Control | Keys.C))
{
if (this.dgvDefectTypeName.CurrentRow != null
&& !string.IsNullOrEmpty(dgvDefectTypeName.CurrentRow.Cells[dgvDefectTypeName.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
{
Clipboard.SetText(dgvDefectTypeName.CurrentRow.Cells[dgvDefectTypeName.CurrentCell.ColumnIndex].EditedFormattedValue + "");
}
}
else if (e.KeyData == Keys.Enter)
{
Commit();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 双击DataGridView窗体,返回选中记录
///
///
///
private void dgvProductionLine_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
// 判断是否是双击列头,如果是双击列头的话,不做任何操作
if (-1 < e.RowIndex && -1 < e.ColumnIndex)
{
//判断有没有复选框,如果有不做任何操作
if (!this.Sel.Visible)
{
Commit();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 查询方法
///
private void Search()
{
// 清空之前的查询结果
this.dgvDefectTypeName.DataSource = null;
// 根据查询条件查询数据源中的数据,并显示
DataTable ProductionLineTable = this.DataSource.Copy();
ProductionLineTable.DefaultView.RowFilter = GetFilterExpression();
this.dgvDefectTypeName.DataSource = ProductionLineTable.DefaultView.ToTable();
this.dgvDefectTypeName.Focus();
// 当没有查询结果时,提示无查询结构消息
if (this.dgvDefectTypeName.RowCount <= 0)
{
MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.txtDefectTypeName.Focus();
this.btnOK.Enabled = false;
return;
}
this.btnOK.Enabled = true;
}
///
/// 提交时给取得的行赋值
///
private void Commit()
{
if (this.Sel.Visible)
{
if (this.dgvDefectTypeName.CurrentCell != null)
{
this.dataDT = (DataTable)this.dgvDefectTypeName.DataSource;
this.DialogResult = DialogResult.OK;
}
}
else
{
if (this.dgvDefectTypeName.CurrentCell != null)
{
ProductionLineRow = this.dgvDefectTypeName.GetDataRow(this.dgvDefectTypeName.CurrentCell.RowIndex);
this.DialogResult = DialogResult.OK;
}
}
this.Close();
}
///
/// 根据画面输入内容拼接过滤条件
///
///
private string GetFilterExpression()
{
StringBuilder strbFilterExpressions = new StringBuilder();
strbFilterExpressions.Append("(1=1");
if (!string.IsNullOrEmpty(this.txtDefectTypeName.Text))
{
// 产品类别编码条件
strbFilterExpressions.Append(string.Format(" AND DefectTypeName LIKE '%{0}%'",
Utility.SelectFilterLike(this.txtDefectTypeName.Text.Trim())));
}
strbFilterExpressions.Append(")");
return strbFilterExpressions.ToString();
}
#endregion
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtDefectTypeName.Clear();
}
}
}