mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Finished the program
This commit is contained in:
parent
dc4fff061f
commit
2369889020
@ -19,7 +19,7 @@ namespace csharp
|
||||
Console.SetOut(new StringWriter(fakeoutput));
|
||||
Console.SetIn(new StringReader("a\n"));
|
||||
|
||||
appGUI.Main(new string[] { });
|
||||
MainForm.Main(new string[] { });
|
||||
var output = fakeoutput.ToString();
|
||||
|
||||
Approvals.Verify(output);
|
||||
|
||||
@ -5,18 +5,15 @@ namespace csharp
|
||||
{
|
||||
public class GildedRose
|
||||
{
|
||||
IList<Item> Items;
|
||||
public const int sulfurasMaxQuality = 80;
|
||||
public const int itemMaxQuality = 50;
|
||||
public const int qualityScore = 50;
|
||||
public const int daysToDoublePassesQuantity = 11;
|
||||
public const int daysToTriplePassesQuantity = 6;
|
||||
public GildedRose(IList<Item> Items)
|
||||
public GildedRose()
|
||||
{
|
||||
this.Items = Items;
|
||||
}
|
||||
|
||||
public void UpdateQuality()
|
||||
public void UpdateQuality(IList<Item> Items)
|
||||
{
|
||||
for (var i = 0; i < Items.Count; i++)
|
||||
{
|
||||
@ -31,20 +28,29 @@ namespace csharp
|
||||
|
||||
if (Items[i].SellIn < daysToTriplePassesQuantity)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 2;
|
||||
Items[i].Quality = Items[i].Quality + 3;
|
||||
}
|
||||
|
||||
else if (Items[i].SellIn < daysToDoublePassesQuantity)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
Items[i].Quality = Items[i].Quality + 2;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality +1;
|
||||
}
|
||||
|
||||
if (Items[i].Quality > 50)
|
||||
{
|
||||
Items[i].Quality = 50;
|
||||
}
|
||||
|
||||
}
|
||||
else if(Items[i].Name == "Conjured Mana Cake" && Items[i].Quality > 0)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 2;
|
||||
}
|
||||
else if (Items[i].Quality > 0 && Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
else if (Items[i].Quality > 0 && Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert" && Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
}
|
||||
@ -63,11 +69,7 @@ namespace csharp
|
||||
{
|
||||
Items[i].Quality = 0;
|
||||
}
|
||||
else if (Items[i].Name == "Aged Brie" && Items[i].Quality < itemMaxQuality)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
}
|
||||
else if(Items[i].Quality > 0 && Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
else if(Items[i].Quality > 0 && Items[i].Name != "Sulfuras, Hand of Ragnaros" && Items[i].Name != "Aged Brie")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
}
|
||||
|
||||
@ -10,8 +10,8 @@ namespace csharp
|
||||
public void foo()
|
||||
{
|
||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||
GildedRose app = new GildedRose(Items);
|
||||
app.UpdateQuality();
|
||||
GildedRose app = new GildedRose();
|
||||
app.UpdateQuality(Items);
|
||||
Assert.AreEqual("fixme", Items[0].Name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,16 @@
|
||||
public string Name { get; set; }
|
||||
public int SellIn { get; set; }
|
||||
public int Quality { get; set; }
|
||||
public Item()
|
||||
{
|
||||
|
||||
}
|
||||
public Item(Item item)
|
||||
{
|
||||
this.Name = item.Name;
|
||||
this.SellIn = item.SellIn;
|
||||
this.Quality = item.Quality;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name + ", " + this.SellIn + ", " + this.Quality;
|
||||
|
||||
119
csharp/MainForm.cs
Normal file
119
csharp/MainForm.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using csharp;
|
||||
using System.Data;
|
||||
|
||||
namespace csharp
|
||||
{
|
||||
class MainForm :Form
|
||||
{
|
||||
private Button btnShowData;
|
||||
private Button btnInsertItem;
|
||||
private IList<Item> Items;
|
||||
private GildedRose app;
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
Items = new List<Item>{
|
||||
new Item {Name = "+5 Dexterity Vest", SellIn = 5, Quality = 20},
|
||||
new Item {Name = "Aged Brie", SellIn = 8, Quality = 0},
|
||||
new Item {Name = "Elixir of the Mongoose", SellIn = 10, Quality = 7},
|
||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
|
||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 5,
|
||||
Quality = 49
|
||||
},
|
||||
// this conjured item does not work properly yet
|
||||
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
|
||||
};
|
||||
|
||||
app = new GildedRose();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnShowData = new System.Windows.Forms.Button();
|
||||
this.btnInsertItem = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnShowData
|
||||
//
|
||||
this.btnShowData.Location = new System.Drawing.Point(61, 53);
|
||||
this.btnShowData.Name = "btnShowData";
|
||||
this.btnShowData.Size = new System.Drawing.Size(163, 37);
|
||||
this.btnShowData.TabIndex = 0;
|
||||
this.btnShowData.Text = "Show Items";
|
||||
this.btnShowData.UseVisualStyleBackColor = true;
|
||||
this.btnShowData.Click += new System.EventHandler(this.btnShowData_Click);
|
||||
//
|
||||
// btnInsertItem
|
||||
//
|
||||
this.btnInsertItem.Location = new System.Drawing.Point(61, 136);
|
||||
this.btnInsertItem.Name = "btnInsertItem";
|
||||
this.btnInsertItem.Size = new System.Drawing.Size(163, 41);
|
||||
this.btnInsertItem.TabIndex = 1;
|
||||
this.btnInsertItem.Text = "Insert item";
|
||||
this.btnInsertItem.UseVisualStyleBackColor = true;
|
||||
this.btnInsertItem.Click += new System.EventHandler(this.btnInsertItem_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(282, 253);
|
||||
this.Controls.Add(this.btnInsertItem);
|
||||
this.Controls.Add(this.btnShowData);
|
||||
this.Name = "MainForm";
|
||||
this.Text = "Gilded Rose";
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var mainForm = new MainForm();
|
||||
mainForm.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnShowData_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var showDataForm = new showDataForm(app, Items);
|
||||
showDataForm.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
private void btnInsertItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var Additemform = new addItemForm(Items);
|
||||
Additemform.ShowDialog();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
120
csharp/MainForm.resx
Normal file
120
csharp/MainForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
3
csharp/RuleSet1.ruleset
Normal file
3
csharp/RuleSet1.ruleset
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RuleSet Name="New Rule Set" Description=" " ToolsVersion="10.0">
|
||||
</RuleSet>
|
||||
164
csharp/addItemForm.cs
Normal file
164
csharp/addItemForm.cs
Normal file
@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using csharp;
|
||||
using System.Data;
|
||||
|
||||
|
||||
namespace csharp
|
||||
{
|
||||
class addItemForm :Form
|
||||
{
|
||||
private ComboBox cbType;
|
||||
private Label lblItemType;
|
||||
private Label lblSellIn;
|
||||
private Label lblQuality;
|
||||
private NumericUpDown nudlSellIn;
|
||||
private Button btnAdd;
|
||||
private NumericUpDown nudlQuality;
|
||||
private IList<Item> Items;
|
||||
public addItemForm(IList<Item> Items)
|
||||
{
|
||||
this.Items = Items;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.cbType = new System.Windows.Forms.ComboBox();
|
||||
this.lblItemType = new System.Windows.Forms.Label();
|
||||
this.lblSellIn = new System.Windows.Forms.Label();
|
||||
this.lblQuality = new System.Windows.Forms.Label();
|
||||
this.nudlSellIn = new System.Windows.Forms.NumericUpDown();
|
||||
this.nudlQuality = new System.Windows.Forms.NumericUpDown();
|
||||
this.btnAdd = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudlSellIn)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudlQuality)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// cbType
|
||||
//
|
||||
this.cbType.FormattingEnabled = true;
|
||||
this.cbType.Location = new System.Drawing.Point(99, 40);
|
||||
this.cbType.Name = "cbType";
|
||||
this.cbType.Size = new System.Drawing.Size(121, 24);
|
||||
this.cbType.TabIndex = 0;
|
||||
this.cbType.SelectedIndexChanged += new System.EventHandler(this.cbType_SelectedIndexChanged);
|
||||
//
|
||||
// lblItemType
|
||||
//
|
||||
this.lblItemType.AutoSize = true;
|
||||
this.lblItemType.Location = new System.Drawing.Point(13, 40);
|
||||
this.lblItemType.Name = "lblItemType";
|
||||
this.lblItemType.Size = new System.Drawing.Size(70, 17);
|
||||
this.lblItemType.TabIndex = 1;
|
||||
this.lblItemType.Text = "Item Type";
|
||||
//
|
||||
// lblSellIn
|
||||
//
|
||||
this.lblSellIn.AutoSize = true;
|
||||
this.lblSellIn.Location = new System.Drawing.Point(12, 86);
|
||||
this.lblSellIn.Name = "lblSellIn";
|
||||
this.lblSellIn.Size = new System.Drawing.Size(46, 17);
|
||||
this.lblSellIn.TabIndex = 2;
|
||||
this.lblSellIn.Text = "Sell In";
|
||||
//
|
||||
// lblQuality
|
||||
//
|
||||
this.lblQuality.AutoSize = true;
|
||||
this.lblQuality.Location = new System.Drawing.Point(13, 142);
|
||||
this.lblQuality.Name = "lblQuality";
|
||||
this.lblQuality.Size = new System.Drawing.Size(52, 17);
|
||||
this.lblQuality.TabIndex = 3;
|
||||
this.lblQuality.Text = "Quality";
|
||||
//
|
||||
// nudlSellIn
|
||||
//
|
||||
this.nudlSellIn.Location = new System.Drawing.Point(99, 86);
|
||||
this.nudlSellIn.Name = "nudlSellIn";
|
||||
this.nudlSellIn.Size = new System.Drawing.Size(120, 22);
|
||||
this.nudlSellIn.TabIndex = 4;
|
||||
//
|
||||
// nudlQuality
|
||||
//
|
||||
this.nudlQuality.Location = new System.Drawing.Point(99, 137);
|
||||
this.nudlQuality.Name = "nudlQuality";
|
||||
this.nudlQuality.Size = new System.Drawing.Size(120, 22);
|
||||
this.nudlQuality.TabIndex = 5;
|
||||
//
|
||||
// btnAdd
|
||||
//
|
||||
this.btnAdd.Location = new System.Drawing.Point(99, 202);
|
||||
this.btnAdd.Name = "btnAdd";
|
||||
this.btnAdd.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnAdd.TabIndex = 6;
|
||||
this.btnAdd.Text = "Add Item";
|
||||
this.btnAdd.UseVisualStyleBackColor = true;
|
||||
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
|
||||
//
|
||||
// addItemForm
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(282, 253);
|
||||
this.Controls.Add(this.btnAdd);
|
||||
this.Controls.Add(this.nudlQuality);
|
||||
this.Controls.Add(this.nudlSellIn);
|
||||
this.Controls.Add(this.lblQuality);
|
||||
this.Controls.Add(this.lblSellIn);
|
||||
this.Controls.Add(this.lblItemType);
|
||||
this.Controls.Add(this.cbType);
|
||||
this.Name = "addItemForm";
|
||||
this.Text = "Add an item";
|
||||
this.Load += new System.EventHandler(this.addItemForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudlSellIn)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudlQuality)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var itemType = cbType.SelectedItem;
|
||||
if(itemType == null)
|
||||
{
|
||||
MessageBox.Show("Please Select Item Type");
|
||||
return;
|
||||
}
|
||||
var sellIn = nudlSellIn.Value;
|
||||
var Quality = nudlQuality.Value;
|
||||
this.Items.Add(new Item { Name = itemType.ToString(), SellIn = (int)sellIn, Quality = (int)Quality });
|
||||
MessageBox.Show("Item Added Sucessfully");
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
private void addItemForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
cbType.Items.Add("+5 Dexterity Vest");
|
||||
cbType.Items.Add("Aged Brie");
|
||||
cbType.Items.Add("Elixir of the Mongoose");
|
||||
cbType.Items.Add("Sulfuras, Hand of Ragnaros");
|
||||
cbType.Items.Add("Backstage passes to a TAFKAL80ETC concert");
|
||||
cbType.Text = "Choose an item";
|
||||
}
|
||||
|
||||
private void cbType_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(cbType.SelectedItem.ToString() == "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
nudlQuality.Maximum = 80;
|
||||
nudlQuality.Minimum = 80;
|
||||
nudlQuality.Value = 80;
|
||||
} else
|
||||
{
|
||||
nudlQuality.Minimum = 0;
|
||||
nudlQuality.Maximum = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
csharp/addItemForm.resx
Normal file
120
csharp/addItemForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
169
csharp/appGUI.cs
169
csharp/appGUI.cs
@ -1,169 +0,0 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using csharp;
|
||||
using System.Data;
|
||||
|
||||
public partial class appGUI : Form
|
||||
{
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridViewTextBoxColumn Day;
|
||||
private DataGridViewTextBoxColumn itemName;
|
||||
private DataGridViewTextBoxColumn SellIn;
|
||||
private DataGridViewTextBoxColumn Quality;
|
||||
private Button button1;
|
||||
|
||||
public appGUI()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.Day = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.itemName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.SellIn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Quality = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
this.dataGridView1.AllowUserToOrderColumns = true;
|
||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.Day,
|
||||
this.itemName,
|
||||
this.SellIn,
|
||||
this.Quality});
|
||||
this.dataGridView1.Location = new System.Drawing.Point(-7, 56);
|
||||
this.dataGridView1.Name = "dataGridView1";
|
||||
this.dataGridView1.RowHeadersWidth = 51;
|
||||
this.dataGridView1.RowTemplate.Height = 24;
|
||||
this.dataGridView1.Size = new System.Drawing.Size(560, 414);
|
||||
this.dataGridView1.TabIndex = 0;
|
||||
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick_1);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(199, 12);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(181, 23);
|
||||
this.button1.TabIndex = 1;
|
||||
this.button1.Text = "Show Data";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// Day
|
||||
//
|
||||
this.Day.HeaderText = "Day";
|
||||
this.Day.MinimumWidth = 6;
|
||||
this.Day.Name = "Day";
|
||||
this.Day.ReadOnly = true;
|
||||
this.Day.Width = 125;
|
||||
//
|
||||
// itemName
|
||||
//
|
||||
this.itemName.HeaderText = "itemName";
|
||||
this.itemName.MinimumWidth = 6;
|
||||
this.itemName.Name = "itemName";
|
||||
this.itemName.ReadOnly = true;
|
||||
this.itemName.Width = 125;
|
||||
//
|
||||
// SellIn
|
||||
//
|
||||
this.SellIn.HeaderText = "SellIn";
|
||||
this.SellIn.MinimumWidth = 6;
|
||||
this.SellIn.Name = "SellIn";
|
||||
this.SellIn.ReadOnly = true;
|
||||
this.SellIn.Width = 125;
|
||||
//
|
||||
// Quality
|
||||
//
|
||||
this.Quality.HeaderText = "Quality";
|
||||
this.Quality.MinimumWidth = 6;
|
||||
this.Quality.Name = "Quality";
|
||||
this.Quality.ReadOnly = true;
|
||||
this.Quality.Width = 125;
|
||||
//
|
||||
// appGUI
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(554, 460);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.dataGridView1);
|
||||
this.Name = "appGUI";
|
||||
this.Text = "appGUI";
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var guiForm = new appGUI();
|
||||
guiForm.ShowDialog();
|
||||
}
|
||||
|
||||
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Item> Items = new List<Item>{
|
||||
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
|
||||
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
|
||||
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
|
||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
|
||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 5,
|
||||
Quality = 49
|
||||
},
|
||||
// this conjured item does not work properly yet
|
||||
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
|
||||
};
|
||||
|
||||
var app = new GildedRose(Items);
|
||||
|
||||
|
||||
for (var i = 0; i < 31; i++)
|
||||
{
|
||||
Console.WriteLine("-------- day " + i + " --------");
|
||||
Console.WriteLine("name, sellIn, quality");
|
||||
for (var j = 0; j < Items.Count; j++)
|
||||
{
|
||||
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[j].Clone();
|
||||
row.Cells[0].Value = i;
|
||||
row.Cells[1].Value = Items[j].Name;
|
||||
row.Cells[2].Value = Items[j].SellIn;
|
||||
row.Cells[3].Value = Items[j].Quality;
|
||||
dataGridView1.Rows.Add(row);
|
||||
}
|
||||
app.UpdateQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,26 +86,39 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="appGUI.cs">
|
||||
<Compile Include="addItemForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="showDataForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ApprovalTest.cs" />
|
||||
<Compile Include="GildedRose.cs" />
|
||||
<Compile Include="GildedRoseTest.cs" />
|
||||
<Compile Include="Item.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="RuleSet1.ruleset" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="appGUI.resx">
|
||||
<DependentUpon>appGUI.cs</DependentUpon>
|
||||
<EmbeddedResource Include="addItemForm.resx">
|
||||
<DependentUpon>addItemForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="showDataForm.resx">
|
||||
<DependentUpon>showDataForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
164
csharp/showDataForm.cs
Normal file
164
csharp/showDataForm.cs
Normal file
@ -0,0 +1,164 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using csharp;
|
||||
using System.Data;
|
||||
|
||||
public partial class showDataForm : Form
|
||||
{
|
||||
private DataGridView dgvData;
|
||||
private Label lblDay;
|
||||
private DataGridViewTextBoxColumn itemName;
|
||||
private DataGridViewTextBoxColumn SellIn;
|
||||
private DataGridViewTextBoxColumn Quality;
|
||||
private GildedRose app;
|
||||
private ComboBox cbDay;
|
||||
private IList<Item> Items;
|
||||
|
||||
public showDataForm(GildedRose app, IList<Item> Items)
|
||||
{
|
||||
this.app = app;
|
||||
this.Items = Items;
|
||||
InitializeComponent();
|
||||
for(int i=1; i<31; i++)
|
||||
{
|
||||
cbDay.Items.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dgvData = new System.Windows.Forms.DataGridView();
|
||||
this.itemName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.SellIn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Quality = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.lblDay = new System.Windows.Forms.Label();
|
||||
this.cbDay = new System.Windows.Forms.ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvData)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dgvData
|
||||
//
|
||||
this.dgvData.AllowUserToOrderColumns = true;
|
||||
this.dgvData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.itemName,
|
||||
this.SellIn,
|
||||
this.Quality});
|
||||
this.dgvData.Location = new System.Drawing.Point(79, 128);
|
||||
this.dgvData.Name = "dgvData";
|
||||
this.dgvData.RowHeadersWidth = 51;
|
||||
this.dgvData.RowTemplate.Height = 24;
|
||||
this.dgvData.Size = new System.Drawing.Size(426, 327);
|
||||
this.dgvData.TabIndex = 0;
|
||||
this.dgvData.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick_1);
|
||||
//
|
||||
// itemName
|
||||
//
|
||||
this.itemName.HeaderText = "itemName";
|
||||
this.itemName.MinimumWidth = 6;
|
||||
this.itemName.Name = "itemName";
|
||||
this.itemName.ReadOnly = true;
|
||||
this.itemName.Width = 125;
|
||||
//
|
||||
// SellIn
|
||||
//
|
||||
this.SellIn.HeaderText = "SellIn";
|
||||
this.SellIn.MinimumWidth = 6;
|
||||
this.SellIn.Name = "SellIn";
|
||||
this.SellIn.ReadOnly = true;
|
||||
this.SellIn.Width = 125;
|
||||
//
|
||||
// Quality
|
||||
//
|
||||
this.Quality.HeaderText = "Quality";
|
||||
this.Quality.MinimumWidth = 6;
|
||||
this.Quality.Name = "Quality";
|
||||
this.Quality.ReadOnly = true;
|
||||
this.Quality.Width = 125;
|
||||
//
|
||||
// lblDay
|
||||
//
|
||||
this.lblDay.AutoSize = true;
|
||||
this.lblDay.Location = new System.Drawing.Point(171, 48);
|
||||
this.lblDay.Name = "lblDay";
|
||||
this.lblDay.Size = new System.Drawing.Size(33, 17);
|
||||
this.lblDay.TabIndex = 3;
|
||||
this.lblDay.Text = "Day";
|
||||
//
|
||||
// cbDay
|
||||
//
|
||||
this.cbDay.FormattingEnabled = true;
|
||||
this.cbDay.Location = new System.Drawing.Point(229, 45);
|
||||
this.cbDay.Name = "cbDay";
|
||||
this.cbDay.Size = new System.Drawing.Size(121, 24);
|
||||
this.cbDay.TabIndex = 4;
|
||||
this.cbDay.SelectedIndexChanged += new System.EventHandler(this.cbDay_SelectedIndexChanged);
|
||||
//
|
||||
// showDataForm
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(554, 460);
|
||||
this.Controls.Add(this.cbDay);
|
||||
this.Controls.Add(this.lblDay);
|
||||
this.Controls.Add(this.dgvData);
|
||||
this.Name = "showDataForm";
|
||||
this.Text = "Show Data";
|
||||
this.Load += new System.EventHandler(this.showDataForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvData)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnShowData_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void showDataForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void cbDay_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
dgvData.Rows.Clear();
|
||||
int counter = 0;
|
||||
IList<Item> tempItems = new List<Item>();
|
||||
foreach (var it in Items)
|
||||
{
|
||||
tempItems.Add(new Item(it));
|
||||
}
|
||||
|
||||
for (var i = 0; i < (int)cbDay.SelectedItem; i++)
|
||||
{
|
||||
app.UpdateQuality(tempItems);
|
||||
}
|
||||
|
||||
for (var j = 0; j < tempItems.Count; j++)
|
||||
{
|
||||
if (tempItems[j].Quality > 0)
|
||||
{
|
||||
DataGridViewRow row = (DataGridViewRow)dgvData.Rows[counter].Clone();
|
||||
row.Cells[0].Value = tempItems[j].Name;
|
||||
row.Cells[1].Value = tempItems[j].SellIn < 0 ? 0 : tempItems[j].SellIn;
|
||||
row.Cells[2].Value = tempItems[j].Quality;
|
||||
dgvData.Rows.Add(row);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="Day.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<metadata name="itemName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="SellIn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Quality.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="itemName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
Loading…
Reference in New Issue
Block a user