90 lines
2.8 KiB
C#
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|