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 int ListBoxFontSize = 0; public FrmComboxPopup() { InitializeComponent(); } public FrmComboxPopup(ControlModel model, MyControl controlObj, int FontSize = 0) { try { InitializeComponent(); this.ListBoxFontSize = FontSize; this.mControlModel = model; this.ControlObj = controlObj; this.Text = model.LabelText + "选择"; if (this.ListBoxFontSize > 0) { foreach (System.Windows.Forms.Control ctrol in this.panel3.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 FrmComboxPopup(GridColumnModel model) { try { InitializeComponent(); this.mControlModel = new ControlModel(); this.mControlModel.SourceSql = model.SqlSource; this.mControlModel.ValueMember = model.ValueMember; this.mControlModel.TextMember = model.TextMember; this.Text = model.FieldText + "选择"; if (this.ListBoxFontSize > 0) { foreach (System.Windows.Forms.Control ctrol in this.panel3.Controls) { if (ctrol is SimpleButton) { SimpleButton simpleButton = ctrol as SimpleButton; Font oldFont = simpleButton.Font; simpleButton.Font = new Font(oldFont.Name, ListBoxFontSize); } } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } public void OnLoadnew(string sql) { this.mSourceTable = BaseImpl.GetDataTableResult(sql); 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; if (ListBoxFontSize > 0) { btn.Font = new Font("微软雅黑", ListBoxFontSize); } else { 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); } } } }