Esempio n. 1
0
        /// <summary>
        /// Creates or updates a Crm connection
        /// </summary>
        /// <param name="isCreation">Indicates if it is a connection creation</param>
        /// <param name="connectionToUpdate">Details of the connection to update</param>
        /// <returns>Created or updated connection</returns>
        public ConnectionDetail EditConnection(bool isCreation, ConnectionDetail connectionToUpdate)
        {
            var cForm = new ConnectionWizard(connectionToUpdate)
            {
                StartPosition = FormStartPosition.CenterParent
            };

            //var cForm = new ConnectionForm(isCreation) { StartPosition = FormStartPosition.CenterParent };

            //if (!isCreation)
            //{
            //    cForm.CrmConnectionDetail = connectionToUpdate;
            //}

            if (cForm.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                // TODO on garde?
                //if (cForm.DoConnect)
                //{
                //    ConnectionManager.Instance.ConnectToServer(cForm.CrmConnectionDetail);
                //}

                //if (!cForm.CrmConnectionDetail.PasswordIsEmpty && !cForm.CrmConnectionDetail.SavePassword)
                //{
                //    cForm.CrmConnectionDetail.ErasePassword();
                //}

                if (isCreation)
                {
                    if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                            d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null)
                    {
                        ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);
                    }
                }
                else
                {
                    foreach (ConnectionDetail detail in ConnectionManager.Instance.ConnectionsList.Connections)
                    {
                        if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                        {
                            detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                        }
                    }
                }

                ConnectionManager.Instance.SaveConnectionsFile();

                return(cForm.CrmConnectionDetail);
            }

            return(null);
        }
        private void tsbNewConnection_Click(object sender, EventArgs e)
        {
            var cForm = new ConnectionWizard
            {
                StartPosition = FormStartPosition.CenterParent
            };

            //var cForm = new ConnectionForm(true, false)
            //{
            //    StartPosition = FormStartPosition.CenterParent
            //};

            if (cForm.ShowDialog(this) == DialogResult.OK)
            {
                var newConnection = cForm.CrmConnectionDetail;
                hadCreatedNewConnection = true;

                var item = new ListViewItem(newConnection.ConnectionName);
                item.SubItems.Add(newConnection.ServerName);
                item.SubItems.Add(newConnection.Organization);
                item.SubItems.Add(newConnection.OrganizationVersion);
                item.Tag        = newConnection;
                item.Group      = GetGroup(newConnection.AuthType);
                item.ImageIndex = GetImageIndex(newConnection);

                lvConnections.Items.Add(item);
                lvConnections.SelectedItems.Clear();
                item.Selected = true;

                lvConnections.Sort();

                if (isConnectionSelection)
                {
                    BValidateClick(sender, e);
                }

                // If the connection id is not found and the user want to save
                // the connection (ie. he provided a name for the connection)
                if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(d => d.ConnectionId == newConnection.ConnectionId) == null &&
                    !string.IsNullOrEmpty(newConnection.ConnectionName))
                {
                    ConnectionManager.Instance.ConnectionsList.Connections.Add(newConnection);
                    ConnectionManager.Instance.SaveConnectionsFile();
                }
            }
        }
        private void tsbUpdateConnection_Click(object sender, EventArgs e)
        {
            if (lvConnections.SelectedItems.Count == 1)
            {
                ListViewItem item = lvConnections.SelectedItems[0];

                var cForm = new ConnectionWizard((ConnectionDetail)item.Tag)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                //var cForm = new ConnectionForm(false, false)
                //{
                //    CrmConnectionDetail = (ConnectionDetail)item.Tag,
                //    StartPosition = FormStartPosition.CenterParent
                //};

                if (cForm.ShowDialog(this) == DialogResult.OK)
                {
                    item.SubItems[0].Text = cForm.CrmConnectionDetail.ConnectionName;
                    item.SubItems[1].Text = cForm.CrmConnectionDetail.ServerName;
                    item.SubItems[2].Text = cForm.CrmConnectionDetail.Organization;
                    if (item.SubItems.Count == 4)
                    {
                        item.SubItems[3].Text = cForm.CrmConnectionDetail.OrganizationVersion;
                    }
                    else
                    {
                        item.SubItems.Add(cForm.CrmConnectionDetail.OrganizationVersion);
                    }
                    item.Group = GetGroup(cForm.CrmConnectionDetail.AuthType);

                    lvConnections.Refresh();

                    var updatedConnectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                        c => c.ConnectionId == cForm.CrmConnectionDetail.ConnectionId);

                    ConnectionManager.Instance.ConnectionsList.Connections.Remove(updatedConnectionDetail);
                    ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);

                    ConnectionManager.Instance.SaveConnectionsFile();
                }
            }
        }
Esempio n. 4
0
        private void tsbUpdateConnection_Click(object sender, EventArgs e)
        {
            if (lvConnections.SelectedItems.Count == 1)
            {
                ListViewItem item = lvConnections.SelectedItems[0];

                var cForm = new ConnectionWizard((ConnectionDetail)item.Tag)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                //var cForm = new ConnectionForm(false, false)
                //{
                //    CrmConnectionDetail = (ConnectionDetail)item.Tag,
                //    StartPosition = FormStartPosition.CenterParent
                //};

                if (cForm.ShowDialog(this) == DialogResult.OK)
                {
                    item.SubItems[0].Text = cForm.CrmConnectionDetail.ConnectionName;
                    item.SubItems[1].Text = cForm.CrmConnectionDetail.ServerName;
                    item.SubItems[2].Text = cForm.CrmConnectionDetail.Organization;
                    if (item.SubItems.Count == 4)
                    {
                        item.SubItems[3].Text = cForm.CrmConnectionDetail.OrganizationVersion;
                    }
                    else
                    {
                        item.SubItems.Add(cForm.CrmConnectionDetail.OrganizationVersion);
                    }
                    item.Group = GetGroup(cForm.CrmConnectionDetail.AuthType);

                    lvConnections.Refresh();

                    var updatedConnectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                            c => c.ConnectionId == cForm.CrmConnectionDetail.ConnectionId);

                    ConnectionManager.Instance.ConnectionsList.Connections.Remove(updatedConnectionDetail);
                    ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);

                    ConnectionManager.Instance.SaveConnectionsFile();
                }
            }
        }
Esempio n. 5
0
        private void tsbNewConnection_Click(object sender, EventArgs e)
        {
            var cForm = new ConnectionWizard
            {
                StartPosition = FormStartPosition.CenterParent
            };

            //var cForm = new ConnectionForm(true, false)
            //{
            //    StartPosition = FormStartPosition.CenterParent
            //};

            if (cForm.ShowDialog(this) == DialogResult.OK)
            {
                var newConnection = cForm.CrmConnectionDetail;
                hadCreatedNewConnection = true;

                var item = new ListViewItem(newConnection.ConnectionName);
                item.SubItems.Add(newConnection.ServerName);
                item.SubItems.Add(newConnection.Organization);
                item.SubItems.Add(newConnection.OrganizationVersion);
                item.Tag = newConnection;
                item.Group = GetGroup(newConnection.AuthType);
                item.ImageIndex = GetImageIndex(newConnection);

                lvConnections.Items.Add(item);
                lvConnections.SelectedItems.Clear();
                item.Selected = true;

                lvConnections.Sort();

                if (isConnectionSelection)
                {
                    BValidateClick(sender, e);
                }

                // If the connection id is not found and the user want to save
                // the connection (ie. he provided a name for the connection)
                if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(d => d.ConnectionId == newConnection.ConnectionId) == null
                             && !string.IsNullOrEmpty(newConnection.ConnectionName))
                {
                    ConnectionManager.Instance.ConnectionsList.Connections.Add(newConnection);
                    ConnectionManager.Instance.SaveConnectionsFile();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates or updates a Crm connection
        /// </summary>
        /// <param name="isCreation">Indicates if it is a connection creation</param>
        /// <param name="connectionToUpdate">Details of the connection to update</param>
        /// <returns>Created or updated connection</returns>
        public ConnectionDetail EditConnection(bool isCreation, ConnectionDetail connectionToUpdate)
        {
            var cForm = new ConnectionWizard(connectionToUpdate) { StartPosition = FormStartPosition.CenterParent };

            //var cForm = new ConnectionForm(isCreation) { StartPosition = FormStartPosition.CenterParent };

            //if (!isCreation)
            //{
            //    cForm.CrmConnectionDetail = connectionToUpdate;
            //}

            if (cForm.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                // TODO on garde?
                //if (cForm.DoConnect)
                //{
                //    ConnectionManager.Instance.ConnectToServer(cForm.CrmConnectionDetail);
                //}

                //if (!cForm.CrmConnectionDetail.PasswordIsEmpty && !cForm.CrmConnectionDetail.SavePassword)
                //{
                //    cForm.CrmConnectionDetail.ErasePassword();
                //}

                if (isCreation)
                {
                    if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                        d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null)
                    {
                        ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);
                    }
                }
                else
                {
                    foreach (ConnectionDetail detail in ConnectionManager.Instance.ConnectionsList.Connections)
                    {
                        if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                        {
                            detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                        }
                    }
                }

                ConnectionManager.Instance.SaveConnectionsFile();

                return cForm.CrmConnectionDetail;
            }

            return null;
        }
Esempio n. 7
0
        /// <summary>
        /// Creates or updates a Crm connection
        /// </summary>
        /// <param name="isCreation">Indicates if it is a connection creation</param>
        /// <param name="connectionToUpdate">Details of the connection to update</param>
        /// <param name="connectionFile">List of connections where the connection is edited from</param>
        /// <returns>Created or updated connection</returns>
        public ConnectionDetail EditConnection(bool isCreation, ConnectionDetail connectionToUpdate, ConnectionFile connectionFile = null)
        {
            var cForm = new ConnectionWizard(connectionToUpdate)
            {
                StartPosition = FormStartPosition.CenterParent
            };

            if (cForm.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                if (isCreation)
                {
                    if (connectionFile == null)
                    {
                        if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                                d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null)
                        {
                            ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);
                        }

                        ConnectionManager.Instance.SaveConnectionsFile();
                    }
                    else
                    {
                        var connections = CrmConnections.LoadFromFile(connectionFile.Path);
                        if (connections.Connections.FirstOrDefault(
                                d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null)
                        {
                            connections.Connections.Add(cForm.CrmConnectionDetail);
                        }

                        connections.SerializeToFile(connectionFile.Path);
                    }
                }
                else
                {
                    if (connectionFile == null)
                    {
                        foreach (ConnectionDetail detail in ConnectionManager.Instance.ConnectionsList.Connections)
                        {
                            if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                            {
                                detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                            }
                        }

                        ConnectionManager.Instance.SaveConnectionsFile();
                    }
                    else
                    {
                        var connections = CrmConnections.LoadFromFile(connectionFile.Path);
                        foreach (ConnectionDetail detail in connections.Connections)
                        {
                            if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                            {
                                detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                            }
                        }

                        connections.SerializeToFile(connectionFile.Path);
                    }
                }

                return(cForm.CrmConnectionDetail);
            }

            return(null);
        }