Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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;
        }