コード例 #1
0
        private void createReport(bool isCart)
        {
            string nameFile = DateTime.Now.ToShortDateString() + " - " + (isCart ? "Нал." : "БезНал.");

            DataTable dtTmp = Config.hCntMain.getReportPayment(true, isCart);

            if (dtTmp == null || dtTmp.Rows.Count == 0)
            {
                MessageBox.Show("Данных для печати нет"); return;
            }
            ;

            var groupedData
                = from b in dtTmp.AsEnumerable()
                  group b by new { id_Department = b.Field <Int32>("id_Department") } into g
                select new
            {
                id_Department = g.Key.id_Department
                                //  netto = g.Sum(x => x.Field<decimal>("netto"))
            };

            Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad("Лист - 1");

            int indexRow = 1;

            report.Merge(indexRow, 1, indexRow, 6);
            report.AddSingleValue("Отчёт по выданным " + (isCart ? "Безнал." : "Нал.") + " ДС ", indexRow, 1);
            report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 1);
            report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1);
            report.SetFontSize(indexRow, 1, indexRow, 1, 16);
            report.SetFontBold(indexRow, 1, indexRow, 1);
            indexRow++;
            indexRow++;

            report.Merge(indexRow, 1, indexRow, 6);
            report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1);
            indexRow++;

            report.Merge(indexRow, 1, indexRow, 6);
            report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1);
            indexRow++;
            indexRow++;

            report.AddSingleValue("№ СЗ", indexRow, 1);
            report.AddSingleValue("Описание", indexRow, 2);
            report.AddSingleValue("Должность", indexRow, 3);
            report.AddSingleValue("Сумма", indexRow, 4);
            report.AddSingleValue("Дата", indexRow, 5);
            report.AddSingleValue("Подпись руководителя", indexRow, 6);
            report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 6);
            report.SetBorders(indexRow, 1, indexRow, 6);
            indexRow++;


            foreach (var grp in groupedData)
            {
                DataRow[] row = dtTmp.Select(string.Format("id_Department = {0}", grp.id_Department));
                report.Merge(indexRow, 1, indexRow, 6);
                report.AddSingleValue(row[0]["nameDeps"].ToString(), indexRow, 1);
                report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 6);
                report.SetBorders(indexRow, 1, indexRow, 6);
                indexRow++;

                foreach (DataRow r in row)
                {
                    report.AddSingleValue(r["Number"].ToString(), indexRow, 1);
                    report.AddSingleValue(r["Description"].ToString(), indexRow, 2);
                    report.AddSingleValue(r["FIO"].ToString(), indexRow, 3);
                    report.AddSingleValue(r["Summa"].ToString(), indexRow, 4);
                    report.AddSingleValue(r["DataSumma"].ToString(), indexRow, 5);
                    //report.AddSingleValue(r["Summa"].ToString(), indexRow, 6);

                    report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 4);
                    report.SetBorders(indexRow, 1, indexRow, 6);
                    indexRow++;
                }
            }

            report.SetColumnAutoSize(6, 1, indexRow - 1, 6);
            //report.Show();
            report.SaveToFile(@"Report\" + nameFile + ".xlsx");
        }