private void LibraryDataList_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
 {
     LibraryData library = new Libraries().GetLibraryById(int.Parse(e.CommandArgument.ToString()));
     LibraryNameTextBox.Text = library.Libraries[0].LibraryName;
     ViewState["LibraryId"] = library.Libraries[0].LibraryId;
     AddLibraryButton.Visible = false;
     AddLibraryTitle.Text = GetPageResource("UpdateLibraryTitle");
     UpdateLibraryButton.Visible = true;
     DeleteLibraryButton.Visible = true;
     editplaceholder.Visible = true;
 }
 /// <summary>
 /// Get the current DB stats and fill 
 /// the label with them
 /// </summary>
 private void BindData()
 {
     // Retrieve the library data
     LibraryData libraryData =
         new Libraries().GetLibraries();
     gridLibraries.DataSource = libraryData;
     gridLibraries.DataMember = "Libraries";
     gridLibraries.DataBind();
 }
        private void SourceDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (SourceDropDownList.SelectedValue == "-1")
            {
                SurveyListDropdownlist.Items.Clear();
                SurveyListDropdownlist.Visible = false;
                SurveyQuestionListDropdownlist.Items.Clear();
                SurveyQuestionListDropdownlist.Visible = false;
                LibraryDropDownList.Items.Clear();
                LibraryDropDownList.Visible = false;
                LibraryQuestionsDropDownList.Items.Clear();
                LibraryQuestionsDropDownList.Visible = false;
                CopyExistingQuestionButton.Enabled = false;

            }
            else if (SourceDropDownList.SelectedValue == "0")
            {
                SurveyListDropdownlist.Items.Clear();
                SurveyListDropdownlist.Visible = false;
                SurveyQuestionListDropdownlist.Items.Clear();
                SurveyQuestionListDropdownlist.Visible = false;

                // Retrieve the library data
                LibraryData libraryData =
                    new Libraries().GetLibraries();
                LibraryDropDownList.DataSource = libraryData;
                LibraryDropDownList.DataMember = "Libraries";
                LibraryDropDownList.DataTextField = "LibraryName";
                LibraryDropDownList.DataValueField = "LibraryId";
                LibraryDropDownList.DataBind();
                LibraryDropDownList.Items.Insert(0, new ListItem(GetPageResource("SelectLibraryMessage"), "-1"));
                LibraryDropDownList.Visible = true;
                CopyExistingQuestionButton.Enabled = false;
            }
            else
            {
                CheckRight(NSurveyRights.CopyQuestionFromAllSurvey, true);
                LibraryDropDownList.Items.Clear();
                LibraryDropDownList.Visible = false;
                LibraryQuestionsDropDownList.Items.Clear();
                LibraryQuestionsDropDownList.Visible = false;

                SurveyData surveys;
                /*
                if (CheckRight(NSurveyRights.CopyQuestionFromAllSurvey, false) ||
                    NSurveyUser.Identity.HasAllSurveyAccess)
              
                {
                    surveys = new Surveys().GetAllSurveysList();
                }
                else
                     
                {
                 * */
                surveys = new Surveys().GetAssignedSurveysList(NSurveyUser.Identity.UserId);


                SurveyListDropdownlist.DataSource = surveys;
                SurveyListDropdownlist.DataMember = "surveys";
                SurveyListDropdownlist.DataTextField = "title";
                SurveyListDropdownlist.DataValueField = "surveyid";
                SurveyListDropdownlist.DataBind();
                SurveyListDropdownlist.Items.Insert(0, new ListItem(GetPageResource("SelectSurveyMessage"), "-1"));
                SurveyListDropdownlist.Visible = true;
                CopyExistingQuestionButton.Enabled = false;
            }

        }
        public void FillData()
        {
            btnDeleteLib.Visible = LibraryEditMode;
            pnllanguageSelection.Visible = LibraryEditMode;
            btnDeleteLib.Text = ((PageBase)Page).GetPageResource("LibraryTabDelete");
            btnAddLib.Text = ((PageBase)Page).GetPageResource((LibraryEditMode) ? "LibraryTabNewEditLanguage" : "LibraryTabNewAddLanguage");
            lblLibraryTitle.Text = ((PageBase)Page).GetPageResource((LibraryEditMode) ? "LibraryTabEdit" : "LibraryTabNewAdd");

            lblTableName.Text = ((PageBase)Page).GetPageResource("LibraryTabNewName");
            lblNewDescription.Text = ((PageBase)Page).GetPageResource("LibraryTabNewDescription");
            lblLanguageSrc.Text = ((PageBase)Page).GetPageResource("LibraryTabNewEnabledLanguages");
            lblDdlLanguage.Text = ((PageBase)Page).GetPageResource("LibraryTabNewDefaultLanguage");

            MessageLabel.Text = string.Empty;
            lbLangSrc.DataMember = "MultiLanguages";
            lbLangSrc.DataTextField = "LanguageDescription";
            lbLangSrc.DataValueField = "LanguageCode";
            lbLangSrc.DataSource = null;
            lbLangSrc.DataSource = new MultiLanguages().GetMultiLanguages();
            lbLangSrc.DataBind();
            lbLangSrc.SelectedIndex = -1;
            /* JJ Library does not depend on Survey- So this is meaningless */
            if (LibraryEditMode)
            {
                lbLangEnabled.DataMember = "MultiLanguages";
                lbLangEnabled.DataTextField = "LanguageDescription";
                lbLangEnabled.DataValueField = "LanguageCode";
                lbLangEnabled.DataSource = null;
                lbLangEnabled.DataSource = new MultiLanguages().GetSurveyLanguages(LibraryId, Constants.Constants.EntityLibrary);
                lbLangEnabled.DataBind();
                lbLangEnabled.SelectedIndex = -1;
                /*  */
                foreach (ListItem enabledItem in lbLangEnabled.Items)
                {
                    ListItem disabledItem = lbLangSrc.Items.FindByValue(enabledItem.Value);
                    if (disabledItem != null)
                    {
                        lbLangSrc.Items.Remove(disabledItem);
                    }
                }
            }
            Data.MultiLanguageData data = new MultiLanguages().GetSurveyLanguages(LibraryId, Constants.Constants.EntityLibrary);


            LibraryData libraryData = null;
            if (LibraryEditMode)
            {

                libraryData = new Libraries().GetLibraryById(LibraryId);
                LibraryData.LibrariesRow library = (LibraryData.LibrariesRow)libraryData.Libraries.Rows[0];
                txtLibName.Text = library.LibraryName;
                txtLibDescr.Text = library.Description;
            }

            ddlDefaultLang.Items.Clear();

            foreach (Data.MultiLanguageData.MultiLanguagesRow language in data.MultiLanguages)
            {
                ListItem defaultItem = new ListItem(language.LanguageDescription, language.LanguageCode);

                if (language.DefaultLanguage)
                {
                    defaultItem.Selected = true;
                }

                ddlDefaultLang.Items.Add(defaultItem);
            }


            ((PageBase)Page).TranslateListControl(ddlDefaultLang,true);
            ((PageBase)Page).TranslateListControl(lbLangSrc,true);
            ((PageBase)Page).TranslateListControl(lbLangEnabled,true);
        }
        private void LocalizePage()
        {
            if (_libraryId != -1)
            {
                AddQuestionButton.Text = GetPageResource("AddQuestionToLibraryButton");

                LibraryData library = new Libraries().GetLibraryById(_libraryId);
                if (library.Libraries.Rows.Count != 0)
                {
                    NewQuestionTitle.Text = string.Format(
                        GetPageResource("NewLibraryQuestionTitle"), library.Libraries[0].LibraryName);
                }
            }
            else
            {
                NewQuestionTitle.Text = GetPageResource("NewQuestionTitle");
                AddQuestionButton.Text = GetPageResource("AddQuestionButton");
            }

            QuestionLabel.Text = GetPageResource("QuestionLabel");
            if (!Page.IsPostBack)
            {
                QuestionDropDownList.Items.Add(new ListItem(GetPageResource("SingleQuestionOption"), "single"));
                QuestionDropDownList.Items.Add(new ListItem(GetPageResource("MatrixQuestionOption"), "matrix"));
                QuestionDropDownList.Items.Add(new ListItem(GetPageResource("StaticTextQuestionOption"), "static"));

                SourceDropDownList.Items.Add(new ListItem(GetPageResource("SelectSourceMessage"), "-1"));
                if (_libraryId == -1 && CheckRight(NSurveyRights.CopyQuestionFromLibrary, false))
                {
                    SourceDropDownList.Items.Add(new ListItem(GetPageResource("LibraryOption"), "0"));
                }
                if (CheckRight(NSurveyRights.CopyQuestionFromAllSurvey, false) ||
                    NSurveyUser.Identity.HasAllSurveyAccess)
                {
                    SourceDropDownList.Items.Add(new ListItem(GetPageResource("SurveyOption"), "1"));
                }
            }
            ImportQuestionTitle.Text = GetPageResource("ImportQuestionTitle");
            ImportXMLButton.Text = GetPageResource("ImportXMLButton");
            TypeLabel.Text = GetPageResource("TypeLabel");
            if (_libraryId == -1)
            {
                CopyExistingQuestionButton.Text = GetPageResource("CopyExistingQuestionButton");
            }
            else
            {
                CopyExistingQuestionButton.Text = GetPageResource("CopyExistingQuestionToLibraryButton");
            }

            CopyExistingQuestionTitle.Text = GetPageResource("CopyExistingQuestionTitle");
            TypeLabel.Text = GetPageResource("TypeLabel");

        }