87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using System.Data;
|
|
using YLErp.Modules;
|
|
|
|
namespace YLErp.Forms
|
|
{
|
|
public partial class FormSelectClient : Form
|
|
{
|
|
public FormSelectClient()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public string SelectedClient { get; private set; }
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
var clients = DataCacheProvider.GetClientDataSource().AsQueryable()
|
|
.Select(n => new ListViewItem { Text = n.Name + "# " + n.id }).ToArray();
|
|
listView1.Items.AddRange(clients);
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
var search = tbSearch.Text.Trim();
|
|
var query = DataCacheProvider.GetClientDataSource().AsQueryable();
|
|
if (!string.IsNullOrEmpty(search))
|
|
{
|
|
query = query.Where(n => n.Name != null && n.Name.Contains(search));
|
|
}
|
|
var clients = query.Select(n => new ListViewItem { Text = n.Name + "# " + n.id }).ToArray();
|
|
listView1.Items.Clear();
|
|
listView1.Items.AddRange(clients);
|
|
}
|
|
|
|
private void btnSelect_Click(object sender, EventArgs e)
|
|
{
|
|
if (listView1.CheckedItems.Count > 0)
|
|
{
|
|
var si = listView1.CheckedItems[0];
|
|
var index = si.Text.LastIndexOf("# ");
|
|
SelectedClient = si.Text.Substring(0, index);
|
|
}
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
|
|
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
|
|
{
|
|
if (!e.Item.Checked) return;
|
|
|
|
if (!e.Item.Selected)
|
|
{
|
|
e.Item.Selected = true;
|
|
}
|
|
|
|
if (listView1.CheckedItems.Count > 1)
|
|
{
|
|
foreach (ListViewItem item in listView1.CheckedItems)
|
|
{
|
|
if (item != e.Item)
|
|
{
|
|
item.Checked = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"[select]{e.IsSelected} -- {e.Item.Text}");
|
|
|
|
if (e.IsSelected && !e.Item.Checked)
|
|
{
|
|
e.Item.Checked = true;
|
|
}
|
|
}
|
|
|
|
private void tbSearch_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if(e.KeyCode == Keys.Enter)
|
|
{
|
|
btnSearch.PerformClick();
|
|
}
|
|
}
|
|
}
|
|
}
|