| | |
| | | using DevExpress.XtraEditors; |
| | | using System; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Data.SqlTypes; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using System.Collections.Generic; |
| | | 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 System.Collections; |
| | | using DevExpress.XtraGrid.Views.Base.ViewInfo; |
| | | using FastReport.MSChart; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using static Gs.DevApp.ToolBox.UtilityHelper; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace Gs.DevApp.UserControl |
| | | { |
| | | public partial class ShowFilter : DevExpress.XtraEditors.XtraForm |
| | | public partial class ShowFilter : XtraForm |
| | | { |
| | | public event EventHandler<UpdateParentEventArgs> UpdateParent; |
| | | |
| | | private GridColumnCollection _columns; |
| | | public ShowFilter(GridColumnCollection Columns) |
| | | { |
| | | this._columns = Columns; |
| | | InitializeComponent(); |
| | | this.gridView1.OptionsFind.ShowSearchNavButtons = false; |
| | | // this.gridView1.OptionsView.ShowAutoFilterRow = true; |
| | | this.gridView1.OptionsView.ShowGroupPanel = false; |
| | | this.btnEsc.Click += BtnEsc_Click; |
| | | this.btnQuery.Click += BtnQuery_Click; |
| | | getPageList(); |
| | | } |
| | | |
| | | private void BtnQuery_Click(object sender, EventArgs e) |
| | | { |
| | | UpdateParent?.Invoke(this, new UpdateParentEventArgs { Data = "hi,这里是查询条件" }); |
| | | this.Close(); |
| | | } |
| | | |
| | | private void BtnEsc_Click(object sender, EventArgs e) |
| | | { |
| | | this.Close(); |
| | | } |
| | | |
| | | private readonly GridColumnCollection _columns; |
| | | private readonly string _fullName; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="curPage">第几页</param> |
| | | /// <param name="pageSize">每页几条</param> |
| | | /// <param name="Columns">列名</param> |
| | | /// <param name="list">默认值</param> |
| | | /// <param name="FullName">类名</param> |
| | | public ShowFilter(GridColumnCollection Columns, |
| | | List<FilterEntity> 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(); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查询集合 |
| | | /// </summary> |
| | | public List<FilterEntity> FilterList { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 回调事件 |
| | | /// </summary> |
| | | public event EventHandler<UpdateParentEventArgs> UpdateParent; |
| | | |
| | | private void BtnQuery_Click(object sender, EventArgs e) |
| | | { |
| | | gridView1.CloseEditor(); |
| | | gridView1.UpdateCurrentRow(); |
| | | var sbWhere = new StringBuilder(); |
| | | var list = new List<FilterEntity>(); |
| | | 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(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// </summary> |
| | | private void getPageList() |
| | | { |
| | | |
| | | repositoryItemComboBox1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
| | | foreach (GridColumn col in _columns) |
| | | { |
| | | CboItemEntity item = new CboItemEntity(); |
| | | item.Text = col.Caption; |
| | | item.Value = col.FieldName; |
| | | repositoryItemComboBox1.Items.Add(item); |
| | | } |
| | | repositoryItemComboBox1.SelectedIndexChanged += RepositoryItemComboBox1_SelectedIndexChanged; |
| | | repositoryItemComboBox1.ParseEditValue += RepositoryItemComboBox1_ParseEditValue; |
| | | Dictionary<string, string> d2 = new Dictionary<string, string>(); |
| | | 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<string, string>(); |
| | | d2.Add(">", "大于"); |
| | | d2.Add("<", "小于"); |
| | | d2.Add("=", "等于"); |
| | | d2.Add("<>", "不等于"); |
| | | d2.Add("like", "包含"); |
| | | foreach (KeyValuePair<string, string> kvp in d2) |
| | | foreach (var kvp in d2) |
| | | { |
| | | CboItemEntity item = new CboItemEntity(); |
| | | item.Text = kvp.Value; |
| | | var item = new CboItemEntity(); |
| | | item.Text = kvp.Key + "(" + kvp.Value + ")"; |
| | | item.Value = kvp.Key; |
| | | repositoryItemComboBox2.Items.Add(item); |
| | | } |
| | | repositoryItemComboBox2.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
| | | repositoryItemComboBox2.SelectedIndexChanged += RepositoryItemComboBox2_SelectedIndexChanged; |
| | | repositoryItemComboBox2.ParseEditValue += RepositoryItemComboBox2_ParseEditValue; |
| | | try |
| | | { |
| | | DataTable dt = new DataTable(); |
| | | var dt = new DataTable(); |
| | | dt.Columns.Add("field", typeof(string)); |
| | | dt.Columns.Add("fieldWhere", typeof(string)); |
| | | dt.Columns.Add("fieldValue", typeof(string)); |
| | | dt.Rows.Add(dt.NewRow()); |
| | | 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) |
| | | { |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 移出一行 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | 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 |
| | | /// <summary> |
| | | /// 截取表名 |
| | | /// </summary> |
| | | /// <param name="strName"></param> |
| | | /// <returns></returns> |
| | | private string _getTableName(string strName) |
| | | { |
| | | var _tableName = strName.Split('(')[0]; |
| | | return _tableName; |
| | | } |
| | | private void BtnSqlTable_Click(object sender, EventArgs e) |
| | | { |
| | | if (string.IsNullOrEmpty(_fullName)) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.Warning("请选择页面!"); |
| | | return; |
| | | } |
| | | var _obj = new |
| | | { |
| | | formPath = _fullName, |
| | | list = new List<dynamic>(), |
| | | }; |
| | | gvTable.CloseEditor(); |
| | | gvTable.UpdateCurrentRow(); |
| | | if (gvTable.DataRowCount <= 0) |
| | | { |
| | | MsgHelper.ShowError("明细不能为空,请选择你的明细!"); |
| | | return; |
| | | } |
| | | for (var i = 0; i < gvTable.DataRowCount; i++) |
| | | { |
| | | var row = gvTable.GetDataRow(i); |
| | | if (row != null) |
| | | { |
| | | string _msl = row["tableOtherName"].ToString(); |
| | | if (string.IsNullOrEmpty(_msl)) |
| | | { |
| | | MsgHelper.ShowError("别名不能为空!"); |
| | | return; |
| | | } |
| | | _obj.list.Add(new |
| | | { |
| | | tableName = (row["tableName"].ToString()), |
| | | tableOtherName = row["tableOtherName"].ToString(), |
| | | }); |
| | | } |
| | | } |
| | | try |
| | | { |
| | | string strJson = UtilityHelper.HttpPost("", "Fm/EditQuery", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | getPageListQuery(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void RepositoryItemComboBox2_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e) |
| | | } |
| | | private void getPageListQuery() |
| | | { |
| | | if (e.Value != null) |
| | | repositoryItemComboBoxSql.Items.Clear(); |
| | | repositoryItemComboBoxSql.Items.Add("1"); |
| | | repositoryItemComboBoxSql.Items.Add("1"); |
| | | repositoryItemComboBoxSql.Items.Add("1"); |
| | | var _obj = new |
| | | { |
| | | e.Value = e.Value.ToString(); e.Handled = true; |
| | | formPath = this._fullName, |
| | | list = new List<dynamic>(), |
| | | }; |
| | | 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<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); |
| | | JObject _job = JObject.Parse(strJson); |
| | | //读前选择 |
| | | JArray array00 = new JArray(); |
| | | foreach (var a in _job["rtnData"]["list3"]) |
| | | { |
| | | array00.Add(a); |
| | | } |
| | | DataTable dt00 = JsonConvert.DeserializeObject<DataTable>(array00.ToString()); |
| | | this.repositoryItemSearchLookUpEdit1.DataSource = dt00; |
| | | //////////// |
| | | JArray array = new JArray(); |
| | | foreach (var a in _job["rtnData"]["list"]) |
| | | { |
| | | array.Add(a); |
| | | } |
| | | DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString()); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | gcTable.BindingContext = new BindingContext(); |
| | | gcTable.DataSource = dt; |
| | | gcTable.ForceInitialize(); |
| | | gvTable.BestFitColumns(); |
| | | } |
| | | else |
| | | { |
| | | Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcTable, gvTable); |
| | | } |
| | | //////////// |
| | | JArray array2 = new JArray(); |
| | | foreach (var a in _job["rtnData"]["list2"]) |
| | | { |
| | | array2.Add(a); |
| | | } |
| | | DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString()); |
| | | gcQuery.BindingContext = new BindingContext(); |
| | | gcQuery.DataSource = dt2; |
| | | gcQuery.ForceInitialize(); |
| | | gvQuery.BestFitColumns(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void RepositoryItemComboBox2_SelectedIndexChanged(object sender, EventArgs e) |
| | | private void repositoryItemSearchLookUpEdit1_EditValueChanged(object sender, EventArgs e) |
| | | { |
| | | SearchLookUpEdit LookupEdit = sender as SearchLookUpEdit; |
| | | DataRowView SelectedDataRow = (DataRowView)LookupEdit.GetSelectedDataRow(); |
| | | gvTable.SetFocusedRowCellValue("tableName", SelectedDataRow["tableName"].ToString()); |
| | | gvTable.SetFocusedRowCellValue("tableCap", SelectedDataRow["tableCap"].ToString()); |
| | | gvTable.CloseEditor(); |
| | | gvTable.PostEditor(); |
| | | gvTable.UpdateCurrentRow(); |
| | | } |
| | | |
| | | private void RepositoryItemComboBox1_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e) |
| | | private void repositoryItemButtonEdit2_ButtonClick(object sender, ButtonPressedEventArgs e) |
| | | { |
| | | if (e.Value != null) |
| | | var rowhandle = gvTable.FocusedRowHandle; |
| | | if (rowhandle < 0) |
| | | return; |
| | | if (e.Button.Index == 0) |
| | | { |
| | | e.Value = e.Value.ToString(); e.Handled = true; |
| | | var dr = gvTable.GetDataRow(rowhandle); |
| | | var mxGuid = dr["guid"].ToString(); |
| | | if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?")) |
| | | return; |
| | | if (string.IsNullOrEmpty(mxGuid)) |
| | | { |
| | | gvTable.DeleteRow(rowhandle); |
| | | return; |
| | | } |
| | | var _obj = new |
| | | { |
| | | guid = mxGuid, |
| | | }; |
| | | try |
| | | { |
| | | var strJson = UtilityHelper.HttpPost("", |
| | | "Fm/DeleteQuery", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var _rtn = UtilityHelper.ReturnToDynamic(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | if (_rtn.rtnCode > 0) getPageListQuery(); |
| | | } |
| | | MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void RepositoryItemComboBox1_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | #endregion |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |