public Tip getTipByID(int id) { List<Tip> tips = getAllTips(); Tip tip = new Tip(); foreach (Tip tip_ in tips.Where(t => t.ID == id)) { tip = tip_; } return tip; }
private void button1_Click(object sender, EventArgs e) { Handler handler = new Handler(); string name = textBox1.Text; string text = richTextBox1.Text; List<string> tags = new List<string>(); if (Data.Value.ID > 0){ handler.updateTip(name, text, Data.Value.ID); }else{ Tip tip = new Tip(name, text, tags); handler.saveTip(tip); } }
public List<Tip> ParserTips() { List<string> input = new List<string>(); List<Tip> tips = new List<Tip>(); int id = 0; string name = "", text = ""; List<string> tags = new List<string>(); Regex rxTipName = new Regex(@"<name>(.*)</name>"); Regex rxTipID = new Regex(@"<id>(.*)</id>"); Regex rxTipText = new Regex(@"<text>(.*)</text>"); Regex rxTipTags = new Regex(@"<tags>(.*)</tags>"); input = fh.Reader(); for (int counter = 0; counter < input.Count; counter++) { if (input[counter] == "<Tip>") { name = ""; id = 0; text = ""; } else if (input[counter] == "</Tip>") { Tip tip = new Tip(name, text, tags, id); System.Console.WriteLine(name+" "+text+" "+tags+" "+id); tips.Add(tip); } else { MatchCollection mc_name = rxTipName.Matches(input[counter]); MatchCollection mc_tags = rxTipTags.Matches(input[counter]); MatchCollection mc_id = rxTipID.Matches(input[counter]); MatchCollection mc_text = rxTipText.Matches(input[counter]); if (mc_name.Count > 0) { name = mc_name[0].Groups[1].ToString(); } else if (mc_id.Count > 0) { id = System.Int32.Parse(mc_id[0].Groups[1].ToString()); } else if (mc_text.Count > 0) { text = mc_text[0].Groups[1].ToString(); } } } return tips; }
public void saveTip(Tip tip) { string[] lines = { "<Tip>", " <id>" + tip.ID + "</id>", " <name>" + tip.Name + "</name>", " <tags>" + tip.Tags + "</tags>", " <text>" + tip.Text + "</text>", "</Tip>" }; fh.Writer(lines); }