narsil/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.cs

75 lines
2.0 KiB
C#

using System;
using System.Linq;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Repository;
using System.Collections.Generic;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.PointOfSale
{
public partial class CustomerListForm : Form
{
private IList<Customer> _list;
public CustomerListForm()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
using (var frm = new CustomerForm(null))
frm.ShowDialog();
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void CustomerListForm_Load(object sender, EventArgs e)
{
ShowGrid();
}
private void ShowGrid()
{
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void btnEdit_Click(object sender, EventArgs e)
{
var id = ((Customer)bsList.Current).CustomerID;
using (var frm = new CustomerForm(id))
frm.ShowDialog();
using (var bi = new CustomerBI())
_list = bi.List();
bsList.DataSource = _list;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
public Customer SelectedItem
{
get
{
if (bsList.Position >= 0)
{
var item = _list[bsList.Position];
if (item != null)
return item;
}
return _list.First(x => x.CustomerID == Constants.CASH_CUSTOMER);
}
}
private void dgvCustomers_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
this.Close();
}
}
}