Beispiel #1
0
        private void confAddButton_Click(object sender, EventArgs e)
        {
            string AddType = addColSelect.Text;

            if (ColNameText.Text == "")
            {
                MessageBox.Show("need Column name as attribute!");
                goto ret;
            }
            if (attribText.Visible)
            {
                AddType = AddType + "(" + attribText.Text + ")";
            }
            if (AskPgSQL.addColumn(nowTable, ColNameText.Text, AddType) != -1)
            {
                MessageBox.Show("add succeed");
                ldTable(nowTable, "");
            }
ret:
            this.acButton.Show();
            this.confAddButton.Hide();
            this.ColNameLabel.Hide();
            this.ColTypeLabel.Hide();
            this.addColSelect.Hide();
            this.ColNameText.Hide();
            this.attribText.Hide();
        }
Beispiel #2
0
        //input : table that should be loaded to dataGridView, data constrain
        //this function should load the given table, in a given condition
        public void ldTable(string tblName, string constraint)
        {
            try
            {
                dataGridView1.Rows.Clear();
                dataGridView1.Columns.Clear();
            }
            catch (InvalidOperationException) { }
            this.reader = AskPgSQL.Fullinq(tblName, constraint);
            if (this.reader == null)
            {
                return;
            }
            nowTable = tblName;
            for (int i = 0; i < reader.VisibleFieldCount; i++)
            {
                Create_NewCol(reader.GetName(i), reader.GetDataTypeName(i).ToString());
            }

            while (reader.Read())
            {
                int newrows = dataGridView1.Rows.Add();
                for (int i = 0; i < reader.VisibleFieldCount; i++)
                {
                    readerJudge(this.reader, newrows, i);
                }
                if (dataGridView1.Rows.Count > 100)
                {
                    break;
                }
            }
        }
        private void modButton_Click(object sender, EventArgs e)
        {
            string constype = "";

            string[] numbers = { "integer", "real", "numeric" };
            if (less.Checked)
            {
                constype = "<";
            }
            if (more.Checked)
            {
                constype = ">";
            }
            if (equal.Checked)
            {
                constype = "=";
            }
            constype += consText.Text;
            string constraint = dataGridView1.Columns[ColumnIndex].Name + " " + constype;
            string condition  = dataGridView1.Columns[ColumnIndex].Name + " " + updText.Text;

            AskPgSQL.updateCell(nowTable, constraint, dataGridView1.Columns[ColumnIndex].Name, condition,
                                numbers.Contains(dataGridView1.Columns[ColumnIndex].DataPropertyName));
            management.ldTable(nowTable, "");
            this.Close();
        }
Beispiel #4
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
            {
                return;
            }
            string[] numbers  = { "integer", "real", "numeric" };
            bool     is_empty = true;

            Console.WriteLine(e.RowIndex + " " + dataGridView1.RowCount);
            for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
            {
                if (i == e.ColumnIndex)
                {
                    continue;
                }
                if (dataGridView1.Rows[e.RowIndex].Cells[i].Value != null)
                {
                    is_empty = false;
                    break;
                }
            }
            if (e.RowIndex == dataGridView1.RowCount - 2 && is_empty)
            {
                MessageBox.Show("New Line!");
                AskPgSQL.insertRow(nowTable, dataGridView1.Columns[e.ColumnIndex].Name, dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString(),
                                   numbers.Contains(dataGridView1.Columns[e.ColumnIndex].DataPropertyName));
                ldTable(nowTable, "");
            }
            else
            {
                UpdateCellData(e);
            }
        }
 private void confrimAltButton_Click(object sender, EventArgs e)
 {
     if (AskPgSQL.altetColType(nowTable, dataGridView1.Columns[ColumnIndex].Name, consText.Text) != -1)
     {
         MessageBox.Show("Alter into " + consText.Text + " Succeed");
     }
     this.Close();
 }
        private void delButton_Click(object sender, EventArgs e)
        {
            string columName = dataGridView1.Columns[ColumnIndex].Name;

            if (MessageBox.Show("Sure to DELETE column " + columName + "?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                AskPgSQL.deleteCol(nowTable, columName);
            }
            this.Close();
        }
Beispiel #7
0
 //load the name of the database into the selection list
 private void load_database()
 {
     this.reader = AskPgSQL.dbNameinq();
     while (reader.Read())
     {
         string dbName = reader.GetString(0);
         if (listBox1.Items.Contains(dbName) == false)
         {
             listBox1.Items.Add(dbName);
         }
     }
 }
Beispiel #8
0
        private void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string constraint = "";

            string[] numbers = { "integer", "real", "numeric" };
            if (MessageBox.Show("Delete row " + "?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                constraint = constraintSelection(e.RowIndex, e.ColumnIndex);


                AskPgSQL.deleteRow(nowTable, constraint.Substring(0, constraint.Length - 4));
                ldTable(nowTable, "");
            }
        }
Beispiel #9
0
 private void drpTabel_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Sure to DROP" + listBox1.SelectedItem.ToString().Substring(1) + " ?",
                         "", MessageBoxButtons.YesNo) == DialogResult.No)
     {
         return;
     }
     else
     {
         AskPgSQL.dropTable(listBox1.SelectedItem.ToString().Substring(1));
     }
     listBox1.Items.Clear();
     load_database();
     MessageBox.Show("Table dropped");
 }
Beispiel #10
0
        //load the table name of the database into the selection list
        private void load_tableName()
        {
            int initialNum = listBox1.Items.Count;

            this.reader = AskPgSQL.tableNameinq();
            while (reader.Read())
            {
                int    i         = 1;
                string tableName = "-" + reader.GetString(0);
                if (listBox1.Items.Contains(tableName) == false)
                {
                    listBox1.Items.Insert(listBox1.SelectedIndex + i, tableName);
                    i++;
                }
            }
        }
Beispiel #11
0
 //answer to the button 'Query' ,load the table for dataGridView
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string selectedTable = listBox1.SelectedItem.ToString();
         if (selectedTable[0] != '-')
         {
             AskPgSQL.connection(selectedTable);
             load_tableName();
             return;
         }
         selectedTable = selectedTable.Substring(1);
         ldTable(selectedTable, "");
     }
     catch (NullReferenceException)
     {
     }
 }
Beispiel #12
0
        //Update the database by editing the grid cell
        private void UpdateCellData(DataGridViewCellEventArgs e)
        {
            if (MessageBox.Show("Sure to edit" + txtBeforeEdit + "to" + dataGridView1[e.ColumnIndex, e.RowIndex].Value + " ?",
                                "", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }
            string constraint = constraintSelection(e.RowIndex, e.ColumnIndex);

            // Console.WriteLine(constraint.Substring(0,constraint.Length-1));
            string[] numbers        = { "integer", "real", "numeric" };
            string   txtBeforeEditn = txtBeforeEdit;

            if (!numbers.Contains(dataGridView1.Columns[e.ColumnIndex].DataPropertyName))
            {
                txtBeforeEditn = '\'' + txtBeforeEdit + '\'';
            }
            else
            {
                try
                {
                    int.Parse(txtBeforeEdit);
                    constraint = constraint + dataGridView1.Columns[e.ColumnIndex].Name + " = " + txtBeforeEditn;
                }
                catch (FormatException)
                {
                }
            }
            while (constraint.Substring(constraint.Length - 4) == "AND ")
            {
                constraint = constraint.Substring(0, constraint.Length - 4);
            }
            if (AskPgSQL.updateCell(nowTable, constraint, dataGridView1.Columns[e.ColumnIndex].Name,
                                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(),
                                    numbers.Contains(dataGridView1.Columns[e.ColumnIndex].DataPropertyName))
                == -1)
            {
                MessageBox.Show("Update Error");
                ldTable(nowTable, "");
            }
        }
Beispiel #13
0
 private void fileButton_Click(object sender, EventArgs e)
 {
     openFileDialog1.ShowDialog();
     Console.WriteLine(openFileDialog1.FileName);
     AskPgSQL.copyFrom(nowTable, openFileDialog1.FileName);
 }
Beispiel #14
0
 private void createBtn_Click(object sender, EventArgs e)
 {
     AskPgSQL.creatTable(generate_sqlCommand());
     this.Close();
 }