private void ShowTableData() { int i = 1; WatsEmiDataManager watsEmiDataManager; double azimuth; int rowId; ChannelSetting channelSetting; WatsEmiData watsEmiData; ChannelPower channelPower; DataTable.Rows.Clear(); foreach (EMIFileData emiFileData in mEmiFileDatas) { watsEmiDataManager = WatsEmiReportTool.Utility.GetEmiDataManager(emiFileData, mChannelSettings); foreach (KeyValuePair<double, Dictionary<ChannelSetting, WatsEmiData>> pair in watsEmiDataManager.AllChannelSamples) { azimuth = pair.Key; if ((BothToolStripButton.Checked || VerticalToolStripButton.Checked) && FilterToolStripButton.Checked || UnFilterToolStripButton.Checked) { //vertical channel foreach (KeyValuePair<ChannelSetting, WatsEmiData> subPair in pair.Value) { channelSetting = subPair.Key; watsEmiData = subPair.Value; channelPower = new ChannelPower(emiFileData.SA_RBW, channelSetting, new LimitSetting(), watsEmiData); rowId = DataTable.Rows.Add(); DataTable.Rows[rowId].Cells[0].Value = i.ToString(); //No. DataTable.Rows[rowId].Cells[1].Value = emiFileData.Site_ID; //Site Name DataTable.Rows[rowId].Cells[2].Value = emiFileData.Site_ID; //Site ID DataTable.Rows[rowId].Cells[3].Value = "Vertical"; //Polarization DataTable.Rows[rowId].Cells[4].Value = azimuth.ToString(); //Azimuth DataTable.Rows[rowId].Cells[5].Value = channelSetting.ChannelName; //CH No DataTable.Rows[rowId].Cells[6].Value = channelSetting.StartFreq.ToString(); //Start Freq DataTable.Rows[rowId].Cells[7].Value = channelSetting.EndFreq.ToString(); //End Freq DataTable.Rows[rowId].Cells[8].Value = channelSetting.CenterFreq.ToString(); //Center Freq DataTable.Rows[rowId].Cells[9].Value = channelSetting.BandWidth.ToString(); //Bandwidth DataTable.Rows[rowId].Cells[10].Value = channelPower.VPower.ToString(); //Channel Power //DataTable.Rows[rowId].Cells[11].Value = ... //Color i++; } //vertical channel pair foreach (KeyValuePair<ChannelSetting, WatsEmiData> subPair in pair.Value) { channelSetting = subPair.Key; watsEmiData = subPair.Value; channelPower = new ChannelPower(emiFileData.SA_RBW, channelSetting, new LimitSetting(), watsEmiData); rowId = DataTable.Rows.Add(); DataTable.Rows[rowId].Cells[0].Value = i.ToString(); //No. DataTable.Rows[rowId].Cells[1].Value = emiFileData.Site_ID; //Site Name DataTable.Rows[rowId].Cells[2].Value = emiFileData.Site_ID; //Site ID DataTable.Rows[rowId].Cells[3].Value = "Vertical"; //Polarization DataTable.Rows[rowId].Cells[4].Value = azimuth.ToString(); //Azimuth DataTable.Rows[rowId].Cells[5].Value = channelSetting.Pair.ChannelName; //CH No DataTable.Rows[rowId].Cells[6].Value = channelSetting.Pair.StartFreq.ToString(); //Start Freq DataTable.Rows[rowId].Cells[7].Value = channelSetting.Pair.EndFreq.ToString(); //End Freq DataTable.Rows[rowId].Cells[8].Value = channelSetting.Pair.CenterFreq.ToString(); //Center Freq DataTable.Rows[rowId].Cells[9].Value = channelSetting.Pair.BandWidth.ToString(); //Bandwidth DataTable.Rows[rowId].Cells[10].Value = channelPower.VPairPower.ToString(); //Channel Power //DataTable.Rows[rowId].Cells[11].Value = ... //Color i++; } } if ((BothToolStripButton.Checked || HorizontalToolStripButton.Checked) && FilterToolStripButton.Checked || UnFilterToolStripButton.Checked) { //horizontal channel foreach (KeyValuePair<ChannelSetting, WatsEmiData> subPair in pair.Value) { channelSetting = subPair.Key; watsEmiData = subPair.Value; channelPower = new ChannelPower(emiFileData.SA_RBW, channelSetting, new LimitSetting(), watsEmiData); rowId = DataTable.Rows.Add(); DataTable.Rows[rowId].Cells[0].Value = i.ToString(); //No. DataTable.Rows[rowId].Cells[1].Value = emiFileData.Site_ID; //Site Name DataTable.Rows[rowId].Cells[2].Value = emiFileData.Site_ID; //Site ID DataTable.Rows[rowId].Cells[3].Value = "Horizontal"; //Polarization DataTable.Rows[rowId].Cells[4].Value = azimuth.ToString(); //Azimuth DataTable.Rows[rowId].Cells[5].Value = channelSetting.ChannelName; //CH No DataTable.Rows[rowId].Cells[6].Value = channelSetting.StartFreq.ToString(); //Start Freq DataTable.Rows[rowId].Cells[7].Value = channelSetting.EndFreq.ToString(); //End Freq DataTable.Rows[rowId].Cells[8].Value = channelSetting.CenterFreq.ToString(); //Center Freq DataTable.Rows[rowId].Cells[9].Value = channelSetting.BandWidth.ToString(); //Bandwidth DataTable.Rows[rowId].Cells[10].Value = channelPower.HPower.ToString(); //Channel Power //DataTable.Rows[rowId].Cells[11].Value = ... //Color i++; } //horizontal channel pair foreach (KeyValuePair<ChannelSetting, WatsEmiData> subPair in pair.Value) { channelSetting = subPair.Key; watsEmiData = subPair.Value; channelPower = new ChannelPower(emiFileData.SA_RBW, channelSetting, new LimitSetting(), watsEmiData); rowId = DataTable.Rows.Add(); DataTable.Rows[rowId].Cells[0].Value = i.ToString(); //No. DataTable.Rows[rowId].Cells[1].Value = emiFileData.Site_ID; //Site Name DataTable.Rows[rowId].Cells[2].Value = emiFileData.Site_ID; //Site ID DataTable.Rows[rowId].Cells[3].Value = "Horizontal"; //Polarization DataTable.Rows[rowId].Cells[4].Value = azimuth.ToString(); //Azimuth DataTable.Rows[rowId].Cells[5].Value = channelSetting.Pair.ChannelName; //CH No DataTable.Rows[rowId].Cells[6].Value = channelSetting.Pair.StartFreq.ToString(); //Start Freq DataTable.Rows[rowId].Cells[7].Value = channelSetting.Pair.EndFreq.ToString(); //End Freq DataTable.Rows[rowId].Cells[8].Value = channelSetting.Pair.CenterFreq.ToString(); //Center Freq DataTable.Rows[rowId].Cells[9].Value = channelSetting.Pair.BandWidth.ToString(); //Bandwidth DataTable.Rows[rowId].Cells[10].Value = channelPower.HPairPower.ToString(); //Channel Power //DataTable.Rows[rowId].Cells[11].Value = ... //Color i++; } } } } }
private List<ChannelSetting> GetAvailableChannels() { ChannelPower powerA, powerB; List<ChannelSetting> availableChannels = new List<ChannelSetting>(); foreach (ChannelSetting channelSetting in mChannelSettings) { if (!mEmiAzimuthDataA.ChannelDatas.ContainsKey(channelSetting) || !mEmiAzimuthDataB.ChannelDatas.ContainsKey(channelSetting)) continue; powerA = new ChannelPower(mEmiA.SA_RBW, channelSetting, mLimitSetting, mEmiAzimuthDataA.ChannelDatas[channelSetting]); powerB = new ChannelPower(mEmiB.SA_RBW, channelSetting, mLimitSetting, mEmiAzimuthDataB.ChannelDatas[channelSetting]); if (powerA.IsValidHPower && powerA.IsValidVPower && powerA.IsValidVPairPower && powerA.IsValidHPairPower && powerB.IsValidHPower && powerB.IsValidVPower && powerB.IsValidVPairPower && powerB.IsValidHPairPower) availableChannels.Add(channelSetting); } return availableChannels; }
public static BitMapInfo create(EMIFileData emi, double azimuth, double actualAzimuth, string title, WatsEmiDataManager dataMgr, List<ChannelSetting> channelSettings, LimitSetting limitSetting, int minAbsRssi, int maxAbsRssi) { BitMapInfo bitMapInfo = new BitMapInfo(); List<WatsEmiSample> verticalSamples = new List<WatsEmiSample>(); List<WatsEmiSample> horizontalSamples = new List<WatsEmiSample>(); bitMapInfo.Title1 = title + " " + azimuth.ToString() + "\x00B0" + " V"; bitMapInfo.Title2 = title + " " + azimuth.ToString() + "\x00B0" + " H"; bitMapInfo.BmpFile1 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + ((int)azimuth).ToString() + "_Vertical_" + (++counter).ToString() + ".emf"; bitMapInfo.BmpFile2 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + ((int)azimuth).ToString() + "_Horizontal_" + (++counter).ToString() + ".emf"; for (int i = 0; i < dataMgr.AllSamples[actualAzimuth][0].Count; i++) { if (dataMgr.AllSamples[actualAzimuth][0][i].mFreq >= channelSettings[0].StartFreq && dataMgr.AllSamples[actualAzimuth][0][i].mFreq <= channelSettings[channelSettings.Count - 1].Pair.EndFreq) verticalSamples.Add(dataMgr.AllSamples[actualAzimuth][0][i]); } for (int i = 0; i < dataMgr.AllSamples[actualAzimuth][1].Count; i++) { if (dataMgr.AllSamples[actualAzimuth][1][i].mFreq >= channelSettings[0].StartFreq && dataMgr.AllSamples[actualAzimuth][1][i].mFreq <= channelSettings[channelSettings.Count - 1].Pair.EndFreq) horizontalSamples.Add(dataMgr.AllSamples[actualAzimuth][1][i]); } List<Marker> verticalMarkers = new List<Marker>(); List<Marker> hoizontalMarkers = new List<Marker>(); Marker marker; ChannelPower channelPower; foreach (ChannelSetting channelSetting in channelSettings) { channelPower = new ChannelPower(emi.SA_RBW, channelSetting, limitSetting, dataMgr.AllChannelSamples[actualAzimuth][channelSetting]); if (!channelPower.IsValidVPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[actualAzimuth][channelSetting].mVSamples); verticalMarkers.Add(marker); } if (!channelPower.IsValidVPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[actualAzimuth][channelSetting].mVPairSamples); verticalMarkers.Add(marker); } if (!channelPower.IsValidHPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[actualAzimuth][channelSetting].mHSamples); hoizontalMarkers.Add(marker); } if (!channelPower.IsValidHPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[actualAzimuth][channelSetting].mHPairSamples); hoizontalMarkers.Add(marker); } } verticalMarkers.Sort(Utility.SortMarkerByFrequency); hoizontalMarkers.Sort(Utility.SortMarkerByFrequency); drawPicture(emi, verticalSamples, channelSettings, limitSetting, bitMapInfo.BmpFile1, bitMapInfo.Title1, minAbsRssi, maxAbsRssi, verticalMarkers); drawPicture(emi, horizontalSamples, channelSettings, limitSetting, bitMapInfo.BmpFile2, bitMapInfo.Title2, minAbsRssi, maxAbsRssi, hoizontalMarkers); return bitMapInfo; }
public static Dictionary<string, List<BitMapInfo>> create(EMIFileData emi, double azimuth, string relativeAzimuth, WatsEmiDataManager dataMgr, Dictionary<string, List<ChannelSetting>> allBandchannels, LimitSetting limitSetting, int minAbsRssi, int maxAbsRssi) { Dictionary<string, List<BitMapInfo>> allChannelBitmapInfos = new Dictionary<string,List<BitMapInfo>>(); List<BitMapInfo> channelBitmapInfos; BitMapInfo loBitMapInfo, hiBitMapInfo; List<WatsEmiSample> loVerticalSamples, hiVerticalSamples; List<WatsEmiSample> loHorizontalSamples, hiHorizontalSamples; string bandName; double curFreq; int counter = 0; List<BitMapInfo> channelBitmaps; List<Marker> loVerticalMarkers, loHoizontalMarkers; List<Marker> hiVerticalMarkers, hiHoizontalMarkers; List<ChannelSetting> channelSettings; List<ChannelSetting> pairChannelSettings; Marker marker; ChannelPower channelPower; foreach (KeyValuePair<string, List<ChannelSetting>> pair in allBandchannels) { bandName = pair.Key; channelBitmapInfos = new List<BitMapInfo>(); channelSettings = pair.Value; pairChannelSettings = new List<ChannelSetting>(); foreach (ChannelSetting channelSetting in channelSettings) pairChannelSettings.Add(channelSetting.Pair); loVerticalSamples = new List<WatsEmiSample>(); for (int i = 0; i < dataMgr.AllSamples[azimuth][0].Count; i++) { curFreq = dataMgr.AllSamples[azimuth][0][i].mFreq; if (curFreq >= channelSettings[0].StartFreq && curFreq <= channelSettings[channelSettings.Count - 1].EndFreq) { loVerticalSamples.Add(dataMgr.AllSamples[azimuth][0][i]); } } loHorizontalSamples = new List<WatsEmiSample>(); for (int i = 0; i < dataMgr.AllSamples[azimuth][1].Count; i++) { curFreq = dataMgr.AllSamples[azimuth][1][i].mFreq; if (curFreq >= channelSettings[0].StartFreq && curFreq <= channelSettings[channelSettings.Count - 1].EndFreq) { loHorizontalSamples.Add(dataMgr.AllSamples[azimuth][1][i]); } } hiVerticalSamples = new List<WatsEmiSample>(); for (int i = 0; i < dataMgr.AllSamples[azimuth][0].Count; i++) { curFreq = dataMgr.AllSamples[azimuth][0][i].mFreq; if (curFreq >= pairChannelSettings[0].StartFreq && curFreq <= pairChannelSettings[pairChannelSettings.Count - 1].EndFreq) { hiVerticalSamples.Add(dataMgr.AllSamples[azimuth][0][i]); } } hiHorizontalSamples = new List<WatsEmiSample>(); for (int i = 0; i < dataMgr.AllSamples[azimuth][1].Count; i++) { curFreq = dataMgr.AllSamples[azimuth][1][i].mFreq; if (curFreq >= pairChannelSettings[0].StartFreq && curFreq <= pairChannelSettings[pairChannelSettings.Count - 1].EndFreq) { hiHorizontalSamples.Add(dataMgr.AllSamples[azimuth][1][i]); } } loBitMapInfo = new BitMapInfo(); loBitMapInfo.Title1 = "Spectrum Analyzer Data MDEF-LAXI_" + bandName + "_" + relativeAzimuth + "V (LO)"; loBitMapInfo.Title2 = "Spectrum Analyzer Data MDEF-LAXI_" + bandName + "_" + relativeAzimuth + "H (LO)"; loBitMapInfo.BmpFile1 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + relativeAzimuth + "_" + bandName + "_LowBand_Vertical_" + (++counter).ToString() + ".emf"; loBitMapInfo.BmpFile2 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + relativeAzimuth + "_" + bandName + "_LowBand_Horizontal_" + (counter).ToString() + ".emf"; hiBitMapInfo = new BitMapInfo(); hiBitMapInfo.Title1 = "Spectrum Analyzer DataMDEF-LAXI_" + bandName + "_" + relativeAzimuth + "V (HI)"; hiBitMapInfo.Title2 = "Spectrum Analyzer DataMDEF-LAXI_" + bandName + "_" + relativeAzimuth + "H (HI)"; hiBitMapInfo.BmpFile1 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + relativeAzimuth + "_" + bandName + "_HighBand_Vertical_" + (++counter).ToString() + ".emf"; hiBitMapInfo.BmpFile2 = Utility.GetAppPath() + "\\Temp\\Site_" + emi.Site_ID + "_Azimuth_" + relativeAzimuth + "_" + bandName + "_HighBand_Horizontal_" + (counter).ToString() + ".emf"; loVerticalMarkers = new List<Marker>(); loHoizontalMarkers = new List<Marker>(); hiVerticalMarkers = new List<Marker>(); hiHoizontalMarkers = new List<Marker>(); foreach (ChannelSetting channelSetting in channelSettings) { channelPower = new ChannelPower(emi.SA_RBW, channelSetting, limitSetting, dataMgr.AllChannelSamples[azimuth][channelSetting]); if (!channelPower.IsValidVPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mVSamples); loVerticalMarkers.Add(marker); } if (!channelPower.IsValidVPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mVPairSamples); hiVerticalMarkers.Add(marker); } if (!channelPower.IsValidHPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mHSamples); loHoizontalMarkers.Add(marker); } if (!channelPower.IsValidHPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mHPairSamples); hiHoizontalMarkers.Add(marker); } } drawPicture(emi, loVerticalSamples, channelSettings, limitSetting, loBitMapInfo.BmpFile1, loBitMapInfo.Title1, minAbsRssi, maxAbsRssi, loVerticalMarkers); drawPicture(emi, loHorizontalSamples, channelSettings, limitSetting, loBitMapInfo.BmpFile2, loBitMapInfo.Title2, minAbsRssi, maxAbsRssi, loHoizontalMarkers); drawPicture(emi, hiVerticalSamples, pairChannelSettings, limitSetting, hiBitMapInfo.BmpFile1, hiBitMapInfo.Title1, minAbsRssi, maxAbsRssi, hiVerticalMarkers); drawPicture(emi, hiHorizontalSamples, pairChannelSettings, limitSetting, hiBitMapInfo.BmpFile2, hiBitMapInfo.Title2, minAbsRssi, maxAbsRssi, hiHoizontalMarkers); channelBitmaps = new List<BitMapInfo>(); channelBitmaps.Add(loBitMapInfo); channelBitmaps.Add(hiBitMapInfo); allChannelBitmapInfos[bandName] = channelBitmaps; } return allChannelBitmapInfos; }
private void ExportButton_Click(object sender, EventArgs e) { if (Utility.GetExcelVersion() < 0) { MessageBox.Show("Excel was not installed !"); return; } ExcelExportSettingForm exportSettingForm = new ExcelExportSettingForm(); if (exportSettingForm.ShowDialog() == DialogResult.Cancel) return; string reportTemplateFile; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Select report file name"; if (exportSettingForm.ExportOffice2003) { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "1HopReportTemplate.xls"; saveFileDialog.Filter = "report file(*.xls)|*.xls"; } else { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "1HopReportTemplate.xlsx"; saveFileDialog.Filter = "report file(*.xlsx)|*.xlsx"; } do { if (DialogResult.Cancel == saveFileDialog.ShowDialog()) return; if (saveFileDialog.FileName.Equals(reportTemplateFile, StringComparison.OrdinalIgnoreCase)) { MessageBox.Show("Can't select report template file !"); continue; } try { File.Copy(reportTemplateFile, saveFileDialog.FileName, true); } catch (System.Exception ex) { MessageBox.Show("Can't save file " + saveFileDialog.FileName + "!\r\n" + "Select another file name for report."); continue; } mExportFileName = saveFileDialog.FileName; break; } while (true); Hide(); mExportStatusForm.Show(); mCancelExport = false; mExportThread = new Thread(delegate() { bool isReportSucceed = false; string[] subBands = new string[2]; System.Globalization.CultureInfo Oldci = null; Excel._Application app = null; Excel.WorkbookClass workBook = null; Excel.Sheets sheets = null; Excel.Worksheet sheet = null; Excel.Worksheet summarySheet; Excel.Worksheet combinationSheet; try { Oldci = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); app = new Excel.Application(); app.DisplayAlerts = false; object objOpt = System.Reflection.Missing.Value; UpdateStatus("Initialize ..."); workBook = (Excel.WorkbookClass)app.Workbooks.Open( mExportFileName, objOpt, false, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt); sheets = workBook.Worksheets; summarySheet = (Excel.Worksheet)sheets["Summary"]; summarySheet.Cells[1, 4] = mEmiA.Site_ID; summarySheet.Cells[1, 12] = mEmiB.Site_ID; combinationSheet = (Excel.Worksheet)sheets["available channels combination"]; if (AnalysisChannelCombination) UpdateCombinationSheet(combinationSheet); else combinationSheet.Delete(); UpdateStatus("Export Cover sheet ..."); /* Cover Sheet */ sheet = (Excel.Worksheet)sheets["Cover"]; if (!string.IsNullOrEmpty(mEmiA.PI_ID)) sheet.Cells[15, 5] = mEmiA.PI_ID; if (!string.IsNullOrEmpty(mEmiA.PA_UserName)) sheet.Cells[17, 5] = mEmiA.PA_UserName; double startFrequencyA = double.MaxValue; double startFrequencyB = double.MaxValue; double endFrequencyA = double.MinValue; double endFrequencyB = double.MinValue; WatsEmiDataManager dataManagerA, dataManagerB; dataManagerA = Utility.GetEmiDataManager(mEmiA, mChannelSettings); dataManagerB = Utility.GetEmiDataManager(mEmiB, mChannelSettings); foreach (DG_Type dataGroup in mEmiA.DataGroups) { if (dataGroup.DG_FB_Angle != mAzimuthA) continue; if (dataGroup.DG_FB_Start < startFrequencyA) startFrequencyA = dataGroup.DG_FB_Start; if (dataGroup.DG_FB_End > endFrequencyA) endFrequencyA = dataGroup.DG_FB_End; } foreach (DG_Type dataGroup in mEmiB.DataGroups) { if (dataGroup.DG_FB_Angle != mAzimuthB) continue; if (dataGroup.DG_FB_Start < startFrequencyB) startFrequencyB = dataGroup.DG_FB_Start; if (dataGroup.DG_FB_End > endFrequencyB) endFrequencyB = dataGroup.DG_FB_End; } for (int i = 1; i < mChannelSettings.Count; i++) { if (mCancelExport) return; ((Excel.Range)summarySheet.Rows[3, objOpt]).Copy(objOpt); ((Excel.Range)summarySheet.Cells[3 + i, 1]).EntireRow.Insert(objOpt, objOpt); } for (int i = 0; i < mChannelSettings.Count; i++) { subBands[0] = ""; subBands[1] = ""; if (mChannelSettings[i].ODUSubBand.Length == 1) subBands[0] = mChannelSettings[i].ODUSubBand; else if (mChannelSettings[i].ODUSubBand.Length == 3) { subBands[0] = mChannelSettings[i].ODUSubBand.Substring(0, 1); subBands[1] = mChannelSettings[i].ODUSubBand.Substring(2); } summarySheet.Cells[3 + i, 1] = subBands[0]; summarySheet.Cells[3 + i, 2] = subBands[1]; summarySheet.Cells[3 + i, 3] = mChannelSettings[i].ChannelName; summarySheet.Cells[3 + i, 4] = mChannelSettings[i].CenterFreq.ToString(); summarySheet.Cells[3 + i, 7] = mChannelSettings[i].Pair.ChannelName; summarySheet.Cells[3 + i, 8] = mChannelSettings[i].Pair.CenterFreq.ToString(); summarySheet.Cells[3 + i, 11] = mChannelSettings[i].ChannelName; summarySheet.Cells[3 + i, 12] = mChannelSettings[i].CenterFreq.ToString(); summarySheet.Cells[3 + i, 15] = mChannelSettings[i].Pair.ChannelName; summarySheet.Cells[3 + i, 16] = mChannelSettings[i].Pair.CenterFreq.ToString(); summarySheet.Cells[3 + i, 5] = summarySheet.Cells[3 + i, 6] = summarySheet.Cells[3 + i, 9] = summarySheet.Cells[3 + i, 10] = summarySheet.Cells[3 + i, 13] = summarySheet.Cells[3 + i, 14] = summarySheet.Cells[3 + i, 17] = summarySheet.Cells[3 + i, 18] = summarySheet.Cells[3 + i, 19] = summarySheet.Cells[3 + i, 20] = "X"; } UpdateStatus("Export Device Info sheet ..."); /* Device Info Sheet */ sheet = (Excel.Worksheet)sheets["Device info"]; sheet.Cells[18, 12] = mEmiA.SA_RBW + "kHz"; sheet.Cells[19, 12] = mEmiA.SA_VBW + "kHz"; sheet.Cells[20, 12] = mEmiA.SA_Detector; sheet.Cells[21, 12] = mEmiA.SA_Trace; sheet.Cells[22, 12] = mEmiA.SA_Attenuation_Value + "dB"; sheet.Cells[23, 12] = mEmiA.SA_REF_LEVEL + "dBm"; List<EMIFileData> emis = new List<EMIFileData>(); emis.Add(mEmiA); emis.Add(mEmiB); List<double> startFrequencies = new List<double>(); startFrequencies.Add(startFrequencyA); startFrequencies.Add(startFrequencyB); List<double> endFrequencies = new List<double>(); endFrequencies.Add(endFrequencyA); endFrequencies.Add(endFrequencyB); List<double> azimuths = new List<double>(); azimuths.Add(mAzimuthA); azimuths.Add(mAzimuthB); List<List<BitMapInfo>> bitmapInfos = new List<List<BitMapInfo>>(); bitmapInfos.Add(mBmpInfosA); bitmapInfos.Add(mBmpInfosB); List<WatsEmiDataManager> dataManagers = new List<WatsEmiDataManager>(); dataManagers.Add(dataManagerA); dataManagers.Add(dataManagerB); for (int i = 0; i < 2; i++) { UpdateStatus("Export Information of EMI file '" + emis[i].Site_ID + "'"); sheet = (Excel.Worksheet)sheets["EMI" + (i+1).ToString()]; sheet.Name = emis[i].Site_ID; sheet.Cells[2, 3] = emis[i].Site_ID; sheet.Cells[2, 11] = emis[i].Site_ID; sheet.Cells[3, 3] = emis[i].Site_Address; sheet.Cells[4, 3] = Utility.ConvertLatitude(emis[i].Site_Latitude); sheet.Cells[4, 11] = Utility.ConvertLongtitude(emis[i].Site_Longitude); if (mLimitSetting.UseChannelPowerLimit) sheet.Cells[5, 11] = mLimitSetting.ChannelPowerLimit.ToString(); else sheet.Cells[5, 11] = ""; if (mLimitSetting.UseDeltaPowerLimit) sheet.Cells[5, 15] = mLimitSetting.DeltaPowerLimit.ToString(); else sheet.Cells[5, 15] = ""; sheet.Cells[6, 3] = Utility.ConvertToDate(emis[i].PA_TestTime); sheet.Cells[6, 11] = emis[i].PA_UserName; int channelIndex = 0; Excel.Range range; Dictionary<ChannelSetting, WatsEmiData> channelSamples = dataManagers[i].AllChannelSamples[azimuths[i]]; foreach (KeyValuePair<ChannelSetting, WatsEmiData> channelSamplePair in channelSamples) { if (mCancelExport) return; if (channelIndex > 0) { ((Excel.Range)sheet.Rows[11, objOpt]).Copy(objOpt); ((Excel.Range)sheet.Cells[11 + channelIndex, 1]).EntireRow.Insert(objOpt, objOpt); } sheet.Cells[11 + channelIndex, 3] = channelSamplePair.Key.ChannelName; sheet.Cells[11 + channelIndex, 4] = channelSamplePair.Key.CenterFreq; sheet.Cells[11 + channelIndex, 5] = channelSamplePair.Key.BandWidth; //channel pair sheet.Cells[11 + channelIndex, 10] = channelSamplePair.Key.Pair.ChannelName; sheet.Cells[11 + channelIndex, 11] = channelSamplePair.Key.Pair.CenterFreq; sheet.Cells[11 + channelIndex, 12] = channelSamplePair.Key.Pair.BandWidth; ChannelPower channelPower = new ChannelPower(emis[i].SA_RBW, channelSamplePair.Key, mLimitSetting, channelSamplePair.Value); sheet.Cells[11 + channelIndex, 8] = channelPower.HPower; sheet.Cells[11 + channelIndex, 15] = channelPower.HPairPower; sheet.Cells[11 + channelIndex, 6] = channelPower.VPower; sheet.Cells[11 + channelIndex, 13] = channelPower.VPairPower; if (!channelPower.IsValidVPower) { sheet.Cells[11 + channelIndex, 7] = "X"; } else { sheet.Cells[11 + channelIndex, 7] = ""; } if (!channelPower.IsValidHPower) { sheet.Cells[11 + channelIndex, 9] = "X"; } else { sheet.Cells[11 + channelIndex, 9] = ""; } if (!channelPower.IsValidVPairPower) { sheet.Cells[11 + channelIndex, 14] = "X"; } else { sheet.Cells[11 + channelIndex, 14] = ""; } if (!channelPower.IsValidHPairPower) { sheet.Cells[11 + channelIndex, 16] = "X"; } else { sheet.Cells[11 + channelIndex, 16] = ""; } UpdateSummarySheet(summarySheet, channelSamplePair.Key, i == 0, channelPower.IsValidVPower, channelPower.IsValidHPower, channelPower.IsValidVPairPower, channelPower.IsValidHPairPower); channelIndex++; } if (channelIndex > 1) { range = sheet.get_Range(sheet.Cells[11, 1], sheet.Cells[11 + channelIndex - 1, 1]); range.ClearContents(); range.Merge(objOpt); range = sheet.get_Range(sheet.Cells[11, 2], sheet.Cells[11 + channelIndex - 1, 2]); range.ClearContents(); range.Merge(objOpt); } sheet.Cells[11, 1] = startFrequencies[i].ToString() + "-" + endFrequencies[i].ToString(); sheet.Cells[11, 2] = azimuths[i].ToString() + "\x00B0"; int pictureRows = bitmapInfos[i].Count; if (pictureRows > 1) { for (int j = 0; j < pictureRows - 1; j++) { ((Excel.Range)sheet.Rows[12 + channelIndex, objOpt]).Copy(objOpt); ((Excel.Range)sheet.Cells[13 + channelIndex + j, 1]).EntireRow.Insert(objOpt, objOpt); } } for (int j = 0; j < pictureRows; j++) { UpdateStatus("Export sheet " + azimuths[i].ToString() + "\x00B0 vertical picture " + (j + 1).ToString() + " ..."); if (mCancelExport) return; sheet.Cells[12 + channelIndex + j, 1] = bitmapInfos[i][j].Title1; range = (Excel.Range)sheet.Cells[12 + channelIndex + j, 1]; //range.Select(); float left = Convert.ToSingle(range.Left) + 15; float top = Convert.ToSingle(range.Top) + 15; float width = 310; float height = 150; sheet.Shapes.AddPicture(bitmapInfos[i][j].BmpFile1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height); UpdateStatus("Export sheet " + azimuths[i] + "\x00B0 horizontal picture " + (j + 1).ToString() + " ..."); if (mCancelExport) return; sheet.Cells[12 + channelIndex + j, 9] = bitmapInfos[i][j].Title2; range = (Excel.Range)sheet.Cells[12 + channelIndex + j, 9]; //range.Select(); left = Convert.ToSingle(range.Left) + 15; top = Convert.ToSingle(range.Top) + 15; width = 310; height = 150; sheet.Shapes.AddPicture(bitmapInfos[i][j].BmpFile2, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height); } } isReportSucceed = true; UpdateStatus("Save export file, please wait ..."); workBook.Save(); UpdateStatus("Export succeed !"); } catch (Exception ex) { MessageBox.Show("Create report failed !\r\nException: " + ex.Message); } finally { if (Oldci != null) { System.Threading.Thread.CurrentThread.CurrentCulture = Oldci; } if (app != null) app.Quit(); ExcelAppKiller.Kill(app); Utility.ReleaseCom(sheet); Utility.ReleaseCom(sheets); Utility.ReleaseCom(workBook); Utility.ReleaseCom(app); GC.Collect(System.GC.GetGeneration(sheet)); GC.Collect(System.GC.GetGeneration(sheets)); GC.Collect(System.GC.GetGeneration(workBook)); GC.Collect(System.GC.GetGeneration(app)); GC.Collect(); /* ReleaseCom(sheet); ReleaseCom(sheets); ReleaseCom(workBook); if (app != null) app.Quit(); ExcelAppKiller.Kill(app); ReleaseCom(app); GC.Collect(); */ } if (isReportSucceed) { try { UpdateStatus("Open excel ..."); Process process = Process.Start("excel", "\"" + mExportFileName + "\""); process.Close(); } catch (System.Exception ex) { } } UpdateStatus("Finished"); } ); mExportThread.Start(); }
private void ExportButton_Click(object sender, EventArgs e) { if (Utility.GetWordVersion() < 0) { MessageBox.Show("Word was not installed !"); return; } WordExportSettingForm exportSettingForm = new WordExportSettingForm(); if (exportSettingForm.ShowDialog() == DialogResult.Cancel) return; string reportTemplateFile; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Select report file name"; if (exportSettingForm.ExportOffice2003) { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "MalaysiaMaxisTemplate.doc"; saveFileDialog.Filter = "report file(*.doc)|*.doc"; } else { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "MalaysiaMaxisTemplate.docx"; saveFileDialog.Filter = "report file(*.docx)|*.docx"; } do { if (DialogResult.Cancel == saveFileDialog.ShowDialog()) return; if (saveFileDialog.FileName.Equals(reportTemplateFile, StringComparison.OrdinalIgnoreCase)) { MessageBox.Show("Can't select report template file !"); continue; } try { File.Copy(reportTemplateFile, saveFileDialog.FileName, true); } catch (System.Exception ex) { MessageBox.Show("Can't save file " + saveFileDialog.FileName + "!\r\n" + "Select another file name for report."); continue; } mExportFileName = saveFileDialog.FileName; break; } while (true); Hide(); mExportStatusForm.Show(); mCancelExport = false; mExportThread = new Thread(delegate() { bool isReportSucceed = false; System.Globalization.CultureInfo Oldci = null; object oMissing = System.Reflection.Missing.Value; Word._Application app = null; Word._Document doc; try { Oldci = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); app = new Word.Application(); app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; UpdateStatus("Open word document ..."); object objFileName = mExportFileName; doc = app.Documents.Open(ref objFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); UpdateStatus("Calculate graph table count ..."); //Remove picture page int removePageCount = (8 - mAllBandChannels.Count) * 5; for (int i = 0; i < removePageCount; i++) RemovePage(doc, 32); //Remove table page removePageCount = 10 - mAllBandChannels.Count; for (int i = 0; i < removePageCount; i++) RemovePage(doc, 18); int j = 0; List<ChannelSetting> channelSettings; ChannelPower channelPower; foreach (KeyValuePair<string, List<ChannelSetting>> pair in mAllBandChannels) { channelSettings = pair.Value; //Band Name doc.Tables[19 + j * 2].Cell(1, 1).Range.Text = pair.Key; //Frequency data table for (int i = 0; i < channelSettings.Count; i++) { //low band doc.Tables[20 + j * 2].Cell(3 + i, 1).Range.Text = (i + 1).ToString(); doc.Tables[20 + j * 2].Cell(3 + i, 2).Range.Text = channelSettings[i].CenterFreq.ToString(); //high band doc.Tables[20 + j * 2].Cell(20 + i, 1).Range.Text = (i + 1).ToString(); doc.Tables[20 + j * 2].Cell(20 + i, 2).Range.Text = channelSettings[i].Pair.CenterFreq.ToString(); for (int k = 0; k < mAzimuths.Count; k++) { channelPower = new ChannelPower(mEmi.SA_RBW, channelSettings[i], mLimitSetting, mEmiDataMgr.AllChannelSamples[mAzimuths[k]][channelSettings[i]]); //low band doc.Tables[20 + j * 2].Cell(3 + i, 2 + k * 2 + 1).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[20 + j * 2].Cell(3 + i, 2 + k * 2 + 2).Range.Text = channelPower.IsValidHPower ? "" : "X"; //high band doc.Tables[20 + j * 2].Cell(20 + i, 2 + k * 2 + 1).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[20 + j * 2].Cell(20 + i, 2 + k * 2 + 2).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; } } j++; } //Graph table object linkToFile = false; object saveWithDocument = true; object anchor; ; Word.InlineShape shape; int graphStartTableIndex = 18 + mAllBandChannels.Count * 2 + 2; j = 0; foreach (KeyValuePair<string, List<ChannelSetting>> pair in mAllBandChannels) { //band title doc.Tables[graphStartTableIndex + j * 11].Cell(1, 1).Range.Text = "FREQUENCY SCANNING SCREEN SHOT FOR " + pair.Key + " MDEF - LAXI"; for (int i = 0; i < 5; i++) { //vertical ... //low band doc.Tables[graphStartTableIndex + j * 11 + i * 2 + 1].Cell(1, 1).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(mBitmaps[i][pair.Key][0].BmpFile1, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; //high band doc.Tables[graphStartTableIndex + j * 11 + i * 2 + 1].Cell(1, 3).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(mBitmaps[i][pair.Key][1].BmpFile1, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; //horizontal ... //low band doc.Tables[graphStartTableIndex + j * 11 + i * 2 + 2].Cell(1, 1).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(mBitmaps[i][pair.Key][0].BmpFile2, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; //high band doc.Tables[graphStartTableIndex + j * 11 + i * 2 + 2].Cell(1, 3).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(mBitmaps[i][pair.Key][1].BmpFile2, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; } j++; } isReportSucceed = true; UpdateStatus("Save export file, please wait ..."); doc.Save(); UpdateStatus("Export succeed !"); } catch (Exception ex) { MessageBox.Show("Create report failed !\r\nException: " + ex.Message); } finally { if (Oldci != null) { System.Threading.Thread.CurrentThread.CurrentCulture = Oldci; } if (app != null) app.Quit(ref oMissing, ref oMissing, ref oMissing); } if (isReportSucceed) { try { UpdateStatus("Open word ..."); Process process = Process.Start("winword", "\"" + mExportFileName + "\""); process.Close(); } catch (System.Exception ex) { } } UpdateStatus("Finished"); } ); mExportThread.Start(); }
private void ViewExcelButton_Click(object sender, EventArgs e) { if (WatsEmiReportTool.Utility.GetExcelVersion() < 0) { MessageBox.Show("Excel was not installed !"); return; } ExportSettingForm exportSettingForm = new ExportSettingForm(); if (exportSettingForm.ShowDialog() == DialogResult.Cancel) return; string reportTemplateFile; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Select report file name"; Excel.XlFileFormat excelFormat; if (exportSettingForm.ExportOffice2003) { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "ReportTemplate.xls"; //excelFormat = Excel.XlFileFormat.xlExcel8; //excelFormat = Excel.XlFileFormat.xlWorkbookNormal; saveFileDialog.Filter = "report file(*.xls)|*.xls"; } else { reportTemplateFile = System.AppDomain.CurrentDomain.BaseDirectory + "ReportTemplate.xlsx"; //excelFormat = Excel.XlFileFormat.xlExcel12; saveFileDialog.Filter = "report file(*.xlsx)|*.xlsx"; } do { if (DialogResult.Cancel == saveFileDialog.ShowDialog()) return; if (saveFileDialog.FileName.Equals(reportTemplateFile, StringComparison.OrdinalIgnoreCase)) { MessageBox.Show("Can't select report template file !"); continue; } try { File.Copy(reportTemplateFile, saveFileDialog.FileName, true); } catch (System.Exception ex) { MessageBox.Show("Can't save file " + saveFileDialog.FileName + "!\r\n" + "Select another file name for report."); continue; } mExportFileName = saveFileDialog.FileName; break; } while (true); //Hide(); mExportStatusForm.Show(); mCancelExport = false; //ExportButton.Enabled = false; mExportThread = new Thread(delegate() { bool isReportSucceed = false; string[] subBands = new string[2]; System.Globalization.CultureInfo Oldci = null; Excel._Application app = null; Excel.WorkbookClass workBook = null; Excel.Sheets sheets = null; Excel.Worksheet sheet = null; Excel.Worksheet summarySheet; try { Oldci = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); app = new Excel.Application(); app.DisplayAlerts = false; object objOpt = System.Reflection.Missing.Value; UpdateStatus("Initialize ..."); workBook = (Excel.WorkbookClass)app.Workbooks.Open( mExportFileName, objOpt, false, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt); sheets = workBook.Worksheets; summarySheet = (Excel.Worksheet)sheets["Summary"]; summarySheet.Cells[1, 6] = mEmiFileData.Site_ID; UpdateStatus("Export Cover sheet ..."); /* Cover Sheet */ sheet = (Excel.Worksheet)sheets["Cover"]; if (!string.IsNullOrEmpty(mEmiFileData.PI_ID)) sheet.Cells[15, 5] = mEmiFileData.PI_ID; if (!string.IsNullOrEmpty(mEmiFileData.PA_UserName)) sheet.Cells[17, 5] = mEmiFileData.PA_UserName; Dictionary<double, double> startFrequencys = new Dictionary<double, double>(); Dictionary<double, double> endFrequencys = new Dictionary<double, double>(); WatsEmiDataManager dataManager = new WatsEmiDataManager(); Dictionary<ChannelSetting, WatsEmiData> datas; Dictionary<int, List<WatsEmiSample>> samples = null; ChannelSetting curChannelSetting; WatsEmiData curData; foreach (DG_Type dataGroup in mEmiFileData.DataGroups) { if (mCancelExport) return; if (!startFrequencys.ContainsKey(dataGroup.DG_FB_Angle)) startFrequencys[dataGroup.DG_FB_Angle] = dataGroup.DG_FB_Start; else if (dataGroup.DG_FB_Start < startFrequencys[dataGroup.DG_FB_Angle]) startFrequencys[dataGroup.DG_FB_Angle] = dataGroup.DG_FB_Start; if (!endFrequencys.ContainsKey(dataGroup.DG_FB_Angle)) endFrequencys[dataGroup.DG_FB_Angle] = dataGroup.DG_FB_End; else if (dataGroup.DG_FB_End > endFrequencys[dataGroup.DG_FB_Angle]) endFrequencys[dataGroup.DG_FB_Angle] = dataGroup.DG_FB_End; if (!dataManager.AllChannelSamples.TryGetValue(dataGroup.DG_FB_Angle, out datas)) { datas = new Dictionary<ChannelSetting, WatsEmiData>(); dataManager.AllChannelSamples.Add(dataGroup.DG_FB_Angle, datas); } if (!dataManager.AllSamples.TryGetValue(dataGroup.DG_FB_Angle, out samples)) { samples = new Dictionary<int, List<WatsEmiSample>>(); samples[0] = new List<WatsEmiSample>(); samples[1] = new List<WatsEmiSample>(); dataManager.AllSamples.Add(dataGroup.DG_FB_Angle, samples); } foreach (DG_Data_Type data in dataGroup.DGDatas) { if (mCancelExport) return; if (dataGroup.DB_FB_AntennaPolarization == 0) samples[0].Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); else //if (dataGroup.DB_FB_AntennaPolarization == 1) samples[1].Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); curChannelSetting = null; foreach (ChannelSetting channelSetting in mChannelSettings) { if (mCancelExport) return; if (data.DG_DI_Freq >= channelSetting.StartFreq && data.DG_DI_Freq <= channelSetting.EndFreq || data.DG_DI_Freq >= channelSetting.Pair.StartFreq && data.DG_DI_Freq <= channelSetting.Pair.EndFreq) { curChannelSetting = channelSetting; break; } } if (curChannelSetting == null) continue; if (!datas.TryGetValue(curChannelSetting, out curData)) { curData = new WatsEmiData(); datas.Add(curChannelSetting, curData); } if (dataGroup.DB_FB_AntennaPolarization == 0) { if (data.DG_DI_Freq >= curChannelSetting.StartFreq && data.DG_DI_Freq <= curChannelSetting.EndFreq) curData.mVSamples.Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); else curData.mVPairSamples.Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); } else { if (data.DG_DI_Freq >= curChannelSetting.StartFreq && data.DG_DI_Freq <= curChannelSetting.EndFreq) curData.mHSamples.Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); else curData.mHPairSamples.Add(new WatsEmiSample(data.DG_DI_Freq, data.DG_DI_RSSI)); } } } for (int i = 1; i < dataManager.AllChannelSamples.Count; i++) { if (mCancelExport) return; ((Excel.Range)summarySheet.Rows[3, objOpt]).Copy(objOpt); ((Excel.Range)summarySheet.Cells[3 + i, 1]).EntireRow.Insert(objOpt, objOpt); } UpdateStatus("Export Device Info sheet ..."); /* Device Info Sheet */ sheet = (Excel.Worksheet)sheets["Device info"]; sheet.Cells[18, 12] = mEmiFileData.SA_RBW + "kHz"; sheet.Cells[19, 12] = mEmiFileData.SA_VBW + "kHz"; sheet.Cells[20, 12] = mEmiFileData.SA_Detector; sheet.Cells[21, 12] = mEmiFileData.SA_Trace; sheet.Cells[22, 12] = mEmiFileData.SA_Attenuation_Value + "dB"; sheet.Cells[23, 12] = mEmiFileData.SA_REF_LEVEL + "dBm"; int channelIndex; Excel.Range range; int summaryAngleStartRowIndex = 3; List<Excel.Range> boldBorderRanges = new List<Excel.Range>(); boldBorderRanges.Add(summarySheet.get_Range(summarySheet.Cells[1, 1], summarySheet.Cells[2, 14])); foreach (KeyValuePair<double, Dictionary<ChannelSetting, WatsEmiData>> pair in dataManager.AllChannelSamples) { UpdateStatus("Export sheet " + pair.Key.ToString() + "\x00B0" + " ..."); if (mCancelExport) return; ((Excel.Worksheet)sheets["template"]).Copy(objOpt, workBook.ActiveSheet); sheet = (Excel.Worksheet)workBook.ActiveSheet; sheet.Name = pair.Key.ToString() + "\x00B0"; sheet.Cells[2, 3] = mEmiFileData.Site_ID; sheet.Cells[2, 11] = mEmiFileData.Site_ID; sheet.Cells[3, 3] = mEmiFileData.Site_Address; sheet.Cells[4, 3] = WatsEmiReportTool.Utility.ConvertLatitude(mEmiFileData.Site_Latitude); sheet.Cells[4, 11] = WatsEmiReportTool.Utility.ConvertLongtitude(mEmiFileData.Site_Longitude); if (mLimitSetting.UseChannelPowerLimit) sheet.Cells[5, 11] = mLimitSetting.ChannelPowerLimit.ToString(); else sheet.Cells[5, 11] = ""; if (mLimitSetting.UseDeltaPowerLimit) sheet.Cells[5, 15] = mLimitSetting.DeltaPowerLimit.ToString(); else sheet.Cells[5, 15] = ""; sheet.Cells[6, 3] = WatsEmiReportTool.Utility.ConvertToDate(mEmiFileData.PA_TestTime); sheet.Cells[6, 11] = mEmiFileData.PA_UserName; summarySheet.Cells[summaryAngleStartRowIndex, 1] = pair.Key.ToString() + "\x00B0"; channelIndex = 0; foreach (KeyValuePair<ChannelSetting, WatsEmiData> dataPair in pair.Value) { if (mCancelExport) return; if (channelIndex > 0) { ((Excel.Range)sheet.Rows[11, objOpt]).Copy(objOpt); ((Excel.Range)sheet.Cells[11 + channelIndex, 1]).EntireRow.Insert(objOpt, objOpt); ((Excel.Range)summarySheet.Rows[summaryAngleStartRowIndex, objOpt]).Copy(objOpt); ((Excel.Range)summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 1]).EntireRow.Insert(objOpt, objOpt); } sheet.Cells[11 + channelIndex, 3] = dataPair.Key.ChannelName; sheet.Cells[11 + channelIndex, 4] = dataPair.Key.CenterFreq; sheet.Cells[11 + channelIndex, 5] = dataPair.Key.BandWidth; //channel pair sheet.Cells[11 + channelIndex, 10] = dataPair.Key.Pair.ChannelName; sheet.Cells[11 + channelIndex, 11] = dataPair.Key.Pair.CenterFreq; sheet.Cells[11 + channelIndex, 12] = dataPair.Key.Pair.BandWidth; summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 5] = dataPair.Key.ChannelName; summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 6] = dataPair.Key.CenterFreq; summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 9] = dataPair.Key.Pair.ChannelName; summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 10] = dataPair.Key.Pair.CenterFreq; WatsEmiReportTool.ChannelPower channelPower = new WatsEmiReportTool.ChannelPower(mEmiFileData.SA_RBW, dataPair.Key, mLimitSetting, dataPair.Value); sheet.Cells[11 + channelIndex, 8] = channelPower.HPower; sheet.Cells[11 + channelIndex, 15] = channelPower.HPairPower; sheet.Cells[11 + channelIndex, 6] = channelPower.VPower; sheet.Cells[11 + channelIndex, 13] = channelPower.VPairPower; subBands[0] = ""; subBands[1] = ""; if (dataPair.Key.ODUSubBand.Length == 1) subBands[0] = dataPair.Key.ODUSubBand; else if (dataPair.Key.ODUSubBand.Length == 3) { subBands[0] = dataPair.Key.ODUSubBand.Substring(0, 1); subBands[1] = dataPair.Key.ODUSubBand.Substring(2); } summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 3] = subBands[0]; summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 4] = subBands[1]; if (!channelPower.IsValidVPower || !channelPower.IsValidVPairPower) summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 13] = "X"; else summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 13] = ""; if (!channelPower.IsValidHPower || !channelPower.IsValidHPairPower) summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 14] = "X"; else summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 14] = ""; if (!channelPower.IsValidVPower) { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 7] = "X"; sheet.Cells[11 + channelIndex, 7] = "X"; } else { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 7] = ""; sheet.Cells[11 + channelIndex, 7] = ""; } if (!channelPower.IsValidHPower) { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 8] = "X"; sheet.Cells[11 + channelIndex, 9] = "X"; } else { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 8] = ""; sheet.Cells[11 + channelIndex, 9] = ""; } if (!channelPower.IsValidVPairPower) { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 11] = "X"; sheet.Cells[11 + channelIndex, 14] = "X"; } else { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 11] = ""; sheet.Cells[11 + channelIndex, 14] = ""; } if (!channelPower.IsValidHPairPower) { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 12] = "X"; sheet.Cells[11 + channelIndex, 16] = "X"; } else { summarySheet.Cells[summaryAngleStartRowIndex + channelIndex, 12] = ""; sheet.Cells[11 + channelIndex, 16] = ""; } channelIndex++; } if (channelIndex > 1) { range = sheet.get_Range(sheet.Cells[11, 1], sheet.Cells[11 + channelIndex - 1, 1]); range.ClearContents(); range.Merge(objOpt); range = sheet.get_Range(sheet.Cells[11, 2], sheet.Cells[11 + channelIndex - 1, 2]); range.ClearContents(); range.Merge(objOpt); range = summarySheet.get_Range(summarySheet.Cells[summaryAngleStartRowIndex, 1], summarySheet.Cells[summaryAngleStartRowIndex + channelIndex - 1, 1]); range.Merge(objOpt); } boldBorderRanges.Add(summarySheet.get_Range(summarySheet.Cells[summaryAngleStartRowIndex, 1], summarySheet.Cells[summaryAngleStartRowIndex + channelIndex - 1, 14])); summaryAngleStartRowIndex += channelIndex; sheet.Cells[11, 1] = startFrequencys[pair.Key].ToString() + "-" + endFrequencys[pair.Key].ToString(); sheet.Cells[11, 2] = pair.Key.ToString() + "\x00B0"; List<BitMapInfo> bitmapInfos = mBitmaps[pair.Key]; int pictureRows = bitmapInfos.Count; if (pictureRows > 1) { for (int i = 0; i < pictureRows - 1; i++) { ((Excel.Range)sheet.Rows[12 + channelIndex, objOpt]).Copy(objOpt); ((Excel.Range)sheet.Cells[13 + channelIndex + i, 1]).EntireRow.Insert(objOpt, objOpt); } } for (int i = 0; i < pictureRows; i++) { UpdateStatus("Export sheet " + pair.Key.ToString() + "\x00B0 vertical picture " + (i + 1).ToString() + " ..."); if (mCancelExport) return; sheet.Cells[12 + channelIndex + i, 1] = bitmapInfos[i].Title1; range = (Excel.Range)sheet.Cells[12 + channelIndex + i, 1]; range.Select(); float left = Convert.ToSingle(range.Left) + 15; float top = Convert.ToSingle(range.Top) + 15; float width = 310; float height = 150; sheet.Shapes.AddPicture(bitmapInfos[i].BmpFile1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height); UpdateStatus("Export sheet " + pair.Key.ToString() + "\x00B0 horizontal picture " + (i + 1).ToString() + " ..."); if (mCancelExport) return; sheet.Cells[12 + channelIndex + i, 9] = bitmapInfos[i].Title2; range = (Excel.Range)sheet.Cells[12 + channelIndex + i, 9]; range.Select(); left = Convert.ToSingle(range.Left) + 15; top = Convert.ToSingle(range.Top) + 15; width = 310; height = 150; sheet.Shapes.AddPicture(bitmapInfos[i].BmpFile2, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, left, top, width, height); } } foreach (Excel.Range boldBorderRange in boldBorderRanges) { boldBorderRange.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).Weight = Excel.XlBorderWeight.xlMedium; boldBorderRange.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).Weight = Excel.XlBorderWeight.xlMedium; boldBorderRange.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).Weight = Excel.XlBorderWeight.xlMedium; boldBorderRange.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).Weight = Excel.XlBorderWeight.xlMedium; } UpdateStatus("Delete template sheet ..."); ((Excel.Worksheet)sheets["template"]).Delete(); isReportSucceed = true; UpdateStatus("Save export file, please wait ..."); workBook.Save(); /* workBook.SaveAs(mExportFileName, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); */ UpdateStatus("Export succeed !"); } catch (Exception ex) { MessageBox.Show("Create report failed !\r\nException: " + ex.Message); } finally { if (Oldci != null) { System.Threading.Thread.CurrentThread.CurrentCulture = Oldci; } if (app != null) app.Quit(); ExcelAppKiller.Kill(app); WatsEmiReportTool.Utility.ReleaseCom(sheet); WatsEmiReportTool.Utility.ReleaseCom(sheets); WatsEmiReportTool.Utility.ReleaseCom(workBook); WatsEmiReportTool.Utility.ReleaseCom(app); GC.Collect(System.GC.GetGeneration(sheet)); GC.Collect(System.GC.GetGeneration(sheets)); GC.Collect(System.GC.GetGeneration(workBook)); GC.Collect(System.GC.GetGeneration(app)); GC.Collect(); /* ReleaseCom(sheet); ReleaseCom(sheets); ReleaseCom(workBook); if (app != null) app.Quit(); ExcelAppKiller.Kill(app); ReleaseCom(app); GC.Collect(); */ } if (isReportSucceed) { try { UpdateStatus("Open excel ..."); Process process = Process.Start("excel", "\"" + mExportFileName + "\""); process.Close(); } catch (System.Exception ex) { } } UpdateStatus("Finished"); } ); mExportThread.Start(); }
public static List<BitMapInfo> create(EMIFileData emi, double azimuth, string title, WatsEmiDataManager dataMgr, List<ChannelSetting> channelSettings, LimitSetting limitSetting, int minAbsRssi, int maxAbsRssi, double span, List<FrequencyRange> ranges, ref string verticalCircleTitle, ref string horizontalCircleTitle, ref string verticalCircleBmpFile, ref string horizontalCircleBmpFile) { List<BitMapInfo> bitMapInfos = new List<BitMapInfo>(); List<WatsEmiSample> verticalSamples; List<WatsEmiSample> horizontalSamples; verticalCircleBmpFile = Utility.GetAppPath() + "\\Temp\\" + azimuth.ToString() + "-circle-vertical.emf"; verticalCircleTitle = "V-" + azimuth.ToString() + "\x00B0[" + ranges[0].FromFreq + "~" + ranges[ranges.Count - 1].EndFreq + " MHz]"; horizontalCircleBmpFile = Utility.GetAppPath() + "\\Temp\\" + azimuth.ToString() + "circle-horizontal.emf"; horizontalCircleTitle = "H-" + azimuth.ToString() + "\x00B0[" + ranges[0].FromFreq + "~" + ranges[ranges.Count - 1].EndFreq + " MHz]"; //draw circle picture drawCirclePicture(true, verticalCircleBmpFile, azimuth, 30, emi.SA_RBW, dataMgr.AllChannelSamples[azimuth], limitSetting); drawCirclePicture(false, horizontalCircleBmpFile, azimuth, 30, emi.SA_RBW, dataMgr.AllChannelSamples[azimuth], limitSetting); //calculate all Markers List<Marker> allVerticalMarkers = new List<Marker>(); List<Marker> allHoizontalMarkers = new List<Marker>(); Marker marker; ChannelPower channelPower; foreach (ChannelSetting channelSetting in channelSettings) { channelPower = new ChannelPower(emi.SA_RBW, channelSetting, limitSetting, dataMgr.AllChannelSamples[azimuth][channelSetting]); if (!channelPower.IsValidVPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mVSamples); allVerticalMarkers.Add(marker); } if (!channelPower.IsValidVPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mVPairSamples); allVerticalMarkers.Add(marker); } if (!channelPower.IsValidHPower) { marker = Utility.CreateMarker(channelSetting.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mHSamples); allHoizontalMarkers.Add(marker); } if (!channelPower.IsValidHPairPower) { marker = Utility.CreateMarker(channelSetting.Pair.ChannelName, dataMgr.AllChannelSamples[azimuth][channelSetting].mHPairSamples); allHoizontalMarkers.Add(marker); } } allVerticalMarkers.Sort(Utility.SortMarkerByFrequency); allHoizontalMarkers.Sort(Utility.SortMarkerByFrequency); //draw picture per range BitMapInfo bitMapInfo; List<Marker> verticalMarkers; List<Marker> horizontalMarkers; foreach (FrequencyRange range in ranges) { bitMapInfo = new BitMapInfo(); verticalSamples = new List<WatsEmiSample>(); horizontalSamples = new List<WatsEmiSample>(); verticalMarkers = new List<Marker>(); horizontalMarkers = new List<Marker>(); foreach (Marker rangeMarker in allVerticalMarkers) { if (rangeMarker.frequency >= range.FromFreq && rangeMarker.frequency <= range.EndFreq) verticalMarkers.Add(rangeMarker); } foreach (Marker rangeMarker in allHoizontalMarkers) { if (rangeMarker.frequency >= range.FromFreq && rangeMarker.frequency <= range.EndFreq) horizontalMarkers.Add(rangeMarker); } int markerRows = Math.Max(verticalMarkers.Count, horizontalMarkers.Count); bitMapInfo.Band = Utility.ConvertDoubleString(range.FromFreq) + "-" + Utility.ConvertDoubleString(range.EndFreq); bitMapInfo.Title1 = "V-" + Utility.ConvertDoubleString(azimuth) + "\x00B0" + "[" + Utility.ConvertDoubleString(range.FromFreq) + "~" + range.EndFreq + " MHz]"; bitMapInfo.Title2 = "H-" + Utility.ConvertDoubleString(azimuth) + "\x00B0" + "[" + Utility.ConvertDoubleString(range.FromFreq) + "~" + range.EndFreq + " MHz]"; bitMapInfo.BmpFile1 = Utility.GetAppPath() + "\\Temp\\Angle" + azimuth.ToString() + "-vertical-" + ((int)range.FromFreq).ToString() + ".emf"; bitMapInfo.BmpFile2 = Utility.GetAppPath() + "\\Temp\\Angle" + azimuth.ToString() + "-horizontal-" + ((int)range.FromFreq).ToString() + ".emf"; for (int i = 0; i < dataMgr.AllSamples[azimuth][0].Count; i++) { if (dataMgr.AllSamples[azimuth][0][i].mFreq >= range.FromFreq && dataMgr.AllSamples[azimuth][0][i].mFreq <= range.EndFreq) verticalSamples.Add(dataMgr.AllSamples[azimuth][0][i]); } for (int i = 0; i < dataMgr.AllSamples[azimuth][1].Count; i++) { if (dataMgr.AllSamples[azimuth][1][i].mFreq >= range.FromFreq && dataMgr.AllSamples[azimuth][1][i].mFreq <= range.EndFreq) horizontalSamples.Add(dataMgr.AllSamples[azimuth][1][i]); } drawPicture(emi, verticalSamples, span, range, limitSetting, bitMapInfo.BmpFile1, title + " V", minAbsRssi, maxAbsRssi, verticalMarkers, markerRows); drawPicture(emi, horizontalSamples, span, range, limitSetting, bitMapInfo.BmpFile2, title + " H", minAbsRssi, maxAbsRssi, horizontalMarkers, markerRows); bitMapInfos.Add(bitMapInfo); } return bitMapInfos; }
private static bool drawCirclePicture(bool isVertical, string picturePath, double azimuth, double azimuth_step, double sa_rbw, Dictionary<ChannelSetting, WatsEmiData> channelSamples, LimitSetting limitSetting) { try { Bitmap bmp = new Bitmap(300, 260); Graphics gs = Graphics.FromImage(bmp); Metafile mf = new Metafile(picturePath, gs.GetHdc()); Graphics g = Graphics.FromImage(mf); using (Brush backgroundBrush = new SolidBrush(Color.White)) { g.FillRectangle(backgroundBrush, 0, 0, 300, 260); } using (Pen circlePen = new Pen(Color.Blue, 3.0f)) { g.DrawEllipse(circlePen, 45, 25, 210, 210); } ChannelPower power; ChannelPowerSpectrum spectrum; List<ChannelPowerSpectrum> spectrums = new List<ChannelPowerSpectrum>(); foreach (KeyValuePair<ChannelSetting, WatsEmiData> pair in channelSamples) { power = new ChannelPower(sa_rbw, pair.Key, limitSetting, pair.Value); spectrum = new ChannelPowerSpectrum(); spectrum.startFreq = pair.Key.StartFreq; spectrum.endFreq = pair.Key.EndFreq; spectrum.isValidPower = (isVertical ? power.IsValidVPower : power.IsValidHPower); spectrums.Add(spectrum); power = new ChannelPower(sa_rbw, pair.Key.Pair, limitSetting, pair.Value); spectrum = new ChannelPowerSpectrum(); spectrum.startFreq = pair.Key.Pair.StartFreq; spectrum.endFreq = pair.Key.Pair.EndFreq; spectrum.isValidPower = (isVertical ? power.IsValidVPairPower : power.IsValidHPairPower); spectrums.Add(spectrum); } spectrums.Sort(SortSpectrumByStartFreq); float freqSpan = (float)(spectrums[0].endFreq - spectrums[spectrums.Count - 1].startFreq); int length; Rectangle rect; Color color; float drawAzimuth; for (int i = 0; i < spectrums.Count; i++) { if (azimuth >= 0 && azimuth <= 90) drawAzimuth = (float)azimuth - 90; else if (azimuth >= 90 && azimuth <= 180) drawAzimuth = (float)azimuth - 90; else if (azimuth >= 180 && azimuth <= 270) drawAzimuth = (float)azimuth - 90; else drawAzimuth = (float)azimuth - 450; Debug.WriteLine(spectrums[i].startFreq + " - " + spectrums[i].endFreq); color = spectrums[i].isValidPower ? Color.Green : Color.Red; using (Brush brush = new SolidBrush(color)) { length = 2 * (int)(100 * (spectrums[i].endFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan); rect = new Rectangle((300 - length) / 2, (260 - length) /2, length, length); g.FillPie(brush, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step); } if (i != spectrums.Count - 1) { using (Brush whiteBrush = new SolidBrush(Color.White)) { length = 2 * (int)(100 * (spectrums[i].startFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan); rect = new Rectangle((300 - length) / 2, (260 - length) / 2, length, length); g.FillPie(whiteBrush, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step); } using (Pen seperateCirclePen = new Pen(Color.White, 1.0f)) { length = 2 * (int)(100 * (spectrums[i].endFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan); rect = new Rectangle((300 - length) / 2, (260 - length) / 2, length, length); g.DrawArc(seperateCirclePen, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step); } } } using (Pen directionPen = new Pen(Color.Blue, 2.0f)) { Point[] pt = new Point[]{new Point(50, 50), new Point(50, -50)}; GraphicsPath strokePath = new GraphicsPath(); strokePath.AddLine(new Point(0, 0), new Point(0, 5)); strokePath.AddLine(new Point(0, 5), new Point(3, 0)); strokePath.AddLine(new Point(0, 5), new Point(-3, 0)); CustomLineCap customLineCap = new CustomLineCap(null, strokePath); customLineCap.SetStrokeCaps(LineCap.Round, LineCap.Round); directionPen.CustomEndCap = customLineCap; Point center = new Point(150, 130); int endX, endY; int deltX = (int)(Math.Abs(Math.Sin(azimuth * Math.PI / 180)) * 120); int deltY = (int)(Math.Abs(Math.Cos(azimuth * Math.PI / 180)) * 120); if (azimuth >= 0 && azimuth <= 90) { endX = 150 + deltX; endY = 130 - deltY; } else if (azimuth >= 90 && azimuth <= 180) { endX = 150 + deltX; endY = 130 + deltY; } else if (azimuth >= 180 && azimuth <= 270) { endX = 150 - deltX; endY = 130 + deltY; } else { endX = 150 - deltX; endY = 130 - deltY; } Point end = new Point(endX, endY); g.DrawLine(directionPen, center, end); using (Font font = new Font("Times New Roman", 10.0f)) { string text = azimuth.ToString() + "\x00B0"; SizeF sizef = g.MeasureString(text, font, Int32.MaxValue); float textX, textY; if (azimuth >= 0 && azimuth <= 90) { textX = end.X - 1; textY = end.Y - sizef.Height - 10; } else if (azimuth >= 90 && azimuth <= 180) { textX = end.X - 1; textY = end.Y + sizef.Height; } else if (azimuth >= 180 && azimuth <= 270) { textX = end.X - sizef.Width / 2; textY = end.Y + sizef.Height; } else { textX = end.X - sizef.Width / 2; textY = end.Y - sizef.Height - 10; } RectangleF rf = new RectangleF(textX, textY, sizef.Width, sizef.Height); g.DrawString(text, font, Brushes.Blue, rf); } } g.Save(); g.Dispose(); } catch (System.Exception e) { File.Delete("c:\\watsLog.txt"); FileStream fs = new FileStream("c:\\watsLog.txt", FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(e.Message); sw.WriteLine(e.StackTrace); sw.Flush(); sw.Close(); fs.Close(); return false; } return true; }
private void ExportSiteReport(int offset, Word._Document doc, bool isSiteA) { object oMissing = System.Reflection.Missing.Value; Dictionary<double, BitMapInfo> bitmaps = (isSiteA ? mBitmapsA : mBitmapsB); List<double> azimuths = (isSiteA ? mAzimuthsA : mAzimuthsB); int graphTableCount = (int)Math.Ceiling(azimuths.Count / 2.0); WatsEmiDataManager emiDataMgr = (isSiteA ? mEmiDataMgrA : mEmiDataMgrB); EMIFileData emi = (isSiteA ? mEmiA : mEmiB); Dictionary<double, double> actualAzimuthMap = (isSiteA ? mActualAzimuthMapA : mActualAzimuthMapB); object linkToFile = false; object saveWithDocument = true; object anchor; ; Word.InlineShape shape; for (int i = 0; i < graphTableCount; i++) { UpdateStatus("Export Site " + (isSiteA ? "A":"B") + " graph table " + (i + 1).ToString()); doc.Tables[offset + 4 + i].Cell(1, 1).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(bitmaps[azimuths[2 * i]].BmpFile1, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; doc.Tables[offset + 4 + i].Cell(2, 1).Range.Text = azimuths[2 * i].ToString() + "\x00B0" + " V"; doc.Tables[offset + 4 + i].Cell(1, 3).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(bitmaps[azimuths[2 * i]].BmpFile2, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; doc.Tables[offset + 4 + i].Cell(2, 3).Range.Text = azimuths[2 * i].ToString() + "\x00B0" + " H"; if (2 * i + 1 == azimuths.Count) break; doc.Tables[offset + 4 + i].Cell(4, 1).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(bitmaps[azimuths[2 * i + 1]].BmpFile1, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; doc.Tables[offset + 4 + i].Cell(5, 1).Range.Text = azimuths[2 * i + 1].ToString() + "\x00B0" + " V"; doc.Tables[offset + 4 + i].Cell(4, 3).Select(); anchor = doc.Application.Selection.Range; shape = doc.Application.ActiveDocument.InlineShapes.AddPicture(bitmaps[azimuths[2 * i + 1]].BmpFile2, ref linkToFile, ref saveWithDocument, ref anchor); shape.Width = GRAPH_WIDTH; shape.Height = GRAPH_HEIGHT; doc.Tables[offset + 4 + i].Cell(5, 3).Range.Text = azimuths[2 * i + 1].ToString() + "\x00B0" + " H"; } if (mIsFiveAzimuthReport) { UpdateStatus("Export Site " + (isSiteA ? "A" : "B") + " 5-azimuth detail"); for (int i = 1; i <= 5; i++) doc.Tables[offset + 3 + graphTableCount + 3].Delete(); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 1).Merge(doc.Tables[offset + 3 + graphTableCount + 2].Cell(2, 1)); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 2).Merge(doc.Tables[offset + 3 + graphTableCount + 2].Cell(2, 2)); for (int i = 0; i < mChannelSettings.Count * 2 - 1; i++) doc.Tables[offset + 3 + graphTableCount + 2].Rows.Add(ref oMissing); ChannelSetting channelSetting; ChannelPower channelPower; for (int i = 0; i < mChannelSettings.Count; i++) { channelSetting = mChannelSettings[i]; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 1).Range.Text = channelSetting.ChannelName; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 2).Range.Text = ((float)(((float)channelSetting.CenterFreq) / 1000)).ToString(); doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 1).Range.Text = channelSetting.Pair.ChannelName; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 2).Range.Text = ((float)(((float)channelSetting.Pair.CenterFreq) / 1000)).ToString(); //1st Center channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[actualAzimuthMap[azimuths[2]]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 3).Range.Text = "Center (0\x00B0)"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 3).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 4).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 3).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 4).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; //2nd channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[actualAzimuthMap[azimuths[3]]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 4).Range.Text = azimuths[3] + "\x00B0"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 5).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 6).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 5).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 6).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; //3rd channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[actualAzimuthMap[azimuths[1]]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 5).Range.Text = azimuths[1] + "\x00B0"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 7).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 8).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 7).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 8).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; //4th channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[actualAzimuthMap[azimuths[4]]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 6).Range.Text = azimuths[4] + "\x00B0"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 9).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 10).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 9).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 10).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; //5th channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[actualAzimuthMap[azimuths[0]]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2].Cell(1, 7).Range.Text = azimuths[0] + "\x00B0"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 11).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i, 12).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 11).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2].Cell(3 + i + mChannelSettings.Count, 12).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; } } else { UpdateStatus("Export Site " + (isSiteA ? "A" : "B") + " all-azimuth detail"); doc.Tables[offset + 3 + graphTableCount + 2].Delete(); int detailTableCount = (int)Math.Ceiling(azimuths.Count / 6.0); int removeDetailTableCount = 5 - detailTableCount; for (int i = 0; i < removeDetailTableCount; i++) doc.Tables[offset + 3 + graphTableCount + 3].Delete(); ChannelSetting channelSetting; ChannelPower channelPower; for (int i = 0; i < detailTableCount; i++) { doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(1, 1).Merge(doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(2, 1)); doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(1, 2).Merge(doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(2, 2)); for (int k = 0; k < mChannelSettings.Count * 2 - 1; k++) doc.Tables[offset + 3 + graphTableCount + 2 + i].Rows.Add(ref oMissing); for (int j = 0; j < 6; j++) { if (i * 6 + j < azimuths.Count) { doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(1, 3 + j).Range.Text = azimuths[i * 6 + j].ToString() + "\x00B0"; for (int k = 0; k < mChannelSettings.Count; k++) { channelSetting = mChannelSettings[k]; channelPower = new ChannelPower(emi.SA_RBW, channelSetting, mLimitSetting, emiDataMgr.AllChannelSamples[azimuths[i * 6 + j]][channelSetting]); doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k, 1).Range.Text = channelSetting.ChannelName; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k, 2).Range.Text = ((float)(((float)channelSetting.CenterFreq) / 1000)).ToString(); doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k, 3 + 2 * j).Range.Text = channelPower.IsValidVPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k, 3 + 2 * j + 1).Range.Text = channelPower.IsValidHPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k + mChannelSettings.Count, 1).Range.Text = channelSetting.Pair.ChannelName; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k + mChannelSettings.Count, 2).Range.Text = ((float)(((float)channelSetting.Pair.CenterFreq) / 1000)).ToString(); doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k + mChannelSettings.Count, 3 + 2 * j).Range.Text = channelPower.IsValidVPairPower ? "" : "X"; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(3 + k + mChannelSettings.Count, 3 + 2 * j + 1).Range.Text = channelPower.IsValidHPairPower ? "" : "X"; } } else { doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(1, 3 + j).Range.Text = ""; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(2, 3 + 2 * j).Range.Text = ""; doc.Tables[offset + 3 + graphTableCount + 2 + i].Cell(2, 3 + 2 * j + 1).Range.Text = ""; } } } } }