Exemplo n.º 1
0
        //public void ShowP()
        //{
        //	foreach (DataGridViewRow row in this.dataGridView1.Rows)
        //	{
        //		TableObject obj = row.DataBoundItem as TableObject;
        //		row.Cells[4].Value = obj.Perce;
        //		var parent = row.DataGridView;
        //		parent.CurrentCell = row.Cells[3];
        //		parent.UpdateCellValue(2, row.Index);

        //	}
        //}

        public void ShowProgress(object sender, ProgressChangedEventArgs e)
        {
            //BackgroundWorker worker = (BackgroundWorker)sender;

            if (e.UserState != null)
            {
                TableObject table = e.UserState as TableObject;
                //this.ShowProgress(table);
                table.ShowProgress();
            }
        }
Exemplo n.º 2
0
        //public void ShowProgress(TableObject table)
        //{
        //	var Row = table.Row;
        //	//table.ShowProgress();

        //	//DataGridViewRow row = e.UserState as DataGridViewRow;

        //	//if (row != null)
        //	//{
        //	//   // this.dataGridView1.FirstDisplayedScrollingRowIndex = row.Index;
        //	//	//this.dataGridView1.Refresh();
        //	//	this.dataGridView1.CurrentCell = row.Cells[3];
        //	//	this.dataGridView1.UpdateCellValue(2, row.Index);
        //	//}
        //	if (Row != null)
        //	{
        //		//int i = (int) Math.Round((decimal) this.Copied / this.Count, 0) * 100;
        //		//Row.Cells[4].Value = e.ProgressPercentage;
        //		Row.Cells[4].Value = table.Percentage;
        //		var parent = Row.DataGridView;
        //		parent.CurrentCell = Row.Cells[3];
        //		parent.UpdateCellValue(2, Row.Index);
        //	}
        //}


        public async void CopyTablesAsync(CopyObject settings)
        {
            CopyManager manager = new CopyManager(settings);

            //manager.OnRowsCopied +=manager_OnRowsCopied;

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    await Task.Run(() => manager.PreCopy());
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Pre SQL Error");
                return;
            }

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                TableObject obj = (TableObject)row.DataBoundItem;

                // prepare
                obj.Row = row;
                //obj.Worker = worker;
                //worker.ReportProgress(0, obj);

                //if (worker.CancellationPending)
                //{
                //	break;
                //}
                try
                {
                    if (obj.Selected)
                    {
                        await Task.Run(() => manager.Copy(obj));

                        //manager.Copy(obj);
                        //obj.Status = "Success";
                        obj.CopyStatus = CopyStatusEnum.Success;
                        //this.ShowProgress(obj);

                        //worker.ReportProgress(0, row);
                        //worker.ReportProgress(100, obj);
                        //obj.ShowProgress();
                    }
                    else
                    {
                        obj.CopyStatus = CopyStatusEnum.Skipped;
                    }
                    obj.ShowProgress();
                }
                catch (Exception er)
                {
                    obj.CopyStatus = CopyStatusEnum.Error;
                    //obj.Status = er.Message;
                    obj.Message = er.Message;
                    //this.ShowProgress(obj);
                    obj.ShowProgress();
                    //worker.ReportProgress(0, er);
                    //worker.ReportProgress(0, row);
                    //worker.ReportProgress(0, obj);
                    //obj.ShowProgress();
                }
                finally
                {
                }
            }

            //foreach (TableObject obj in settings.Tables)
            //{
            //    if (worker.CancellationPending)
            //    {
            //        break;
            //    }
            //    try
            //    {
            //        if (obj.Selected)
            //        {
            //            manager.Copy(obj.Name);
            //            obj.Status = "Success";
            //            worker.ReportProgress(0);
            //        }
            //    }
            //    catch (Exception er)
            //    {
            //        obj.Status = er.Message;
            //        worker.ReportProgress(0, er);
            //    }
            //    finally
            //    {
            //    }
            //}

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    await Task.Run(() => manager.PostCopy());

                    //manager.PostCopy();
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Post SQL Error");
                return;
            }
        }