narsil/Tanshu.Accounts.Helpers/SelectCustomer.cs

114 lines
3.6 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.Repository;
using Tanshu.Data;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Helpers
{
public class SelectCustomer : Tanshu.Data.BaseSelector<Customer>
{
public event CustomerEventHandler customerEvent;
public SelectCustomer(GetData<Customer> 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(Customer item)
{
if (item == null)
DisplayLabel = "";
else
DisplayLabel = string.Format("Chosen Customer is {0} with phone number {1}", item.Name, item.Phone);
}
protected override Customer HandleKeydown(object sender, ExtendedKeyEventArgs e)
{
Customer customer = bindingSource.Current as Customer;
if (customerEvent == null)
{
e.Handled = false;
return customer;
}
int? 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 Customer CustomerEventHandler(object sender, CustomerEventArgs e);
public class CustomerEventArgs : EventArgs
{
public CustomerEventArgs(int? customerID, string phone)
{
CustomerID = customerID;
Phone = phone;
}
public int? CustomerID
{
get;
private set;
}
public string Phone
{
get;
private set;
}
}
}