public void AddShip(Ship newShip) { DataRow row = this.NewRow(); row[0] = newShip.ID; foreach (Data.Item item in Data.DataShip.Common) if (this.Columns.Contains(item.Name)) row[this.Columns[item.Name]] = Data.DataShip.GetData(newShip, item.Name); this.Rows.Add(row); }
partial void DeleteShip(Ship instance);
private void buttonAdd_Click(object sender, EventArgs e) { for (int i = 0; i < dataGridViewNew.RowCount - 1; i++) { if (!RowIsEmpty(dataGridViewNew.Rows[i])) { switch (_tableType) { case SampleType.Patients: Patient newPatient = new Patient(); //Data.DataPatient dataPatient = new Data.DataPatient(); newPatient.MedCard = new MedCard(); //newPatient.MedAccount = new MedAccount(); newPatient.MilitaryCard = new MilitaryCard(); newPatient.PsyCard = new PsyCard(); newPatient.StudyCard = new StudyCard(); newPatient.WorkCard = new WorkCard(); newPatient.BehaviorCard = new BehaviorCard(); newPatient.FamilyCard = new FamilyCard(); foreach (DataGridView gridTable in tables) { if (!RowIsEmpty(gridTable.Rows[i])) { _table = (DataTable)gridTable.DataSource; for (int j = 0; j < _table.Columns.Count; j++) Data.DataPatient.SetData(_table.Rows[i][_table.Columns[j].ColumnName], _table.Columns[j].ColumnName, ref newPatient); } } int shipID = 0; if (int.TryParse(dataGridViewMil[2, i].Value.ToString(), out shipID)) { var ships = from ship in FormMain.myContext.Ships where ship.BoardNum == shipID select ship; newPatient.MilitaryCard.Ship = ships.Single(); } newPatient.MedCard.Illnesses.AddRange(_illnesses[i]); newPatient.BehaviorCard.PoliceEvents.AddRange(_events[i]); newPatient.Relatives.AddRange(_relatives[i]); FormMain.myContext.Patients.InsertOnSubmit(newPatient); break; case SampleType.Ships: Ship newShip = new Ship(); _table = (DataTable)dataGridViewNew.DataSource; for (int j = 0; j < _table.Columns.Count; j++) Data.DataShip.SetData(_table.Rows[i][_table.Columns[j].ColumnName], _table.Columns[j].ColumnName, ref newShip); if (dataGridViewNew[2, i].Value.ToString() != "" && dataGridViewNew[3, i].Value.ToString() != "") { var officers = from officer in FormMain.myContext.Officers where officer.Surname == dataGridViewNew[2, i].Value.ToString() && officer.Name == dataGridViewNew[3, i].Value.ToString() select officer; newShip.Officer = officers.Single(); } FormMain.myContext.Ships.InsertOnSubmit(newShip); break; case SampleType.Officers: Officer newOfficer = new Officer(); _table = (DataTable)dataGridViewNew.DataSource; for (int j = 0; j < _table.Columns.Count; j++) Data.DataOfficer.SetData(_table.Rows[i][_table.Columns[j].ColumnName], _table.Columns[j].ColumnName, ref newOfficer); FormMain.myContext.Officers.InsertOnSubmit(newOfficer); break; } } } FormMain.myContext.SubmitChanges(); }
partial void UpdateShip(Ship instance);
partial void InsertShip(Ship instance);
private void detach_Ships(Ship entity) { this.SendPropertyChanging(); entity.Officer = null; }
private void attach_Ships(Ship entity) { this.SendPropertyChanging(); entity.Officer = this; }
private void AddShip(String name, int num) { Ship newShip = new Ship(); newShip.BoardNum = num; newShip.Name = name; myContext.Ships.InsertOnSubmit(newShip); myContext.SubmitChanges(); }