public ServiceTransportationIEF(ServiceTransportation obj, my_db_for_db_2Entities _db) { InitializeComponent(); db = _db; serviceBindingSource.DataSource = db.Service.ToList(); serviceCenterBindingSource.DataSource = db.ServiceCenter.ToList(); serviceTransportationBindingSource.DataSource = db.ServiceTransportation.ToList(); if (obj == null) { serviceTransportationBindingSource.DataSource = new ServiceTransportation(); db.ServiceTransportation.Add(serviceTransportationBindingSource.Current as ServiceTransportation); } else { serviceTransportationBindingSource.DataSource = obj; db.ServiceTransportation.Attach(serviceTransportationBindingSource.Current as ServiceTransportation); } }
private void NewServiceTransportationForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.OK) { if (ServiceComboBox.SelectedValue != null) { if (SCComboBox.SelectedValue != null) { ServiceTransportation serviceTransportation = new ServiceTransportation() { Code = CodeGenerator.GenerateCode("ServiceTransportation", "st"), Service_ID = (int)ServiceComboBox.SelectedValue, SC_ID = (int)SCComboBox.SelectedValue, Date = DateTime.Now }; Service service = db.Service .Where(x => x.Service_ID.Equals((int)ServiceComboBox.SelectedValue)) .FirstOrDefault(); db.Service.Attach(service); service.Status_ID = 4;//у перевезені db.ServiceTransportation.Add(serviceTransportation); db.SaveChanges(); } else { MessageBox.Show("Оберіть сервісний центр", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Cancel = true; return; } } else { MessageBox.Show("оберіть заявку на ремонт", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Cancel = true; return; } } e.Cancel = false; }