示例#1
0
 private void runToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try {
         run = true;
         runToolStripMenuItem.Enabled  = false;
         killToolStripMenuItem.Enabled = true;
         utcStart = DateTime.UtcNow;
         int           exported = 0;
         int           chunk    = 1000;
         int           offset   = 0;
         bool          header   = true;
         StringBuilder sb       = new StringBuilder();
         if (File.Exists(exportFile.Text.ToString()))
         {
             File.Delete(exportFile.Text.ToString());
         }
         ProgressForm pform = new ProgressForm(this, "Progress [Export - " + table + "]");
         pform.update(0, chunk, 0);
         pform.Show();
         while (DS.executeSql("SELECT * FROM `" + table + "` LIMIT " + offset + "," + chunk) && run == true)
         {
             Application.DoEvents();
             if (DS.hasResult() == false)
             {
                 run = false;
             }
             if (DS.hasErrors() == true)
             {
                 run = false;
             }
             if (header == true)
             {
                 string line = "";
                 foreach (DataGridViewRow col in fileGrid.Rows)
                 {
                     if (col.Cells[0].Value != null)
                     {
                         if (col.Cells[0].Value.ToString() != "(skip column)")
                         {
                             line += col.Cells[0].Value.ToString() + ",";
                         }
                     }
                 }
                 line = line.Substring(0, line.Length - 1);
                 sb.Append(line + "\r\n");
                 //IEnumerable<string> columnNames = DS.result.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
                 //sb.AppendLine(string.Join(",", columnNames));
                 header = false;
             }
             if (DS.row_count > 0)
             {
                 foreach (DataRow row in DS.result.Rows)
                 {
                     string line = "";
                     foreach (DataGridViewRow col in fileGrid.Rows)
                     {
                         if (col.Cells[0].Value != null)
                         {
                             if (col.Cells[0].Value.ToString() != "(skip column)")
                             {
                                 line += row[col.Cells[0].Value.ToString()].ToString() + ",";
                             }
                         }
                     }
                     line = line.Substring(0, line.Length - 1);
                     sb.Append(line + "\r\n");
                     //IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
                     //sb.AppendLine(string.Join(",", fields));
                     exported++;
                     offset++;
                 }
                 pform.update(0, offset, exported);
                 Application.DoEvents();
                 File.AppendAllText(exportFile.Text.ToString(), sb.ToString());
             }
             else
             {
                 run = false;
             }
         }
         pform.Hide();
         pform.Dispose();
         run = false;
         runToolStripMenuItem.Enabled  = true;
         killToolStripMenuItem.Enabled = false;
         utcStop = DateTime.UtcNow;
         this.Close();
     } catch (Exception err) {
         run = false;
         runToolStripMenuItem.Enabled  = true;
         killToolStripMenuItem.Enabled = false;
         throw err;
     }
 }
示例#2
0
        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;
            }
        }
示例#3
0
 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;
     }
 }