2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
using Tanshu.Data;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Helpers
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public class SelectUser : Tanshu.Data.BaseSelector<User>
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
public event UserEventHandler UserEvent;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public SelectUser(GetData<User> getData, bool autoClose) : base (getData, true, "Select a User")
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var filters = new List<string> {"Name"};
|
2010-03-02 17:56:21 +00:00
|
|
|
|
SetFilterColumns(filters);
|
|
|
|
|
grid.Columns["UserID"].Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void FilterChanged(Dictionary<string, string> filter)
|
|
|
|
|
{
|
|
|
|
|
//data = originalData.Where(d => d.Name.ToLower().Contains(filter["Name"].ToLower())).ToList();
|
|
|
|
|
data = getData(filter);
|
|
|
|
|
bindingSource.DataSource = data;
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
protected override void UpdateDisplay(User item)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
DisplayLabel = item == null ? "" : string.Format("User Name: {0}", item.Name);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
protected override User HandleKeydown(object sender, ExtendedKeyEventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var user = bindingSource.Current as User;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
if (UserEvent == null)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
e.Handled = false;
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
if ((e.KeyCode != Keys.F1) && (e.KeyCode != Keys.F2))
|
|
|
|
|
{
|
|
|
|
|
e.Handled = false;
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
if ((user == null) && (e.KeyCode == Keys.F2))
|
|
|
|
|
{
|
|
|
|
|
e.Handled = false;
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.KeyCode == Keys.F1)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
user = new User();
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var userEventArgs = new UserEventArgs(user);
|
|
|
|
|
user = UserEvent(sender, userEventArgs);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
e.Handled = userEventArgs.Handled;
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
#region Designer Code
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required designer variable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private System.ComponentModel.IContainer components = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clean up any resources being used.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing && (components != null))
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
|
|
|
|
}
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Windows Form Designer generated code
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required method for Designer support - do not modify
|
|
|
|
|
/// the contents of this method with the code editor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
|
|
|
|
this.components = new System.ComponentModel.Container();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public delegate User UserEventHandler(object sender, UserEventArgs e);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
public class UserEventArgs : EventArgs
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public UserEventArgs(User user)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
Handled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public User User
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Handled
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|