private void btnPrintReport_Click(object sender, EventArgs e) { if (dtReport.DefaultView.Count == 0) { MessageBox.Show("Нет данных для выгрузки отчёта!", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка отчета по проверке отчетов, со следующими параметрами"); Logging.Comment($"Период с {dateTimeStart.Value.ToShortDateString()} по {dateTimeEnd.Value.ToShortDateString()}"); Logging.Comment($"Статус:{cmbStatusReport.Text}"); Logging.Comment($"Наличие долга:{cmbDebt.Text}"); Logging.StopFirstLevel(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; foreach (DataGridViewColumn col in dgvReport.Columns) { if (col.Visible && !col.Name.Equals(colV.Name)) { maxColumns++; if (col.Name.Equals("Number")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("Description")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("Summa")) { setWidthColumn(indexRow, maxColumns, 22, report); } if (col.Name.Equals("Valuta")) { setWidthColumn(indexRow, maxColumns, 13, report); } if (col.Name.Equals("sumGet")) { setWidthColumn(indexRow, maxColumns, 20, report); } if (col.Name.Equals("SummaReport")) { setWidthColumn(indexRow, maxColumns, 18, report); } if (col.Name.Equals("DebtReport")) { setWidthColumn(indexRow, maxColumns, 16, report); } if (col.Name.Equals("DateEdit")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("typeCashNonCash")) { setWidthColumn(indexRow, maxColumns, 10, report); } if (col.Name.Equals("nameStatusReport")) { 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($"Период с {dateTimeStart.Value.ToShortDateString()} по {dateTimeEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Статус: {cmbStatusReport.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{lbHasDebt.Text}: {cmbDebt.Text}", indexRow, 1); indexRow++; if (tbNumber.Text.Trim().Length != 0 || tbDiscript.Text.Trim().Length != 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтры:" + $"{(tbNumber.Text.Trim().Length==0?"":$"{Number.HeaderText}:{tbNumber.Text}")} " + $"{(tbDiscript.Text.Trim().Length == 0 ? "" : $"{Description.HeaderText}:{tbDiscript.Text}")}", indexRow, 1);
private async void btPrint_Click(object sender, EventArgs e) { report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); progressBar1.Visible = true; DateTime date = new DateTime(dtpYear.Value.Year, dtpMonth.Value.Month, 1); var result = await Task <bool> .Factory.StartNew(() => { DataTable dtReport = _proc.GetReportFinesPay(date.Date); if (dtReport == null || dtReport.Rows.Count == 0) { DoOnUIThread(() => { MessageBox.Show("Нет данных для выгрузки", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); return(false); } int indexRow = 1; int maxColumns = 11; setWidthColumn(indexRow, 1, 8, report); setWidthColumn(indexRow, 2, 12, report); setWidthColumn(indexRow, 3, 30, report); setWidthColumn(indexRow, 4, 10, report); setWidthColumn(indexRow, 5, 17, report); setWidthColumn(indexRow, 6, 18, report); setWidthColumn(indexRow, 7, 10, report); setWidthColumn(indexRow, 8, 17, report); setWidthColumn(indexRow, 9, 18, report); #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отчёт по дополнительным оплатам за {monthNames[date.Month - 1]} {date.Year}", 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.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 (DataRow row in dtReport.Rows) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(npp, indexRow, 1, report); addDataToCell(row["nameObject"], indexRow, 2, report); addDataToCell(row["nameTenant"], indexRow, 3, report); addDataToCell(row["Agreement"], indexRow, 4, report); addDataToCell(row["cName"], indexRow, 5, report); addDataToCell(row["Summa"], indexRow, 6, report); addDataToCell(row["DateFines"], indexRow, 7, report); addDataToCell(row["MetersData"], indexRow, 8, report); addDataToCell(row["sumPay"], indexRow, 9, report); addDataToCell(row["resultSum"], indexRow, 10, report); addDataToCell(row["Comment"], indexRow, 11, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; npp++; } addDataToCell("Итого", indexRow, 5, report); object objValue = dtReport.Compute("SUM(Summa)", ""); addDataToCell(objValue, indexRow, 6, report); objValue = dtReport.Compute("SUM(sumPay)", ""); addDataToCell(objValue, indexRow, 9, report); objValue = dtReport.Compute("SUM(resultSum)", ""); addDataToCell(objValue, indexRow, 10, report); report.SetBorders(indexRow, 5, indexRow, 6); report.SetBorders(indexRow, 9, indexRow, 10); report.SetFontBold(indexRow, 1, indexRow, maxColumns); indexRow++; report.SetPageSetup(1, 9999, false); report.Show(); DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); return(true); }); }
private async void btPrintRow_Click(object sender, EventArgs e) { if (dgvData.CurrentRow != null && dgvData.CurrentRow.Index != -1 && dtData != null && dtData.DefaultView.Count != 0) { DataRowView rowSelect = dtData.DefaultView[dgvData.CurrentRow.Index]; int id = (int)rowSelect["id"]; DataTable dtBody = Config.hCntMain.getRouteBody(id).Result; if (dtBody == null || dtBody.Rows.Count == 0) { return; } await 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); //if (report == null) report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxCol = 5; setWidthColumn(indexRow, 1, 14, report); setWidthColumn(indexRow, 2, 15, report); setWidthColumn(indexRow, 3, 40, report); setWidthColumn(indexRow, 4, 13, report); setWidthColumn(indexRow, 5, 13, report); report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"Маршрут №{rowSelect["RouteNumber"]}", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 18); indexRow++; indexRow++; Config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label3.Text} {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label5.Text}:{cmbDriver.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label6.Text}:{cmbShop.Text}", indexRow, 1); indexRow++; if (tbNumber.Text.Length > 0 || tbFioMan.Text.Length > 0) { report.Merge(indexRow, 1, indexRow, maxCol); string str = "Фильтры: "; if (tbNumber.Text.Length > 0) { str += $"Номер маршрута: {tbNumber.Text};"; } if (tbFioMan.Text.Length > 0) { str += $"Водитель: {tbFioMan.Text};"; } report.AddSingleValue($"{str}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); }, this); indexRow++; indexRow++; report.AddSingleValue("№ заказа в маршруте", indexRow, 1); report.AddSingleValue("№ заказа", indexRow, 2); report.AddSingleValue("Адрес доставки", indexRow, 3); report.AddSingleValue("Вес заказа, кг", indexRow, 4); report.AddSingleValue("Длина маршрута, км", indexRow, 5); report.SetFontBold(indexRow, 1, indexRow, maxCol); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetWrapText(indexRow, 1, indexRow, maxCol); indexRow++; dtBody.DefaultView.Sort = "RouteNumber asc"; foreach (DataRowView row in dtBody.DefaultView) { setValueToCell(indexRow, 1, row["RouteNumber"]); setValueToCell(indexRow, 2, row["OrderNumber"]); setValueToCell(indexRow, 3, row["Address"]); setValueToCell(indexRow, 4, row["weigth"]); setValueToCell(indexRow, 5, row["RouteLength"]); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToRight(indexRow, 4, indexRow, 5); indexRow++; } setValueToCell(indexRow, 3, "Итого"); decimal routeWeigth = dtBody.AsEnumerable().Sum(r => r.Field <decimal>("weigth")); setValueToCell(indexRow, 4, routeWeigth); decimal routeLength = dtBody.AsEnumerable().Sum(r => r.Field <decimal>("RouteLength")); setValueToCell(indexRow, 5, routeLength); report.SetBorders(indexRow, 1, indexRow, maxCol); indexRow++; report.SetPageSetup(1, 9999, true); report.Show(); Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); fLoad.Dispose(); }, this); }); } }
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(); }
public static void printWriteOff(int id) { DataTable dtDataHead = readSQL.getActWriteOff(DateTime.Now, DateTime.Now, id); DataTable dtDataBody = readSQL.getContentWriteOff(id); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; report.Merge(indexRow, 1, indexRow, 6); report.AddSingleValue("Акт списания оборудования", indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetFontBold(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); indexRow++; indexRow++; report.Merge(indexRow, 5, indexRow, 6); report.AddSingleValue("Дата: " + ((DateTime)dtDataHead.Rows[0]["Date"]).ToShortDateString(), indexRow, 5); indexRow++; report.Merge(indexRow, 1, indexRow, 6); report.AddSingleValue("Причина: " + dtDataHead.Rows[0]["Reason"].ToString(), indexRow, 1); report.SetWrapText(indexRow, 1, indexRow, 1); //report.SetAutoFit(indexRow, 1, indexRow, 1); report.SetRowHeight(indexRow, 1, indexRow, 1, 60); indexRow++; indexRow++; report.AddSingleValue("№ п\\п", indexRow, 1); report.AddSingleValue("Наименование", indexRow, 2); report.AddSingleValue("Инвентарный номер", indexRow, 3); report.AddSingleValue("EAN", indexRow, 4); report.AddSingleValue("Местоположение", indexRow, 5); report.AddSingleValue("Комментарий", indexRow, 6); report.SetFontBold(indexRow, 1, indexRow, 6); report.SetBorders(indexRow, 1, indexRow, 6); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 6); indexRow++; foreach (DataRow row in dtDataBody.Rows) { report.AddSingleValue(row["npp"].ToString(), indexRow, 1); report.AddSingleValue(row["cName"].ToString(), indexRow, 2); report.AddSingleValue(row["InventoryNumber"].ToString(), indexRow, 3); report.AddSingleValue(row["EAN"].ToString(), indexRow, 4); report.AddSingleValue(row["nameLocation"].ToString(), indexRow, 5); //report.AddSingleValue(row[""].ToString(), indexRow, 6); report.SetBorders(indexRow, 1, indexRow, 6); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 6); indexRow++; } indexRow++; report.Merge(indexRow, 1, indexRow, 6); report.AddSingleValue("ОЭЭС:", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 6); report.AddSingleValue("РБ5:", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 6); report.AddSingleValue("О1:", indexRow, 1); indexRow++; report.SetColumnAutoSize(5, 1, indexRow, 6); report.SetPageSetup(1, 9999, false); report.Show(); }
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(); }
public static void createReport(int id_hardware, DateTime startDate, DateTime endDate, string strType, int type, List <string> listFilter) { DataTable dtReport = new DataTable(); if (id_hardware != 0) { dtReport = readSQL.getReportHistory(id_hardware, null, null, null); } else { dtReport = readSQL.getReportHistory(id_hardware, startDate, endDate, type); } if (dtReport == null) { MessageBox.Show("Нет данных для выгрузки!", "Информирование");; return; } if (dtReport.Rows.Count == 0) { MessageBox.Show("Нет данных для выгрузки!", "Информирование");; return; } if (listFilter != null) { EnumerableRowCollection <DataRow> rowsFind = dtReport.AsEnumerable().Where(r => listFilter.Contains(r.Field <string>("cName").Trim())); if (rowsFind.Count() == 0) { MessageBox.Show("Нет данных для выгрузки!", "Информирование");; return; } dtReport = rowsFind.CopyToDataTable(); } Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; string[] listTitle = new string[] { "Инв. номер", @"Оборудование\Комплектующее", @"Наименование оборуд.\комплект.", @"Дата добавления оборудования", "Параметр", "Значение До", "Значение после", "Время изменения", "Кто изменил" }; report.Merge(indexRow, 1, indexRow, listTitle.Length); report.AddSingleValue("Отчёт по изменению в оборудовании", indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 16); report.SetFontBold(indexRow, 1, indexRow, 1); indexRow++; if (id_hardware == 0) { report.Merge(indexRow, 1, indexRow, listTitle.Length); report.AddSingleValue("Период с " + startDate.ToShortDateString() + " по " + endDate.ToShortDateString() + "", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, listTitle.Length); report.AddSingleValue("Условие: " + strType, indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, listTitle.Length); report.AddSingleValue("Дата и время выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, listTitle.Length); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; indexRow++; int startPos = indexRow; for (int i = 0; i < listTitle.Length; i++) { report.AddSingleValue(listTitle[i], indexRow, i + 1); report.SetBorders(indexRow, i + 1, indexRow, i + 1); report.SetCellAlignmentToCenter(indexRow, i + 1, indexRow, i + 1); } indexRow++; //EnumerableRowCollection<DataRow> var rowCollect = from hosp in dtReport.AsEnumerable() group hosp by new { id_jHardware = hosp["id_jHardware"], id_Creator = hosp["id_Creator"], DateCreate = hosp["DateCreate"] } into grp orderby grp.Key.id_jHardware ascending, grp.Key.DateCreate ascending select new { id_jHardware = grp.Key.id_jHardware, id_Creator = grp.Key.id_Creator, DateCreate = grp.Key.DateCreate, }; foreach (var rC in rowCollect) { DataRow[] row = dtReport.Select(string.Format("id_jHardware = {0} and id_Creator = {1} AND DateCreate = '{2}'", rC.id_jHardware, rC.id_Creator, rC.DateCreate)); report.Merge(indexRow, 1, indexRow + row.Count() - 1, 1); report.Merge(indexRow, 2, indexRow + row.Count() - 1, 2); report.Merge(indexRow, 3, indexRow + row.Count() - 1, 3); report.Merge(indexRow, 8, indexRow + row.Count() - 1, 8); report.Merge(indexRow, 9, indexRow + row.Count() - 1, 9); report.AddSingleValue(row[0]["InventoryNumber"].ToString(), indexRow, 1); report.AddSingleValue(row[0]["TypeComponentsHardware"].ToString(), indexRow, 2); report.AddSingleValue(row[0]["nameOb"].ToString(), indexRow, 3); report.AddSingleValue(row[0]["DateCreate"].ToString(), indexRow, 8); report.AddSingleValue(row[0]["FIO"].ToString(), indexRow, 9); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 9); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 2, indexRow, 2); report.SetCellAlignmentToCenter(indexRow, 3, indexRow, 3); report.SetCellAlignmentToCenter(indexRow, 8, indexRow, 8); report.SetCellAlignmentToCenter(indexRow, 9, indexRow, 9); foreach (DataRow r in row) { report.AddSingleValue(r["DateCreateHardWare"].ToString(), indexRow, 4); report.AddSingleValue(r["cName"].ToString(), indexRow, 5); report.AddSingleValue(r["valueOld"].ToString(), indexRow, 6); report.AddSingleValue(r["valueNew"].ToString(), indexRow, 7); report.SetCellAlignmentToCenter(indexRow, 4, indexRow, 4); if ((bool)r["isDeleteRow"]) { report.SetCellColor(indexRow, 1, indexRow, listTitle.Length, Color.Green); } report.SetBorders(indexRow, 1, indexRow, listTitle.Length); indexRow++; } } indexRow++; report.SetCellColor(indexRow, 1, indexRow, 1, Color.Green); report.AddSingleValue("Удалённые записи", indexRow, 2); /* * foreach (DataRow r in dtReport.Rows) * { * report.AddSingleValue(r["InventoryNumber"].ToString(), indexRow, 1); * report.AddSingleValue(r["TypeComponentsHardware"].ToString(), indexRow, 2); * report.AddSingleValue(r["nameOb"].ToString(), indexRow, 3); * report.AddSingleValue(r["cName"].ToString(), indexRow, 4); * report.AddSingleValue(r["valueOld"].ToString(), indexRow, 5); * report.AddSingleValue(r["valueNew"].ToString(), indexRow, 6); * report.AddSingleValue(r["DateCreate"].ToString(), indexRow, 7); * report.AddSingleValue(r["FIO"].ToString(), indexRow, 8); * report.SetBorders(indexRow, 1, indexRow, listTitle.Length); * indexRow++; * } */ report.SetColumnAutoSize(startPos, 1, indexRow, listTitle.Length); report.Show(); }
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 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 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 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 btPrint_Click(object sender, EventArgs e) { if (dgvData.Rows.Count == 0) { MessageBox.Show("Нет данных для формирования отчёта!", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Logging.StartFirstLevel(79); Logging.Comment($"Фомирование отчёта из \"{this.Text}\""); Logging.Comment($"Договор:{tbAgreement.Text}"); Logging.Comment($"Арендатор:{tbTenant.Text}"); Logging.Comment($"Арендодатель:{tbLandLord.Text}"); Logging.Comment($"Место:{tbNamePlace.Text}"); Logging.Comment($"Период с:{dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}"); Logging.Comment($"Объект аренды ID:{cmbObject.SelectedValue}; Наименование:{cmbObject.Text}"); Logging.Comment($"Съезд подтвержден: {(chbCongressAccept.Checked ? "Да" : "Нет")}"); Logging.Comment($"Аннуляция поддтверждена/имеется расторжение договора: {(chbDropAgreements.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++; } } setWidthColumn(indexRow, 1, 25, report); setWidthColumn(indexRow, 2, 23, report); setWidthColumn(indexRow, 3, 14, report); setWidthColumn(indexRow, 4, 11, report); setWidthColumn(indexRow, 5, 50, report); setWidthColumn(indexRow, 6, 16, report); setWidthColumn(indexRow, 7, 13, report); setWidthColumn(indexRow, 8, 15, report); setWidthColumn(indexRow, 9, 13, 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($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Объект аренды: {cmbObject.Text}", indexRow, 1); indexRow++; if (tbLandLord.Text.Trim().Length > 0 || tbTenant.Text.Trim().Length > 0 || tbAgreement.Text.Trim().Length > 0 || tbNamePlace.Text.Trim().Length > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Фильтры: " + $"{(tbLandLord.Text.Trim().Length > 0 ? $"Арендодатель: {tbLandLord.Text.Trim()}" : "")}; " + $"{(tbLandLord.Text.Trim().Length > 0 ? $"Арендатор: {tbTenant.Text.Trim()}" : "")}; " + $"{(tbLandLord.Text.Trim().Length > 0 ? $"Номер договора: {tbAgreement.Text.Trim()}" : "")}; " + $"{(tbLandLord.Text.Trim().Length > 0 ? $"Местоположение места аренды: {tbNamePlace.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 indexColumn = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexColumn++; report.AddSingleValue(col.HeaderText, indexRow, indexColumn); report.SetWrapText(indexRow, indexColumn, indexRow, indexColumn); } } report.SetFontBold(indexRow, 1, indexRow, maxColumns); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); indexRow++; foreach (DataGridViewRow row in dgvData.Rows) { Color rColor = Color.White; if ((!(bool)dtData.DefaultView[row.Index]["isLinkPetitionLeave"] || !(bool)dtData.DefaultView[row.Index]["isConfirmed_LinkPetitionLeave"]) && (bool)dtData.DefaultView[row.Index]["isConfirmed"]) { rColor = panel2.BackColor; } if ((bool)dtData.DefaultView[row.Index]["isLinkPetitionLeave"] && (bool)dtData.DefaultView[row.Index]["isConfirmed_LinkPetitionLeave"]) { rColor = panel3.BackColor; } else if (dtData.DefaultView[row.Index]["isCancelAgreements"] != DBNull.Value && (bool)dtData.DefaultView[row.Index]["isConfirmed"]) { rColor = panel3.BackColor; } report.SetCellColor(indexRow, 1, indexRow, maxColumns, rColor); indexColumn = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { indexColumn++; if (row.Cells[col.Index].Value is DateTime) { report.AddSingleValue(((DateTime)row.Cells[col.Index].Value).ToShortDateString(), indexRow, indexColumn); } else { report.AddSingleValue(row.Cells[col.Index].Value.ToString(), indexRow, indexColumn); } report.SetWrapText(indexRow, indexColumn, indexRow, indexColumn); if ((bool)dtData.DefaultView[row.Index]["isLinkPetitionLeave"] && col.Index == Date_of_Departure.Index) { report.SetCellColor(indexRow, indexColumn, indexRow, indexColumn, panel1.BackColor); } } } report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } indexRow++; report.Merge(indexRow, 2, indexRow, maxColumns); report.SetCellColor(indexRow, 1, indexRow, 1, panel1.BackColor); report.AddSingleValue($"{label4.Text}", indexRow, 2); indexRow++; report.Merge(indexRow, 2, indexRow, maxColumns); report.SetCellColor(indexRow, 1, indexRow, 1, panel2.BackColor); report.AddSingleValue($"{chbCongressAccept.Text}", indexRow, 2); indexRow++; report.Merge(indexRow, 2, indexRow, maxColumns); report.SetCellColor(indexRow, 1, indexRow, 1, panel3.BackColor); report.AddSingleValue($"{chbDropAgreements.Text}", indexRow, 2); report.SetPageSetup(1, 9999, true); report.Show(); }
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); }); }
private async void BtPrint_Click(object sender, EventArgs e) { await 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); //if (report == null) report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; } } setWidthColumn(indexRow, 1, 29, report); setWidthColumn(indexRow, 2, 22, report); setWidthColumn(indexRow, 3, 25, report); setWidthColumn(indexRow, 4, 25, report); report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 18); indexRow++; indexRow++; Config.DoOnUIThread(() => { /* * report.Merge(indexRow, 1, indexRow, maxCol); * report.AddSingleValue($"{label5.Text}{cmbDeps.Text}", indexRow, 1); * indexRow++; * * report.Merge(indexRow, 1, indexRow, maxCol); * report.AddSingleValue($"{label3.Text}{cmbPost.Text}", indexRow, 1); * indexRow++; */ report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); }, this); indexRow++; indexRow++; maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; report.AddSingleValue(col.HeaderText, indexRow, maxCol); } } report.SetFontBold(indexRow, 1, indexRow, maxCol); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetWrapText(indexRow, 1, indexRow, maxCol); indexRow++; foreach (DataRowView row in dtData.DefaultView) { maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; setValueToCell(indexRow, maxCol, row[col.DataPropertyName]); } } report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToRight(indexRow, 3, indexRow, 4); indexRow++; } report.SetPageSetup(1, 9999, true); report.Show(); Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); fLoad.Dispose(); }, this); }); }
private async void BtPrint_Click(object sender, EventArgs e) { int id_driver = (int)cmbDriver.SelectedValue; DateTime dateStart = dtpStart.Value.Date; DateTime dateEnd = dtpEnd.Value.Date; DataTable dtReport = Config.hCntMain.getReportDriver(dateStart, dateEnd, id_driver).Result; if (dtReport == null || dtReport.Rows.Count == 0) { MessageBox.Show("Нет данных для отчёта", "Выгрузка отчёта"); return; } var groupDriver = dtReport.AsEnumerable() .GroupBy(g => new { nameShop = g.Field <string>("nameShop"), id_Driver = g.Field <int>("id_Driver"), nameDriver = g.Field <string>("nameDriver"), DateRoute = g.Field <DateTime>("DateRoute"), CarNumber = g.Field <string>("CarNumber"), RouteNumber = g.Field <int>("RouteNumber"), id = g.Field <int>("id") }) .Select(s => new { s.Key.nameShop, s.Key.nameDriver, s.Key.DateRoute, s.Key.id_Driver, s.Key.CarNumber, s.Key.RouteNumber, s.Key.id, allCost = s.Max(r => r.Field <decimal>("Cost100km")), allCostFull = (s.Sum(r => r.Field <decimal>("RouteLength")) * s.Max(r => r.Field <decimal>("Cost100km"))) / 100.0m, sumWeightGood = s.Sum(r => r.Field <decimal>("weightGood")) }).OrderBy(o => o.nameShop).ThenBy(o => o.nameDriver).ThenBy(o => o.DateRoute).ThenBy(o => o.RouteNumber); await 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); //if (report == null) report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxCol = 10; setWidthColumn(indexRow, 1, 14, report); setWidthColumn(indexRow, 2, 15, report); setWidthColumn(indexRow, 3, 20, report); setWidthColumn(indexRow, 4, 30, report); setWidthColumn(indexRow, 5, 30, report); setWidthColumn(indexRow, 6, 14, report); setWidthColumn(indexRow, 7, 13, report); setWidthColumn(indexRow, 8, 13, report); setWidthColumn(indexRow, 9, 14, report); setWidthColumn(indexRow, 10, 50, report); report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Отчет по водителям", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 18); indexRow++; indexRow++; Config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label3.Text} {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label5.Text}:{cmbDriver.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); }, this); indexRow++; indexRow++; report.AddSingleValue("Магазин", indexRow, 1); report.AddSingleValue("Дата маршрута", indexRow, 2); report.AddSingleValue("№ маршрута", indexRow, 3); report.AddSingleValue("Водитель", indexRow, 4); report.AddSingleValue("Машина", indexRow, 5); report.AddSingleValue("Расход на 100 км. в городе, литр", indexRow, 6); report.AddSingleValue("Сумма веса заказов", indexRow, 7); report.AddSingleValue("Длина маршрута, км.", indexRow, 8); report.AddSingleValue("№ заказа", indexRow, 9); report.AddSingleValue("Адрес доставки", indexRow, 10); report.SetFontBold(indexRow, 1, indexRow, maxCol); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetWrapText(indexRow, 1, indexRow, maxCol); indexRow++; foreach (var gd in groupDriver) { setValueToCell(indexRow, 1, gd.nameShop); setValueToCell(indexRow, 2, gd.DateRoute); setValueToCell(indexRow, 3, gd.RouteNumber); setValueToCell(indexRow, 4, gd.nameDriver); setValueToCell(indexRow, 5, gd.CarNumber); setValueToCell(indexRow, 6, gd.allCost); setValueToCell(indexRow, 7, gd.sumWeightGood); EnumerableRowCollection <DataRow> rowCollect = dtReport.AsEnumerable().Where(r => r.Field <int>("id") == gd.id); if (rowCollect.Count() > 0) { int indexStart = indexRow; //DataRow row = rowCollect.First(); foreach (DataRow row in rowCollect) { setValueToCell(indexRow, 8, row["RouteLength"]); setValueToCell(indexRow, 9, row["OrderNumber"]); setValueToCell(indexRow, 10, row["Address"]); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); //report.SetCellAlignmentToRight(indexRow, 4, indexRow, 5); indexRow++; } report.Merge(indexStart, 1, indexStart + rowCollect.Count() - 1, 1); report.Merge(indexStart, 2, indexStart + rowCollect.Count() - 1, 2); report.Merge(indexStart, 3, indexStart + rowCollect.Count() - 1, 3); report.Merge(indexStart, 4, indexStart + rowCollect.Count() - 1, 4); report.Merge(indexStart, 5, indexStart + rowCollect.Count() - 1, 5); report.Merge(indexStart, 6, indexStart + rowCollect.Count() - 1, 6); report.Merge(indexStart, 7, indexStart + rowCollect.Count() - 1, 7); } } report.Merge(indexRow, 1, indexRow, 2); setValueToCell(indexRow, 1, "Итого кол-во маршрутов"); setValueToCell(indexRow, 3, groupDriver.Count()); setValueToCell(indexRow, 5, "Итого"); setValueToCell(indexRow, 6, groupDriver.Sum(r => r.allCostFull)); decimal routeLength = dtReport.AsEnumerable().Sum(r => r.Field <decimal>("weightGood")); setValueToCell(indexRow, 7, routeLength); routeLength = dtReport.AsEnumerable().Sum(r => r.Field <decimal>("RouteLength")); setValueToCell(indexRow, 8, routeLength); report.SetBorders(indexRow, 1, indexRow, 3); report.SetBorders(indexRow, 5, indexRow, 8); indexRow++; report.SetPageSetup(1, 9999, true); report.Show(); Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); fLoad.Dispose(); }, this); }); }
private void getReport() { DoOnUIThread(delegate() { this.Enabled = false; DataTable dtReport = proc.GetTenantReport((int)cbObjects.SelectedValue, (int)cbLandlord.SelectedValue, (int)cbActivties.SelectedValue); if (dtReport.Rows.Count == 0) { MessageBox.Show("Нет данных для выгрузки", "Нет данных", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Enabled = true; return; } else { Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; report.SetPageOrientationToLandscape(); ///Заголовок report.Merge(indexRow, 1, indexRow, 11); report.AddSingleValue("ОТЧЕТ О ВИДАХ ДЕЯТЕЛЬНОСТИ АРЕНДАТОРОВ", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow + 1, 11); report.SetCellAlignmentToCenter(indexRow, 1, indexRow + 1, 11); report.SetFontBold(indexRow, 1, indexRow, 11); report.SetFontSize(indexRow, 1, indexRow, 11, 16); indexRow++; indexRow++; ///Параметры report.AddSingleValue("Объект:", indexRow, 2); report.SetFontBold(indexRow, 2, indexRow, 2); report.AddSingleValue(cbObjects.Text.Trim(), indexRow, 3); indexRow++; report.AddSingleValue("Арендодатель:", indexRow, 2); report.SetFontBold(indexRow, 2, indexRow, 2); report.AddSingleValue(cbLandlord.Text.Trim(), indexRow, 3); indexRow++; report.AddSingleValue("Вид деятельности:", indexRow, 2); report.SetFontBold(indexRow, 2, indexRow, 2); report.AddSingleValue(cbActivties.Text.Trim(), indexRow, 3); indexRow++; indexRow++; report.AddSingleValue("Выгрузил:", indexRow, 2); report.SetFontBold(indexRow, 2, indexRow, 2); report.AddSingleValue(Nwuram.Framework.Settings.User.UserSettings.User.FullUsername.Trim(), indexRow, 3); indexRow++; report.AddSingleValue("Дата:", indexRow, 2); report.SetFontBold(indexRow, 2, indexRow, 2); report.AddSingleValue(proc.GetDate().ToString(), indexRow, 3); indexRow++; indexRow++; ///Названия столбцов report.Merge(indexRow, 1, indexRow + 1, 1); report.AddSingleValue("Объект", indexRow, 1); report.Merge(indexRow, 2, indexRow + 1, 2); report.AddSingleValue("Арендодатель", indexRow, 2); report.Merge(indexRow, 3, indexRow + 1, 3); report.AddSingleValue("Вид деятельности", indexRow, 3); report.Merge(indexRow, 4, indexRow + 1, 4); report.AddSingleValue("№ п/п", indexRow, 4); report.SetWrapText(indexRow, 4, indexRow + 1, 4); report.Merge(indexRow, 5, indexRow + 1, 5); report.AddSingleValue("Арендатор", indexRow, 5); report.Merge(indexRow, 6, indexRow + 1, 6); report.AddSingleValue("Вид договора", indexRow, 6); report.Merge(indexRow, 7, indexRow, 9); report.AddSingleValue("Местоположение", indexRow, 7); report.AddSingleValue("Здание", indexRow + 1, 7); report.AddSingleValue("Этаж", indexRow + 1, 8); report.AddSingleValue("№ секции", indexRow + 1, 9); report.Merge(indexRow, 10, indexRow + 1, 10); report.AddSingleValue("Телефон", indexRow, 10); report.Merge(indexRow, 11, indexRow + 1, 11); report.AddSingleValue("Эл.почта", indexRow, 11); report.SetCellAlignmentToJustify(indexRow, 1, indexRow + 1, 11); report.SetCellAlignmentToCenter(indexRow, 1, indexRow + 1, 11); report.SetBorders(indexRow, 1, indexRow + 1, 11); report.SetFontBold(indexRow, 1, indexRow + 1, 11); report.SetFontSize(indexRow, 1, indexRow + 1, 11, 14); indexRow++; indexRow++; int ObjIndexStart = indexRow, ActIndexStart = indexRow, LandlordIndexStart = indexRow; int NumPP = 1;///Номер строки var dtObject = dtReport.AsEnumerable().Select(r => r.Field <int>("IdObject")).Distinct();; foreach (var obj in dtObject) { ObjIndexStart = indexRow; EnumerableRowCollection <DataRow> rcObj = dtReport.AsEnumerable().Where(r => r.Field <int>("IdObject") == obj); report.AddSingleValue(rcObj.First()["Object"].ToString(), indexRow, 1); var dtLandlord = rcObj.AsEnumerable().Select(r => r.Field <int>("IdLandlord")).Distinct(); foreach (var Landlord in dtLandlord) { LandlordIndexStart = indexRow; EnumerableRowCollection <DataRow> rcLandlord = dtReport.AsEnumerable().Where(r => r.Field <int>("IdObject") == obj && r.Field <int>("IdLandlord") == Landlord); report.AddSingleValue(rcLandlord.First()["Landlord"].ToString(), indexRow, 2); var dtActivities = rcLandlord.AsEnumerable().Select(r => r.Field <int>("IdActivities")).Distinct(); foreach (var act in dtActivities) { ActIndexStart = indexRow; EnumerableRowCollection <DataRow> rcAct = dtReport.AsEnumerable().Where(r => r.Field <int>("IdObject") == obj && r.Field <int>("IdLandlord") == Landlord && r.Field <int>("IdActivities") == act); report.AddSingleValue(rcAct.First()["Activities"].ToString(), indexRow, 3); foreach (var dr in rcAct) { report.AddSingleValue(NumPP.ToString(), indexRow, 4); report.AddSingleValue(dr["Tenant"].ToString(), indexRow, 5); report.AddSingleValue(dr["TypeContract"].ToString(), indexRow, 6); report.AddSingleValue(dr["Building"].ToString(), indexRow, 7); report.AddSingleValue(dr["Floor"].ToString(), indexRow, 8); report.AddSingleValue(dr["Section"].ToString(), indexRow, 9); report.AddSingleValue(dr["Work_phone"].ToString(), indexRow, 10); report.AddSingleValue(dr["email"].ToString(), indexRow, 11); report.SetCellAlignmentToLeft(indexRow, 4, indexRow, 11); report.SetCellAlignmentToJustify(indexRow, 4, indexRow, 11); report.SetBorders(indexRow, 4, indexRow, 11); NumPP++; indexRow++; } report.Merge(ActIndexStart, 3, indexRow - 1, 3); report.SetCellAlignmentToLeft(ActIndexStart, 3, indexRow - 1, 3); report.SetCellAlignmentToJustify(ActIndexStart, 3, indexRow - 1, 3); report.SetBorders(ActIndexStart, 3, indexRow - 1, 3); } report.Merge(LandlordIndexStart, 2, indexRow - 1, 2); report.SetCellAlignmentToLeft(LandlordIndexStart, 2, indexRow - 1, 2); report.SetCellAlignmentToJustify(LandlordIndexStart, 2, indexRow - 1, 2); report.SetBorders(LandlordIndexStart, 2, indexRow - 1, 2); } report.Merge(ObjIndexStart, 1, indexRow - 1, 1); report.SetCellAlignmentToLeft(ObjIndexStart, 1, indexRow - 1, 1); report.SetCellAlignmentToJustify(ObjIndexStart, 1, indexRow - 1, 1); report.SetBorders(ObjIndexStart, 1, indexRow - 1, 1); } report.SetColumnAutoSize(1, 1, indexRow - 1, 11); report.SetColumnWidth(10, 4, 11, 4, 5); ///Для № п/п report.SetWrapText(12, 1, indexRow - 1, 11); ///Перенос текста для всех данных кроме телефон и почта report.SetPageSetup(1, 1, true); report.Show(); } this.Enabled = 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 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 void printBlockPass(int indexRow, int indexCol, Nwuram.Framework.ToExcelNew.ExcelUnLoad rep, string nameShort, string fio, string code) { int rowStart = indexRow; //Размеры колонок //rep.SetBorders(indexRow, indexCol, indexRow+8, indexCol+4); rep.SetColumnWidth(indexRow, indexCol, indexRow, indexCol, 15); rep.SetColumnWidth(indexRow, indexCol + 1, indexRow, indexCol, 8); rep.SetColumnWidth(indexRow, indexCol + 2, indexRow, indexCol + 2, 10); rep.SetColumnWidth(indexRow, indexCol + 3, indexRow, indexCol + 3, 5); rep.SetColumnWidth(indexRow, indexCol + 4, indexRow, indexCol + 4, 12); //Начало rep.Merge(indexRow, indexCol, indexRow, indexCol + 1); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 1, "Times New Roman"); rep.AddSingleValue("Пропуск", indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 16); rep.SetCellAlignmentToLeft(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToJustify(indexRow, indexCol, indexRow, indexCol); rep.SetFontBold(indexRow, indexCol, indexRow, indexCol); //+2 колонки rep.Merge(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetFontName(indexRow, indexCol + 2, indexRow, indexCol + 3, "Times New Roman"); rep.AddSingleValue("часы работы", indexRow, indexCol + 2); rep.SetFontSize(indexRow, indexCol + 2, indexRow, indexCol + 3, 12); rep.SetCellAlignmentToLeft(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetCellAlignmentToJustify(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetFontBold(indexRow, indexCol + 2, indexRow, indexCol + 3); //Колонка +4 rep.SetFontName(indexRow, indexCol + 4, indexRow, indexCol + 4, "Code EAN13"); rep.Merge(indexRow, indexCol + 4, indexRow + 8, indexCol + 4); rep.SetOrientation(indexRow, indexCol + 4, indexRow, indexCol + 4, 90); rep.SetFontSize(indexRow, indexCol + 4, indexRow, indexCol + 4, 41); rep.AddSingleValue(ConvertToNewEan(code), indexRow, indexCol + 4); rep.SetCellAlignmentToLeft(indexRow, indexCol + 4, indexRow, indexCol + 4); rep.SetCellAlignmentToJustify(indexRow, indexCol + 4, indexRow, indexCol + 4); //Вторая строка indexRow++; rep.Merge(indexRow, indexCol, indexRow, indexCol + 1); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 1, "Times New Roman"); rep.AddSingleValue("на служебную парковку", indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 12); rep.SetCellAlignmentToLeft(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToJustify(indexRow, indexCol, indexRow, indexCol); //rep.SetFontBold(indexRow, indexCol, indexRow, indexCol); //+2 колонки rep.Merge(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetFontName(indexRow, indexCol + 2, indexRow, indexCol + 3, "Times New Roman"); rep.AddSingleValue("с 7:30 до 2:30", indexRow, indexCol + 2); rep.SetFontSize(indexRow, indexCol + 2, indexRow, indexCol + 3, 12); rep.SetCellAlignmentToLeft(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetCellAlignmentToJustify(indexRow, indexCol + 2, indexRow, indexCol + 3); rep.SetFontBold(indexRow, indexCol + 2, indexRow, indexCol + 3); //3 и 4 строка indexRow++; indexRow++; rep.Merge(indexRow, indexCol, indexRow, indexCol + 3); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 1, "Times New Roman"); rep.AddSingleValue(fio, indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 12); rep.SetCellAlignmentToCenter(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToJustify(indexRow, indexCol, indexRow, indexCol); rep.SetFontBold(indexRow, indexCol, indexRow, indexCol); //5 строка indexRow++; rep.Merge(indexRow, indexCol, indexRow, indexCol + 3); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 1, "Times New Roman"); rep.AddSingleValue("(Фамилия И.О.)", indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 9); rep.SetCellAlignmentToCenter(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToTop(indexRow, indexCol, indexRow, indexCol); //rep.SetFontBold(indexRow, indexCol, indexRow, indexCol); //6 и 7 и 8 строка indexRow++; indexRow++; //rep.Merge(indexRow, indexCol, indexRow, indexCol); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 1, "Times New Roman"); rep.AddSingleValue("Гос. Номер а/м:", indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 11); rep.SetCellAlignmentToLeft(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToJustify(indexRow, indexCol, indexRow, indexCol); //rep.SetFontBold(indexRow, indexCol, indexRow, indexCol); rep.Merge(indexRow, indexCol + 1, indexRow + 1, indexCol + 3); rep.SetWrapText(indexRow, indexCol + 1, indexRow + 1, indexCol + 3); rep.SetFontName(indexRow, indexCol + 1, indexRow, indexCol + 3, "Times New Roman"); rep.AddSingleValue(nameShort, indexRow, indexCol + 1); rep.SetFontSize(indexRow, indexCol + 1, indexRow, indexCol + 3, 12); rep.SetCellAlignmentToCenter(indexRow, indexCol + 1, indexRow, indexCol + 3); rep.SetCellAlignmentToJustify(indexRow, indexCol + 1, indexRow, indexCol + 3); rep.SetFontBold(indexRow, indexCol + 1, indexRow, indexCol + 3); //9 строка indexRow++; indexRow++; rep.Merge(indexRow, indexCol, indexRow, indexCol + 3); rep.SetFontName(indexRow, indexCol, indexRow, indexCol + 3, "Times New Roman"); rep.AddSingleValue("Подпись РДО ___________", indexRow, indexCol); rep.SetFontSize(indexRow, indexCol, indexRow, indexCol, 11); rep.SetCellAlignmentToLeft(indexRow, indexCol, indexRow, indexCol); rep.SetCellAlignmentToJustify(indexRow, indexCol, indexRow, indexCol); rep.SetBordersToAll(rowStart, indexCol, rowStart, indexCol + 4, OfficeOpenXml.Style.ExcelBorderStyle.Medium, 1); rep.SetBordersToAll(indexRow, indexCol, indexRow, indexCol + 4, OfficeOpenXml.Style.ExcelBorderStyle.Medium, 2); rep.SetBordersToAll(rowStart, indexCol, indexRow, indexCol, OfficeOpenXml.Style.ExcelBorderStyle.Medium, 3); rep.SetBordersToAll(rowStart, indexCol + 4, indexRow, indexCol + 4, OfficeOpenXml.Style.ExcelBorderStyle.Medium, 4); rep.SetBordersToAll(rowStart, indexCol + 3, indexRow, indexCol + 3, OfficeOpenXml.Style.ExcelBorderStyle.Medium, 4); }
private void btPrint_Click(object sender, EventArgs e) { if (rbErrorRealiz.Checked) { Task <DataTable> task = Parameters.hConnect.GetReportMainKass(dtpStart.Value.Date, dtpEnd.Value.Date, 1); task.Wait(); if (task.Result == null || task.Result.Rows.Count == 0) { MessageBox.Show("Нет данных для отчёта!", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Logging.StartFirstLevel(489); Logging.Comment($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}"); Logging.Comment($"Отчет по ошибкам в реализации"); Logging.StopFirstLevel(); DataTable dtReport = task.Result.Copy(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); //Nwuram.Framework.ToExcel.HandmadeReport report = new Nwuram.Framework.ToExcel.HandmadeReport(); int indexRow = 1; report.Merge(indexRow, 1, indexRow, 7); 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, 7); report.AddSingleValue($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 7); report.AddSingleValue($"Магазин: {(ConnectionSettings.GetServer().Contains("K21") ? "K21" : "X14")}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 7); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 7); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; report.SetColumnWidth(1, 1, 1, 1, 26); report.SetColumnWidth(1, 2, 1, 2, 20); report.SetColumnWidth(1, 3, 1, 3, 28); report.SetColumnWidth(1, 4, 1, 4, 21); report.SetColumnWidth(1, 5, 1, 5, 22); report.SetColumnWidth(1, 6, 1, 6, 22); report.SetColumnWidth(1, 7, 1, 7, 22); 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.SetFontBold(indexRow, 1, indexRow, 7); report.SetBorders(indexRow, 1, indexRow, 7); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 7); indexRow++; foreach (DataRow row in dtReport.Rows) { report.SetBorders(indexRow, 1, indexRow, 7); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 7); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 7); report.SetWrapText(indexRow, 1, indexRow, 7); report.AddSingleValue($"{((DateTime)row["Data"]).ToShortDateString()}", indexRow, 1); report.AddSingleValue($"{row["nameType"]}", indexRow, 2); report.AddSingleValue($"{row["DateSubmission"]}", indexRow, 3); report.AddSingleValue($"{row["Number"]}", indexRow, 4); report.AddSingleValue($"{row["Comment"]}", indexRow, 5); report.AddSingleValue($"{row["DateConfirm"]}", indexRow, 6); report.AddSingleValue($"{row["Fault"]}", indexRow, 7); indexRow++; } report.Show(); } else if (rbNullDataValidate.Checked) { Task <DataTable> task = Parameters.hConnect.GetReportMainKass(dtpStart.Value.Date, dtpEnd.Value.Date, 2); task.Wait(); if (task.Result == null || task.Result.Rows.Count == 0) { MessageBox.Show("Нет данных для отчёта!", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Logging.StartFirstLevel(489); Logging.Comment($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}"); Logging.Comment($"Отчет об отсутствии сверки данных"); Logging.StopFirstLevel(); DataTable dtReport = task.Result.Copy(); task = Parameters.hConnect.GetRealizForReportMainKass(dtpStart.Value.Date, dtpEnd.Value.Date); task.Wait(); DataTable dtRealiz = new DataTable(); if (task.Result != null && task.Result.Rows.Count != 0) { dtRealiz = task.Result.Copy(); } task = Parameters.hConnectVVO.GetRealizForReportMainKass(dtpStart.Value.Date, dtpEnd.Value.Date); task.Wait(); DataTable dtRealizVVO = new DataTable(); if (task.Result != null && task.Result.Rows.Count != 0) { dtRealizVVO = task.Result.Copy(); } Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); bool isFirstTab = true; for (int i = 3; i >= 1; i--) { EnumerableRowCollection <DataRow> rowCollect = dtReport.AsEnumerable().Where(r => r.Field <int>("type") == i); if (rowCollect.Count() == 0) { continue; } if (!isFirstTab) { report.GoToNextSheet(); } int indexRow = 1; report.Merge(indexRow, 1, indexRow, 3); 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, 3); report.AddSingleValue($"Период с {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 3); report.AddSingleValue($"Магазин: {(ConnectionSettings.GetServer().Contains("K21") ? "K21" : "X14")}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 3); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 3); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; report.SetColumnWidth(1, 1, 1, 1, 26); report.SetColumnWidth(1, 2, 1, 2, 20); report.SetColumnWidth(1, 3, 1, 3, 28); report.AddSingleValue("Причина", indexRow, 1); report.AddSingleValue("Дата", indexRow, 2); report.AddSingleValue("Отдел", indexRow, 3); report.SetFontBold(indexRow, 1, indexRow, 3); report.SetBorders(indexRow, 1, indexRow, 3); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 3); indexRow++; #region "Нет данных «Главная касса»" if (i == 1) { //EnumerableRowCollection<DataRow> rowCollect = dtReport.AsEnumerable().Where(r => r.Field<int>("type") == 1); if (rowCollect.Count() > 0) { if (isFirstTab) { isFirstTab = false; report.changeNameTab("Нет данных «Главная касса»"); } else { report.changeNameTab("Нет данных «Главная касса»"); } int headerStart = indexRow; for (DateTime ii11 = dtpStart.Value; ii11 <= dtpEnd.Value; ii11 = ii11.AddDays(1)) { int midStart = indexRow; bool showData = false; if (rowCollect.AsEnumerable().Where(r => !r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == ii11.Date).Count() == 0) { showData = true; report.AddSingleValue("Все отделы, кроме ВВО", indexRow, 3); indexRow++; } if (rowCollect.AsEnumerable().Where(r => r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == ii11.Date).Count() == 0) { showData = true; report.AddSingleValue("Отдел ВВО", indexRow, 3); indexRow++; } if (showData) { report.Merge(midStart, 2, indexRow - 1, 2); report.AddSingleValue($"{ii11.ToShortDateString()}", midStart, 2); report.SetCellAlignmentToCenter(midStart, 2, indexRow - 1, 2); report.SetCellAlignmentToJustify(midStart, 2, indexRow - 1, 2); } } if (indexRow > headerStart) { report.Merge(headerStart, 1, indexRow - 1, 1); report.SetBorders(headerStart, 1, indexRow - 1, 3); report.SetCellAlignmentToCenter(headerStart, 1, indexRow - 1, 1); report.SetCellAlignmentToJustify(headerStart, 1, indexRow - 1, 1); report.SetWrapText(headerStart, 1, indexRow - 1, 1); report.AddSingleValue($"Нет данных «Главная касса»", headerStart, 1); } } } #endregion #region "Нет сверки с «Реал. SQL»" if (i == 2) { //EnumerableRowCollection<DataRow> rowCollect = dtReport.AsEnumerable().Where(r => r.Field<int>("type") == 2); if (rowCollect.Count() > 0) { if (isFirstTab) { isFirstTab = false; report.changeNameTab("Нет сверки с «Реал. SQL»"); } else { report.changeNameTab("Нет сверки с «Реал. SQL»"); } int headerStart = indexRow; var groupData = rowCollect.AsEnumerable() .GroupBy(g => new { date = g.Field <DateTime>("Data") }) .Select(s => new { s.Key.date }); foreach (var gDate in groupData) { int midStart = indexRow; bool showData = false; foreach (DataRow row in rowCollect.AsEnumerable().Where(r => !r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == gDate.date.Date)) { showData = true; report.AddSingleValue("Все отделы, кроме ВВО", indexRow, 3); indexRow++; } foreach (DataRow row in rowCollect.AsEnumerable().Where(r => r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == gDate.date.Date)) { showData = true; report.AddSingleValue("Отдел ВВО", indexRow, 3); indexRow++; } if (showData) { report.Merge(midStart, 2, indexRow - 1, 2); report.AddSingleValue($"{gDate.date.ToShortDateString()}", midStart, 2); report.SetCellAlignmentToCenter(midStart, 2, indexRow - 1, 2); report.SetCellAlignmentToJustify(midStart, 2, indexRow - 1, 2); } } if (indexRow > headerStart) { report.Merge(headerStart, 1, indexRow - 1, 1); report.AddSingleValue($"Нет сверки с «Реал. SQL»", headerStart, 1); report.SetBorders(headerStart, 1, indexRow - 1, 3); report.SetCellAlignmentToCenter(headerStart, 1, indexRow - 1, 1); report.SetCellAlignmentToJustify(headerStart, 1, indexRow - 1, 1); } } } #endregion #region "Данные «Реал. SQL» отличаются от сохраненных" if (i == 3) { //EnumerableRowCollection<DataRow> rowCollect = dtReport.AsEnumerable().Where(r => r.Field<int>("type") == 3); if (rowCollect.Count() > 0) { if (isFirstTab) { isFirstTab = false; report.changeNameTab("Данные «Реал. SQL» отличаются от сохраненных"); } else { report.changeNameTab("Данные «Реал. SQL» отличаются от сохраненных"); } int headerStart = indexRow; var groupData = rowCollect.AsEnumerable() .GroupBy(g => new { date = g.Field <DateTime>("Data") }) .Select(s => new { s.Key.date }); foreach (var gDate in groupData) { int midStart = indexRow; bool showData = false; foreach (DataRow row in rowCollect.AsEnumerable().Where(r => !r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == gDate.date.Date)) { if (dtRealiz.Rows.Count > 0) { if (dtRealiz.AsEnumerable().Where(r => r.Field <DateTime>("dreal").Date == gDate.date.Date && r.Field <decimal>("RealSql") == (decimal)row["MainKass"]).Count() == 0) { showData = true; report.AddSingleValue("Все отделы, кроме ВВО", indexRow, 3); indexRow++; } } else { showData = true; report.AddSingleValue("Все отделы, кроме ВВО", indexRow, 3); indexRow++; } } foreach (DataRow row in rowCollect.AsEnumerable().Where(r => r.Field <bool>("isVVO") && r.Field <DateTime>("Data").Date == gDate.date.Date)) { if (dtRealizVVO.Rows.Count > 0) { if (dtRealizVVO.AsEnumerable().Where(r => r.Field <DateTime>("dreal").Date == gDate.date.Date && r.Field <decimal>("RealSql") == (decimal)row["MainKass"]).Count() == 0) { showData = true; report.AddSingleValue("Отдел ВВО", indexRow, 3); indexRow++; } } else { showData = true; report.AddSingleValue("Отдел ВВО", indexRow, 3); indexRow++; } } if (showData) { report.Merge(midStart, 2, indexRow - 1, 2); report.AddSingleValue($"{gDate.date.ToShortDateString()}", midStart, 2); report.SetCellAlignmentToCenter(midStart, 2, indexRow - 1, 2); report.SetCellAlignmentToJustify(midStart, 2, indexRow - 1, 2); } } if (indexRow > headerStart) { report.Merge(headerStart, 1, indexRow - 1, 1); report.SetBorders(headerStart, 1, indexRow - 1, 3); report.SetCellAlignmentToCenter(headerStart, 1, indexRow - 1, 1); report.SetCellAlignmentToJustify(headerStart, 1, indexRow - 1, 1); report.SetWrapText(headerStart, 1, indexRow - 1, 1); report.AddSingleValue($"Данные «Реал. SQL» отличаются от сохраненных", headerStart, 1); } } } #endregion } report.Show(); } }
private void btPrint_Click(object sender, EventArgs e) { Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка отчета с превышения процента наценки"); Logging.Comment($"Количество выгруженных записей: {dtResult.Rows.Count}"); Logging.Comment($"Настройка процента наценки: {tbPrcn.Text}"); Logging.StopFirstLevel(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad("list-1"); int rIndex = 1; int maxMerge = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxMerge++; } } report.Merge(rIndex, 1, rIndex, maxMerge); report.AddSingleValue("Проверка превышения процента наценки", rIndex, 1); report.SetCellAlignmentToCenter(rIndex, 1, rIndex, 1); report.SetFontBold(rIndex, 1, rIndex, 1); report.SetFontSize(rIndex, 1, rIndex, 1, 14); rIndex++; report.Merge(rIndex, 1, rIndex, 2); report.Merge(rIndex, 5, rIndex, 7); report.AddSingleValue("Дата: " + date.ToShortDateString(), rIndex, 1); report.AddSingleValue("Выгрузил: " + UserSettings.User.FullUsername, rIndex, 3); report.SetCellAlignmentToRight(rIndex, 3, rIndex, 3); rIndex++; string shotName = ""; if (Nwuram.Framework.Settings.Connection.ConnectionSettings.GetServer().ToLower().Contains("k21")) { shotName = "Косыгина 21"; } else { shotName = "Хошимина 14"; } report.Merge(rIndex, 1, rIndex, 2); report.Merge(rIndex, 3, rIndex, 4); report.Merge(rIndex, 5, rIndex, 7); report.AddSingleValue("Процент наценки: " + tbPrcn.Text, rIndex, 1); report.AddSingleValue("Магазин: " + shotName, rIndex, 3); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), rIndex, 5); report.SetCellAlignmentToRight(rIndex, 3, rIndex, 3); rIndex++; rIndex++; int cIndex = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { cIndex++; report.AddSingleValue(col.HeaderText, rIndex, cIndex); } } report.SetBorders(rIndex, 1, rIndex, cIndex); report.SetCellAlignmentToCenter(rIndex, 1, rIndex, cIndex); report.SetWrapText(rIndex, 1, rIndex, cIndex); rIndex++; foreach (DataRowView row in dtResult.DefaultView) { cIndex = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { cIndex++; report.AddSingleValue(row[col.DataPropertyName].ToString(), rIndex, cIndex); } } report.SetBorders(rIndex, 1, rIndex, cIndex); report.SetCellAlignmentToCenter(rIndex, 1, rIndex, cIndex); rIndex++; } report.SetColumnAutoSize(1, 1, rIndex, maxMerge); report.Show(); }
private async void btPrint_Click(object sender, EventArgs e) { var result = await Task <bool> .Factory.StartNew(() => { if (dtData == null || dtData.Rows.Count == 0 || dtData.DefaultView.Count == 0) { MessageBox.Show("Нет данных для формирования отчёта.", "Печать", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxColumns = 0; Config.DoOnUIThread(() => { blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); progressBar1.Visible = true; Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка отчета из формы \"Сравнение наименований товаров\" со следующими фильтрами:"); Logging.Comment($"Отдел ID:{cmbDeps.SelectedValue}; Наименование:{cmbDeps.Text}"); Logging.Comment($"Т/У группа ID:{cmbTU.SelectedValue}; Наименование:{cmbTU.Text}"); Logging.Comment($"Инв. группа ID:{cmbInv.SelectedValue}; Наименование:{cmbInv.Text}"); Logging.Comment($"Тип товара:{(rbAll.Checked ? rbAll.Text : rbSingle.Checked ? rbSingle.Text : rbMass.Text)}"); if (tbEan.Text.Trim().Length > 0) { Logging.Comment($"EAN:{tbEan.Text}"); } if (tbNameTerminal.Text.Trim().Length > 0) { Logging.Comment($"Наименование товара на кассе:{tbNameTerminal.Text}"); } if (tbName.Text.Trim().Length > 0) { Logging.Comment($"Короткое наименование товар на сайте:{tbName.Text}"); } Logging.StopFirstLevel(); }, this); foreach (DataGridViewColumn col in dgvData.Columns) { if (!col.Visible || col.Name.Equals(cV.Name)) { continue; } maxColumns++; if (col.Name.Equals(cEan.Name)) { setWidthColumn(indexRow, maxColumns, 17, report); } else { setWidthColumn(indexRow, maxColumns, 60, report); } } #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.SetWrapText(indexRow, 1, indexRow, 1); report.SetRowHeight(indexRow, 1, indexRow, 1, 45); 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($"Отдел: {cmbDeps.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Т/У группа: {cmbTU.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Инв. группа: {cmbInv.Text}", indexRow, 1); indexRow++; string typeGoods = rbAll.Checked ? rbAll.Text : rbMass.Checked ? rbMass.Text : rbSingle.Checked ? rbSingle.Text : ""; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Тип товара: {typeGoods}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"Отдел: {cmbDeps.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); }, this); indexRow++; indexRow++; #endregion int j = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (!col.Visible || col.Name.Equals(cV.Name)) { continue; } j++; report.AddSingleValue(col.HeaderText, indexRow, j); } 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) { j = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (!col.Visible || col.Name.Equals(cV.Name)) { continue; } j++; setValueToCell(indexRow, j, row[col.DataPropertyName]); } 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++; } Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); report.SetPageSetup(1, 9999, true); report.ShowPreview(); return(true); }); }
private void btExcel_Click(object sender, EventArgs e) { Logging.StartFirstLevel(79); Logging.Comment("Произведена выгрузка в Excel отчета «Отчет по сканерам»"); Logging.Comment("Операцию выполнил: ID:" + Nwuram.Framework.Settings.User.UserSettings.User.Id + " ; ФИО:" + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername); Logging.StopFirstLevel(); Nwuram.Framework.ToExcelNew.ExcelUnLoad report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad("Лист - 1"); report.SetPageOrientationToLandscape(); int indexRow = 1; report.Merge(indexRow, 1, indexRow, 9); report.AddSingleValue("Отчёт по сканерам", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 3); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 3); report.SetFontSize(indexRow, 1, indexRow, 1, 16); indexRow++; report.Merge(indexRow, 1, indexRow, 9); report.AddSingleValue("Период с : " + dtpStart.Value.ToShortDateString() + " по: " + dtpEnd.Value.ToShortDateString(), indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 9); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, 9); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); indexRow++; indexRow++; indexRow++; int indexColum = 1; foreach (DataGridViewColumn col in dgvScaner.Columns) { report.AddSingleValue(col.HeaderText, indexRow, indexColum); indexColum++; if (col.Name.Equals("cTimeDrop")) { report.AddSingleValue("Сканер Выдал", indexRow, indexColum); indexColum++; } } //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.SetCellAlignmentToCenter(indexRow, 1, indexRow, indexColum - 1); report.SetBorders(indexRow, 1, indexRow, indexColum - 1); indexRow++; foreach (DataRowView r in dtJournalScaner.DefaultView) { report.AddSingleValue(r["InventoryNumber"].ToString(), indexRow, 1); report.AddSingleValue(r["EAN"].ToString(), indexRow, 2); report.AddSingleValue(r["cName"].ToString(), indexRow, 3); report.AddSingleValue(r["nameOut"].ToString(), indexRow, 4); report.AddSingleValue(r["nameDeps"].ToString(), indexRow, 5); report.AddSingleValue(r["DateOut"].ToString(), indexRow, 6); report.AddSingleValue(r["FIO"].ToString(), indexRow, 7); report.AddSingleValue(r["nameGet"].ToString(), indexRow, 8); report.AddSingleValue(r["DateGet"].ToString(), indexRow, 9); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 9); report.SetBorders(indexRow, 1, indexRow, 9); indexRow++; } report.SetColumnAutoSize(1, 1, indexRow - 1, 9); 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("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++; 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, indexCol); if (tmpValue is DateTime) { report.AddSingleValue(((DateTime)tmpValue).ToShortDateString(), startMergRow, indexCol); } else { report.AddSingleValue(tmpValue.ToString(), startMergRow, 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 { 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 { 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) { await 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); //if (report == null) report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); int indexRow = 1; int maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; } } setWidthColumn(indexRow, 1, 13, report); setWidthColumn(indexRow, 2, 16, report); setWidthColumn(indexRow, 3, 25, report); setWidthColumn(indexRow, 4, 25, report); setWidthColumn(indexRow, 5, 17, report); setWidthColumn(indexRow, 6, 17, report); setWidthColumn(indexRow, 7, 20, report); report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{this.Text}", indexRow, 1); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, 1); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, 1); report.SetFontSize(indexRow, 1, indexRow, 1, 18); indexRow++; indexRow++; Config.DoOnUIThread(() => { report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label3.Text} {dtpStart.Value.ToShortDateString()} по {dtpEnd.Value.ToShortDateString()}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label5.Text}:{cmbDriver.Text}", indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue($"{label6.Text}:{cmbShop.Text}", indexRow, 1); indexRow++; if (tbNumber.Text.Length > 0 || tbFioMan.Text.Length > 0) { report.Merge(indexRow, 1, indexRow, maxCol); string str = "Фильтры: "; if (tbNumber.Text.Length > 0) { str += $"Номер маршрута: {tbNumber.Text};"; } if (tbFioMan.Text.Length > 0) { str += $"Водитель: {tbFioMan.Text};"; } report.AddSingleValue($"{str}", indexRow, 1); indexRow++; } report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Выгрузил: " + Nwuram.Framework.Settings.User.UserSettings.User.FullUsername, indexRow, 1); indexRow++; report.Merge(indexRow, 1, indexRow, maxCol); report.AddSingleValue("Дата выгрузки: " + DateTime.Now.ToString(), indexRow, 1); }, this); indexRow++; indexRow++; maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; report.AddSingleValue(col.HeaderText, indexRow, maxCol); } } report.SetFontBold(indexRow, 1, indexRow, maxCol); report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetWrapText(indexRow, 1, indexRow, maxCol); indexRow++; foreach (DataRowView row in dtData.DefaultView) { maxCol = 0; foreach (DataGridViewColumn col in dgvData.Columns) { if (col.Visible) { maxCol++; setValueToCell(indexRow, maxCol, row[col.DataPropertyName]); } } report.SetBorders(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxCol); report.SetCellAlignmentToRight(indexRow, 5, indexRow, 7); indexRow++; } report.SetPageSetup(1, 9999, true); report.Show(); Config.DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); fLoad.Dispose(); }, this); }); }
private async void btPrint_Click(object sender, EventArgs e) { report = new Nwuram.Framework.ToExcelNew.ExcelUnLoad(); blockers.SaveControlsEnabledState(this); blockers.SetControlsEnabled(this, false); progressBar1.Visible = true; var result = await Task <bool> .Factory.StartNew(() => { DataTable dtReport = _proc.GetReportPayAgreement(dtpStart.Value.Date, dtpEnd.Value.Date); if (dtReport == null || dtReport.Rows.Count == 0) { DoOnUIThread(() => { MessageBox.Show("Нет данных для выгрузки", "Выгрузка отчёта", MessageBoxButtons.OK, MessageBoxIcon.Information); blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); return(false); } Logging.StartFirstLevel(79); Logging.Comment("Выгрузка отчёта по добавленным оплатам"); Logging.StopFirstLevel(); int indexRow = 1; int maxColumns = 9; bool isFirstLoad = false; List <int> numbers = new List <int>() { 1, 3, 2 }; //for (int i = 1; i <= 3; i++) foreach (int i in numbers) { EnumerableRowCollection <DataRow> rowCollect = dtReport.AsEnumerable() .Where(r => r.Field <int>("id_PayType") == i) .OrderBy(r => r.Field <DateTime>("Date")); if (rowCollect.Count() == 0) { continue; } if (!isFirstLoad) { isFirstLoad = true; report.changeNameTab(rowCollect.First()["namePayType"].ToString()); } else { report.GoToNextSheet(rowCollect.First()["namePayType"].ToString()); } indexRow = 1; #region "Head" report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rowCollect.First()["namePayType"]}", 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 setWidthColumn(indexRow, 1, 21, report); setWidthColumn(indexRow, 2, 21, report); setWidthColumn(indexRow, 3, 20, report); setWidthColumn(indexRow, 4, 30, report); report.AddSingleValue("Арендодатель", indexRow, 1); report.AddSingleValue("Арендатор", indexRow, 2); report.AddSingleValue("Номер договора", indexRow, 3); report.AddSingleValue("Местоположение по договору", indexRow, 4); report.SetPrintRepeatHead(indexRow, indexRow); #region "Обеспечительный платёж" if (i == 1) { maxColumns = 8; setWidthColumn(indexRow, 5, 14, report); setWidthColumn(indexRow, 6, 17, report); setWidthColumn(indexRow, 7, 20, report); 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++; EnumerableRowCollection <DataRow> Rows = rowCollect.Where(r => r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Наличные", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["Date"], indexRow, 5, report); addDataToCell(row["Summa"], indexRow, 6, report); addDataToCell(row["nameSavePayment"], indexRow, 7, report); addDataToCell(row["nameToTenant"], indexRow, 8, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } Rows = rowCollect.Where(r => !r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Безналичный расчёт", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["Date"], indexRow, 5, report); addDataToCell(row["Summa"], indexRow, 6, report); addDataToCell(row["nameSavePayment"], indexRow, 7, report); addDataToCell(row["nameToTenant"], indexRow, 8, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } } #endregion #region "Оплата аренды" if (i == 2) { maxColumns = 8; setWidthColumn(indexRow, 5, 14, report); setWidthColumn(indexRow, 6, 17, report); setWidthColumn(indexRow, 7, 10, report); setWidthColumn(indexRow, 8, 17, report); 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++; EnumerableRowCollection <DataRow> Rows = rowCollect.Where(r => r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Наличные", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["Date"], indexRow, 5, report); addDataToCell(row["Summa"], indexRow, 6, report); addDataToCell(row["nameToTenant"], indexRow, 7, report); addDataToCell(row["PlaneDate"], indexRow, 8, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } Rows = rowCollect.Where(r => !r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Безналичный расчёт", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["Date"], indexRow, 5, report); addDataToCell(row["Summa"], indexRow, 6, report); addDataToCell(row["nameToTenant"], indexRow, 7, report); addDataToCell(row["PlaneDate"], indexRow, 8, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } } #endregion #region "Дополнительная оплата" if (i == 3) { maxColumns = 10; setWidthColumn(indexRow, 5, 17, report); setWidthColumn(indexRow, 6, 13, report); setWidthColumn(indexRow, 7, 12, report); setWidthColumn(indexRow, 8, 12, report); setWidthColumn(indexRow, 9, 15, report); setWidthColumn(indexRow, 10, 13, report); 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.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++; EnumerableRowCollection <DataRow> Rows = rowCollect.Where(r => r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Наличные", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["nameAddPayment"], indexRow, 5, report); addDataToCell(row["DateFines"], indexRow, 6, report); addDataToCell(row["Date"], indexRow, 7, report); addDataToCell(row["Summa"], indexRow, 8, report); addDataToCell(row["nameToTenant"], indexRow, 9, report); addDataToCell(row["PlaneDate"], indexRow, 10, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } Rows = rowCollect.Where(r => !r.Field <bool>("isCash")); if (Rows.Count() > 0) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue("Безналичный расчёт", indexRow, 1); 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 gData = Rows.AsEnumerable().GroupBy(g => new { Date = g.Field <DateTime>("Date") }).Select(s => new { s.Key.Date }); foreach (var rData in gData) { report.Merge(indexRow, 1, indexRow, maxColumns); report.AddSingleValue($"{rData.Date.ToShortDateString()}", indexRow, 1); 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 (DataRow row in Rows.AsEnumerable().Where(r => r.Field <DateTime>("Date").Date == rData.Date)) { report.SetWrapText(indexRow, 1, indexRow, maxColumns); addDataToCell(row["nameTenant"], indexRow, 1, report); addDataToCell(row["nameLandLord"], indexRow, 2, report); addDataToCell(row["Agreement"], indexRow, 3, report); addDataToCell(row["namePlace"], indexRow, 4, report); addDataToCell(row["nameAddPayment"], indexRow, 5, report); addDataToCell(row["DateFines"], indexRow, 6, report); addDataToCell(row["Date"], indexRow, 7, report); addDataToCell(row["Summa"], indexRow, 8, report); addDataToCell(row["nameToTenant"], indexRow, 9, report); addDataToCell(row["PlaneDate"], indexRow, 10, report); report.SetBorders(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToCenter(indexRow, 1, indexRow, maxColumns); report.SetCellAlignmentToJustify(indexRow, 1, indexRow, maxColumns); indexRow++; } } } } #endregion report.SetPageSetup(1, 9999, true); } report.Show(); DoOnUIThread(() => { blockers.RestoreControlEnabledState(this); progressBar1.Visible = false; }, this); return(true); }); }
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 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]); //} }