Ejemplo n.º 1
0
        private string GetKhuyenMai(string maSanPham, int idSanPham, double donGia)
        {
            if (ngayLap == DateTime.MinValue)
            {
                return("");
            }

            List <BangGiaChinhSachInfor> liChinhSach =
                ChinhSachDataProvider.Instance.GetAllChinhSachApDung(0, -1, 0, maSanPham, -1);
            List <KhuyenMaiWeb>        lstKhuyenMai = new List <KhuyenMaiWeb>();
            List <DMTrungTamPairInfor> liTTNoWeb    = DMTrungTamDataProvider.GetTrungTamNoWeb();
            List <int> lstDiemThuong = new List <int>();

            if (liChinhSach != null && liChinhSach.Count > 0)
            {
                foreach (BangGiaChinhSachInfor bgcs in liChinhSach)
                {
                    string lstMatHangKhongAD = String.Format(",{0},", bgcs.MatHangKhongApDung);//khong nam trong danh sach ko duoc ap dung
                    if (lstMatHangKhongAD.Contains(String.Format(",{0},", idSanPham)))
                    {
                        continue;
                    }

                    KhuyenMaiWeb kmWeb = new KhuyenMaiWeb();
                    kmWeb.ListKMaiChiTiet = new List <string>();

                    bgcs.ListBangGiaADDKMua = KhuyenMaiDataProvider.Instance.GetBangGiaADDKMuaInforsById(bgcs.IdDKMua);
                    foreach (BangGiaADDKMuaInfor dkm in bgcs.ListBangGiaADDKMua)
                    {
                        if (String.IsNullOrEmpty(dkm.KhuyenMaiWeb))
                        {
                            List <BangGiaADKhuyenMaiInfor> lstKM = KhuyenMaiDataProvider.Instance.GetAllBangGiaKhuyenMaiADInfors(dkm.IdDKMua);
                            for (int i = 0; i < lstKM.Count; i++)
                            {
                                string km = "";
                                lstKM[i].ListKhuyenMaiChiTiet = KhuyenMaiDataProvider.Instance.GetAllKhuyenMaiWebCTietInfors(lstKM[i].IdKhuyenMai);
                                foreach (BangGiaADKhuyenMaiChiTietInfor kmct in lstKM[i].ListKhuyenMaiChiTiet)
                                {
                                    string ghichu = kmct.HetTonDungKM == 1 ? " (<b><i>khuyến mại đến khi hết hàng</i></b>)" : "";
                                    km += String.Format("<li>{0}, số lượng {1}{2}</li>", kmct.TenHangKM.Replace("\"", ""), kmct.SoLuong, ghichu);
                                }
                                if (!String.IsNullOrEmpty(km))
                                {
                                    kmWeb.ListKMaiChiTiet.Add(km);
                                }
                            }
                        }
                        else
                        {
                            string[] kms   = dkm.KhuyenMaiWeb.Split("\r\n".ToCharArray());
                            string   strkm = "";
                            for (int k = 0; k < kms.Length; k++)
                            {
                                strkm += String.IsNullOrEmpty(kms[k].Trim())
                                             ? String.Empty
                                             : String.Format("<li>{0}</li>", kms[k].Trim());
                            }
                            kmWeb.ListKMaiChiTiet.Add(strkm);
                        }
                    }
                    if (kmWeb.ListKMaiChiTiet.Count > 0)              //neu co khuyen mai thi them vao danh sach
                    {
                        foreach (DMTrungTamPairInfor tt in liTTNoWeb) //loai bo cac trung tam ko dua len web
                        {
                            if (!String.IsNullOrEmpty(bgcs.SieuThiAD) && bgcs.SieuThiAD.Contains(tt.TenTrungTam))
                            {
                                bgcs.SieuThiAD = bgcs.SieuThiAD.Replace(tt.TenTrungTam + ";", "");
                                bgcs.SieuThiAD = bgcs.SieuThiAD.Replace(tt.TenTrungTam, "");
                            }
                        }
                        string sthi = bgcs.LoaiDoiTuong == 1
                                          ? "chỉ áp dụng Online"
                                          : (String.IsNullOrEmpty(bgcs.SieuThiAD) || bgcs.SieuThiAD.Trim().ToLower().Contains("tất cả")
                                                 ? "tại tất cả siêu thị Trần Anh"
                                                 : String.Format("tại siêu thị {0}", bgcs.SieuThiAD));
                        kmWeb.KhuyenMai = String.Format("(áp dụng từ {0} đến {1}), {2}",
                                                        Common.Date2String(bgcs.NgayHieuLuc),
                                                        Common.Date2String(bgcs.HanHieuLuc),
                                                        sthi);
                        lstKhuyenMai.Add(kmWeb);
                    }
                    //diem thuong
                    int diemThuong = Common.IntValue(bgcs.TyLeDiemThuong * donGia / 100);
                    lstDiemThuong.Add(diemThuong);
                }
            }
            return(GetKhuyenMaiInfor(lstKhuyenMai, lstDiemThuong));
        }