Esempio n. 1
0
        /// <summary>
        /// 列出sales 每个月的业绩(以收到钱为准),并和上一个月比较
        /// </summary>
        /// <param name="Year"></param>
        /// <param name="Month">每2个月的后面那个月</param>
        private void SalesByPerson(int Year, int Month)
        {
            //read the template via FileStream, it is suggested to use FileAccess.Read to prevent file lock.
            FileStream file = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Invoice\\SalesByPerson_Template.xls", FileMode.Open, FileAccess.Read);

            HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
            HSSFSheet    sheet1       = hssfworkbook.GetSheetAt(0);

            int       Cnt = Ticket.GetTicketCountByMonth(Year, Month);
            int       PrevCnt;
            DataTable dt, dtPrevYear = new DataTable();

            //现在Month参数没有用到,一次把每年12个月的数值都取出来
            dt = Ticket.GetMonthlyProfit(Year);
            //如果是1月份,要把去年12月份的数据取出来
            if (Month == 1)
            {
                dtPrevYear = Ticket.GetMonthlyProfit(Year - 1);
                PrevCnt    = Ticket.GetTicketCountByMonth(Year - 1, 12);
            }
            else
            {
                PrevCnt = Ticket.GetTicketCountByMonth(Year, Month - 1);
            }

            FillExcelPersonProfit(sheet1, dt, dtPrevYear, Month, ddlDept2.Text, Cnt, PrevCnt);


            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;
            string FullFileName = AppDomain.CurrentDomain.BaseDirectory + "Upload\\Excel\\SalesByPerson_" + Year.ToString() + "_" + Month.ToString("00") + ".xls";

            file = new FileStream(FullFileName, FileMode.Create);
            hssfworkbook.Write(file);
            file.Close();
            DownloadFileAsAttachment(FullFileName);
        }