1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DGVPrinterHelper;
using System.Threading;
namespace MapScopeNG
{
public partial class frmDist : Form
{
DataTable dtAdr = null;
bool Started = false;
public frmDist(DataTable dt)
{
dtAdr = dt;
InitializeComponent();
}
public void ShowMatrix()
{
this.Show();
DistMatrix dm = new DistMatrix();
dm.AddRow += new DistMatrix.StepRowDelegateHandler(Dist_StepRow);
dm.AddCell += new DistMatrix.StepCellDelegateHandler(Dist_StepCell);
ThreadPool.QueueUserWorkItem(new WaitCallback(Process),dm);
}
void Process(Object rien)
{
DistMatrix dm = (DistMatrix)rien;
DataTable dtn = dm.getMatrix(dtAdr);
btn_print.Visible = true;
}
// *****************************************************************************************
public delegate void StepCellDelegateHandler(int a, int b);
private void Dist_StepCell(int a, int b)
{
if (this.InvokeRequired)
{
try
{
this.Invoke(new StepCellDelegateHandler(StepCell), new object[] { a, b });
return;
}
catch (Exception)
{
}
}
else
{
this.StepCell(a, b);
}
}
// *****************************************************************************************
private void StepCell(int X,int Y)
{
lbl_Progress.Text = string.Format("{0}-{1} / {2}", Y, X,dtAdr.Rows.Count);
}
// *****************************************************************************************
public delegate void StepRowDelegateHandler(DataTable dt);
private void Dist_StepRow(DataTable dt)
{
if (this.InvokeRequired)
{
try
{
this.Invoke(new StepRowDelegateHandler(AddRow), new object[] { dt });
return;
}
catch (Exception)
{
}
}
else
{
this.AddRow(dt);
}
}
// *****************************************************************************************
private void AddRow(DataTable Dt)
{
if (dgv_Dist.DataSource == null)
{
dgv_Dist.DataSource = Dt;
foreach (DataGridViewColumn dgvc in dgv_Dist.Columns)
{
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Format = "N2";
style.Alignment = DataGridViewContentAlignment.MiddleRight;
dgvc.DefaultCellStyle = style;
}
}
dgv_Dist.Refresh();
}
}
} |