narsil/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs

83 lines
2.5 KiB
C#
Raw Normal View History

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;
2018-08-24 10:41:33 +00:00
bsLocations.DataSource = LocationBI.List();
if (_machineLocationID.HasValue)
{
2018-08-24 10:41:33 +00:00
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;
2018-08-24 10:41:33 +00:00
if (_machineLocationID.HasValue)
machineLocation = MachineLocationBI.Get(_machineLocationID.Value);
else
machineLocation = new MachineLocation();
2018-08-24 10:41:33 +00:00
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();
}
}
}