narsil/Tanshu.Accounts.Helpers/SelectWaiter.cs

110 lines
3.7 KiB
C#
Raw Normal View History

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;
using Tanshu.Accounts.Entities;
2010-03-02 17:56:21 +00:00
namespace Tanshu.Accounts.Helpers
{
public class SelectWaiter : Tanshu.Data.BaseSelector<Waiter>
2010-03-02 17:56:21 +00:00
{
public event WaiterEventHandler WaiterEvent;
public SelectWaiter(GetData<Waiter> getData, bool autoClose) : base(getData, true, "Select a Waiter")
2010-03-02 17:56:21 +00:00
{
var filters = new List<string> {"Name"};
2010-03-02 17:56:21 +00:00
SetFilterColumns(filters);
grid.Columns["WaiterID"].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;
}
protected override void UpdateDisplay(Waiter item)
2010-03-02 17:56:21 +00:00
{
DisplayLabel = item == null ? "" : string.Format("Waiter Name: {0}", item.Name);
2010-03-02 17:56:21 +00:00
}
protected override Waiter HandleKeydown(object sender, ExtendedKeyEventArgs e)
2010-03-02 17:56:21 +00:00
{
var waiter = bindingSource.Current as Waiter;
2010-03-02 17:56:21 +00:00
if (WaiterEvent == null)
2010-03-02 17:56:21 +00:00
{
e.Handled = false;
return waiter;
}
var eventArgs = new SelectorEventArgs<Waiter>(null,SelectorAction.Insert);
2010-03-02 17:56:21 +00:00
switch (e.KeyCode)
{
case Keys.F1:
{
waiter = new Waiter { Name = base.filterColumns["Name"].Trim() };
eventArgs = new SelectorEventArgs<Waiter>(waiter,SelectorAction.Insert);
2010-03-02 17:56:21 +00:00
break;
}
case Keys.F2:
{
if (waiter != null)
waiter.Name = base.filterColumns["Name"].Trim();
eventArgs = new SelectorEventArgs<Waiter>(waiter, SelectorAction.Update);
2010-03-02 17:56:21 +00:00
break;
}
case Keys.F8:
{
if (waiter != null)
eventArgs = new SelectorEventArgs<Waiter>(waiter, SelectorAction.Delete);
2010-03-02 17:56:21 +00:00
break;
}
}
if ((waiter != null) && ((e.KeyCode == Keys.F1) || (e.KeyCode == Keys.F2) || (e.KeyCode == Keys.F8)))
waiter = WaiterEvent(sender, eventArgs);
2010-03-02 17:56:21 +00:00
e.Handled = eventArgs.Handled;
return waiter;
}
#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 Waiter WaiterEventHandler(object sender, SelectorEventArgs<Waiter> e);
2010-03-02 17:56:21 +00:00
}