Skip to content

Commit

Permalink
read/write to github updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xantari committed Mar 27, 2021
1 parent 71b010e commit a0dd407
Show file tree
Hide file tree
Showing 36 changed files with 1,784 additions and 221 deletions.
4 changes: 3 additions & 1 deletion PinCab.Configurator/AboutBoxForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using PinCab.Utils.WinForms.TabOrder;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
Expand All @@ -20,6 +21,7 @@ public AboutBoxForm()
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
(new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst);
}

#region Assembly Attribute Accessors
Expand Down
199 changes: 199 additions & 0 deletions PinCab.Configurator/AddDatabaseForm.Designer.cs

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

101 changes: 101 additions & 0 deletions PinCab.Configurator/AddDatabaseForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using PinCab.Utils.Extensions;
using PinCab.Utils.Models;
using PinCab.Utils.Utils;
using PinCab.Utils.WinForms.TabOrder;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PinCab.Configurator
{
public partial class AddDatabaseForm : Form
{
private readonly ProgramSettingsManager _settingManager = new ProgramSettingsManager();
private ProgramSettings _settings { get; set; }

public AddDatabaseForm()
{
InitializeComponent();

cmbContentDatabaseType.DataSource = EnumExtensions.GetEnumDescriptionList<DatabaseType>();
_settings = _settingManager.LoadSettings();
DialogResult = DialogResult.None;
(new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst);
}

private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}

public ContentDatabase GetContentDatabaseFromForm()
{
var cd = new ContentDatabase()
{
AccessToken = txtContentDatabaseAccessToken.Text,
Name = txtContentDatabaseName.Text,
Url = txtContentDatabaseUrl.Text,
Type = cmbContentDatabaseType.SelectedItem.ToString().GetValueFromDescription<DatabaseType>()
};
return cd;
}

private bool ValidateForm()
{
var dbAlreadyExists = _settings.Databases.Any(c => c.Name.ToLower() == txtContentDatabaseName.Text.ToLower());
if (dbAlreadyExists)
{
MessageBox.Show("Database already exists with this name: " + txtContentDatabaseName.Text);
return false;
}
if (string.IsNullOrEmpty(txtContentDatabaseName.Text))
{
MessageBox.Show("Database name is required.");
return false;
}
if (string.IsNullOrEmpty(txtContentDatabaseUrl.Text))
{
MessageBox.Show("Database path / url is required.");
return false;
}
return true;
}

private void btnSave_Click(object sender, EventArgs e)
{
bool valid = ValidateForm();

if (valid)
{
var newCb = GetContentDatabaseFromForm();
_settings.Databases.Add(newCb);
_settingManager.SaveSettings(_settings);
DialogResult = DialogResult.OK;
Close();
}
}

private void btnContentDatabaseUrl_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(txtContentDatabaseUrl.Text);
}

private void btnFilePathDatabaseBrowser_Click(object sender, EventArgs e)
{
using (OpenFileDialog fileDialog = new OpenFileDialog())
{
fileDialog.Filter = "JSON Files|*.json|All files (*.*)|*.*";
fileDialog.RestoreDirectory = true;
var result = fileDialog.ShowDialog(this);
if (result == DialogResult.OK)
txtContentDatabaseUrl.Text = fileDialog.FileName;
}
}
}
}
Loading

0 comments on commit a0dd407

Please sign in to comment.