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();
        }
Example #2
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, "");
            }
        }