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 FrmComboxPopup : 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 FrmComboxPopup() { InitializeComponent(); } public FrmComboxPopup(ControlModel model, MyControl controlObj) { try { InitializeComponent(); this.mControlModel = model; this.ControlObj = controlObj; this.Text = model.LabelText + "选择"; 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; //text.Length > 6 ? text.Substring(0, 6) + "\n" + text.Substring(6) : btn.Text = text; btn.Font = new Font("微软雅黑", 12); btn.Click -= new EventHandler(btn_Click); btn.Click += new EventHandler(btn_Click); } 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 { DataRow rowItem = (sender as SimpleButton).Tag as DataRow; this.ShowValue = rowItem[this.mControlModel.ValueMember] + ""; this.ShowText = rowItem[this.mControlModel.TextMember] + ""; this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } 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); } } } }