private void licenseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try {
         using (var sform = new LicenseForm(this)) {
             var result = sform.ShowDialog();
             if (result == DialogResult.OK)
             {
             }
         }
     } catch (Exception err) {
         errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
     }
 }
Exemple #2
0
        private void runToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try {
                run = true;
                runToolStripMenuItem.Enabled  = false;
                killToolStripMenuItem.Enabled = true;
                if (LicenseInformation.Contains("Move") == false)
                {
                    try {
                        using (var sform = new LicenseForm(parent)) {
                            var result = sform.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                            }
                        }
                    } catch (Exception err) {
                        parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                    }
                }
                utcStart = DateTime.UtcNow;
                string query  = "";
                string queryV = "";
                moveHistoryBox.Text  = "";
                moveResultBox.Text   = "";
                moveProgress.Minimum = 0;
                records_moved        = 0;
                rps = 0;
                statusTimer.Enabled = true;
                if (LDS.row_count > 0)
                {
                    moveProgress.Maximum = LDS.row_count;
                }
                else
                {
                    moveProgress.Maximum = LDS.result.Rows.Count;
                }
                recordsLbl.Text = LDS.result.Rows.Count.ToString() + " Records";
                if (truncateBox.Checked == true)
                {
                    RDS.executeSql("TRUNCATE `" + RDS.table + "`;");
                }
                query += "INSERT ";
                if (ignoreCheck.Checked == true)
                {
                    query += "IGNORE ";
                }
                query += "INTO `" + RDS.table + "` (";
                foreach (DataGridViewRow col in moveMapGrid.Rows)
                {
                    if (col.Cells[2].Value != null)
                    {
                        if (col.Cells[2].Value.ToString() != "(skip column)")
                        {
                            if (RDS.conectionString.Contains("csv") == true)
                            {
                                query += "\"" + col.Cells[2].Value.ToString() + "\",";
                            }
                            else
                            {
                                query += "`" + col.Cells[2].Value.ToString() + "`,";
                            }
                        }
                    }
                }
                query  = query.Substring(0, query.Length - 1);
                query += ") ";

                int pos = 0;
                foreach (DataRow row in LDS.result.Rows)
                {
                    string sqlStr;
                    queryV = "Values(";
                    int colpos = 0;
                    foreach (DataGridViewRow col in moveMapGrid.Rows)
                    {
                        if (col.Cells[2].Value != null)
                        {
                            if (col.Cells[2].Value.ToString() != "(skip column)")
                            {
                                queryV += "'" + row.ItemArray[colpos].ToString() + "',";
                            }
                        }
                        colpos++;
                    }

                    queryV             = queryV.Substring(0, queryV.Length - 1);
                    queryV            += ");";
                    sqlStr             = query + queryV;
                    moveResultBox.Text = sqlStr + "\n";

                    if (RDS.executeSql(sqlStr))
                    {
                        records_moved++;
                        moveResultBox.Text = "Date: " + RDS.utcStart.ToString("yyyy-MM-dd HH':'mm':'ss") + " - " +
                                             "Result: " + RDS.row_count.ToString() + " Records\n" +
                                             "Query: '" + RDS.sql.ToString() + "'\n";
                        if (historyCheck.Checked == true)
                        {
                            moveHistoryBox.Text = "Date: " + RDS.utcStart.ToString("yyyy-MM-dd HH':'mm':'ss") + " - " +
                                                  "Result: " + RDS.row_count.ToString() + " Records\n" +
                                                  "Query: '" + RDS.sql.ToString() + "'\n" +
                                                  "\n" + moveHistoryBox.Text.ToString();
                        }
                    }
                    else
                    {
                        moveResultBox.Text = "Date: " + RDS.utcStart.ToString("yyyy-MM-dd HH':'mm':'ss") + " - " +
                                             "Error: " + RDS.error.ToString() + "\n" +
                                             "Query: '" + RDS.sql.ToString() + "'\n";
                        if (historyCheck.Checked == true)
                        {
                            moveHistoryBox.Text = "Date: " + RDS.utcStart.ToString("yyyy-MM-dd HH':'mm':'ss") + " - " +
                                                  "Error: " + RDS.error.ToString() + "\n" +
                                                  "Query: '" + RDS.sql.ToString() + "'\n" +
                                                  "\n" + moveHistoryBox.Text.ToString();
                        }
                        if (stopCheck.Checked == true)
                        {
                            run = false;
                        }
                    }
                    pos++;
                    moveProgress.Value = pos;
                    posLbl.Text        = records_moved.ToString();
                    moveProgress.Refresh();
                    Application.DoEvents();
                    if (run == false)
                    {
                        break;
                    }
                }
                run = false;
                runToolStripMenuItem.Enabled  = true;
                killToolStripMenuItem.Enabled = false;
                utcStop             = DateTime.UtcNow;
                statusTimer.Enabled = false;
            } catch (Exception err) {
                parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                run = false;
                runToolStripMenuItem.Enabled  = true;
                killToolStripMenuItem.Enabled = false;
            }
        }
        private void runToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try {
                run = true;
                runToolStripMenuItem.Enabled  = false;
                killToolStripMenuItem.Enabled = true;
                if (LicenseInformation.Contains("Chunk") == false)
                {
                    try {
                        using (var sform = new LicenseForm(parent)) {
                            var result = sform.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                            }
                        }
                    } catch (Exception err) {
                        parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                    }
                }
                utcStart = DateTime.UtcNow;
                ProgressForm pform = new ProgressForm(this, "Progress [Chunk]");
                pform.update(0, LDS.row_count, 0);
                pform.Show();

                string query  = selectSQL.Text.Replace("%limit%", "LIMIT " + chunk.Text.ToString() + "," + offset.Text.ToString());
                string queryv = insertupdateSQL.Text.ToString();
                int    pos    = 0;
                while (LDS.executeSql(query) && LDS.hasResult() == true && LDS.hasErrors() == false && run == true)
                {
                    DT = new DataTable();
                    DT.Clear();
                    chunkResultGrid.Columns.Clear();
                    chunkResultGrid.DataSource = null;
                    if (LDS.hasResult() == true)
                    {
                        //Needed to Copy for Cell Edit
                        DT = LDS.result.Copy();
                    }
                    else
                    {
                        run = false;
                    }
                    chunkResultGrid.DataSource = DT;
                    chunkResultGrid.Refresh();
                    foreach (DataRow row in LDS.result.Rows)
                    {
                        queryv = insertupdateSQL.Text.ToString();
                        foreach (DataColumn col in LDS.result.Columns)
                        {
                            if (queryv.ToLower().Contains("#" + col.Caption.ToString().ToLower() + "#"))
                            {
                                queryv = queryv.Replace("#" + col.Caption.ToString().ToLower() + "#", row[col.Ordinal].ToString());
                            }
                        }
                        pos++;
                        if (pos % 250 == 0)
                        {
                            offset.Text = pos.ToString();
                            pform.update(0, LDS.row_count, pos);
                            Application.DoEvents();
                        }
                        if (run == false)
                        {
                            break;
                        }
                    }
                }

                pform.Hide();
                pform.Dispose();
                run = false;
                runToolStripMenuItem.Enabled  = true;
                killToolStripMenuItem.Enabled = false;
                utcStop = DateTime.UtcNow;
            } catch (Exception err) {
                parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                run = false;
                runToolStripMenuItem.Enabled  = true;
                killToolStripMenuItem.Enabled = false;
            }
        }
        private void crossJoinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try {
                run = true;
                crossJoinToolStripMenuItem.Enabled = false;
                killToolStripMenuItem.Enabled      = true;
                if (LicenseInformation.Contains("CrossJoin") == false)
                {
                    try {
                        using (var sform = new LicenseForm(parent)) {
                            var result = sform.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                            }
                        }
                    } catch (Exception err) {
                        parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                    }
                }
                if (Directory.Exists(Path.GetTempPath() + "Queryit") == false)
                {
                    Directory.CreateDirectory(Path.GetTempPath() + "Queryit");
                }
                if (File.Exists(Path.GetTempPath() + "Queryit\\l.csv"))
                {
                    File.Delete(Path.GetTempPath() + "Queryit\\l.csv");
                }
                LDS.exportCSV(Path.GetTempPath() + "Queryit\\l.csv");

                if (File.Exists(Path.GetTempPath() + "Queryit\\r.csv"))
                {
                    File.Delete(Path.GetTempPath() + "Queryit\\r.csv");
                }
                RDS.exportCSV(Path.GetTempPath() + "Queryit\\r.csv");
                string conStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + Path.GetTempPath() + "Queryit;Extensions=asc,csv,tab,txt;";
                DT = new DataTable();
                DT.Clear();
                DS = new Datasource(conStr);
                string sqlQuery = "SELECT ";
                foreach (DataColumn lcol in LDS.result.Columns)
                {
                    sqlQuery += "l." + lcol.Caption.ToString() + " as source_" + lcol.Caption.ToString() + ",";
                }
                foreach (DataColumn rcol in RDS.result.Columns)
                {
                    sqlQuery += "r." + rcol.Caption.ToString() + " as destination_" + rcol.Caption.ToString() + ",";
                }
                sqlQuery  = sqlQuery.Substring(0, sqlQuery.Length - 1);
                sqlQuery += " FROM l.csv l LEFT JOIN r.csv r ON l." + SourceSelect.Items[0].ToString() + " = r." + DestinationSelect.Items[0].ToString() + ";";
                if (DS.executeSql(sqlQuery.ToString()))
                {
                    crossjoinView.Columns.Clear();
                    crossjoinView.DataSource = null;
                    crossjoinView.DataSource = DS.result;
                    crossjoinView.Refresh();
                }

                DS.disconnect();
                if (File.Exists(Path.GetTempPath() + "Queryit\\l.csv"))
                {
                    File.Delete(Path.GetTempPath() + "Queryit\\l.csv");
                }
                if (File.Exists(Path.GetTempPath() + "Queryit\\r.csv"))
                {
                    File.Delete(Path.GetTempPath() + "Queryit\\r.csv");
                }
                run = false;
                crossJoinToolStripMenuItem.Enabled = true;
                killToolStripMenuItem.Enabled      = false;
            } catch (Exception err) {
                parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                run = false;
                crossJoinToolStripMenuItem.Enabled = true;
                killToolStripMenuItem.Enabled      = false;
            }
        }
 public void compareRaw()
 {
     try {
         bool limit = false;
         compareToolStripMenuItem.Enabled = false;
         killToolStripMenuItem.Enabled    = true;
         Source      = LDS.result.Copy();
         Both        = LDS.result.Clone();
         Destination = RDS.result.Copy();
         if (LicenseInformation.Contains("Compare") == false)
         {
             limit = true;
         }
         DateTime     utcStart;
         DateTime     utcStop;
         ProgressForm pform = new ProgressForm(this, "Progress [Compare]");
         pform.update(0, Source.Rows.Count, 0);
         pform.Show();
         int loops = 0;
         sourceGrid.DataSource      = Source;
         bothGrid.DataSource        = Both;
         destinationGrid.DataSource = Destination;
         run = true;
         int  total   = Source.Rows.Count;
         bool match   = false;
         int  matches = 0;
         int  indexS  = 0;
         int  indexD  = 0;
         utcStart = DateTime.UtcNow;
         while (indexS < Source.Rows.Count && run == true)
         {
             indexD = 0;
             while (indexD < Destination.Rows.Count && run == true)
             {
                 if (Source.Rows[indexS].ItemArray.arrEquals(Destination.Rows[indexD].ItemArray))
                 {
                     Both.ImportRow(Source.Rows[indexS]);
                     Source.Rows[indexS].Delete();
                     Destination.Rows[indexD].Delete();
                     matches++;
                     match = true;
                     break;
                 }
                 indexD++;
             }
             if (match == false || indexD == Destination.Rows.Count)
             {
                 indexS++;
             }
             loops++;
             if (loops % 250 == 0)
             {
                 pform.update(0, Source.Rows.Count, indexS + matches);
                 Application.DoEvents();
             }
             if (limit == true && indexS + matches > 500)
             {
                 try {
                     using (var sform = new LicenseForm(parent)) {
                         var result = sform.ShowDialog();
                         if (result == DialogResult.OK)
                         {
                         }
                     }
                 } catch (Exception err) {
                     parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
                 }
                 break;
             }
         }
         utcStop = DateTime.UtcNow;
         pform.Hide();
         pform.Dispose();
         run = false;
         compareToolStripMenuItem.Enabled = true;
         killToolStripMenuItem.Enabled    = false;
         sourceGrid.Refresh();
         bothGrid.Refresh();
         destinationGrid.Refresh();
     } catch (Exception err) {
         parent.errorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, err);
         run = false;
         compareToolStripMenuItem.Enabled = true;
         killToolStripMenuItem.Enabled    = false;
     }
 }