Beispiel #1
0
        //удаление коллекции
        private void delCollection(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            if (tvFund.SelectedNode.Text != "Фонды:")
            {
                if (tvFund.SelectedNode.Text != "Общие")
                {
                    DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите удалить коллекцию '" + tvFund.SelectedNode.Text + "'?", "Удаление коллекции", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        string sql     = "SELECT * FROM " + tvFund.SelectedNode.Text;
                        string selFund = tvFund.SelectedNode.Text;

                        OleDbConnection connection = new OleDbConnection(frmMain.connection_string);

                        connection.Open();
                        OleDbDataAdapter    adapter    = new OleDbDataAdapter(sql, connection);
                        OleDbCommandBuilder comBuilder = new OleDbCommandBuilder(adapter);
                        DataSet             dsDelExh   = new DataSet();
                        adapter.Fill(dsDelExh, "delExhibition");
                        connection.Close();

                        for (int i = 0; i < dsDelExh.Tables[0].Rows.Count; i++)
                        {
                            frmMain.sqlQuery("DELETE FROM Общие WHERE idExhibition = " + dsDelExh.Tables[0].Rows[i]["idExhibition"]);
                            frmMain.sqlQuery("DELETE FROM Экспонаты WHERE idExhibition = " + dsDelExh.Tables[0].Rows[i]["idExhibition"]);
                        }

                        frmMain.sqlQuery("DROP TABLE " + tvFund.SelectedNode.Text);

                        MessageBox.Show("Коллекция '" + selFund + "' удалена!");

                        tvFund.Nodes.Clear();
                        fundsExtract();
                        frmMain.firstSelection = true;
                        frmMain.tvFund.Nodes.Clear();
                        frmMain.fundsExtract();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        //ничего
                    }
                }
                else
                {
                    MessageBox.Show("Нельзя удалить данную коллекцию!");
                }
            }
            else
            {
                MessageBox.Show("Выберите один из фондов!");
            }
        }
Beispiel #2
0
        //сохранить изменения
        private void saveChanges(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            OleDbConnection connection = new OleDbConnection(frmMain.connection_string);

            connection.Open();
            OleDbDataAdapter    adapter    = new OleDbDataAdapter("SELECT * FROM " + selectedFund, connection);
            OleDbCommandBuilder comBuilder = new OleDbCommandBuilder(adapter);
            DataSet             dsBuffer   = new DataSet();

            adapter.Fill(dsBuffer, "Rows");
            connection.Close();

            //добавление
            if (lbNewAttr.Items.Count > 0)
            {
                for (int i = 0; i < lbNewAttr.Items.Count; i++)
                {
                    if (lbNewAttr.Items[i].ToString().Contains(' '))
                    {
                        lbNewAttr.Items[i] = lbNewAttr.Items[i].ToString().Replace(" ", "_");
                    }
                    string sqlQuery = "ALTER TABLE " + selectedFund + " ADD COLUMN [" + lbNewAttr.Items[i].ToString() + "] text(255)";
                    frmMain.sqlQuery(sqlQuery);

                    for (int j = 0; j < dsBuffer.Tables[0].Rows.Count; j++)
                    {
                        sqlQuery = "UPDATE " + selectedFund + " SET [" + lbNewAttr.Items[i].ToString() + "] = ''";
                        frmMain.sqlQuery(sqlQuery);
                    }
                }
            }

            //удаление атрибута
            for (int i = 0; i < lbAttr.Items.Count; i++)
            {
                if (lbAttr.Items[i].ToString().Contains("Удалено: "))
                {
                    connection = new OleDbConnection(frmMain.connection_string);
                    frmMain.sqlQuery("ALTER TABLE " + selectedFund + " DROP [" + attrNames[i] + "]");
                }
            }

            tbAttr.Text = "";
            lbAttr.Items.Clear();
            lbNewAttr.Items.Clear();

            frmMain.tvFund.Nodes.Clear();
            frmMain.fundsExtract();
            frmMain.selectedFund = frmMain.tvFund.Nodes[0].Nodes[0].Text;
            frmMain.filtersExtract();
        }
Beispiel #3
0
        //добавление коллекции
        private void addCollection(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            if ((sender as ToolStripButton).Name == "tsbtnAddCol")
            {
                tslblCollName.Visible       = true;
                tstbCollName.Visible        = true;
                tsbtnCollName.Visible       = true;
                tssepCollName.Visible       = true;
                tsbtnCollNameCancel.Visible = true;
            }
            else
            {
                try
                {
                    tslblCollName.Visible       = false;
                    tstbCollName.Visible        = false;
                    tsbtnCollName.Visible       = false;
                    tssepCollName.Visible       = false;
                    tsbtnCollNameCancel.Visible = false;

                    if (tstbCollName.Text != "")
                    {
                        frmMain.sqlQuery("CREATE TABLE " + tstbCollName.Text + " (idExhibition int)");
                        tvFund.Nodes.Clear();
                        fundsExtract();
                        frmMain.tvFund.Nodes.Clear();
                        frmMain.firstSelection = true;
                        frmMain.fundsExtract();
                    }
                    else
                    {
                        MessageBox.Show("Введите название коллекции!");
                    }

                    tstbCollName.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }