Compare commits
3 Commits
v7.2.14.1_
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| d8c3578144 | |||
| 905a3cc636 | |||
| 3cfd642f66 |
@ -838,7 +838,6 @@ namespace ENI2
|
||||
{
|
||||
List<MessageViolation> vViolations = new List<MessageViolation>();
|
||||
List<MessageError> vErrors = new List<MessageError>();
|
||||
Dictionary<Message, MessageValidationCounts> counts = new Dictionary<Message, MessageValidationCounts>();
|
||||
|
||||
RuleEngine ruleEngine = new RuleEngine();
|
||||
foreach (Message aMessage in messagesSnapshot)
|
||||
@ -849,14 +848,6 @@ namespace ENI2
|
||||
List<MessageViolation> violations = new List<MessageViolation>();
|
||||
ruleEngine.ValidateMessage(aMessage, out errors, out violations);
|
||||
|
||||
MessageValidationCounts messageCounts = new MessageValidationCounts
|
||||
{
|
||||
ErrorCount = errors.Count > 0 ? (int?)errors.Count : null,
|
||||
ViolationCount = violations.Count > 0 ? (int?)violations.Count : null,
|
||||
PositionViolationCount = violations.Count > 0 ? (int?)violations.Count(v => !v.Identifier.IsNullOrEmpty()) : null
|
||||
};
|
||||
counts[aMessage] = messageCounts;
|
||||
|
||||
string messageGroup = this.MessageGroupForMessage(aMessage);
|
||||
|
||||
if (messageGroup != null)
|
||||
@ -1267,7 +1258,7 @@ namespace ENI2
|
||||
case 401:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.5)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1285,7 +1276,7 @@ namespace ENI2
|
||||
case 511:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.25)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1294,7 +1285,7 @@ namespace ENI2
|
||||
case 602:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.75)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1315,7 +1306,7 @@ namespace ENI2
|
||||
case 105:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.25)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1323,7 +1314,7 @@ namespace ENI2
|
||||
case 401:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.5)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1341,7 +1332,7 @@ namespace ENI2
|
||||
case 511:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.2)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1350,7 +1341,7 @@ namespace ENI2
|
||||
case 602:
|
||||
if (waste.WasteAmountRetained_MTQ > waste.WasteCapacity_MTQ * 0.25)
|
||||
{
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "WAS", waste.Identifier, "WAS");
|
||||
MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Acc. to EU Regulation 2022/89 the amount retained on board is noticeably", null, "Waste", waste.Identifier, was.Tablename);
|
||||
mv.MessageGroupName = wasMessageGroup;
|
||||
vViolations.Add(mv);
|
||||
}
|
||||
@ -1393,9 +1384,70 @@ namespace ENI2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Recompute per-message counts after all global validations
|
||||
Dictionary<Message, MessageValidationCounts> counts = new Dictionary<Message, MessageValidationCounts>();
|
||||
|
||||
int assignViolationCounter = 0;
|
||||
int assignErrorCounter = 0;
|
||||
|
||||
List<MessageViolation> tmpVList = new List<MessageViolation>(vViolations);
|
||||
List<MessageError> tmpEList = new List<MessageError>(vErrors);
|
||||
|
||||
foreach (Message aMessage in messagesSnapshot)
|
||||
{
|
||||
counts[aMessage] = new MessageValidationCounts();
|
||||
counts[aMessage].ErrorCount = tmpEList.Count(me => me.NotificationClass == aMessage.MessageNotificationClassDisplay); // generic
|
||||
// special cases
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.WAS_RCPT) && (me.NotificationClass == "WasteReceived"));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IMDGPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IGCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IBCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IMSBCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "MARPOL_Annex_I_Position") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IMDGPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IGCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IBCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IMSBCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "MARPOL_Annex_I_Position") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.WAS) && (me.NotificationClass == "Waste"));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) && (me.NotificationClass == "LastTenPortFacilitiesCalled"));
|
||||
counts[aMessage].ErrorCount += tmpEList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) && (me.NotificationClass == "ShipToShipActivitiesDuringLastTenPortFacilitiesCalled"));
|
||||
|
||||
if (counts[aMessage].ErrorCount == 0) counts[aMessage].ErrorCount = null; // set to empty if nothing counted
|
||||
assignErrorCounter += counts[aMessage].ErrorCount ?? 0;
|
||||
|
||||
counts[aMessage].ViolationCount = vViolations.Count(mv => mv.NotificationClass == aMessage.MessageNotificationClassDisplay); // generic
|
||||
// special cases
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.WAS_RCPT) && (me.NotificationClass == "WasteReceived"));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IMDGPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IGCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IBCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "IMSBCPosition") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) && (me.NotificationClass == "MARPOL_Annex_I_Position") && me.MessageGroupName.Contains("arrival", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IMDGPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IGCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IBCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "IMSBCPosition") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) && (me.NotificationClass == "MARPOL_Annex_I_Position") && me.MessageGroupName.Contains("departure", StringComparison.OrdinalIgnoreCase));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.WAS) && (me.NotificationClass == "Waste"));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) && (me.NotificationClass == "LastTenPortFacilitiesCalled"));
|
||||
counts[aMessage].ViolationCount += tmpVList.Count(me => (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) && (me.NotificationClass == "ShipToShipActivitiesDuringLastTenPortFacilitiesCalled"));
|
||||
|
||||
if (counts[aMessage].ViolationCount == 0) counts[aMessage].ViolationCount = null;
|
||||
|
||||
assignViolationCounter += counts[aMessage].ViolationCount ?? 0;
|
||||
}
|
||||
|
||||
|
||||
Trace.WriteLine(string.Format("Unassigned errors: {0}, unassigned violations: {1}", vErrors.Count - assignErrorCounter, vViolations.Count - assignViolationCounter));
|
||||
|
||||
|
||||
return new ValidationResult(vViolations, vErrors, counts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ApplyValidationResult(ValidationResult result, bool showMessages)
|
||||
{
|
||||
// TODO: clear highlighting
|
||||
@ -1405,7 +1457,6 @@ namespace ENI2
|
||||
MessageValidationCounts messageCounts = entry.Value;
|
||||
aMessage.ErrorCount = messageCounts.ErrorCount;
|
||||
aMessage.ViolationCount = messageCounts.ViolationCount;
|
||||
aMessage.PositionViolationCount = messageCounts.PositionViolationCount;
|
||||
}
|
||||
|
||||
foreach (MessageError me in result.Errors)
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
using bsmd.database;
|
||||
using ClosedXML.Excel;
|
||||
using ENI2.EditControls;
|
||||
using ENI2.Excel;
|
||||
using ENI2.Util;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
@ -479,87 +480,13 @@ namespace ENI2.DetailViewControls
|
||||
|
||||
private void buttonImportFromExcel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "Excel Files|*.xls;*.xlsx";
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
int importWasteListCnt = ExcelLocalImportHelper.ImportWaste(_was);
|
||||
|
||||
if (importWasteListCnt > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
using (var workbook = new XLWorkbook(stream))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(3); // Skip first three rows
|
||||
|
||||
List<Waste> importWasteList = new List<Waste>();
|
||||
|
||||
int cnt = 0;
|
||||
object o = null;
|
||||
|
||||
// Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen!
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (cnt >= 35) break; // Maximum 35 rows
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 9)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 9 Columns of data");
|
||||
}
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) o = row.Cell(2).Value; else o = null;
|
||||
if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType))
|
||||
{
|
||||
Waste waste = _was.GetWasteForType(wasteType);
|
||||
if (waste == null)
|
||||
{
|
||||
waste = new Waste();
|
||||
waste.WasteType = wasteType;
|
||||
waste.WAS = this._was;
|
||||
waste.IsDirty = true;
|
||||
waste.Identifier = Waste.GetNewIdentifier(this._was.Waste);
|
||||
this._was.Waste.Add(waste);
|
||||
}
|
||||
else
|
||||
{
|
||||
waste.IsDirty = true;
|
||||
}
|
||||
|
||||
if (!row.Cell(5).IsEmpty()) waste.WasteDescription = row.Cell(5).GetString();
|
||||
if (waste.WasteDescription.IsNullOrEmpty())
|
||||
waste.WasteDescription = "-";
|
||||
|
||||
if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value; else o = null;
|
||||
if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value; else o = null;
|
||||
if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value; else o = null;
|
||||
if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(9).IsEmpty()) waste.WasteDisposalPort = row.Cell(9).GetString().ToUpper();
|
||||
|
||||
if (!row.Cell(10).IsEmpty()) o = row.Cell(10).Value; else o = null;
|
||||
if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o);
|
||||
|
||||
importWasteList.Add(waste);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (importWasteList.Count > 0)
|
||||
{
|
||||
this.dataGridWaste.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.WAS);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
this.dataGridWaste.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.WAS);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteListCnt), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
<MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion>
|
||||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>publish.html</WebPage>
|
||||
<ApplicationRevision>1</ApplicationRevision>
|
||||
<ApplicationVersion>7.2.14.1</ApplicationVersion>
|
||||
<ApplicationRevision>2</ApplicationRevision>
|
||||
<ApplicationVersion>7.2.14.2</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
|
||||
@ -4,6 +4,7 @@ using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace ENI2.Excel
|
||||
@ -244,5 +245,89 @@ namespace ENI2.Excel
|
||||
|
||||
#endregion
|
||||
|
||||
#region Waste from Excel
|
||||
|
||||
public static int ImportWaste(WAS was)
|
||||
{
|
||||
int cnt = 0;
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "Excel Files|*.xls;*.xlsx";
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
using (var workbook = new XLWorkbook(stream))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(3); // Skip first three rows
|
||||
|
||||
List<Waste> importWasteList = new List<Waste>();
|
||||
|
||||
object o = null;
|
||||
|
||||
// Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen!
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (cnt >= 35) break; // Maximum 35 rows
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 9)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 9 Columns of data");
|
||||
}
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) o = row.Cell(2).Value; else o = null;
|
||||
if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType))
|
||||
{
|
||||
Waste waste = was.GetWasteForType(wasteType);
|
||||
if (waste == null)
|
||||
{
|
||||
waste = new Waste();
|
||||
waste.WasteType = wasteType;
|
||||
waste.WAS = was;
|
||||
waste.IsDirty = true;
|
||||
waste.Identifier = Waste.GetNewIdentifier(was.Waste);
|
||||
was.Waste.Add(waste);
|
||||
}
|
||||
else
|
||||
{
|
||||
waste.IsDirty = true;
|
||||
}
|
||||
|
||||
if (!row.Cell(5).IsEmpty()) waste.WasteDescription = row.Cell(5).GetString();
|
||||
if (waste.WasteDescription.IsNullOrEmpty())
|
||||
waste.WasteDescription = "-";
|
||||
|
||||
if (!row.Cell(6).IsEmpty())
|
||||
waste.WasteDisposalAmount_MTQ = row.Cell(6).GetDouble();
|
||||
|
||||
if (!row.Cell(7).IsEmpty())
|
||||
waste.WasteCapacity_MTQ = row.Cell(7).GetDouble();
|
||||
|
||||
if (!row.Cell(8).IsEmpty()) waste.WasteAmountRetained_MTQ = row.Cell(8).GetDouble();
|
||||
|
||||
if (!row.Cell(9).IsEmpty())
|
||||
waste.WasteDisposalPort = row.Cell(9).GetString().ToUpper();
|
||||
|
||||
if (!row.Cell(10).IsEmpty())
|
||||
waste.WasteAmountGeneratedTillNextPort_MTQ = row.Cell(10).GetDouble();
|
||||
|
||||
importWasteList.Add(waste);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
using bsmd.database;
|
||||
using ClosedXML.Excel;
|
||||
using ENI2.EditControls;
|
||||
using ENI2.Excel;
|
||||
using Microsoft.Win32;
|
||||
|
||||
using System;
|
||||
@ -514,88 +515,13 @@ namespace ENI2.SheetDisplayControls
|
||||
|
||||
private void buttonImportFromExcel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "Excel Files|*.xls;*.xlsx";
|
||||
if (ofd.ShowDialog() ?? false)
|
||||
int importWasteListCnt = ExcelLocalImportHelper.ImportWaste(_was);
|
||||
|
||||
if (importWasteListCnt > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
using (var workbook = new XLWorkbook(stream))
|
||||
{
|
||||
var worksheet = workbook.Worksheet(1); // Get first worksheet
|
||||
var rows = worksheet.RangeUsed().RowsUsed().Skip(3); // Skip first three rows
|
||||
|
||||
List<Waste> importWasteList = new List<Waste>();
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
// Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen!
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (cnt >= 35) break; // Maximum 35 rows
|
||||
|
||||
if (worksheet.RangeUsed().ColumnCount() < 9)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have 9 Columns of data");
|
||||
}
|
||||
|
||||
object o = null;
|
||||
|
||||
if (!row.Cell(2).IsEmpty()) o = row.Cell(2).Value; else o = null;
|
||||
if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType))
|
||||
{
|
||||
Waste waste = _was.GetWasteForType(wasteType);
|
||||
if (waste == null)
|
||||
{
|
||||
waste = new Waste();
|
||||
waste.WasteType = wasteType;
|
||||
waste.WAS = this._was;
|
||||
waste.IsDirty = true;
|
||||
waste.Identifier = Waste.GetNewIdentifier(this._was.Waste);
|
||||
this._was.Waste.Add(waste);
|
||||
}
|
||||
else
|
||||
{
|
||||
waste.IsDirty = true;
|
||||
}
|
||||
|
||||
if (!row.Cell(5).IsEmpty()) waste.WasteDescription = row.Cell(5).GetString();
|
||||
if (waste.WasteDescription.IsNullOrEmpty())
|
||||
waste.WasteDescription = "-";
|
||||
|
||||
if (!row.Cell(6).IsEmpty()) o = row.Cell(6).Value; else o = null;
|
||||
if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(7).IsEmpty()) o = row.Cell(7).Value; else o = null;
|
||||
if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(8).IsEmpty()) o = row.Cell(8).Value; else o = null;
|
||||
if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o);
|
||||
|
||||
if (!row.Cell(9).IsEmpty()) waste.WasteDisposalPort = row.Cell(9).GetString().ToUpper();
|
||||
|
||||
if (!row.Cell(10).IsEmpty()) o = row.Cell(10).Value; else o = null;
|
||||
if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o);
|
||||
|
||||
importWasteList.Add(waste);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (importWasteList.Count > 0)
|
||||
{
|
||||
this.dataGridWaste.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.WAS);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
this.dataGridWaste.Items.Refresh();
|
||||
this.SublistElementChanged(Message.NotificationClass.WAS);
|
||||
MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteListCnt), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -431,11 +431,6 @@ namespace bsmd.database
|
||||
/// </summary>
|
||||
public int? ViolationCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of violations during last validation that have the "identifier" set and are thus detected violations
|
||||
/// from underlying list elements
|
||||
/// </summary>
|
||||
public int? PositionViolationCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of errors during last validation
|
||||
|
||||
Loading…
Reference in New Issue
Block a user