/*******************************************************************************
* Copyright(c) 2012 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_SelectGoods.cs
* 2.功能描述:产品查询界面
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈冰 2014/09/15 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
{
///
/// 产品查询界面
///
public partial class F_SelectGoods : FormBase
{
#region 构造函数
public F_SelectGoods()
{
InitializeComponent();
this.btnOK.Text = ButtonText.BTN_OK;
this.btnClose.Text = ButtonText.BTN_CANCEL;
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
}
#endregion
#region 属性
///
/// 选择的数据
///
public DataTable SelTable { get; set; }
///
/// 转入的产品编码
///
public string SetGoodsCode { get; set; }
#endregion
#region 事件
///
/// 页面加载
///
///
///
private void SelectProduct_Load(object sender, EventArgs e)
{
try
{
// 设置表格不自动创建列
this.dgvGoods.AutoGenerateColumns = false;
// 加载页面所需的数据源
LoadDataSource();
this.txtGoodsCode.Text = this.SetGoodsCode;
btnSearch_Click(null, null);
// 编辑单元格的颜色
this.dgvGoods.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查询
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
GoodsEntity goods = new GoodsEntity();
//goods.CeaseFlag = 0;
goods.ValueFlag = 1;
if (!string.IsNullOrEmpty(this.txtGoodsCode.Text.Trim()))
{
goods.GoodsCode = this.txtGoodsCode.Text.Trim();
}
if (!string.IsNullOrEmpty(this.txtGoodsName.Text.Trim()))
{
goods.GoodsName = this.txtGoodsName.Text.Trim();
}
if (!string.IsNullOrEmpty(this.txtGoodsSpecification.Text.Trim()))
{
goods.GoodsSpecification = this.txtGoodsSpecification.Text.Trim();
}
if (!string.IsNullOrEmpty(scbGoodsType.SearchedValue + ""))
{
goods.GoodsTypeCode = scbGoodsType.SearchedValue + "";
}
if (!string.IsNullOrEmpty(this.txtGoodsModel.Text.Trim()))
{
goods.GoodsModel = this.txtGoodsModel.Text.Trim();
}
if (this.ddlGlazeTypeID.SelectedValue != null && this.ddlGlazeTypeID.SelectedValue + "" != "")
{
goods.GlazeTypeID = Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
}
// 查询
DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.SerachGoods(goods);
}));
if (ds != null
&& ds.Tables.Count > 0
&& ds.Tables[0].Rows.Count > 0)
{
this.dgvGoods.DataSource = ds.Tables[0];
// 取消全选
this.chkChooseAll.Checked = false;
this.dgvGoods.CurrentCell = this.dgvGoods.Rows[0].Cells["Sel"];
this.dgvGoods.Columns["Sel"].ReadOnly = false;
}
else
{
// 清空数据
this.dgvGoods.DataSource = null;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
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();
}
///
/// 全选
///
///
///
private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.dgvGoods.Rows.Count; i++)
{
this.dgvGoods.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
}
}
///
/// 选中产品
///
///
///
private void dgvGoods_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
// 点击的是选中列
if (e.ColumnIndex != -1 && e.RowIndex != -1)
{
if (this.dgvGoods.Columns[e.ColumnIndex].Name == "Sel")
{
int value = int.Parse(this.dgvGoods.Rows[e.RowIndex].Cells["Sel"].Value.ToString());
this.dgvGoods.Rows[e.RowIndex].Cells["Sel"].Value = value == Constant.INT_IS_ONE ? Constant.INT_IS_ZERO : Constant.INT_IS_ONE;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 清空条件
///
///
///
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtGoodsCode.Text = "";
this.txtGoodsName.Text = "";
this.txtGoodsSpecification.Text = "";
this.scbGoodsType.ClearValue();
this.txtGoodsModel.Text = "";
this.ddlGlazeTypeID.SelectedIndex = 0;
}
#endregion
#region 私有方法
///
/// 加载页面所需的数据源
///
private void LoadDataSource()
{
try
{
// 绑定釉料类别
DataTable dt = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, 1);
if (dt != null)
{
DataRow row = dt.NewRow();
row["DictionaryValue"] = "";
row["DictionaryID"] = DBNull.Value;
dt.Rows.InsertAt(row, 0);
ddlGlazeTypeID.DisplayMember = "DictionaryValue";
ddlGlazeTypeID.ValueMember = "DictionaryID";
ddlGlazeTypeID.DataSource = dt;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 点击确定或者回车键时调用
///
private void Commit()
{
try
{
DataTable invDt = (DataTable)this.dgvGoods.DataSource;
if (invDt == null || invDt.Rows.Count == 0)
{
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;
}
}
#endregion
}
}