//================================================================= // CALCULATE RESULTS EVERY TIME A VALUE HAS CHANGED IN ANY COMBOBOX //================================================================= #region Calculate event trigger, fires when a value in any Combobox has changed /// <summary> /// Calculate event trigger, fires every time a value has changed in any Combobox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Calculate_Click(object sender, EventArgs e) { // Reset the message after Copy button pressed when value in any combobox has changed lbl_copy.Visible = false; if (cmb_threadClass.SelectedItem != null) { if (cmb_threadClass.Text == "1A" || cmb_threadClass.Text == "2A" || cmb_threadClass.Text == "3A") { // Get D-Basic Dia first before setting LE if (cmb_basicDia.SelectedItem != null) { // Check if selected Basic Dia is a code or actual size if (cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem).Length < 4) { // Pass selected code to Below025Model.CalculateBasicDia and return actual thread size Male.BasicDia = Below025Model.CalculateBasicDia(cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem)); } else { // Get Basic Dia Male.BasicDia = Convert.ToDouble(cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem)); } } // Get TPI first before setting LE if (cmb_tpi.SelectedItem != null) { Male.TPI = Convert.ToDouble(cmb_tpi.GetItemText(cmb_tpi.SelectedItem)); } // Get Thread Class first before setting LE if (cmb_threadClass.SelectedItem != null) { Male.ClassThread = cmb_threadClass.GetItemText(cmb_threadClass.SelectedItem); } // Get U Cut if (cmb_uCutWidth != null) { Male.UCutWidth = cmb_uCutWidth.GetItemText(cmb_uCutWidth.SelectedItem); } // Get Other Coating if (cmb_other != null) { Male.CoatingOther = cmb_other.GetItemText(cmb_other.SelectedItem); } // Get PS 309 Coating if (cmb_ps309 != null) { Male.CoatingPS309 = cmb_ps309.GetItemText(cmb_ps309.SelectedItem); } // Get NoCoating if (cmb_noCoating != null) { Male.NoCoating = cmb_noCoating.GetItemText(cmb_noCoating.SelectedItem); } } else // Set the same data but for female threads { // Get D first before setting LE if (cmb_basicDia.SelectedItem != null) { // Check if selected Basic Dia is a code or actual size if (cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem).Length < 4) { // Pass selected code to Below025Model.CalculateBasicDia and return actual thread size Female.BasicDia = Below025Model.CalculateBasicDia(cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem)); } else { // Get Basic Dia Female.BasicDia = Convert.ToDouble(cmb_basicDia.GetItemText(cmb_basicDia.SelectedItem)); } } // Get TPI first before setting LE if (cmb_tpi.SelectedItem != null) { Female.TPI = Convert.ToDouble(cmb_tpi.GetItemText(cmb_tpi.SelectedItem)); } // Get Thread Class first before setting LE if (cmb_threadClass.SelectedItem != null) { Female.ClassThread = cmb_threadClass.GetItemText(cmb_threadClass.SelectedItem); } // Get U Cut if (cmb_uCutWidth != null) { Female.UCutWidth = cmb_uCutWidth.GetItemText(cmb_uCutWidth.SelectedItem); } // Get Other Coating if (cmb_other != null) { Female.CoatingOther = cmb_other.GetItemText(cmb_other.SelectedItem); } // Get PS 309 Coating if (cmb_ps309 != null) { Female.CoatingPS309 = cmb_ps309.GetItemText(cmb_ps309.SelectedItem); } // Get NoCoating if (cmb_noCoating != null) { Female.NoCoating = cmb_noCoating.GetItemText(cmb_noCoating.SelectedItem); } } } #region Set main Data for Male & Female thread if (cmb_threadClass.Text == "1A" || cmb_threadClass.Text == "2A" || cmb_threadClass.Text == "3A") { // Calculate Le and pass it to MainData Class for other calculations Male.Le = GetLe.CalculateLe(Male.BasicDia, Male.TPI); // Get Pitch Male.Pitch = (1 / Male.TPI); // Get Allowance - G Male.Allowance = Math.Round(((0.30 * (0.0015 * (Math.Pow(Male.BasicDia, 1F / 3F)) + 0.0015 * (Math.Sqrt(Male.Le)) + 0.0150 * (Math.Pow((Male.Pitch * Male.Pitch), 1F / 3F))))), 4); // Get Height of Fundamental Triangle - H Male.Triangle = (0.86603 * Male.Pitch); // Get Basic Effective Diameter - E Male.BasicEffectiveDia = Math.Round((Male.BasicDia - (0.75 * Male.Triangle)), 4); // DIAGNOSTICS DATA DiagnosticsData.GetBasicDia = Male.BasicDia; DiagnosticsData.GetLe = Male.Le; DiagnosticsData.GetPitch = Male.Pitch; DiagnosticsData.GetAllowance = Male.Allowance; DiagnosticsData.GetTriangle = Male.Triangle; DiagnosticsData.GetBasicDia = Male.BasicEffectiveDia; DiagnosticsData.GetThreadClass = Male.ClassThread; DiagnosticsData.GetPS309 = Male.CoatingPS309; DiagnosticsData.GetOther = Male.CoatingOther; DiagnosticsData.GetNoCoating = Male.NoCoating; } else { // Calculate Le and pass it to MainData Class for other calculations Female.Le = GetLe.CalculateLe(Female.BasicDia, Female.TPI); // Get Pitch Female.Pitch = (1 / Female.TPI); // Get Allowance - G Female.Allowance = Math.Round(((0.30 * (0.0015 * (Math.Pow(Female.BasicDia, 1F / 3F)) + 0.0015 * (Math.Sqrt(Female.Le)) + 0.0150 * (Math.Pow((Female.Pitch * Female.Pitch), 1F / 3F))))), 4); // Get Height of Fundamental Triangle - H Female.Triangle = (0.86603 * Female.Pitch); // Get Basic Effective Diameter - E Female.BasicEffectiveDia = Math.Round((Female.BasicDia - (0.75 * Female.Triangle)), 4); // Set Tolerance variations for 3B only Female.For12TPI = (0.12 * Female.Pitch); Female.For13to80TPI = (0.23 * Female.Pitch - (1.5 * (Female.Pitch * Female.Pitch))); Female.MinorToleranceBase = (0.05 * Math.Pow((Female.Pitch * Female.Pitch), 1F / 3F) + 0.03 * Female.Pitch / Female.BasicDia - 0.002); // DIAGNOSTICS DATA DiagnosticsData.GetBasicDia = Female.BasicDia; DiagnosticsData.GetLe = Female.Le; DiagnosticsData.GetPitch = Female.Pitch; DiagnosticsData.GetAllowance = Female.Allowance; DiagnosticsData.GetTriangle = Female.Triangle; DiagnosticsData.GetBasicEffDia = Female.BasicEffectiveDia; DiagnosticsData.Get12TPI = Female.For12TPI; DiagnosticsData.Get13to80TPI = Female.For13to80TPI; DiagnosticsData.GetMinorToleranceBase = Female.MinorToleranceBase; DiagnosticsData.GetThreadClass = Female.ClassThread; DiagnosticsData.GetPS309 = Female.CoatingPS309; DiagnosticsData.GetOther = Female.CoatingOther; DiagnosticsData.GetNoCoating = Female.NoCoating; DiagnosticsData.GetTPI = Female.TPI; } #endregion #region Calculate Male & Female //Calculate Male 1A 2A 3A if (cmb_threadClass.Text == "1A" || cmb_threadClass.Text == "2A" || cmb_threadClass.Text == "3A") { // Set Major Property Male.MajorMax = Male.MajorMax_A(); Male.MajorTolerance = Male.MajorTolerance_A(); Male.MajorMin = Male.MajorMin_A(Male.MajorMax); // Set Effective Property Male.EffectiveMax = Male.EffectiveMax_A(); Male.EffectiveTolerance = Male.EffectiveTolerance_A(); Male.EffectiveMin = Male.EffectiveMin_A(Male.EffectiveMax); // Set Minor Property Male.MinorMax = Male.MinorMax_A(); Male.MinorTolerance = Male.MinorTollerance_A(Male.EffectiveTolerance); Male.MinorMin = Male.MinorMin_A(Male.MinorMax, Male.MinorTolerance); // MODEL TO Male.ModelTo = Male.CalculateModelto_A(Male.MajorMax, Male.MajorMin); // DIAGNOSTICS DATA DiagnosticsData.GetMajorMax = Male.MajorMax; DiagnosticsData.GetMajorTol = Male.MajorTolerance; DiagnosticsData.GetMajorMin = Male.MajorMin; DiagnosticsData.GetEffMax = Male.EffectiveMax; DiagnosticsData.GetEffTol = Male.EffectiveTolerance; DiagnosticsData.GetEffMin = Male.EffectiveMin; DiagnosticsData.GetMinorMax = Male.MinorMax; DiagnosticsData.GetMinorTol = Male.MinorTolerance; DiagnosticsData.GetMinorMin = Male.MinorMin; // MAJOR txt_majorMax.Text = Male.MajorMax.ToString("F4"); txt_majorToler.Text = Male.MajorTolerance.ToString("F4"); txt_majorMin.Text = Male.MajorMin.ToString("F4"); // EFFECTIVE txt_effMax.Text = Male.EffectiveMax.ToString("F4"); txt_effToler.Text = Male.EffectiveTolerance.ToString("F4"); txt_effMin.Text = Male.EffectiveMin.ToString("F4"); // MINOR txt_minorMax.Text = Male.MinorMax.ToString("F4"); txt_minorToler.Text = Male.MinorTolerance.ToString("F4"); txt_minorMin.Text = Male.MinorMin.ToString("F4"); // MODEL TO txt_modelTo.Text = Male.ModelTo.ToString("F4"); //======================== // CALCULATE DMAX AND DMIN //======================== Male.DMax = Male.DMax_A(Male.MinorMin); Male.DMin = Male.DMin_A(Male.MinorMin); txt_dMax.Text = Male.DMax.ToString("F3"); txt_dMin.Text = Male.DMin.ToString("F3"); // MODEL TO D BASED ON DMAX AND DMIN Male.ModelToD = Male.CalculateModeltoD(Male.DMax, Male.DMin); txt_modelToD.Text = Male.ModelToD.ToString("F3"); //=========================================== // CALCULATE RADII BASED ON TPI AND UCUTWIDTH //=========================================== Male.Radii = RadiiModel.CalculateRadii(Male.TPI, Male.UCutWidth); txt_radii.Text = Male.Radii.ToString("F3"); //===================================================== // CALCULATE WIDTH MAX BASED ON UCUT MAX AND UCUT WIDTH //===================================================== // Calculate UCut Max based on UCut Width selection - 1p 1.5p 3p Male.UCutMax = UCutWidthModel.CalculateUWidth(Male.TPI, Male.UCutWidth); // Calculate UCut Width Max based on UCut Max Male.UCutWidthMax = Male.CalculateWidthMax(Male.UCutMax); txt_widthMax.Text = Male.UCutWidthMax.ToString("F3"); // Calculate UCut Width Min based on UCut Max Male.UCutWidthMin = Male.CalculateWidthMin(Male.UCutMax); txt_widthMin.Text = Male.UCutWidthMin.ToString("F3"); // Calculate ModelTo for Width based on Width Max and Width Min Male.ModelToWidth = Male.CalculateModeltoWidth(Male.UCutWidthMax, Male.UCutWidthMin); txt_modelToWidth.Text = Male.ModelToWidth.ToString("F3"); //=================== // POPULATE TEXTBOXES //=================== // Populate Thread Designation Textbox txt_threadDesignation.Text = ThreadDesignationModel.GetDesignationModel(Male.BasicDia, Male.TPI); // Populate Allowance Textbox txt_allowance.Text = Male.PopulateAllowance(); // Populate Results Textbox txt_results.Text = string.Join("", Male.resultList()); } else { // Calculate Female 1B 2B 3B // MAJOR Female.MajorMax = Female.MajorMax_B(); Female.MajorTolerance = Female.MajorTolerance_B(); Female.MajorMin = Female.MajorMin_B(); // EFFECTIVE Female.EffectiveMin = Female.EffectiveMin_B(); Female.EffectiveTolerance = Female.EffectiveTolerance_B(); Female.EffectiveMax = Female.EffectiveMax_B(); // MINOR Female.MinorMin = Female.MinorMin_B(); Female.MinorTolerance = Female.MinorTollerance_B(); Female.MinorMax = Female.MinorMax_B(Female.MinorMin, Female.MinorTolerance); // MODEL TO Female.ModelTo = Female.CalculateModelto_B(Female.MinorMax, Female.MinorMin); // DIAGNOSTICS DATA DiagnosticsData.GetMajorMax_Female = Female.MajorMax; DiagnosticsData.GetMajorTol_Female = Female.MajorTolerance; DiagnosticsData.GetMajorMin = Female.MajorMin; DiagnosticsData.GetEffMin = Female.EffectiveMin; DiagnosticsData.GetEffMax = Female.EffectiveMax; DiagnosticsData.GetEffTol = Female.EffectiveTolerance; DiagnosticsData.GetMinorMin = Female.MinorMin; DiagnosticsData.GetMinorMax = Female.MinorMax; DiagnosticsData.GetMinorTol = Female.MinorTolerance; // Populate Text Boxes // MAJOR txt_majorMax.Text = Female.MajorMax; txt_majorToler.Text = Female.MajorTolerance; txt_majorMin.Text = Female.MajorMin.ToString("F4"); // EFFECTIVE txt_effMin.Text = Female.EffectiveMin.ToString("F4"); txt_effToler.Text = Female.EffectiveTolerance.ToString("F4"); txt_effMax.Text = Female.EffectiveMax.ToString("F4"); // MINOR txt_minorMin.Text = Female.MinorMin.ToString("F4"); txt_minorToler.Text = Female.MinorTolerance.ToString("F4"); txt_minorMax.Text = Female.MinorMax.ToString("F4"); // MODEL TO txt_modelTo.Text = Female.ModelTo.ToString("F4"); //======================== // CALCULATE DMAX AND DMIN //======================== Female.DMax = Female.DMax_B(Female.BasicDia); Female.DMin = Female.DMin_B(Female.BasicDia); txt_dMax.Text = Female.DMax.ToString("F3"); txt_dMin.Text = Female.DMin.ToString("F3"); // MODEL TO D BASED ON DMAX AND DMIN Female.ModelToD = Female.CalculateModeltoD(Female.DMax, Female.DMin); txt_modelToD.Text = Female.ModelToD.ToString("F3"); //=========================================== // CALCULATE RADII BASED ON TPI AND UCUTWIDTH //=========================================== Female.Radii = RadiiModel.CalculateRadii(Female.TPI, Female.UCutWidth); txt_radii.Text = Female.Radii.ToString("F3"); //===================================================== // CALCULATE WIDTH MAX BASED ON UCUT MAX AND UCUT WIDTH //===================================================== // Calculate UCut Max based on UCut Width selection - 1p 1.5p 3p Female.UCutMax = UCutWidthModel.CalculateUWidth(Female.TPI, Female.UCutWidth); // Calculate UCut Width Max based on UCut Max Female.UCutWidthMax = Female.CalculateWidthMax(Female.UCutMax); txt_widthMax.Text = Female.UCutWidthMax.ToString("F3"); // Calculate UCut Width Min based on UCut Max Female.UCutWidthMin = Female.CalculateWidthMin(Female.UCutMax); txt_widthMin.Text = Female.UCutWidthMin.ToString("F3"); // Calculate ModelTo for Width based on Width Max and Width Min Female.ModelToWidth = Female.CalculateModeltoWidth(Female.UCutWidthMax, Female.UCutWidthMin); txt_modelToWidth.Text = Female.ModelToWidth.ToString("F3"); // Populate Thread Designation text box //Formula.GetThreadDesignation = Female.PopulateThreadDesignation(Female.BasicDia, Female.TPI); txt_threadDesignation.Text = ThreadDesignationModel.GetDesignationModel(Female.BasicDia, Female.TPI); // Populate Allowance text box txt_allowance.Text = Female.PopulateAllowance(); // Populate results text box txt_results.Text = string.Join("", Female.resultList()); } #endregion }