init
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using DTS.Common.Classes.Groups;
|
||||
using DTS.Common.Interface.Groups;
|
||||
using DTS.Common.Strings;
|
||||
using GroupImport.Resources;
|
||||
|
||||
namespace GroupImport
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for GroupImportOptionsView.xaml
|
||||
/// </summary>
|
||||
public partial class GroupImportPreviewView : IGroupImportPreviewView
|
||||
{
|
||||
public GroupImportPreviewView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// handles when tb group name changes
|
||||
/// in this case the UI needs to be notified and the validity of the group name may change
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void GroupName_Changed(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
var tb = (TextBox)sender;
|
||||
|
||||
var group = (GroupGRPImportGroup)tb.DataContext;
|
||||
|
||||
group.GroupName = tb.Text;
|
||||
|
||||
foreach (var ch in group.Channels)
|
||||
{
|
||||
ch.GroupNameInvalidate();
|
||||
}
|
||||
|
||||
var vm = (GroupImportViewModel)DataContext;
|
||||
vm.CheckGroupName();
|
||||
}
|
||||
/// <summary>
|
||||
/// handles when tb group tag changes
|
||||
/// in this case the UI needs to be notified and the validity of the group tag may change
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void GroupTags_Changed(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
var tb = (TextBox)sender;
|
||||
|
||||
var group = (GroupGRPImportGroup)tb.DataContext;
|
||||
|
||||
group.GroupTags = tb.Text;
|
||||
}
|
||||
/// <summary>
|
||||
/// handles included checkbox being checked for a group
|
||||
/// in this case the channels for the group should be added to the UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void IncludedChecked(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
var vm = (GroupImportViewModel)DataContext;
|
||||
vm.InvalidateChannels();
|
||||
}
|
||||
/// <summary>
|
||||
/// handles the included checkbox being unchecked for a group
|
||||
/// in this case the channels for the group should be removed from the UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void IncludedUnchecked(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
var vm = (GroupImportViewModel)DataContext;
|
||||
vm.InvalidateChannels();
|
||||
}
|
||||
/// <summary>
|
||||
/// checks whether it is okay to proceed to import,
|
||||
/// checks the validity of the selected channels and groups
|
||||
/// </summary>
|
||||
/// <param name="userIsAdmin">whether or not the user has Administrator privileges</param>
|
||||
/// <param name="errors">any fatal errors that would prevent importing</param>
|
||||
/// <param name="warnings">any non fatal errors that the user needs to be warned about (but that don't prevent importing)</param>
|
||||
/// <returns>true if it is okay to proceed to import</returns>
|
||||
public bool Validate(bool userIsAdmin, out List<string> errors, out List<string> warnings)
|
||||
{
|
||||
errors = new List<string>();
|
||||
warnings = new List<string>();
|
||||
var bValid = true;
|
||||
|
||||
var vm = (GroupImportViewModel)DataContext;
|
||||
var bAnyValidChannels = false;
|
||||
if (vm.Groups.Any())
|
||||
{
|
||||
foreach (var g in vm.Groups)
|
||||
{
|
||||
if (!g.Included) { continue; }
|
||||
if (!string.IsNullOrWhiteSpace(g.GroupTags) && !userIsAdmin)
|
||||
{
|
||||
foreach (var userTag in g.ImportingUserTags.Split())
|
||||
{
|
||||
if (g.GroupTags.Split().Contains(userTag)) continue;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(string.Format(StringResources.PreviewGroups_WontSaveWithIncompatibleTags, userTag, g.GroupTags));
|
||||
sb.Append($"\r\n{StringResources.UserTags}");
|
||||
sb.Append(g.ImportingUserTags.Length == 0 ? StringResources.None : g.ImportingUserTags);
|
||||
//The static group in question will always have at least 1 Tag, otherwise there would be no problem
|
||||
sb.Append($"\r\n{StringResources.GroupTags}");
|
||||
sb.Append(g.GroupTags);
|
||||
|
||||
errors.Add(sb.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (g.GroupNameHasError)
|
||||
{
|
||||
var msg = string.Format(StringResources.Preview_InvalidName, g.GroupName);
|
||||
if (!errors.Contains(msg))
|
||||
{
|
||||
errors.Add(msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (null != g.GroupErrors && g.GroupErrors.Any())
|
||||
{
|
||||
foreach (var error in g.GroupErrors)
|
||||
{
|
||||
if (!errors.Contains(error.ExtraInfo))
|
||||
{
|
||||
errors.Add(error.ExtraInfo);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (vm.CheckGroupExists(g.GroupName) && !g.Overwrite)
|
||||
{
|
||||
var msg = string.Format(StringResources.Preview_InvalidName, g.GroupName);
|
||||
if (!errors.Contains(msg)) { errors.Add(msg); }
|
||||
return false;
|
||||
}
|
||||
bValid = false;
|
||||
foreach (var ch in g.Channels)
|
||||
{
|
||||
if (null != ch.Error)
|
||||
{
|
||||
switch (ch.Error.ErrorCode)
|
||||
{
|
||||
case GroupGRPImportError.Errors.FileEmpty:
|
||||
case GroupGRPImportError.Errors.InvalidISOCodeInput:
|
||||
bAnyValidChannels = true;
|
||||
break;
|
||||
case GroupGRPImportError.Errors.InvalidFullScaleInput:
|
||||
warnings.Add(string.Format(StringResources.Preview_InvalidFullScaleInput,
|
||||
g.GroupName, ch.DisplayName));
|
||||
bAnyValidChannels = true;
|
||||
break;
|
||||
case GroupGRPImportError.Errors.InvalidInvertInput:
|
||||
warnings.Add(string.Format(StringResources.Preview_InvalidSensorInput,
|
||||
g.GroupName,
|
||||
ch.DisplayName));
|
||||
bAnyValidChannels = true;
|
||||
break;
|
||||
case GroupGRPImportError.Errors.InvalidSensorInput:
|
||||
var msg = string.Format(StringResources.Preview_InvalidRow, g.GroupName);
|
||||
if (!warnings.Contains(msg))
|
||||
{
|
||||
warnings.Add(msg);
|
||||
}
|
||||
break;
|
||||
case GroupGRPImportError.Errors.SensorNotFound:
|
||||
warnings.Add(string.Format(StringResources.Preview_InvalidSensor, g.GroupName,
|
||||
ch.DisplayName));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bValid = true;
|
||||
bAnyValidChannels = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bAnyValidChannels)
|
||||
{
|
||||
errors.Add(StringResources.Preview_NoGroupsToImport);
|
||||
}
|
||||
return bValid;
|
||||
}
|
||||
errors.Add(StringResources.Preview_NoGroupsToImport);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user