private void UpdateFormMode(bool IsDraftMode)
        {
            try
            {
                Template template = new Template(this.mediator);

               var client = Epi.Core.ServiceClient.EWEServiceClient.GetClient();
                DataTable table;
                View RootView = this.mediator.Project.Metadata.GetParentView(this.mediator.ProjectExplorer.CurrentView.Id);
                if (RootView == null)
                    {
                    table = this.mediator.Project.Metadata.GetPublishedViewKeys(this.mediator.ProjectExplorer.CurrentView.Id);
                    }
                else
                    {
                    table = this.mediator.Project.Metadata.GetPublishedViewKeys(RootView.Id);
                    }

                DataRow ViewRow = table.Rows[0];

                string WebSurveyId = ViewRow.ItemArray[3].ToString();
                string OrganizationKey = ViewRow.ItemArray[2].ToString();

                Configuration config = Configuration.GetNewInstance();
                Epi.EWEManagerService.SurveyInfoRequest Request = new Epi.EWEManagerService.SurveyInfoRequest();
                Epi.EWEManagerService.SurveyInfoResponse Result = new Epi.EWEManagerService.SurveyInfoResponse();
                Epi.EWEManagerService.SurveyInfoCriteria Criteria = new EWEManagerService.SurveyInfoCriteria();

                //   Request.Criteria.ClosingDate = this.CloseDate;
                Criteria.OrganizationKey = new Guid(OrganizationKey);
                //Criteria.UserPublishKey = new Guid(this.UserPublishKey);
                List<string> List = new List<string>();
                List.Add(WebSurveyId);
                Criteria.SurveyIdList = List.ToArray();
                Request.Criteria = Criteria;

                Epi.EWEManagerService.SurveyInfoDTO SurveyInfoDTO = new Epi.EWEManagerService.SurveyInfoDTO();

                SurveyInfoDTO.StartDate = DateTime.Now;
                SurveyInfoDTO.SurveyId = new Guid(WebSurveyId).ToString();
                SurveyInfoDTO.SurveyType = 2;
                SurveyInfoDTO.SurveyName = mediator.Project.Name;
                SurveyInfoDTO.OrganizationKey = new Guid(OrganizationKey);
                if (this.mediator.Project.CollectedData.GetDbDriver().ConnectionDescription.ToString().Contains("Microsoft SQL Server:"))
                {
                    SurveyInfoDTO.IsSqlProject= true;
                }// Update IsSqlProject to true on change survey mode for Sql project.

                //SurveyInfoDTO.UserPublishKey = new Guid(this.UserPublishKey);
                SurveyInfoDTO.XML = template.CreateWebEnterTemplate();

                Request.Criteria.SurveyType = 2;

                if (IsDraftMode)
                    {
                    Request.Action = "Update";
                    Request.Criteria.IsDraftMode = true;
                    SurveyInfoDTO.IsDraftMode = true;
                    }
                else
                    {
                    Request.Action = "UpdateMode";
                    Request.Criteria.IsDraftMode = false;
                    SurveyInfoDTO.IsDraftMode = false;
                    }
                List<Epi.EWEManagerService.SurveyInfoDTO> DTOList = new List<Epi.EWEManagerService.SurveyInfoDTO>();
                DTOList.Add(SurveyInfoDTO);
                Request.SurveyInfoList = DTOList.ToArray();

                Result = client.SetSurveyInfo(Request);
                if (Result != null && Result.SurveyInfoList.Count() > 0)
                    {
                    //this.UpdateStatus("Survey mode was successfully updated!");
                    if (IsDraftMode)
                        {
                        MessageBox.Show("Form mode was successfully changed to Staging.", "", MessageBoxButtons.OK);
                        }
                    else
                        {
                        MessageBox.Show("Form mode was successfully changed to Production.", "", MessageBoxButtons.OK);
                        }
                    }
                }

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

                }
        }
        public void SetFormInfo()
        {
            try
            {
                var client = Epi.Core.ServiceClient.EWEServiceClient.GetClient();
                Configuration config = Configuration.GetNewInstance();
                DataTable table = mediator.Project.Metadata.GetPublishedViewKeys(this.projectExplorer.CurrentView.Id);
                DataRow ViewRow = table.Rows[0];

                string WebSurveyId = ViewRow.ItemArray[3].ToString();

                Epi.EWEManagerService.SurveyInfoRequest infoRequest = new Epi.EWEManagerService.SurveyInfoRequest();
                Epi.EWEManagerService.SurveyInfoResponse infoResult = new Epi.EWEManagerService.SurveyInfoResponse();
                infoRequest.Criteria = new EWEManagerService.SurveyInfoCriteria();

                if (!string.IsNullOrWhiteSpace(WebSurveyId))
                {
                    infoRequest.Criteria.OrganizationKey = new Guid(this.EWEOrganizationKey);
                    infoRequest.Criteria.ReturnSizeInfoOnly = false;
                    infoRequest.Criteria.SurveyIdList = new string[]{WebSurveyId};
                    infoResult = client.GetSurveyInfo(infoRequest);
                }

                if (infoResult != null && infoResult.SurveyInfoList.Count() > 0)
                {
                    SurveyName = infoResult.SurveyInfoList[0].SurveyName;
                    DepartmentName = infoResult.SurveyInfoList[0].DepartmentName;
                    SurveyNumber = infoResult.SurveyInfoList[0].SurveyNumber;
                    OrganizationName = infoResult.SurveyInfoList[0].OrganizationName;
                    StartDate = infoResult.SurveyInfoList[0].StartDate;
                    CloseDate = infoResult.SurveyInfoList[0].ClosingDate;
                    IsDraftMode = infoResult.SurveyInfoList[0].IsDraftMode;
                    IntroductionText = infoResult.SurveyInfoList[0].IntroductionText;
                    ExitText = infoResult.SurveyInfoList[0].ExitText;
                    TemplateXML = infoResult.SurveyInfoList[0].XML;
                    SurveyType = infoResult.SurveyInfoList[0].SurveyType;
                    this.UserPublishKey = infoResult.SurveyInfoList[0].UserPublishKey.ToString();
                    SetEWEModetoolStripDropDown(IsDraftMode);
                    }

                }
            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 DoQuickPublish(Template template)
        {
            var client = Epi.Core.ServiceClient.EWEServiceClient.GetClient();

            DataTable table;
            View RootView = this.mediator.Project.Metadata.GetParentView(this.mediator.ProjectExplorer.CurrentView.Id);
            if (RootView == null)
                {
                table = this.mediator.Project.Metadata.GetPublishedViewKeys(this.mediator.ProjectExplorer.CurrentView.Id);
                }
            else
                {
                table = this.mediator.Project.Metadata.GetPublishedViewKeys(RootView.Id);
                }
            DataRow ViewRow = table.Rows[0];

            string WebSurveyId = ViewRow.ItemArray[3].ToString();
            string OrganizationKey = ViewRow.ItemArray[2].ToString();

            Configuration config = Configuration.GetNewInstance();
            Epi.EWEManagerService.SurveyInfoRequest Request = new Epi.EWEManagerService.SurveyInfoRequest();
            Epi.EWEManagerService.SurveyInfoResponse Result = new Epi.EWEManagerService.SurveyInfoResponse();
            Epi.EWEManagerService.SurveyInfoCriteria Criteria = new EWEManagerService.SurveyInfoCriteria();

            //   Request.Criteria.ClosingDate = this.CloseDate;
            Criteria.OrganizationKey = new Guid(OrganizationKey);
            //Criteria.UserPublishKey = new Guid(this.UserPublishKey);
            List<string> List = new List<string>();
            List.Add(WebSurveyId);
            Criteria.SurveyIdList = List.ToArray();
            Request.Criteria = Criteria;
            Request.Action = "Update";

            Epi.EWEManagerService.SurveyInfoDTO SurveyInfoDTO = new Epi.EWEManagerService.SurveyInfoDTO();

            SurveyInfoDTO.StartDate = DateTime.Now;
            SurveyInfoDTO.SurveyId = new Guid(WebSurveyId).ToString();
            SurveyInfoDTO.SurveyType = 2;
            SurveyInfoDTO.SurveyName = mediator.Project.Name;
            SurveyInfoDTO.OrganizationKey = new Guid(OrganizationKey);

            if (this.mediator.Project.CollectedData.GetDbDriver().ConnectionDescription.ToString().Contains("Microsoft SQL Server:"))
            {
                SurveyInfoDTO.IsSqlProject = true;
            }//changed IsSqlProject to true on quick publishing a SQL project

            //SurveyInfoDTO.UserPublishKey = new Guid(this.UserPublishKey);
            SurveyInfoDTO.XML = template.CreateWebEnterTemplate();

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

                MessageBox.Show("Form was successfully updated.", "", MessageBoxButtons.OK);
                }
        }