Exemple #1
0
        private void buildConnStr()
        {
            ConfigManipulator c = new ConfigManipulator();

            SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();

            try
            {
                sb.DataSource     = c.GetValue("Server");
                sb.InitialCatalog = c.GetValue("Database");
                if (String.Equals(c.GetValue("ConnectionMethod"), Resources.SSPIConnection))
                {
                    sb.IntegratedSecurity = true;
                }
                else
                {
                    sb.IntegratedSecurity = false;
                    sb.UserID             = c.GetValue("ConnectionUsername");
                    sb.Password           = c.GetValue("ConnectionPassword");
                }
            }
            catch
            {
                MessageBox.Show(Resources.AppconfigBroken);
            }

            connStr = sb.ConnectionString;
        }
Exemple #2
0
        internal FormOptions()
        {
            InitializeComponent();

            tabControl1.Visible = false;

            foreach (TreeNode n in treeView1.Nodes)
            {
                n.Expand();
            }

            // populate login method opts
            comboBox1.Items.Add(Resources.SSPIConnection);
            comboBox1.Items.Add(Resources.UsernamePasswordConnection);

            foreach (DataGridViewColumn c1 in resultSetNamesGrid.Columns)
            {
                c1.HeaderCell.ToolTipText = Resources.TooltipResultNames;
            }

            toolStripStatusLabel1.Text = string.Empty;

            toolTip1.SetToolTip(label9, Resources.MaxSize);
            toolTip1.SetToolTip(textBox7, Resources.MaxSize);

            toolTip2.SetToolTip(label10, Resources.DupeKeyColumnsToolTip);
            toolTip2.AutoPopDelay = Settings1.Default.toolTipDelayBeforeFade;
            toolTip2.SetToolTip(textBox8, Resources.DupeKeyColumnsToolTip);

            ConfigManipulator c = new ConfigManipulator();

            try
            {
                p = LoadOpts();

                textBox1.Text = c.GetValue("Server");
                textBox2.Text = c.GetValue("Database");
                textBox3.Text = c.GetValue("ConnectionUsername");
                textBox4.Text = c.GetValue("ConnectionPassword");

                checkBox1.Checked = p.WriteEmptyResultSetColumns;
                checkBox2.Checked = p.AutoRewriteOverpunch;

                textBox5.Text = p.QueryTimeout.ToString();
                textBox6.Text = p.MaxRowsPerSheet.ToString();
                textBox9.Text = p.MaximumResultSetsPerWorkbook.ToString();

                var p1    = p.ResultNames;
                int count = 0;
                foreach (object o in p1.Keys)
                {
                    DataGridViewRow r = new DataGridViewRow();
                    resultSetNamesGrid.Rows.Add();
                    resultSetNamesGrid.Rows[count].Cells[0].Value = o;
                    resultSetNamesGrid.Rows[count].Cells[1].Value = p1[(int)o];
                    count++;
                }

                if (String.Equals(c.GetValue("ExcelFileType"), Resources.FileTypeXml))
                {
                    comboBox3.SelectedIndex = 1;
                }
                else
                {
                    comboBox3.SelectedIndex = 0;
                }

                if (String.Equals(c.GetValue("ConnectionMethod"), Resources.SSPIConnection))
                {
                    comboBox1.SelectedItem = Resources.SSPIConnection;
                }
                else
                {
                    comboBox1.SelectedItem = Resources.UsernamePasswordConnection;
                }

                if (String.Equals(c.GetValue("NewResultSet"), Resources.NewResultSetWorksheet))
                {
                    radioButton1.Checked = true;
                    radioButton2.Checked = false;
                }
                else
                {
                    radioButton1.Checked = false;
                    radioButton2.Checked = true;
                }

                textBox7.Text = Math.Round((double)p.MaxWorkBookSize / 1024 / 1024 / 1024, 3, MidpointRounding.AwayFromZero).ToString();

                if (p.DupeKeysToDelayStartingNewWorksheet != null && p.DupeKeysToDelayStartingNewWorksheet.Length > 0)
                {
                    textBox8.Text = string.Join(",", p.DupeKeysToDelayStartingNewWorksheet);
                }
            }
            catch (Exceptions.ConfigFileBroken e)
            {
                MessageBox.Show(e.Message);
                if (e.Data.Contains("key"))
                {
                    toolStripStatusLabel1.Text = Resources.AppconfigBroken + " Missing key: " + (string)e.Data["key"];
                }
                else
                {
                    toolStripStatusLabel1.Text = Resources.AppconfigBroken;
                }
                panel7.Enabled = false;
                c1             = e;
            }
        }
Exemple #3
0
        /// <summary>
        /// Save values to form state and app.config.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            double dd;

            if (!double.TryParse(textBox7.Text, out dd))
            {
                MessageBox.Show("Error: Maximum workbook filesize must be a numeric entry.");
                return;
            }
            dd = Math.Round(Convert.ToDouble(textBox7.Text) * Math.Pow(1024, 3), 0, MidpointRounding.AwayFromZero);

            ConfigManipulator c = new ConfigManipulator();

            Dictionary <string, string> h = new Dictionary <string, string>();

            h.Add("Server", textBox1.Text);
            h.Add("Database", textBox2.Text);
            h.Add("ConnectionMethod", String.Equals(comboBox1.SelectedItem.ToString(), Resources.SSPIConnection)
                ? Resources.SSPIConnection : Resources.UsernamePasswordConnection);
            h.Add("NewResultSet", radioButton1.Checked
                ? Resources.NewResultSetWorksheet : Resources.NewResultSetWorkbook);
            h.Add("ConnectionUsername", textBox3.Text);
            h.Add("ConnectionPassword", textBox4.Text);
            h.Add("QueryTimeout", textBox5.Text);
            h.Add("MaxRowsPerSheet", textBox6.Text);

            h.Add("MaximumWorkbookSizeInBytes", dd.ToString());
            h.Add("MaximumResultSetsPerWorkbook", textBox9.Text);

            if (Regex.IsMatch(comboBox3.SelectedItem.ToString(), Resources.FileTypeXml, RegexOptions.IgnoreCase))
            {
                h.Add("ExcelFileType", Resources.FileTypeXml);
            }
            else
            {
                h.Add("ExcelFileType", Resources.FileTypeXlsx);
            }
            h.Add("WriteEmptyResultColumnHeaders", checkBox1.Checked.ToString());
            h.Add("AutoRewriteOverpunch", checkBox2.Checked.ToString());

            string[] a = null;
            if (!string.IsNullOrEmpty(textBox8.Text))
            {
                a = textBox8.Text.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                Dictionary <object, object> d1a = new Dictionary <object, object>();
                int i = 1;
                foreach (var entry in a)
                {
                    if (!string.IsNullOrWhiteSpace(entry))
                    {
                        d1a.Add("column" + i.ToString(), entry);
                        i++;
                    }
                }
                if (d1a.Count > 0)
                {
                    c.SaveValue(d1a, "ColumnsThatPreventNewWorksheets");
                }
            }

            Dictionary <object, object> d2 = new Dictionary <object, object>();

            foreach (DataGridViewRow d in resultSetNamesGrid.Rows.Cast <DataGridViewRow>().Where(x => x.Cells[0].Value != null))
            {
                d2.Add(Convert.ToInt32(d.Cells[0].Value.ToString()), d.Cells[1].Value.ToString());
            }
            c.SaveValue(d2, "ResultNames");

            foreach (string i in h.Keys)
            {
                c.SaveValue(i, h[i]);
            }

            c.WriteConfig();
            p = LoadOpts();
            this.DialogResult = DialogResult.OK;
        }
Exemple #4
0
        internal static WorkBookParams LoadOpts()
        {
            ConfigManipulator c = new ConfigManipulator();
            WorkBookParams    a = new WorkBookParams();


            a.WriteEmptyResultSetColumns = Convert.ToBoolean(c.GetValue("WriteEmptyResultColumnHeaders"));
            a.AutoRewriteOverpunch       = Convert.ToBoolean(c.GetValue("AutoRewriteOverpunch"));
            a.BackendMethod = Enum.GetValues(typeof(ExcelBackend))
                              .Cast <ExcelBackend>()
                              .Where(x => String.Equals(x.ToString(), c.GetValue("ExcelFileType"))).First();

            int res = 0;

            if (!Int32.TryParse(c.GetValue("MaxRowsPerSheet"), out res))
            {
                a.MaxRowsPerSheet = Convert.ToInt32(Resources.DefaultMaxRowsPerSheet);
            }
            else
            {
                a.MaxRowsPerSheet = Convert.ToInt32(c.GetValue("MaxRowsPerSheet"));
            }
            if (Int32.TryParse(c.GetValue("QueryTimeout"), out res))
            {
                a.QueryTimeout = Convert.ToInt32(c.GetValue("QueryTimeout"));
            }

            var p1 = c.GetDictionary("ResultNames", typeof(int), typeof(string));

            foreach (object o in p1.Keys)
            {
                a.ResultNames.Add(Convert.ToInt32(o)
                                  , p1[o].ToString());
            }

            var p2 = c.GetDictionary("ColumnsThatPreventNewWorksheets", typeof(string), typeof(string));

            string[] aa = null;
            if (p2.Values.Count > 0)
            {
                aa = new string[p2.Values.Count];
                a.DupeKeysToDelayStartingNewWorksheet = new string[aa.Length];
                for (int i = 0; i < aa.Length; i++)
                {
                    a.DupeKeysToDelayStartingNewWorksheet[i] = p2.Values.ElementAt(i).ToString();
                }
            }

            long res2 = 0;

            if (long.TryParse(c.GetValue("MaximumWorkbookSizeInBytes"), out res2))
            {
                a.MaxWorkBookSize = res2;
            }

            int res3 = 0;

            if (Int32.TryParse(c.GetValue("MaximumResultSetsPerWorkbook"), out res3))
            {
                a.MaximumResultSetsPerWorkbook = res3;
            }

            return(a);
        }
Exemple #5
0
        public FormEntrance()
        {
            InitializeComponent();

            saveFileDialog1.Filter = Resources.SaveDialogFilter;
            this.Text = Resources.Version;

            toolStripStatusLabel2.Text = Resources.Waiting;

            toolTip1.SetToolTip(label3, Resources.TooltipInitialFilename);
            toolTip1.AutoPopDelay = Settings1.Default.toolTipDelayBeforeFade;
            toolTip1.SetToolTip(textBox1, Resources.TooltipInitialFilename);

            ConfigManipulator c = new ConfigManipulator();

            try
            {
                p = FormOptions.LoadOpts();
            }
            catch (Exception e)
            {
                if (e is Exceptions.ConfigFileBroken || e is ArgumentNullException || e is ArgumentException || e is InvalidOperationException)
                {
                    MessageBox.Show(e.Message);
                    if (e is Exceptions.ConfigFileBroken)
                    {
                        if (e.Data.Contains("key"))
                        {
                            toolStripStatusLabel2.Text = Resources.AppconfigBroken + " Missing key: " + (string)e.Data["key"];
                        }
                        else
                        {
                            toolStripStatusLabel2.Text = Resources.AppconfigBroken;
                        }
                    }
                    LockUnlockGUIControls(true);
                }
                else
                {
                    MessageBox.Show(e.Message);
                    throw;
                }
            }

            string debugFilePath = Application.ExecutablePath;

            debugFilePath     = Path.GetDirectoryName(debugFilePath);
            userFileName.Text = debugFilePath + Path.DirectorySeparatorChar.ToString();
            textBox1.Text     = "a.xlsx";
            fileName          = userFileName.Text + textBox1.Text;

#if DEBUG
            string path = Assembly.GetExecutingAssembly().Location;
            if (!string.IsNullOrEmpty(path))
            {
                path = Path.GetDirectoryName(path);
            }
            if (!string.IsNullOrEmpty(path))
            {
                path = Path.GetDirectoryName(path);
            }
            if (!string.IsNullOrEmpty(path))
            {
                path = Path.GetDirectoryName(path);
            }
            if (!string.IsNullOrEmpty(path))
            {
                path = Path.GetDirectoryName(path);
            }
            if (!string.IsNullOrEmpty(path))
            {
                path = path + Path.DirectorySeparatorChar.ToString()
                       + "ExcelXmlWriterNTest" + Path.DirectorySeparatorChar.ToString()
                       + "Resources" + Path.DirectorySeparatorChar.ToString()
                       + "Sql exceeds filesize limit.sql";
            }
            if (File.Exists(path))
            {
                FileStream   fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader sr = new StreamReader(fs);
                richTextBox1.Text = sr.ReadToEnd();
                sr.Close();
                fs.Close();
            }
#endif
        }