public void ShowAlgorythmList() { AlgorythmEntities3 db = new AlgorythmEntities3(); var list = db.algorythmLists.ToList(); this.lstAlgorythm.DataSource = list; }
private void FormEdit_Load(object sender, EventArgs e) { var db = new AlgorythmEntities3(); this.textName.Text = this.al.Name; this.textDescription.Text = this.al.Description; this.textSyntax.Text = this.al.Syntax; }
private void btnSave_Click(object sender, EventArgs e) { try { var db = new AlgorythmEntities3(); var newAl = db.algorythmLists.Find(this.al.Id); newAl.Name = this.textName.Text; newAl.Description = this.textDescription.Text; newAl.Syntax = this.textSyntax.Text; db.Entry(newAl).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btSave_Click(object sender, EventArgs e) { algorythmList al = new algorythmList(); al.Name = this.txtName.Text; al.Description = this.txtDescription.Text; al.Syntax = this.txtSyntax.Text; try { var db = new AlgorythmEntities3(); db.algorythmLists.Add(al); db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btDelete_Click(object sender, EventArgs e) { var db = new AlgorythmEntities3(); if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { for (int i = 0; i < this.lstAlgorythm.SelectedRows.Count; i++) { var row = this.lstAlgorythm.SelectedRows[i]; var item = (algorythmList)row.DataBoundItem; try { algorythmList al = db.algorythmLists.Find(item.Id); db.algorythmLists.Remove(al); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot delete student" + item); } } } this.ShowAlgorythmList(); }