Skip to content

Commit

Permalink
Connection control updated
Browse files Browse the repository at this point in the history
  • Loading branch information
artyomdeykun committed Sep 9, 2020
1 parent c0691bc commit d11f306
Show file tree
Hide file tree
Showing 181 changed files with 17,758 additions and 2,567 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Linq;
using System.Windows.Forms;

namespace McTools.Xrm.Connection.WinForms
{
public partial class AddConnectionFileDialog : Form
{
public AddConnectionFileDialog()
{
InitializeComponent();
}

public ConnectionFile OpenedFile { get; private set; }
public string OpenedFilePath { get; private set; }

private void btnBrowse_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog
{
Filter = "XML file|*.xml|CONFIG file|*.config",
};

if (ofd.ShowDialog(this) == DialogResult.OK)
{
txtFilePath.Text = ofd.FileName;
}
}

private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}

private void btnOk_Click(object sender, EventArgs e)
{
try
{
var newCc = CrmConnections.LoadFromFile(txtFilePath.Text);
OpenedFile = new ConnectionFile(newCc)
{
Path = txtFilePath.Text,
Name = newCc.Name,
LastUsed = DateTime.Now
};

if (ConnectionsList.Instance.Files.Any(f => f.Name == OpenedFile.Name))
{
int cloneId = 1;
string newName = OpenedFile.Name ?? "New File";

while (ConnectionsList.Instance.Files.FirstOrDefault(f => f.Name == newName) != null)
{
var rule = new System.Text.RegularExpressions.Regex(".* \\(" + cloneId + "\\)$");
if (rule.IsMatch(newName))
{
cloneId++;
newName = $"{OpenedFile.Name.Replace($" ({cloneId - 1})", "")} ({cloneId})";
}
else
{
newName = $"{newName} ({cloneId})";
}
}

OpenedFile.Name = newName;

MessageBox.Show(this, $"A connection file with this name already exists!\n\nIt has been renamed to '{newName}'", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

ConnectionManager.ConfigurationFile = txtFilePath.Text;
ConnectionsList.Instance.Files.First(f => f.Path == txtFilePath.Text).Name = OpenedFile.Name;
ConnectionManager.Instance.LoadConnectionsList();
ConnectionsList.Instance.Save();

OpenedFilePath = txtFilePath.Text;

DialogResult = DialogResult.OK;
Close();
}
catch (Exception error)
{
MessageBox.Show(this, "It seems something went wrong when loading your file: " + error,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Window x:Class="McTools.Xrm.Connection.WinForms.CRMLoginForm1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CrmLoginCtrl="clr-namespace:Microsoft.Xrm.Tooling.CrmConnectControl;assembly=Microsoft.Xrm.Tooling.CrmConnectControl"
Title="CRM Login" Width="465" Height="471"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
BorderThickness="1"
BorderBrush="#173561"
Loaded="Window_Loaded">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Microsoft.Xrm.Tooling.Ui.Styles;component/Resources/Button/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<CrmLoginCtrl:CrmServerLoginControl Name="CrmLoginCtrl" Grid.Row="1" ShowTitle="False" Margin="10,5" VerticalAlignment="Bottom" />
</Grid>
</Window>
Loading

0 comments on commit d11f306

Please sign in to comment.