void QInputVoltageTypes_QInputVoltageTypesRowDeleted(object sender, DataSetQuery.QInputVoltageTypesRowChangeEvent e) { if (e.Action == DataRowAction.Delete) { if (!m_bAcceptChanges) { e.Row.RejectChanges(); } else { try { using (var cmdBuilder = new SQLiteCommandBuilder(this.qInputVoltageTypesTableAdapter.Adapter)) this.qInputVoltageTypesTableAdapter.Adapter.Update(this.dataSetQuery.QInputVoltageTypes); } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DBConcurrencyException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/*void InputVoltageTypes_InputVoltageTypesRowChanging(object sender, DataSetQuery.InputVoltageTypesRowChangeEvent e) * { * //throw new NotImplementedException(); * }*/ void QInputVoltageTypes_QInputVoltageTypesRowChanged(object sender, DataSetQuery.QInputVoltageTypesRowChangeEvent e) { if (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change) { try { if (e.Action == DataRowAction.Change && m_bUpdateID) { this.dataSetQuery.QInputVoltageTypes.AcceptChanges(); m_bUpdateID = false; return; } else { using (var cmdBuilder = new SQLiteCommandBuilder(this.qInputVoltageTypesTableAdapter.Adapter)) this.qInputVoltageTypesTableAdapter.Adapter.Update(this.dataSetQuery.QInputVoltageTypes); } 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 = 'InputVoltageTypes'"; 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)(qInputVoltageTypesBindingSource.Current)).Row["InputVoltageTypeID"] = id; } } catch (SQLiteException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DBConcurrencyException ex) { MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
void QInputVoltageTypes_QInputVoltageTypesRowDeleting(object sender, DataSetQuery.QInputVoltageTypesRowChangeEvent 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["InputVoltageTypeID"]); 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 WHERE InputVoltageTypeID = ?"; * com.CommandType = CommandType.Text; * SQLiteParameter param1 = new SQLiteParameter("@Param1", DbType.Int64); * param1.Value = id; * com.Parameters.Add(param1); * 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();*/ com.CommandText = "Select COUNT(*) AS Cnt from Inputs AS i WHERE i.InputTypeID = ?"; SQLiteParameter param1 = new SQLiteParameter("@Param1", DbType.Int64); param1.Value = id; com.Parameters.Add(param1); 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); } }