diff --git a/.github/Notes/file manipulation.txt b/.github/Notes/file manipulation.txt new file mode 100644 index 00000000..a89d712f --- /dev/null +++ b/.github/Notes/file manipulation.txt @@ -0,0 +1,18 @@ +for adding from the saved file, the idea is that the "add" function can be modified to output the whole thing/ be used to get all of the entrie. + +that way, the order is: + +1. open +2. read file +3. split CSV +4. create classes based on CSV +5. add that into the list +6. use this to add it to the contacts +7. done! + +___________________________________________________________ +save to file just adds a new line with the necessary separation symbol (determined by a constant variable, in this case a "~") + +a new system will be added to replace tildes with something else, so the splitting symbol is replaced in the text by something, then that becomes a tilde. + +details to be figured out \ No newline at end of file diff --git a/Example-Only Files/Example-Only Files.txt b/Example-Only Files/Example-Only Files.txt new file mode 100644 index 00000000..d4c22d88 --- /dev/null +++ b/Example-Only Files/Example-Only Files.txt @@ -0,0 +1,3 @@ +Contact.cs +store.con + Snack-Shack\bin\Debug\contacts \ No newline at end of file diff --git a/Program.cs b/Program.cs index dd4bb892..b6b15f7d 100644 --- a/Program.cs +++ b/Program.cs @@ -18,7 +18,38 @@ static void Main() Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frm_snackInvent()); } - - internal static List snacks = new List(); + internal const bool debug = true; //global var to controll default for debugs + internal static List inventory = new List(); //makes a collection that refferences the class that will store information } -} + internal static class coreCommands + { + internal static void error(string message, Exception ex = null, bool revealException = false) + { + string msg = message; //what message to display + if (revealException) //put the toggle + { + msg = msg + ": " + ex.Message; //the message + }//a bool to toggle if the exception code should be included in the error message + MessageBox.Show(msg); //show the message + } //this is for error messages. the text is mandatory, but the + //rest isn't necessary. if you don't provide an exception, it won't display one. If you provide an error, it will default to "hide error". + // WARNING: If you provide a boolean, you can controll if it's hidden. If you provide a boolean but no error, well, it won't work righ + + /* internal static string path() + { + var pathSpliter = '\\'; //part between paths + var loc = AppDomain.CurrentDomain.BaseDirectory; //get the current domain + var comps = loc.Split('\\'); //array of path after being split + var len = comps.Length; //length of path + var completeLoc = string.Empty; //blank variable for path + for (var i = 0; i < len-3; i++) //repeat by the length minus 2, which will lead to it excluding the 2 folders that are unwanted + { + var comp = comps[i]; + completeLoc = completeLoc + comp + char.ToString(pathSpliter); //add next part to path + } + return completeLoc; //output path + } //derive the path of the base file */ + + } //base commands to aid in everything + +} \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 9c8e39d3..4ef2a888 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace snackShack.Properties -{ - - +namespace snackShack.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,53 +19,55 @@ namespace snackShack.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("snackShack.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap VendingMachine { + get { + object obj = ResourceManager.GetObject("VendingMachine", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/Properties/Resources.resx b/Properties/Resources.resx index af7dbebb..207cdd8f 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,13 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Files\presetImages\VendingMachine.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/bin/Debug/Inventory/inventory.csv b/bin/Debug/Inventory/inventory.csv new file mode 100644 index 00000000..e69de29b diff --git a/bin/Debug/contacts/store.con b/bin/Debug/contacts/store.con new file mode 100644 index 00000000..1c418349 --- /dev/null +++ b/bin/Debug/contacts/store.con @@ -0,0 +1,20 @@ +tests~test~1~test~True~test~1 +testing~test2~ 1~test~False~test~2 +test~test~ 2~test~True~test~3 +tests~testing~~ 11~True~1~4 +w~test~ 12 124~test~False~testasae~5 +t~e~ 1~s~False~tests~6 +hi~test~test~ 1~False~test~7 +tests~h~test~ 1~True~test~8 +tests ~h~ 1~ 11~True~test~9 +1~2~ 4~3~False~5~10 +t~e~ 1~ 1~False~tests~11 +charlie~hatch~1234567891~test~True~this is a largeer scale test~12 +test~test~ 12~large~True~this is a very large scale test and I do mean very as in very, very, very....................................~13 +test~test2~ 1~test3~True~t~14 +testt~~~~False~~15 +t~~~~False~~16 +t~~~~False~~17 +test~test~ 12~large~True~4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~18 +1~1~1234567890~1~False~info~19 +test~test~ 1~test2~True~test~20 diff --git a/constants.cs b/constants.cs new file mode 100644 index 00000000..4e264071 --- /dev/null +++ b/constants.cs @@ -0,0 +1,23 @@ +namespace snackShack +{ + internal static class constants //pre-defined constants + { + const char fileSepChar_con = '\\'; //seperater in file paths + internal const int min = 4; //length of entries + internal const char entrySep = ','; //seperation character + internal const string preMadeErrorMsg = "I'm sorry dave, I'm afraid I can't do that"; //pre-made error message + internal const double minPrice = 0.05; + internal static string fileSepString() //give the seperation character as a string + { + return char.ToString(fileSepChar_con); + } + internal static char fileSepChar() //give the seperation character as a char + { + return fileSepChar_con; + } + internal static decimal minimumPrice() + { + return (decimal)minPrice; + } + } +} \ No newline at end of file diff --git a/fileCode.cs b/fileCode.cs new file mode 100644 index 00000000..5ed1cd7a --- /dev/null +++ b/fileCode.cs @@ -0,0 +1,92 @@ + +using System.Diagnostics; +using System.IO; +using System.Windows.Forms; +using System; + +namespace snackShack +{ + internal static class files + { + #region I/O + internal static void Write(string filepath, char sep) + { + bool status = File.Exists(filepath); //check if the file exists + if (status || Program.debug) //if file exists, or debug is active, run system + { + try + { + using (StreamWriter sw = new StreamWriter(filepath)) //utilize the file path to find the file + { + foreach (var c in Program.inventory) //the loop for createing the contents which will be saved + { + //csv - comma seperated values + //name-imagepath-cost-index + string ind = (c.index + 1).ToString(); //indux to string + string cost = c.cost.ToString(); //cost to string + string line = c.name + sep + c.imagePath + sep + //combine string + cost + sep + ind; + sw.WriteLine(line); //write the information to the line + } + } //streamwriter + } + catch (Exception ex) //find if exception + { + snackShack.coreCommands.error(constants.preMadeErrorMsg, ex, true); //show error + } + } + else //say if no file + { + snackShack.coreCommands.error("File Not Found"); //show error + } + } //the write function + + internal static void read(string path, char sep, int min) //the read function + { + bool status = File.Exists(path); //check if the file exists + if (status || Program.debug) //check if there + { + try + { + using (StreamReader sr = new StreamReader(path)) //make stringreader + { + //csv - comma seperated values + //firstname-lastname-email-phone-buisness-notes + while (!sr.EndOfStream) //add each line to it one by one + { + string item = sr.ReadLine(); //gets the next line of text from the file + var entry = item.Split(sep); //splits it by the seperator + if (entry.Length >= min) + { + inventory c = new inventory //make new constact + { + name = entry[0], //put the realevent input into the releavent field + imagePath = entry[1], //same + cost = Convert.ToInt32(entry[2]), //same + index = Convert.ToInt32(entry[3]) -1 //any guesses? + }; + Program.inventory.Add(c); //add to list + } + else + { + + coreCommands.error("error: below Max Length"); //show error during read + } + } + } + } + catch (Exception ex) //show if exception + { + MessageBox.Show("error" + ex.Message); //show error + + } + } + else + { + MessageBox.Show("file not found"); //show error + + } + } + #endregion + } //the code for files +} \ No newline at end of file diff --git a/frm_snackInvent.cs b/frm_snackInvent.cs index b4f1ad97..4b6568f0 100644 --- a/frm_snackInvent.cs +++ b/frm_snackInvent.cs @@ -75,15 +75,7 @@ private void btn_add_Click(object sender, EventArgs e) private void frm_snackInvent_FormClosing(object sender, FormClosingEventArgs e) { - try - { - using (StreamWriter sw = new StreamWriter("snacks.csv")) { - int count = 0; - toolStripStatusLabel1.Text = String.Format("Wrote {0} snacks to file", count); //show current number of entries, which is 0. - //If this is what you see when done, something went wrong - foreach (var snack in Program.snacks) - { - //snack name, price, quantity, imagepath + snackShack.files.files.write(); sw.WriteLine(snack.name + "," + snack.price + "," + snack.amount + "," + snack.imagepath); //write in csv format count++; //increment count @@ -91,20 +83,21 @@ private void frm_snackInvent_FormClosing(object sender, FormClosingEventArgs e) } } } - catch (Exception ex) //catch exception - { - MessageBox.Show("Error during file write", "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void frm_snackInvent_Load(object sender, EventArgs e) - { - try - { - if(File.Exists("snacks.csv")) - { toolStripStatusLabel1.Text = String.Format("Proceeding to load snacks from file"); //if you see this, something went wrong... //It means that it failed before it loaded something + } + snackShack.files.files.write(); + int count = 0; + private void frm_snackInvent_Load(object sender, EventArgs e) + { + snackInvent snack = new snackInvent(); //make new class + //order is: snackname, price, quantity, imagepath + + string line = sr.ReadLine(); //read line + string[] arr = line.Split(','); //split into an array based on the csv format + + //populate class based on the contents of the file using (StreamReader sr = new StreamReader("snacks.csv")) { int count = 0; diff --git a/snackShack.csproj b/snackShack.csproj index dea014e4..a7b6b2b0 100644 --- a/snackShack.csproj +++ b/snackShack.csproj @@ -46,6 +46,7 @@ + Form diff --git a/snackShack.sln b/snackShack.sln index 9cec5f70..8107c567 100644 --- a/snackShack.sln +++ b/snackShack.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34607.119 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "snackShack", "snackShack.csproj", "{0B7C67A3-C011-4C1B-AAE5-E8233779010F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "snackShack", "snackShack.csproj", "{1855EEDC-A659-4D31-B976-ACEF2B3918FE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +11,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0B7C67A3-C011-4C1B-AAE5-E8233779010F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B7C67A3-C011-4C1B-AAE5-E8233779010F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B7C67A3-C011-4C1B-AAE5-E8233779010F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B7C67A3-C011-4C1B-AAE5-E8233779010F}.Release|Any CPU.Build.0 = Release|Any CPU + {1855EEDC-A659-4D31-B976-ACEF2B3918FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1855EEDC-A659-4D31-B976-ACEF2B3918FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1855EEDC-A659-4D31-B976-ACEF2B3918FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1855EEDC-A659-4D31-B976-ACEF2B3918FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE