narsil/Tanshu.Accounts.Helpers/SelectCustomer.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

103 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
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")
{
var filters = new List<string> {"Universal"};
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)
{
DisplayLabel = item == null ? "" : string.Format("Chosen Customer is {0} with phone number {1}", item.Name, item.Phone);
}
protected override Customer HandleKeydown(object sender, ExtendedKeyEventArgs e)
{
var customer = bindingSource.Current as Customer;
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 Customer 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;
}
}
}