private void updateSurveyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Template template = new Template(this.mediator);
     string InvalidForPublishing = ListFieldsNotSupportedForWeb();
     if (InvalidForPublishing.Length > 0)
     {
         SupportedFieldTypeDialog dialog = new SupportedFieldTypeDialog(InvalidForPublishing);
         dialog.ShowDialog();
     }
     else
     {
         RepublishSurveyFields dialog = new RepublishSurveyFields(this.OrganizationKey, this.projectExplorer.CurrentView, template.CreateWebSurveyTemplate());
         dialog.ShowDialog();
     }
 }
        private void QuickSurveyInfoUpdate()
        {
            try
            {
                Template template = new Template(this.mediator);
                SurveyManagerService.ManagerServiceClient client = Epi.Windows.MakeView.Utils.ServiceClient.GetClient();
                Configuration config = Configuration.GetNewInstance();

                Epi.Web.Common.Message.SurveyInfoRequest Request = new Web.Common.Message.SurveyInfoRequest();//(Epi.Web.Common.Message.SurveyInfoRequest)((object[])e.Argument)[0];
                Epi.Web.Common.Message.SurveyInfoResponse Result = new Web.Common.Message.SurveyInfoResponse();//(Epi.Web.Common.Message.SurveyInfoResponse)((object[])e.Argument)[1];

                Request.Criteria.ClosingDate = this.CloseDate;
                Request.Criteria.OrganizationKey = new Guid(this.OrganizationKey);
                Request.Criteria.UserPublishKey = new Guid(this.UserPublishKey);
                Request.Criteria.SurveyIdList.Add(this.SurveyId);
                Request.Action = "Update";

                Epi.Web.Common.DTO.SurveyInfoDTO SurveyInfoDTO = new Web.Common.DTO.SurveyInfoDTO();

                SurveyInfoDTO.ClosingDate = this.CloseDate;
                SurveyInfoDTO.StartDate = this.StartDate;
                SurveyInfoDTO.SurveyId = new Guid(this.CurrentView.WebSurveyId).ToString();
                SurveyInfoDTO.SurveyType = this.SurveyType;
                SurveyInfoDTO.SurveyNumber = this.SurveyNumber;
                SurveyInfoDTO.SurveyName = this.SurveyName;
                SurveyInfoDTO.OrganizationKey = new Guid(OrganizationKey);
                SurveyInfoDTO.OrganizationName = this.OrganizationName;
                SurveyInfoDTO.UserPublishKey = new Guid(this.UserPublishKey);
                SurveyInfoDTO.XML = template.CreateWebSurveyTemplate();
                SurveyInfoDTO.ExitText = this.ExitText;
                SurveyInfoDTO.IntroductionText = this.IntroductionText;
                SurveyInfoDTO.DepartmentName = this.DepartmentName;

                Request.Criteria.SurveyType = this.SurveyType;
                Request.Criteria.IsDraftMode = true;
                SurveyInfoDTO.IsDraftMode = this.IsDraftMode;
                Request.SurveyInfoList.Add(SurveyInfoDTO);
                Result = client.SetSurveyInfo(Request);
                if (Result != null && Result.SurveyInfoList.Count > 0)
                {
                    //this.UpdateStatus("Survey was successfully updated!");

                MessageBox.Show("Survey was successfully updated.","",MessageBoxButtons.OK);
                }
            }
            catch (FaultException<CustomFaultException> cfe)
            {
                // this.BeginInvoke(new FinishWithCustomFaultExceptionDelegate(FinishWithCustomFaultException), cfe);

            }
            catch (FaultException fe)
            {
                //this.BeginInvoke(new FinishWithFaultExceptionDelegate(FinishWithFaultException), fe);

            }
            catch (SecurityNegotiationException sne)
            {
                //this.BeginInvoke(new FinishWithSecurityNegotiationExceptionDelegate(FinishWithSecurityNegotiationException), sne);

            }
            catch (CommunicationException ce)
            {
                //this.BeginInvoke(new FinishWithCommunicationExceptionDelegate(FinishWithCommunicationException), ce);

            }
            catch (TimeoutException te)
            {
                // this.BeginInvoke(new FinishWithTimeoutExceptionDelegate(FinishWithTimeoutException), te);

            }
            catch (Exception ex)
            {
                //this.BeginInvoke(new FinishWithExceptionDelegate(FinishWithException), ex);

            }
        }
        private void updateSurveyInformationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Template template = new Template(this.mediator);
            string InvalidForPublishing = ListFieldsNotSupportedForWeb();
            if (InvalidForPublishing.Length > 0)
            {
                SupportedFieldTypeDialog dialog = new SupportedFieldTypeDialog(InvalidForPublishing);
                dialog.ShowDialog();
            }
            else
            {
                WebPublishDialog dialog = new WebPublishDialog(this.OrganizationKey, this.projectExplorer.CurrentView, template.CreateWebSurveyTemplate(), true);
                dialog.ShowDialog();
            }

            this.OrganizationKey = this.projectExplorer.CurrentView.CheckCodeBefore;
            this.projectExplorer.CurrentView.CheckCodeBefore = "";
        }
        private void publishNewSurveyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Template template = new Template(this.mediator);
            string InvalidForPublishing = ListFieldsNotSupportedForWeb();
            View view;
            if (projectExplorer.CurrentView != null)
            {
                view = projectExplorer.CurrentView;
            }
            else
            {
                view = projectExplorer.SelectedPage.view;
            }
            if (InvalidForPublishing.Length > 0)
            {
                SupportedFieldTypeDialog dialog = new SupportedFieldTypeDialog(InvalidForPublishing);
                dialog.ShowDialog();
            }
            else
            {
                    Configuration config = Configuration.GetNewInstance();

                    try
                    {
                        if (config.Settings.Republish_IsRepbulishable == true)

                        {

                        if (string.IsNullOrWhiteSpace(this.OrganizationKey) && !string.IsNullOrWhiteSpace(view.WebSurveyId))
                            {
                            Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum IsValidOKey = Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum.No;
                            if (string.IsNullOrWhiteSpace(view.WebSurveyId))
                                {
                                IsValidOKey = Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrgKey(this.OrganizationKey);
                                }
                            else
                                {
                                IsValidOKey = Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrgKey(this.OrganizationKey, view.WebSurveyId);
                                }
                            WebPublishDialog dialog = null;
                            WebSurveyOptions wso = null;
                            switch (IsValidOKey)
                                {
                                case Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum.No:
                                    OrgKey NewDialog = new OrgKey(this.CurrentView.WebSurveyId, false, "The organization key has been successfully submitted!", "The organization key is required for security purposes before you can republish this survey.");
                                    DialogResult result = NewDialog.ShowDialog();
                                    if (result == System.Windows.Forms.DialogResult.OK)
                                        {
                                        this.OrganizationKey = NewDialog.OrganizationKey;
                                        if (!string.IsNullOrWhiteSpace(OrganizationKey))
                                            {
                                            SetSurveyInfo();
                                            dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                            dialog.ShowDialog();
                                            }
                                        }
                                    break;
                                case Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum.EndPointNotFound:
                                    WebSurveyOptions dialog1 = new WebSurveyOptions();
                                    DialogResult result1 = dialog1.ShowDialog();
                                    if (result1 == System.Windows.Forms.DialogResult.OK)
                                        {
                                        OrgKey OrgKeyDialog = new OrgKey(this.CurrentView.WebSurveyId, false, "The organization key has been successfully submitted!", "The organization key is required for security purposes before you can republish this survey.");
                                        DialogResult result2 = OrgKeyDialog.ShowDialog();
                                        if (result2 == System.Windows.Forms.DialogResult.OK)
                                            {
                                            this.OrganizationKey = OrgKeyDialog.OrganizationKey;
                                            if (!string.IsNullOrWhiteSpace(OrganizationKey))
                                                {
                                                SetSurveyInfo();
                                                dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                                dialog.ShowDialog();
                                                }
                                            }
                                        }
                                    break;
                                case Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum.GeneralException:
                                    WebSurveyOptions dialog2 = new WebSurveyOptions();
                                    DialogResult result3 = dialog2.ShowDialog();
                                    if (result3 == System.Windows.Forms.DialogResult.OK)
                                        {
                                        OrgKey OrgKeyDialog = new OrgKey(this.CurrentView.WebSurveyId, false, "The organization key has been successfully submitted!", "The organization key is required for security purposes before you can republish this survey.");
                                        DialogResult result4 = OrgKeyDialog.ShowDialog();
                                        if (result4 == System.Windows.Forms.DialogResult.OK)
                                            {
                                            this.OrganizationKey = OrgKeyDialog.OrganizationKey;
                                            if (!string.IsNullOrWhiteSpace(OrganizationKey))
                                                {
                                                SetSurveyInfo();
                                                dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                                dialog.ShowDialog();
                                                }
                                            }
                                        }
                                    break;
                                case Epi.Windows.MakeView.Utils.ServiceClient.IsValidOrganizationKeyEnum.Yes:
                                    SetSurveyInfo();
                                    dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                    dialog.ShowDialog();
                                    break;
                                }

                             }
                        else {
                        if (!string.IsNullOrEmpty(this.OrganizationKey))
                            {
                               WebPublishDialog dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                               dialog.ShowDialog();
                                }else
                                {
                                        try
                                            {

                                            SurveyManagerService.ManagerServiceClient client = Epi.Windows.MakeView.Utils.ServiceClient.GetClient();
                                            Epi.Web.Common.Message.OrganizationRequest Request = new Epi.Web.Common.Message.OrganizationRequest();
                                            var TestService = client.GetOrganization(Request);

                                            WebPublishDialog dialog = new WebPublishDialog(null, view, template.CreateWebSurveyTemplate());
                                            DialogResult result = dialog.ShowDialog();
                                            if (result == System.Windows.Forms.DialogResult.Cancel)
                                                {
                                                this.OrganizationKey = dialog.GetOrgKey;
                                                }

                                            }
                                        catch (Exception ex)
                                            {
                                            WebSurveyOptions dialog2 = new WebSurveyOptions();
                                            DialogResult result3 = dialog2.ShowDialog();
                                            if (result3 == System.Windows.Forms.DialogResult.OK)
                                                {

                                                    WebPublishDialog dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                                    DialogResult result = dialog.ShowDialog();
                                                    if (result == System.Windows.Forms.DialogResult.Cancel)
                                                        {
                                                        this.OrganizationKey = dialog.GetOrgKey;
                                                        }

                                                }
                                             }
                                }
                            }
                        }
                        else
                        {
                        try {

                           SurveyManagerService.ManagerServiceClient client = Epi.Windows.MakeView.Utils.ServiceClient.GetClient();
                           Epi.Web.Common.Message.OrganizationRequest Request = new Epi.Web.Common.Message.OrganizationRequest();
                           var TestService = client.GetOrganization(Request);

                            WebPublishDialog dialog = new WebPublishDialog(null, view, template.CreateWebSurveyTemplate());
                            DialogResult result =  dialog.ShowDialog();
                                if (result == System.Windows.Forms.DialogResult.Cancel)
                                    {
                                     this.OrganizationKey = dialog.GetOrgKey;
                                    }

                            }
                            catch (Exception ex)
                            {

                                if (config.Settings.Republish_IsRepbulishable == true)
                                   {
                                    WebSurveyOptions dialog2 = new WebSurveyOptions();
                                    DialogResult result3 = dialog2.ShowDialog();
                                    if (result3 == System.Windows.Forms.DialogResult.OK)
                                        {

                                        WebPublishDialog dialog = new WebPublishDialog(this.OrganizationKey, view, template.CreateWebSurveyTemplate());
                                        DialogResult result = dialog.ShowDialog();
                                        if (result == System.Windows.Forms.DialogResult.Cancel)
                                            {
                                            this.OrganizationKey = dialog.GetOrgKey;
                                            }

                                        }
                                    }
                                 else
                                    {

                                     WebPublishDialog dialog = new WebPublishDialog(null, view, template.CreateWebSurveyTemplate());
                                     dialog.ShowDialog();
                                    }
                            }
                        }
                    }
                    catch(Exception ex)// not republishable
                    {
                        WebPublishDialog dialog = new WebPublishDialog(null, view, template.CreateWebSurveyTemplate());
                        dialog.ShowDialog();
                    }
            }

            this.SetPublishMenuItems(view);
        }