Exemple #1
0
 private void clearDrag()
 {
     if (ndDrop != null)
     {
         ndDrop.BackColor = System.Drawing.Color.White;
         ndDrop           = null;
     }
     dragData = null;
 }
Exemple #2
0
        private void btIndex_Click(object sender, System.EventArgs e)
        {
            TableNode nd = treeView1.SelectedNode as TableNode;

            if (nd != null)
            {
                dlgIndexes dlg = new dlgIndexes();
                dlg.LoadData(nd.table, qry.DatabaseConnection.ConnectionObject);
                dlg.ShowDialog(this);
                if (dlg.bChanged)
                {
                    nd.table.GetIndexes(qry.DatabaseConnection.ConnectionObject);
                }
            }
        }
Exemple #3
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();
     }
 }
Exemple #4
0
 private void treeView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if ((e.Button & MouseButtons.Left) == MouseButtons.Left && bMouseDown)
     {
         bMouseDown = false;
         //start drag group for re-grouping
         System.Drawing.Point pt = new System.Drawing.Point(e.X, e.Y);
         TableNode            nd = (TableNode)treeView1.GetNodeAt(pt);
         if (nd != null)
         {
             treeView1.SelectedNode = nd;
             dragData         = new clsDragTableData();
             dragData.objNode = nd;
             System.Windows.Forms.DragDropEffects ret = treeView1.DoDragDrop(dragData, System.Windows.Forms.DragDropEffects.All);
             if (ret == System.Windows.Forms.DragDropEffects.Move)
             {
             }
         }
     }
 }
Exemple #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);
                }
            }
        }
Exemple #6
0
        private void treeView1_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
        {
            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)
            {
                //nd to be parent, must be top node
                if (nd.Parent == null)
                {
                    if (nd != dragData.objNode)
                    {
                        //nd must have unique key cannot be a child of dragData
                        if (nd.table.HasUniqueKey())
                        {
                            bCanDrop = !schema.RelationExists(nd.table.TableName, dragData.objNode.table.TableName);
                        }
                    }
                    if (bCanDrop)
                    {
                        e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
                        if (ndDrop != nd)
                        {
                            if (ndDrop != null)
                            {
                                ndDrop.BackColor = System.Drawing.Color.White;
                            }
                        }
                        ndDrop           = nd;
                        ndDrop.BackColor = System.Drawing.Color.GreenYellow;
                    }
                }
            }
            if (!bCanDrop)
            {
                if (ndDrop != null)
                {
                    ndDrop.BackColor = System.Drawing.Color.White;
                    ndDrop           = null;
                }
            }

            //scroll up/down
            int nDltX, nDltY;

            if (pt.Y < treeView1.ItemHeight)
            {
                //scroll up
                nDltY = pt.Y - y0;
                if (nDltY < 0)
                {
                    nDltY = -nDltY;
                }
                nDltX = pt.X - x0;
                if (nDltX < 0)
                {
                    nDltX = -nDltX;
                }
                if (nDltX < nDltY)
                {
                    nDltX = nDltY;
                }
                if (nDltX > nDeltaDragMove)
                {
                    y0 = pt.Y;
                    x0 = pt.X;
                    nd = (TableNode)treeView1.TopNode;
                    //find the first invisible node
                    TreeNode nd1;
                    while (nd != null)
                    {
                        nd1 = FindInvisibleNodeUp(nd);
                        if (nd1 != null)
                        {
                            nd1.EnsureVisible();
                            break;
                        }
                        nd = (TableNode)nd.Parent;
                    }
                }
            }
            else if (pt.Y > treeView1.ClientSize.Height - treeView1.ItemHeight)
            {
                //scroll down
                nDltY = pt.Y - y0;
                if (nDltY < 0)
                {
                    nDltY = -nDltY;
                }
                nDltX = pt.X - x0;
                if (nDltX < 0)
                {
                    nDltX = -nDltX;
                }
                if (nDltX < nDltY)
                {
                    nDltX = nDltY;
                }
                if (nDltX > nDeltaDragMove)
                {
                    y0 = pt.Y;
                    x0 = pt.X;
                    nd = (TableNode)treeView1.GetNodeAt(pt);
                    if (nd != null)
                    {
                        nd = (TableNode)FindInvisibleNodeDn(nd);
                    }
                    if (nd != null)
                    {
                        nd.EnsureVisible();
                    }
                }
            }
            ///
        }
Exemple #7
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);
                }
            }
        }