changeset 6:d63df495cf5a

Implemented initial support for adding and editing categories.
author Tsudico
date Mon, 13 Dec 2010 22:38:01 -0600
parents 387f17b36f52
children d4c03cc5bfb7
files FrmMain.cs FrmSystem.Designer.cs FrmSystem.cs IBBoard.WarFoundry.Forge.WinForms.suo
diffstat 4 files changed, 114 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMain.cs	Mon Dec 13 21:07:20 2010 -0600
+++ b/FrmMain.cs	Mon Dec 13 22:38:01 2010 -0600
@@ -306,9 +306,11 @@
 
 		private void miOpenSystem_Click(object sender, System.EventArgs e)
 		{
-			OpenFile();
-			FrmSystem system = new FrmSystem(CurrentGameSystem);
-			system.ShowDialog(this);
+			if(OpenFile())
+			{
+				FrmSystem system = new FrmSystem(CurrentGameSystem);
+				system.ShowDialog(this);
+			}
 		}
 		
 		private bool OpenFile()
--- a/FrmSystem.Designer.cs	Mon Dec 13 21:07:20 2010 -0600
+++ b/FrmSystem.Designer.cs	Mon Dec 13 22:38:01 2010 -0600
@@ -352,15 +352,14 @@
 			// 
 			// numPercentMax
 			// 
-			this.numPercentMax.DecimalPlaces = 4;
 			this.numPercentMax.Increment = new decimal(new int[] {
             5,
             0,
             0,
             0});
-			this.numPercentMax.Location = new System.Drawing.Point(202, 97);
+			this.numPercentMax.Location = new System.Drawing.Point(229, 97);
 			this.numPercentMax.Name = "numPercentMax";
-			this.numPercentMax.Size = new System.Drawing.Size(69, 20);
+			this.numPercentMax.Size = new System.Drawing.Size(42, 20);
 			this.numPercentMax.TabIndex = 9;
 			this.numPercentMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
 			// 
@@ -376,15 +375,14 @@
 			// 
 			// numPercentMin
 			// 
-			this.numPercentMin.DecimalPlaces = 4;
 			this.numPercentMin.Increment = new decimal(new int[] {
             5,
             0,
             0,
             0});
-			this.numPercentMin.Location = new System.Drawing.Point(202, 71);
+			this.numPercentMin.Location = new System.Drawing.Point(229, 71);
 			this.numPercentMin.Name = "numPercentMin";
-			this.numPercentMin.Size = new System.Drawing.Size(69, 20);
+			this.numPercentMin.Size = new System.Drawing.Size(42, 20);
 			this.numPercentMin.TabIndex = 7;
 			this.numPercentMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
 			// 
@@ -461,6 +459,7 @@
 			this.btnGenerateCatID.TabIndex = 22;
 			this.btnGenerateCatID.Text = "Generate ID";
 			this.btnGenerateCatID.UseVisualStyleBackColor = true;
+			this.btnGenerateCatID.Click += new System.EventHandler(this.btnGenerateCatID_Click);
 			// 
 			// txtCategoryID
 			// 
@@ -528,6 +527,7 @@
 			this.btnCategoryAdd.TabIndex = 13;
 			this.btnCategoryAdd.Text = "Add";
 			this.btnCategoryAdd.UseVisualStyleBackColor = true;
+			this.btnCategoryAdd.Click += new System.EventHandler(this.btnCategoryAdd_Click);
 			// 
 			// btnCategoryRemove
 			// 
@@ -546,6 +546,7 @@
 			this.btnCategoryEdit.TabIndex = 14;
 			this.btnCategoryEdit.Text = "Edit";
 			this.btnCategoryEdit.UseVisualStyleBackColor = true;
+			this.btnCategoryEdit.Click += new System.EventHandler(this.btnCategoryEdit_Click);
 			// 
 			// tabStats
 			// 
--- a/FrmSystem.cs	Mon Dec 13 21:07:20 2010 -0600
+++ b/FrmSystem.cs	Mon Dec 13 22:38:01 2010 -0600
@@ -20,28 +20,51 @@
 		{
 			InitializeComponent();
 			system = loadSystem;
-			if(loadSystem.IsFullyLoaded)
+			this.txtSystemName.Text = system.Name;
+			this.txtSystemId.Text = system.ID;
+			if(system.AllowAllies)
+			{
+				this.radSystemAlliesYes.Checked = true;
+			}
+			else
 			{
-				this.txtSystemName.Text = system.Name;
-				this.txtSystemId.Text = system.ID;
-				if(system.AllowAllies)
-				{
-					this.radSystemAlliesYes.Checked = true;
-				}
-				else
+				this.radSystemAlliesNo.Checked = true;
+			}
+			if (system.WarnOnError)
+			{
+				this.radSystemWarnYes.Checked = true;
+			}
+			else
+			{
+				this.radSystemWarnNo.Checked = true;
+			}
+			if(system.Categories.Length > 0)
+			{
+				this.listCategories.Items.Clear();
+				for(int i = 0; i < system.Categories.Length; i++)
 				{
-					this.radSystemAlliesNo.Checked = true;
-				}
-				if (system.WarnOnError)
-				{
-					this.radSystemWarnYes.Checked = true;
-				}
-				else
-				{
-					this.radSystemWarnNo.Checked = true;
+					this.listCategories.Items.Add(system.Categories[i].Name);
 				}
 			}
 		}
+		
+		private string generateID(string name)
+		{
+			string newId = String.Empty;
+
+			MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]");
+			foreach (Match part in id_parts)
+			{
+				newId += part.ToString();
+			}
+
+			if (newId.Length < 3)
+			{
+				newId = name.ToLower().Replace(" ", "");
+			}
+
+			return newId.ToLower();
+		}
 
 		private void btnSystemClose_Click(object sender, EventArgs e)
 		{
@@ -50,20 +73,74 @@
 
 		private void btnGenerateSysId_Click(object sender, EventArgs e)
 		{
-			string newId = String.Empty;
+			this.txtSystemId.Text = generateID(this.txtSystemName.Text);
+		}
 
-			MatchCollection id_parts = Regex.Matches(this.txtSystemName.Text, @"[A-Z\d]");
-			foreach(Match part in id_parts)
+		private void btnCategoryAdd_Click(object sender, EventArgs e)
+		{
+			if(this.txtCategoryName.Text == string.Empty)
 			{
-				newId += part.ToString();
+				MessageBox.Show("Category must have a name", "Category Error");
+				return;
+			}
+			if (this.txtCategoryID.Text == string.Empty)
+			{
+				MessageBox.Show("Category must have an ID", "Category Error");
+				return;
 			}
+			IBBoard.WarFoundry.API.Objects.Category cat = new IBBoard.WarFoundry.API.Objects.Category(
+					this.txtCategoryID.Text,
+					this.txtCategoryName.Text
+					);
 			
-			if(newId.Length < 3)
+			cat.MinimumPoints = (int)this.numPointMin.Value;
+			cat.MaximumPoints = (int)this.numPointMax.Value;
+			cat.MinimumPercentage = (int)this.numPercentMin.Value;
+			cat.MaximumPercentage = (int)this.numPercentMax.Value;
+			
+			system.AddCategory(cat);
+
+			if (system.Categories.Length > 0)
+			{
+				this.listCategories.Items.Clear();
+				for (int i = 0; i < system.Categories.Length; i++)
+				{
+					this.listCategories.Items.Add(system.Categories[i].Name);
+				}
+			}
+		}
+
+		private void btnCategoryEdit_Click(object sender, EventArgs e)
+		{
+			foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
 			{
-				newId = this.txtSystemName.Text.ToLower().Replace(" ", "");
+				if(cat.Name == this.listCategories.SelectedItem)
+				{
+					this.txtCategoryName.Text = cat.Name;
+					this.txtCategoryID.Text = cat.ID;
+					if(cat.MinimumPoints >= 0)
+					{
+						this.numPointMin.Value = cat.MinimumPoints;
+					}
+					if(cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPointMax.Maximum)
+					{	
+						this.numPointMax.Value = cat.MaximumPoints;
+					}
+					if(cat.MinimumPercentage >= 0)
+					{
+						this.numPercentMin.Value = cat.MinimumPercentage;
+					}
+					if(cat.MaximumPercentage <= 100)
+					{
+						this.numPercentMax.Value = cat.MaximumPercentage;
+					}
+				}
 			}
-			
-			this.txtSystemId.Text = newId.ToLower();
+		}
+
+		private void btnGenerateCatID_Click(object sender, EventArgs e)
+		{
+			this.txtCategoryID.Text = generateID(this.txtCategoryName.Text);
 		}
 	}
 }
Binary file IBBoard.WarFoundry.Forge.WinForms.suo has changed