void QManufacturersInputs_QManufacturersInputsRowDeleted(object sender, DataSetQuery.QManufacturersInputsRowChangeEvent e) { if (e.Action == DataRowAction.Delete) { if (!m_bAcceptChanges) { e.Row.RejectChanges(); } else { try { using (var cmdBuilder = new SQLiteCommandBuilder(this.qManufacturersInputsTableAdapter.Adapter)) this.qManufacturersInputsTableAdapter.Adapter.Update(this.dataSetQuery.QManufacturersInputs); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DBConcurrencyException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
void QManufacturersInputs_QManufacturersInputsRowChanged(object sender, DataSetQuery.QManufacturersInputsRowChangeEvent e) { if (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change) { /*if (!m_bAcceptChanges) * e.Row.RejectChanges(); * else * {*/ try { if (e.Action == DataRowAction.Change && m_bUpdateID) { this.dataSetQuery.QManufacturersInputs.AcceptChanges(); m_bUpdateID = false; return; } else { using (var cmdBuilder = new SQLiteCommandBuilder(this.qManufacturersInputsTableAdapter.Adapter)) this.qManufacturersInputsTableAdapter.Adapter.Update(this.dataSetQuery.QManufacturersInputs); } if (e.Action == DataRowAction.Add) { SQLiteConnection connection = new SQLiteConnection(global::DiarMain.Properties.Settings.Default.diarConnectionString); connection.Open(); SQLiteCommand com = new SQLiteCommand(connection); com.CommandText = "select seq from sqlite_sequence where name = 'ManufacturersInputs'"; com.CommandType = CommandType.Text; SQLiteDataReader dr = com.ExecuteReader(); long id = 0; while (dr.Read()) { id = Convert.ToInt64(dr["seq"]); } dr.Close(); connection.Close(); m_bUpdateID = true; ((DataRowView)(qManufacturersInputsBindingSource.Current)).Row["ManufacturerInputID"] = id; } } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DBConcurrencyException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } //} } }
void QManufacturersInputs_QManufacturersInputsRowDeleting(object sender, DataSetQuery.QManufacturersInputsRowChangeEvent e) { try { if (e.Action == DataRowAction.Delete) { if (Convert.ToInt64(e.Row["ReadOnly"]) != 0) { MyLocalizer.XtraMessageBoxShow("Недостаточно прав для удаления записи.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); m_bAcceptChanges = false; return; } if (MyLocalizer.XtraMessageBoxShow("Удалить запись?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { m_bAcceptChanges = false; return; } else { long id = Convert.ToInt64(e.Row["ManufacturerInputID"]); SQLiteConnection connection = new SQLiteConnection(global::DiarMain.Properties.Settings.Default.diarConnectionString); connection.Open(); SQLiteCommand com = new SQLiteCommand(connection); /*com.CommandText = "Select COUNT(*) AS Cnt from Equipments AS e WHERE e.ManufacturerID = @id"; * com.CommandType = CommandType.Text; * SQLiteDataReader dr = com.ExecuteReader(); * while (dr.Read()) * { * if (Convert.ToInt64(dr["Cnt"]) > 0) * { * MyLocalizer.XtraMessageBoxShow("Существует оборудование, изготовленные на данном заводе.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); * m_bAcceptChanges = false; * dr.Close(); * connection.Close(); * return; * } * } * dr.Close();*/ SQLiteParameter param1 = new SQLiteParameter("@id", DbType.Int64); param1.Value = id; com.Parameters.Add(param1); com.CommandText = "Select COUNT(*) AS Cnt from Inputs AS i WHERE i.InputManufacturerID = ?"; SQLiteDataReader dr2 = com.ExecuteReader(); while (dr2.Read()) { if (Convert.ToInt64(dr2["Cnt"]) > 0) { MyLocalizer.XtraMessageBoxShow("Существуют вводы в оборудовании, изготовленные на данном заводе.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); m_bAcceptChanges = false; dr2.Close(); connection.Close(); return; } } dr2.Close(); m_bAcceptChanges = true; connection.Close(); } } } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DBConcurrencyException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }