/*******************************************************************************
* Copyright(c) 2012 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:S_CMN_018.cs
* 2.功能描述:工种控件查询界面
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈冰 2014/11/4 1.0 新建
*******************************************************************************/
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;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.Controls
{
///
/// 工种控件查询界面
///
public partial class S_CMN_018 : FormBase
{
#region 成员变量
private DataTable _dataSource; // 画面的数据源
#endregion
#region 构造函数
///
/// 重载的构造函数
///
public S_CMN_018()
{
InitializeComponent();
// 按钮
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 属性
///
/// 选择的数据
///
public DataTable SelTable { get; set; }
///
/// 传入的工种编码
///
public string SetJobsCode { get; set; }
///
/// 获取或者设定画面的数据源。
///
[Description("获取或者设定画面的数据源。")]
public new DataTable DataSource
{
get
{
return _dataSource;
}
set
{
_dataSource = value;
}
}
#endregion
#region 控件事件
///
/// 窗体加载
///
///
///
private void S_CMN_018_Load(object sender, EventArgs e)
{
try
{
this.dgvJobs.AutoGenerateColumns = false;
this.txtJobsCode.Text = SetJobsCode;
if (!string.IsNullOrEmpty(this.txtJobsCode.Text))
{
Search();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查询按钮按下事件
///
///
///
private void btnSearch_Click(object sender, System.EventArgs e)
{
try
{
Search();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// KeyDown事件
///
///
///
private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
{
try
{
// 拷贝单元格文本到剪切板
if (e.KeyData == (Keys.Control | Keys.C))
{
if (dgvJobs.CurrentRow != null
&& !string.IsNullOrEmpty(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
{
Clipboard.SetText(dgvJobs.CurrentRow.Cells[dgvJobs.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);
}
}
///
/// 确定按钮按下事件
///
///
///
private void btnOK_Click(object sender, System.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, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
///
/// 双击DataGridView窗体,返回选中记录
///
///
///
private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
// 判断是否是双击列头,如果是双击列头的话,不做任何操作
if (-1 < e.RowIndex && -1 < e.ColumnIndex)
{
Commit();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 全选
///
///
///
private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
{
try
{
for (int i = 0; i < this.dgvJobs.Rows.Count; i++)
{
this.dgvJobs.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 查询方法
///
private void Search()
{
// 清空之前的查询结果
this.dgvJobs.DataSource = null;
if (_dataSource == null)
{
DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetJobsData(1);
}));
if (defectds != null
&& defectds.Tables.Count > Constant.INT_IS_ZERO
&& defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
_dataSource = defectds.Tables[0].DefaultView.ToTable();
}
}
if (_dataSource != null)
{
_dataSource.DefaultView.RowFilter = GetFilterExpression();
this.dgvJobs.DataSource = _dataSource.DefaultView.ToTable();
this.dgvJobs.Focus();
}
// 当没有查询结果时,提示无查询结构消息
if (this.dgvJobs.RowCount <= 0)
{
MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.txtJobsCode.Focus();
this.btnOK.Enabled = false;
return;
}
this.btnOK.Enabled = true;
}
///
/// 提交时给取得的行赋值
///
private void Commit()
{
try
{
DataTable invDt = (DataTable)this.dgvJobs.DataSource;
if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
invDt.AcceptChanges();
invDt = invDt.Copy();
string filter = "Sel = 1";
invDt.DefaultView.RowFilter = filter;
invDt = invDt.DefaultView.ToTable();
// 如果选中了数据就关闭窗体,反之则不关
if (invDt.Rows.Count > 0)
{
SelTable = invDt;
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据画面输入内容拼接过滤条件
///
///
private string GetFilterExpression()
{
StringBuilder strbFilterExpressions = new StringBuilder();
strbFilterExpressions.Append("(1=1");
if (!string.IsNullOrEmpty(this.txtJobsCode.Text))
{
// 工种编码条件
strbFilterExpressions.Append(string.Format(" AND JobsCode LIKE '%{0}%'",
Utility.SelectFilterLike(this.txtJobsCode.Text.Trim())));
}
if (!string.IsNullOrEmpty(this.txtJobsName.Text))
{
// 工种名称条件
strbFilterExpressions.Append(string.Format(" AND JobsName LIKE '%{0}%'",
Utility.SelectFilterLike(this.txtJobsName.Text.Trim())));
}
strbFilterExpressions.Append(")");
return strbFilterExpressions.ToString();
}
#endregion
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtJobsCode.Clear();
this.txtJobsName.Clear();
}
}
}