using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Text;
using System.Windows.Forms;
using DevExpress.Pdf.Native.BouncyCastle.Utilities.Collections;
using DevExpress.PivotGrid.OLAP.Mdx;
using DevExpress.Utils.DirectXPaint;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
using FastReport.MSChart;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Gs.DevApp.UserControl
{
public partial class ShowFilter : XtraForm
{
private readonly GridColumnCollection _columns;
private readonly string _fullName;
///
///
///
/// 列名
/// 默认值
/// 类名
public ShowFilter(GridColumnCollection Columns,
List list = null, string FullName = "")
{
FilterList = list;
_columns = Columns;
_fullName = FullName;
InitializeComponent();
repositoryItemComboBox1.TextEditStyle =
TextEditStyles.DisableTextEditor;
repositoryItemComboBox1.SelectedIndexChanged +=
RepositoryItemComboBox1_SelectedIndexChanged;
repositoryItemComboBox1.ParseEditValue +=
RepositoryItemComboBox1_ParseEditValue;
repositoryItemComboBox2.TextEditStyle =
TextEditStyles.DisableTextEditor;
repositoryItemComboBox2.SelectedIndexChanged +=
RepositoryItemComboBox2_SelectedIndexChanged;
repositoryItemComboBox2.ParseEditValue +=
RepositoryItemComboBox2_ParseEditValue;
gridView1.OptionsFind.ShowSearchNavButtons = false;
// this.gridView1.OptionsView.ShowAutoFilterRow = true;
gridView1.OptionsView.ShowGroupPanel = false;
gvQuery.OptionsView.ShowGroupPanel = false;
gvTable.OptionsView.ShowGroupPanel = false;
btnEsc.Click += BtnEsc_Click;
btnQuery.Click += BtnQuery_Click;
getPageList();
//下面为查询配置
this.btnSqlTable.Click += BtnSqlTable_Click;
getPageListQuery();
}
///
/// 查询集合
///
public List FilterList { get; set; }
///
/// 回调事件
///
public event EventHandler UpdateParent;
private void BtnQuery_Click(object sender, EventArgs e)
{
gridView1.CloseEditor();
gridView1.UpdateCurrentRow();
var sbWhere = new StringBuilder();
var list = new List();
for (var i = 0; i < gridView1.DataRowCount; i++)
{
if (string.IsNullOrEmpty(gridView1.GetRowCellValue(i, "field")
.ToString())
|| string.IsNullOrEmpty(gridView1
.GetRowCellValue(i, "fieldWhere").ToString())
|| string.IsNullOrEmpty(gridView1
.GetRowCellValue(i, "fieldValue").ToString())
)
continue;
string _fieId, _fileIdDec;
(_fieId, _fileIdDec) =
_getFiled(gridView1.GetRowCellValue(i, "field").ToString());
string _fileWhere, _fileWhereDec;
(_fileWhere, _fileWhereDec) = _getFiled(gridView1
.GetRowCellValue(i, "fieldWhere").ToString());
var _fieldValue = gridView1.GetRowCellValue(i, "fieldValue")
.ToString();
if (_fileWhere.Contains("like"))
{
_fileWhere = " like ";
_fieldValue = "%" + _fieldValue + "%";
}
list.Add(new FilterEntity(_fieId, _fileIdDec, _fileWhere,
_fileWhereDec, _fieldValue));
}
UpdateParent?.Invoke(this,
new UpdateParentEventArgs { FilterList = list });
Close();
}
///
///
private void getPageList()
{
foreach (GridColumn col in _columns)
if (col.Tag != null && col.Tag.ToString().StartsWith("query"))
{
var item = new CboItemEntity();
item.Text = col.Tag.ToString().Replace("query_", "") +
"(" + col.Caption + ")";
//item.Value = col.FieldName;
item.Value = col.Tag.ToString().Replace("query_", "");
repositoryItemComboBox1.Items.Add(item);
}
var d2 = new Dictionary();
d2.Add(">", "大于");
d2.Add("<", "小于");
d2.Add("=", "等于");
d2.Add("<>", "不等于");
d2.Add("like", "包含");
foreach (var kvp in d2)
{
var item = new CboItemEntity();
item.Text = kvp.Key + "(" + kvp.Value + ")";
item.Value = kvp.Key;
repositoryItemComboBox2.Items.Add(item);
}
try
{
var dt = new DataTable();
dt.Columns.Add("field", typeof(string));
dt.Columns.Add("fieldWhere", typeof(string));
dt.Columns.Add("fieldValue", typeof(string));
foreach (var _sql in FilterList)
{
var dr = dt.NewRow();
dr["field"] = _sql.fileId + "(" + _sql.fileIdDec;
dr["fieldWhere"] = _sql.fileOper + "(" + _sql.fileOperDec;
dr["fieldValue"] = _sql.fileValue.Replace("%", "");
dt.Rows.Add(dr);
}
gcMain.BindingContext = new BindingContext();
gcMain.DataSource = dt;
gcMain.ForceInitialize();
}
catch (Exception ex)
{
MsgHelper.Warning("提示:" + ex.Message);
}
}
private (string, string) _getFiled(string _field)
{
return (_field.Split('(')[0], _field.Split('(')[1]);
}
private void BtnEsc_Click(object sender, EventArgs e)
{
Close();
}
private void RepositoryItemComboBox2_ParseEditValue(object sender,
ConvertEditValueEventArgs e)
{
if (e.Value != null)
{
e.Value = e.Value.ToString();
e.Handled = true;
}
}
private void RepositoryItemComboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
}
private void RepositoryItemComboBox1_ParseEditValue(object sender,
ConvertEditValueEventArgs e)
{
if (e.Value != null)
{
e.Value = e.Value.ToString();
e.Handled = true;
}
}
private void RepositoryItemComboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
}
///
/// 移出一行
///
///
///
private void repositoryItemButtonEdit1_ButtonClick(object sender, ButtonPressedEventArgs e)
{
gridView1.CloseEditor();
gridView1.UpdateCurrentRow();
var rowhandle = gridView1.FocusedRowHandle;
if (rowhandle < 0)
return;
if (e.Button.Index == 0)
{
var dr = gridView1.GetDataRow(rowhandle);
gridView1.DeleteRow(rowhandle);
return;
}
}
#region MyRegion
///
/// 截取表名
///
///
///
private string _getTableName(string strName)
{
var _tableName = strName.Split('(')[0];
return _tableName;
}
private void BtnSqlTable_Click(object sender, EventArgs e)
{
//System.Text.StringBuilder sb = new System.Text.StringBuilder();
//var list = txt_table.Properties.Items.GetCheckedValues();
//foreach (var obj in list)
//{
// if (sb.Length > 0)
// sb.Append(",");
// sb.Append(_getTableName(obj.ToString()));
//}
//if (sb.Length < 0)
//{
// Gs.DevApp.ToolBox.MsgHelper.Warning("请选择关联表!");
// txt_table.Focus();
// return;
//}
//var _obj = new
//{
// guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
// djlx = djlx,//单据类型
// salesId = _sqGuid,//销售单号
// inRemark = FNote.Trim(),//备注
// list = new List(),
//};
//try
//{
// string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj));
// ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
// ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
// if (_rtn.rtnCode > 0)
// {
// lbGuid.Text = _rtn.rtnData.outGuid;
// txt_billNo.Text = _rtn.rtnData.outNo;
// toolBarMenu1.isSetBtn = true;
// List gvList = new List();
// gvList.Add(gvMx1);
// UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false, gvList);
// toolBarMenu1.currentAction = "";
// }
//}
//catch (Exception ex)
//{
// ToolBox.MsgHelper.Warning("提示:" + ex.Message);
//}
}
private void getPageListQuery()
{
repositoryItemComboBoxSql.Items.Clear();
repositoryItemComboBoxSql.Items.Add("1");
repositoryItemComboBoxSql.Items.Add("1");
repositoryItemComboBoxSql.Items.Add("1");
var _obj = new
{
formPath = this._fullName,
list = new List(),
};
foreach (GridColumn col in _columns)
{
_obj.list.Add(new
{
colName = col.Name.ToString(),
colCap = col.Caption
});
}
try
{
var strJson = UtilityHelper.HttpPost("",
"Fm/GetQuery", JsonConvert.SerializeObject(_obj));
ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
JObject _job = JObject.Parse(strJson);
////////////
JArray array = new JArray();
foreach (var a in _job["rtnData"]["list"])
{
array.Add(a);
}
DataTable dt = JsonConvert.DeserializeObject(array.ToString());
gcTable.BindingContext = new BindingContext();
gcTable.DataSource = dt;
gcTable.ForceInitialize();
////////////
JArray array2 = new JArray();
foreach (var a in _job["rtnData"]["list2"])
{
array2.Add(a);
}
DataTable dt2 = JsonConvert.DeserializeObject(array2.ToString());
gcQuery.BindingContext = new BindingContext();
gcQuery.DataSource = dt2;
gcQuery.ForceInitialize();
}
catch (Exception ex)
{
MsgHelper.Warning("提示:" + ex.Message);
}
}
#endregion
}
}