public ObjectOfInvestigationPojo addObjectOfInvestigation(ObjectOfInvestigationPojo objectOfInvestigation) { SQLiteTransaction transact = Program.conn.BeginTransaction(); SQLiteCommand addObjects = new SQLiteCommand(INSERT, Program.conn, transact); addObjects.Parameters.Add(new SQLiteParameter("@id", null)); addObjects.Parameters.Add(new SQLiteParameter("@name", objectOfInvestigation.name)); try { addObjects.ExecuteNonQuery(); } catch (Exception ex) { logger.Error(ex); transact.Rollback(); if (ex.Message.Contains("FOREIGN")) { MessageBox.Show("Данную запись нельзя удалить.\nОна используется в связанных таблицах.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } throw new Exception(ex.Message); } objectOfInvestigation.id = SQLLiteUtil.getLastRowId(); foreach (Characteristic characteristic in objectOfInvestigation.characteristics) { SQLiteCommand addCharactsForObject = new SQLiteCommand(INSERT_CHARACTS, Program.conn, transact); addCharactsForObject.Parameters.Add(new SQLiteParameter("@InputParameterId", characteristic.id)); addCharactsForObject.Parameters.Add(new SQLiteParameter("@SampeTypeId", objectOfInvestigation.id)); try { addCharactsForObject.ExecuteNonQuery(); } catch (Exception ex) { logger.Error(ex); transact.Rollback(); if (ex.Message.Contains("FOREIGN")) { MessageBox.Show("Данную запись нельзя удалить.\nОна используется в связанных таблицах.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } throw new Exception(ex.Message); } } transact.Commit(); return(objectOfInvestigation); }
private void changeToolStripMenuItem_Click(object sender, EventArgs e) { if (this.obOfInvestigateListView.SelectedIndices.Count > 0) { ObjectOfInvestigationPojo objectOfInvestigation = new ObjectOfInvestigationPojo(); objectOfInvestigation.id = Int32.Parse(this.obOfInvestigateListView.SelectedItems[0].SubItems[0].Text); objectOfInvestigation.name = this.obOfInvestigateListView.SelectedItems[0].SubItems[1].Text; objectOfInvestigation.characteristics = objectsOfInvestService.getObjectCharactsByObjctId(objectOfInvestigation.id); var modObOfInvest = new ObjectOfInvestigationEdit(e); modObOfInvest.selectedObjectOfInvestigation = objectOfInvestigation; modObOfInvest.ShowDialog(this); this.obOfInvestigateListView.Items.Clear(); loadObjectsList(); this.obOfInvestigateListView.Refresh(); } }
private void SaveButton_Click(object sender, EventArgs e) { if (selectedObjectOfInvestigation == null) { ObjectOfInvestigationPojo objectOfInvestigationPojo = new ObjectOfInvestigationPojo(); objectOfInvestigationPojo.name = this.OjectName.Text; foreach (ListViewItem item in selectedCharectlistView.Items) { Characteristic characteristic = new Characteristic(Int32.Parse(item.SubItems[0].Text), item.SubItems[1].Text); objectOfInvestigationPojo.characteristics.Add(characteristic); } objectsOfInvestService.addObjectOfInvestigation(objectOfInvestigationPojo); } else//UPDATE Object of Investigation with characteristics { } }
public List <ObjectOfInvestigationPojo> getAllObjectOfInvestigations() { SQLiteCommand cmd = new SQLiteCommand(Program.conn); List <ObjectOfInvestigationPojo> objectOfInvestigations = new List <ObjectOfInvestigationPojo>(); cmd.CommandText = SELECT_ALL; try { SQLiteDataReader r = cmd.ExecuteReader(); ObjectOfInvestigationPojo objectOfInvestigation = null; while (r.Read()) { objectOfInvestigation = new ObjectOfInvestigationPojo(Int32.Parse(r["id"].ToString()), r["name"].ToString()); objectOfInvestigations.Add(objectOfInvestigation); logger.Debug("r.Read(): " + objectOfInvestigation); } r.Close(); } catch (SQLiteException ex) { logger.Error(ex); } return(objectOfInvestigations); }
public void updateObjectOfInvestigation(ObjectOfInvestigationPojo objectOfInvestigation) { throw new NotImplementedException(); }