private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Convert.ToString(listDatabase.SelectedValue)))
            {
                MessageBox.Show(string.Format("Please Select Database Name"));
                return;
            }
            else if (string.IsNullOrEmpty(txtQuery.Text))
            {
                MessageBox.Show(string.Format("Please Enter Query"));
                return;
            }

            else
            {
                ConnectionString = ConnectionString + $"database={listDatabase.SelectedValue};";

                var cmLibrary        = new CommonLibrary.CommonLibrary();
                var validationresult = cmLibrary.ValidateQuery(txtQuery.Text);
                var validate         = cmLibrary.ValidateQueryMustContain(txtQuery.Text);
                if (string.IsNullOrEmpty(validationresult) && validate == false)
                {
                    if (backgroundWorker1.IsBusy)
                    {
                        MessageBox.Show(@"Please Wait ... Process is under Exceution");
                        return;
                    }
                    else
                    {
                        backgroundWorker1.RunWorkerAsync(txtQuery.Text);
                        backgroundWorker1.ReportProgress(10, "Process Started");
                    }
                }
                else
                {
                    MessageBox.Show(@"Please Enter Valid Query");
                }
            }
        }
Example #2
0
        private void BindDatabases()
        {
            // ReSharper disable once RedundantAssignment
            var dsDataTable = new DataTable();
            var cmLibrary   = new CommonLibrary.CommonLibrary();

            dsDataTable = cmLibrary.BindDatabases(ConnectionString);
            try
            {
                if (dsDataTable.Rows.Count <= 0)
                {
                    return;
                }
                listDatabase.DataSource    = dsDataTable;
                listDatabase.DisplayMember = "NAME";
                listDatabase.ValueMember   = "NAME";
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void ProcessMethod(string query)
        {
            backgroundWorker1.ReportProgress(20, "Pulling Records from Database");

            var dsTables = new DataTable();

            try
            {
                DataColumn column = new DataColumn
                {
                    DataType          = System.Type.GetType("System.Int32"),
                    AutoIncrement     = true,
                    AutoIncrementSeed = 1,
                    AutoIncrementStep = 1,
                    ColumnName        = "___Id"
                };

                dsTables.Columns.Add(column);

                using (var con = new MySqlConnection(ConnectionString))
                {
                    con.Open();
                    var cmd = new MySqlCommand(query, con)
                    {
                        CommandTimeout = 0
                    };
                    var daTab = new MySqlDataAdapter(cmd);
                    daTab.Fill(dsTables);
                    backgroundWorker1.ReportProgress(30, "Pulling Records from Database");
                }

                // ReSharper disable once InvertIf
                if (dsTables.Rows.Count > 0)
                {
                    var minRow = Convert.ToInt32(dsTables.Compute("min([___Id])", string.Empty));
                    var maxRow = Convert.ToInt32(dsTables.Compute("max([___Id])", string.Empty));

                    backgroundWorker1.ReportProgress(50, "Processing Data");
                    var cmLibrary = new CommonLibrary.CommonLibrary();
                    var loopCount = cmLibrary.Listgenerator(minRow, maxRow);

                    for (var j = 0; j < loopCount.Count; j++)
                    {
                        int value   = 50 + j;
                        int counter = 1;
                        counter = counter + j;
                        backgroundWorker1.ReportProgress(value, "Generating Files " + counter);

                        var fromtemp = loopCount[j].From;
                        var totemp   = loopCount[j].To;

                        IEnumerable <DataRow> myDataPage =
                            from myrow in dsTables.AsEnumerable()
                            where myrow.Field <int>("___Id") >= fromtemp && myrow.Field <int>("___Id") <= totemp
                            select myrow;

                        var newDt = myDataPage.CopyToDataTable();

                        var count = j;
                        GenerateSheet(newDt, count, "QueryGenerated", loopCount.Count);
                    }

                    backgroundWorker1.ReportProgress(100, "Process Completed");
                }
            }
            catch (Exception)
            {
                var message = "1. Choose Proper Database" + Environment.NewLine + "2. Optimize Query" +
                              Environment.NewLine + "3. " + "check Query Once";

                MessageBox.Show(@message);
            }
            finally
            {
                dsTables.Dispose();
            }
        }