// Make loads for export from combination rules private void applyCombinationRule(CombinationRule rule) { //Prepare new load LoadForExport combinedLoad = new LoadForExport(); combinedLoad.name = rule.name; // Take bytes' count from 1st load combinedLoad.bytes = new byte[this.loads[0].bytes.Length]; // Combine byte by byte for (int i=0; i < combinedLoad.bytes.Length; i += 4) { // Combine only necessary sections in members if (this.sections[(int)((i % (13 * 4 * 6)) / (6 * 4))] == true) { // Prepare array with values float[] arrayValues = new float[this.loadsCount]; // Prepare array with frequencies double[] arrayFrequencies = new double[this.loadsCount]; // Fill array for (int k = 0; k < this.loadsCount; k++) { //Read 4 bytes arrayValues[k] = BitConverter.ToSingle(this.loads[k].bytes, i); //Get frequency arrayFrequencies[k] = this.loads[k].frequency; } //Combine array float result = (float)rule.combine(arrayValues, arrayFrequencies); //Write value to combined load Array.Copy(BitConverter.GetBytes(result), 0, combinedLoad.bytes, i, 4); } } // Add combined load this.loads.Add(combinedLoad); }
// Add worksheet to workbook private void addWorksheet(LoadForExport load) { //Add Worksheet var xlSheets = this.xlWorkBook.Sheets as Excel.Sheets; this.xlWorkSheet = (Excel.Worksheet)this.xlWorkBook.Worksheets.Add(xlSheets[1], Type.Missing, Type.Missing, Type.Missing); this.xlWorkSheet.Name = load.name; // Write Units xlWorkSheet.Cells[1, 4] = "KN"; xlWorkSheet.Cells[1, 5] = "KN"; xlWorkSheet.Cells[1, 6] = "KN"; xlWorkSheet.Cells[1, 7] = "KN*m"; xlWorkSheet.Cells[1, 8] = "KN*m"; xlWorkSheet.Cells[1, 9] = "KN*m"; // Write Head Titles xlWorkSheet.Cells[2, 1] = "LOAD"; xlWorkSheet.Cells[2, 2] = "MEMBER"; xlWorkSheet.Cells[2, 3] = "SECTION"; xlWorkSheet.Cells[2, 4] = "AXIAL"; xlWorkSheet.Cells[2, 5] = "SHEAR-Y"; xlWorkSheet.Cells[2, 6] = "SHEAR-Z"; xlWorkSheet.Cells[2, 7] = "TORSION"; xlWorkSheet.Cells[2, 8] = "MOM-Y"; xlWorkSheet.Cells[2, 9] = "MOM-Z"; int rowIndex = 3; // Export for (int elementNumber = 0; elementNumber < this.elementNumbers.Length; elementNumber++) { for (int sectionNumber = 0; sectionNumber < 13; sectionNumber++) { if (this.sections[sectionNumber] == true) { // Prepare string xlWorkSheet.Cells[rowIndex, 1] = load.name; xlWorkSheet.Cells[rowIndex, 2] = this.elementNumbers[elementNumber]; xlWorkSheet.Cells[rowIndex, 3] = sectionNumber + 1; //Read all internal loads for (int i = 0; i < 6; i++) { int offset = (elementNumber * 13 * 6 * 4) + (sectionNumber * 6 * 4) + (i * 4); // Read 4 bytes in new array byte[] valueArray = new byte[4]; Array.Copy(load.bytes, offset, valueArray, 0, 4); //Convert array to float float value = BitConverter.ToSingle(valueArray, 0); //Convert from lbs to KN value = (float)(value * Preferences.ratioLbsToNewton); // If it's moment convert from Inch to Meter additionally if (i >= 3) { value = (float)(value * Preferences.ratioInchToMeter); } //Add value to string xlWorkSheet.Cells[rowIndex, 4 + i] = value; } //Next row rowIndex++; } } } // Number format xlWorkSheet.Range["A3", "C" + rowIndex].NumberFormat = "0"; xlWorkSheet.Range["D3", "I" + rowIndex].NumberFormat = "0,000"; }
private void button2_Click(object sender, EventArgs e) { bool[] sections = new bool[13] { false, false, false, false, false, false, false, false, false, false, false, false, false }; //Prepare sections array foreach (Control c in this.Controls) { if (c is CheckBox) { if (c.Name.Contains("sectionCheckBox")) { CheckBox checkBox = (CheckBox)c; // Take sectionNumber from name of CheckBox int sectionNumber = Convert.ToInt32(checkBox.Name.Substring(15)); // Update array sections[sectionNumber - 1] = checkBox.Checked; } } } // Prepare export factory ExcelExportFactory factory = new ExcelExportFactory(); factory.sections = sections; factory.elementNumbers = Preferences.stdFileManager.getBeamNumberList(); //Get list of loads int[] xlsLoadList = Preferences.convertStringToLoadArray(xlsLoadListTextBox.Text, false); int[] bmdLoadList = Preferences.convertStringToLoadArray(bmdLoadListTextBox.Text); int[] mshLoadList = Preferences.convertStringToLoadArray(mshModeListTextBox.Text); int loadCount = bmdLoadList.Count(); // Set Frequency Flag if (mshLoadList.Count() != 0) { Preferences.isFrequencyUsed = true; } // Check correspondance of lists if (xlsLoadList.Count() != loadCount) { MessageBox.Show("Wrong Load List !!!"); return; } if (Preferences.isFrequencyUsed && mshLoadList.Count() !=loadCount) { MessageBox.Show("Wrong Mode List !!!"); return; } // Validate load numbers for (int i = 0; i < loadCount; i++) { if (!Preferences.bmdFileManager.validateLoadNumber(i)) { return; } } if (Preferences.isFrequencyUsed) { for (int i = 0; i < loadCount; i++) { if (!Preferences.mshFileManager.validateModeNumber(i)) { return; } } } // Prepare loads for for (int i = 0; i < loadCount; i++) { LoadForExport load = new LoadForExport(); /**/ load.bytes = Preferences.bmdFileManager.getBytesForLoad(bmdLoadList[i]); load.name = xlsLoadList[i].ToString(); load.frequency = Preferences.mshFileManager.getFrequency(mshLoadList[i]); factory.loads.Add(load); } // Add combination rules if (srssCheckBox.Checked) { factory.rules.Add(new SRSSCombinationRule("SRSS", 1.0)); } if (multiSrssCheckBox.Checked) { factory.rules.Add(new SRSSCombinationRule("sqrt(1.3)_SRSS", Math.Sqrt(1.3))); } if (uzCheсkBox.Checked) { factory.rules.Add(new UZCombinationRule("UZ", 1.0)); } if (modulusUzCheckBox.Checked) { factory.rules.Add(new UZModulusCombinationRule("|UZ|", 1.0)); } if (Preferences.isFrequencyUsed) { if (cqcCheckBox.Checked) { factory.rules.Add(new CQCCombinationRule("CQC", 1.0, 0.03)); } if (asceCheckBox.Checked) { factory.rules.Add(new ASCECombinationRule("ASCE", 1.0, 0.03, 2, 33)); } if (sp14CheckBox.Checked) { factory.rules.Add(new SP14CombinationRule("SP14.13330", 1.0, 0.03)); } if (absCheckBox.Checked) { factory.rules.Add(new ABSCombinationRule("ABS", 1.0, 0.03)); } } factory.saveToExcelFile(Directory.GetCurrentDirectory() + "\\" + Preferences.fileName + ".xls"); factory = null; }