Exemplo n.º 1
0
        protected void lblExpenseMeessageDownload_Click(object sender, EventArgs e)
        {
            DataTable dt;
            int       stairCase;

            if (int.TryParse(drpDisplayMode.SelectedValue, out stairCase))
            {
                dt = ApartmentExpensesManager.GetMonthlyRaportAsDataTable(Association.Id, Year, Month, stairCase);
                dt.Rows.Add(new TableCell());
            }
            else
            {
                dt = ApartmentExpensesManager.GetMonthlyRaportAsDataTable(Association.Id, Year, Month, null);
            }

            MemoryStream stream;

            using (XLWorkbook wb = new XLWorkbook())
            {
                var ws = wb.Worksheets.Add(dt, "Cheltuieli");
                ws.Row(1).InsertRowsAbove(1);

                ws.Cells("A1").Value = ws.Cell(2, 1).Value;
                ws.Range("A1:A2").Merge();

                ws.Cells("B1").Value = ws.Cell(2, 2).Value;
                ws.Range("B1:B2").Merge();

                ws.Cells("C1").Value = ws.Cell(3, 2).Value;
                ws.Range("C1:C2").Merge();

                ws.Cells("D1").Value = ws.Cell(4, 2).Value;
                ws.Range("D1:D2").Merge();

                var  expenses = AssociationExpensesManager.GetByMonthAndYearNotDisabled(Association.Id, Year, Month).GroupBy(ee => ee.Id_ExpenseType).OrderBy(er => er.Key);
                char position = 'E';
                foreach (var expense in expenses)
                {
                    var tempPosition = position;
                    position = (char)(position + expense.ToList().Count - 1);
                    var range = string.Format("{0}1:{1}1", tempPosition.ToString(), position.ToString());
                    ws.Cells(tempPosition + "1").Value = expense.FirstOrDefault().ExpenseTypes.Name;
                    ws.Range(range).Merge();
                    position = (char)(position + 1);
                }

                stream = GetStream(wb);
            }

            string myName = Server.UrlEncode("Cheltuieli" + "_" + DateTime.Now.ToShortDateString() + ".xlsx");

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=" + myName);
            Response.ContentType = "application/vnd.ms-excel";
            Response.BinaryWrite(stream.ToArray());
            Response.Flush();
            Response.SuppressContent = true;
        }
Exemplo n.º 2
0
        private void InitializeGridView(int?stairCase = null)
        {
            RecalculationManager.RecalculateMonthlyExpenses(Association.Id, Year, Month);

            var dt = ApartmentExpensesManager.GetMonthlyRaportAsDataTable(Association.Id, Year, Month, stairCase);

            ViewState["dt"]      = dt;
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }