private void button1_Click(object sender, EventArgs e) { Object_Document od = new Object_Document(); od.Document_Specialty_Id = db.Document_Specialty .FirstOrDefault( ds => ds.Specialty_Id == db.Specialty .FirstOrDefault(s => s.Specialty_Name == comboBox4.SelectedItem.ToString()) .Specialty_Id&& ds.Document_Id == db.Document.FirstOrDefault(d => d.Document_Name == comboBox1.SelectedValue.ToString()) .Document_Id).Document_Specialty_Id; od.Object_Id = db.Object.FirstOrDefault(o => o.Variaton_Id == null ? db.Object_Library.FirstOrDefault(ol => ol.Object_Library_Name == comboBox2.SelectedItem.ToString()) .Object_Library_Id == o.Object_Library_Id : db.Variation.FirstOrDefault(ol => ol.Variation_Name == comboBox2.SelectedItem.ToString()) .Variation_Id == o.Variaton_Id).Object_Id; Object_Document_Parameter odp = new Object_Document_Parameter(); odp.Object_Document_Id = od.Object_Document_Id; odp.Parameter_Id = db.Parameter.FirstOrDefault(p => p.Parameter_Name == comboBox3.SelectedValue.ToString()) .Parameter_Id; odp.Type = radioButton1.Checked ? 0 : radioButton2.Checked ? 1 : 2; db.Object_Document_Parameter.Add(odp); db.Object_Document.Add(od); db.SaveChanges(); MessageBox.Show("Добавлено"); }
private void button1_Click(object sender, EventArgs e) { Object obj = new Object(); obj.Object_Library_Id = db.Object_Library .FirstOrDefault(o => o.Object_Library_Name == comboBox1.SelectedValue).Object_Library_Id; obj.Place_Id = db.Place .FirstOrDefault(o => o.Place_Name == comboBox4.SelectedValue).Place_Id; obj.Amount = Convert.ToInt32(textBox1.Text); try { obj.Variaton_Id = db.Variation .FirstOrDefault(o => o.Variation_Name == comboBox2.SelectedItem.ToString()).Variation_Id; } catch (Exception) { } Station_Object so = new Station_Object(); so.Object_Id = obj.Object_Id; so.Station_Id = UserData.station; Department_Object dob = new Department_Object(); dob.Department_Id = UserData.department; dob.Object_Id = obj.Object_Id; db.Department_Object.Add(dob); db.Station_Object.Add(so); db.Object.Add(obj); db.SaveChanges(); MessageBox.Show("Добавлено"); }
private void button1_Click(object sender, EventArgs e) { Document doc = new Document(); doc.Document_Name = textBox1.Text; doc.Type = radioButton2.Checked ? 1 : 0; db.Document.Add(doc); db.SaveChanges(); MessageBox.Show("Добавлено"); }
private void button2_Click(object sender, EventArgs e) { User u = new User(); u.Login = textBox1.Text; u.Password = textBox2.Text; if (radioButton1.Checked) { u.Type = 4; } else if (radioButton3.Checked) { u.Type = 3; } else if (radioButton2.Checked) { u.Type = 2; } else { u.Type = 1; } db.User.Add(u); Department_User d = new Department_User(); d.User_Id = u.User_Id; d.Deprtment_Id = db.Department.FirstOrDefault(de => de.Department_Name == comboBox1.SelectedValue) .Department_Id; db.Department_User.Add(d); for (int i = 0; i < count; i++) { Station_User su = new Station_User(); string s = dataGridView1.Rows[i].Cells[0].Value.ToString(); su.Station_id = db.Station .FirstOrDefault(st => st.Station_Name == s).Station_Id; su.User_Id = u.User_Id; db.Station_User.Add(su); } db.SaveChanges(); MessageBox.Show("Добавлено"); }