narsil/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs
tanshu caf9b3106c Feature: Added Machine Locations so that setting the location in the config file is not needed.
Feature: Settings database table added to store string based settings.
         It is right now used to store bill header and footer.
         Hard Coded header/footer removed from file.
Feature: Tax Analysis form created to easily show the tax calculation.
Feature: Management form uses background workers.  Dont' know if it is functional though.
Chore: Reorder Table form moved to masters from sales folder.
Refactor: ManagementBI and SalesAnalysisBI
2016-01-04 10:52:01 +05:30

90 lines
2.8 KiB
C#

using System;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
using System.Linq;
using System.Collections.Generic;
namespace Tanshu.Accounts.PointOfSale
{
public partial class MachineEditForm : Form
{
private Guid? _machineLocationID;
private string _machineName;
public MachineEditForm(Guid machineLocationID)
: this()
{
_machineLocationID = machineLocationID;
}
public MachineEditForm(string machineName)
: this()
{
_machineName = machineName;
}
public MachineEditForm()
{
InitializeComponent();
}
private void MachineEditForm_Load(object sender, EventArgs e)
{
MachineLocation machineLocation;
using (var bi = new MachineLocationBI())
{
bsLocations.DataSource = bi.LocationList();
if (_machineLocationID.HasValue)
{
machineLocation = bi.Get(x => x.MachineLocationID == _machineLocationID.Value);
txtMachine.Text = machineLocation.Machine;
cmbLocation.SelectedItem = machineLocation.Location;
txtMachine.Focus();
}
else if (!string.IsNullOrEmpty(_machineName))
{
txtMachine.Text = _machineName;
txtMachine.ReadOnly = true;
cmbLocation.Focus();
}
else
{
txtMachine.Focus();
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
MachineLocation machineLocation;
using (var bi = new MachineLocationBI())
{
if (_machineLocationID.HasValue)
machineLocation = bi.Get(x => x.MachineLocationID == _machineLocationID.Value);
else
machineLocation = new MachineLocation();
if (string.IsNullOrEmpty(txtMachine.Text.Trim()))
return;
machineLocation.Machine = txtMachine.Text.Trim();
var location = (string)cmbLocation.SelectedItem;
if (string.IsNullOrEmpty(location))
return;
machineLocation.Location = location;
if (_machineLocationID.HasValue)
bi.Update(machineLocation);
else
bi.Insert(machineLocation);
bi.SaveChanges();
}
MessageBox.Show("Update / Save Successful");
this.Close();
}
}
}