Esempio n. 1
0
 protected override void OnFormClosing(FormClosingEventArgs e)
 {
     try
     {
         base.OnFormClosing(e);
         save();
         if (_dlgUsage == enumDlgUsage.All)
         {
         }
         else
         {
             //merge the list?
             //disable new button so that we do not need to do merge here
             if (_dlgUsage == enumDlgUsage.Project && _listOwner != null)
             {
                 if (ConnectionItem.SetProjectDatabaseConnections != null && _connectionList != null)
                 {
                     List <Guid> gl = new List <Guid>();
                     foreach (ConnectionItem ci in _connectionList)
                     {
                         gl.Add(ci.ConnectionGuid);
                     }
                     ConnectionItem.SetProjectDatabaseConnections(gl, _listOwner);
                 }
             }
         }
     }
     catch (Exception err)
     {
         FormLog.NotifyException(true, err, "Error closing connection manager. {0}", this.ToString());
     }
 }
 public void Save()
 {
     if (!_loaded)
     {
     }
     try
     {
         int         c     = 0x20;
         List <Type> types = new List <Type>();
         XmlDocument doc   = VPL.XmlSerializerUtility.Save(this, types);
         doc.Save(ConnectionItem.GetConnectionFilename(ConnectionObject.ConnectionGuid));
         if (EncryptConnectionString)
         {
             if (!ConnectionObject.ConnectionString.StartsWith(new string(new char[] { (char)(c + 1) }), StringComparison.Ordinal))
             {
                 ConnectionConfig.SetConnection(ConnectionObject.ConnectionGuid, new string(new char[] { (char)(c + 1) }) + get_pagenumber(ConnectionObject.ConnectionString));
             }
             else
             {
                 ConnectionConfig.SetConnection(ConnectionObject.ConnectionGuid, ConnectionObject.ConnectionString);
             }
         }
     }
     catch (Exception err)
     {
         FormLog.NotifyException(true, err, "Error saving connection {0}", this.ToString());
     }
 }
        /// <summary>
        /// load from outside
        /// </summary>
        /// <param name="sql"></param>
        public void LoadData(SQLNoneQuery sql)
        {
            if (editState != EnumEditState.NotLoaded)
            {
                throw new ExceptionLimnorDatabase("Calling LoadData at the state of {0}", editState);
            }

            dbConn = sql.Connection;
            //load table names into lstTable
            QueryParser._UseLowerCase = sql.Connection.ConnectionObject.LowerCaseSqlKeywords;
            System.Data.DataTable tbl = sql.Connection.ConnectionObject.GetTables();
            if (tbl != null)
            {
                for (int i = 0; i < tbl.Rows.Count; i++)
                {
                    if (tbl.Rows[i]["Table_Name"] != null)
                    {
                        string s = tbl.Rows[i]["Table_Name"].ToString();
                        int    n = lstTable.Items.Add(s);
                        if (string.Compare(s, sql.TableName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            lstTable.SelectedIndex = n;
                        }
                    }
                }
            }
            objRet = ((SQLNoneQuery)sql.Clone());

            int k = (int)(objRet.CommandType);

            if (k >= 0 && k < cbxType.Items.Count)
            {
                cbxType.SelectedIndex = k;
            }

            txtWhere.Text          = objRet.Filter;
            txtSQL.Text            = objRet.SQL;
            btQueryBuilder.Enabled = (objRet.CommandType != enmNonQueryType.Insert);

            if (!string.IsNullOrEmpty(objRet.TableName))
            {
                for (int i = 0; i < lstTable.Items.Count; i++)
                {
                    if (string.Compare(objRet.TableName, lstTable.Items[i].ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        lstTable.SelectedIndex = i;
                        break;
                    }
                }
            }
            else
            {
                if (lstTable.Items.Count > 0)
                {
                    lstTable.SelectedIndex = 0;
                }
            }
            editState = EnumEditState.Ready;
            lstTable_SelectedIndexChanged(this, null);
        }
 private void setDefaultConnection()
 {
     if (_defConnectionType != null && !string.IsNullOrEmpty(_defConnectionString))
     {
         if (connect != null)
         {
             Guid id;
             if (!string.IsNullOrEmpty(connect.Filename))
             {
                 id = new Guid(connect.Filename);
             }
             else
             {
                 id = connect.ConnectionObject.ConnectionGuid;
             }
             Connection _def = new Connection();
             _def.ConnectionGuid   = id;
             _def.DatabaseType     = _defConnectionType;
             _def.ConnectionString = _defConnectionString;
             ConnectionItem.AddDefaultConnection(_def);
             if (connect.ConnectionObject.DatabaseType == null)
             {
                 connect.ConnectionObject.DatabaseType = _defConnectionType;
             }
             if (string.IsNullOrEmpty(connect.ConnectionObject.ConnectionString))
             {
                 connect.ConnectionObject.ConnectionString = _defConnectionString;
             }
         }
     }
 }
 public void SetConnectionString(string connectionString)
 {
     if (connect == null)
     {
         connect = new ConnectionItem();
     }
     connect.ConnectionString = connectionString;
 }
Esempio n. 6
0
        private void save()
        {
            ConnectionItem cnn = propertyGrid1.SelectedObject as ConnectionItem;

            if (cnn != null)
            {
                cnn.Save();
            }
        }
Esempio n. 7
0
        private void toolStripButtonCleanup_Click(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            List <TreeNodeConnectionItem> delItems = new List <TreeNodeConnectionItem>();

            for (int i = 0; i < treeView1.Nodes.Count; i++)
            {
                TreeNodeConnectionItem tc = treeView1.Nodes[i] as TreeNodeConnectionItem;
                if (tc != null)
                {
                    tc.OnSelected();
                    ConnectionItem ci = tc.OwnerItem;
                    if (ci != null)
                    {
                        if (string.IsNullOrEmpty(ci.DatabaseType) && string.IsNullOrEmpty(ci.ConnectionStringPlain))
                        {
                            delItems.Add(tc);
                        }
                    }
                    else
                    {
                        delItems.Add(tc);
                    }
                }
            }

            foreach (TreeNodeConnectionItem tn in delItems)
            {
                ConnectionItem ci = tn.OwnerItem;
                if (ci != null)
                {
                    if (propertyGrid1.SelectedObject == ci)
                    {
                        propertyGrid1.SelectedObject = null;
                    }
                    if (System.IO.File.Exists(ci.FullFilePath))
                    {
                        try
                        {
                            System.IO.File.Delete(ci.FullFilePath);
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(this, err.Message, "Remove Database Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    _connectionList.Remove(ci);
                    ConnectionConfig.RemoveConnection(ci.ConnectionObject.ConnectionGuid);
                }
                tn.Remove();
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
Esempio n. 8
0
        private void toolStripButtonNew_Click(object sender, EventArgs e)
        {
            Connection cnn = new Connection();

            cnn.ConnectionGuid = Guid.NewGuid();
            ConnectionItem ci = new ConnectionItem(cnn);

            _connectionList.Add(ci);
            TreeNodeConnectionItem tc = new TreeNodeConnectionItem(ci);

            treeView1.Nodes.Add(tc);
            treeView1.SelectedNode = tc;
        }
        public object Clone()
        {
            ConnectionItem obj = new ConnectionItem();

            obj._desc     = _desc;
            obj._filename = _filename;
            obj._key      = _key;
            obj._name     = _name;
            if (_cnn != null)
            {
                obj._cnn = (Connection)_cnn.Clone();
            }
            return(obj);
        }
 public TreeNodeConnectionItem(ConnectionItem item)
 {
     _item = item;
     Text  = _item.ToString();
     if (item.IsValid)
     {
         ImageIndex = IMG_CNN;
     }
     else
     {
         ImageIndex = IMG_CNN_ERR;
     }
     SelectedImageIndex = ImageIndex;
     this.Nodes.Add(new CLoad());
 }
 public static ConnectionItem LoadConnection(string dbcFile)
 {
     if (System.IO.File.Exists(dbcFile))
     {
         try
         {
             ConnectionItem ci = XmlSerializerUtility.LoadFromXmlFile <ConnectionItem>(dbcFile);
             ci.SetLoaded();
             return(ci);
         }
         catch (Exception err)
         {
             FormLog.NotifyException(true, err, "Invalid connection file [{0}]", dbcFile);
         }
     }
     return(null);
 }
Esempio n. 12
0
 public void AddConnection(ConnectionItem ci)
 {
     try
     {
         if (ci == null)
         {
             throw new ExceptionLimnorDatabase("Cannot add a null connection");
         }
         if (_connectionList == null)
         {
             _connectionList = new List <ConnectionItem>();
         }
         foreach (ConnectionItem c in _connectionList)
         {
             if (c.ConnectionObject.ConnectionGuid.Equals(ci.ConnectionObject.ConnectionGuid))
             {
                 if (!string.IsNullOrEmpty(ci.Name))
                 {
                     if (string.IsNullOrEmpty(c.Name))
                     {
                         c.Name = ci.Name;
                     }
                 }
                 SetSelection(ci);
                 TreeNodeConnectionItem tnc = treeView1.SelectedNode as TreeNodeConnectionItem;
                 if (tnc != null && tnc.OwnerItem != null)
                 {
                     if (tnc.OwnerItem.ConnectionObject.ConnectionGuid.Equals(ci.ConnectionObject.ConnectionGuid))
                     {
                         tnc.Text = c.ToString();
                     }
                 }
                 return;
             }
         }
         _connectionList.Add(ci);
         TreeNodeConnectionItem tc = new TreeNodeConnectionItem(ci);
         treeView1.Nodes.Add(tc);
         treeView1.SelectedNode = tc;
     }
     catch (Exception err)
     {
         FormLog.NotifyException(true, err, "Error adding connection {0}", this.ToString());
     }
 }
Esempio n. 13
0
 private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
 {
     if (string.CompareOrdinal(e.ChangedItem.PropertyDescriptor.Name, "Name") == 0)
     {
         ConnectionItem ci = propertyGrid1.SelectedObject as ConnectionItem;
         if (ci != null)
         {
             TreeNodeConnectionItem tnc = treeView1.SelectedNode as TreeNodeConnectionItem;
             if (tnc != null)
             {
                 if (tnc.OwnerItem.ConnectionGuid == ci.ConnectionGuid)
                 {
                     tnc.Text = ci.ToString();
                 }
             }
         }
     }
 }
        public void SelectQuery(Form dialogParent)
        {
            Connection cnn;

            if (connect != null)
            {
                cnn = (Connection)connect.ConnectionObject.Clone();
            }
            else
            {
                cnn = new Connection();
            }
            DlgConnection dlg = cnn.CreateDataDialog();

            if (dlg.ShowDialog(dialogParent) == DialogResult.OK)
            {
                connect = new ConnectionItem(cnn);
            }
        }
        public void MergeFromFile()
        {
            string f = GetConnectionFilename(this.ConnectionGuid);

            if (System.IO.File.Exists(f))
            {
                ConnectionItem ci = XmlSerializerUtility.LoadFromXmlFile <ConnectionItem>(f);
                if (ci != null)
                {
                    ci.SetDataFolder();
                    if (!string.IsNullOrEmpty(ci._name))
                    {
                        _name = ci._name;
                    }
                    if (ci._cnn != null)
                    {
                        _cnn = ci._cnn;
                    }
                }
            }
        }
Esempio n. 16
0
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IDatabaseConnectionUserExt dbu = context.Instance as IDatabaseConnectionUserExt;
             if (dbu != null)
             {
                 if (!(dbu.DatabaseConnection != null && dbu.DatabaseConnection.ConnectionObject != null && dbu.DatabaseConnection.ConnectionObject.IsConnectionReady))
                 {
                     ConnectionItem       ci  = dbu.DatabaseConnection;
                     DlgConnectionManager dlg = new DlgConnectionManager();
                     dlg.UseProjectScope = true;
                     dlg.SetSelection(ci);
                     if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         dbu.DatabaseConnection = dlg.SelectedConnection;
                     }
                 }
                 if (dbu.DatabaseConnection != null && dbu.DatabaseConnection.ConnectionObject != null && dbu.DatabaseConnection.ConnectionObject.IsConnectionReady)
                 {
                     string   v  = value as string;
                     string[] vs = dbu.DatabaseConnection.ConnectionObject.GetTableNames();
                     if (vs != null && vs.Length > 0)
                     {
                         ValueList list = new ValueList(edSvc, vs, v);
                         edSvc.DropDownControl(list);
                         if (list.MadeSelection)
                         {
                             value = list.Selection;
                         }
                     }
                 }
             }
         }
     }
     return(base.EditValue(context, provider, value));
 }
Esempio n. 17
0
 private void toolStripButtonTest_Click(object sender, EventArgs e)
 {
     this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
     if (treeView1.SelectedNode != null)
     {
         TreeNodeConnectionItem tc = treeView1.SelectedNode as TreeNodeConnectionItem;
         if (tc == null)
         {
             tc = treeView1.SelectedNode.Parent as TreeNodeConnectionItem;
         }
         if (tc != null)
         {
             ConnectionItem ci = tc.OwnerItem;
             if (ci != null)
             {
                 try
                 {
                     if (ci.ConnectionObject.TestConnection(this, true))
                     {
                         tc.ImageIndex         = TreeNodeConnectionItem.IMG_CNN_OK;
                         tc.SelectedImageIndex = TreeNodeConnectionItem.IMG_CNN_OK;
                     }
                     else
                     {
                         tc.ImageIndex         = TreeNodeConnectionItem.IMG_CNN_ERR;
                         tc.SelectedImageIndex = TreeNodeConnectionItem.IMG_CNN_ERR;
                     }
                 }
                 catch (Exception err)
                 {
                     MessageBox.Show(this, err.Message, "Database Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     tc.ImageIndex         = TreeNodeConnectionItem.IMG_CNN_ERR;
                     tc.SelectedImageIndex = TreeNodeConnectionItem.IMG_CNN_ERR;
                 }
             }
         }
     }
     this.Cursor = System.Windows.Forms.Cursors.Default;
 }
Esempio n. 18
0
 public void SetSelection(ConnectionItem ci)
 {
     _currentSelection = ci;
     if (ci != null)
     {
         for (int i = 0; i < treeView1.Nodes.Count; i++)
         {
             TreeNodeConnectionItem tnc = treeView1.Nodes[i] as TreeNodeConnectionItem;
             if (tnc != null)
             {
                 ConnectionItem c = tnc.OwnerItem;
                 if (c != null)
                 {
                     if (string.Compare(c.Filename, ci.Filename, StringComparison.OrdinalIgnoreCase) == 0)
                     {
                         treeView1.SelectedNode = tnc;
                         break;
                     }
                 }
             }
         }
     }
 }
Esempio n. 19
0
 private void toolStripButtonOK_Click(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode != null)
     {
         TreeNodeConnectionItem tc = treeView1.SelectedNode as TreeNodeConnectionItem;
         if (tc == null)
         {
             tc = treeView1.SelectedNode.Parent as TreeNodeConnectionItem;
         }
         if (tc != null)
         {
             SelectedConnection = tc.OwnerItem;
             if (SelectedConnection != null)
             {
                 this.DialogResult = DialogResult.OK;
             }
         }
     }
     if (_dlgUsage == enumDlgUsage.Project)
     {
         this.DialogResult = DialogResult.OK;
     }
 }
Esempio n. 20
0
 private void toolStripButtonDelete_Click(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode != null)
     {
         TreeNodeConnectionItem tc = treeView1.SelectedNode as TreeNodeConnectionItem;
         if (tc == null)
         {
             tc = treeView1.SelectedNode.Parent as TreeNodeConnectionItem;
         }
         if (tc != null)
         {
             ConnectionItem ci = tc.OwnerItem;
             if (ci != null)
             {
                 if (MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Do you want to delete connection [{0}]?", ci.ToString()), "Database Connection Manager", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                 {
                     if (System.IO.File.Exists(ci.FullFilePath))
                     {
                         try
                         {
                             System.IO.File.Delete(ci.FullFilePath);
                         }
                         catch (Exception err)
                         {
                             MessageBox.Show(this, err.Message, "Database Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                     propertyGrid1.SelectedObject = null;
                     tc.Remove();
                     _connectionList.Remove(ci);
                     ConnectionConfig.RemoveConnection(ci.ConnectionObject.ConnectionGuid);
                 }
             }
         }
     }
 }
        public override string Execute()
        {
            string sMsg = string.Empty;

            SetError(sMsg);
            ResetAffectedRows();
            SQLNoneQuery   sql         = base.ExecutionCommand;
            ConnectionItem connect     = Connection;
            DbTransaction  transaction = Transaction;

            if (sql != null && connect != null)
            {
                DbCommand cmd = connect.ConnectionObject.CreateCommand();
                if (transaction != null)
                {
                    cmd.Transaction = transaction;
                }
                bool bClosed = !connect.ConnectionObject.Opened;
                if (bClosed)
                {
                    connect.ConnectionObject.Open();
                }
                if (connect.ConnectionObject.Opened)
                {
                    try
                    {
                        int i;
                        EnumParameterStyle pstyle = connect.ParameterStyle;
                        cmd.CommandText = sql.SQL;
                        if (sql.CommandType == enmNonQueryType.StoredProcedure)
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                        }
                        else
                        {
                            cmd.CommandType = CommandType.Text;
                        }
                        int nCount = ParameterCount;
                        for (i = 0; i < nCount; i++)
                        {
                            DbParameter pam = cmd.CreateParameter();
                            if (pstyle == EnumParameterStyle.LeadingQuestionMark)
                            {
                                if (sql.Param_Name[i].StartsWith("@", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "?{0}", sql.Param_Name[i].Substring(1));
                                }
                                else if (sql.Param_Name[i].StartsWith("?", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = sql.Param_Name[i];
                                }
                                else
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "?{0}", sql.Param_Name[i]);
                                }
                            }
                            else
                            {
                                if (sql.Param_Name[i].StartsWith("@", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = sql.Param_Name[i];
                                }
                                else
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "@{0}", sql.Param_Name[i]);
                                }
                            }
                            pam.DbType    = ValueConvertor.OleDbTypeToDbType(sql.Param_OleDbType[i]);
                            pam.Direction = this.Param_Directions[i];
                            pam.Size      = EPField.FieldDataSize(sql.Param_OleDbType[i], this.Param_DataSize[i]);
                            pam.Value     = ValueConvertor.ConvertByOleDbType(sql.Parameters[i].Value, sql.Param_OleDbType[i]);
                            cmd.Parameters.Add(pam);
                        }
                        cmd.Prepare();
                        DbDataReader dr = cmd.ExecuteReader();

                        _dataset = new DataSet("Results");
                        int n = 1;
                        while (true)
                        {
                            DataTable tbl = new DataTable(string.Format("Table{0}", n));
                            for (i = 0; i < dr.FieldCount; i++)
                            {
                                DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                                tbl.Columns.Add(dc);
                            }
                            _dataset.Tables.Add(tbl);
                            while (dr.Read())
                            {
                                object[] vs = new object[dr.FieldCount];
                                for (int k = 0; k < dr.FieldCount; k++)
                                {
                                    vs[k] = dr.GetValue(k);
                                }
                                tbl.Rows.Add(vs);
                            }
                            n++;
                            if (!dr.NextResult())
                            {
                                break;
                            }
                        }
                        dr.Close();
                        if (bClosed)
                        {
                            closeConnections();
                        }
                        for (i = 0; i < nCount; i++)
                        {
                            ParameterDirection pt = cmd.Parameters[i].Direction;
                            if (pt != ParameterDirection.Input)
                            {
                                sql.Parameters[i].Value = cmd.Parameters[i].Value;
                            }
                        }
                        FireExecuteFinish();
                    }
                    catch (Exception er)
                    {
                        if (transaction != null)
                        {
                            transaction.Rollback();
                            transaction.Dispose();
                            ResetTransaction();
                            throw;
                        }
                        else
                        {
                            sMsg = ExceptionLimnorDatabase.FormExceptionText(er);
                        }
                    }
                    finally
                    {
                        if (bClosed)
                        {
                            if (connect.ConnectionObject.State != ConnectionState.Closed)
                            {
                                connect.ConnectionObject.Close();
                            }
                        }
                    }
                }
                else
                {
                    sMsg = "Database connection not set";
                }
            }
            else
            {
                sMsg = "SQL statement not set";
            }
            if (!string.IsNullOrEmpty(sMsg))
            {
                SetError(sMsg);
            }
            return(sMsg);
        }
Esempio n. 22
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    IDatabaseTableUser tbu = context.Instance as IDatabaseTableUser;
                    if (tbu != null)
                    {
                        if (!(tbu.DatabaseConnection != null && tbu.DatabaseConnection.ConnectionObject != null && tbu.DatabaseConnection.ConnectionObject.IsConnectionReady))
                        {
                            ConnectionItem       ci  = tbu.DatabaseConnection;
                            DlgConnectionManager dlg = new DlgConnectionManager();
                            dlg.UseProjectScope = true;
                            dlg.SetSelection(ci);
                            if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                            {
                                tbu.DatabaseConnection = dlg.SelectedConnection;
                            }
                        }
                        if (string.IsNullOrEmpty(tbu.TableName))
                        {
                            TypeSelectorTable ts = new TypeSelectorTable();
                            tbu.TableName = ts.EditValue(context, provider, string.Empty) as string;
                        }
                        if (!string.IsNullOrEmpty(tbu.TableName))
                        {
                            if (tbu.DatabaseConnection != null &&
                                tbu.DatabaseConnection.ConnectionObject != null &&
                                tbu.DatabaseConnection.ConnectionObject.IsConnectionReady)
                            {
                                FieldList fl = tbu.DatabaseConnection.ConnectionObject.GetTableFields(tbu.TableName);
                                if (fl != null)
                                {
                                    string[] names = new string[fl.Count];
                                    for (int i = 0; i < names.Length; i++)
                                    {
                                        names[i] = fl[i].Name;
                                    }
                                    FieldList sels = value as FieldList;
                                    string[]  ss;
                                    if (sels == null)
                                    {
                                        FieldCollection fc = value as FieldCollection;
                                        if (fc == null)
                                        {
                                            ss = new string[] { };
                                        }
                                        else
                                        {
                                            ss = new string[fc.Count];
                                            for (int i = 0; i < fc.Count; i++)
                                            {
                                                ss[i] = fc[i].Name;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ss = new string[sels.Count];
                                        for (int i = 0; i < sels.Count; i++)
                                        {
                                            ss[i] = sels[i].Name;
                                        }
                                    }
                                    UserControlSelectFieldNames fns = new UserControlSelectFieldNames();

                                    fns.LoadData(edSvc, names, ss);
                                    edSvc.DropDownControl(fns);
                                    if (fns.SelectedStrings != null)
                                    {
                                        FieldCollection newFields = new FieldCollection();
                                        for (int i = 0; i < fns.SelectedStrings.Length; i++)
                                        {
                                            EPField f = fl[fns.SelectedStrings[i]];
                                            if (f != null)
                                            {
                                                newFields.AddField(f);
                                            }
                                        }
                                        value = newFields;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
 internal void SetTransaction(DbTransaction tr, ConnectionItem connection)
 {
     _transaction = tr;
     connect      = connection;
 }
Esempio n. 24
0
        private void loadData(ProgressBar pb)
        {
            try
            {
                pb.Value = 10;
                pb.Refresh();
                if (_connectionList == null)
                {
                    if (UseProjectScope && ConnectionItem.GetProjectDatabaseConnections != null)
                    {
                        List <Guid> glst = new List <Guid>();
                        _connectionList = new List <ConnectionItem>();
                        if (_projectUsages != null && _projectUsages.Count > 0)
                        {
                            glst.AddRange(_projectUsages);
                        }
                        IList <Guid> gl = ConnectionItem.GetProjectDatabaseConnections(out _listOwner);
                        if (gl != null && gl.Count > 0)
                        {
                            foreach (Guid g in gl)
                            {
                                if (g != Guid.Empty)
                                {
                                    if (!glst.Contains(g))
                                    {
                                        glst.Add(g);
                                    }
                                }
                            }
                        }
                        if (glst.Count > 0)
                        {
                            foreach (Guid g in glst)
                            {
                                if (g != Guid.Empty)
                                {
                                    ConnectionItem ci = ConnectionItem.LoadConnection(g, false, false);
                                    if (ci != null)
                                    {
                                        _connectionList.Add(ci);
                                    }
                                }
                            }
                        }
                        if (_listOwner != null)
                        {
                            this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                      "Database connections for project {0}", _listOwner.ToString());
                        }
                    }
                    else
                    {
                        _dlgUsage = enumDlgUsage.All;
                        string dir = ConnectionItem.GetConnectionFileFolder();
                        if (!System.IO.Directory.Exists(dir))
                        {
                            System.IO.Directory.CreateDirectory(dir);
                        }
                        _connectionList = new List <ConnectionItem>();

                        string[] files = ConnectionItem.GetConnectionFiles();
                        if (files != null && files.Length > 0)
                        {
                            double r = (double)85 / (double)(files.Length);
                            for (int i = 0; i < files.Length; i++)
                            {
                                Guid           g  = new Guid(System.IO.Path.GetFileNameWithoutExtension(files[i]));
                                ConnectionItem ci = ConnectionItem.LoadConnection(g, false, true);
                                if (ci != null && !ci.EncryptConnectionString)
                                {
                                    _connectionList.Add(ci);
                                    pb.Value = 10 + (int)((i + 1) * r);
                                    pb.Refresh();
                                }
                            }
                        }
                    }
                }
                else
                {
                    _dlgUsage = enumDlgUsage.Partial;
                    toolStripButtonCancel.Enabled = false;
                }
                pb.Value = 95;
                pb.Refresh();
                treeView1.Nodes.Clear();
                bool bSelected = false;
                foreach (ConnectionItem item in _connectionList)
                {
                    if (item != null)
                    {
                        TreeNodeConnectionItem tn = new TreeNodeConnectionItem(item);
                        treeView1.Nodes.Add(tn);
                        if (!bSelected)
                        {
                            if (_currentSelection != null)
                            {
                                if (_currentSelection.ConnectionGuid == item.ConnectionGuid)
                                {
                                    treeView1.SelectedNode = tn;
                                    bSelected = true;
                                }
                            }
                        }
                    }
                }
                if (!bSelected)
                {
                    for (int i = 0; i < treeView1.Nodes.Count; i++)
                    {
                        TreeNodeConnectionItem tn = treeView1.Nodes[i] as TreeNodeConnectionItem;
                        if (tn != null)
                        {
                            if (!tn.OwnerItem.IsValid)
                            {
                                treeView1.SelectedNode = tn;
                                bSelected = true;
                                break;
                            }
                        }
                    }
                }
                if (!bSelected)
                {
                    if (treeView1.Nodes.Count > 0)
                    {
                        for (int i = 0; i < treeView1.Nodes.Count; i++)
                        {
                            TreeNodeConnectionItem tn = treeView1.Nodes[i] as TreeNodeConnectionItem;
                            if (tn != null)
                            {
                                treeView1.SelectedNode = tn;
                                bSelected = true;
                                break;
                            }
                        }
                    }
                }
                pb.Value = 100;
                pb.Refresh();
            }
            catch (Exception err)
            {
                FormLog.NotifyException(true, err);
            }
        }
        public static ConnectionItem LoadConnection(Guid g, bool updateUsage, bool quickLoad)
        {
            ConnectionItem ci = null;

            try
            {
                string f = GetConnectionFilename(g);
                if (!System.IO.File.Exists(f))
                {
                    f = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                               System.IO.Path.GetFileName(f));
                }
                if (System.IO.File.Exists(f))
                {
                    try
                    {
                        ci = XmlSerializerUtility.LoadFromXmlFile <ConnectionItem>(f);
                        ci.SetDataFolder();
                        ci.SetLoaded();
                        if (updateUsage)
                        {
                            ci.UpdateUsage(Application.ExecutablePath);
                        }
                    }
                    catch (Exception errXml)
                    {
                        FormLog.NotifyException(true, errXml, "Invalid connection file [{0}] for connection item {1}.", f, g);
                    }
                }
                if (quickLoad)
                {
                    if (ci == null)
                    {
                        Connection cn = GetDefaultConnection(g);
                        if (cn == null)
                        {
                            ci = new ConnectionItem(f);
                        }
                        else
                        {
                            ci = new ConnectionItem(cn);
                        }
                        if (updateUsage)
                        {
                            ci.UpdateUsage(Application.ExecutablePath);
                        }
                        ci.Save();
                        ci.SetLoaded();
                    }
                    else
                    {
                        ci.setConnectionID(g);
                    }
                }
                else
                {
                    if (ci == null || !ci.ConnectionObject.IsConnectionReady)
                    {
                        Connection cn = GetDefaultConnection(g);
                        if (cn == null)
                        {
                            if (ci == null)
                            {
                                ci = new ConnectionItem(f);
                            }
                        }
                        else
                        {
                            ci = new ConnectionItem(cn);
                        }
                        if (updateUsage)
                        {
                            ci.UpdateUsage(Application.ExecutablePath);
                        }
                        ci.Save();
                        ci.SetLoaded();
                        ci._connectionChecked = true;
                    }
                }
            }
            catch (Exception err)
            {
                FormLog.NotifyException(true, err, "Error loading connection item {0}.", g);
            }
            return(ci);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             ConnectionItem       ci  = value as ConnectionItem;
             DlgConnectionManager dlg = new DlgConnectionManager();
             dlg.UseProjectScope = true;
             dlg.SetSelection(ci);
             if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
             {
                 if (dlg.SelectedConnection != null)
                 {
                     PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance);
                     PropertyDescriptor           p;
                     p = ps["Reserved"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                     }
                     p = ps["ConnectionID"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, new Guid(dlg.SelectedConnection.Filename));
                     }
                     value = dlg.SelectedConnection;
                     if (VPLUtil.CurrentProject != null)
                     {
                         dlg.SelectedConnection.UpdateUsage(VPLUtil.CurrentProject.ProjectFile);
                     }
                     else
                     {
                         dlg.SelectedConnection.UpdateUsage(Application.ExecutablePath);
                     }
                     IDevClassReferencer dcr = context.Instance as IDevClassReferencer;
                     if (dcr == null)
                     {
                         IClassId classPointer = context.Instance as IClassId;
                         if (classPointer != null)
                         {
                             dcr = classPointer.ObjectInstance as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         ICustomEventMethodType cemt = context.Instance as ICustomEventMethodType;
                         if (cemt != null)
                         {
                             dcr = cemt.ObjectValue as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         IDevClassReferencerHolder dcrh = context.Instance as IDevClassReferencerHolder;
                         if (dcrh != null)
                         {
                             dcr = dcrh.DevClass;
                         }
                     }
                     if (dcr != null)
                     {
                         IDevClass dc = dcr.GetDevClass();
                         if (dc != null)
                         {
                             dc.NotifyChange(context.Instance, "SqlQuery");
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }