Exemplo n.º 1
0
        private void frmTables_Load(object sender, EventArgs e)
        {
            // Populate the Language Pulldown
            ProgSettings.LoadLangs(lstLangs);

            // The following command reads all the columns for the selected table
            var dbViewList =
                ProgSettings.SelectRows(
                    "SELECT T.TABLE_NAME AS TableName, T.ENGINE AS TableEngine, T.TABLE_COMMENT AS TableComment FROM INFORMATION_SCHEMA.Tables T WHERE T.TABLE_NAME <> 'dtproperties' AND T.TABLE_SCHEMA <> 'INFORMATION_SCHEMA' AND T.TABLE_SCHEMA='" +
                    ProgSettings.DbName + "' ORDER BY T.TABLE_NAME");

            // Did we return anything
            if (dbViewList != null)
            {
                // Do we have rows
                if (dbViewList.Tables[0].Rows.Count > 0)
                {
                    lstTables.Items.Clear();

                    // for each Field returned, populate the listbox with the table name
                    for (var thisRow = 0; thisRow <= dbViewList.Tables[0].Rows.Count - 1; thisRow++)
                    {
                        var tableName = dbViewList.Tables[0].Rows[thisRow]["TableName"].ToString();
                        lstTables.Items.Add(tableName);
                    }
                }
            }

            blnTextChanged = false;
        }
Exemplo n.º 2
0
        private void btnNewEntry_Click(object sender, EventArgs e)
        {
            // Get the Next Subtable EntryID
            var thissubTableId = Convert.ToInt32(ProgSettings.GetNewSubTableId());

            var thisSubtableName = "";
            var returnVal        = ProgSettings.ShowInputDialog(ref thisSubtableName, "subTable Name");

            // If the user clicked ok, add the new table
            if (returnVal != DialogResult.OK)
            {
                return;
            }
            // Add to the table
            ProgSettings.SubTableInsert(thissubTableId, lstLangs.SelectedIndex, thisSubtableName, "To be populated",
                                        "To be populated");
            SubTableId = thissubTableId;

            // Add it to the listbox and select it
            lstsubtables.Items.Add(thisSubtableName);

            var intSubTableListIndex = lstsubtables.Items.IndexOf(thisSubtableName);

            lstsubtables.SelectedIndex = intSubTableListIndex; // lstsubtables.Items.Count - 1;

            blnTextChanged  = true;
            btnSave.Enabled = true;
            mnuSave.Enabled = btnSave.Enabled;
        }
Exemplo n.º 3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     SubTableId   = Convert.ToInt32(ProgSettings.LookupSubTableId(lstsubtables.Text));
     FormClosing -= FrmSubtablesLookup_FormClosing;
     Close();
     // MessageBox.Show("Save Complete");
 }
Exemplo n.º 4
0
        private void frmFields_Load(object sender, EventArgs e)
        {
            Text = Resources.DBDocs_for_Table + TableName;
            ProgSettings.LoadLangs(lstLangs);

            // The following command reads all the columns for the selected table
            var dbViewList = ProgSettings.SelectRows("SHOW COLUMNS FROM " + TableName);

            // Did we return anything
            if (dbViewList != null)
            {
                // Do we have rows
                if (dbViewList.Tables[0].Rows.Count > 0)
                {
                    lstFields.Items.Clear();

                    // for each Field returned, populate the listbox with the column name
                    for (var thisRow = 0; thisRow <= dbViewList.Tables[0].Rows.Count - 1; thisRow++)
                    {
                        var fieldName = dbViewList.Tables[0].Rows[thisRow]["Field"].ToString();
                        lstFields.Items.Add(fieldName);
                    }
                }
            }

            blnTextChanged = false;
        }
Exemplo n.º 5
0
        private void frmsubtables_Load(object sender, EventArgs e)
        {
            // Populate the Language Pulldown
            ProgSettings.LoadLangs(lstLangs);

            DataSet dbViewList;

            if (SubTableId == 0)
            {
                // The following command reads all the columns for all the subtables
                dbViewList = ProgSettings.SelectRows("SELECT subtablename from dbdocssubtables");
            }
            else
            {
                // The following command reads all the columns for just the selected subtable
                dbViewList =
                    ProgSettings.SelectRows("SELECT subtablename from dbdocssubtables where subtableid=" + SubTableId);
            }

            // Did we return anything
            if (dbViewList == null)
            {
                return;
            }

            // Do we have rows
            if (dbViewList.Tables[0].Rows.Count <= 0)
            {
                return;
            }

            // for each Field returned, populate the listbox with the table name
            for (var thisRow = 0; thisRow <= dbViewList.Tables[0].Rows.Count - 1; thisRow++)
            {
                var fieldName = dbViewList.Tables[0].Rows[thisRow]["subtablename"].ToString();
                lstsubtables.Items.Add(fieldName);
            }

            if (SubTableId != 0)
            {
                //Select the first entry if we passed in an Id
                if (lstsubtables.SelectedIndex < 0)
                {
                    lstsubtables.SelectedIndex = 0;
                }
                Text = Resources.SubTable + lstsubtables.Text;
            }
            else
            {
                Text = Resources.SubTables;
            }

            blnTextChanged = false;
        }
Exemplo n.º 6
0
 private void btnCloseWindow_Click(object sender, EventArgs e)
 {
     if (blnTextChanged)
     {
         var response = MessageBox.Show(this, Resources.You_have_unsaved_changes, Resources.Exit_Check, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (response == DialogResult.No)
         {
             return;
         }
     }
     ProgSettings.ShowThisForm(ProgSettings.MainForm);
     Close();
 }
Exemplo n.º 7
0
        private void btnRebuildContent_Click(object sender, EventArgs e)
        {
            if (txtSubtableTemplate.Text.Contains("\r\n"))
            {
                var header = txtSubtableTemplate.Text;
                header = header.Substring(0, header.IndexOf("\r\n", StringComparison.Ordinal));

                var body = txtSubtableTemplate.Text;
                body = body.Substring(body.IndexOf("\r\n", StringComparison.Ordinal) + 2,
                                      body.Length - (body.IndexOf("\r\n", StringComparison.Ordinal) + 2));

                txtSubtableContent.Text = ProgSettings.ConvertTemplateToHtml(header, body);
            }

            webBrowse.DocumentText = txtSubtableContent.Text;
        }
Exemplo n.º 8
0
        private void frmDatabaseSelect_Load(object sender, EventArgs e)
        {
            var dbViewList = ProgSettings.SelectRows("SHOW DATABASES");

            if (dbViewList == null)
            {
                return;
            }
            if (dbViewList.Tables[0].Rows.Count <= 0)
            {
                return;
            }
            for (var thisRow = 0; thisRow <= dbViewList.Tables[0].Rows.Count - 1; thisRow++)
            {
                lstDatabases.Items.Add(dbViewList.Tables[0].Rows[thisRow]["database"].ToString());
            }
        }
Exemplo n.º 9
0
 private void frmTables_FormClosing(object sender, FormClosingEventArgs e)
 {
     // Has any text changed on the form
     if (blnTextChanged)
     {
         // Ask the user if they which to close without saving
         var response = MessageBox.Show(this, Resources.You_have_unsaved_changes, Resources.Exit_Check,
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (response == DialogResult.No)
         {
             // Bail out of the form closing
             e.Cancel = true;
             return;
         }
     }
     ProgSettings.ShowThisForm(ProgSettings.MainForm);
 }
Exemplo n.º 10
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 lstsubtables_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedSubtable = lstsubtables.Text;

            txtSubtableName.Text = selectedSubtable;
            SubTableId           = 0; // Force to new entry before the lookup updates it should it exist

            var dbViewList = ProgSettings.SelectRows("SELECT subtableid,languageid, subtablecontent,subtabletemplate FROM `dbdocssubtables` WHERE `subtablename` = '" + selectedSubtable + "'");

            if (dbViewList != null)
            {
                if (dbViewList.Tables[0].Rows.Count > 0)
                {
                    txtSubtableContent.Text  = dbViewList.Tables[0].Rows[0]["subtablecontent"].ToString();
                    txtSubtableTemplate.Text = dbViewList.Tables[0].Rows[0]["subtabletemplate"].ToString();

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

                    // Render the HTML
                    webBrowse.DocumentText = txtSubtableContent.Text;

                    if (string.IsNullOrEmpty(txtSubtableTemplate.Text))
                    {   //If the template is missing, attempt to build it from the content, only for historic entries !!
                        txtSubtableTemplate.Text = ProgSettings.ConvertHtmlToTemplate(txtSubtableContent.Text);

                        //Save the updated Template
                        btnSave_Click(sender, e);
                    }
                }
                else  // No dbdocs match
                {
                    txtSubtableName.Text = "";
                }
            }
            else  // No dbdocs match
            {
                txtSubtableName.Text = "";
            }

            btnSave.Enabled = true;
        }
Exemplo n.º 11
0
        private void lstLangs_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Are we looking for a localised version ?

            if (lstLangs.SelectedIndex > 0)
            {
                // Check whether a localised version exists
                if (ProgSettings.LookupTableEntryLocalised(lstLangs.SelectedIndex, SubTableId) == false)
                {
                    // If 'Use English' is not selected, clear the text
                    if (chkUseEnglish.Checked == false)
                    {
                        txtSubtableContent.Text  = "";
                        txtSubtableTemplate.Text = "";
                    }
                }
            }
            blnTextChanged  = false;
            btnSave.Enabled = false;
            mnuSave.Enabled = btnSave.Enabled;
        }
Exemplo n.º 12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (blnEditmode == false)
            {   // When saving a new item, we only need to add it to the listbox and update the registry
                lstServers.Items.Add(txtServerName.Text + "-" + txtDefaultDB.Text);
            }
            else
            {   // When editing a connection, we have to allow for a changed servername and delete the old entry
                var selectedServer = lstServers.SelectedIndex;

                if (selectedServer > 0)
                {
                    if (serverList.Count > 0)
                    {
                        var thisServer      = serverList[selectedServer - 1];
                        var dummyServerName = thisServer.ServerNameorIp;
                        var dummyDefaultDb  = thisServer.DatabaseName;

                        // Delete the old connection from the registry
                        ProgSettings.DeleteConnection(dummyServerName + "-" + dummyDefaultDb);
                    }
                }
            }
            ProgSettings.DbName     = txtDefaultDB.Text;
            ProgSettings.ServerName = txtServerName.Text;
            ProgSettings.UserName   = txtUsername.Text;
            ProgSettings.Password   = txtPassword.Text;
            ProgSettings.Port       = txtPort.Text;

            ProgSettings.WriteRegistry();

            // Repopulate from datastore
            frmServerSelect_Load(sender, e);

            // Set the screen to 'Normal' Mode
            ToggleControls(false);

            btnConnect.Enabled = false;
        }
Exemplo n.º 13
0
        private void frmServerSelect_Load(object sender, EventArgs e)
        {
            lstServers.Items.Clear();

            //// Add default entry
            //lstServers.Items.Add("localhost-*");

            serverList = ProgSettings.PopulateConnections();
            if (serverList == null)
            {
                return;
            }
            if (serverList.Count <= 0)
            {
                return;
            }

            foreach (var thisConnection in serverList)
            {
                lstServers.Items.Add(thisConnection.ServerNameorIp + "-" + thisConnection.DatabaseName);
            }
        }
Exemplo n.º 14
0
        private void lstLangs_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Are we looking for a localised version ?

            if (lstLangs.SelectedIndex == 0)
            {
                if (ProgSettings.LookupFieldEntry(lstLangs.SelectedIndex, fieldId))
                {
                    chkDBDocsEntry.Checked = true;
                }
                else
                {
                    chkDBDocsEntry.Checked = false;
                }
            }
            else
            {
                // Check whether a localised version exists
                if (ProgSettings.LookupFieldEntryLocalised(lstLangs.SelectedIndex, fieldId))
                {
                    chkDBDocsEntry.Checked = true;
                }
                else
                {
                    chkDBDocsEntry.Checked = false;

                    // If 'Use English' is not selected, clear the text
                    if (chkUseEnglish.Checked == false)
                    {
                        txtFieldNotes.Text = "";
                    }
                }
            }
            blnTextChanged  = false;
            btnSave.Enabled = false;
            mnuSave.Enabled = btnSave.Enabled;
        }
Exemplo n.º 15
0
        private void btnDeleteEntry_Click(object sender, EventArgs e)
        {
            var isUsed            = false;
            var dbDocsTableOutput = new StringBuilder();
            var outputFolder      = Application.ExecutablePath;

            // Strip the Executable name from the path
            outputFolder = outputFolder.Substring(0, outputFolder.LastIndexOf(@"\", StringComparison.Ordinal));

            if (lstsubtables.SelectedIndex > 0)
            {
                // Need to check whether the subtable is used or not

                if (ProgSettings.IsSubtableInTable(lstsubtables.Text))
                {
                    isUsed = true;
                }

                if (ProgSettings.IsSubtableLocalisedInTable(lstsubtables.Text))
                {
                    isUsed = true;
                }

                if (ProgSettings.IsSubtableInField(lstsubtables.Text))
                {
                    isUsed = true;
                }

                if (ProgSettings.IsSubtableLocalisedInField(lstsubtables.Text))
                {
                    isUsed = true;
                }

                if (isUsed)
                {
                    return;
                }
                if (MessageBox.Show(@"Are you sure you wish to delete this subtable ?", @"Delete Subtable",
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    MessageBox.Show(@"deleted subtable ?", @"Deleted Subtable", MessageBoxButtons.OK);
                    if (lstLangs.SelectedIndex == 0)
                    {
                        // If English, connect to main table

                        dbDocsTableOutput.Append("DELETE FROM dbdocssubtables where subTableId=" +
                                                 lstsubtables.SelectedIndex + ";");

                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables.SQL",
                                                 true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }

                        ProgSettings.SubTableDelete(lstsubtables.Text, lstLangs.SelectedIndex);

                        lstsubtables.Items.Remove(lstsubtables.SelectedIndex);
                    }
                    else
                    {
                        dbDocsTableOutput.Append("DELETE FROM dbdocssubtables_localised where languageid=" +
                                                 lstLangs.SelectedIndex
                                                 + "and subTableId=" + lstsubtables.SelectedIndex + ";");
                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(
                                    outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables_localised.SQL",
                                    true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }

                        ProgSettings.SubTableDelete(lstsubtables.Text, lstLangs.SelectedIndex);

                        lstsubtables.Items.Remove(lstsubtables.SelectedIndex);
                    }
                }
            }
            else
            {
                MessageBox.Show(@"No subtable to delete?", @"Deleted Subtable", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtFieldComment.TextLength <= 80)
            {
                var dbDocsTableOutput = new StringBuilder();
                var outputFolder      = Application.ExecutablePath;

                // Strip the Executable name from the path
                outputFolder = outputFolder.Substring(0, outputFolder.LastIndexOf(@"\", StringComparison.Ordinal));

                var selectedField = lstFields.Text;

                // If the output folder doesnt exist, create it
                if (!Directory.Exists(outputFolder + @"\"))
                {
                    Directory.CreateDirectory(outputFolder + @"\");
                }

                if (fieldId == 0) // New Record
                {
                    if (lstLangs.SelectedIndex != 0)
                    {
                        // If English, connect to main table
                        dbDocsTableOutput.AppendLine("-- WARNING: The default entry should really be in english --");
                    }

                    //insert  into `dbdocsfields`(`languageId`, `tableName`,`fieldName`,`tableNotes`) values (0,'creature','entry','xxxx');
                    dbDocsTableOutput.AppendLine(
                        "insert  into `dbdocsfields` (`languageId`,`tableName`,`fieldName`,`tableComments`,`tableNotes`) values (" +
                        lstLangs.SelectedIndex + ",'" + TableName + "','" + selectedField + "','" +
                        ProgSettings.PrepareSqlString(txtFieldComment.Text) + "','" +
                        ProgSettings.PrepareSqlString(ProgSettings.ConvertCrlfToBr(txtFieldNotes.Text)) + "');");

                    // Open the file for append and write the entries to it
                    using (
                        var outfile = new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable.SQL",
                                                       true))
                    {
                        outfile.Write(dbDocsTableOutput.ToString());
                    }

                    // Write the entry out to the Database directly

                    // For an insert, the record is always saved to the primary table, regardless of the language Since the system is English based, it should really have an English
                    // base record.

                    // Language Id Selected Table Field Notes
                    ProgSettings.FieldInsert(lstLangs.SelectedIndex, TableName, selectedField, txtFieldComment.Text,
                                             ProgSettings.ConvertCrlfToBr(txtFieldNotes.Text));

                    blnTextChanged  = false;
                    btnSave.Enabled = false;
                    mnuSave.Enabled = btnSave.Enabled;
                }
                else // Updated Record
                {
                    if (lstLangs.SelectedIndex == 0)
                    {
                        // If English, connect to main table
                        //update `dbdocsfields` set `fieldnotes`= xxx where `fieldId`= xxx and languageId=yyy;
                        dbDocsTableOutput.AppendLine("update `dbdocsfields` set `FieldComment` = '" +
                                                     ProgSettings.PrepareSqlString(txtFieldComment.Text) +
                                                     "', `fieldNotes` = '" +
                                                     ProgSettings.PrepareSqlString(
                                                         ProgSettings.ConvertCrlfToBr(txtFieldNotes.Text)) +
                                                     "' where `fieldId`= '" + fieldId + "' and `languageId`= " +
                                                     lstLangs.SelectedIndex + ";");

                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable.SQL", true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }
                    }
                    else
                    {
                        dbDocsTableOutput.AppendLine("delete from `dbdocsfields_localised` where `fieldId`= '" +
                                                     fieldId + " and `languageId`= " + lstLangs.SelectedIndex + ";");
                        dbDocsTableOutput.AppendLine(
                            "insert into `dbdocsfields_localised` (`fieldId`,`languageId`,`FieldComment`,`fieldNotes`) values (" +
                            fieldId + ", " + lstLangs.SelectedIndex + ", '" +
                            ProgSettings.PrepareSqlString(txtFieldComment.Text) + "', '" +
                            ProgSettings.PrepareSqlString(ProgSettings.ConvertCrlfToBr(txtFieldNotes.Text)) + "');");

                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(
                                    outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable_localised.SQL", true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }
                    }

                    // Write the entry out to the Database directly For an update the logic to decide which table to update is in the Update function itself

                    // Field ID Language ID Notes
                    ProgSettings.FieldUpdate(fieldId, lstLangs.SelectedIndex, txtFieldComment.Text,
                                             ProgSettings.ConvertCrlfToBr(txtFieldNotes.Text));

                    blnTextChanged  = false;
                    btnSave.Enabled = false;
                    mnuSave.Enabled = btnSave.Enabled;
                }
                lblStatus.Text = DateTime.Now + Resources.Save_Complete_for + selectedField;
            }
            else
            {
                //Report that the comment is too long for the db
                MessageBox.Show(this, Resources.Text_Too_Long, Resources.Error_Saving, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtSubTableName.TextLength <= 80)
            {
                // First thing we need to do it sync the other tabs data based on the Template
                if (txtSubtableTemplate.Text.Contains("\r\n"))
                {
                    // Uses the first line of the template as the headings
                    var header = txtSubtableTemplate.Text;
                    header = header.Substring(0, header.IndexOf("\r\n", StringComparison.Ordinal));

                    // Renders everything beyond the first line as the table body
                    var body = txtSubtableTemplate.Text;
                    body = body.Substring(body.IndexOf("\r\n", StringComparison.Ordinal) + 2,
                                          body.Length - (body.IndexOf("\r\n", StringComparison.Ordinal) + 2));

                    // Sync the Content tab with the current template
                    txtSubtableContent.Text = ProgSettings.ConvertTemplateToHtml(header, body);

                    // Not technically needed, but render the HTML panel
                    webBrowse.DocumentText = txtSubtableContent.Text;
                }
                var dbDocsTableOutput = new StringBuilder();
                var outputFolder      = Application.ExecutablePath;

                // Strip the Executable name from the path
                outputFolder = outputFolder.Substring(0, outputFolder.LastIndexOf(@"\", StringComparison.Ordinal));

                var selectedTable = lstsubtables.Text;

                // If the output folder doesnt exist, create it
                if (!Directory.Exists(outputFolder + @"\"))
                {
                    Directory.CreateDirectory(outputFolder + @"\");
                }

                if (SubTableId == 0) // New Record
                {
                    if (lstLangs.SelectedIndex != 0)
                    {
                        // If English, connect to main table
                        dbDocsTableOutput.AppendLine("-- WARNING: The default entry should really be in english --");
                    }

                    var newSubtableId = Convert.ToInt32(ProgSettings.GetNewSubTableId());
                    dbDocsTableOutput.AppendLine(
                        "insert  into `dbdocssubtables`(`subtableId`,`languageId`,`subtableName`,`subtablecontent`,`subtableTemplate`) values (" +
                        newSubtableId + "," + lstLangs.SelectedIndex + ",'" + selectedTable + "','" +
                        ProgSettings.PrepareSqlString(txtSubtableContent.Text) + "','" +
                        ProgSettings.PrepareSqlString(txtSubtableTemplate.Text) + "');");

                    // Open the file for append and write the entries to it
                    using (
                        var outfile =
                            new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables.SQL",
                                             true))
                    {
                        outfile.Write(dbDocsTableOutput.ToString());
                    }

                    // Write the entry out to the Database directly

                    // For an insert, the record is always saved to the primary table, regardless of the language Since the system is English based, it should really have an English
                    // base record.

                    ProgSettings.SubTableInsert(newSubtableId, lstLangs.SelectedIndex, selectedTable,
                                                txtSubtableContent.Text, txtSubtableTemplate.Text);
                    SubTableId      = newSubtableId;
                    blnTextChanged  = false;
                    btnSave.Enabled = false;
                    mnuSave.Enabled = btnSave.Enabled;
                }
                else // Updated Record
                {
                    if (lstLangs.SelectedIndex == 0)
                    {
                        // If English, connect to main table
                        dbDocsTableOutput.AppendLine("delete from `dbdocssubtables` where `subtableId`= " + SubTableId +
                                                     " and languageId=" + lstLangs.SelectedIndex + ";");
                        dbDocsTableOutput.AppendLine(
                            "insert  into `dbdocssubtables`(`subtableId`,`languageId`,`subtableName`,`subtablecontent`,`subtableTemplate`) values (" +
                            SubTableId + "," + lstLangs.SelectedIndex + ",'" + selectedTable + "','" +
                            ProgSettings.PrepareSqlString(txtSubtableContent.Text) + "','" +
                            ProgSettings.PrepareSqlString(txtSubtableTemplate.Text) + "');");

                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables.SQL",
                                                 true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }
                    }
                    else
                    {
                        dbDocsTableOutput.AppendLine("delete from `dbdocssubtables_localised` where `subtableId`= " +
                                                     SubTableId + " and languageId=" + lstLangs.SelectedIndex + ";");
                        dbDocsTableOutput.AppendLine(
                            "insert  into `dbdocssubtable_localised`(`subtableId`,`languageId`,`subtablecontent`,`subtableTemplate`) values (" +
                            SubTableId + "," + lstLangs.SelectedIndex + ",'" +
                            ProgSettings.PrepareSqlString(txtSubtableContent.Text) + "','" +
                            ProgSettings.PrepareSqlString(txtSubtableTemplate.Text) + "');");

                        // Open the file for append and write the entries to it
                        using (
                            var outfile =
                                new StreamWriter(
                                    outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables_localised.SQL", true))
                        {
                            outfile.Write(dbDocsTableOutput.ToString());
                        }
                    }

                    // Write the entry out to the Database directly For an update the logic to decide which table to update is in the Update function itself

                    ProgSettings.SubTableUpdate(SubTableId, lstLangs.SelectedIndex, selectedTable,
                                                txtSubtableContent.Text,
                                                txtSubtableTemplate.Text);

                    blnTextChanged  = false;
                    btnSave.Enabled = false;
                    mnuSave.Enabled = btnSave.Enabled;
                }
                lblStatus.Text = DateTime.Now + Resources.Save_Complete_for + selectedTable;
            }
            else
            {
                //Report that the comment is too long for the db
                MessageBox.Show(this, Resources.Text_Too_Long, Resources.Error_Saving, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Exemplo n.º 19
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     ProgSettings.DeleteConnection(txtServerName.Text + "-" + txtDefaultDB.Text);
     lstServers.Items.RemoveAt(lstServers.SelectedIndex);
 }
Exemplo n.º 20
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;
        }
Exemplo n.º 21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var dbDocsTableOutput = new StringBuilder();
            var outputFolder      = Application.ExecutablePath;

            // Strip the Executable name from the path
            outputFolder = outputFolder.Substring(0, outputFolder.LastIndexOf(@"\", StringComparison.Ordinal));

            var selectedTable = lstTables.Text;

            // If the output folder doesnt exist, create it
            if (!Directory.Exists(outputFolder + @"\"))
            {
                Directory.CreateDirectory(outputFolder + @"\");
            }

            if (tableId == 0) // New Record
            {
                if (lstLangs.SelectedIndex != 0)
                {
                    // If English, connect to main table
                    dbDocsTableOutput.AppendLine("-- WARNING: The default entry should really be in english --");
                }

                //insert  into `dbdocstable`(`languageId`,`tableName`,`tableNotes`) values (2,'script_texts','xxxx');
                dbDocsTableOutput.AppendLine(
                    "insert  into `dbdocstable`(`languageId`,`tableName`,`tableNotes`) values (" +
                    lstLangs.SelectedIndex + ", '" + selectedTable + "','" +
                    ProgSettings.PrepareSqlString(ProgSettings.ConvertCrlfToBr(txtTableNotes.Text)) + "');");

                // Open the file for append and write the entries to it
                using (
                    var outfile = new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable.SQL", true)
                    )
                {
                    outfile.Write(dbDocsTableOutput.ToString());
                }

                // Write the entry out to the Database directly

                // For an insert, the record is always saved to the primary table, regardless of the language Since the system is English based, it should really have an English
                // base record.

                // Selected Table Language ID Notes
                ProgSettings.TableInsert(selectedTable, lstLangs.SelectedIndex, txtTableNotes.Text);

                blnTextChanged  = false;
                btnSave.Enabled = false;
                mnuSave.Enabled = btnSave.Enabled;
            }
            else // Updated Record
            {
                if (lstLangs.SelectedIndex == 0)
                {
                    // If English, connect to main table
                    //update `dbdocstable` set `languageId`=xx,`tableName`=yy,`tableNotes`=zz where tableId=aa;
                    dbDocsTableOutput.AppendLine("update `dbdocstable` set `languageId`=" + lstLangs.SelectedIndex +
                                                 ", `tableName`='" + selectedTable + "', `tableNotes`='" +
                                                 ProgSettings.PrepareSqlString(
                                                     ProgSettings.ConvertCrlfToBr(txtTableNotes.Text)) +
                                                 "' where tableId=" + tableId + ";");

                    // Open the file for append and write the entries to it
                    using (
                        var outfile = new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable.SQL",
                                                       true))
                    {
                        outfile.Write(dbDocsTableOutput.ToString());
                    }
                }
                else
                {
                    dbDocsTableOutput.AppendLine("delete from `dbdocstable_localisation` where `languageId`=" +
                                                 lstLangs.SelectedIndex + " and `tableId`= " + tableId + ";");
                    dbDocsTableOutput.AppendLine(
                        "insert  into `dbdocstable_localisation`(`tableId`,`languageId`,`tableNotes`) values (" +
                        tableId + ", " + lstLangs.SelectedIndex + ", '" +
                        ProgSettings.PrepareSqlString(ProgSettings.ConvertCrlfToBr(txtTableNotes.Text)) + "');");

                    // Open the file for append and write the entries to it
                    using (
                        var outfile =
                            new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocsTable_localised.SQL",
                                             true))
                    {
                        outfile.Write(dbDocsTableOutput.ToString());
                    }
                }

                // Write the entry out to the Database directly For an update the logic to decide which table to update is in the Update function itself

                // Table ID Language ID Notes
                ProgSettings.TableUpdate(tableId, lstLangs.SelectedIndex,
                                         ProgSettings.ConvertCrlfToBr(txtTableNotes.Text));

                blnTextChanged  = false;
                btnSave.Enabled = false;
                mnuSave.Enabled = btnSave.Enabled;
            }
            lblStatus.Text = DateTime.Now + Resources.Save_Complete_for + selectedTable;
        }
Exemplo n.º 22
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 lstsubtables_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;
                    lstsubtables.SelectedIndex = selectedListId;
                }
            }
            if (!blnSwitch)
            {
                return;
            }
            if (blnSwitchOverride)
            {
                blnSwitchOverride = false;
                return;
            }

            blnTextChanged = false;
            var selectedSubtable = lstsubtables.Text;

            txtSubTableName.Text = selectedSubtable;
            selectedListId       = lstsubtables.SelectedIndex;
            SubTableId           = 0; // Force to new entry before the lookup updates it should it exist

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

            DataSet dbViewList;

            if (lstLangs.SelectedIndex == 0)
            {
                // If English, connect to main table
                dbViewList =
                    ProgSettings.SelectRows(
                        "SELECT subtableid,languageid, subtablecontent,subtabletemplate FROM `dbdocssubtables` WHERE `subtablename` = '" +
                        selectedSubtable + "'");
            }
            else
            {
                // If Non-English, join to localised table and grab field
                dbViewList =
                    ProgSettings.SelectRows(
                        "SELECT COALESCE(`dbdocstable_localised`.`languageid`,-1) AS languageId,`dbdocssubtables`.`subtableid`, `dbdocssubtables_localised`.`subtabletemplate`, `dbdocssubtables_localised`.`subtablecontent`, `dbdocssubtables`.`subtabletemplate` as subtableTemplateEnglish, `dbdocssubtables`.`subtablecontent` as subTableContentEnglish FROM `dbdocssubtables` LEFT JOIN `dbdocssubtables_localised` ON `dbdocssubtables`.`subtableid` = `dbdocssubtables_localised`.`subtableid` WHERE `subtablename` = '" +
                        selectedSubtable + "' AND (`dbdocssubtables_localised`.`languageId`=" +
                        lstLangs.SelectedIndex +
                        "  OR `dbdocssubtables`.`languageId`=0);");
            }

            if (dbViewList != null)
            {
                if (dbViewList.Tables[0].Rows.Count > 0)
                {
                    if (Convert.ToInt32(dbViewList.Tables[0].Rows[0]["languageId"]) == lstLangs.SelectedIndex)
                    {
                        txtSubtableContent.Text  = dbViewList.Tables[0].Rows[0]["subtablecontent"].ToString();
                        txtSubtableTemplate.Text = dbViewList.Tables[0].Rows[0]["subtabletemplate"].ToString();
                    }
                    else
                    {
                        txtSubtableContent.Text  = "";
                        txtSubtableTemplate.Text = "";
                    }

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

                    // If the 'Use English' if blank checkbox is ticked
                    if (chkUseEnglish.Checked && lstLangs.SelectedIndex != 0)
                    {
                        // If Localised SubTable Template is blank, go grab the English
                        if (string.IsNullOrEmpty(txtSubtableTemplate.Text))
                        {
                            if (
                                !string.IsNullOrEmpty(
                                    dbViewList.Tables[0].Rows[0]["subtablecontentEnglish"].ToString()))
                            {
                                txtSubtableContent.Text =
                                    dbViewList.Tables[0].Rows[0]["subtablecontentEnglish"].ToString();
                            }
                            if (
                                !string.IsNullOrEmpty(
                                    dbViewList.Tables[0].Rows[0]["subtabletemplateEnglish"].ToString()))
                            {
                                txtSubtableTemplate.Text =
                                    dbViewList.Tables[0].Rows[0]["subtabletemplateEnglish"].ToString();
                            }
                        }
                    }

                    // Render the HTML
                    webBrowse.DocumentText = txtSubtableContent.Text;

                    if (string.IsNullOrEmpty(txtSubtableTemplate.Text))
                    {
                        //If the template is missing, attempt to build it from the content, only for historic entries !!
                        txtSubtableTemplate.Text = ProgSettings.ConvertHtmlToTemplate(txtSubtableContent.Text);

                        //Save the updated Template
                        btnSave_Click(sender, e);
                    }
                }
                else // No dbdocs match
                {
                    txtSubtableContent.Text  = "";
                    txtSubtableTemplate.Text = "";
                }
            }
            else // No dbdocs match
            {
                txtSubtableContent.Text  = "";
                txtSubtableTemplate.Text = "";
            }
            blnTextChanged         = false;
            btnSave.Enabled        = false;
            mnuSave.Enabled        = btnSave.Enabled;
            btnDeleteEntry.Enabled = true;
        }
Exemplo n.º 23
0
 private void btnStripTemplate_Click(object sender, EventArgs e)
 {
     txtSubtableTemplate.Text = ProgSettings.ConvertHtmlToTemplate(txtSubtableTemplate.Text);
 }
Exemplo n.º 24
0
 private void btnQuit_Click(object sender, EventArgs e)
 {
     ProgSettings.ShowThisForm(ProgSettings.MainForm);
     Close();
 }