326 lines
11 KiB
C#
326 lines
11 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 Lskj.Control.Model;
|
|
using Lskj.Business.Impl;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using Lskj.Core;
|
|
using System.Diagnostics;
|
|
using Lskj.Business;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class FrmGridSelectPopup : BaseForm
|
|
{
|
|
private string _checkFieldName = "选";
|
|
public int mPage = 1, mMaxPage = 1, mPageSize = 5;
|
|
public ControlModel Model;
|
|
public string ShowText = "";
|
|
public string ShowValue = "";
|
|
public MyControl ControlObj;
|
|
public DataTable mSourceTable = null;
|
|
public Font mColumnFont = new Font("微软雅黑", 12);
|
|
public Font mRowFont = new Font("微软雅黑", 12);
|
|
|
|
public FrmGridSelectPopup()
|
|
{
|
|
InitializeComponent();
|
|
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
|
|
}
|
|
|
|
public FrmGridSelectPopup(ControlModel model, MyControl ControlObj,string ShowText,string ShowValue)
|
|
{
|
|
try {
|
|
InitializeComponent();
|
|
this.Model = model;
|
|
this.ControlObj = ControlObj;
|
|
this.ShowText = ShowText;
|
|
this.ShowValue = ShowValue;
|
|
this.Init();
|
|
this.gridView.BestFitColumns();//设置根据内容填充列宽
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
if (string.IsNullOrEmpty(this.Model.SourceSql))
|
|
{
|
|
MessageUtil.Show("请先配置数据源");
|
|
}
|
|
else
|
|
{
|
|
this.mSourceTable = BaseImpl.GetDataTableResult(ControlObj.ReplaceControlValue(this.Model.SourceSql));
|
|
|
|
if (this.Model.FieldType == ControlType.LabGridPopupMutilText || this.Model.FieldType == ControlType.LabGridPopupMutilValue)
|
|
{
|
|
this.simpleButton5.Visible = true;
|
|
this.mSourceTable.Columns.Add(_checkFieldName, typeof(bool));
|
|
this.mSourceTable.Columns[_checkFieldName].SetOrdinal(0);
|
|
|
|
for (int i = 0; i < mSourceTable.Rows.Count; i++)
|
|
{
|
|
mSourceTable.Rows[i][_checkFieldName] = 0;
|
|
}
|
|
}
|
|
|
|
this.InitColumn();
|
|
this.InitControl();
|
|
this.gridView.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(gridView_RowClick);
|
|
}
|
|
}
|
|
|
|
public FrmGridSelectPopup(GridColumnModel model)
|
|
{
|
|
try
|
|
{
|
|
InitializeComponent();
|
|
this.Model = new ControlModel();
|
|
this.Model.SourceSql = model.SqlSource;
|
|
this.Model.ValueMember = model.ValueMember;
|
|
this.Model.TextMember = model.TextMember;
|
|
this.Model.FieldType = model.FieldType;
|
|
this.gridView.BestFitColumns();//设置根据内容填充列宽
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
public void InitNew(string sql, string ShowText, string ShowValue)
|
|
{
|
|
this.ShowText = ShowText;
|
|
this.ShowValue = ShowValue;
|
|
if (string.IsNullOrEmpty(sql))
|
|
{
|
|
MessageUtil.Show("请先配置数据源");
|
|
}
|
|
else
|
|
{
|
|
this.mSourceTable = BaseImpl.GetDataTableResult(sql);
|
|
|
|
if (this.Model.FieldType == ControlType.LabGridPopupMutilText || this.Model.FieldType == ControlType.LabGridPopupMutilValue)
|
|
{
|
|
this.simpleButton5.Visible = true;
|
|
this.mSourceTable.Columns.Add(_checkFieldName, typeof(bool));
|
|
this.mSourceTable.Columns[_checkFieldName].SetOrdinal(0);
|
|
|
|
for (int i = 0; i < mSourceTable.Rows.Count; i++)
|
|
{
|
|
mSourceTable.Rows[i][_checkFieldName] = 0;
|
|
}
|
|
}
|
|
|
|
this.InitColumn();
|
|
this.InitControl();
|
|
this.gridView.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(gridView_RowClick);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void gridView_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.Model.FieldType == ControlType.LabGridPopupValue || this.Model.FieldType == ControlType.LabGridPopupText)
|
|
{
|
|
DataRow rowItem = this.gridView.GetFocusedDataRow();
|
|
|
|
this.ShowValue = rowItem[this.Model.ValueMember] + "";
|
|
this.ShowText = rowItem[this.Model.TextMember] + "";
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
DataRow rowItem = this.gridView.GetFocusedDataRow();
|
|
if (rowItem != null)
|
|
{
|
|
rowItem[_checkFieldName] = "True".Equals(rowItem[_checkFieldName] + "", StringComparison.OrdinalIgnoreCase) ? 0 : 1;
|
|
rowItem.AcceptChanges();
|
|
|
|
bool isCheck = "True".Equals(rowItem[_checkFieldName] + "");
|
|
string text = rowItem[this.Model.TextMember] + "";
|
|
string value = rowItem[this.Model.ValueMember] + "";
|
|
if (isCheck)
|
|
{
|
|
this.ShowText += "," + text;
|
|
this.ShowValue += "," + value;
|
|
}
|
|
else
|
|
{
|
|
this.ShowText = this.ShowText.Replace(text, "").TrimStart(',').TrimEnd(',');
|
|
this.ShowValue = this.ShowValue.Replace(value, "").TrimStart(',').TrimEnd(',');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
public void InitColumn()
|
|
{
|
|
this.gridView.Appearance.Row.Font = mRowFont;
|
|
this.gridView.RowHeight = 40;
|
|
this.gridView.ColumnPanelRowHeight = 40;
|
|
}
|
|
|
|
public void InitControl()
|
|
{
|
|
try {
|
|
if (mSourceTable != null && mSourceTable.Rows.Count > 0)
|
|
{
|
|
this.gridControl.DataSource = this.mSourceTable.Rows.Cast<DataRow>().Skip((mPage - 1) * mPageSize).Take(mPageSize).CopyToDataTable();
|
|
if (mSourceTable.Columns.Contains(_checkFieldName))
|
|
{
|
|
String[] strRating = ShowValue.Split(',');
|
|
foreach (string sr in strRating)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sr)) continue;
|
|
foreach (DataRow item in this.gridControl.DataSourceTable().Rows)
|
|
{
|
|
if ((sr).Equals(item[this.Model.ValueMember].ToString()))
|
|
{
|
|
string a = item[this.Model.ValueMember].ToString();
|
|
item[_checkFieldName] = 1;
|
|
bool aa = sr.Contains(a);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
this.mMaxPage = Convert.ToInt32(this.mSourceTable.Rows.Count / mPageSize) + (this.mSourceTable.Rows.Count % mPageSize > 0 ? 1 : 0);
|
|
}
|
|
//筛选改成 包含
|
|
foreach (GridColumn col in gridView.Columns)
|
|
{
|
|
if (col.Visible)
|
|
{
|
|
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
|
}
|
|
}
|
|
this.gridView.BestFitColumns();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton22_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.mPage == 1) return;
|
|
this.mPage = 1;
|
|
this.InitControl();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton23_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.mPage > 1)
|
|
{
|
|
this.mPage -= 1;
|
|
this.InitControl();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton24_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.mPage < this.mMaxPage)
|
|
{
|
|
this.mPage += 1;
|
|
this.InitControl();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton25_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.mPage == this.mMaxPage) return;
|
|
this.mPage = this.mMaxPage;
|
|
this.InitControl();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton5_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
this.ShowText = this.ShowText.TrimStart(',');
|
|
this.ShowValue = this.ShowValue.TrimStart(',');
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void simpleButton6_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|