narsil/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs
2018-08-24 16:11:33 +05:30

83 lines
2.5 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;
bsLocations.DataSource = LocationBI.List();
if (_machineLocationID.HasValue)
{
machineLocation = MachineLocationBI.Get(_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;
if (_machineLocationID.HasValue)
machineLocation = MachineLocationBI.Get(_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)
MachineLocationBI.Update(machineLocation);
else
MachineLocationBI.Insert(machineLocation);
MessageBox.Show("Update / Save Successful");
this.Close();
}
}
}