public void InitialDefaultUser() { using (DataContainer c = new DataContainer()) { User u = new User(); u.Birth = DateTime.Now; u.Height = 10; u.Weight = 10; u.QQ = "363212404"; u.Male = true; u.Married = false; } }
private void button1_Click(object sender, EventArgs e) { string name = textBox2.Text; if (string.IsNullOrEmpty(name)) return; using (DataContainer c = new DataContainer()) { int id = Convert.ToInt32(Tree1.SelectedNode.Tag); Category parent = c.Category.First(p => p.Id == id); Category category = new Category(); category.Name = name; category.Parent = parent; c.AddToCategory(category); c.SaveChanges(); } //LoadInfo(); }
private void addCountry(string zhou, string name) { using (DataContainer c = new DataContainer()) { var guo = (from l in c.Category where l.Id == 43 select l).First();//洲 Object z1 = new Object(); z1.Category.Add(guo); z1.Name = name; z1.Remark = ""; z1.ObjectPropty.Add(new ObjectPropty() { Name = "国家",Value = ""}); z1.ObjectPropty.Add(new ObjectPropty() { Name = "洲", Value = zhou }); c.AddToObject(z1); c.SaveChanges(); w("保存:" + name); } }
private void addCity(string province,string name) { using (DataContainer c = new DataContainer()) { var sheng = (from l in c.Category where l.Id == 82 select l).First();//城市 Object z1 = new Object(); z1.Category.Add(sheng); z1.Name = name; z1.Remark = ""; z1.ObjectPropty.Add(new ObjectPropty() { Name = "城市", Value = "" }); z1.ObjectPropty.Add(new ObjectPropty() { Name = "省", Value = province }); c.AddToObject(z1); c.SaveChanges(); w("保存:" + name); } }
public void TryAddSomeCitys() { using (DataContainer c = new DataContainer()) { addZhou("亚洲"); addZhou("非洲"); addZhou("欧洲"); addZhou("南美洲"); addZhou("北美洲"); addZhou("大洋洲"); addZhou("南极洲"); addCountry("亚洲","中国"); addCountry("亚洲", "日本"); addProvince("中国", "辽宁"); addProvince("中国", "北京"); addCity("辽宁","沈阳"); addCity("辽宁", "大连"); } }
private void LoadInfo() { using (DataContainer c = new DataContainer()) { var allCategorys = c.Category.ToList(); if (allCategorys.Count == 0 || allCategorys.Any(p => p.Name == "root") == false) { Category root_add = new Category(); root_add.Name = "root"; root_add.Parent = null; c.AddToCategory(root_add); c.SaveChanges(); } Category root = c.Category.Where(p => p.Name == "root").First(); Tree1.Nodes.Clear(); var nodes = GetTreeNodes(root); nodes.ExpandAll(); Tree1.Nodes.Add(nodes); } }
private void IniQuestionTemplate() { w("Initialling question template..."); using (DataContainer c = new DataContainer()) { QuestionTemplate q1 = new QuestionTemplate(); q1.Regex = @"(今天|现在)几号"; c.AddToQuestionTemplate(q1); AnswerTemplate a1 = new AnswerTemplate(); a1.Answer = "{nowdate}"; c.AddToAnswerTemplate(a1); AnswerTemplate a11 = new AnswerTemplate(); a11.Answer = "今天应该是{nowdate}"; c.AddToAnswerTemplate(a11); QuestionTemplate q2 = new QuestionTemplate(); q2.Regex = @"(现在)?几点"; c.AddToQuestionTemplate(q2); AnswerTemplate a2 = new AnswerTemplate(); a2.Answer = "{nowtime}"; c.AddToAnswerTemplate(a2); AnswerTemplate a21 = new AnswerTemplate(); a21.Answer = "差不多{nowtime}的样子"; c.AddToAnswerTemplate(a21); q1.AnswerTemplate.Add(a1); q1.AnswerTemplate.Add(a11); q2.AnswerTemplate.Add(a2); q2.AnswerTemplate.Add(a21); c.SaveChanges(); } w("Initialling question template complete."); }
private void addZhou(string name) { using (DataContainer c = new DataContainer()) { var zhou = (from l in c.Category where l.Id == 42 select l).First();//洲 Object z1 = new Object(); z1.Category.Add(zhou); z1.Name = name; z1.Remark = ""; c.AddToObject(z1); c.SaveChanges(); w("保存:" + name); } }
private static void Learning() { while (true) { string input = Console.ReadLine().Trim(); if (string.IsNullOrEmpty(input)) { continue; } using (DataContainer c = new DataContainer()) { var temps = c.QuestionTemplate.ToList(); QuestionTemplate findedQuestion = null; foreach (QuestionTemplate temp in temps) { if (Regex.IsMatch(input, temp.Regex)) { findedQuestion = temp; } } if (findedQuestion == null) { Console.WriteLine("answer:"); string str_a = Console.ReadLine(); List<AnswerTemplate> OtherAnswers = new List<AnswerTemplate>(); Console.WriteLine("onther answer:"); string str_other_answer = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(str_other_answer) == false) { AnswerTemplate ans = new AnswerTemplate(); ans.Answer = str_other_answer; c.AddToAnswerTemplate(ans); OtherAnswers.Add(ans); str_other_answer = Console.ReadLine().Trim(); } Console.WriteLine("Possible questrion:"); string str_reg = Console.ReadLine(); QuestionTemplate q = new QuestionTemplate(); if (string.IsNullOrEmpty(str_reg)) { q.Regex = input; } else { q.Regex = str_reg; } c.AddToQuestionTemplate(q); AnswerTemplate a = new AnswerTemplate(); a.Answer = str_a; a.QuestionTemplate = q; c.AddToAnswerTemplate(a); foreach (AnswerTemplate answerTemplate in OtherAnswers) { answerTemplate.QuestionTemplate = q; } c.SaveChanges(); Console.WriteLine("ok ,I got it."); } else { Console.WriteLine(WordsProcess.ProcessAll(findedQuestion.AnswerTemplate.OrderBy(p => Guid.NewGuid()).First().Answer)); List<AnswerTemplate> OtherAnswers = new List<AnswerTemplate>(); Console.WriteLine("onther answer:"); string str_other_answer = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(str_other_answer) == false) { AnswerTemplate ans = new AnswerTemplate(); ans.Answer = str_other_answer; c.AddToAnswerTemplate(ans); OtherAnswers.Add(ans); ans.QuestionTemplate = findedQuestion; str_other_answer = Console.ReadLine().Trim(); } c.SaveChanges(); } } } }
static void Main(string[] args) { using (Data2Container c = new Data2Container()) { string s = "我去吃饭了"; var sr = SpWords(s); foreach (List<string> list in sr) { Console.Write("pi:"); foreach (string s1 in list) { Console.Write(s1+"/"); } Console.WriteLine(""); } Console.ReadLine(); } return; while (true) { string input = Console.ReadLine().Trim(); input = WordsProcess.UserWordsProcess(input); if (input == "weathertest") { Wisdom.ServiceHelper.Svc.GetWeatherByName("大连"); } if (input == "addcity") { Ini i = new Ini(); i.TryAddSomeCitys(); } if (input == "初始化全部数据") { Ini i = new Ini(); i.InitialAll(); } if (input == "learning") { Learning(); } using (DataContainer c = new DataContainer()) { var temps = c.QuestionTemplate.ToList(); QuestionTemplate findedQuestion = null; string key = ""; foreach (QuestionTemplate temp in temps) { if (Regex.IsMatch(input, temp.Regex)) { findedQuestion = temp; key = new Regex(temp.Regex).Match(input).Groups["key"].Value; } } if (findedQuestion == null) { Console.WriteLine("Sorry Can Not Know What That Mean."); } else { string str_q = WordsProcess.ProcessAll(findedQuestion.AnswerTemplate.OrderBy(p => Guid.NewGuid()).First().Answer, key); Console.WriteLine(str_q); } } } }
private void Save_Click(object sender, EventArgs e) { using (DataContainer c = new DataContainer()) { int id = Convert.ToInt32(Tree1.SelectedNode.Tag); var cs = c.Category.Where(p => p.Id == id); foreach (Category category in cs) { category.Name = textBox1.Text; } c.SaveChanges(); } LoadInfo(); }