/*******************************************************************************
* Copyright(c) 2012 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:S_CMN_023.cs
* 2.功能描述:窑炉信息控件查询界面
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/09/10 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;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
{
public partial class S_CMN_023 : FormBase
{
#region 成员变量
// 单例模式
private static S_CMN_023 _instance;
// 最后选择行
private int _selecedRow;
#endregion
#region 属性
///
/// 选择的数据
///
public DataTable SelTable { get; set; }
///
/// 传入的窑炉编码
///
public string SetKilnCode { get; set; }
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static S_CMN_023 Instance
{
get
{
if (_instance == null)
{
_instance = new S_CMN_023();
}
return _instance;
}
}
#endregion
#region 构造函数
public S_CMN_023()
{
InitializeComponent();
this.Text ="窑炉选择";
this.btnSearch.Text = ButtonText.BTN_SEARCH;
//this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
this.btnOK.Text = ButtonText.BTN_OK;
this.btnClose.Text = ButtonText.BTN_CANCEL;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
}
#endregion
#region 事件
///
/// 窗体加载事件
///
///
///
private void FrmUser_Load(object sender, EventArgs e)
{
try
{
// 设置表格不自动创建列
this.dgvKiln.AutoGenerateColumns = false;
this.dgvKiln.Columns["Sel"].ReadOnly = false;
this.txtKilnCode.Text = this.SetKilnCode;
this.btnSearch_Click(null, null);
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 释放成员变量
///
///
///
private void FrmOrganization_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 搜索按钮事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
// 根据页面设定用户实体值
//this.GetUserEntityFromLayout();
// 记录当前选中行
int selectRowIndex = this._selecedRow;
// 异步处理
this.btnSearch.Enabled = false;
//this.btnClearCondition.Enabled = false;
DataSet userDataSet = (DataSet)DoAsync(new BaseAsyncMethod(this.SearchKilnData));
this.btnSearch.Enabled = true;
if (userDataSet != null)
{
string sql = null;
if (!string.IsNullOrWhiteSpace(this.txtKilnCode.Text))
{
sql = " kilncode like '%" + this.txtKilnCode.Text.Trim() + "%' ";
}
if (!string.IsNullOrWhiteSpace(this.txtKilnName.Text))
{
if (sql != null)
{
sql += " and ";
}
sql += " kilnname like '%" + this.txtKilnName.Text.Trim() + "%' ";
}
userDataSet.Tables[0].DefaultView.RowFilter = sql;
base.DataSource = (DataSet)userDataSet;
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
this.dgvKiln.DataSource = this.DataSource.Tables[0];
if (this.DataSource.Tables[0].DefaultView.Count <= Constant.INT_IS_ZERO)
{
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
//if (selectRowIndex >= Constant.INT_IS_ZERO)
//{
// if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
// {
// this.dgvKiln.Rows[this.dgvKiln.Rows.Count - 1].Selected = true;
// this.dgvKiln.CurrentCell = this.dgvKiln.Rows[this.dgvKiln.Rows.Count - 1].Cells["kilnCode"];
// }
// else
// {
// this.dgvKiln.Rows[selectRowIndex].Selected = true;
// this.dgvKiln.CurrentCell = this.dgvKiln.Rows[selectRowIndex].Cells["kilnCode"];
// }
//}
}
}
}
this.dgvKiln.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
this.btnSearch.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 选中行发生改变时 有效停用相互切换
///
///
///
private void dgvUser_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (dgvKiln.Rows.Count > Constant.INT_IS_ZERO)
{
this._selecedRow = this.dgvKiln.CurrentCell.RowIndex;
}
}
///
/// 窗体关闭事件
///
///
///
private void F_MST_0203_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 自动适应列宽事件
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvKiln.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 全选
///
///
///
private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
{
try
{
for (int i = 0; i < this.dgvKiln.Rows.Count; i++)
{
this.dgvKiln.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 确定
///
///
///
private void btnOK_Click(object sender, EventArgs e)
{
try
{
this.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.Close();
}
#endregion
#region 私有方法
///
/// 点击确定或者回车键时调用
///
private void Commit()
{
try
{
DataTable invDt = (DataTable)this.dgvKiln.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 > Constant.INT_IS_ZERO)
{
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 DataSet SearchKilnData()
{
try
{
return SystemModuleProxy.Service.GetKilnData(1);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtKilnCode.Clear();
this.txtKilnName.Clear();
}
}
}