Ejemplo n.º 1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            ExcelUnLoad rep = new ExcelUnLoad("Отчет по секциям");

            rep.AddSingleValue("Справочник секций", 1, 1);
            rep.Merge(1, 1, 1, 9);
            rep.SetBordersToBottom(1, 1, 9, true);
            rep.SetBordersToBottom(1, 2, 9, true);
            rep.SetBordersToBottom(1, 3, 9, true);
            rep.SetBordersToBottom(1, 4, 9, true);
            rep.SetBordersToBottom(1, 5, 9, true);
            rep.SetBordersToBottom(1, 6, 9, true);
            rep.SetBordersToBottom(1, 7, 9, true);
            rep.SetBordersToBottom(1, 8, 9, true);
            rep.SetBordersToBottom(1, 9, 9, true);

            // rep.SetBorders(1, 1, 1, 9);
            rep.SetFontBold(1, 1, 1, 1);
            rep.SetFontSize(1, 1, 1, 1, 16);
            rep.SetCellAlignmentToCenter(1, 1, 1, 1);
            int crow = 3;

            rep.AddSingleValue($"Объект: {obj}", crow, 1);
            crow++;
            rep.AddSingleValue($"Здание: {build}", crow, 1);
            crow++;
            rep.AddSingleValue($"Этаж: {floor}", crow, 1);
            crow += 2;
            rep.AddSingleValue($"Выгрузил: {Nwuram.Framework.Settings.User.UserSettings.User.FullUsername}", crow, 1);
            crow++;
            rep.AddSingleValue($"Дата выгрузки: {DateTime.Now}", crow, 1);
            crow += 2;
            int startRow = crow;

            #region Шапка
            rep.AddSingleValue("Секция", crow, 1);
            rep.AddSingleValue("Объект", crow, 2);
            rep.AddSingleValue("Здание", crow, 3);
            rep.AddSingleValue("Этаж", crow, 4);
            rep.AddSingleValue("Кол-во телефонных линий", crow, 5);
            rep.AddSingleValue("Кол-во светильников", crow, 6);
            rep.AddSingleValue("Номер телефона", crow, 7);
            rep.AddSingleValue("Оборудование и кол-во", crow, 8);
            rep.AddSingleValue("Приборы/части системы", crow, 9);

            #endregion

            #region ширина столбцов
            rep.SetColumnWidth(1, 1, 1, 1, 9);
            rep.SetColumnWidth(1, 2, 1, 2, 9);
            rep.SetColumnWidth(1, 3, 1, 3, 17);
            rep.SetColumnWidth(1, 4, 1, 4, 9);
            rep.SetColumnWidth(1, 5, 1, 5, 13);
            rep.SetColumnWidth(1, 6, 1, 6, 14);
            rep.SetColumnWidth(1, 7, 1, 7, 10);
            rep.SetColumnWidth(1, 8, 1, 8, 20);
            rep.SetColumnWidth(1, 9, 1, 9, 20);
            #endregion

            rep.SetFontBold(crow, 1, crow, 9);
            rep.SetCellAlignmentToCenter(crow, 1, crow, 9);
            rep.SetCellAlignmentToJustify(crow, 1, crow, 9);
            rep.SetWrapText(crow, 1, crow, 9);
            crow++;



            if (tSec.Rows.Count > 0)
            {
                for (int i = 0; i < view.Count; i++)
                {
                    string A, I, sEq = "";
                    string sDevices = "";
                    A = "A" + (i + 11);
                    I = "I" + (i + 11);

                    int isActive = 0;

                    if (checEq.Checked == true)
                    {
                        isActive = 1;
                    }
                    else
                    {
                        isActive = 0;
                    }

                    foreach (DataRow dr in _proc.GetEqVsSec(tSec.DefaultView[i]["id"].ToString(), isActive).Rows)
                    {
                        if (sEq.Length > 0)
                        {
                            sEq += "\n";
                        }
                        sEq += dr["cName"] + " " + dr["Quantity"] + " шт.";
                    }

                    DataTable dtDevices = _proc.GetSectionDevices(Convert.ToInt32(tSec.DefaultView[i]["id"]));
                    foreach (DataRow dr in dtDevices.Rows)
                    {
                        if (sDevices.Length > 0)
                        {
                            sDevices += "\n";
                        }
                        sDevices += dr["cname"].ToString() + " " + dr["quantity"].ToString() + " " + dr["unit"].ToString();
                    }

                    rep.AddSingleValue(tSec.DefaultView[i]["Sec"].ToString(), crow, 1);
                    rep.AddSingleValue(tSec.DefaultView[i]["Obj"].ToString(), crow, 2);
                    rep.AddSingleValue(tSec.DefaultView[i]["Build"].ToString(), crow, 3);
                    rep.AddSingleValue(tSec.DefaultView[i]["Floo"].ToString(), crow, 4);
                    rep.AddSingleValue(tSec.DefaultView[i]["Telephone_lines"].ToString(), crow, 5);
                    rep.AddSingleValue(tSec.DefaultView[i]["Lamps"].ToString(), crow, 6);
                    rep.AddSingleValue(tSec.DefaultView[i]["Phone_number"].ToString(), crow, 7);
                    rep.AddSingleValue(sEq, crow, 8);
                    rep.AddSingleValue(sDevices, crow, 9);
                    rep.SetWrapText(crow, 1, crow, 9);
                    rep.SetCellAlignmentToTop(crow, 1, crow, 9);
                    crow++;
                }
            }

            rep.SetBorders(startRow, 1, crow - 1, 9);
            rep.SetPageOrientationToLandscape();
            rep.Show();
            string logEvent = "Выгрузка справочника секций в Excel";

            string BuildName = "";
            cbZdan.Invoke((MethodInvoker) delegate
            {
                BuildName = cbZdan.Text;
            });

            string FloorName = "";

            cbZloor.Invoke((MethodInvoker) delegate
            {
                FloorName = cbZloor.Text;
            });

            Logging.StartFirstLevel(763);
            Logging.Comment(logEvent);
            Logging.Comment("Имя выгруженного excel файла \"" + file.Name + "\"");
            Logging.Comment("Выгрузка произведена для здания: \"" + BuildName + "\" и этажа: \"" + FloorName + "\". Выгружено " + view.Count.ToString() + " строк.");
            Logging.Comment("Завершение операции \"" + logEvent + "\"");
            Logging.StopFirstLevel();
        }