narsil/Tanshu.Accounts.Helpers/SelectCustomer.cs

103 lines
3.2 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tanshu.Data;
using Tanshu.Accounts.Entities;
2010-03-02 17:56:21 +00:00
namespace Tanshu.Accounts.Helpers
{
public class SelectCustomer : Tanshu.Data.BaseSelector<Customer>
2010-03-02 17:56:21 +00:00
{
public event CustomerEventHandler CustomerEvent;
public SelectCustomer(GetData<Customer> getData, bool autoClose) : base(getData, true, "List of Products")
2010-03-02 17:56:21 +00:00
{
var filters = new List<string> {"Universal"};
2010-03-02 17:56:21 +00:00
SetFilterColumns(filters);
grid.Columns["CustomerID"].Visible = false;
}
protected override void FilterChanged(Dictionary<string, string> filter)
{
//data = new CustomerBI().GetFilteredCustomers(filter["Universal"].Split(' ')).ToList();
data = getData(filter);
bindingSource.DataSource = data;
}
protected override void UpdateDisplay(Customer item)
2010-03-02 17:56:21 +00:00
{
DisplayLabel = item == null ? "" : string.Format("Chosen Customer is {0} with phone number {1}", item.Name, item.Phone);
2010-03-02 17:56:21 +00:00
}
protected override Customer HandleKeydown(object sender, ExtendedKeyEventArgs e)
2010-03-02 17:56:21 +00:00
{
var customer = bindingSource.Current as Customer;
2010-03-02 17:56:21 +00:00
if (CustomerEvent == null)
2010-03-02 17:56:21 +00:00
{
e.Handled = false;
return customer;
}
int? id = null;
2010-03-02 17:56:21 +00:00
if ((customer != null) && (e.KeyCode == Keys.F2))
id = customer.CustomerID;
if ((e.KeyCode == Keys.F1) || (e.KeyCode == Keys.F2))
{
customer = CustomerEvent(sender, new CustomerEventArgs(id, base.filterColumns["Universal"]));
2010-03-02 17:56:21 +00:00
e.Handled = customer != null;
}
return customer;
}
#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
}
public delegate Customer CustomerEventHandler(object sender, CustomerEventArgs e);
2010-03-02 17:56:21 +00:00
public class CustomerEventArgs : EventArgs
{
public CustomerEventArgs(int? customerID, string phone)
2010-03-02 17:56:21 +00:00
{
CustomerID = customerID;
Phone = phone;
}
public int? CustomerID
2010-03-02 17:56:21 +00:00
{
get;
private set;
}
public string Phone
{
get;
private set;
}
}
}