private byte[] GetDataFromGridView(bool upsidedown)
{
byte[] retval = new byte[m_map_length];
DataTable gdt = (DataTable)gridControl1.DataSource;
int cellcount = 0;
if (upsidedown)
{
for (int t = gdt.Rows.Count - 1; t >= 0; t -- )
{
foreach (object o in gdt.Rows[t].ItemArray)
{
if (o != null)
{
if (o != DBNull.Value)
{
if (cellcount < retval.Length)
{
if (m_issixteenbit)
{
// twee waarde toevoegen
Int32 cellvalue = 0;
string bstr1 = "0";
string bstr2 = "0";
//if (m_isHexMode)
if (m_viewtype == ViewType.Hexadecimal)
{
cellvalue = Convert.ToInt32(o.ToString(), 16);
}
else
{
cellvalue = Convert.ToInt32(o.ToString());
}
/*if (cellvalue < 0)
{
Console.WriteLine("value < 0");
}*/
bstr1 = cellvalue.ToString("X8").Substring(4, 2);
bstr2 = cellvalue.ToString("X8").Substring(6, 2);
retval.SetValue(Convert.ToByte(bstr1, 16), cellcount++);
retval.SetValue(Convert.ToByte(bstr2, 16), cellcount++);
}
else
{
//if (m_isHexMode)
if (m_viewtype == ViewType.Hexadecimal)
{
//double v = Convert.ToDouble(o);
int iv = Convert.ToInt32(o.ToString(), 16);//(int)Math.Floor(v);
retval.SetValue(Convert.ToByte(iv), cellcount++);
}
else
{
double v = Convert.ToDouble(o);
retval.SetValue(Convert.ToByte((int)Math.Floor(v)), cellcount++);
}
}
}
}
}
}
}
}
else
{
foreach (DataRow dr in gdt.Rows)
{
foreach (object o in dr.ItemArray)
{
if (o != null)
{
if (o != DBNull.Value)
{
if (cellcount < retval.Length)
{
if (m_issixteenbit)
{
// twee waarde toevoegen
Int32 cellvalue = 0;
string bstr1 = "0";
string bstr2 = "0";
//if (m_isHexMode)
if (m_viewtype == ViewType.Hexadecimal)
{
cellvalue = Convert.ToInt32(o.ToString(), 16);
}
else
{
cellvalue = Convert.ToInt32(o.ToString());
}
bstr1 = cellvalue.ToString("X8").Substring(4, 2);
bstr2 = cellvalue.ToString("X8").Substring(6, 2);
retval.SetValue(Convert.ToByte(bstr1, 16), cellcount++);
retval.SetValue(Convert.ToByte(bstr2, 16), cellcount++);
/* bstr1 = cellvalue.ToString("X4").Substring(0, 2);
bstr2 = cellvalue.ToString("X4").Substring(2, 2);
retval.SetValue(Convert.ToByte(bstr1, 16), cellcount++);
retval.SetValue(Convert.ToByte(bstr2, 16), cellcount++);*/
}
else
{
// if (m_isHexMode)
if (m_viewtype == ViewType.Hexadecimal)
{
//double v = Convert.ToDouble(o);
try
{
int iv = Convert.ToInt32(o.ToString(), 16);
//int iv = (int)Math.Floor(v);
retval.SetValue(Convert.ToByte(iv.ToString()), cellcount++);
}
catch (Exception cE)
{
Console.WriteLine(cE.Message);
}
}
else
{
try
{
double v = Convert.ToDouble(o);
if (v >= 0)
{
retval.SetValue(Convert.ToByte((int)Math.Floor(v)), cellcount++);
}
}
catch (Exception sE)
{
Console.WriteLine(sE.Message);
}
}
}
}
}
}
}
}
}
return retval;
}