Exemple #1
0
        public AlugueresDataSet()
            : base("xmlType")
        {
            aluguerTable   = new AluguerTable();
            alugueresTable = new AlugueresTable();
            this.Tables.Add(aluguerTable);
            this.Tables.Add(alugueresTable);

            this.ReadXmlSchema("AlugueresSchema.xsd");
        }
Exemple #2
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);
            }
        }