public override global::System.Data.DataSet Clone() { DataSetDoanhThu cln = ((DataSetDoanhThu)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { DataSetDoanhThu ds = new DataSetDoanhThu(); 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(); DataSetDoanhThu ds = new DataSetDoanhThu(); 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 = "DataTableDoanhThuDataTable"; 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); }
public ActionResult ReportDoanhThu(int Chon, DateTime?NgayBatDau, DateTime?NgayKetThuc) { DataSetDoanhThu ds = new DataSetDoanhThu(); DataTable dt = ds.DataTableDoanhThu; var user = kiemtra.getUser(User.Identity.Name); db = ShopEntities.CreateEntitiesForSpecificDatabaseName(user.MaCN); var Dons = db.DonHangs.Where(x => x.State == (int)LapHoaDonKhach.Complete); var NgayHomNay = DateTime.Today; var NgayKeTiep = NgayHomNay.AddDays(1); //Ngày bắt đầu có giá trị --> Lọc lại đơn if (NgayBatDau.HasValue) { Dons = Dons.Where(x => x.Completiontime.CompareTo(NgayBatDau) >= 0); } //Ngày kết thúc có gia trị --> Lọc lại đơn if (NgayKetThuc.HasValue) { DateTime NgaySoSanh = NgayKeTiep.AddDays(1); Dons = Dons.Where(x => x.Completiontime.CompareTo(NgaySoSanh) < 0); } //Tính số ngày và ngày bắt đầu var NgayDau = new DateTime();; var NgayKe = new DateTime(); double n = 0; if (NgayBatDau.HasValue && NgayKetThuc.HasValue) { n = (NgayKetThuc.Value - NgayBatDau.Value).TotalDays; NgayDau = NgayBatDau.Value; } else if (NgayBatDau.HasValue) { n = (DateTime.Now - NgayBatDau.Value).TotalDays; NgayDau = NgayBatDau.Value; } else if (NgayKetThuc.HasValue) { var k = Dons.OrderBy(x => x.Completiontime).First().Completiontime; n = (NgayKetThuc.Value - k).TotalDays; NgayDau = k; } //Theo Ngày if (Chon == 1) { var DonsHomNay = new List <DonHang>(); if (!NgayBatDau.HasValue && !NgayKetThuc.HasValue) { DonsHomNay = Dons.Where(x => x.Completiontime.CompareTo(NgayHomNay) >= 0 && x.Completiontime.CompareTo(NgayKeTiep) < 0).ToList(); for (int i = 0; i < 7; i++) { var DonsMoi3Tieng = DonsHomNay.Where(x => x.Completiontime.Hour >= i * 3 && x.Completiontime.Hour < (i + 1) * 3); if (DonsMoi3Tieng.Count() > 0) { dt.Rows.Add(i + "-" + ((i + 1) * 3) + " h", DonsMoi3Tieng.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonsMoi3Tieng.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(i + "-" + ((i + 1) * 3) + " h", 0, 0); } } } else { for (int i = 0; i < n; i++) { NgayKe = NgayDau.AddDays(1); var DonsMoiNgay = DonsHomNay.Where(x => x.Completiontime >= NgayDau && x.Completiontime < NgayKe); if (DonsMoiNgay.Count() > 0) { dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month, DonsMoiNgay.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonsMoiNgay.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month, 0, 0); } NgayDau = NgayKe; } } } //Theo Tuần else if (Chon == 2) { if (!NgayBatDau.HasValue && !NgayKetThuc.HasValue) { var Thu2 = kiemtra.GetFirstDayOfWeek(NgayHomNay); var TuanSau = Thu2.AddDays(7); var DonsTuanNay = Dons.Where(x => x.Completiontime.CompareTo(Thu2) >= 0 && x.Completiontime.CompareTo(TuanSau) < 0); for (int i = 0; i < 7; i++) { string Thu = ""; switch (i) { case 0: Thu = "Thứ Hai"; break; case 1: Thu = "Thứ Ba"; break; case 2: Thu = "Thứ Tư"; break; case 3: Thu = "Thứ Năm"; break; case 4: Thu = "Thứ Sáu"; break; case 5: Thu = "Thứ Bảy"; break; case 6: Thu = "Chủ Nhật"; break; } NgayKeTiep = Thu2.AddDays(1); var DonNgay = DonsTuanNay.Where(x => x.Completiontime.CompareTo(Thu2) >= 0 && x.Completiontime.CompareTo(NgayKeTiep) < 0); if (DonNgay.Count() > 0) { dt.Rows.Add(Thu, DonNgay.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonNgay.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Thu, 0, 0); } Thu2 = Thu2.AddDays(1); } } else { var ChuNhat = kiemtra.GetFirstDayOfWeek(NgayDau).AddDays(6); var TuanSau = ChuNhat.AddDays(1); var flag = false; string Tuan = ""; n = n / 7; for (int i = 0; i < n; i++) { Tuan = "Tuần " + (i + 1); var DonMoiTuan = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(TuanSau) < 0); if (DonMoiTuan.Count() > 0) { if (!flag) { if (NgayDau.DayOfWeek == DayOfWeek.Monday) { dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month + "-" + ChuNhat.Day + "/" + ChuNhat.Month, DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Tuan, DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } flag = true; } else { dt.Rows.Add(Tuan, DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiTuan.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } } else { dt.Rows.Add(Tuan, 0, 0); } NgayDau = TuanSau; TuanSau = NgayDau.AddDays(7); } } } //Theo Tháng else if (Chon == 3) { if (!NgayBatDau.HasValue && !NgayKetThuc.HasValue) { var ThangNay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var ThangSau = ThangNay.AddMonths(1); var CuoiThang = ThangSau.AddDays(-1); var Dot = ThangNay.AddDays(5); var DonsThangNay = Dons.Where(x => x.Completiontime.CompareTo(ThangNay) >= 0 && x.Completiontime.CompareTo(ThangSau) < 0); for (int i = 0; i < 6; i++) { string Ngay = (i * 5 + 1) + "-" + ((i + 1) * 5); if (i == 5) { Ngay = (i * 5 + 1) + "-" + CuoiThang.Day; } var DonTrongThang = DonsThangNay.Where(x => x.Completiontime.CompareTo(ThangNay) >= 0 && x.Completiontime.CompareTo(Dot) < 0); if (DonTrongThang.Count() > 0) { dt.Rows.Add(Ngay, DonTrongThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonTrongThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Ngay, 0, 0); } ThangNay = ThangNay.AddDays(5); Dot = Dot.AddDays(5); } } else { var DauThang = new DateTime(NgayDau.Year, NgayDau.Month, 1); var ThangSau = DauThang.AddMonths(1); var Thang = "T" + ThangSau.Month; var ThangKetThuc = NgayDau.AddDays(n); var flag = false; var QuaHan = false; var DonMoiThang = new List <DonHang>(); while (!QuaHan) { if (ThangKetThuc <= ThangSau) { QuaHan = true; ThangKetThuc = ThangKetThuc.AddDays(1); DonMoiThang = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(ThangKetThuc) < 0).ToList(); ThangKetThuc = ThangKetThuc.AddDays(-1); Thang = "1/" + ThangKetThuc.Month + "-" + ThangKetThuc.Day + "/" + ThangKetThuc.Month; } else { DonMoiThang = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(ThangSau) < 0).ToList(); Thang = "T" + NgayDau.Month; } if (DonMoiThang.Count() > 0) { if (!flag) { if (NgayDau.Day != 1) { var CuoiThang = ThangSau.AddDays(-1); dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month + "-" + CuoiThang.Day + "/" + CuoiThang.Month, DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Thang, DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } flag = true; } else { dt.Rows.Add(Thang, DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } } else { dt.Rows.Add(Thang, 0, 0); } NgayDau = ThangSau; ThangSau = NgayDau.AddMonths(1); } } } //Theo quý else if (Chon == 4) { if (!NgayBatDau.HasValue && !NgayKetThuc.HasValue) { var QuyDau = kiemtra.GetQuarter(DateTime.Now); var QuySau = QuyDau.AddMonths(3); var NgayCuoi = QuySau; var DonsQuyNay = Dons.Where(x => x.Completiontime.CompareTo(QuyDau) >= 0 && x.Completiontime.CompareTo(QuySau) < 0); for (int i = 0; i < 6; i++) { QuySau = QuyDau.AddDays(15); string Ngay = QuyDau.Day + "/" + QuyDau.Month + "-" + QuySau.Day + "/" + QuySau.Month; var DonTrongQuy = new List <DonHang>(); if (i == 5) { DonTrongQuy = DonsQuyNay.Where(x => x.Completiontime.CompareTo(QuyDau) >= 0 && x.Completiontime.CompareTo(NgayCuoi) < 0).ToList(); } else { DonTrongQuy = DonsQuyNay.Where(x => x.Completiontime.CompareTo(QuyDau) >= 0 && x.Completiontime.CompareTo(QuySau) < 0).ToList(); } if (DonTrongQuy.Count() > 0) { dt.Rows.Add(Ngay, DonTrongQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonTrongQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Ngay, 0, 0); } QuyDau = QuyDau.AddDays(15); } } else { var k = NgayDau.Month % 3; var QuySau = new DateTime(); if (k == 1) { QuySau = NgayDau.AddMonths(3); } if (k == 2) { QuySau = NgayDau.AddMonths(2); } if (k == 0) { QuySau = NgayDau.AddMonths(1); } QuySau = new DateTime(QuySau.Year, QuySau.Month, 1); var Quy = ""; var QuaHan = false; var flag = false; var DonMoiQuy = new List <DonHang>(); var NgayCuoi = NgayDau.AddDays(n); while (!QuaHan) { if (NgayCuoi <= QuySau) { QuaHan = true; NgayCuoi = NgayCuoi.AddDays(1); DonMoiQuy = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(NgayCuoi) < 0).ToList(); NgayCuoi = NgayCuoi.AddDays(-1); if (NgayCuoi.Month % 3 == 1) { Quy = "1/" + NgayCuoi.Month + "-" + NgayCuoi.Day + "/" + NgayCuoi.Month; } else if (NgayCuoi.Month % 3 == 2) { Quy = "1/" + (NgayCuoi.Month - 1) + "-" + NgayCuoi.Day + "/" + NgayCuoi.Month; } else { Quy = "1/" + (NgayCuoi.Month - 2) + "-" + NgayCuoi.Day + "/" + NgayCuoi.Month; } } else { DonMoiQuy = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(QuySau) < 0).ToList(); Quy = "Quý" + ((NgayDau.Month / 3) + 1); } if (DonMoiQuy.Count() > 0) { if (!flag) { if (NgayDau.Day != 1 && (NgayDau.Month % 3) != 1) { var CuoiQuy = QuySau.AddDays(-1); dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month + "-" + CuoiQuy.Day + "/" + CuoiQuy.Month, DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Quy, DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } flag = true; } else { dt.Rows.Add(Quy, DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiQuy.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } } else { dt.Rows.Add(Quy, 0, 0); } NgayDau = QuySau; QuySau = NgayDau.AddMonths(3); } if (k == 1 && NgayDau.Day == 1) { } } } //Theo năm else if (Chon == 5) { if (!NgayBatDau.HasValue && !NgayKetThuc.HasValue) { var DauNam = new DateTime(DateTime.Now.Year, 1, 1); var ThangSau = new DateTime(); var NamSau = DauNam.AddYears(1); var DonsNamNay = Dons.Where(x => x.Completiontime.CompareTo(DauNam) >= 0 && x.Completiontime.CompareTo(NamSau) < 0); for (int i = 0; i < 12; i++) { ThangSau = DauNam.AddMonths(1); var DonTrongThang = DonsNamNay.Where(x => x.Completiontime.CompareTo(DauNam) >= 0 && x.Completiontime.CompareTo(ThangSau) < 0).ToList(); string Thang = "Tháng " + (i + 1); if (DonTrongThang.Count() > 0) { dt.Rows.Add(Thang, DonTrongThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonTrongThang.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Thang, 0, 0); } DauNam = DauNam.AddMonths(1); } } else { var NamSau = new DateTime(NgayDau.Year + 1, 1, 1); var CuoiNam = NamSau.AddDays(-1); var NgayCuoi = NgayDau.AddDays(n); var Nam = ""; var QuaHan = false; var flag = false; var DonMoiNam = new List <DonHang>(); while (!QuaHan) { if (NgayCuoi <= NamSau) { QuaHan = true; NgayCuoi = NgayCuoi.AddDays(1); DonMoiNam = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(NgayCuoi) < 0).ToList(); NgayCuoi = NgayCuoi.AddDays(-1); Nam = "->" + NgayCuoi.Day + "/" + NgayCuoi.Month + "/" + NgayCuoi.Year; } else { DonMoiNam = Dons.Where(x => x.Completiontime.CompareTo(NgayDau) >= 0 && x.Completiontime.CompareTo(NamSau) < 0).ToList(); Nam = "Năm" + NgayDau.Year; } if (DonMoiNam.Count() > 0) { if (!flag) { if (NgayDau.Day != 1 && NgayDau.Month != 1) { dt.Rows.Add(NgayDau.Day + "/" + NgayDau.Month + "/" + NgayDau.Day + "->", DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } else { dt.Rows.Add(Nam, DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } flag = true; } else { dt.Rows.Add(Nam, DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Quantities)), DonMoiNam.Sum(x => x.ChiTietDonHangs.Sum(y => y.Price * y.Quantities))); } } else { dt.Rows.Add(Nam, 0, 0); } NgayDau = NamSau; NamSau = NgayDau.AddYears(1); } } } CrystalReportDoanhThu rpt = new CrystalReportDoanhThu(); rpt.Load(); rpt.SetDataSource(ds); if (Chon == 1) { rpt.SetParameterValue("NoiDung", "Ngày"); } if (Chon == 2) { rpt.SetParameterValue("NoiDung", "Tuần"); } if (Chon == 3) { rpt.SetParameterValue("NoiDung", "Tháng"); } if (Chon == 4) { rpt.SetParameterValue("NoiDung", "Quý"); } if (Chon == 5) { rpt.SetParameterValue("NoiDung", "Năm"); } Stream s = rpt.ExportToStream(ExportFormatType.PortableDocFormat); return(File(s, "application/pdf")); }