245 lines
8.4 KiB
C#
245 lines
8.4 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.XtraEditors;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class FrmComboxMutilPopup : BaseForm
|
|
{
|
|
public int mPage = 1, mMaxPage = 1, mPageSize = 20;
|
|
public string mControlName = "simpleButton";
|
|
public DataTable mSourceTable = null;
|
|
public string ShowValue = "", ShowText = "";
|
|
public MyControl ControlObj;
|
|
public ControlModel mControlModel;
|
|
public int ListBoxFontSize = 0;
|
|
public FrmComboxMutilPopup()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public FrmComboxMutilPopup(ControlModel model, string showValue, string showText, MyControl ControlObj,int FontSize= 0)
|
|
{
|
|
try {
|
|
InitializeComponent();
|
|
this.ListBoxFontSize = FontSize;
|
|
this.ShowValue = showValue;
|
|
this.ShowText = showText;
|
|
this.mControlModel = model;
|
|
this.ControlObj = ControlObj;
|
|
this.Text = model.LabelText + "选择";
|
|
if (this.ListBoxFontSize>0)
|
|
{
|
|
foreach (System.Windows.Forms.Control ctrol in this.panel2.Controls)
|
|
{
|
|
if (ctrol is SimpleButton)
|
|
{
|
|
SimpleButton simpleButton = ctrol as SimpleButton;
|
|
Font oldFont = simpleButton.Font;
|
|
simpleButton.Font = new Font(oldFont.Name, ListBoxFontSize);
|
|
|
|
}
|
|
}
|
|
}
|
|
this.OnLoad();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void OnLoad()
|
|
{
|
|
this.mSourceTable = BaseImpl.GetDataTableResult(ControlObj.ReplaceControlValue(this.mControlModel.SourceSql));
|
|
this.InitControl();
|
|
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
|
|
}
|
|
|
|
public void VisableControl()
|
|
{
|
|
for (int i = 0; i < this.plContainer.Controls.Count; i++)
|
|
{
|
|
var c = this.plContainer.Controls[i];
|
|
c.Visible = false;
|
|
}
|
|
}
|
|
|
|
public void InitControl()
|
|
{
|
|
int pageIndex = (mPage - 1) * mPageSize;
|
|
if (pageIndex < this.mSourceTable.Rows.Count)
|
|
{
|
|
this.VisableControl();
|
|
int controlIndex = 0;
|
|
for (int i = pageIndex; i < this.mSourceTable.Rows.Count; i++)
|
|
{
|
|
DataRow rowItem = this.mSourceTable.Rows[i];
|
|
var c = this.plContainer.Controls.Find(mControlName + (controlIndex + 1), true);
|
|
if (c.Length > 0 && c[0] is SimpleButton)
|
|
{
|
|
string text = rowItem[mControlModel.TextMember] + "";
|
|
SimpleButton btn = c[0] as SimpleButton;
|
|
btn.Visible = true;
|
|
btn.Tag = rowItem;
|
|
btn.Text = text.Length > 6 ? text.Substring(0, 6) + "\n" + text.Substring(6) : text;
|
|
btn.Click -= new EventHandler(btn_Click);
|
|
btn.Click += new EventHandler(btn_Click);
|
|
|
|
if (ListBoxFontSize>0)
|
|
{
|
|
Font oldFont = btn.Font;
|
|
btn.Font = new Font(oldFont.Name, ListBoxFontSize);
|
|
}
|
|
|
|
|
|
this.SetSelect(btn, this.ShowValue.Contains(rowItem[this.mControlModel.ValueMember] + ","));
|
|
}
|
|
controlIndex++;
|
|
}
|
|
this.mMaxPage = Convert.ToInt32(this.mSourceTable.Rows.Count / mPageSize) + (this.mSourceTable.Rows.Count % mPageSize > 0 ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
void btn_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SimpleButton button = sender as SimpleButton;
|
|
DataRow rowItem = (sender as SimpleButton).Tag as DataRow;
|
|
|
|
string value = rowItem[this.mControlModel.ValueMember] + "";
|
|
string text = rowItem[this.mControlModel.TextMember] + "";
|
|
|
|
if (button.ForeColor == Color.White)
|
|
{
|
|
this.SetSelect(button, false);
|
|
this.ShowText = this.ShowText.Replace(text + ",", "");
|
|
this.ShowValue = this.ShowValue.Replace(value + ",", "");
|
|
}
|
|
else
|
|
{
|
|
this.SetSelect(button, true);
|
|
this.ShowText += text + ",";
|
|
this.ShowValue += value + ",";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
public void SetSelect(SimpleButton button,bool isSelect)
|
|
{
|
|
if (isSelect)
|
|
{
|
|
button.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
|
button.Appearance.BorderColor = button.Appearance.BackColor = Color.Blue;
|
|
button.Appearance.Options.UseBackColor = button.Appearance.Options.UseBorderColor = button.Appearance.Options.UseForeColor = true;
|
|
button.ForeColor = Color.White;
|
|
}
|
|
else
|
|
{
|
|
button.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
|
|
button.Appearance.Options.UseBackColor = button.Appearance.Options.UseBorderColor = button.Appearance.Options.UseForeColor = false;
|
|
button.ForeColor = Color.Black;
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void simpleButton21_Click(object sender, EventArgs e)
|
|
{
|
|
try {
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|
|
} |