using System;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using WHC.Pager.Entity;
using WHC.OrderWater.Commons;
using WHC.Dictionary;
using WHC.TestProject.BLL;
using WHC.TestProject.Entity;
namespace WHC.TestProject.UI
{
public partial class FrmItemDetail : BaseDock
{
public FrmItemDetail()
{
InitializeComponent();
InitDictItem();
this .winGridViewPager1.OnPageChanged += new EventHandler(winGridViewPager1_OnPageChanged);
this .winGridViewPager1.OnStartExport += new EventHandler(winGridViewPager1_OnStartExport);
this .winGridViewPager1.OnEditSelected += new EventHandler(winGridViewPager1_OnEditSelected);
this .winGridViewPager1.OnAddNew += new EventHandler(winGridViewPager1_OnAddNew);
this .winGridViewPager1.OnDeleteSelected += new EventHandler(winGridViewPager1_OnDeleteSelected);
this .winGridViewPager1.OnRefresh += new EventHandler(winGridViewPager1_OnRefresh);
this .winGridViewPager1.AppendedMenu = this .contextMenuStrip1;
this .winGridViewPager1.ShowLineNumber = true ;
this .winGridViewPager1.dataGridView1.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
}
/// <summary>
/// 绑定数据后,分配各列的宽度
/// </summary>
void dataGridView1_DataBindingComplete( object sender, DataGridViewBindingCompleteEventArgs e)
{
if ( this .winGridViewPager1.dataGridView1.Columns.Count > 0 )
{
this .winGridViewPager1.dataGridView1.Columns[ " ID " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " ItemNo " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " ItemName " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Manufacture " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " MapNo " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Specification " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Material " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " ItemBigType " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " ItemType " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Unit " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Price " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Source " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " StoragePos " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " UsagePos " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Note " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " WareHouse " ].Width = 100 ;
this .winGridViewPager1.dataGridView1.Columns[ " Dept " ].Width = 100 ;
}
}
/// <summary>
/// 编写初始化窗体的实现,可以用于刷新
/// </summary>
public override void FormOnLoad()
{
BindData();
}
/// <summary>
/// 初始化字典列表内容
/// </summary>
private void InitDictItem()
{
// 初始化代码
}
/// <summary>
/// 分页控件刷新操作
/// </summary>
private void winGridViewPager1_OnRefresh( object sender, EventArgs e)
{
BindData();
}
/// <summary>
/// 分页控件删除操作
/// </summary>
private void winGridViewPager1_OnDeleteSelected( object sender, EventArgs e)
{
if (MessageUtil.ShowYesNoAndTips( " 您确定删除选定的记录么? " ) == DialogResult.No)
{
return ;
}
DataGridView grid = this .winGridViewPager1.dataGridView1;
if (grid != null )
{
foreach (DataGridViewRow row in grid.SelectedRows)
{
BLLFactory < ItemDetail > .Instance.Delete(row.Cells[ " ID " ].Value.ToString());
}
}
BindData();
}
/// <summary>
/// 分页控件编辑项操作
/// </summary>
private void winGridViewPager1_OnEditSelected( object sender, EventArgs e)
{
DataGridView grid = this .winGridViewPager1.dataGridView1;
if (grid.SelectedRows.Count == 0 ) return ;
string ID = grid.SelectedRows[ 0 ].Cells[ " ID " ].Value.ToString();
List < string > IDList = new List < string > ();
if (grid != null )
{
foreach (DataGridViewRow row in grid.Rows)
{
IDList.Add(row.Cells[ " ID " ].Value.ToString());
}
}
if ( ! string .IsNullOrEmpty(ID))
{
FrmEditItemDetail dlg = new FrmEditItemDetail();
dlg.ID = ID;
dlg.IDList = IDList;
if (DialogResult.OK == dlg.ShowDialog())
{
BindData();
}
}
}
/// <summary>
/// 分页控件新增操作
/// </summary>
private void winGridViewPager1_OnAddNew( object sender, EventArgs e)
{
btnAddNew_Click( null , null );
}
/// <summary>
/// 分页控件全部导出操作前的操作
/// </summary>
private void winGridViewPager1_OnStartExport( object sender, EventArgs e)
{
string where = GetConditionSql();
this .winGridViewPager1.AllToExport = BLLFactory < ItemDetail > .Instance.FindToDataTable( where );
}
/// <summary>
/// 分页控件翻页的操作
/// </summary>
private void winGridViewPager1_OnPageChanged( object sender, EventArgs e)
{
BindData();
}
/// <summary>
/// 根据查询条件构造查询语句
/// </summary>
private string GetConditionSql()
{
SearchCondition condition = new SearchCondition();
condition.AddCondition( " ItemNo " , this .txtItemNo.Text, SqlOperator.Like);
condition.AddCondition( " ItemName " , this .txtItemName.Text, SqlOperator.Like);
condition.AddCondition( " Manufacture " , this .txtManufacture.Text, SqlOperator.Like);
condition.AddCondition( " MapNo " , this .txtMapNo.Text, SqlOperator.Like);
condition.AddCondition( " Specification " , this .txtSpecification.Text, SqlOperator.Like);
condition.AddCondition( " Material " , this .txtMaterial.Text, SqlOperator.Like);
condition.AddCondition( " ItemBigType " , this .txtItemBigType.Text, SqlOperator.Like);
condition.AddCondition( " ItemType " , this .txtItemType.Text, SqlOperator.Like);
string where = condition.BuildConditionSql(DatabaseType.SqlServer).Replace( " Where " , "" );
return where ;
}
/// <summary>
/// 绑定列表数据
/// </summary>
private void BindData()
{
this .winGridViewPager1.DisplayColumns = " ID,ItemNo,ItemName,Manufacture,MapNo,Specification,Material,ItemBigType,ItemType,Unit,Price,Source,StoragePos,UsagePos,Note,WareHouse,Dept " ;
#region 添加别名解析
this .winGridViewPager1.AddColumnAlias( " ID " , " ID " );
this .winGridViewPager1.AddColumnAlias( " ItemNo " , " 备件编号 " );
this .winGridViewPager1.AddColumnAlias( " ItemName " , " 备件名称 " );
this .winGridViewPager1.AddColumnAlias( " Manufacture " , " 供货商 " );
this .winGridViewPager1.AddColumnAlias( " MapNo " , " 图号 " );
this .winGridViewPager1.AddColumnAlias( " Specification " , " 规格型号 " );
this .winGridViewPager1.AddColumnAlias( " Material " , " 材质 " );
this .winGridViewPager1.AddColumnAlias( " ItemBigType " , " 备件属类 " );
this .winGridViewPager1.AddColumnAlias( " ItemType " , " 备件类别 " );
this .winGridViewPager1.AddColumnAlias( " Unit " , " 单位 " );
this .winGridViewPager1.AddColumnAlias( " Price " , " 单价 " );
this .winGridViewPager1.AddColumnAlias( " Source " , " 来源 " );
this .winGridViewPager1.AddColumnAlias( " StoragePos " , " 库位 " );
this .winGridViewPager1.AddColumnAlias( " UsagePos " , " 使用位置 " );
this .winGridViewPager1.AddColumnAlias( " Note " , " 备注 " );
this .winGridViewPager1.AddColumnAlias( " WareHouse " , " 所属库房 " );
this .winGridViewPager1.AddColumnAlias( " Dept " , " 所属部门 " );
#endregion
string where = GetConditionSql();
List < ItemDetailInfo > list = BLLFactory < ItemDetail > .Instance.Find( where , this .winGridViewPager1.PagerInfo);
this .winGridViewPager1.DataSource = new WHC.Pager.WinControl.SortableBindingList < ItemDetailInfo > (list);
this .winGridViewPager1.PrintTitle = Portal.gc.gAppUnit + " -- " + " 信息报表 " ;
}
/// <summary>
/// 查询数据操作
/// </summary>
private void btnSearch_Click( object sender, EventArgs e)
{
BindData();
}
/// <summary>
/// 新增数据操作
/// </summary>
private void btnAddNew_Click( object sender, EventArgs e)
{
FrmEditItemDetail dlg = new FrmEditItemDetail();
if (DialogResult.OK == dlg.ShowDialog())
{
BindData();
}
}
/// <summary>
/// 提供给控件回车执行查询的操作
/// </summary>
private void SearchControl_KeyUp( object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnSearch_Click( null , null );
}
}
}
}