Exemplo n.º 1
0
        public string ExportarXml(string inicio, string fim)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(xmlType), "xml");
            xmlType       xml        = new xmlType();

            xml.alugueres            = new alugueresType();
            xml.alugueres.dataInicio = inicio;
            xml.alugueres.dataFim    = fim;

            using (SqlCommand cmd = con.CreateCommand())
            {
                AluguerTable   at = new AluguerTable();
                SqlDataAdapter adapterAluguer;
                SqlParameter   param_inicio = new SqlParameter("@inicio", SqlDbType.DateTime);
                SqlParameter   param_fim    = new SqlParameter("@fim", SqlDbType.DateTime);
                param_inicio.Value = inicio;
                param_fim.Value    = fim;

                cmd.Parameters.Add(param_inicio);
                cmd.Parameters.Add(param_fim);
                cmd.CommandText = "SELECT id, eq.tipo as tipo, equipamento, cliente " +
                                  "FROM AluguerView al INNER JOIN Equipamento eq ON (al.equipamento = eq.eqId) " +
                                  "WHERE dataInicio >= @inicio AND dataFim <= @fim";
                adapterAluguer = new SqlDataAdapter(cmd);
                adapterAluguer.Fill(at);
                xml.alugueres.aluguer = new aluguerType[at.Select().Length];

                int count = 0;
                foreach (DataRow row in at.Rows)
                {
                    xml.alugueres.aluguer[count]             = new aluguerType();
                    xml.alugueres.aluguer[count].cliente     = row["cliente"].ToString();
                    xml.alugueres.aluguer[count].equipamento = row["equipamento"].ToString();
                    xml.alugueres.aluguer[count].id          = row["id"].ToString();
                    xml.alugueres.aluguer[count].tipo        = row["tipo"].ToString();
                    count++;
                }
            }
            String path = Environment.CurrentDirectory + "\\ADOAlugueres" + inicio.Replace(":", "").Replace(" ", "") + "_" + fim.Replace(":", "").Replace(" ", "") + ".xml";

            using (FileStream file = File.Create(path))
            {
                serializer.Serialize(file, xml);
                return(path);
            }
        }
Exemplo n.º 2
0
        public string ExportarXml(string inicio, string fim)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(xmlType));
            xmlType       xml        = new xmlType();

            xml.alugueres            = new alugueresType();
            xml.alugueres.dataInicio = inicio;
            xml.alugueres.dataFim    = fim;

            DateTime fimDate    = DateTime.Parse(fim);
            DateTime inicioDate = DateTime.Parse(inicio);

            var alugueres = ctx.AluguerView.Join(ctx.Equipamento,
                                                 al => al.equipamento,
                                                 eq => eq.eqId,
                                                 (al, eq) => new { al.dataInicio, al.dataFim, al.cliente, al.empregado, al.equipamento, al.id, eq.tipo }
                                                 ).Where(
                (al) => (al.dataFim <= fimDate && al.dataInicio >= inicioDate)
                ).ToArray();


            xml.alugueres.aluguer = new aluguerType[alugueres.Length];
            int count = 0;

            foreach (var al in alugueres)
            {
                xml.alugueres.aluguer[count]             = new aluguerType();
                xml.alugueres.aluguer[count].cliente     = al.cliente.ToString();
                xml.alugueres.aluguer[count].equipamento = al.equipamento.ToString();
                xml.alugueres.aluguer[count].id          = al.id;
                xml.alugueres.aluguer[count].tipo        = al.tipo;

                count++;
            }
            String path = Environment.CurrentDirectory + "\\EFAlugueres" + inicio.Replace(":", "").Replace(" ", "") + "_" + fim.Replace(":", "").Replace(" ", "") + ".xml";

            using (FileStream file = File.Create(path))
            {
                serializer.Serialize(file, xml);
                return(path);
            }
        }