Ejemplo n.º 1
0
        private void btEdit_Click(object sender, System.EventArgs e)
        {
            TableNode nd = treeView1.SelectedNode as TableNode;
            int       n  = cbxFields.SelectedIndex;

            if (nd != null && n >= 0)
            {
                try
                {
                    dlgEditField dlg = new dlgEditField();
                    EPField      fld = (EPField)((EPField)cbxFields.Items[n]).Clone();
                    dlg.LoadData(nd.Text, fld, qry.DatabaseConnection.ConnectionObject);
                    if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                    {
                        nd.table.GetFields(qry.DatabaseConnection.ConnectionObject);
                        nd.table.GetIndexes(qry.DatabaseConnection.ConnectionObject);
                        treeView1_AfterSelect(null, null);
                        if (n < cbxFields.Items.Count)
                        {
                            cbxFields.SelectedIndex = n;
                        }
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(this, VPLUtil.FormExceptionText(er), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private void btDelTable_Click(object sender, System.EventArgs e)
        {
            TableNode nd = treeView1.SelectedNode as TableNode;

            if (nd != null)
            {
                try
                {
                    string s = "Table name:" + nd.Text + "\r\n" + "Do you want to delete this table from the database?";
                    if (MessageBox.Show(this, s, this.Text, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        qry.DatabaseConnection.ConnectionObject.DropTable(nd.Text);
                        Connection cn = new Connection();
                        cn.TheConnection = qry.DatabaseConnection.ConnectionObject.TheConnection;
                        schema.dbCon     = cn;
                        schema.LoadSchema();
                        loadTables();
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(this, VPLUtil.FormExceptionText(er), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 3
0
        private void btAddTable_Click(object sender, System.EventArgs e)
        {
            string      sRet = "";
            string      sID  = "";
            dlgNewTable dlg  = new dlgNewTable();

            if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                sRet = dlg.sName;
                sID  = dlg.sID.Trim();
                bool bUsed = false;
                int  i;
                for (i = 0; i < treeView1.Nodes.Count; i++)
                {
                    if (string.Compare(sRet, treeView1.Nodes[i].Text, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bUsed = true;
                        break;
                    }
                }
                if (bUsed)
                {
                    MessageBox.Show(this, Resource1.dbMsg1, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                }
                else
                {
                    try
                    {
                        Connection connect = qry.DatabaseConnection.ConnectionObject;
                        connect.CreateTable(sRet, sID);
                        schema.dbCon = connect;
                        schema.LoadSchema();
                        loadTables();
                        for (i = 0; i < treeView1.Nodes.Count; i++)
                        {
                            if (string.Compare(sRet, treeView1.Nodes[i].Text, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                treeView1.SelectedNode = treeView1.Nodes[i];
                                break;
                            }
                        }
                    }
                    catch (Exception er)
                    {
                        MessageBox.Show(this, VPLUtil.FormExceptionText(er), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /*
  * For MySQL
  * CREATE TABLE  child_table(
  *      foo INT
  *      ,bar INT
  *      ,FOREIGN KEY (bar) REFERENCES parent_table(parent_key)
  *      ON UPDATE CASCADE ON DELETE SET NULL
  */
 private void treeView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
 {
     try
     {
         bool bCanDrop           = false;
         System.Drawing.Point pt = new System.Drawing.Point(e.X, e.Y);
         pt = treeView1.PointToClient(pt);
         TableNode nd = (TableNode)treeView1.GetNodeAt(pt);
         if (dragData != null && nd != null)
         {
             if (nd.Parent == null)
             {
                 if (nd != dragData.objNode)
                 {
                     //nd must have unique key and cannot be a child of dragData
                     if (nd.table.HasUniqueKey())
                     {
                         bCanDrop = !schema.RelationExists(nd.table.TableName, dragData.objNode.table.TableName);
                     }
                 }
                 if (bCanDrop)
                 {
                     dlgSetRelation dlg = new dlgSetRelation();
                     dlg.LoadData(nd.table, dragData.objNode.table, qry.DatabaseConnection.ConnectionObject);
                     if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                     {
                         schema.dbCon = qry.DatabaseConnection.ConnectionObject;
                         schema.LoadSchema();
                         this.loadTables();
                     }
                 }
             }
         }
     }
     catch (Exception er)
     {
         MessageBox.Show(this, VPLUtil.FormExceptionText(er), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         clearDrag();
     }
 }
Ejemplo n.º 5
0
        private void btDelField_Click(object sender, System.EventArgs e)
        {
            TableNode nd = treeView1.SelectedNode as TableNode;
            int       n  = cbxFields.SelectedIndex;

            if (nd != null && n >= 0)
            {
                try
                {
                    EPField fld = (EPField)cbxFields.Items[n];
                    string  s   = fld.Name + "\r\n";
                    s += Resource1.askDeleteField;
                    if (MessageBox.Show(this, s, this.Text, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        qry.DatabaseConnection.ConnectionObject.DropColumn(nd.Text, fld.Name);
                        nd.table.GetFields(qry.DatabaseConnection.ConnectionObject);
                        nd.table.GetIndexes(qry.DatabaseConnection.ConnectionObject);
                        treeView1_AfterSelect(null, null);
                        if (n < cbxFields.Items.Count)
                        {
                            cbxFields.SelectedIndex = n;
                        }
                        else
                        {
                            if (cbxFields.Items.Count > 0)
                            {
                                cbxFields.SelectedIndex = cbxFields.Items.Count - 1;
                            }
                        }
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(this, VPLUtil.FormExceptionText(er), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 6
0
        private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            btDelChild.Enabled = false;
            cbxFields.Items.Clear();
            TableNode nd = treeView1.SelectedNode as TableNode;

            if (nd != null)
            {
                try
                {
                    int i;
                    btDelChild.Enabled = (nd.Parent != null);
                    //
                    if (!nd.FieldsLoaded)
                    {
                        nd.FieldsLoaded = true;
                        nd.table.GetFields(schema.dbCon);
                        nd.table.GetIndexes(schema.dbCon);
                    }
                    for (i = 0; i < nd.table.FieldCount; i++)
                    {
                        cbxFields.Items.Add(nd.table.GetField(i));
                    }
                    //check unique index
                    bool bIndexed = false;
                    for (i = 0; i < nd.table.FieldCount; i++)
                    {
                        if (nd.table.GetField(i).Indexed)
                        {
                            bIndexed = true;
                            break;
                        }
                    }
                    if (!bIndexed)
                    {
                        if (nd.table.Indexes != null)
                        {
                            for (i = 0; i < nd.table.Indexes.Length; i++)
                            {
                                if (nd.table.Indexes[i].IsUnique)
                                {
                                    for (int j = 0; j < nd.table.Indexes[i].fields.Count; j++)
                                    {
                                        nd.table.fields[nd.table.Indexes[i].fields[i].Name].Indexed = true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    //
                    dataGrid1.Refresh();
                    dataGrid1.DataBindings.Clear();
                    dataGrid1.DataSource = null;
                    dataGrid1.DataMember = null;
                    //
                    qry.ClearQuery();
                    //
                    dataGrid1.Refresh();
                    dataGrid1.Name = nd.Text;
                    //create a query for the table
                    qry.UpdatableTableName = nd.Text;
                    qry.Description        = nd.Text;
                    qry.SampleTopRec       = nd.TopRec;
                    qry.UseSampleTopRec    = true;
                    if (qry.DatabaseConnection.TopRecordStyle == EnumTopRecStyle.NotAllowed)
                    {
                        qry.Where = "1=2";
                    }
                    else
                    {
                        qry.Where = "";
                    }
                    qry.From = string.Format(CultureInfo.InvariantCulture,
                                             "{0}{1}{2}", qry.NameDelimiterBegin, nd.Text, qry.NameDelimiterEnd);
                    FieldList fl = new FieldList();
                    for (i = 0; i < nd.table.FieldCount; i++)
                    {
                        fl.AddField(nd.table.GetField(i));
                    }
                    for (i = 0; i < fl.Count; i++)
                    {
                        fl[i].SetDefaultEditor();
                    }
                    qry.Fields = fl;
                    qry.Query();
                    //
                    dataGrid1.DataSource = qry.DataStorage;
                    if (qry.DataStorage != null)
                    {
                        dataGrid1.DataMember = qry.DataStorage.Tables[0].TableName;
                    }
                    dataGrid1.Refresh();
                    //
                    schema.dbCon = qry.DatabaseConnection.ConnectionObject;
                    dataGrid1_CurrentCellChanged(null, null);
                    dlgDatabase_Resize(null, null);
                    dataGrid1.Visible = (qry.Fields.Count > 0);
                    if (cbxFields.Items.Count > 0)
                    {
                        cbxFields.SelectedIndex = 0;
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(this, VPLUtil.FormExceptionText(err), this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
                }
            }
        }