202 lines
8.7 KiB
C#
202 lines
8.7 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 System.Reflection;
|
||
using WMS.Attirubte;
|
||
using System.Collections;
|
||
using WMS.Common;
|
||
using WMS.Model.SystemManage;
|
||
using WMS.Business;
|
||
using WMS.Business.Common;
|
||
|
||
namespace WMS.Frm
|
||
{
|
||
public partial class FrmSelect: DevExpress.XtraEditors.XtraForm
|
||
{
|
||
private string TableName = string.Empty;
|
||
|
||
public DataTable SelectData = new DataTable();
|
||
object classType;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="className"></param>
|
||
public FrmSelect(object className)
|
||
{
|
||
InitializeComponent();
|
||
classType = className;
|
||
|
||
}
|
||
|
||
|
||
string sqlStr = string.Empty;
|
||
string jionclumns = "";
|
||
List<string> clmDataValue = new List<string>();
|
||
/// <summary>
|
||
/// 差
|
||
/// </summary>
|
||
// List<classType)> ListTypeData = new List<classType>();
|
||
// List<SelectTye> selectType = new List<SelectTye>();
|
||
private void FrmSelect_Load(object sender, EventArgs e)
|
||
{
|
||
PropertyInfo[] model = classType.GetType().GetProperties();
|
||
object[] tableAttributess= classType.GetType().GetCustomAttributes(false);
|
||
TableName = (tableAttributess.First(r => r.GetType() == typeof(TableClmAttribute)) as TableClmAttribute).TableName;
|
||
char flag = 'a';
|
||
foreach (PropertyInfo info in model)
|
||
{
|
||
object[] attiBus= info.GetCustomAttributes(false);
|
||
int cutCount = attiBus.Count(r => r.GetType() == typeof(TableClmAttribute));
|
||
if (cutCount > 0)
|
||
{
|
||
if (!(attiBus.First(r => r.GetType() == typeof(TableClmAttribute)) as TableClmAttribute).NoSelect)
|
||
{
|
||
|
||
continue;
|
||
}
|
||
}
|
||
clmDataValue.Add("t."+info.Name.ToString());
|
||
foreach (var att in attiBus)
|
||
{
|
||
DevExpress.XtraVerticalGrid.Rows.EditorRow cl = new DevExpress.XtraVerticalGrid.Rows.EditorRow();
|
||
if (att.GetType() == typeof(DisplayNameAttribute))
|
||
{
|
||
|
||
cl.Properties.FieldName = info.Name;
|
||
cl.Properties.Caption = (att as DisplayNameAttribute).DisplayName;
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (cutCount > 0)
|
||
{
|
||
TableClmAttribute clmAttute= attiBus.First(r => r.GetType() == typeof(TableClmAttribute)) as TableClmAttribute;
|
||
////如果指定了属性JoinTableClmName和属性ClmJoinTable说明为下拉,查询表ClmJoinTable,显示列JoinTableClmName。
|
||
|
||
if (clmAttute.ClmJoinTable.Trim().Length > 0 && clmAttute.JoinTableClmName.Trim().Length > 0)
|
||
{
|
||
|
||
DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit abc = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
|
||
|
||
abc.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(clmAttute.JoinTableClmName, (att as DisplayNameAttribute).DisplayName));
|
||
|
||
vGridControlCustom1.RepositoryItems.Add(abc);
|
||
|
||
abc.NullText = " ";
|
||
|
||
abc.ValueMember = clmAttute.JoinTableClm;
|
||
|
||
abc.DisplayMember = clmAttute.JoinTableClmName;
|
||
|
||
cl.Properties.RowEdit = abc;
|
||
|
||
DataTable table = IBussFactory<BussCommon>.Instance().GetCustomCtrlData(clmAttute.ClmJoinTable, clmAttute.JoinTableClmName, clmAttute.JoinTableClm, clmAttute.JoinTableWhere, "");
|
||
|
||
abc.DataSource = table;
|
||
if (string.IsNullOrEmpty(clmAttute.JoinTableWhere))
|
||
{
|
||
sqlStr = sqlStr + " left join " + clmAttute.ClmJoinTable + " " + flag.ToString() + " on t." + info.Name + "=" + flag.ToString() + "." + clmAttute.JoinTableClm + "";
|
||
}
|
||
else
|
||
{
|
||
clmAttute.JoinTableWhere = clmAttute.JoinTableWhere.Replace("and", "and " + flag.ToString()+".");
|
||
sqlStr = sqlStr + " left join " + clmAttute.ClmJoinTable + " " + flag.ToString() + " on t." + info.Name + "=" + flag.ToString() + "." + clmAttute.JoinTableClm + " and " + flag.ToString() + "." + clmAttute.JoinTableWhere;
|
||
}
|
||
clmDataValue.Add(flag + "." + clmAttute.JoinTableClmName);
|
||
flag++;
|
||
// clmDataValue.Add(clmAttute.JoinTableClmName + " as " + clmAttute.ClassName);
|
||
}
|
||
|
||
if (clmAttute.ColumnData.Trim().Length > 0)
|
||
{
|
||
List<SelectTye> selectData = new List<SelectTye>();
|
||
string []clmData= clmAttute.ColumnData.Trim().Split('|');
|
||
foreach (string c in clmData)
|
||
{
|
||
string []clmValue = c.Split('%');
|
||
SelectTye select = new SelectTye();
|
||
select.ClmName = clmValue[0].ToString();
|
||
select.ClmValue = clmValue[1].ToString();
|
||
selectData.Add(select);
|
||
}
|
||
|
||
DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit custLook = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
|
||
custLook.NullText = " ";
|
||
custLook.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ClmName", (att as DisplayNameAttribute).DisplayName));
|
||
custLook.ValueMember = "ClmValue";
|
||
custLook.DisplayMember = "ClmName";
|
||
vGridControlCustom1.RepositoryItems.Add(custLook);
|
||
cl.Properties.RowEdit = custLook;
|
||
custLook.DataSource = selectData;
|
||
bindingSource1.DataSource = selectData;
|
||
}
|
||
|
||
//}
|
||
}
|
||
vGridControlCustom1.Rows.Add(cl);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
Dictionary<string, string> keyValue = new Dictionary<string, string>();
|
||
private void ctrlButtons1_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
//DictionaryEntry dctEty=new DictionaryEntry();
|
||
for(int j=0;j<vGridControlCustom1.Rows.Count;j++)
|
||
{
|
||
if (vGridControlCustom1.Rows[j].Properties.Value != null)
|
||
{
|
||
string valueData = vGridControlCustom1.Rows[j].Properties.Value.ToString();
|
||
keyValue.Add(vGridControlCustom1.Rows[j].Properties.FieldName.ToString(), vGridControlCustom1.Rows[j].Properties.Value.ToString());
|
||
}
|
||
|
||
}
|
||
|
||
|
||
if (sqlStr.Trim().Length > 0)
|
||
{
|
||
TableName = TableName + " t " + sqlStr;
|
||
|
||
}
|
||
else
|
||
{
|
||
TableName = TableName + " t ";
|
||
}
|
||
//};datalum.
|
||
SelectData = IBussFactory<BussCommon>.Instance().GetListData(clmDataValue, keyValue, TableName);
|
||
if (SelectData != null)
|
||
{
|
||
if (SelectData.Rows.Count == 0)
|
||
{
|
||
if (SystemCommon.ShowMessageBoxResultCancel("没有查询到记录,是否退出") == System.Windows.Forms.DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
DialogResult = System.Windows.Forms.DialogResult.OK;
|
||
|
||
}
|
||
|
||
private void ctrlButtons4_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||
}
|
||
}
|
||
|
||
}
|