コード例 #1
0
        protected DataTable PrepareOperation(OleDbConnection connection, MethodArgs args)
        {
            var cmd     = new OleDbCommand(String.Format("SELECT TOP {0} ED_ENC_NUM FROM Documents", args.MaxRowsToUpdate), connection);
            var adapter = new OleDbDataAdapter(cmd);

            var table = new DataTable();

            adapter.Fill(table);

            args.MaxRowsToUpdate = args.MaxRowsToUpdate < table.Rows.Count ? args.MaxRowsToUpdate : table.Rows.Count;

            return(table);
        }
コード例 #2
0
        protected bool ReportProgress(MethodArgs args, BackgroundWorker worker)
        {
            if (worker.CancellationPending)
            {
                return(false);
            }

            ///////////////////////////////////////////////////////////////////////////////

            var progressPercentage = (int)((double)args.TotalRowsUpdated / args.MaxRowsToUpdate * 100d);

            worker.ReportProgress(progressPercentage);

            return(true);
        }
コード例 #3
0
        protected void RunMethod(UpdateMethod method)
        {
            var args = new MethodArgs
            {
                Method          = method,
                MaxRowsToUpdate = Convert.ToInt64(txtMaxRowsToUpdate.Value),
                PrepareCommand  = chkbPrepareCommand.Checked
            };

            ///////////////////////////////////////////////////////////////////////////////

            var progressForm = new FormGenericProgress(method.ToString(), PerformOperation, args, true);

            progressForm.ShowDialog();

            ///////////////////////////////////////////////////////////////////////////////

            ShowResults(args);
        }
コード例 #4
0
        protected void RunMethod_StoredProcedure(OleDbConnection connection, DataTable table, MethodArgs args, BackgroundWorker worker)
        {
            var query = "UpdateDocument";

            var cmd = new OleDbCommand(query, connection);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("ScoreVal", 0).DbType = DbType.Int32;
            cmd.Parameters.AddWithValue("IdVal", 0).DbType    = DbType.Double;

            if (args.PrepareCommand)
            {
                cmd.Prepare();
            }

            ///////////////////////////////////////////////////////////////////////////////

            foreach (var row in table.Rows.Cast <DataRow>())
            {
                var id = (double)row.ItemArray[0];

                cmd.Parameters[0].Value = Convert.ToInt32(id);
                cmd.Parameters[1].Value = id;

                ///////////////////////////////////////////////////////////////////////////////

                var rowsUpdated = cmd.ExecuteNonQuery();
                if (rowsUpdated != 1)
                {
                    throw new Exception();
                }

                ///////////////////////////////////////////////////////////////////////////////

                args.TotalRowsUpdated++;
                if (args.TotalRowsUpdated >= args.MaxRowsToUpdate)
                {
                    break;
                }

                if (args.TotalRowsUpdated % 50 == 0)
                {
                    if (!ReportProgress(args, worker))
                    {
                        break;
                    }
                }
            }
        }
コード例 #5
0
        protected void ShowResults(MethodArgs args)
        {
            var elapsedPerRecord = args.TotalElapsed.TotalMilliseconds / args.TotalRowsUpdated;

            gridResults.Rows.Add(args.Method.ToString(), args.TotalRowsUpdated.ToString(""), args.TotalElapsed.ToString(@"mm\:ss\.ff"), elapsedPerRecord.ToString("F3") + " ms");
        }