423 lines
14 KiB
C#
423 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using WMS.Common;
|
|
|
|
namespace WMS.Ctrl
|
|
{
|
|
/// <summary>
|
|
/// 字典窗体
|
|
/// </summary>
|
|
public partial class FormDictonary : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
private List<ColumnsItem> frmClumn = new List<ColumnsItem>();
|
|
private readonly SystemItemDataInfo syetmInfo = new SystemItemDataInfo();
|
|
|
|
private string TextBoxVal = string.Empty;
|
|
|
|
private ComplexItems ShowColumns;
|
|
private List<ColumnsItem> UserColumns = new List<ColumnsItem>();
|
|
public DataTable tableSelect = new DataTable();
|
|
public bool m_isSqlWhere = false;
|
|
public string m_sqlStr = string.Empty;
|
|
public DataTable tableDictonary = new DataTable();
|
|
public string selSql = string.Empty;
|
|
public string txtKeyWordtext = string.Empty;
|
|
public string txtKeyWordCloum = string.Empty;
|
|
/// <summary>
|
|
///
|
|
/// 字典窗体
|
|
/// </summary>
|
|
public FormDictonary(ComplexItems showColumns, List<ColumnsItem> userColumns, DictonaryType dictonaryTableName,
|
|
DataSlectType selectType, string whereVal, bool isSqlWhere, string sqlStr,string selSql)
|
|
{
|
|
if (tableDictonary.Rows.Count > 0)
|
|
{
|
|
tableDictonary.Rows.Clear();
|
|
}
|
|
this.selSql = selSql;
|
|
ShowColumns = showColumns;
|
|
UserColumns = userColumns;
|
|
DictonaryTableName = dictonaryTableName;
|
|
SelectType = selectType;
|
|
m_isSqlWhere = isSqlWhere;
|
|
m_sqlStr = sqlStr;
|
|
TextBoxVal = whereVal;
|
|
string errText = SelectDataTable();
|
|
if (errText.Trim().Length > 0)
|
|
{
|
|
tableSelect = null;
|
|
tableDictonary = null;
|
|
}
|
|
if (tableDictonary != null)
|
|
{
|
|
if (tableDictonary.Rows.Count == 1)
|
|
{
|
|
tableSelect = tableDictonary.Copy();
|
|
this.Close();
|
|
return;
|
|
|
|
}
|
|
}
|
|
InitializeComponent();
|
|
|
|
AddGridColumn();
|
|
if (tableDictonary != null)
|
|
{
|
|
tableSelect = tableDictonary.Clone();
|
|
tableSelect.Rows.Clear();
|
|
if (tableDictonary.Rows.Count > 0)
|
|
{
|
|
gridControlItem.DataSource = tableDictonary;
|
|
|
|
txtKeyWord.Text = TextBoxVal;
|
|
gridViewItem.EndInit();
|
|
if (gridViewItem.RowCount > 0)
|
|
{
|
|
gridControlItem.Focus();
|
|
gridViewItem.Focus();
|
|
gridViewItem.FocusedRowHandle = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private string SelectDataTable()
|
|
{
|
|
string errText = string.Empty;
|
|
string realText = string.Empty;
|
|
if (DictonaryTableName.ToString().Trim() != "选择")
|
|
{
|
|
string tablename = DictonaryTableName.ToString().Substring(DictonaryTableName.ToString().IndexOf('t'));
|
|
Dictionary<string, bool> dataClumn = new Dictionary<string, bool>();
|
|
|
|
foreach (ColumnsItem item in ShowColumns)
|
|
{
|
|
|
|
dataClumn.Add(item.NameCmn, item.SelectCmn);
|
|
frmClumn.Add(item);
|
|
|
|
}
|
|
if (UserColumns.Count > 0)
|
|
{
|
|
foreach (ColumnsItem item in UserColumns)
|
|
{
|
|
|
|
dataClumn.Add(item.NameCmn, item.SelectCmn);
|
|
|
|
frmClumn.Add(item);
|
|
|
|
}
|
|
}
|
|
string whereSql = string.Empty;
|
|
|
|
|
|
|
|
//if (TextBoxVal.Trim().Length > 0)
|
|
//{
|
|
// whereSql = TextBoxVal ;
|
|
// }
|
|
|
|
if (!string.IsNullOrEmpty(TextBoxVal))
|
|
{
|
|
for (int i = 0; i < ShowColumns.Count; i++)
|
|
{
|
|
if (ShowColumns[i].SelectCmn)
|
|
{
|
|
if (!string.IsNullOrEmpty(whereSql))
|
|
{
|
|
whereSql = whereSql + " or " + ShowColumns[i].NameCmn + " like '%" + TextBoxVal + "%'";
|
|
}
|
|
else
|
|
{
|
|
whereSql = ShowColumns[i].NameCmn + " like '%" + TextBoxVal + "%'";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(whereSql.Trim().Length>0)
|
|
{
|
|
whereSql = " where ( " + whereSql+" )";
|
|
}
|
|
if (m_isSqlWhere)
|
|
{
|
|
if(whereSql.Length>0)
|
|
{
|
|
if (m_sqlStr.Trim().Length > 0)
|
|
whereSql = whereSql+" and "+ m_sqlStr.Replace("where", " ");
|
|
}
|
|
else if(m_sqlStr.Trim().Length>0)
|
|
{
|
|
whereSql = " where " + m_sqlStr.Replace("where", " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tableDictonary = syetmInfo.GetItemInfo(tablename, dataClumn, whereSql, ref errText);
|
|
if (errText.Trim().Length > 0 || tableDictonary == null)
|
|
{
|
|
WMS.Common.SystemCommon.ShowInfoMessageBox("查询出错,请重试!");
|
|
return "查询出错,请重试!";
|
|
}
|
|
if (tableDictonary.Rows.Count > 0)
|
|
{
|
|
DataColumn clmn = new DataColumn("CFLAG", typeof(string));
|
|
tableDictonary.Columns.Add(clmn);
|
|
foreach (DataRow r in tableDictonary.Rows)
|
|
{
|
|
r["CFLAG"] = "0";
|
|
|
|
}
|
|
}
|
|
}
|
|
return string.Empty;
|
|
}
|
|
private DictonaryType DictonaryTableName;
|
|
|
|
|
|
private DataSlectType SelectType;
|
|
private void AddGridColumn()
|
|
{
|
|
if (SelectType == DataSlectType.MultiSelect)
|
|
{
|
|
|
|
DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
|
|
ck_CFlag = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
|
|
DevExpress.XtraGrid.Columns.GridColumn colCFlag = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
|
|
colCFlag.Caption = "选择";
|
|
colCFlag.ColumnEdit = ck_CFlag;
|
|
colCFlag.Name = "colCFlag";
|
|
|
|
colCFlag.Visible = true;
|
|
colCFlag.VisibleIndex = 0;
|
|
colCFlag.FieldName = "CFLAG";
|
|
colCFlag.Width = 42;
|
|
colCFlag.UnboundType = DevExpress.Data.UnboundColumnType.String;
|
|
colCFlag.AppearanceCell.Font = new System.Drawing.Font("宋体", 10);
|
|
colCFlag.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
|
ck_CFlag.AutoHeight = false;
|
|
ck_CFlag.Caption = "Check";
|
|
ck_CFlag.Name = "CK_CFLAG";
|
|
ck_CFlag.ValueChecked = "1";
|
|
ck_CFlag.ValueUnchecked = "0";
|
|
ck_CFlag.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
|
|
this.gridViewItem.Columns.Add(colCFlag);
|
|
this.gridControlItem.RepositoryItems.Add(ck_CFlag);
|
|
}
|
|
int i = 1;
|
|
foreach (ColumnsItem item in frmClumn)
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn gridColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
gridColumn.VisibleIndex = i;
|
|
gridColumn.Caption = item.NameCaption;
|
|
gridColumn.FieldName = item.NameCmn;
|
|
gridColumn.AppearanceCell.Font = new System.Drawing.Font("宋体", 10);
|
|
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
|
gridColumn.Width = 190;
|
|
gridColumn.OptionsColumn.AllowEdit = false;
|
|
if (i > 1)
|
|
{
|
|
gridColumn.Width = 240;
|
|
}
|
|
|
|
gridColumn.AppearanceHeader.Options.UseTextOptions = true;
|
|
//gridColumn.OptionsColumn.AllowEdit = false;
|
|
if (!item.DispalyCmn)
|
|
{
|
|
gridColumn.Visible = false;
|
|
}
|
|
this.gridViewItem.Columns.Add(gridColumn);
|
|
i = i + 1;
|
|
}
|
|
|
|
}
|
|
|
|
private void ctrlButtons1_Click(object sender, EventArgs e)
|
|
{
|
|
if (txtKeyWord.Text.Trim().Length > 0)
|
|
{
|
|
TextBoxVal = txtKeyWord.Text;
|
|
}
|
|
else
|
|
{
|
|
TextBoxVal = string.Empty;
|
|
}
|
|
SelectDataTable();
|
|
if (tableDictonary != null && tableDictonary.Rows.Count == 0)
|
|
{
|
|
SystemCommon.ShowInfoMessageBox(ErrText);
|
|
txtKeyWord.Focus();
|
|
txtKeyWord.SelectAll();
|
|
}
|
|
else
|
|
{
|
|
gridControlItem.Focus();
|
|
gridControlItem.Select();
|
|
}
|
|
if (tableDictonary != null)
|
|
{
|
|
gridControlItem.DataSource = tableDictonary;
|
|
TextBoxVal = txtKeyWord.Text.Trim();
|
|
}
|
|
|
|
}
|
|
|
|
private void txtKeyWord_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyData == Keys.Enter)
|
|
{
|
|
ctrlButtons1_Click(null, null);
|
|
}
|
|
}
|
|
|
|
private void ctrlButtons2_Click(object sender, EventArgs e)
|
|
{
|
|
if (tableDictonary.Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (SelectType == DataSlectType.MultiSelect)
|
|
{
|
|
if (tableDictonary.AsEnumerable().Count(r => r["CFLAG"].ToString() == "1") == 0)
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("请选择数据!");
|
|
gridViewItem.FocusedRowHandle = 0;
|
|
return;
|
|
}
|
|
tableSelect.Rows.Clear();
|
|
|
|
IEnumerable<DataRow> rows = tableDictonary.AsEnumerable().Where(r => r["CFLAG"].ToString() == "1");
|
|
tableSelect = rows.CopyToDataTable();
|
|
}
|
|
else
|
|
{
|
|
if (gridViewItem.RowCount == 0)
|
|
{
|
|
DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
return;
|
|
}
|
|
if (tableSelect.Rows.Count == 0)
|
|
{
|
|
SystemCommon.ShowInfoMessageBox("请选择数据!");
|
|
gridControlItem.Select();
|
|
gridViewItem.SelectRow(0);
|
|
gridViewItem.FocusedRowHandle = 0;
|
|
return;
|
|
}
|
|
}
|
|
DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
}
|
|
|
|
private void gridViewItem_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
ctrlButtons2_Click(null, null);
|
|
}
|
|
|
|
private void gridViewItem_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
|
{
|
|
if (gridViewItem.RowCount < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (e.RowHandle < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (SelectType == DataSlectType.RadioSelect)
|
|
{
|
|
tableSelect.Rows.Clear();
|
|
tableSelect.Rows.Add(gridViewItem.GetFocusedDataRow().ItemArray);
|
|
gridViewItem.EndInit();
|
|
}
|
|
}
|
|
public string ErrText = string.Empty;
|
|
|
|
private void ctrlButtons3_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
}
|
|
|
|
private void FormDictonary_Load(object sender, EventArgs e)
|
|
{
|
|
if ((tableDictonary == null) || (tableDictonary != null && tableDictonary.Rows.Count == 0))
|
|
{
|
|
SystemCommon.ShowInfoMessageBox(ErrText);
|
|
txtKeyWord.Select();
|
|
txtKeyWord.Focus();
|
|
//if (txtKeyWord.Text.Trim().Length == 0)
|
|
//{
|
|
// DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
gridControlItem.Select();
|
|
gridViewItem.SelectRow(0);
|
|
gridViewItem.FocusedRowHandle = 0;
|
|
tableSelect.Rows.Clear();
|
|
tableSelect.Rows.Add(gridViewItem.GetFocusedDataRow().ItemArray);
|
|
if (!string.IsNullOrEmpty(txtKeyWordtext))
|
|
{
|
|
txtKeyWord.Text = txtKeyWordtext;
|
|
SelectDataTable();
|
|
}
|
|
gridControlItem.DataSource = tableDictonary;
|
|
gridViewItem.RefreshData();
|
|
}
|
|
}
|
|
|
|
private void gridViewItem_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyData == Keys.Enter)
|
|
{
|
|
ctrlButtons2_Click(null, null);
|
|
}
|
|
}
|
|
|
|
private void gridViewItem_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
|
{
|
|
if (gridViewItem.RowCount < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (e.FocusedRowHandle < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (SelectType == DataSlectType.RadioSelect)
|
|
{
|
|
tableSelect.Rows.Clear();
|
|
tableSelect.Rows.Add(gridViewItem.GetFocusedDataRow().ItemArray);
|
|
gridViewItem.EndInit();
|
|
}
|
|
}
|
|
|
|
private void FormDictonary_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyData == Keys.Escape)
|
|
{
|
|
DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
}
|
|
}
|
|
|
|
private void ctrlButtons2_Click_1(object sender, EventArgs e)
|
|
{
|
|
ctrlButtons2_Click(null, null);
|
|
}
|
|
|
|
private void panel1_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|