Linq to sql
Publicado por jose antonio (3 intervenciones) el 15/10/2010 18:15:38
esta es la clase para hacer el arry, pero la modifique por que no me deja usar el arrylist asi que utilizo el list<array>, lo que quiero hacer es crear un array para utilizarlo el el prosedimiento de abajo.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
namespace EJECUTIVORT.CONTROLDA
{
class leetablagenerica
{
public static List<Array> leertablag(string sql)
{
string sConn = "Data Source=tony-pc\\SQLEXPRESS;Initial Catalog=Control25MW;User ID=ROOT;Password=***********;Trusted_Connection=True ";
conexionDataContext context = new conexionDataContext(sConn);
var generica = context.GetTable<TAGS>();
var datos = from d in generica
select d;
return datos.ToArray(); //Aqui me marca error, no me deja regresar los datos como arry
}
}
}
Aqui esta el procedimiento donde quiero llamar el resultado de la clase para hacer el procedimiento
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
public static class TRA
{
public static void XTMODELO()
{
ACT.proceso();
}
class ACT
{
static int[] AO;
static int[] VARMODI;
static int[] VARMODII;
static int[] VARMODE;
static int[] VARMODD;
static int[] VARMODP;
static float[] P1;
static float[] P2;
static string[] P3;
static float[] P4;
static float[] P5;
static float[] P6;
static int[] FA;
static int[] FC;
static int[] FO;
static EJECUTIVORT.bdsim BD;
static int LONP = 0;
static float EPSILO = (float)0.001;
static int diraire = 0;
public static void configura(EJECUTIVORT.bdsim BDa, string path)
{
char[] c = { ',' };
BD = BDa;
string sConn = "Data Source=tony-pc;Initial Catalog=Control25MW;User ID=ROOT;Password=*************;Trusted_Connection=True ";
Array info ="";// aki debo asignar el resultado del array a la variable info para poder hacer el procedimiento de abajo, enteriomente estaba trabajando con una conexion con acces pero la tengo que pasar a linq.
int len = info.Count;
AO = new int[len];
VARMODI = new int[len];
VARMODII = new int[len];
VARMODE = new int[len];
VARMODD = new int[len];
VARMODP = new int[len];
FA = new int[len];
FC = new int[len];
FO = new int[len];
P1 = new float[len];
P2 = new float[len];
P4 = new float[len];
P5 = new float[len];
P6 = new float[len];
P3 = new string[len];
int j = 0;
for (int i = 0; i < info.Count; i++)
{
object[] o = (object[])info[i];
int dirAO = V.GetDireccion((string)o[1]); // APERTURA
if (dirAO > -1)
{
string[] var = ((string)o[8]).Split(c);
int diri = BD.bdIndiceVariable(var[0]);
int dirii = BD.bdIndiceVariable(var[1]);
int dire = BD.bdIndiceVariable(var[5]);
int dird = BD.bdIndiceVariable(var[6]);
int dirfa = BD.bdIndiceVariable(var[7]);
int dirfc = BD.bdIndiceVariable(var[8]);
int dirfo = BD.bdIndiceVariable(var[9]);
int DIRPRO = BD.bdIndiceVariable((string)o[9]);
if (DIRPRO > -1 && diri > -1 && dirii > -1 && dire > -1 && dird > -1 && dirfa > -1 && dirfc > -1 && dirfo > -1)
{
AO[j] = dirAO;
VARMODI[j] = diri;
VARMODII[j] = dirii;
VARMODE[j] = dire;
VARMODD[j] = dird;
VARMODP[j] = DIRPRO;
FA[j] = dirfa;
FC[j] = dirfc;
FO[j] = dirfo;
P1[j] = Convert.ToSingle((string)o[2]);
P2[j] = Convert.ToSingle((string)o[3]);
P4[j] = Convert.ToSingle((string)o[5]);
P5[j] = Convert.ToSingle((string)o[6]);
P6[j] = Convert.ToSingle((string)o[7]);
if (EJECUTIVORT.ProCmd.S.vaddr.simulador == EJECUTIVORT.ProCmd.S.vaddr.SIM25MW)
diraire = BD.bdIndiceVariable("AIPATQ2A");
else
diraire = BD.bdIndiceVariable("AMPAAIIA");
j++;
}
}
}
LONP = j;
manbdtControl.CierraBaseControl();
}
public static void proceso()
{
for (int i = 0; i < LONP; i++)
{
if (BD.vaddr.ObtieneValorBool(FA[i]))
{ // TIENE FALLA ATORADA
BD.vaddr.AsignaValorFloat(VARMODD[i], 0.0f);
continue;
}
if (BD.vaddr.ObtieneValorBool(FC[i])) // TIENE FALLA CLOSE
{
BD.vaddr.AsignaValorFloat(VARMODD[i], -0.4555f);
continue;
}
else if (BD.vaddr.ObtieneValorBool(FO[i])) // TIENE FALLA OPEN
{
BD.vaddr.AsignaValorFloat(VARMODD[i], 0.4555f);
continue;
}
float XOUT;
if ((BD.vaddr.ObtieneValorFloat(diraire) < P4[i]) || !BD.vaddr.ObtieneValorBool(VARMODP[i])) // PARA SIM25MW: AIPATQ2A 14mayo2008 FALTA UNIFICAR
{
if (P3[i] == "1")
XOUT = 1;
else
XOUT = 0;
}
else
XOUT = V.GetValorAnalogico(AO[i]) * P1[i] + P2[i];
float e;
float E = e = BD.vaddr.ObtieneValorFloat(VARMODE[i]);
e = Math.Min(1, Math.Max(0, e));
float XDEL = XOUT - e;
float d = 0;
if (Math.Abs(XDEL) < EPSILO)
e = XOUT;
else
{
d = XDEL / P5[i];
if (d > P6[i])
d = P6[i];
else if (d < -P6[i])
d = -P6[i];
}
BD.vaddr.AsignaValorFloat(VARMODD[i], d);
if (E != e)
BD.vaddr.AsignaValorFloat(VARMODE[i], e);
BD.vaddr.AsignaValorFloat(VARMODI[i], e);
BD.vaddr.AsignaValorFloat(VARMODII[i], e);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
namespace EJECUTIVORT.CONTROLDA
{
class leetablagenerica
{
public static List<Array> leertablag(string sql)
{
string sConn = "Data Source=tony-pc\\SQLEXPRESS;Initial Catalog=Control25MW;User ID=ROOT;Password=***********;Trusted_Connection=True ";
conexionDataContext context = new conexionDataContext(sConn);
var generica = context.GetTable<TAGS>();
var datos = from d in generica
select d;
return datos.ToArray(); //Aqui me marca error, no me deja regresar los datos como arry
}
}
}
Aqui esta el procedimiento donde quiero llamar el resultado de la clase para hacer el procedimiento
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
public static class TRA
{
public static void XTMODELO()
{
ACT.proceso();
}
class ACT
{
static int[] AO;
static int[] VARMODI;
static int[] VARMODII;
static int[] VARMODE;
static int[] VARMODD;
static int[] VARMODP;
static float[] P1;
static float[] P2;
static string[] P3;
static float[] P4;
static float[] P5;
static float[] P6;
static int[] FA;
static int[] FC;
static int[] FO;
static EJECUTIVORT.bdsim BD;
static int LONP = 0;
static float EPSILO = (float)0.001;
static int diraire = 0;
public static void configura(EJECUTIVORT.bdsim BDa, string path)
{
char[] c = { ',' };
BD = BDa;
string sConn = "Data Source=tony-pc;Initial Catalog=Control25MW;User ID=ROOT;Password=*************;Trusted_Connection=True ";
Array info ="";// aki debo asignar el resultado del array a la variable info para poder hacer el procedimiento de abajo, enteriomente estaba trabajando con una conexion con acces pero la tengo que pasar a linq.
int len = info.Count;
AO = new int[len];
VARMODI = new int[len];
VARMODII = new int[len];
VARMODE = new int[len];
VARMODD = new int[len];
VARMODP = new int[len];
FA = new int[len];
FC = new int[len];
FO = new int[len];
P1 = new float[len];
P2 = new float[len];
P4 = new float[len];
P5 = new float[len];
P6 = new float[len];
P3 = new string[len];
int j = 0;
for (int i = 0; i < info.Count; i++)
{
object[] o = (object[])info[i];
int dirAO = V.GetDireccion((string)o[1]); // APERTURA
if (dirAO > -1)
{
string[] var = ((string)o[8]).Split(c);
int diri = BD.bdIndiceVariable(var[0]);
int dirii = BD.bdIndiceVariable(var[1]);
int dire = BD.bdIndiceVariable(var[5]);
int dird = BD.bdIndiceVariable(var[6]);
int dirfa = BD.bdIndiceVariable(var[7]);
int dirfc = BD.bdIndiceVariable(var[8]);
int dirfo = BD.bdIndiceVariable(var[9]);
int DIRPRO = BD.bdIndiceVariable((string)o[9]);
if (DIRPRO > -1 && diri > -1 && dirii > -1 && dire > -1 && dird > -1 && dirfa > -1 && dirfc > -1 && dirfo > -1)
{
AO[j] = dirAO;
VARMODI[j] = diri;
VARMODII[j] = dirii;
VARMODE[j] = dire;
VARMODD[j] = dird;
VARMODP[j] = DIRPRO;
FA[j] = dirfa;
FC[j] = dirfc;
FO[j] = dirfo;
P1[j] = Convert.ToSingle((string)o[2]);
P2[j] = Convert.ToSingle((string)o[3]);
P4[j] = Convert.ToSingle((string)o[5]);
P5[j] = Convert.ToSingle((string)o[6]);
P6[j] = Convert.ToSingle((string)o[7]);
if (EJECUTIVORT.ProCmd.S.vaddr.simulador == EJECUTIVORT.ProCmd.S.vaddr.SIM25MW)
diraire = BD.bdIndiceVariable("AIPATQ2A");
else
diraire = BD.bdIndiceVariable("AMPAAIIA");
j++;
}
}
}
LONP = j;
manbdtControl.CierraBaseControl();
}
public static void proceso()
{
for (int i = 0; i < LONP; i++)
{
if (BD.vaddr.ObtieneValorBool(FA[i]))
{ // TIENE FALLA ATORADA
BD.vaddr.AsignaValorFloat(VARMODD[i], 0.0f);
continue;
}
if (BD.vaddr.ObtieneValorBool(FC[i])) // TIENE FALLA CLOSE
{
BD.vaddr.AsignaValorFloat(VARMODD[i], -0.4555f);
continue;
}
else if (BD.vaddr.ObtieneValorBool(FO[i])) // TIENE FALLA OPEN
{
BD.vaddr.AsignaValorFloat(VARMODD[i], 0.4555f);
continue;
}
float XOUT;
if ((BD.vaddr.ObtieneValorFloat(diraire) < P4[i]) || !BD.vaddr.ObtieneValorBool(VARMODP[i])) // PARA SIM25MW: AIPATQ2A 14mayo2008 FALTA UNIFICAR
{
if (P3[i] == "1")
XOUT = 1;
else
XOUT = 0;
}
else
XOUT = V.GetValorAnalogico(AO[i]) * P1[i] + P2[i];
float e;
float E = e = BD.vaddr.ObtieneValorFloat(VARMODE[i]);
e = Math.Min(1, Math.Max(0, e));
float XDEL = XOUT - e;
float d = 0;
if (Math.Abs(XDEL) < EPSILO)
e = XOUT;
else
{
d = XDEL / P5[i];
if (d > P6[i])
d = P6[i];
else if (d < -P6[i])
d = -P6[i];
}
BD.vaddr.AsignaValorFloat(VARMODD[i], d);
if (E != e)
BD.vaddr.AsignaValorFloat(VARMODE[i], e);
BD.vaddr.AsignaValorFloat(VARMODI[i], e);
BD.vaddr.AsignaValorFloat(VARMODII[i], e);
}
}
}
Valora esta pregunta


0