Add window, user group filtering and minor change
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.DirectoryServices;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace wpf_ax_utility
|
||||
{
|
||||
@@ -15,8 +17,35 @@ namespace wpf_ax_utility
|
||||
{
|
||||
public App()
|
||||
{
|
||||
// TODO: Verifica se l'utente fa parte di GG IT, in caso yes fai apparire una pagina, in caso no ne fai apparire un'altra
|
||||
this.StartupUri = new Uri("/wpf_ax_utility;component/MainWindow.xaml", UriKind.Relative);
|
||||
string userName = WindowsIdentity.GetCurrent().Name.Replace("PAL\\", "");
|
||||
var userGroups = GetGroups(userName);
|
||||
|
||||
var uriString = "/wpf_ax_utility;component/UserWindow.xaml";
|
||||
|
||||
if (userGroups.Contains("PAL\\BRAIN FORCE - AX DEV ADMINS") || userGroups.Contains("PAL\\PAL GG ITe"))
|
||||
{
|
||||
uriString = "/wpf_ax_utility;component/MainWindow.xaml";
|
||||
}
|
||||
|
||||
this.StartupUri = new Uri(uriString, UriKind.Relative);
|
||||
}
|
||||
|
||||
private List<string> GetGroups(string userName)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
WindowsIdentity wi = new WindowsIdentity(userName);
|
||||
|
||||
foreach (IdentityReference group in wi.Groups)
|
||||
{
|
||||
try
|
||||
{
|
||||
result.Add(group.Translate(typeof(NTAccount)).ToString());
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
result.Sort();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,36 +59,46 @@
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="LIVE"
|
||||
Click="ButtonClicked"
|
||||
Height="115" Width="320"
|
||||
Height="115" Width="325"
|
||||
Content="LIVE"
|
||||
FontSize="36"/>
|
||||
FontSize="36"
|
||||
Background="LightGray"/>
|
||||
<DockPanel HorizontalAlignment="Center"
|
||||
Margin="0,10,0,0">
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="LIVE02"
|
||||
Click="ButtonClicked"
|
||||
Height="45" Width="75"
|
||||
Margin="0,0,5,0"
|
||||
Content="LIVE 02"
|
||||
FontSize="16"
|
||||
FontWeight="DemiBold"
|
||||
Background="LightGray"/>
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="DEV"
|
||||
Click="ButtonClicked"
|
||||
Height="45" Width="100"
|
||||
Height="45" Width="75"
|
||||
Margin="0,0,5,0"
|
||||
Content="DEV"
|
||||
FontSize="18"
|
||||
FontSize="16"
|
||||
FontWeight="DemiBold"
|
||||
Background="#00FF80"/>
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="TEST"
|
||||
Click="ButtonClicked"
|
||||
Height="45" Width="100"
|
||||
Height="45" Width="75"
|
||||
Margin="5,0,5,0"
|
||||
Content="TEST"
|
||||
FontSize="18"
|
||||
FontSize="16"
|
||||
FontWeight="DemiBold"
|
||||
Background="#8080FF"/>
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="STAGING"
|
||||
Click="ButtonClicked"
|
||||
Height="45" Width="100"
|
||||
Height="45" Width="75"
|
||||
Margin="5,0,0,0"
|
||||
Content="STAGING"
|
||||
FontSize="18"
|
||||
FontSize="16"
|
||||
FontWeight="DemiBold"
|
||||
Background="#FFFF00"/>
|
||||
</DockPanel>
|
||||
|
||||
@@ -27,12 +27,14 @@ namespace wpf_ax_utility
|
||||
{
|
||||
AucCleaner();
|
||||
|
||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
||||
string AxArgs = string.Empty;
|
||||
|
||||
switch (((Button)sender).Name)
|
||||
{
|
||||
case "LIVE":
|
||||
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_USR.axc";
|
||||
break;
|
||||
case "LIVE02":
|
||||
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_02_USR.axc";
|
||||
break;
|
||||
case "DEV":
|
||||
@@ -46,11 +48,13 @@ namespace wpf_ax_utility
|
||||
break; ;
|
||||
}
|
||||
|
||||
AxExecution(AxClient, AxArgs);
|
||||
AxExecution(AxArgs);
|
||||
}
|
||||
|
||||
public static void AxExecution(string AxClient, string AxArgs)
|
||||
public static void AxExecution(string AxArgs)
|
||||
{
|
||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
||||
|
||||
if (System.IO.File.Exists(AxClient))
|
||||
{
|
||||
var p = new System.Diagnostics.Process();
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<Window x:Class="wpf_ax_utility.UserWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
MouseLeftButtonDown="MouseLeftDrag"
|
||||
Height="260" Width="400"
|
||||
ResizeMode="NoResize"
|
||||
WindowStyle="None"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent"
|
||||
Title="PAL Ax Utility"
|
||||
Icon="/axlogo.ico">
|
||||
|
||||
<Window.Resources>
|
||||
<Style TargetType="Button" x:Key="TabButton">
|
||||
<Setter Property="Background" Value="White"/>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
<Style.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="3"/>
|
||||
</Style>
|
||||
</Style.Resources>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Border BorderBrush="#0082C4" BorderThickness="1.5" CornerRadius="10" Background="White">
|
||||
<StackPanel>
|
||||
<DockPanel>
|
||||
<Border Height="25" Width="25" CornerRadius="5" Margin="2,0,0,0">
|
||||
<Border.Background>
|
||||
<ImageBrush Stretch="Fill" ImageSource="/axlogo.ico"/>
|
||||
</Border.Background>
|
||||
</Border>
|
||||
<TextBlock Margin="5,0,0,0" FontWeight="DemiBold" Text="PAL Ax Utility" VerticalAlignment="Center"/>
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
Click="CloseButton"
|
||||
Height="25" Width="25"
|
||||
FontSize="18"
|
||||
FontWeight="DemiBold"
|
||||
Background="Transparent"
|
||||
HorizontalAlignment="Right"
|
||||
BorderBrush="{x:Null}"
|
||||
Margin="0,3,3,0">
|
||||
<TextBlock Text="x" Margin="0,-5,0,0"/>
|
||||
</Button>
|
||||
</DockPanel>
|
||||
<GroupBox Margin="15,5,15,10"
|
||||
VerticalAlignment="Center"
|
||||
BorderBrush="LightGray"
|
||||
BorderThickness="1"
|
||||
Header="Ambienti">
|
||||
<StackPanel Name="LayoutRoot"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,5,5,5">
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="LIVE"
|
||||
Click="ButtonClicked"
|
||||
Height="115" Width="325"
|
||||
Content="LIVE"
|
||||
FontSize="36"
|
||||
Background="LightGray"/>
|
||||
<DockPanel HorizontalAlignment="Center"
|
||||
Margin="0,10,0,0">
|
||||
<Button Style="{StaticResource TabButton}"
|
||||
x:Name="STAGING"
|
||||
Click="ButtonClicked"
|
||||
Height="45" Width="325"
|
||||
Content="STAGING"
|
||||
FontSize="18"
|
||||
FontWeight="DemiBold"
|
||||
Background="#FFFF00"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace wpf_ax_utility
|
||||
{
|
||||
public partial class UserWindow : Window
|
||||
{
|
||||
public UserWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void MouseLeftDrag(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
DragMove();
|
||||
}
|
||||
|
||||
private void CloseButton(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AucCleaner();
|
||||
|
||||
string AxArgs = string.Empty;
|
||||
|
||||
switch (((Button)sender).Name)
|
||||
{
|
||||
case "LIVE":
|
||||
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_USR.axc";
|
||||
break;
|
||||
case "STAGING":
|
||||
AxArgs = @"-regConfig=L:\Link\PAL_STAGING_USR.axc";
|
||||
break; ;
|
||||
}
|
||||
|
||||
AxExecution(AxArgs);
|
||||
}
|
||||
|
||||
public static void AxExecution(string AxArgs)
|
||||
{
|
||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
||||
|
||||
if (System.IO.File.Exists(AxClient))
|
||||
{
|
||||
var p = new System.Diagnostics.Process();
|
||||
p.StartInfo.FileName = AxClient;
|
||||
p.StartInfo.Arguments = AxArgs;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Microsoft Dynamics Ax 2012 non è installato.", "Informazioni PAL Ax Utility", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AucCleaner()
|
||||
{
|
||||
string sourceDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
|
||||
DirectoryInfo directory = new DirectoryInfo(sourceDir);
|
||||
FileInfo[] files = directory.GetFiles();
|
||||
|
||||
string[] aucList = Directory.GetFiles(sourceDir, "*.auc");
|
||||
|
||||
foreach (string f in aucList)
|
||||
{
|
||||
File.Delete(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user