private void btnAdd_Click(object sender, EventArgs e) { using (var context = new EverythingContext()) { var value = Int32.Parse(txtValue.Text); if (context.SysDictionaries.Any(x => x.DictionaryNO == txtDictionaryNO.Text && x.Value == value)) { MessageBox.Show("the dictionay" + txtDictionaryName.Text + "already has this value"); return; } var item = new SysDictionary { ID = Guid.NewGuid().ToString(), DictionaryNO = txtDictionaryNO.Text, Name = txtDictionaryName.Text, Value = Int32.Parse(txtValue.Text), Display = txtDisplay.Text, Remark = txtRemark.Text }; context.SysDictionaries.Add(item); if (context.SaveChanges() == 1) { MessageBox.Show("success"); } } }
private void btnAddDic_Click(object sender, EventArgs e) { string dicNO = txtDicNO.Text; string dicName = txtDicName.Text; using (var context = new EverythingContext()) { var exit = context.SysDictionaries.Any(x => x.DictionaryNO == dicNO); if (exit) { MessageBox.Show("ExitDicNO"); } else { var dictionary = new SysDictionary { ID = Guid.NewGuid().ToString(), DictionaryNO = dicNO, Name = dicName, Value = -1, Display = dicName }; context.SysDictionaries.Add(dictionary); if (context.SaveChanges() == 1) { MessageBox.Show("success"); } } } }