private static void setValueToCell(int indexRow, int indexCol, object value, Nwuram.Framework.ToExcelNew.ExcelUnLoad report) { if (value is DateTime) { report.AddSingleValue(((DateTime)value).ToShortDateString(), indexRow, indexCol); } else if (value is decimal || value is double) { report.AddSingleValueObject(value, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else if (value is int) { report.AddSingleValueObject(value, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0"); } else if (value is bool) { report.AddSingleValue((bool)value ? "+" : "", indexRow, indexCol); } else { report.AddSingleValue(value.ToString(), indexRow, indexCol); } }
private void addDataToCell(object value, int indexRow, int indexCol, Nwuram.Framework.ToExcelNew.ExcelUnLoad report, bool isFullTime = false) { if (value is DateTime) { if (isFullTime) { report.AddSingleValue(((DateTime)value).ToString(), indexRow, indexCol); } else { report.AddSingleValue(((DateTime)value).ToShortDateString(), indexRow, indexCol); } } else if (value is bool) { report.AddSingleValue((bool)value ? "Да" : "Нет", indexRow, indexCol); } else if (value is decimal || value is double) { report.AddSingleValueObject(value, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(value.ToString(), indexRow, indexCol); } }
private void setValueToCell(int indexRow, int indexCol, object value) { if (value is DateTime) { report.AddSingleValue(((DateTime)value).ToShortDateString(), indexRow, indexCol); } else if (value is decimal || value is double) { report.AddSingleValueObject(value, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else if (value is int) { report.AddSingleValueObject(value, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0"); } else { report.AddSingleValue(value.ToString(), indexRow, indexCol); } }
private void addDataToCell(DataRowView row, int indexRow, int indexCol, string nameCol, Nwuram.Framework.ToExcelNew.ExcelUnLoad report) { if (row[nameCol] is DateTime) { report.AddSingleValue(((DateTime)row[nameCol]).ToShortDateString(), indexRow, indexCol); } else if (row[nameCol] is bool) { report.AddSingleValue((bool)row[nameCol] ? "Да" : "Нет", indexRow, indexCol); } else if (row[nameCol] is decimal) { report.AddSingleValueObject(row[nameCol], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[nameCol].ToString(), indexRow, indexCol); } }
private void btPrint_Click(object sender, EventArgs e) { Logging.StartFirstLevel(79); foreach (Control cnt in this.Controls) { if (!cnt.Visible) { continue; } if (cnt is TextBox) { Logging.Comment($"{cnt.Tag}: {cnt.Text}"); } } Logging.Comment($"Объект ID:{cmbObject.SelectedValue}; Наименование:{cmbObject.Text}"); Logging.Comment($"Тип договора ID:{cmbTypeDoc.SelectedValue}; Наименование:{cmbTypeDoc.Text}"); Logging.Comment($"Тип оплат ID:{cmbTypePayment.SelectedValue}; Наименование:{cmbTypePayment.Text}"); foreach (Control cnt in this.groupBox1.Controls) { if (!cnt.Visible) { continue; } if (cnt is RadioButton) { if ((cnt as RadioButton).Checked) { Logging.Comment($"Тип долгов:{cnt.Text}"); break; } } } Logging.StopFirstLevel(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; int indexSumPay = 9, indexSumItogSum = 10, indexSumOwe = 11; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("nameTenant")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cAgreements")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cObject")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cPlace")) { setWidthColumn(indexRow, maxColumns, 35, report); } if (col.Name.Equals("cSumMeter")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cSumDoc")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cSumPay")) { indexSumPay = maxColumns; setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("cSumItogSum")) { indexSumItogSum = maxColumns; setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cSumOwe")) { indexSumOwe = maxColumns; setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cPrcOwe")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cDateCloseSection")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cNameAddPayment")) { setWidthColumn(indexRow, maxColumns, 23, report); } //Console.WriteLine(col.Name); } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Журнал должников по {(rbPayDopDoc.Checked?"доп.":"")} оплатам", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Объект аренды: {cmbObject.Text}", indexRow, 1); indexRow++; if (tbAgreements.Text.Trim().Length > 0 || tbTenant.Text.Trim().Length > 0 || tbPlace.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтры: " + $"{(tbTenant.Text.Trim().Length == 0 ? "" : "Арендатор: " + tbTenant.Text.Trim())} " + $"{(tbPlace.Text.Trim().Length == 0 ? "" : " Местоположение места аренды: " + tbPlace.Text.Trim())} " + $"{(tbAgreements.Text.Trim().Length == 0 ? "" : " Номер договора: " + tbAgreements.Text.Trim())}", indexRow, 1); 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++; #endregion #region "Блок для долгов" indexRow++; var ResultGroup = dtData.DefaultView.ToTable().AsEnumerable().GroupBy(r => r.Field <int>("id_Tenant")); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Общее кол-во должников: {ResultGroup.Count()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Кол-во секций с долгами: {dtData.DefaultView.Count}", indexRow, 1); indexRow++; EnumerableRowCollection <DataRow> RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 100); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Кол-во должников с долгом от 100% и выше: {RowCollect.Count()}", indexRow, 1); indexRow++; RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 50 && r.Field <decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") <= 99); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Кол-во должников с долгом от 50 до 99%: {RowCollect.Count()}", indexRow, 1); indexRow++; RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 0 && r.Field <decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") <= 49); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Кол-во должников с долгом от 0 до 49%: {RowCollect.Count()}", indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetPrintRepeatHead(indexRow, indexRow); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } #region "Bottom" report.AddSingleValue($"Итого", indexRow, 1); report.SetBorders(indexRow, 1, indexRow, 1); object varSum = dtData.DefaultView.ToTable().Compute($"SUM({(rbPayDoc.Checked ? "SummaPaymentFine_1" : "SummaPaymentFine_2")})", ""); report.AddSingleValue($"{((decimal)varSum).ToString("0.00")}", indexRow, indexSumPay); varSum = dtData.DefaultView.ToTable().Compute($"SUM({(rbPayDoc.Checked ? "SummaFine_1" : "SummaFine_2")})", ""); report.AddSingleValue($"{((decimal)varSum).ToString("0.00")}", indexRow, indexSumItogSum); varSum = dtData.DefaultView.ToTable().Compute($"SUM({(rbPayDoc.Checked ? "SummaPenny_1" : "SummaPenny_2")})", ""); report.AddSingleValue($"{((decimal)varSum).ToString("0.00")}", indexRow, indexSumOwe); report.SetFormat(indexRow, indexSumPay, indexRow, indexSumOwe, "0.00"); report.SetBorders(indexRow, indexSumPay, indexRow, indexSumOwe); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; /* * indexRow++; * var ResultGroup = dtData.DefaultView.ToTable().AsEnumerable().GroupBy(r => r.Field<int>("id_Tenant")); * report.Merge(indexRow, 1, indexRow, maxColumns); * report.AddSingleValue($"Общее кол-во должников: {ResultGroup.Count()}", indexRow, 1); * indexRow++; * * * EnumerableRowCollection<DataRow> RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field<decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 100); * report.Merge(indexRow, 1, indexRow, maxColumns); * report.AddSingleValue($"Кол-во должников с долгом от 100% и выше: {RowCollect.Count()}", indexRow, 1); * indexRow++; * * RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field<decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 50 && r.Field<decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") <= 99); * report.Merge(indexRow, 1, indexRow, maxColumns); * report.AddSingleValue($"Кол-во должников с долгом от 50 до 99%: {RowCollect.Count()}", indexRow, 1); * indexRow++; * * * RowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field<decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") >= 0 && r.Field<decimal>(rbPayDoc.Checked ? "PrcPenny_1" : "PrcPenny_2") <= 49); * report.Merge(indexRow, 1, indexRow, maxColumns); * report.AddSingleValue($"Кол-во должников с долгом от 0 до 49%: {RowCollect.Count()}", indexRow, 1); * indexRow++; */ #endregion report.SetPageSetup(1, 9999, true); /* * var groupByPost = dtData.DefaultView.ToTable().AsEnumerable().GroupBy(r => new { id = r.Field<int>("id_Tenant") }) * .Select(s => new { s.Key.id }); * * foreach (var gPost in groupByPost) * { * EnumerableRowCollection<DataRow> rowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field<int>("id_Tenant") == gPost.id); * int startMergRow = indexRow; * * foreach (DataRow row in rowCollect) * { * indexCol = 1; * report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); * foreach (DataGridViewColumn col in dgvData.Columns) * { * if (col.Visible) * { * if (new List<int>() { nameTenant.Index, cSumPay.Index, cSumItogSum.Index, cSumOwe.Index, cPrcOwe.Index }.Contains(col.Index)) * { * indexCol++; * continue; * } * * * if (row[col.DataPropertyName] is DateTime) * report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); * else * if (row[col.DataPropertyName] is decimal) * { * report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); * report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); * } * else * report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); * * indexCol++; * } * } * * report.SetBorders(indexRow, 1, indexRow, maxColumns); * report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); * report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); * indexRow++; * } * * indexCol = 1; * foreach (DataGridViewColumn col in dgvData.Columns) * { * if (new List<int>() { nameTenant.Index, cSumPay.Index, cSumItogSum.Index, cSumOwe.Index, cPrcOwe.Index }.Contains(col.Index)) * { * report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); * * if (rowCollect.First()[col.DataPropertyName] is DateTime) * report.AddSingleValue(((DateTime)rowCollect.First()[col.DataPropertyName]).ToShortDateString(), startMergRow, indexCol); * else * if (rowCollect.First()[col.DataPropertyName] is decimal) * { * report.AddSingleValueObject(rowCollect.First()[col.DataPropertyName], startMergRow, indexCol); * report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); * } * else * report.AddSingleValue(rowCollect.First()[col.DataPropertyName].ToString(), startMergRow, indexCol); * * } * indexCol++; * } * } */ report.Show(); }
private void btPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cName")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cDeps")) { setWidthColumn(indexRow, maxColumns, 22, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Справочник подгрупп", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; if (tbName.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {tbName.Text}", indexRow, 1); indexRow++; } //if (tbAgreements.Text.Trim().Length > 0 || tbTenant.Text.Trim().Length > 0 || tbPlace.Text.Trim().Length > 0) //{ // report.Merge(indexRow, 1, indexRow, maxColumns); // report.AddSingleValue($"Фильтры: " + // $"{(tbTenant.Text.Trim().Length == 0 ? "" : "Арендатор: " + tbTenant.Text.Trim())} " + // $"{(tbPlace.Text.Trim().Length == 0 ? "" : " Местоположение места аренды: " + tbPlace.Text.Trim())} " + // $"{(tbAgreements.Text.Trim().Length == 0 ? "" : " Номер договора: " + tbAgreements.Text.Trim())}", indexRow, 1); // indexRow++; //} report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); if (!(bool)row["isActive"]) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel1.BackColor); } indexRow++; } indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbNotActive.Text}", indexRow, 2); report.Show(); }
private void addTabExcel(int id_otdel, string nameDep) { int indexRow = 1; int maxColumns = 0; DataTable dtReport = dtData.DefaultView.ToTable(); if (id_otdel != 0) { dtReport.DefaultView.RowFilter = $"id_otdel = {id_otdel}"; } if (dtReport.DefaultView.Count == 0) { return; } if (report == null) { report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); report.changeNameTab($"{nameDep}"); } else { report.GoToNextSheet($"{nameDep}"); } Config.DoOnUIThread(() => { foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals(cDeps.Name)) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals(cEan.Name)) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals(cName.Name)) { setWidthColumn(indexRow, maxColumns, 30, report); } if (col.Name.Equals(cPriceK21.Name)) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals(cPriceX14.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cDelta.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } } } }, this); #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по расхождениям продажных цен по товарам", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; Config.DoOnUIThread(() => { if (chbPeriod.Checked) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Продажи с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Т/У группа: {cmbGrp1.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Инв. группа: {cmbGrp2.Text}", indexRow, 1); indexRow++; if (tbEan.Text.Trim().Length != 0 || tbName.Text.Trim().Length != 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {(tbEan.Text.Trim().Length != 0 ? $"EAN:{tbEan.Text.Trim()} | " : "")} {(tbName.Text.Trim().Length != 0 ? $"Наименование:{tbName.Text.Trim()}" : "")}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); }, this); indexRow++; indexRow++; #endregion int indexCol = 0; Config.DoOnUIThread(() => { foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } }, this); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtReport.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); Config.DoOnUIThread(() => { if (new List <int>(new int[] { 1, 3 }).Contains((int)row["ntypetovar"])) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, pReserv.BackColor); } else if ((bool)row["isPromo"]) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, pPromo.BackColor); } }, this); indexRow++; } indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, pPromo.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbDiscount.Text}", indexRow, 2); indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, pReserv.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbReserv.Text}", indexRow, 2); }
private async void btPrint_Click(object sender, EventArgs e) { report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); progressBar1.Visible = true; var result = await Task <bool> .Factory.StartNew(() => { foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals(cDeps.Name)) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals(cGrp1.Name)) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals(cGrp2.Name)) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals(cEan.Name)) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals(cName.Name)) { setWidthColumn(indexRow, maxColumns, 40, report); } if (col.Name.Equals(cPrice.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } if (col.Name.Equals(cGrp3.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; Config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Магазин: {cmbShop.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Т/У группа: {cmbGrp1.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Инв. группа: {cmbGrp2.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Подгруппы: {cmbGrp3.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Новый товар: {(chbNewGoods.Checked ? "Да":"Нет")}", indexRow, 1); indexRow++; if (tbEan.Text.Trim().Length != 0 || tbName.Text.Trim().Length != 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {(tbEan.Text.Trim().Length != 0 ? $"EAN:{tbEan.Text.Trim()} | " : "")} {(tbName.Text.Trim().Length != 0 ? $"Наименование:{tbName.Text.Trim()}" : "")}", indexRow, 1); indexRow++; } }, this); //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Должность: {cmbPost.Text}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Место работы: {(rbOffice.Checked ? rbOffice.Text : rbUni.Text)}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Статус сотрудника: {(rbWork.Checked ? rbWork.Text : rbUnemploy.Text)}", indexRow, 1); //indexRow++; //if (tbPostName.Text.Trim().Length != 0 || tbKadrName.Text.Trim().Length != 0) //{ // report.Merge(indexRow, 1, indexRow, maxColumns); // report.AddSingleValue($"Фильтр: {(tbPostName.Text.Trim().Length != 0 ? $"Должность:{tbPostName.Text.Trim()} | " : "")} {(tbKadrName.Text.Trim().Length != 0 ? $"ФИО:{tbKadrName.Text.Trim()}" : "")}", indexRow, 1); // indexRow++; //} report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } if (chbReserv.Checked && new List <int>(new int[] { 1, 3 }).Contains((int)row["ntypetovar"])) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel1.BackColor); } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } if (chbReserv.Checked) { indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbReserv.Text}", indexRow, 2); } Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); report.Show(); return(true); }); }
public static void createReport(DataTable dtReport, string _nameObject, string status, DateTime _startDate) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; Control[] cnt = new frmAddReportMonth().Controls.Find("dgvData", false); DataGridView dgvData = (DataGridView)cnt[0]; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("nameLandLord")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("nameTenant")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("TypeContract")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cAgreements")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("timeLimit")) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals("cBuild")) { setWidthColumn(indexRow, maxColumns, 9, report); } if (col.Name.Equals("cFloor")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cSection")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cSquart")) { setWidthColumn(indexRow, maxColumns, 12, report); } if (col.Name.Equals("Cost_of_Meter")) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals("cSumDog")) { setWidthColumn(indexRow, maxColumns, 19, report); } if (col.Name.Equals("cDiscount")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cPlane")) { setWidthColumn(indexRow, maxColumns, 20, report); } //Console.WriteLine(col.Name); } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Ежемесячный отчёт", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; string[] monthNames = DateTimeFormatInfo.CurrentInfo.MonthNames; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Период ежемесячного отчёта {monthNames[_startDate.Month-1]}.{_startDate.Year}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Объект аренды: {_nameObject}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Статус: {status}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; var groupByPost = dtReport.DefaultView.ToTable().AsEnumerable().GroupBy(r => new { id = r.Field <int>("id_Landlord") }) .Select(s => new { s.Key.id, sumPlan = s.Sum(r => r.Field <decimal>("plane")) }); decimal maxResultPlane = 0; foreach (var gPost in groupByPost) { EnumerableRowCollection <DataRow> rowCollect = dtReport.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <int>("id_Landlord") == gPost.id); int startMergRow = indexRow; foreach (DataRow row in rowCollect) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (new List <string>() { "nameLandLord" }.Contains(col.Name)) { indexCol++; continue; } if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } indexCol = 1; foreach (DataGridViewColumn col in dgvData.Columns) { if (new List <string>() { "nameLandLord" }.Contains(col.Name)) { report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); if (rowCollect.First()[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)rowCollect.First()[col.DataPropertyName]).ToShortDateString(), startMergRow, indexCol); } else if (rowCollect.First()[col.DataPropertyName] is decimal) { report.AddSingleValueObject(rowCollect.First()[col.DataPropertyName], startMergRow, indexCol); report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); } else { report.AddSingleValue(rowCollect.First()[col.DataPropertyName].ToString(), startMergRow, indexCol); } } else if (new List <string>() { "cPlane" }.Contains(col.Name)) { report.AddSingleValueObject(gPost.sumPlan, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); report.Merge(indexRow, 1, indexRow, indexCol - 1); report.AddSingleValue("Итого:", indexRow, 1); report.SetCellAlignmentToRight(indexRow, 1, indexRow, indexCol - 1); indexRow++; } indexCol++; } maxResultPlane += gPost.sumPlan; } report.AddSingleValueObject(maxResultPlane, indexRow, maxColumns); report.SetFormat(indexRow, maxColumns, indexRow, maxColumns, "0.00"); report.Merge(indexRow, 1, indexRow, maxColumns - 1); report.AddSingleValue("Итого:", indexRow, 1); report.SetCellAlignmentToRight(indexRow, 1, indexRow, maxColumns - 1); report.SetFontBold(indexRow, 1, indexRow, maxColumns); indexRow++; report.Show(); }
private void btPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cName")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cDeps")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cUniGrp")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cReglam")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cLimitTovar")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cLimitInut")) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("cLimitDay")) { setWidthColumn(indexRow, maxColumns, 16, report); } if (col.Name.Equals("cUnit")) { setWidthColumn(indexRow, maxColumns, 10, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Справочник подгрупп", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{label2.Text}: {cmbUniGrp.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{chbReglam.Text.Replace("-","")}: {(chbReglam.Checked ? "Да" : "Нет")}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{chbLimitTovar.Text.Replace("-", "")}: {(chbLimitTovar.Checked?"Да":"Нет")}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{gTypeGrp.Text}: {(rbAll.Checked ? rbAll.Text : rbNetto.Checked ? rbNetto.Text : rbUnit.Checked ? rbUnit.Text : "")}", indexRow, 1); indexRow++; if (tbName.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {tbName.Text}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is bool) { report.AddSingleValue((bool)row[col.DataPropertyName] ? "Да" : "Нет", indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); if (!(bool)row["isActive"]) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel1.BackColor); } indexRow++; } indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbNotActive.Text}", indexRow, 2); report.Show(); }
private void btPrintPopularTovar_Click(object sender, EventArgs e) { if (dtPopularTovar == null || dtPopularTovar.DefaultView.Count == 0) { return; } Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvDataTovar.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cPeriod")) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals("cEan")) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals("cNameTovar")) { setWidthColumn(indexRow, maxColumns, 36, report); } if (col.Name.Equals("cPrice")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cCount")) { setWidthColumn(indexRow, maxColumns, 12, report); } if (col.Name.Equals("cPrcPopular")) { setWidthColumn(indexRow, maxColumns, 20, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по популярным товарам", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvDataTovar.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtPopularTovar.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvDataTovar.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.Show(); #region log Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка статистики по онлайн магазину по популярным товарам"); DataTable dtPeriod = dgvPeriod.DataSource as DataTable; int id_Period = (int)cmbPeriod.SelectedValue; DateTime dateStart, dateEnd; var rows = dtPopularTovar.DefaultView.ToTable().AsEnumerable().GroupBy(r => r.Field <string>("namePeriod")).Select(s => s.Key); if (rows.Count() > 0) { string listPeriod = ""; foreach (string row in rows) { listPeriod += $"Период: {row}"; } Logging.Comment($"Период: {listPeriod}"); } /*if (id_Period!=0) * { * EnumerableRowCollection<DataRow> rcoll = dtPeriod.AsEnumerable().Where(r => r.Field<int>("id") == id_Period); * dateStart =(DateTime) rcoll.FirstOrDefault()["dateStart"]; * dateEnd = (DateTime)rcoll.FirstOrDefault()["dateEnd"]; * } * else * { * dateStart = dtPeriod.AsEnumerable().Min(r => r.Field<DateTime>("dateStart")); * dateEnd = dtPeriod.AsEnumerable().Max(r => r.Field<DateTime>("dateEnd")); * } * Logging.Comment($"Наименование периода: {cmbPeriod.Text}, Дата начала периода: {dateStart.ToShortDateString()}, Дата окончания периода: {dateEnd.ToShortDateString()}"); */ Logging.Comment($"Отдел: id: {cmbDeps.SelectedValue.ToString()}, Наименование: {cmbDeps.Text}"); Logging.Comment($"Доля заказов с товаром: {tbPercentOrder.Text}"); Logging.Comment("Завершение выгрузки статистики по популярным товарам"); Logging.StopFirstLevel(); #endregion }
private async void btPrint_Click(object sender, EventArgs e) { if (dtJour == null || dtJour.Rows.Count == 0 || dtJour.DefaultView.Count == 0) { MessageBox.Show("Нет данных для формирования отчёта.", "Печать", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); //progressBar1.Visible = true; var result = await Task <bool> .Factory.StartNew(() => { foreach (DataGridViewColumn col in dgvJour.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals(cJouDate.Name)) { setWidthColumn(indexRow, maxColumns, 37, report); } if (col.Name.Equals(cJouNumber.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cJouMol.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cJouCount.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cJouComment.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cJouType.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Движение расходных материалов", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Тип операции {cmbTypeOperation.Text} ", indexRow, 1); indexRow++; }, this); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvJour.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtJour.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvJour.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); //progressBar1.Visible = false; }, this); report.Show(); return(true); }); }
private async void btnPrint_Click(object sender, EventArgs e) { if (!chbCancel.Checked && !chbComplete.Checked && !chbЕmployesОrder.Checked) { return; } int id_Shop = (int)cmbShop.SelectedValue; var outer = Task.Factory.StartNew(() => // внешняя задача { Config.DoOnUIThread(() => { blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); //progressBar1.Visible = progressBar1.Enabled = true; fLoad = new Nwuram.Framework.UI.Forms.frmLoad(); fLoad.TopMost = false; fLoad.Owner = this; fLoad.TextWait = "Грузим отчётик!"; fLoad.Show(); }, this); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); bool isShow = false; if (chbComplete.Checked) { DataTable dtDataStatus3 = Config.connect.getReportData(dtpStart.Value, dtpEnd.Value, 3, id_Shop); DataTable dtDataStatus3Body = (id_Shop == 1 ? Config.connect : Config.hCntSecond).getSumNotesOrderWithRCena(dtpStart.Value, dtpEnd.Value, 3, id_Shop); if (dtDataStatus3 != null && dtDataStatus3.Rows.Count > 0) { isShow = true; report.changeNameTab("Выполненные"); decimal sumOrder = 0, sumNote = 0, SummaDelivery = 0, sumPackage = 0, DeliveryCost = 0, valueOst = 0, valueDelta = 0; int indexRow = 1; int maxColumns = 12; setWidthColumn(indexRow, 1, 6, report); setWidthColumn(indexRow, 2, 10, report); setWidthColumn(indexRow, 3, 17, report); setWidthColumn(indexRow, 4, 11, report); setWidthColumn(indexRow, 5, 16, report); setWidthColumn(indexRow, 6, 22, report); setWidthColumn(indexRow, 7, 16, report); setWidthColumn(indexRow, 8, 12, report); setWidthColumn(indexRow, 9, 14, report); setWidthColumn(indexRow, 10, 16, report); setWidthColumn(indexRow, 11, 16, report); setWidthColumn(indexRow, 12, 13, report); #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт об выполненных заказах с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion 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.AddSingleValue("Стоимость доставки", indexRow, 7); report.AddSingleValue("Кол-во пакетов", indexRow, 8); report.AddSingleValue("Стоимость пакетов", indexRow, 9); report.AddSingleValue("Затраты на доставку", indexRow, 10); report.AddSingleValue("Остаток по доставке", indexRow, 11); report.AddSingleValue("∆ по чеку", indexRow, 12); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; int npp = 1; var groupOrder = dtDataStatus3.AsEnumerable() .GroupBy(r => new { id_tOrders = r.Field <int>("id_tOrders") }) .Select(g => new { g.Key.id_tOrders, sumNote = g.Sum(r => r.Field <decimal>("sumNote")) }); foreach (var g in groupOrder) { EnumerableRowCollection <DataRow> rowCollect = dtDataStatus3.AsEnumerable().Where(r => r.Field <int>("id_tOrders") == g.id_tOrders); DataRow row = rowCollect.First(); int startRow = indexRow; report.SetWrapText(indexRow, 1, indexRow + rowCollect.Count() - 1, maxColumns); report.Merge(indexRow, 1, indexRow + rowCollect.Count() - 1, 1); report.Merge(indexRow, 2, indexRow + rowCollect.Count() - 1, 2); report.Merge(indexRow, 3, indexRow + rowCollect.Count() - 1, 3); report.Merge(indexRow, 4, indexRow + rowCollect.Count() - 1, 4); report.Merge(indexRow, 5, indexRow + rowCollect.Count() - 1, 5); report.Merge(indexRow, 7, indexRow + rowCollect.Count() - 1, 7); report.Merge(indexRow, 8, indexRow + rowCollect.Count() - 1, 8); report.Merge(indexRow, 9, indexRow + rowCollect.Count() - 1, 9); report.Merge(indexRow, 10, indexRow + rowCollect.Count() - 1, 10); report.Merge(indexRow, 11, indexRow + rowCollect.Count() - 1, 11); report.Merge(indexRow, 12, indexRow + rowCollect.Count() - 1, 12); report.AddSingleValue(npp.ToString(), indexRow, 1); report.AddSingleValue(row["OrderNumber"].ToString(), indexRow, 2); report.AddSingleValueObject(row["sumOrder"], indexRow, 3); report.SetFormat(indexRow, 3, indexRow, 3, "0.00"); report.AddSingleValue(((DateTime)row["DeliveryDate"]).ToShortDateString(), indexRow, 4); report.AddSingleValueObject(g.sumNote, indexRow, 5); report.SetFormat(indexRow, 5, indexRow, 5, "0.00"); report.AddSingleValueObject(row["SummaDelivery"], indexRow, 7); report.SetFormat(indexRow, 7, indexRow, 7, "0.00"); report.AddSingleValueObject(row["CountPackage"], indexRow, 8); report.SetFormat(indexRow, 8, indexRow, 8, "0.00"); report.AddSingleValueObject(row["sumPackage"], indexRow, 9); report.SetFormat(indexRow, 9, indexRow, 9, "0.00"); report.AddSingleValueObject(row["DeliveryCost"], indexRow, 10); report.SetFormat(indexRow, 10, indexRow, 10, "0.00"); sumOrder += (decimal)row["sumOrder"]; sumNote += g.sumNote; SummaDelivery += (decimal)row["SummaDelivery"]; sumPackage += (decimal)row["sumPackage"]; DeliveryCost += (decimal)row["DeliveryCost"]; decimal value = (decimal)row["SummaDelivery"] - (decimal)row["sumPackage"] - (decimal)row["DeliveryCost"]; valueOst += value; report.AddSingleValueObject(value, indexRow, 11); report.SetFormat(indexRow, 11, indexRow, 11, "0.00"); if (dtDataStatus3Body != null) { decimal sum = dtDataStatus3Body.AsEnumerable().Where(r => r.Field <int>("id_tOrders") == (int)row["id_tOrders"]).Sum(r => r.Field <decimal>("resultSum")); report.AddSingleValueObject(g.sumNote - sum, indexRow, 12); valueDelta += g.sumNote - sum; } else { report.AddSingleValueObject(0, indexRow, 12); } report.SetFormat(indexRow, 12, indexRow, 12, "0.00"); foreach (DataRow rowSelect in rowCollect) { //report.AddSingleValueObject(rowSelect["sumNote"], indexRow, 5); //report.SetFormat(indexRow, 5, indexRow, 5, "0.00"); report.AddSingleValue($"Касса:{rowSelect["KassNumber"]} Чек:{rowSelect["CheckNumber"]}", indexRow, 6); indexRow++; } report.SetBorders(startRow, 1, indexRow - 1, maxColumns); report.SetCellAlignmentToCenter(startRow, 1, indexRow - 1, maxColumns); report.SetCellAlignmentToJustify(startRow, 1, indexRow - 1, maxColumns); //indexRow++; npp++; } report.SetFormat(indexRow, 2, indexRow, maxColumns, "0.00"); report.AddSingleValue($"Итого:", indexRow, 1); report.AddSingleValueObject(sumOrder, indexRow, 3); report.AddSingleValueObject(sumNote, indexRow, 5); report.AddSingleValueObject(SummaDelivery, indexRow, 7); report.AddSingleValueObject(sumPackage, indexRow, 9); report.AddSingleValueObject(DeliveryCost, indexRow, 10); report.AddSingleValueObject(valueOst, indexRow, 11); report.AddSingleValueObject(valueDelta, indexRow, 12); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); } } if (chbCancel.Checked) { DataTable dtData = Config.connect.getReportData(dtpStart.Value, dtpEnd.Value, 4, id_Shop); if (dtData != null && dtData.Rows.Count > 0) { if (!isShow) { isShow = true; report.changeNameTab("Отменённые"); } else { report.GoToNextSheet("Отменённые"); } int indexRow = 1; int maxColumns = 9; decimal sumOrder = 0; setWidthColumn(indexRow, 1, 9, report); setWidthColumn(indexRow, 2, 20, report); setWidthColumn(indexRow, 3, 20, report); setWidthColumn(indexRow, 4, 16, report); setWidthColumn(indexRow, 5, 20, report); setWidthColumn(indexRow, 6, 18, report); setWidthColumn(indexRow, 7, 16, report); setWidthColumn(indexRow, 8, 16, report); setWidthColumn(indexRow, 9, 40, report); #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт об отменённых заказах с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion report.AddSingleValue("№ п/п", indexRow, 1); report.AddSingleValue("ФИО", indexRow, 2); report.AddSingleValue("Адрес", indexRow, 3); report.AddSingleValue("Телефон", indexRow, 4); report.AddSingleValue("e-mail", indexRow, 5); report.AddSingleValue("Номер заказа", indexRow, 6); report.AddSingleValue("Дата заказа", indexRow, 7); report.AddSingleValue("Сумма заказа", indexRow, 8); report.AddSingleValue("Комментарий об отмене заказа", indexRow, 9); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; int npp = 1; foreach (DataRowView row in dtData.DefaultView) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.AddSingleValue(npp.ToString(), indexRow, 1); report.AddSingleValue(row["FIO"].ToString(), indexRow, 2); report.AddSingleValue(row["Address"].ToString(), indexRow, 3); report.AddSingleValue(row["Phone"].ToString(), indexRow, 4); report.AddSingleValue(row["Email"].ToString(), indexRow, 5); report.AddSingleValue(row["OrderNumber"].ToString(), indexRow, 6); report.AddSingleValue(((DateTime)row["DateOrder"]).ToShortDateString(), indexRow, 7); report.AddSingleValueObject(row["sumOrder"], indexRow, 8); report.SetFormat(indexRow, 4, indexRow, 4, "0.00"); report.AddSingleValue(row["Comment"].ToString(), indexRow, 9); sumOrder += (decimal)row["sumOrder"]; report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; npp++; } report.SetFormat(indexRow, 2, indexRow, maxColumns, "0.00"); report.AddSingleValue($"Итого:", indexRow, 1); report.AddSingleValueObject(sumOrder, indexRow, 8); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); } } if (chbЕmployesОrder.Checked) { DataTable dtData = Config.connect.reportЕmployesОrder(dtpStart.Value, dtpEnd.Value, id_Shop); if (dtData != null && dtData.Rows.Count > 0) { if (!isShow) { isShow = true; report.changeNameTab("Отчет по сотрудникам"); } else { report.GoToNextSheet("Отчет по сотрудникам"); } int indexRow = 1; int maxColumns = 8; decimal sumOrder = 0; setWidthColumn(indexRow, 1, 9, report); setWidthColumn(indexRow, 2, 25, report); setWidthColumn(indexRow, 3, 16, report); setWidthColumn(indexRow, 4, 16, report); setWidthColumn(indexRow, 5, 16, report); setWidthColumn(indexRow, 6, 12, report); setWidthColumn(indexRow, 7, 12, report); setWidthColumn(indexRow, 8, 12, report); #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчет по сотрудникам с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion 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.AddSingleValue("Пробитие", indexRow, 7); report.AddSingleValue("Доставщик", indexRow, 8); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; var groupCountCollector = dtData.AsEnumerable() .Where(r => r.Field <bool>("Collector")) .GroupBy(g => new { OrderNumber = g.Field <int>("OrderNumber") }) .Select(s => new { s.Key.OrderNumber, countCollector = s.Count() }); var groupKadr = dtData.AsEnumerable().GroupBy(r => new { id_Kadr = r.Field <int>("id_Kadr"), FIO = r.Field <string>("FIO") }).Select(s => new { s.Key.id_Kadr, s.Key.FIO }); int npp = 1; Color cCompleted = Color.FromArgb(244, 255, 96); foreach (var gKadr in groupKadr) { EnumerableRowCollection <DataRow> rowCollect = dtData.AsEnumerable().Where(r => r.Field <int>("id_Kadr") == gKadr.id_Kadr).OrderBy(r => r.Field <int>("OrderNumber")); report.Merge(indexRow, 2, indexRow + rowCollect.Count() - 1, 2); setValueToCell(indexRow, 2, gKadr.FIO, report); var groupDate = rowCollect.AsEnumerable().GroupBy(g => new { DeliveryDate = g.Field <DateTime>("DeliveryDate") }).Select(s => new { s.Key.DeliveryDate }); decimal countCollector = 0; int countKassCheck = 0; int countDelivery = 0; foreach (var gDate in groupDate) { EnumerableRowCollection <DataRow> rowCollectDate = rowCollect.Where(r => r.Field <DateTime>("DeliveryDate") == gDate.DeliveryDate); report.Merge(indexRow, 3, indexRow + rowCollectDate.Count() - 1, 3); setValueToCell(indexRow, 3, gDate.DeliveryDate, report); foreach (DataRow row in rowCollectDate) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); setValueToCell(indexRow, 1, npp, report); setValueToCell(indexRow, 4, row["OrderNumber"], report); setValueToCell(indexRow, 5, row["countRow"], report); if ((bool)row["Collector"]) { decimal valResult = Convert.ToDecimal((int)row["countRow"]) / Convert.ToDecimal(groupCountCollector.Where(r => r.OrderNumber == (int)row["OrderNumber"]).First().countCollector); countCollector += valResult; setValueToCell(indexRow, 6, valResult, report); } if ((bool)row["KassCheck"]) { setValueToCell(indexRow, 7, row["KassCheck"], report); countKassCheck++; } if ((bool)row["Delivery"]) { setValueToCell(indexRow, 8, row["Delivery"], report); countDelivery++; } if (!(bool)row["isCompleted"]) { report.SetCellColor(indexRow, 4, indexRow, maxColumns, cCompleted); } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; npp++; } } report.Merge(indexRow, 1, indexRow, 5); setValueToCell(indexRow, 1, $"Итого:", report); setValueToCell(indexRow, 6, countCollector, report); setValueToCell(indexRow, 7, countKassCheck, report); setValueToCell(indexRow, 8, countDelivery, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToRight(indexRow, 1, indexRow, 1); //report.SetCellAlignmentToRight(indexRow, 6, indexRow, maxColumns); indexRow++; } report.SetCellColor(indexRow + 1, 1, indexRow + 1, 1, cCompleted); setValueToCell(indexRow + 1, 2, "-заказ не выполнен", report); } } Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); fLoad.Dispose(); }, this); if (isShow) { report.SetPageSetup(1, 9999, true); report.Show(); } else { MessageBox.Show("Нет данных для отчёта", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); } #region логирование Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка в Excel отчета по работе онлайн-магазина"); Logging.Comment($"Период с: {dtpStart.Value.ToShortDateString()} по: {dtpEnd.Value.ToShortDateString()}"); Logging.Comment($"Отчет о выполненых заказах: {(chbComplete.Checked ? "Да" : "Нет")}"); Logging.Comment($"Отчет об отмененных заказах: {(chbCancel.Checked ? "Да" : "Нет")}"); Logging.Comment("Завершение выгрузки отчета по работе онлайн магазина"); Logging.StopFirstLevel(); #endregion }); }
private void btPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible || col.Name.Equals(cDatePrintPass.Name) || col.Name.Equals(cPhone.Name)) { maxColumns++; if (col.Name.Equals(cDeps.Name)) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals(cPost.Name)) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals(cFIO.Name)) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals(cPass.Name)) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals(cDatePrintPass.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals(cPhone.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по пропускам", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Должность: {cmbPost.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Место работы: {(rbOffice.Checked?rbOffice.Text:rbUni.Text)}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Статус сотрудника: {(rbWork.Checked ? rbWork.Text : rbUnemploy.Text)}", indexRow, 1); indexRow++; if (tbPostName.Text.Trim().Length != 0 || tbKadrName.Text.Trim().Length != 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {(tbPostName.Text.Trim().Length != 0 ? $"Должность:{tbPostName.Text.Trim()} | ":"")} {(tbKadrName.Text.Trim().Length != 0 ? $"ФИО:{tbKadrName.Text.Trim()}" : "")}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible || col.Name.Equals(cDatePrintPass.Name) || col.Name.Equals(cPhone.Name)) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible || col.Name.Equals(cDatePrintPass.Name) || col.Name.Equals(cPhone.Name)) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.Show(); }
private void btnAllReport_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvHistory.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cDateEdit")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cStatus")) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("cFIO")) { setWidthColumn(indexRow, maxColumns, 19, report); } if (col.Name.Equals("cComment")) { setWidthColumn(indexRow, maxColumns, 22, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по истории статусов", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"№ заказа:{numOrder}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvHistory.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvHistory.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.Show(); #region log DataTable dtInfo = Config.connect.getOrderInfo(id); if (dtInfo == null || dtInfo.Rows.Count == 0) { return; } Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка журнала статусов заказа"); Logging.Comment($"id заказа: {id}"); Logging.Comment($"Номер заказа: {dtInfo.Rows[0]["OrderNumber"].ToString()}"); Logging.Comment($"Дата и время заказа: {dtInfo.Rows[0]["DateOrder"].ToString()}"); Logging.Comment($"ФИО покупателя: {dtInfo.Rows[0]["FIO"].ToString()}"); Logging.Comment($"Сумма заказа: {dtInfo.Rows[0]["sumOrder"].ToString()}"); Logging.Comment($"Сумма доставки: {dtInfo.Rows[0]["SummaDelivery"].ToString()}"); Logging.Comment($"Тип оплаты: {dtInfo.Rows[0]["namePayment"].ToString()}"); Logging.StopFirstLevel(); #endregion }
private void buttonPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in grdPrices.Columns) { if (col.Visible) { maxColumns++; /*if (col.Name.Equals(cDeps.Name)) setWidthColumn(indexRow, maxColumns, 18, report); * if (col.Name.Equals(cPost.Name)) setWidthColumn(indexRow, maxColumns, 18, report); * if (col.Name.Equals(cFIO.Name)) setWidthColumn(indexRow, maxColumns, 20, report); * if (col.Name.Equals(cPass.Name)) setWidthColumn(indexRow, maxColumns, 15, report); * if (col.Name.Equals(cDatePrintPass.Name)) setWidthColumn(indexRow, maxColumns, 17, report); * if (col.Name.Equals(cPhone.Name)) setWidthColumn(indexRow, maxColumns, 17, report);*/ } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Должность: {cmbPost.Text}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Место работы: {(rbOffice.Checked ? rbOffice.Text : rbUni.Text)}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Статус сотрудника: {(rbWork.Checked ? rbWork.Text : rbUnemploy.Text)}", indexRow, 1); //indexRow++; //if (tbPostName.Text.Trim().Length != 0 || tbKadrName.Text.Trim().Length != 0) //{ // report.Merge(indexRow, 1, indexRow, maxColumns); // report.AddSingleValue($"Фильтр: {(tbPostName.Text.Trim().Length != 0 ? $"Должность:{tbPostName.Text.Trim()} | " : "")} {(tbKadrName.Text.Trim().Length != 0 ? $"ФИО:{tbKadrName.Text.Trim()}" : "")}", indexRow, 1); // indexRow++; //} report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in grdPrices.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in pricesTable.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in grdPrices.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.SetColumnAutoSize(6, 1, indexRow, maxColumns); report.Show(); //if (grdPrices.DataSource != null) //{ // //Logging.StartFirstLevel(472); // //Logging.Comment("Выгрузка данных по товарам группы"); // string[] filePath = (Application.StartupPath + "\\tmp").Split(new char[] { '\\' }); // grdPrices.Refresh(); // DataTable printTable = pricesTable.Copy(); // if (stFilter != null) // { // printTable.DefaultView.RowFilter = stFilter; // } // Print(printTable.DefaultView.ToTable(), filePath[filePath.Length - 1]); //} }
private async void btViewCartGoods_Click(object sender, EventArgs e) { report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); TabPage tp = tabControl1.SelectedTab; DataGridView grd = null; DataTable dt = null; switch (tabControl1.SelectedIndex) { case 0: grd = dgvData; dt = dgvData.DataSource as DataTable; break; case 1: grd = dgvDataPrice; dt = dgvDataPrice.DataSource as DataTable; break; case 2: grd = dgvDataNewGoods; dt = dgvDataNewGoods.DataSource as DataTable; break; } int indexRow = 1; int maxColumns = 0; blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); progressBar1.Visible = true; var result = await Task <bool> .Factory.StartNew(() => { foreach (DataGridViewColumn col in grd.Columns) { if (col.Visible) { maxColumns++; if (new List <string>(new string[] { cDeps.Name, cNameDepPrice.Name, cNameDepNewGoods.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 13, report); } if (new List <string>(new string[] { cGrp1.Name, nameGrp1Atfer.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 13, report); } if (new List <string>(new string[] { cEan.Name, cEanPrice.Name, cEanNewGoods.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 15, report); } if (new List <string>(new string[] { cNameBefore.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 40, report); } if (new List <string>(new string[] { cNameAfter.Name, cNamePrice.Name, cNameNewGoods.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 40, report); } if (new List <string>(new string[] { cPriceBefore.Name, cPriceNewGoods.Name, cPriceAfter.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } if (new List <string>(new string[] { cSell.Name, cOstMorning.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } if (new List <string>(new string[] { cNdsBefore.Name, cNdsAfter.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } if (new List <string>(new string[] { cUlBefore.Name, cUlAfter.Name, cUlNewGoods.Name }).Contains(col.Name)) { setWidthColumn(indexRow, maxColumns, 11, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{tp.Text}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; Config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Магазин: {cmbShop.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{label4.Text}: {dtpDate.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Т/У группа: {cmbGrp1.Text}", indexRow, 1); indexRow++; //if (tbEan.Text.Trim().Length != 0 || tbName.Text.Trim().Length != 0) //{ // report.Merge(indexRow, 1, indexRow, maxColumns); // report.AddSingleValue($"Фильтр: {(tbEan.Text.Trim().Length != 0 ? $"EAN:{tbEan.Text.Trim()} | " : "")} {(tbName.Text.Trim().Length != 0 ? $"Наименование:{tbName.Text.Trim()}" : "")}", indexRow, 1); // indexRow++; //} }, this); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in grd.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dt.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in grd.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } if (chbReserv.Checked && (bool)row["isReserv"]) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel1.BackColor); } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } if (chbReserv.Checked) { indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbReserv.Text}", indexRow, 2); } Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); report.SetPageSetup(1, 9999, true); report.Show(); return(true); }); }
public static void createReport(DataTable dtReport, string _nameObject, string status, DateTime _startDate) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; List <string> listColumnsSum = new List <string>() { "preCredit", "preOverPayment", "prePlan", "EndPlan", "Penalty", "OtherPayments", "ultraResult", "Included", "Credit", "OverPayment" }; List <string> listColumnGroup = new List <string>() { "nameLandLord" }; Dictionary <string, int> dicColumnNameForIndex = new Dictionary <string, int>(); Control[] cnt = new frmAddReportPlane().Controls.Find("dgvData", false); DataGridView dgvData = (DataGridView)cnt[0]; int maxColumns = 0; bool isAddItog = false; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("nameLandLord")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("nameTenant")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("TypeContract")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cAgreements")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("timeLimit")) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals("cBuild")) { setWidthColumn(indexRow, maxColumns, 9, report); } if (col.Name.Equals("cFloor")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cSection")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cSquart")) { setWidthColumn(indexRow, maxColumns, 12, report); } if (col.Name.Equals("Cost_of_Meter")) { setWidthColumn(indexRow, maxColumns, 14, report); } if (col.Name.Equals("cSumDog")) { setWidthColumn(indexRow, maxColumns, 19, report); } if (col.Name.Equals("cDiscount")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("cPlane")) { setWidthColumn(indexRow, maxColumns, 20, report); } //Console.WriteLine(col.Name); dicColumnNameForIndex.Add(col.Name, maxColumns); } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("План отчёт", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; string[] monthNames = DateTimeFormatInfo.CurrentInfo.MonthNames; report.Merge(indexRow, 1, indexRow, maxColumns); //<<<<<<< HEAD report.AddSingleValue($"Период план-отчёта {monthNames[_startDate.Month-1]}.{_startDate.Year}", indexRow, 1); //======= // report.AddSingleValue($"Период ежемесячного отчёта {monthNames[_startDate.Month-1]}.{_startDate.Year}", indexRow, 1); //>>>>>>> 5b40c2b8d571ec7b2bfd3ee230bb62ce5596e5b9 indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Объект аренды: {_nameObject}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Статус: {status}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; var groupByPost = dtReport.DefaultView.ToTable().AsEnumerable().GroupBy(r => new { id = r.Field <int>("id_Landlord") }) .Select(s => new { s.Key.id, preCredit = s.Sum(r => r.Field <decimal>("preCredit")), preOverPayment = s.Sum(r => r.Field <decimal>("preOverPayment")), prePlan = s.Sum(r => r.Field <decimal>("prePlan")), EndPlan = s.Sum(r => r.Field <decimal>("EndPlan")), Penalty = s.Sum(r => r.Field <decimal>("Penalty")), OtherPayments = s.Sum(r => r.Field <decimal>("OtherPayments")), ultraResult = s.Sum(r => r.Field <decimal>("ultraResult")), Included = s.Sum(r => r.Field <decimal>("Included")), Credit = s.Sum(r => r.Field <decimal>("Credit")), OverPayment = s.Sum(r => r.Field <decimal>("OverPayment")) }); decimal maxResultPlane = 0; foreach (var gPost in groupByPost) { EnumerableRowCollection <DataRow> rowCollect = dtReport.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <int>("id_Landlord") == gPost.id); int startMergRow = indexRow; foreach (DataRow row in rowCollect) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (new List <string>() { "nameLandLord" }.Contains(col.Name)) { indexCol++; continue; } if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } indexCol = 1; isAddItog = false; foreach (DataGridViewColumn col in dgvData.Columns) { if (listColumnGroup.Contains(col.Name)) { report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); if (rowCollect.First()[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)rowCollect.First()[col.DataPropertyName]).ToShortDateString(), startMergRow, indexCol); } else if (rowCollect.First()[col.DataPropertyName] is decimal) { report.AddSingleValueObject(rowCollect.First()[col.DataPropertyName], startMergRow, indexCol); report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); } else { report.AddSingleValue(rowCollect.First()[col.DataPropertyName].ToString(), startMergRow, indexCol); } } else if (listColumnsSum.Contains(col.Name)) { switch (col.Name) { case "preCredit": report.AddSingleValueObject(gPost.preCredit, indexRow, indexCol); break; case "preOverPayment": report.AddSingleValueObject(gPost.preOverPayment, indexRow, indexCol); break; case "prePlan": report.AddSingleValueObject(gPost.prePlan, indexRow, indexCol); break; case "EndPlan": report.AddSingleValueObject(gPost.EndPlan, indexRow, indexCol); break; case "Penalty": report.AddSingleValueObject(gPost.Penalty, indexRow, indexCol); break; case "OtherPayments": report.AddSingleValueObject(gPost.OtherPayments, indexRow, indexCol); break; case "ultraResult": report.AddSingleValueObject(gPost.ultraResult, indexRow, indexCol); break; case "Included": report.AddSingleValueObject(gPost.Included, indexRow, indexCol); break; case "Credit": report.AddSingleValueObject(gPost.Credit, indexRow, indexCol); break; case "OverPayment": report.AddSingleValueObject(gPost.OverPayment, indexRow, indexCol); break; default: break; } //report.AddSingleValueObject(gPost.preCredit, indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); if (!isAddItog) { report.Merge(indexRow, 1, indexRow, indexCol - 1); report.AddSingleValue($" Итого:", indexRow, 1); isAddItog = true; } report.SetCellAlignmentToRight(indexRow, 1, indexRow, indexCol - 1); } indexCol++; } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetFontBold(indexRow, 1, indexRow, maxColumns); indexRow++; maxResultPlane += gPost.preCredit; } indexRow++; isAddItog = false; foreach (string lCol in listColumnsSum) { if (!isAddItog) { report.Merge(indexRow, 1, indexRow, dicColumnNameForIndex[lCol] - 1); report.AddSingleValue($" Итого:", indexRow, 1); isAddItog = true; } report.AddSingleValueObject(dtReport.AsEnumerable().Sum(r => r.Field <decimal>(lCol)), indexRow, dicColumnNameForIndex[lCol]); report.SetFormat(indexRow, dicColumnNameForIndex[lCol], indexRow, dicColumnNameForIndex[lCol], "0.00"); } //report.AddSingleValueObject(maxResultPlane, indexRow, maxColumns); //report.SetFormat(indexRow, maxColumns, indexRow, maxColumns, "0.00"); //report.Merge(indexRow, 1, indexRow, maxColumns - 1); //report.AddSingleValue("Итого:", indexRow, 1); report.SetCellAlignmentToRight(indexRow, 1, indexRow, maxColumns - 1); report.SetFontBold(indexRow, 1, indexRow, maxColumns); indexRow++; report.Show(); }
private void button2_Click(object sender, EventArgs e) { if (dtDataStatic == null || dtDataStatic.DefaultView.Count == 0) { return; } Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvStatistic.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("dataGridViewTextBoxColumn1")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cStaticCountOrder")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cStaticSumOrder")) { setWidthColumn(indexRow, maxColumns, 17, report); } if (col.Name.Equals("cStaticSumTransfer")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("cStatic_1")) { setWidthColumn(indexRow, maxColumns, 12, report); } if (col.Name.Equals("cStatic_2")) { setWidthColumn(indexRow, maxColumns, 12, report); } if (col.Name.Equals("cStatic_3")) { setWidthColumn(indexRow, maxColumns, 12, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по статистике", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvStatistic.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtDataStatic.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvStatistic.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.Show(); #region log Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка статистики по онлайн-магазину"); foreach (DataRow dr in (dgvPeriod.DataSource as DataTable).Rows) { Logging.Comment($"Наименование периода: {dr["cName"].ToString()}, Начало: {dr["dateStart"].ToString()}, Конец: {dr["dateEnd"].ToString()}"); } Logging.Comment("Завершение выгрузки статистики по онлайн-магазину"); Logging.StopFirstLevel(); #endregion }
private void btPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cDate")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cTypePayDoc")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cSumma")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cDatePay")) { setWidthColumn(indexRow, maxColumns, 35, report); } if (col.Name.Equals("cSummPay")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cTypePay")) { setWidthColumn(indexRow, maxColumns, 20, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по прочим платежам", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Договор: {tbAgreements.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{label3.Text}: {tbDate.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{label1.Text}: {tbObject.Text}", indexRow, 1); 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++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; var groupByPost = dtData.DefaultView.ToTable().AsEnumerable() .GroupBy(r => new { id_fines = r.Field <int>("id_fines"), DateFines = r.Field <DateTime>("DateFines"), namePayment = r.Field <string>("namePayment"), summaFines = r.Field <decimal>("summaFines") }) .Select(s => new { s.Key.id_fines, s.Key.DateFines, s.Key.namePayment, s.Key.summaFines }); foreach (var gPost in groupByPost) { EnumerableRowCollection <DataRow> rowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <int>("id_fines") == gPost.id_fines); int startMergRow = indexRow; foreach (DataRow row in rowCollect) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (new List <int>() { cSumma.Index, cTypePayDoc.Index, cDate.Index }.Contains(col.Index)) { indexCol++; continue; } if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } indexCol = 1; foreach (DataGridViewColumn col in dgvData.Columns) { if (new List <int>() { cSumma.Index, cTypePayDoc.Index, cDate.Index }.Contains(col.Index)) { report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); if (rowCollect.First()[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)rowCollect.First()[col.DataPropertyName]).ToShortDateString(), startMergRow, indexCol); } else if (rowCollect.First()[col.DataPropertyName] is decimal) { report.AddSingleValueObject(rowCollect.First()[col.DataPropertyName], startMergRow, indexCol); report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); } else { report.AddSingleValue(rowCollect.First()[col.DataPropertyName].ToString(), startMergRow, indexCol); } } indexCol++; } } report.Show(); }
private void btPrint_Click(object sender, EventArgs e) { Logging.StartFirstLevel(79); Logging.Comment($"Фомирование отчёта из \"{this.Text}\""); Logging.Comment($"Договор:{tbAgreement.Text}"); Logging.Comment($"Арендатор:{tbTenant.Text}"); Logging.Comment($"Период начисления:{cmbPeriodCredit.Text}"); Logging.Comment($"Объект аренды:{cmbObject.Text}"); Logging.Comment($"Тип договора:{cmbTypeContract.Text}"); Logging.Comment($"Подтвержденные пени: {(chbCongressAccept.Checked ? "Да" : "Нет")}"); Logging.StopFirstLevel(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("nameTenant")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("cTypeContract")) { setWidthColumn(indexRow, maxColumns, 21, report); } if (col.Name.Equals("cAgreements")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cPeriodCredit")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("cSummaCredit")) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("cDatePay")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cSumma")) { setWidthColumn(indexRow, maxColumns, 16, report); } if (col.Name.Equals("cCountDaysCredit")) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("cPrcPenalty")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cSummaPenalty")) { setWidthColumn(indexRow, maxColumns, 15, report); } if (col.Name.Equals("cItogPenalty")) { setWidthColumn(indexRow, maxColumns, 15, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Отчёт по начислению пени", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Период начисления {cmbPeriodCredit.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Объект аренды: {cmbObject.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Тип договора: {cmbTypeContract.Text}", indexRow, 1); indexRow++; if (tbAgreement.Text.Trim().Length > 0 || tbTenant.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтры: " + $"{(tbTenant.Text.Trim().Length == 0 ? "" : "Арендатор: " + tbTenant.Text.Trim())} " + $"{(tbAgreement.Text.Trim().Length == 0 ? "" : "Номер договора: " + tbAgreement.Text.Trim())}", indexRow, 1); 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++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; var groupByPost = dtData.DefaultView.ToTable().AsEnumerable().GroupBy(r => new { id = r.Field <int>("id") }) .Select(s => new { s.Key.id }); foreach (var gPost in groupByPost) { EnumerableRowCollection <DataRow> rowCollect = dtData.DefaultView.ToTable().AsEnumerable().Where(r => r.Field <int>("id") == gPost.id); int startMergRow = indexRow; foreach (DataRow row in rowCollect) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (new List <int>() { nameTenant.Index, cTypeContract.Index, cAgreements.Index, cPeriodCredit.Index, cItogPenalty.Index }.Contains(col.Index)) { indexCol++; continue; } if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); if ((int)row["id_StatusPenalty"] == 3) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel2.BackColor); } indexRow++; } indexCol = 1; foreach (DataGridViewColumn col in dgvData.Columns) { if (new List <int>() { nameTenant.Index, cTypeContract.Index, cAgreements.Index, cPeriodCredit.Index, cItogPenalty.Index }.Contains(col.Index)) { report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); if (rowCollect.First()[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)rowCollect.First()[col.DataPropertyName]).ToShortDateString(), startMergRow, indexCol); } else if (rowCollect.First()[col.DataPropertyName] is decimal) { report.AddSingleValueObject(rowCollect.First()[col.DataPropertyName], startMergRow, indexCol); report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); } else { report.AddSingleValue(rowCollect.First()[col.DataPropertyName].ToString(), startMergRow, indexCol); } } indexCol++; } } /* * indexCol = 0; * int indexStartRow = indexRow; * //foreach (DataGridViewRow row in dgvData.Rows) * foreach (DataGridViewColumn col in dgvData.Columns) * { * if (col.Visible) * { * indexCol++; * indexRow = indexStartRow; * int startMergRow = indexRow; * object tmpValue = null; * int preId = 0; * //foreach (DataGridViewColumn col in dgvData.Columns) * foreach (DataGridViewRow row in dgvData.Rows) * { * if ((int)dtData.DefaultView[row.Index]["id_StatusPenalty"] == 3) * report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel2.BackColor); * * report.SetWrapText(indexRow, indexCol, indexRow, indexCol); * * if (new List<int>() { nameTenant.Index, cTypeContract.Index, cAgreements.Index, cPeriodCredit.Index, cItogPenalty.Index }.Contains(col.Index)) * { * if (indexRow == indexStartRow) * { * tmpValue = row.Cells[col.Index].Value; * preId = (int)dtData.DefaultView[row.Index]["id"]; * } * else if (indexRow - indexStartRow == dgvData.Rows.Count - 1) * { * report.Merge(startMergRow, indexCol, indexRow-1, indexCol); * * if (tmpValue is DateTime) * report.AddSingleValue(((DateTime)tmpValue).ToShortDateString(), startMergRow, indexCol); * if (tmpValue is decimal) * { * report.AddSingleValueObject(tmpValue, startMergRow, indexCol); * report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); * } * else * report.AddSingleValue(tmpValue.ToString(), startMergRow, indexCol); * * * if (row.Cells[col.Index].Value is DateTime) * report.AddSingleValue(((DateTime)row.Cells[col.Index].Value).ToShortDateString(), indexRow, indexCol); * else * if (row.Cells[col.Index].Value is decimal) * { * report.AddSingleValueObject(row.Cells[col.Index].Value, indexRow, indexCol); * report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); * } * else * report.AddSingleValue(row.Cells[col.Index].Value.ToString(), indexRow, indexCol); * * } * else if (indexRow != indexStartRow) * { * if (!tmpValue.Equals(row.Cells[col.Index].Value) || preId != (int)dtData.DefaultView[row.Index]["id"]) * { * report.Merge(startMergRow, indexCol, indexRow - 1, indexCol); * * if (tmpValue is DateTime) * report.AddSingleValue(((DateTime)tmpValue).ToShortDateString(), startMergRow, indexCol); * else * if (tmpValue is decimal) * { * report.AddSingleValueObject(tmpValue, startMergRow, indexCol); * report.SetFormat(startMergRow, indexCol, startMergRow, indexCol, "0.00"); * } * else * report.AddSingleValue(tmpValue.ToString(), startMergRow, indexCol); * * startMergRow = indexRow; * tmpValue = row.Cells[col.Index].Value; * preId = (int)dtData.DefaultView[row.Index]["id"]; * } * } * } * else * { * if (row.Cells[col.Index].Value is DateTime) * report.AddSingleValue(((DateTime)row.Cells[col.Index].Value).ToShortDateString(), indexRow, indexCol); * else * if (row.Cells[col.Index].Value is decimal) * { * report.AddSingleValueObject(row.Cells[col.Index].Value, indexRow, indexCol); * report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); * } * else * report.AddSingleValue(row.Cells[col.Index].Value.ToString(), indexRow, indexCol); * } * * * report.SetBorders(indexRow, 1, indexRow, maxColumns); * report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); * report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); * indexRow++; * } * } * } */ report.SetCellColor(indexRow, 1, indexRow, 1, panel2.BackColor); report.Merge(indexRow, 2, indexRow, 4); report.AddSingleValue(chbCongressAccept.Text, indexRow, 2); report.SetFontBold(indexRow, maxColumns - 1, indexRow, maxColumns); report.SetBorders(indexRow, maxColumns - 1, indexRow, maxColumns); report.SetCellAlignmentToRight(indexRow, maxColumns - 1, indexRow, maxColumns); report.AddSingleValue("Итого", indexRow, maxColumns - 1); report.AddSingleValue(tbItogPenalty.Text, indexRow, maxColumns); report.Show(); }
private async void btPrint_Click(object sender, EventArgs e) { if (dtData == null || dtData.Rows.Count == 0 || dtData.DefaultView.Count == 0) { MessageBox.Show("Нет данных для формирования отчёта.", "Печать", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); //progressBar1.Visible = true; var result = await Task <bool> .Factory.StartNew(() => { foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals(cName.Name)) { setWidthColumn(indexRow, maxColumns, 37, report); } if (col.Name.Equals(cUnit.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, 1); report.SetRowHeight(indexRow, 1, indexRow, 1, 45); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; config.DoOnUIThread(() => { //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()} ", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Объект: {cmbObject.Text}", indexRow, 1); //indexRow++; //report.Merge(indexRow, 1, indexRow, maxColumns); //report.AddSingleValue($"Тип договора: {cmbTypeDoc.Text}", indexRow, 1); //indexRow++; if (tbName.Text.Trim().Length != 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {(tbName.Text.Trim().Length != 0 ? $"EAN:{tbName.Text.Trim()} " : "")}", indexRow, 1); indexRow++; } }, this); report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal || row[col.DataPropertyName] is double) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } if (!(bool)row["isActive"]) { report.SetCellColor(indexRow, 1, indexRow, maxColumns, panel1.BackColor); } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.Merge(indexRow, 2, indexRow, maxColumns); report.AddSingleValue($"{chbNotActive.Text}", indexRow, 2); config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); //progressBar1.Visible = false; }, this); report.Show(); return(true); }); }
private void btPrint_Click(object sender, EventArgs e) { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvAdress.Columns) { if (col.Visible) { maxColumns++; if (col.Name.Equals("cNameGrp")) { setWidthColumn(indexRow, maxColumns, 60, report); } } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); indexRow++; indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{tbNameGrp.Text}: {tbNameGrp.Text}", indexRow, 1); indexRow++; if (tbNaneGrp.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтр: {tbNaneGrp.Text}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; #endregion int indexCol = 0; foreach (DataGridViewColumn col in dgvAdress.Columns) { if (col.Visible) { indexCol++; report.AddSingleValue(col.HeaderText, indexRow, indexCol); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataRowView row in dtData.DefaultView) { indexCol = 1; report.SetWrapText(indexRow, indexCol, indexRow, maxColumns); foreach (DataGridViewColumn col in dgvAdress.Columns) { if (col.Visible) { if (row[col.DataPropertyName] is DateTime) { report.AddSingleValue(((DateTime)row[col.DataPropertyName]).ToShortDateString(), indexRow, indexCol); } else if (row[col.DataPropertyName] is bool) { report.AddSingleValue((bool)row[col.DataPropertyName] ? "Да" : "Нет", indexRow, indexCol); } else if (row[col.DataPropertyName] is decimal) { report.AddSingleValueObject(row[col.DataPropertyName], indexRow, indexCol); report.SetFormat(indexRow, indexCol, indexRow, indexCol, "0.00"); } else { report.AddSingleValue(row[col.DataPropertyName].ToString(), indexRow, indexCol); } indexCol++; } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } report.Show(); }