public string GenerateAutopsyReport(deviceFullDetails device)
        {
            string rootPath = AppDomain.CurrentDomain.BaseDirectory;


            string niceDeviceName = "";

            //if(device.deviceName.Length > 25)
            //{
            //    niceDeviceName = "\"" + device.deviceName.Substring(0, 25) + ".\"";
            //}
            //else
            //{
            niceDeviceName = "\"" + device.deviceName + "\"";
            //}

            string[] reasons;
            if (specialDeviceTypeList.Any(device.deviceName.ToLower().Contains))
            {
                reasons = File.ReadAllLines(rootPath + "reasons\\" + specialDeviceReasonsDictionary[specialDeviceTypeList.FirstOrDefault(device.deviceName.ToLower().Contains)]);
            }

            else
            {
                reasons = File.ReadAllLines(rootPath + "reasons\\" + "general.txt", Encoding.ASCII);
            }
            string[] morale = File.ReadAllLines(rootPath + "reasons\\" + "moral.txt", Encoding.ASCII);

            int    n1     = r.Next(reasons.Length);
            int    n2     = r.Next(morale.Length);
            string result = reasons[n1].Replace("$object$", niceDeviceName) + " " + morale[n2] + " " + addToAllAutopsyText;

            return(result);
        }
        public void GenerateFullAutopsyReport(deviceFullDetails device1, string pathToSave, bool needXLSX, bool needPDF)
        {
            string templatePath = AppDomain.CurrentDomain.BaseDirectory + "template.xlsx";

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelApp.Visible = false;

            Workbook myWorkbook = excelApp.Workbooks.Open(templatePath);

            Sheets    myWorksheets = myWorkbook.Worksheets;
            Worksheet myWorksheet  = (Worksheet)myWorksheets.get_Item("sheet");

            Range myRange = myWorksheet.get_Range(deviceNamePos[0]);

            myRange.Value = device1.deviceName;

            myRange       = myWorksheet.get_Range(deviceYearWasMadePos[0]);
            myRange.Value = device1.deviceYearWasMade;

            myRange       = myWorksheet.get_Range(deviceFactoryWasMadePos[0]);
            myRange.Value = device1.deviceFactoryWasMade;

            myRange       = myWorksheet.get_Range(deviceIdPos[0]);
            myRange.Value = device1.deviceId;

            myRange       = myWorksheet.get_Range(deviceWasUsedSincePos[0]);
            myRange.Value = device1.deviceWasUsedSince;

            myRange       = myWorksheet.get_Range(deviceYearWasMadePos[0]);
            myRange.Value = device1.deviceYearWasMade;

            myRange       = myWorksheet.get_Range(deviceAmount[0]);
            myRange.Value = device1.deviceAmount;

            myRange       = myWorksheet.get_Range(devicePlacePos[0]);
            myRange.Value = device1.devicePlace;

            myRange       = myWorksheet.get_Range(deviceBossPos[0]);
            myRange.Value = device1.deviceBoss;

            myRange       = myWorksheet.get_Range(deviceAutopsyReportPos[0]);
            myRange.Value = GenerateAutopsyReport(device1);

            //Random r = new Random();
            string futureFileName = device1.deviceName.Substring(0, 5) + r.Next(100).ToString();

            myWorkbook.SaveAs(pathToSave + futureFileName + ".xlsx");
            myWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pathToSave + futureFileName + ".pdf");
            excelApp.Quit();
        }
        public List <deviceFullDetails> GetDevicesToDrop(string pathToExcelList)
        {
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            excelApp.Visible = false;

            Workbook  myWorkbook   = excelApp.Workbooks.Open(pathToExcelList);
            Sheets    myWorksheets = myWorkbook.Worksheets;
            Worksheet myWorksheet  = (Worksheet)myWorksheets.get_Item("list");

            List <deviceFullDetails> deviceList = new List <deviceFullDetails>();

            for (int i = 2; i < 1000; i++)
            {
                deviceFullDetails tmp     = new deviceFullDetails();
                Range             myRange = myWorksheet.get_Range("A" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceName = myRange.Value.ToString();
                }
                else
                {
                    break;
                }

                myRange = myWorksheet.get_Range("B" + i.ToString());
                if (myRange.Value != null)
                {
                    if (myRange.Value.ToString().IndexOf("шт") < 0)
                    {
                        tmp.deviceAmount = myRange.Value.ToString() + " шт.";
                    }
                    else
                    {
                        tmp.deviceAmount = myRange.Value.ToString();
                    }
                }
                else
                {
                    tmp.deviceAmount = "1 шт.";
                }

                myRange = myWorksheet.get_Range("C" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceYearWasMade = myRange.Value.ToString();
                }
                else
                {
                    tmp.deviceYearWasMade = "";
                }

                myRange = myWorksheet.get_Range("D" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceFactoryWasMade = myRange.Value.ToString();
                }
                else
                {
                    tmp.deviceFactoryWasMade = "";
                }

                myRange = myWorksheet.get_Range("E" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceId = myRange.Value.ToString();
                }
                else
                {
                    tmp.deviceId = "";
                }

                myRange = myWorksheet.get_Range("F" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceWasUsedSince = myRange.Value.ToString();
                }
                else
                {
                    tmp.deviceWasUsedSince = "";
                }

                myRange = myWorksheet.get_Range("G" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.devicePlace = myRange.Value.ToString();
                }
                else
                {
                    tmp.devicePlace = "";
                }

                myRange = myWorksheet.get_Range("H" + i.ToString());
                if (myRange.Value != null)
                {
                    tmp.deviceBoss = myRange.Value.ToString();
                }
                else
                {
                    tmp.deviceBoss = "";
                }

                deviceList.Add(tmp);
            }
            myWorkbook.Close();
            excelApp.Quit();
            return(deviceList);
        }