118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using CommonLib;
|
|
|
|
namespace Lskj.MyControl.LookUpAdd {
|
|
public partial class LabelLookUpAdd : UserControl {
|
|
public LabelLookUpAdd() {
|
|
InitializeComponent();
|
|
}
|
|
[Description("是否多选")]
|
|
public bool IsMultiple { get; set; }
|
|
|
|
[Description("SQL语句")]
|
|
public string SQL { get; set; }
|
|
|
|
[Description("设置列")]
|
|
public Dictionary<string, string> Columns { get; set; }
|
|
|
|
[Description("设置Value")]
|
|
public string ValueField { get; set; }
|
|
|
|
[Description("设置TextFiled")]
|
|
public string TextField { get; set; }
|
|
|
|
[Description("设置Value值")]
|
|
public string ReturnValue { get; set; }
|
|
|
|
[Description("设置Text值")]
|
|
public string ReturnText { get; set; }
|
|
|
|
[Description("窗体高度")]
|
|
public int WinHeight { get; set; }
|
|
|
|
[Description("窗体宽度")]
|
|
public int WinWidth { get; set; }
|
|
|
|
private void btnMore_Click(object sender, EventArgs e) {
|
|
FrmMain frmMain = new FrmMain();
|
|
frmMain.IsMultiple = IsMultiple;
|
|
|
|
frmMain.SQL = SQL;
|
|
frmMain.Columns = Columns;
|
|
frmMain.ValueField = ValueField;
|
|
frmMain.TextField = TextField;
|
|
frmMain.WinHeight = WinHeight;
|
|
frmMain.WinWidth = WinWidth;
|
|
frmMain.ReturnValue = ReturnValue;
|
|
frmMain.ReturnText = ReturnText;
|
|
frmMain.ShowDialog();
|
|
//接受返回来值
|
|
Text = frmMain.ReturnText;
|
|
ReturnValue = frmMain.ReturnValue;
|
|
ReturnText = frmMain.ReturnText;
|
|
}
|
|
[Description("设置值")]
|
|
public override string Text {
|
|
get { return txtBox.Text; }
|
|
set {
|
|
|
|
txtBox.Text = value;
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置Value值
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
public void SetValueText(string ids) {
|
|
if (string.IsNullOrEmpty(ids))
|
|
return;
|
|
string sql2 = "select * from (" + SQL + ") as tab where " + ValueField + " in (" + ids + ")";
|
|
DataTable dt = SqlHelper.ExecuteDataSet(sql2).Tables[0];
|
|
string text = string.Empty;
|
|
foreach (DataRow row in dt.Rows) {
|
|
text += row[TextField] + ",";
|
|
}
|
|
this.Text = text.Trim(',');
|
|
ReturnText = text;
|
|
ReturnValue = ids;
|
|
}
|
|
|
|
public void SetTextValue(string ids)
|
|
{
|
|
if (string.IsNullOrEmpty(ids))
|
|
return;
|
|
string tmpIds = ids.Replace(",", "','");
|
|
tmpIds = "'" + tmpIds + "'";
|
|
string sql2 = "select * from (" + SQL + ") as tab where " + TextField + " in (" + tmpIds + ")";
|
|
DataTable dt = SqlHelper.ExecuteDataSet(sql2).Tables[0];
|
|
string text = string.Empty;
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
text += row[ValueField] + ",";
|
|
}
|
|
this.Text = ids;
|
|
ReturnText = ids;
|
|
ReturnValue = text;
|
|
}
|
|
|
|
private string labelText;
|
|
[Description("Label值")]
|
|
public string LabelText {
|
|
get { return labelText; }
|
|
set {
|
|
labelText = value;
|
|
lbMsg.Text = value;
|
|
pl_left.Width = lbMsg.Width + 7;
|
|
}
|
|
}
|
|
}
|
|
}
|