Ejemplo n.º 1
0
        /// <summary>
        /// Populate the entry information when the item is selected in the listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstTables_SelectedIndexChanged(object sender, EventArgs e)
        {
            var blnSwitch = true;

            if (blnTextChanged && !blnSwitchOverride)
            {
                // Subtable text has tried to change selection without save, warn them
                var dialogResult = MessageBox.Show(this, Resources.You_have_unsaved_changes, Resources.Exit_Check, MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Exclamation);

                // If the user chose no, don't annoy the switch
                if (dialogResult == DialogResult.No)
                {
                    blnSwitch               = false;
                    blnSwitchOverride       = true;
                    lstTables.SelectedIndex = selectedListId;
                }
            }
            if (!blnSwitch)
            {
                return;
            }
            if (blnSwitchOverride)
            {
                blnSwitchOverride = false;
                return;
            }

            blnTextChanged = false;

            var selectedTable = lstTables.Text;

            tableId        = ProgSettings.LookupTableId(selectedTable);
            selectedListId = lstTables.SelectedIndex;

            if (lstLangs.SelectedIndex < 0)
            {
                lstLangs.SelectedIndex = 0;
            }

            DataSet dbViewList;

            if (lstLangs.SelectedIndex == 0)
            {
                // If English, connect to main table
                dbViewList =
                    ProgSettings.SelectRows(
                        "SELECT `dbdocstable`.`languageId`,`dbdocstable`.`tableId`,`dbdocstable`.`tableNotes` FROM `dbdocstable` WHERE `tablename` = '" +
                        selectedTable + "'");
            }
            else
            {
                // If Non-English, join to localised table and grab field
                dbViewList =
                    ProgSettings.SelectRows(
                        "SELECT COALESCE(`dbdocstable_localised`.`languageid`,-1) AS languageId,`dbdocstable_localised`.`tableNotes`, `dbdocstable`.`tableId`, `dbdocstable`.`tableNotes` as TableNotesEnglish FROM `dbdocstable` LEFT JOIN `dbdocstable_localised` ON `dbdocstable`.`tableId` = `dbdocstable_localised`.`tableId` WHERE `tablename` = '" +
                        selectedTable + "' AND (`dbdocstable_localised`.`languageId`=" + lstLangs.SelectedIndex +
                        " OR `dbdocstable`.`languageId`=0)");
            }

            if (dbViewList != null)
            {
                if (dbViewList.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToInt32(dbViewList.Tables[0].Rows[0]["languageId"]) == lstLangs.SelectedIndex)
                    {
                        txtTableNotes.Text     = dbViewList.Tables[0].Rows[0]["TableNotes"].ToString();
                        chkDBDocsEntry.Checked = true;
                    }
                    else
                    {
                        txtTableNotes.Text     = "";
                        chkDBDocsEntry.Checked = false;
                    }

                    tableId = Convert.ToInt32(dbViewList.Tables[0].Rows[0]["TableId"]);

                    // If the 'Use English' if blank checkbox is ticked
                    if (chkUseEnglish.Checked)
                    {
                        // If Localised SubTable Template is blank, go grab the English
                        if (string.IsNullOrEmpty(txtTableNotes.Text))
                        {
                            txtTableNotes.Text = dbViewList.Tables[0].Rows[0]["TableNotesEnglish"].ToString();
                        }
                    }

                    txtTableNotes.Text = ProgSettings.ConvertBrToCrlf(txtTableNotes.Text);

                    //Check for Subtables
                    ProgSettings.ExtractSubTables(txtTableNotes.Text, lstSubtables);
                }
                else // No dbdocs match
                {
                    txtTableNotes.Text     = "";
                    chkDBDocsEntry.Checked = false;
                }
            }
            else // No dbdocs match
            {
                txtTableNotes.Text     = "";
                chkDBDocsEntry.Checked = false;
            }
            btnShowFields.Enabled = true;
            blnTextChanged        = false;
            btnSave.Enabled       = false;
            mnuSave.Enabled       = btnSave.Enabled;
        }