Пример #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 lstFields_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;
                    lstFields.SelectedIndex = selectedListId;
                }
            }
            if (!blnSwitch)
            {
                return;
            }
            if (blnSwitchOverride)
            {
                blnSwitchOverride = false;
                return;
            }

            blnTextChanged = false;

            var selectedField = lstFields.Text;

            fieldId        = ProgSettings.LookupFieldId(TableName, selectedField); // Force to new entry before the lookup updates it should it exist
            selectedListId = lstFields.SelectedIndex;

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

            DataSet dbViewList;

            if (lstLangs.SelectedIndex == 0)
            {   // If English, connect to main table
                dbViewList = ProgSettings.SelectRows("SELECT `dbdocsfields`.`languageId`,`dbdocsfields`.`FieldId`, `dbdocsfields`.`FieldNotes`,`dbdocsfields`.`FieldComment` FROM `dbdocsfields` WHERE `tablename` = '" + TableName + "' and `FieldName` = '" + selectedField + "'");
            }
            else
            {   // If Non-English, join to localised table and grab field
                dbViewList = ProgSettings.SelectRows("SELECT COALESCE(`dbdocsfields_localised`.`languageid`,-1) AS languageId,`dbdocsfields`.`FieldId`, `dbdocsfields_localised`.`FieldNotes`, `dbdocsfields_localised`.`FieldComment`,`dbdocsfields`.`FieldNotes` as FieldNotesEnglish, `dbdocsfields`.`FieldComment` as FieldCommentEnglish FROM `dbdocsfields` LEFT JOIN `dbdocsfields_localised` ON `dbdocsfields`.`fieldId` = `dbdocsfields_localised`.`fieldId` where TableName='" + TableName + "'" + " AND FieldName='" + selectedField + "' AND (`dbdocsfields_localised`.`languageId`=" + lstLangs.SelectedIndex + "  OR `dbdocsfields`.`languageId`=0);");
            }

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

                    // If the Field Comment field is blank, fill it in with the first 80 characters of the notes
                    if (string.IsNullOrEmpty(txtFieldComment.Text) && !string.IsNullOrEmpty(txtFieldNotes.Text))
                    {
                        txtFieldComment.Text = txtFieldNotes.Text;
                        if (txtFieldComment.Text.Length > 80)
                        {
                            txtFieldComment.Text = txtFieldNotes.Text.Substring(0, 80);
                        }
                    }

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

                    // 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(txtFieldNotes.Text))
                        {
                            txtFieldNotes.Text = dbViewList.Tables[0].Rows[0]["FieldNotesEnglish"].ToString();
                        }
                        if (string.IsNullOrEmpty(txtFieldComment.Text))
                        {
                            txtFieldComment.Text = dbViewList.Tables[0].Rows[0]["FieldCommentEnglish"].ToString();
                        }
                        if (string.IsNullOrEmpty(txtFieldComment.Text))
                        {
                            txtFieldComment.Text = txtFieldNotes.Text.Substring(0, 80);
                        }
                    }

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

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