private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("You must enter the name of the movie!"); } else { using (db = new DataClassesDataContext(c.connectionString)) { video v = new video(); v.name = textBox1.Text; v.status_id = 1; v.type_id = Int32.Parse((comboBox1.SelectedValue.ToString())); v.year = Convert.ToString(numericUpDown1.Value); v.@new = Int32.Parse((comboBox2.SelectedValue.ToString())); v.data_add = Convert.ToDateTime(DateTime.Now.ToShortDateString().ToString()); db.video.InsertOnSubmit(v); try { db.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); db.SubmitChanges(); } MessageBox.Show("Great!"); } } }
/// <summary> /// Update /// </summary> /// <param name="sender">The sender<see cref="object"/></param> /// <param name="e">The e<see cref="EventArgs"/></param> private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("You must enter the name of the movie!"); } else { int videoID = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); using (db = new DataClassesDataContext(c.connectionString)) { var results = ( from v in db.video where v.id == videoID select v); foreach (var res in results) { video v_now = db.video.Single(v => v.id == res.id); v_now.name = textBox1.Text; v_now.type_id = Int32.Parse((comboBox1.SelectedValue.ToString())); v_now.year = Convert.ToString(numericUpDown1.Value); v_now.status_id = Int32.Parse((comboBox2.SelectedValue.ToString())); v_now.data_edit = Convert.ToDateTime(DateTime.Now.ToShortDateString().ToString()); db.SubmitChanges(); dataGridView1.DataSource = db.v_video; MessageBox.Show("Updated!"); } } /* var count = (from r in db.rental * where r.video_id == videoID * select r).Count(); * * if (count > 0) * { * } */ } }
private void detach_video(video entity) { this.SendPropertyChanging(); entity.type = null; }
private void attach_video(video entity) { this.SendPropertyChanging(); entity.type = this; }
partial void Deletevideo(video instance);
partial void Updatevideo(video instance);
partial void Insertvideo(video instance);