Exemple #1
0
 void QBranches_QBranchesRowDeleted(object sender, DataSetQuery.QBranchesRowChangeEvent e)
 {
     if (e.Action == DataRowAction.Delete)
     {
         if (!m_bAcceptChanges)
         {
             e.Row.RejectChanges();
         }
         else
         {
             try
             {
                 using (var cmdBuilder = new SQLiteCommandBuilder(this.qBranchesTableAdapter.Adapter)) this.qBranchesTableAdapter.Adapter.Update(this.dataSetQuery.QBranches);
             }
             catch (SQLiteException ex)
             {
                 MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             catch (DBConcurrencyException ex)
             {
                 MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemple #2
0
        /*void repositoryItemLookUpEdit1_Popup(object sender, EventArgs e)
         * {
         *  if (this.dataSetMain.Subjects.Rows.Count < 7)
         *      this.repositoryItemLookUpEdit1.DropDownRows = this.dataSetMain.Subjects.Rows.Count;
         *  else
         *      this.repositoryItemLookUpEdit1.DropDownRows = 7;
         *  //throw new NotImplementedException();
         * }
         *
         * void repositoryItemLookUpEdit1_ListChanged(object sender, ListChangedEventArgs e)
         * {
         *  //this.repositoryItemLookUpEdit1.
         *  //throw new NotImplementedException();
         * }*/

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

                    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 = 'Branches'";
                        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)(qBranchesBindingSource.Current)).Row["BranchID"] = id;
                    }
                }
                catch (SQLiteException ex)
                {
                    MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (DBConcurrencyException ex)
                {
                    MyLocalizer.XtraMessageBoxShow(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #3
0
        void QBranches_QBranchesRowDeleting(object sender, DataSetQuery.QBranchesRowChangeEvent 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["BranchID"]);

                        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 " +
                                          "INNER JOIN Substations AS s ON s.SubstationID = e.SubstationID " +
                                          "WHERE s.BranchID = ?";
                        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 Substations AS s WHERE s.BranchID = ?";
                        SQLiteDataReader dr2             = com.ExecuteReader();
                        long             iCntSubstations = 0;
                        while (dr2.Read())
                        {
                            iCntSubstations = Convert.ToInt64(dr2["Cnt"]);
                            if (iCntSubstations > 0)
                            {
                                if (MyLocalizer.XtraMessageBoxShow("Данный филиал содержит подстанции. Удалить их вместе с филиалом?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                {
                                    m_bAcceptChanges = false;
                                    dr2.Close();
                                    connection.Close();
                                    return;
                                }
                            }
                        }
                        dr2.Close();

                        if (iCntSubstations > 0)
                        {
                            com.CommandText = "Delete from Substations WHERE BranchID = ?";
                            com.ExecuteNonQuery();
                        }

                        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);
            }
        }