narsil/Tanshu.Accounts.Helpers/SelectCustomer.cs
2010-03-02 23:26:21 +05:30

113 lines
3.5 KiB
C#

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.Accounts.BI;
using Tanshu.Data;
namespace Tanshu.Accounts.Helpers
{
public class SelectCustomer : Tanshu.Data.BaseSelector<CustomerBO>
{
public event CustomerEventHandler customerEvent;
public SelectCustomer(GetData<CustomerBO> getData, bool autoClose) : base(getData, true, "List of Products")
{
List<string> filters = new List<string>();
filters.Add("Universal");
SetFilterColumns(filters);
grid.Columns["CustomerID"].Visible = false;
grid.Columns["LedgerID"].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(CustomerBO item)
{
if (item == null)
DisplayLabel = "";
else
DisplayLabel = string.Format("Chosen Customer is {0} with phone number {1}", item.Name, item.Phone);
}
protected override CustomerBO HandleKeydown(object sender, ExtendedKeyEventArgs e)
{
CustomerBO customer = bindingSource.Current as CustomerBO;
if (customerEvent == null)
{
e.Handled = false;
return customer;
}
Guid? id = null;
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"]));
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 CustomerBO CustomerEventHandler(object sender, CustomerEventArgs e);
public class CustomerEventArgs : EventArgs
{
public CustomerEventArgs(Guid? customerID, string phone)
{
CustomerID = customerID;
Phone = phone;
}
public Guid? CustomerID
{
get;
private set;
}
public string Phone
{
get;
private set;
}
}
}