Exemplo n.º 1
0
        private void btPrintPass_Click(object sender, EventArgs e)
        {
            EnumerableRowCollection <DataRow> rowCollect = dtData.AsEnumerable().Where(r => r.Field <bool>("isSelect"));

            if (rowCollect.Count() > 0)
            {
                Nwuram.Framework.ToExcelNew.ExcelUnLoad rep = new Nwuram.Framework.ToExcelNew.ExcelUnLoad();
                rep.SetPageOrientationToLandscape();

                int indexRow = 0;
                int indexCol = 1;
                int cnt      = 0;
                foreach (DataRow row in rowCollect)
                {
                    if (row["FullNameCar"] == DBNull.Value)
                    {
                        continue;
                    }

                    int    id_User_vs_Car = (int)row["id_User_vs_Car"];
                    string nameShort      = (string)row["ShortNameCar"];
                    string fio            = $"{(string)row["lastname"]} {(string)row["firstname"]} {(string)row["secondname"]}";
                    string code           = row["Code"].ToString();

                    if (code.Length == 0)
                    {
                        continue;
                    }

                    if (cnt % 2 != 0)
                    {
                        indexCol += 6;
                    }
                    else
                    {
                        indexRow += indexRow == 0 ? 1 : 11;
                        indexCol  = 1;
                    }



                    printBlockPass(indexRow, indexCol, rep, nameShort, fio, code);
                    cnt++;
                }
                rep.Show();
                return;
            }
            else
            if (dgvData.SelectedRows.Count > 1)
            {
                Nwuram.Framework.ToExcelNew.ExcelUnLoad rep = new Nwuram.Framework.ToExcelNew.ExcelUnLoad();
                rep.SetPageOrientationToLandscape();

                int indexRow = 0;
                int indexCol = 1;
                int cnt      = 0;
                foreach (DataGridViewRow rGrid in dgvData.SelectedRows)
                {
                    DataRowView row = dtData.DefaultView[rGrid.Index];

                    if (row["FullNameCar"] == DBNull.Value)
                    {
                        continue;
                    }

                    int    id_User_vs_Car = (int)row["id_User_vs_Car"];
                    string nameShort      = (string)row["ShortNameCar"];
                    string fio            = $"{(string)row["lastname"]} {(string)row["firstname"]} {(string)row["secondname"]}";
                    string code           = row["Code"].ToString();

                    if (code.Length == 0)
                    {
                        continue;
                    }

                    if (cnt % 2 != 0)
                    {
                        indexCol += 6;
                    }
                    else
                    {
                        indexRow += indexRow == 0 ? 1 : 11;
                        indexCol  = 1;
                    }



                    printBlockPass(indexRow, indexCol, rep, nameShort, fio, code);
                    cnt++;
                }
                rep.Show();

                return;
            }
            else
            {
                DataRowView row = dtData.DefaultView[dgvData.CurrentRow.Index];
                if (row["FullNameCar"] == DBNull.Value)
                {
                    return;
                }

                int    id_User_vs_Car = (int)row["id_User_vs_Car"];
                string nameShort      = (string)row["ShortNameCar"];
                string fio            = $"{(string)row["lastname"]} {(string)row["firstname"]} {(string)row["secondname"]}";
                string code           = row["Code"].ToString();



                Nwuram.Framework.ToExcelNew.ExcelUnLoad rep = new Nwuram.Framework.ToExcelNew.ExcelUnLoad();
                rep.SetPageOrientationToLandscape();

                int indexRow = 1;
                int indexCol = 1;

                printBlockPass(indexRow, indexCol, rep, nameShort, fio, code);
                rep.Show();
                return;
            }


            //return;


            /*
             * string windowsPath = Environment.GetEnvironmentVariable("windir");
             * //задаем путь к файлу шрифта
             * string path = windowsPath[0].ToString() + ":/Windows/Fonts/ean13.ttf";
             * /*if (!File.Exists(path))
             * {
             *  MessageBox.Show("Отсутствует установленный шрифт ean13.ttf", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  return true;
             * }
             */

            /*
             * path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Templates\\pass.xls";
             * if (!File.Exists(path))
             * {
             *  MessageBox.Show("Отсутствует шаблон выгрузки данных по пути\n" + path, "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  return;
             * }
             *
             * string pathOut = Path.GetDirectoryName(Application.ExecutablePath) + "\\passPrint.xls";
             *
             * Nwuram.Framework.ToExcel.Report report = new Nwuram.Framework.ToExcel.Report();
             * report.AddSingleValue("FIO", fio.Trim());
             * report.AddSingleValue("ShortName", nameShort);
             * report.AddSingleValue("code", ConvertToNewEan(code));
             * report.CreateTemplate(path.Replace(".xls", ""), pathOut.Replace(".xls", ""), "");
             * // report.OpenFile(pathOut);
             *
             * Task<DataTable> task = Config.hCntMain.setPassCarUnload(id_User_vs_Car);
             * task.Wait();
             *
             * DataTable dtResult = task.Result;
             *
             * if (dtResult == null || dtResult.Rows.Count == 0)
             * {
             *  MessageBox.Show("Не удалось сохранить данные", "Ошибка сохранения", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  return;
             * }
             *
             * if ((int)dtResult.Rows[0]["id"] == -9999)
             * {
             *  MessageBox.Show($"{dtResult.Rows[0]["msg"]}", "Ошибка сохранения", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  return;
             * }
             *
             * report.OpenFile(pathOut.Replace(".xls", ""));
             */

            getData();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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;
            });
        }