public override global::System.Data.DataSet Clone()
        {
            dsData cln = ((dsData)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            dsData ds = new dsData();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                dsData ds = new dsData();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "CT_RezultatiDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }
        private void Query(int option, int departure)
        {
            ConnectionDB db           = new ConnectionDB();
            crEntry      crEntry      = new crEntry();
            crDeparture  crDeparture  = new crDeparture();
            crDeparture2 crDeparture2 = new crDeparture2();
            dsData       dsData       = new dsData();
            scrReports   scrReports   = new scrReports();

            int id_user = db.Users.Where(x => x.name == cbUser.Text).Select(x => x.Id).FirstOrDefault();

            switch (option)
            {
            case 1:
                #region ENTRADAS
                var EntryHeader = db.Entries.Join(db.Users, x => x.id_user, y => y.Id, (x, y) => new
                {
                    x.serie,
                    x.folio,
                    x.Id,
                    x.date,
                    x.id_user,
                    x.id_warehouse,
                    x.observation,
                    user_name = y.name
                }).Join(db.Warehouses, x => x.id_warehouse, y => y.id, (x, y) => new
                {
                    x.serie,
                    x.folio,
                    x.Id,
                    x.date,
                    x.id_user,
                    x.id_warehouse,
                    x.observation,
                    x.user_name,
                    warehouse_name = y.name
                }).Where(x =>
                         DbFunctions.TruncateTime(x.date) >= DbFunctions.TruncateTime(dtpF1.Value) &&
                         DbFunctions.TruncateTime(x.date) <= DbFunctions.TruncateTime(dtpF2.Value));
                if (cbUser.Text != "TODOS")
                {
                    EntryHeader = EntryHeader.Where(x => x.id_user == id_user);
                }

                foreach (var Entry in EntryHeader.ToList())
                {
                    dsData.dtHeaderEntry.AdddtHeaderEntryRow(Entry.serie, Entry.folio.ToString(), Entry.date.ToString("dd/MMMM/yyyy"), Entry.user_name, Entry.warehouse_name,
                                                             Entry.observation, Entry.Id.ToString());
                    var EntryDetail = db.EntryDet.Join(db.Items, x => x.id_item, y => y.id, (x, y) => new
                    {
                        x.id_entry,
                        x.id_item,
                        x.quantity,
                        y.key,
                        y.description
                    }).Where(x => x.id_entry == Entry.Id).ToList();

                    foreach (var item in EntryDetail)
                    {
                        dsData.dtDetailEntry.AdddtDetailEntryRow(item.key, item.description, item.quantity,
                                                                 item.id_entry.ToString());
                    }
                }

                crEntry.SetDataSource(dsData);
                scrReports.crv.ReportSource = crEntry;

                #endregion
                break;

            case 2:
                #region SALIDAS
                var DepartureHeader = db.Departures.Join(db.Users, x => x.id_user, y => y.Id, (x, y) => new
                {
                    x.id,
                    x.id_user,
                    x.id_cellar,
                    x.id_warehouse,
                    x.serie,
                    x.folio,
                    x.date,
                    x.observation,
                    user_name = y.name
                }).Join(db.Warehouses, x => x.id_warehouse, y => y.id, (x, y) => new
                {
                    x.id,
                    x.id_user,
                    x.id_cellar,
                    x.id_warehouse,
                    x.serie,
                    x.folio,
                    x.date,
                    x.observation,
                    x.user_name,
                    warehouse_name = y.name
                }).Join(db.Warehouses, x => x.id_cellar, y => y.id, (x, y) => new
                {
                    x.id,
                    x.id_user,
                    x.id_cellar,
                    x.id_warehouse,
                    y.id_district,
                    x.serie,
                    x.folio,
                    x.date,
                    x.observation,
                    x.user_name,
                    x.warehouse_name,
                    cellar_name = y.name
                }).Join(db.Districts, x => x.id_district, y => y.id, (x, y) => new
                {
                    x.id,
                    x.id_user,
                    x.serie,
                    x.folio,
                    x.date,
                    x.observation,
                    x.user_name,
                    x.warehouse_name,
                    x.cellar_name,
                    y.district,
                    y.district_name
                }).Where(x =>
                         DbFunctions.TruncateTime(x.date) >= DbFunctions.TruncateTime(dtpF1.Value) &&
                         DbFunctions.TruncateTime(x.date) <= DbFunctions.TruncateTime(dtpF2.Value));

                if (cbUser.Text != "TODOS")
                {
                    DepartureHeader = DepartureHeader.Where(x => x.id_user == id_user);
                }

                foreach (var Departure in DepartureHeader.ToList())
                {
                    dsData.dtDepartureHeader.AdddtDepartureHeaderRow(Departure.id, Departure.serie,
                                                                     Departure.folio.ToString(), Departure.user_name, Departure.warehouse_name,
                                                                     Departure.cellar_name, Departure.observation, Departure.district, Departure.district_name,
                                                                     Departure.date.ToString("dd/MMMM/yyyy"));

                    var DepartureDetail = db.DepartureDet.Join(db.Items, x => x.id_item, y => y.id, (x, y) => new
                    {
                        x.id_departure,
                        x.quantity,
                        x.user,
                        y.key,
                        y.description
                    }).ToList();

                    foreach (var item in DepartureDetail)
                    {
                        dsData.dtDepartureDetail.AdddtDepartureDetailRow(item.id_departure, item.key,
                                                                         item.description, item.quantity, item.user);
                    }
                }

                if (departure == 1)
                {
                    crDeparture.SetDataSource(dsData);
                    scrReports.crv.ReportSource = crDeparture;
                }
                else
                {
                    crDeparture2.SetDataSource(dsData);
                    scrReports.crv.ReportSource = crDeparture2;
                }

                #endregion
                break;
            }

            scrReports.ShowDialog();
            dsData.Clear();
            crEntry.Close();
        }