Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
5.6 kB
9
Indexable
Never
private void CB_CalcMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = CB_CalcMethod.SelectedIndex;
            if (selectedIndex == 0)
            {
                Cursor.Current = Cursors.WaitCursor;
                GetExcelData();
                BTN_Save.Enabled = true; BTN_ReCalc.Enabled = false;
                BTN_ReCalc.Visible = true; BTN_Save.Visible = true;
                BTN_Save.Focus(); BTN_Reset.Visible = true;
                BTN_Calc.Enabled = false; YL_Impound.Focus();
                LoadLineChart(); PNL_Plot.Visible = true;
                CB_CalcMethod.Enabled = true;
                Cursor.Current = Cursors.Default;
            }
            else if (selectedIndex == 1)
            {
                Cursor.Current = Cursors.WaitCursor;
                Program.excelCalc = Program.excelApp.Worksheets["Lot Yield"];
                Worksheet lotYield = Program.excelApp.Worksheets["Lot Yield"];
                lotYield.Activate();
                OptionButtons(selectedIndex);
                Cursor.Current = Cursors.Default;
            }
            else if (selectedIndex == 2)
            {
                Cursor.Current = Cursors.WaitCursor;
                Worksheet lotYield = Program.excelApp.Worksheets["Lot Yield"];
                lotYield.Activate();
                Program.excelCalc = Program.excelApp.Worksheets["Lot Yield"];

                OptionButtons(selectedIndex);
                Cursor.Current = Cursors.Default;
            }
        }
		
		
		
		
		
		
private void OptionButtons(int selectedIndex)
        {
            Cursor.Current = Cursors.WaitCursor;
            // Call the macro
            string macroName = String.Empty;

            if (selectedIndex == 0)
                macroName = "SYL_SBL_Calculator.xlsm!RdoNegBin_Click";
            else if (selectedIndex == 1)
                macroName = "SYL_SBL_Calculator.xlsm!RdoPoisson_Click";
            else if (selectedIndex == 2)
                macroName = "SYL_SBL_Calculator.xlsm!RdoRobust_Click";

            Program.excelApp.Run(macroName);
            string reviewLossLimitOffset = String.Empty, impoundLossLimitOffset = String.Empty,
            reviewLimitOffset = String.Empty, impoundLimitOffset = String.Empty;

            if (!isReCalc)
            {
                Worksheet lotYieldWorksheet = null;
                do
                {
                    lotYieldWorksheet = Program.excelApp.Worksheets["Lot Yield"];
                    Thread.Sleep(200); // Wait for 0.2 seconds before checking again
                }
                while (lotYieldWorksheet == null);

                // Set the active worksheet to "Lot Yield"
                Program.excelCalc = Program.workBook.Sheets[2];
                lotYieldWorksheet.Activate();

                //Adjusted Yield Loss Limit
                range = Program.excelCalc.Range["AA10"];
                reviewLossLimitOffset = range.Value2?.ToString();
                range = Program.excelCalc.Range["AA11"];
                impoundLossLimitOffset = range.Value2?.ToString();

                //Adjusted Yield Limit
                range = Program.excelCalc.Range["AB10"];
                reviewLimitOffset = range.Value2?.ToString();
                range = Program.excelCalc.Range["AB11"];
                impoundLimitOffset = range.Value2?.ToString();

            }
            else
            {
                Worksheet lotYieldWorksheet = null;
                do
                {
                    lotYieldWorksheet = Program.excelApp.Worksheets["Lot Yield"];
                    Thread.Sleep(200); // Wait for 0.2 seconds before checking again
                }
                while (lotYieldWorksheet == null);

                // Set the active worksheet to "Lot Yield"
                Program.excelCalc = Program.workBook.Sheets[3];
                lotYieldWorksheet.Activate();

                //Adjusted Yield Loss Limit
                range = Program.excelCalc.Range["AA10"];
                reviewLossLimitOffset = range.Value2?.ToString();
                range = Program.excelCalc.Range["AA11"];
                impoundLossLimitOffset = range.Value2?.ToString();

                //Adjusted Yield Limit
                range = Program.excelCalc.Range["AB10"];
                reviewLimitOffset = range.Value2?.ToString();
                range = Program.excelCalc.Range["AB11"];
                impoundLimitOffset = range.Value2?.ToString();
            }

            // Convert the yields string to double and round it off to 4 decimal places

            //Adjusted Yield Loss Limit
            double reviewLossLimit = Math.Round(Convert.ToDouble(reviewLossLimitOffset), 4);
            double impoundLossLimit = Math.Round(Convert.ToDouble(impoundLossLimitOffset), 4);
            YLS_Review.Text = "Review Limit: " + Convert.ToString(reviewLossLimit * 100) + "%";
            YLS_Impound.Text = "Impound Limit: " + Convert.ToString(impoundLossLimit * 100) + "%";

            //Adjusted Yield Limit
            double reviewLimit = Math.Round(Convert.ToDouble(reviewLimitOffset), 4);
            double impoundLimit = Math.Round(Convert.ToDouble(impoundLimitOffset), 4);
            YL_Review.Text = "Review Limit: " + Convert.ToString(reviewLimit * 100) + "%";
            YL_Impound.Text = "Impound Limit: " + Convert.ToString(impoundLimit * 100) + "%";

            Cursor.Current = Cursors.Default;
        }