93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using SharedDatabase.Entities;
|
|
using OrderManagement.Resources;
|
|
using NHibernate;
|
|
|
|
namespace OrderManagement
|
|
{
|
|
public partial class EditOrderDlg : Form
|
|
{
|
|
ISession session;
|
|
OrderInfo order;
|
|
IList<OrderInfo> listOfOrders;
|
|
bool editMode;
|
|
string oriPOName;
|
|
|
|
EditParametersCtrl editParametersCtrl;
|
|
|
|
public EditOrderDlg(ISession session, OrderInfo order, IList<OrderInfo> listOfOrders, bool editMode = false)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.session = session;
|
|
this.order = order;
|
|
this.listOfOrders = listOfOrders;
|
|
this.editMode = editMode;
|
|
oriPOName = order.POName;
|
|
|
|
editParametersCtrl = new EditParametersCtrl(this.order);
|
|
editParametersCtrl.Dock = DockStyle.Fill;
|
|
editParametersCtrl.Unlock();
|
|
splitContainer1.Panel1.Controls.Add(editParametersCtrl);
|
|
|
|
Localize();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
okButton.Text = Strings.OK;
|
|
cancelButton.Text = Strings.Cancel;
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
OrderInfo orderWithTheSameName = listOfOrders.FirstOrDefault(x => (x.POName == order.POName));
|
|
|
|
if (orderWithTheSameName != null && (!editMode || order.POName != oriPOName))
|
|
{
|
|
MessageBox.Show(Strings.Order_with_the_same_ID_already_exists);
|
|
return;
|
|
}
|
|
|
|
DialogResult = Save() ? DialogResult.OK : DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
bool Save()
|
|
{
|
|
ITransaction transaction = session.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
session.SaveOrUpdate(order);
|
|
transaction.Commit();
|
|
session.Flush();
|
|
Cursor.Current = Cursors.Default;
|
|
return true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
transaction.Rollback();
|
|
MessageBox.Show(string.Format("{0}{1}{2}", Strings.Saving_order_failed, Environment.NewLine, exc.Message),
|
|
Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
Cursor.Current = Cursors.Default;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|