Ejemplo n.º 1
0
 void QSwitchDriveTypes_QSwitchDriveTypesRowDeleted(object sender, DataSetQuery.QSwitchDriveTypesRowChangeEvent e)
 {
     if (e.Action == DataRowAction.Delete)
     {
         if (!m_bAcceptChanges)
         {
             e.Row.RejectChanges();
         }
         else
         {
             try
             {
                 using (var cmdBuilder = new SQLiteCommandBuilder(this.qSwitchDriveTypesTableAdapter.Adapter)) this.qSwitchDriveTypesTableAdapter.Adapter.Update(this.dataSetQuery.QSwitchDriveTypes);
             }
             catch (SQLiteException ex)
             {
                 MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (DBConcurrencyException ex)
             {
                 MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
        void QSwitchDriveTypes_QSwitchDriveTypesRowDeleting(object sender, DataSetQuery.QSwitchDriveTypesRowChangeEvent 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["SwitchDriveTypeID"]);

                        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 SwitchDriveTypeID = ?";
                        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();

                        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);
            }
        }
Ejemplo n.º 3
0
        /*void QSwitchDriveTypes_QSwitchDriveTypesRowChanging(object sender, DataSetQuery.QSwitchDriveTypesRowChangeEvent e)
         * {
         *  //throw new NotImplementedException();
         * }*/

        void QSwitchDriveTypes_QSwitchDriveTypesRowChanged(object sender, DataSetQuery.QSwitchDriveTypesRowChangeEvent e)
        {
            if (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change)
            {
                try
                {
                    if (e.Action == DataRowAction.Change && m_bUpdateID)
                    {
                        this.dataSetQuery.QSwitchDriveTypes.AcceptChanges();
                        m_bUpdateID = false;
                        return;
                    }
                    else
                    {
                        using (var cmdBuilder = new SQLiteCommandBuilder(this.qSwitchDriveTypesTableAdapter.Adapter)) this.qSwitchDriveTypesTableAdapter.Adapter.Update(this.dataSetQuery.QSwitchDriveTypes);
                    }

                    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 = 'SwitchDriveTypes'";
                        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)(qSwitchDriveTypesBindingSource.Current)).Row["SwitchDriveTypeID"] = id;
                    }
                }
                catch (SQLiteException ex)
                {
                    MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (DBConcurrencyException ex)
                {
                    MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }