Example #1
0
        private void BtnExport_Click(object sender, EventArgs e)
        {
            if (curForm == null)
            {
                return;
            }

            var table = tables[cbxExportData.SelectedIndex];

            curForm.Data = table;
            curForm.ExportWithColumnName = ExportWithColumnName;
            curForm.StartExport();

            curForm.DoWorkCorrectly = false;
            curForm.CancelWork      = false;

            WaitProgressForm wait = new WaitProgressForm(this, curForm.Export, EndExport)
            {
                WidthDialog = this.Size.Width - 10,
                Maximum     = table.Rows.Count,
                Value       = 0
            };

            wait.CancelWork += new EventHandler(Wait_CancelWork);
            wait.CancelImage = this.CancelImage;
            wait.Message     = "Configuration";
            wait.BeginOperation();
        }
Example #2
0
        internal protected override void Export(WaitProgressForm wait)
        {
            wait.Message = "Initalize";

            DoWorkCorrectly = true;
            StreamWriter streamWriter = null;
            FileStream   fs           = null;
            CsvExport    exporter     = new CsvExport(delimiter, Data, ExportWithColumnName);

            try
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                wait.Message = "Create CSV Format";

                fs           = new FileStream(fileName, FileMode.CreateNew);
                streamWriter = new StreamWriter(fs, System.Text.Encoding.UTF8);

                exporter.Progress += (s, e) =>
                {
                    wait.Value = e.CurrentIndex;
                    if (CancelWork)
                    {
                        exporter.CancelWork = true;
                    }
                };

                exporter.Convert(streamWriter);

                streamWriter.Flush();
                fs.Flush();
                streamWriter.Close();
                fs.Close();
            }
            catch
            {
                DoWorkCorrectly = false;
                if (fs != null)
                {
                    if (streamWriter != null)
                    {
                        streamWriter.Close();
                    }
                    fs.Close();
                }
            }
        }
Example #3
0
        private void btnWaitProgress_Click(object sender, EventArgs e)
        {
            WaitProgressForm wait = new WaitProgressForm(
                this, BeginWaitProgress, EndWaitProgress, true);

            wait.WidthDialog = this.Size.Width - 10;
            wait.Maximum     = 20;
            wait.Value       = 0;
            wait.CancelWork += new EventHandler(CancelWorkWaitProgress);
            wait.BeginOperation();
        }
Example #4
0
 private void BeginWaitProgress(WaitProgressForm wait)
 {
     cancelWaitProgress = false;
     wait.Message       = "Initalize";
     for (int i = 0; i < 20 && !cancelWaitProgress; i++)
     {
         if (i == 5)
         {
             wait.Message = "i >= 5";
         }
         wait.Value = i;
         Thread.Sleep(200);
     }
     cancelWaitProgress = true;
 }
Example #5
0
        protected override void Export(WaitProgressForm wait)
        {
            wait.Message = "Initalize";

            DoWorkCorrectly = true;
            FileStream     stream = null;
            XlsExportBIFF2 writer = null;

            try
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                wait.Message = "Open file";
                stream       = new FileStream(fileName, FileMode.OpenOrCreate);
                writer       = new XlsExportBIFF2(stream, Codepage);

                wait.Message = "Move data";
                writer.WriteBegin();

                int row = 0;
                if (ExportWithColumnName)
                {
                    for (int j = 0; j < Data.Columns.Count; j++)
                    {
                        writer.WriteCell(row, j, Data.Columns[j].ColumnName);
                    }
                    row++;
                }

                for (int i = 0; i < Data.Rows.Count; i++)
                {
                    wait.Value = i;
                    if (CancelWork)
                    {
                        throw new Exception("Cancel!");
                    }
                    for (int j = 0; j < Data.Columns.Count; j++)
                    {
                        object o = Data.Rows[i].ItemArray[j];
                        if (o == null)
                        {
                            o = string.Empty;
                        }
                        writer.WriteCell(row, j, o.ToString());
                    }
                    row++;
                }

                wait.Message = "Close file";

                writer.WriteEnd();
                stream.Close();

                if (bOpenAfterCreate)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(fileName);
                    }
                    catch (Exception exc)
                    {
                        throw new Exception("Can not open '" + fileName + "'!", exc);
                    }
                }
            }
            catch
            {
                DoWorkCorrectly = false;
                if (stream != null)
                {
                    if (writer != null)
                    {
                        writer.WriteEnd();
                    }
                    stream.Close();
                }
            }
        }
        }                                                   //use in current thread

        internal protected virtual void Export(WaitProgressForm wait)
        {
        }                                                                   //use in multi-thread