Beispiel #1
0
        protected void btnXuat_Click(object sender, EventArgs e)
        {
            MTCSYT.SYS_Session session = (MTCSYT.SYS_Session)Session["SYS_Session"];
            int ma_dviqly = int.Parse(session.User.ma_dviqly + "");
            var lst       = db.BC_GiaoNhan2Chieu_ChiTiet(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();

            #region Chuẩn bị tệp excel mẫu để ghi dữ liệu
            string   destFile  = Server.MapPath("~/Tem/BC_GiaoNhanChiNhanh.xls");
            string   sTemplate = (destFile);
            Workbook exBook    = new Workbook();
            exBook.Open(sTemplate, FileFormatType.Excel2003);
            _exSheet = exBook.Worksheets[0];
            _range   = _exSheet.Cells;
            #endregion

            // Xử lý replace các thông tin báo cáo tĩnh theo công ty
            //Report.ReplaceSpecificationField(_exSheet);

            int donghientai = 8;

            #region Ghi dữ liệu
            _exSheet.Replace("NGAYTHANG", "Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year);

            if (lst.Count > 0)
            {
                _exSheet.Cells.InsertRows(donghientai + 1, lst.Count * 11 - 3);
            }
            string macto = "", tenchinhanh = "";
            int    vitri      = 0;
            Style  celicaStil = exBook.Styles[exBook.Styles.Add()];
            celicaStil.VerticalAlignment   = TextAlignmentType.Center;
            celicaStil.HorizontalAlignment = TextAlignmentType.Center;
            celicaStil.Pattern             = BackgroundType.Solid;
            celicaStil.Font.IsBold         = true;
            StyleFlag flg = new StyleFlag();
            flg.Font        = true;
            flg.CellShading = true;
            foreach (var ct in lst)
            {
                if (tenchinhanh != ct.TenChiNhanh)
                {
                    _range[donghientai + vitri, 0].PutValue(ct.TenChiNhanh);
                    _range.Merge(donghientai + vitri, 0, 1, 14);
                    celicaStil.ForegroundColor = System.Drawing.Color.Aqua;
                    _range[donghientai + vitri, 0].SetStyle(celicaStil);

                    tenchinhanh = ct.TenChiNhanh;
                }
                vitri = vitri + 1;
                if (macto != ct.MaCongTo)
                {
                    _range[donghientai + vitri, 0].PutValue(ct.TenTram);
                    _range.Merge(donghientai + vitri, 0, 5, 1);

                    celicaStil.ForegroundColor = System.Drawing.Color.White;
                    _range[donghientai + vitri, 0].SetStyle(celicaStil);

                    _range[donghientai + vitri, 1].PutValue(ct.TenDiemDo);
                    _range.Merge(donghientai + vitri, 1, 5, 1);
                    _range[donghientai + vitri, 1].SetStyle(celicaStil);

                    _range[donghientai + vitri, 2].PutValue(ct.TU_TI);
                    _range.Merge(donghientai + vitri, 2, 5, 1);
                    _range[donghientai + vitri, 2].SetStyle(celicaStil);

                    _range[donghientai + vitri, 3].PutValue(ct.TenCongTo);
                    _range.Merge(donghientai + vitri, 3, 5, 1);
                    _range[donghientai + vitri, 3].SetStyle(celicaStil);

                    _range[donghientai + vitri, 4].PutValue(ct.HeSoNhan);
                    _range.Merge(donghientai + vitri, 4, 5, 1);
                    _range[donghientai + vitri, 4].SetStyle(celicaStil);

                    macto = ct.MaCongTo;
                }
                for (int i = 0; i < 5; i++)
                {
                    if (i == 0)
                    {
                        _range[donghientai + vitri + i, 5].PutValue("Tổng P");
                        _range[donghientai + vitri + i, 6].PutValue(ct.Giao_P_Dau);
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_P_Cuoi);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_P_SanLuong);
                        _range[donghientai + vitri + i, 9].PutValue(ct.CosGiao);
                        _range[donghientai + vitri + i, 10].PutValue(ct.Nhan_P_Dau);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_P_Cuoi);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_P_SanLuong);
                        _range[donghientai + vitri + i, 13].PutValue(ct.CosNhan);
                    }
                    else if (i == 1)
                    {
                        _range[donghientai + vitri + i, 5].PutValue("Tổng Q");
                        _range[donghientai + vitri + i, 6].PutValue(ct.Giao_Q_Dau);
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Q_Cuoi);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Q_SanLuong);
                        _range[donghientai + vitri + i, 9].PutValue("");
                        _range[donghientai + vitri + i, 10].PutValue(ct.Nhan_Q_Dau);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Q_Cuoi);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Q_SanLuong);
                        _range[donghientai + vitri + i, 13].PutValue("");
                    }
                    else if (i == 2)
                    {
                        _range[donghientai + vitri + i, 5].PutValue("Biểu 1");
                        _range[donghientai + vitri + i, 6].PutValue(ct.Giao_Bieu1_Dau);
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu1_Cuoi);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 9].PutValue("");
                        _range[donghientai + vitri + i, 10].PutValue(ct.Nhan_Bieu1_Dau);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu1_Cuoi);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 13].PutValue("");
                    }
                    else if (i == 3)
                    {
                        _range[donghientai + vitri + i, 5].PutValue("Biểu 2");
                        _range[donghientai + vitri + i, 6].PutValue(ct.Giao_Bieu2_Dau);
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu2_Cuoi);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 9].PutValue("");
                        _range[donghientai + vitri + i, 10].PutValue(ct.Nhan_Bieu2_Dau);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu2_Cuoi);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu2_SanLuong);
                        _range[donghientai + vitri + i, 13].PutValue("");
                    }
                    else if (i == 4)
                    {
                        _range[donghientai + vitri + i, 5].PutValue("Biểu 3");
                        _range[donghientai + vitri + i, 6].PutValue(ct.Giao_Bieu3_Dau);
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu3_Cuoi);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu3_SanLuong);
                        _range[donghientai + vitri + i, 9].PutValue("");
                        _range[donghientai + vitri + i, 10].PutValue(ct.Nhan_Bieu3_Dau);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu3_Cuoi);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu3_SanLuong);
                        _range[donghientai + vitri + i, 13].PutValue("");
                    }
                }
                //in tổng
                _range[donghientai + vitri + 5, 0].PutValue(ct.motaCN);
                _range.Merge(donghientai + vitri + 5, 0, 5, 5);
                _range[donghientai + vitri + 5, 0].SetStyle(celicaStil);
                var lstTong = db.BC_GiaoNhan2Chieu_TongTram(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();
                var ctTong  = lstTong.SingleOrDefault(x => x.TenTram == ct.TenTram);
                if (ctTong != null)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        if (i == 0)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng P");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.slPGiao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.slPNhan);
                        }
                        else if (i == 1)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng Q");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.slQGiao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.slQNhan);
                        }
                        else if (i == 2)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng Biểu 1");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.slb1Giao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.slb1Nhan);
                        }
                        else if (i == 3)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng Biểu 2");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.slb2Giao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.slb2Nhan);
                        }
                        else if (i == 4)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng Biểu 3");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.slb3Giao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.slb3Nhan);
                        }
                        else if (i == 5)
                        {
                            _range[donghientai + vitri + i + 5, 5].PutValue("Tổng 3 Biểu");
                            _range.Merge(donghientai + vitri + i + 5, 5, 1, 3);
                            _range[donghientai + vitri + i + 5, 8].PutValue(ctTong.tong3B_Giao);
                            _range[donghientai + vitri + i + 5, 12].PutValue(ctTong.tong3B_Nhan);
                        }
                    }
                }



                vitri = vitri + 10;
            }

            #endregion

            exBook.Save("BC_GiaoNhanChiNhanh.xls", SaveType.OpenInExcel, FileFormatType.Default, this.Response);
            //Response.Redirect("../BaoCao/Report.aspx?Loai=5&strSQL=" + strTruyVan);
        }
Beispiel #2
0
        protected void btnXuat_Click(object sender, EventArgs e)
        {
            MTCSYT.SYS_Session session = (MTCSYT.SYS_Session)Session["SYS_Session"];
            int ma_dviqly = int.Parse(session.User.ma_dviqly + "");

            var lst     = db.BC_ChiSoThang_ChuaChot(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();
            var lsttONG = db.BC_GiaoNhan2Chieu_TongTram(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();

            #region Chuẩn bị tệp excel mẫu để ghi dữ liệu
            string   destFile  = Server.MapPath("~/Tem/BC_BCDienLuc.xls");
            string   sTemplate = (destFile);
            Workbook exBook    = new Workbook();
            exBook.Open(sTemplate, FileFormatType.Excel2003);
            _exSheet = exBook.Worksheets[0];
            _range   = _exSheet.Cells;
            #endregion

            // Xử lý replace các thông tin báo cáo tĩnh theo công ty
            //Report.ReplaceSpecificationField(_exSheet);

            int donghientai = 7;

            #region Ghi dữ liệu
            _exSheet.Replace("NGAYTHANG", "Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year);

            Style celicaStil = exBook.Styles[exBook.Styles.Add()];
            celicaStil.Font.IsBold = true;

            DM_DVQLYService dm_dviSer = new DM_DVQLYService();
            var             donvi     = dm_dviSer.SelectDM_DVQLY(ma_dviqly);

            _exSheet.Replace("ntDienLuc", donvi.NAME_DVIQLY.Split('-')[1].ToUpper());

            _exSheet.Replace("ntTieuDe", "BÁO CÁO SẢN LƯỢNG ĐIỆN GIAO CỦA " + donvi.NAME_DVIQLY.Split('-')[1].ToString().ToUpper() + " TRONG THÁNG " + cmbThang.Value + " NĂM " + cmbNam.Value);

            if (lst.Count > 0)
            {
                _exSheet.Cells.InsertRows(donghientai + 1, (lst.Count + lsttONG.Count * 2) - 3);
            }
            string idTram = "0"; int vitri = 0;
            int    sttTong = 0, sttChiTiet = 0;
            foreach (var tongtram in lsttONG)
            {
                if (idTram != tongtram.IDTram + "")
                {
                    var tram = db.DM_Trams.SingleOrDefault(x => x.IDTram == tongtram.IDTram);
                    if (tram == null)
                    {
                        continue;
                    }
                    var phuongthuc = db.DM_ChiNhanhs.SingleOrDefault(x => x.ID == int.Parse(tram.IDChiNhanh));
                    if (phuongthuc == null)
                    {
                        continue;
                    }
                    _range[donghientai + vitri, 0].PutValue(phuongthuc.MoTa);
                    _range.Merge(donghientai + vitri, 0, 1, 21);
                    _range[donghientai + vitri, 0].SetStyle(celicaStil);

                    vitri   = vitri + 1;
                    sttTong = sttTong + 1;
                    _range[donghientai + vitri, 0].PutValue(sttTong);
                    _range[donghientai + vitri, 0].SetStyle(celicaStil);
                    _range[donghientai + vitri, 1].PutValue(tongtram.TenTram);
                    _range[donghientai + vitri, 1].SetStyle(celicaStil);
                    _range[donghientai + vitri, 7].PutValue(tongtram.slPGiao);
                    _range[donghientai + vitri, 7].SetStyle(celicaStil);
                    _range[donghientai + vitri, 11].PutValue(tongtram.slb1Giao);
                    _range[donghientai + vitri, 11].SetStyle(celicaStil);
                    _range[donghientai + vitri, 15].PutValue(tongtram.slb2Giao);
                    _range[donghientai + vitri, 15].SetStyle(celicaStil);
                    _range[donghientai + vitri, 19].PutValue(tongtram.slb3Giao);
                    _range[donghientai + vitri, 19].SetStyle(celicaStil);
                    vitri = vitri + 1;
                    var lstByTram = lst.Where(x => x.IDTram == tongtram.IDTram).ToList();
                    sttChiTiet = sttChiTiet + 1;
                    foreach (var chitiet in lstByTram)
                    {
                        _range[donghientai + vitri, 0].PutValue(sttTong + "." + sttChiTiet);
                        _range[donghientai + vitri, 1].PutValue(chitiet.TenDiemDo);
                        _range[donghientai + vitri, 2].PutValue(chitiet.CapDienAp);
                        _range[donghientai + vitri, 3].PutValue(chitiet.HeSoNhan);
                        _range[donghientai + vitri, 4].PutValue(chitiet.Giao_P_Dau);
                        _range[donghientai + vitri, 5].PutValue(chitiet.Giao_P_Cuoi);
                        _range[donghientai + vitri, 6].PutValue(chitiet.Giao_P_Cuoi - chitiet.Giao_P_Dau);
                        _range[donghientai + vitri, 7].PutValue(chitiet.Giao_P_SanLuong);

                        _range[donghientai + vitri, 8].PutValue(chitiet.Giao_Bieu1_Dau);
                        _range[donghientai + vitri, 9].PutValue(chitiet.Giao_Bieu1_Cuoi);
                        _range[donghientai + vitri, 10].PutValue(chitiet.Giao_Bieu1_Cuoi - chitiet.Giao_Bieu1_Dau);
                        _range[donghientai + vitri, 11].PutValue(chitiet.Giao_Bieu1_SanLuong);

                        _range[donghientai + vitri, 12].PutValue(chitiet.Giao_Bieu2_Dau);
                        _range[donghientai + vitri, 13].PutValue(chitiet.Giao_Bieu2_Cuoi);
                        _range[donghientai + vitri, 14].PutValue(chitiet.Giao_Bieu2_Cuoi - chitiet.Giao_Bieu2_Dau);
                        _range[donghientai + vitri, 15].PutValue(chitiet.Giao_Bieu2_SanLuong);

                        _range[donghientai + vitri, 16].PutValue(chitiet.Giao_Bieu3_Dau);
                        _range[donghientai + vitri, 17].PutValue(chitiet.Giao_Bieu3_Cuoi);
                        _range[donghientai + vitri, 18].PutValue(chitiet.Giao_Bieu3_Cuoi - chitiet.Giao_Bieu3_Dau);
                        _range[donghientai + vitri, 19].PutValue(chitiet.Giao_Bieu3_SanLuong);

                        vitri = vitri + 1;
                    }
                    idTram = tongtram.IDTram + "";
                }
            }


            #endregion

            exBook.Save("bc_dienLuc.xls", SaveType.OpenInExcel, FileFormatType.Default, this.Response);
            //Response.Redirect("../BaoCao/Report.aspx?Loai=5&strSQL=" + strTruyVan);
        }
Beispiel #3
0
        protected void btnXuat_Click(object sender, EventArgs e)
        {
            MTCSYT.SYS_Session session = (MTCSYT.SYS_Session)Session["SYS_Session"];
            int ma_dviqly = int.Parse(session.User.ma_dviqly + "");
            var lst       = db.BC_KhuVuc_ChiTiet(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();

            #region Chuẩn bị tệp excel mẫu để ghi dữ liệu
            string   destFile  = Server.MapPath("~/Tem/BC_KhuVuc.xls");
            string   sTemplate = (destFile);
            Workbook exBook    = new Workbook();
            exBook.Open(sTemplate, FileFormatType.Excel2003);
            _exSheet = exBook.Worksheets[0];
            _range   = _exSheet.Cells;
            #endregion

            // Xử lý replace các thông tin báo cáo tĩnh theo công ty
            //Report.ReplaceSpecificationField(_exSheet);

            int donghientai = 8;

            #region Ghi dữ liệu
            _exSheet.Replace("NGAYTHANG", "Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year);
            DM_DVQLYService dm_dviSer = new DM_DVQLYService();
            var             donvi     = dm_dviSer.SelectDM_DVQLY(ma_dviqly);
            string          tongdong  = Session["tongdong"] + "";
            if (donvi.Type < 3)
            {
                _exSheet.Replace("ntTieuDe", "BÁO CÁO SẢN LƯỢNG ĐIỆN NĂNG GIAO NHẬN VỚI CÁC CÔNG TY ĐIỆN LỰC");
            }
            else
            {
                _exSheet.Replace("ntTieuDe", " BÁO CÁO ĐIỆN NĂNG GIAO NHẬN VỚI CÔNG TY " + donvi.TEN_DVIQLY);
            }
            if (lst.Count > 1)
            {
                _exSheet.Cells.InsertRows(donghientai + 1, (lst.Count() + int.Parse(tongdong)) * 5 - 3);
            }
            string macto = "", tenkhuvuc = "";
            int    vitri      = 0;
            Style  celicaStil = exBook.Styles[exBook.Styles.Add()];
            celicaStil.VerticalAlignment   = TextAlignmentType.Center;
            celicaStil.HorizontalAlignment = TextAlignmentType.Center;
            celicaStil.Pattern             = BackgroundType.Solid;
            celicaStil.Font.IsBold         = true;
            celicaStil.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
            StyleFlag                   flg = new StyleFlag();
            flg.Font        = true; int tongtram = 0;
            flg.CellShading = true;

            foreach (var ct in lst)
            {
                tongtram = tongtram + 1;
                celicaStil.VerticalAlignment = TextAlignmentType.Center;
                if (tenkhuvuc != ct.TEN_DVIQLY)
                {
                    var countKV = lst.Where(x => x.TEN_DVIQLY == ct.TEN_DVIQLY).Count();
                    _range[donghientai + vitri, 0].PutValue(ct.TEN_DVIQLY);
                    var categoryCounts =
                        from p in lst
                        group p by p.TenTram into g
                        select new { TEN_DVIQLY = ct.TEN_DVIQLY, ProductCount = g.Count() };

                    _range.Merge(donghientai + vitri, 0, (categoryCounts.Count() + int.Parse(tongdong)) * 5, 1);
                    _range[donghientai + vitri, 0].SetStyle(celicaStil);

                    tenkhuvuc = ct.TEN_DVIQLY;
                }

                if (macto != ct.MaCongTo)
                {
                    _range[donghientai + vitri, 1].PutValue(ct.TenTram);
                    _range.Merge(donghientai + vitri, 1, 5, 1);
                    _range[donghientai + vitri, 1].SetStyle(celicaStil);

                    _range[donghientai + vitri, 2].PutValue(ct.TenDiemDo);
                    _range.Merge(donghientai + vitri, 2, 5, 1);
                    _range[donghientai + vitri, 2].SetStyle(celicaStil);

                    _range[donghientai + vitri, 3].PutValue(ct.TU_TI);
                    _range.Merge(donghientai + vitri, 3, 5, 1);
                    _range[donghientai + vitri, 3].SetStyle(celicaStil);

                    _range[donghientai + vitri, 4].PutValue(ct.TenCongTo);
                    _range.Merge(donghientai + vitri, 4, 5, 1);
                    _range[donghientai + vitri, 4].SetStyle(celicaStil);

                    _range[donghientai + vitri, 5].PutValue(ct.HeSoNhan);
                    _range.Merge(donghientai + vitri, 5, 5, 1);
                    _range[donghientai + vitri, 5].SetStyle(celicaStil);

                    macto = ct.MaCongTo;
                }
                for (int i = 0; i < 5; i++)
                {
                    if (i == 0)
                    {
                        _range[donghientai + vitri + i, 6].PutValue("Tổng P");
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_P_Dau);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_P_Cuoi);
                        _range[donghientai + vitri + i, 9].PutValue(ct.Giao_P_SanLuong);
                        _range[donghientai + vitri + i, 10].PutValue(ct.CosGiao);
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_P_Dau);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_P_Cuoi);
                        _range[donghientai + vitri + i, 13].PutValue(ct.Nhan_P_SanLuong);
                        _range[donghientai + vitri + i, 14].PutValue(ct.CosNhan);
                    }
                    else if (i == 1)
                    {
                        _range[donghientai + vitri + i, 6].PutValue("Tổng Q");
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Q_Dau);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Q_Cuoi);
                        _range[donghientai + vitri + i, 9].PutValue(ct.Giao_Q_SanLuong);
                        _range[donghientai + vitri + i, 10].PutValue("");
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Q_Dau);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Q_Cuoi);
                        _range[donghientai + vitri + i, 13].PutValue(ct.Nhan_Q_SanLuong);
                        _range[donghientai + vitri + i, 14].PutValue("");
                    }
                    else if (i == 2)
                    {
                        _range[donghientai + vitri + i, 6].PutValue("Biểu 1");
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu1_Dau);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu1_Cuoi);
                        _range[donghientai + vitri + i, 9].PutValue(ct.Giao_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 10].PutValue("");
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu1_Dau);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu1_Cuoi);
                        _range[donghientai + vitri + i, 13].PutValue(ct.Nhan_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 14].PutValue("");
                    }
                    else if (i == 3)
                    {
                        _range[donghientai + vitri + i, 6].PutValue("Biểu 2");
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu2_Dau);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu2_Cuoi);
                        _range[donghientai + vitri + i, 9].PutValue(ct.Giao_Bieu1_SanLuong);
                        _range[donghientai + vitri + i, 10].PutValue("");
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu2_Dau);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu2_Cuoi);
                        _range[donghientai + vitri + i, 13].PutValue(ct.Nhan_Bieu2_SanLuong);
                        _range[donghientai + vitri + i, 14].PutValue("");
                    }
                    else if (i == 4)
                    {
                        _range[donghientai + vitri + i, 6].PutValue("Biểu 3");
                        _range[donghientai + vitri + i, 7].PutValue(ct.Giao_Bieu3_Dau);
                        _range[donghientai + vitri + i, 8].PutValue(ct.Giao_Bieu3_Cuoi);
                        _range[donghientai + vitri + i, 9].PutValue(ct.Giao_Bieu3_SanLuong);
                        _range[donghientai + vitri + i, 10].PutValue("");
                        _range[donghientai + vitri + i, 11].PutValue(ct.Nhan_Bieu3_Dau);
                        _range[donghientai + vitri + i, 12].PutValue(ct.Nhan_Bieu3_Cuoi);
                        _range[donghientai + vitri + i, 13].PutValue(ct.Nhan_Bieu3_SanLuong);
                        _range[donghientai + vitri + i, 14].PutValue("");
                    }
                }
                //in tổng
                _range[donghientai + vitri + 5, 1].PutValue("");
                _range.Merge(donghientai + vitri + 5, 1, 5, 1);
                _range[donghientai + vitri + 5, 1].SetStyle(celicaStil);
                var lstTong = db.BC_GiaoNhan2Chieu_TongTram(ma_dviqly, int.Parse("0" + cmbThang.Value), int.Parse("0" + cmbNam.Value)).ToList();
                var ctTong  = lstTong.SingleOrDefault(x => x.TenTram == ct.TenTram);
                if (ctTong != null)
                {
                    if (tongtram == ctTong.TongTram)
                    {
                        tongtram = 0;
                        for (int i = 0; i < 5; i++)
                        {
                            celicaStil.VerticalAlignment   = TextAlignmentType.Left;
                            celicaStil.HorizontalAlignment = TextAlignmentType.Left;
                            if (i == 0)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng P");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);

                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.slPGiao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.slPNhan);

                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                            else if (i == 1)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng Q");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);
                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.slQGiao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.slQNhan);
                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                            else if (i == 2)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng Biểu 1");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);
                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.slb1Giao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.slb1Nhan);
                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                            else if (i == 3)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng Biểu 2");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);

                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.slb2Giao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.slb2Nhan);
                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                            else if (i == 4)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng Biểu 3");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);

                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.slb3Giao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.slb3Nhan);
                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                            else if (i == 5)
                            {
                                _range[donghientai + vitri + i + 5, 2].PutValue("Tổng 3 Biểu");
                                _range[donghientai + vitri + i + 5, 2].SetStyle(celicaStil);
                                _range.Merge(donghientai + vitri + i + 5, 2, 1, 7);
                                _range[donghientai + vitri + i + 5, 9].PutValue(ctTong.tong3B_Giao);
                                _range[donghientai + vitri + i + 5, 13].PutValue(ctTong.tong3B_Nhan);
                                _range[donghientai + vitri + i + 5, 13].SetStyle(celicaStil);
                                _range[donghientai + vitri + i + 5, 9].SetStyle(celicaStil);
                            }
                        }
                        vitri = vitri + 5;
                    }
                }
                vitri = vitri + 5;
            }

            #endregion

            exBook.Save("BC_KhuVuc.xls", SaveType.OpenInExcel, FileFormatType.Default, this.Response);
            //Response.Redirect("../BaoCao/Report.aspx?Loai=5&strSQL=" + strTruyVan);
        }