Files
lserp_cs_5.0/插件库/ControlLib/inh/autosearcher_Res/FrmAutoSearch.cs
T
2026-07-10 15:25:05 +08:00

160 lines
5.5 KiB
C#

using CommonLib;
using CommonLib.utils;
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;
namespace ControlLib.inh {
/// <summary>
/// 搜索结果窗体
/// </summary>
public partial class FrmAutoSearch : Form {
//--说明,Livview的第一列由于是caption,不好区分,所以都填写空字符,
public delegate void FunctionNameNoParams();
public delegate object FunctionName(object args);
public List<int> widthList = new List<int>();
public int columsWidth { get; set; }
public string addDllName { get; set; }
public string addModuleId { get; set; }
public string FormText { get; set; }
public string OperatorId { get; set; }
public string OperatorName { get; set; }
public string SpeciesNo { get; set; }
public string addResultValue { get; set; }
public AutoSearcher autos { get; set; }
public void StartQuerying() {
iCount = 1;
timer1.Enabled = true;
}
public void EndQuerying() {
timer1.Enabled = false;
this.Text = "查询完毕,请选择。";
}
/// <summary>
/// 线程调用给listv添加item
/// </summary>
/// <param name="item"></param>
public object AddListVItem(object args) {
ListViewItem item = (ListViewItem)args;
for (int i = 0; i < item.SubItems.Count; i++) {
System.Windows.Forms.ListViewItem.ListViewSubItem vItem = item.SubItems[i];
int w = SetAutoWidth(vItem.Text);
if ((widthList.Count - 1) < i) {
if (w < 60)
w = 60;
else
w = w + 50;
widthList.Add(w);
}
else {
int oldWdith = widthList[i];
if (w > oldWdith) {
widthList[i] = w;
}
}
}
return ListVAuto.Items.Add(item);
}
public int SetAutoWidth(string text) {
Graphics graphics = CreateGraphics();
SizeF sizeF = graphics.MeasureString(text, new Font("宋体", 9));
graphics.Dispose();
return (int)sizeF.Width;
}
/// <summary>
/// 线程调用让listv选中第一条记录(在有记录的情况下)
/// </summary>
/// <param name="args"></param>
public void DoSelectItem() {
if (ListVAuto.Items.Count > 0) {
ListVAuto.Items[0].Selected = true;
}
}
/// <summary>
/// 线程调用获取listv指定索引的item
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public object DoGetItem(object args) {
int index = (int)args;
return ListVAuto.Items[index];
}
private int iCount = 0;
public FrmAutoSearch() {
InitializeComponent();
//System.Threading.Thread.CurrentThread.IsBackground = true;
}
private void timer1_Tick(object sender, EventArgs e) {
string strText = "正在读取数据...";
for (int i = 0; i <= iCount; i++) {
strText += ".";
}
this.Text = strText;
iCount++;
if (iCount >= 6)
iCount = 1;
}
public ListView ListV {
get { return ListVAuto; }
}
/// <summary>
/// 是否可以释放窗体
/// </summary>
public bool CanClose = false;
private void ListVAuto_Leave(object sender, EventArgs e) {
this.Hide();
}
private void FrmAutoSearch_Load(object sender, EventArgs e) {
ListVAuto.Scrollable = true;
pnlAdd.Visible = addDllName != "";
}
private void FrmAutoSearch_FormClosing(object sender, FormClosingEventArgs e) {
if (!CanClose && e.CloseReason == CloseReason.UserClosing) {
e.Cancel = true;
this.Hide();
}
}
private void simpleButton1_Click(object sender, EventArgs e) {
this.Hide();
string[] args = {
FormText,
OperatorId,
OperatorName,
"",
addModuleId,
"",
"0",
"",
SpeciesNo+""==""? "01":SpeciesNo,
"默认分类",
""
};
IForm form = PubUtil.LoadDllForm(addDllName, args);
form.SubForm.Tag = "1";
DialogResult drt = form.SubForm.ShowDialog();
if (drt == System.Windows.Forms.DialogResult.OK)
{
if (addResultValue + "" == "")
autos.SetValueSilent(form.SubForm.Tag + "", "");
else
{
addResultValue = addResultValue.Replace("{value}", form.SubForm.Tag+"");
DataTable dt = SqlHelper.ExecuteDataSet(addResultValue).Tables[0];
if (dt != null)
autos.SetValueSilent(dt.Rows[0][0].ToString(), "");
}
}
}
}
}