public void buttonr4_opt(Object sender, System.EventArgs e) { bool b1; /*options 1) basecase a. add opt here b. new whatif name if not new return = message whatif xxx exists already * 2) in whatif a. add opt here b. new whatif name (+save/close cur whatif xxx or trash changes since last save for cur whatif xxx * if not new return = message whatif xxx exists already * */ int wid; string str1; string str2; ADODB.Recordset recprod = null; int fstatus; string name1; int newwhatifid; double val1; double val2; double val3; int ret1; logFiles.RunLog(); if (DbUse.InRunProcess(userDir)) { Master.ShowErrorMessage("Cannot start verification and calculations. The verification and calculations are still in process from the previous run. Please wait."); logFiles.DuplicateRunEndLog(); return; } bool unavailable = false; if (unavailable) { Master.ShowInfoMessage("Optimize lot sizes feature is under construction and currently unavailable."); return; } CreateRunFile(); long currTime = DateTime.Now.Ticks; DbUse.RunMysql("INSERT INTO usercalc (id) SELECT userlist.id FROM userlist WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); DbUse.RunMysql("UPDATE usercalc INNER JOIN userlist ON usercalc.id = userlist.id SET total = 2, calc = 1, lastCheck = " + currTime + ", cancel = 0 WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); try { classE1_1.Open(); //today whatif name change to whatif field on second time around ??? classE1_1.SetBasicModelInfo(); // sets glngwid etc. name1 = MyUtilities.clean(TextBox9.Text).ToUpper(); //name1 = name1.ToUpper(); // get into whatif as needed /* * 1. in basecase - stay * 2. in whatif - stay * 3. if basecase/whatif - switch to new whatif * 4. if in whatif getting new - save old whatif * */ str1 = "New What-If Scenario for lot size optimization"; int currentWhatif = classE1_1.glngwid; if (classE1_1.glngwid == 0) { if (RadioButtonList1.Items[1].Selected) { //start ewhatif if (name1.Length == 0) { classE1_1.Close(); Master.ShowErrorMessage("Invalid name for the new What-If Scenario. Please enter a name for the optimization What-If Scenario to be created."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (WhatifExists(name1)) { classE1_1.Close(); Master.ShowErrorMessage("A What-If Scenario with the same name already exists. Please choose a different name."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } // add new whatif , get into it newwhatifid = classE1_1.addnewwhatif(name1, str1); classE1_1.glngwid = newwhatifid; classE1_1.saveWid(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); classE1_1.dowhatif_all_start(); // start a new whatif Master.PassCurrentWhatifName(name1); Master.SetCurrentWhatifLabel(); WriteTableValuesToDb(); } else { WriteTableValuesToDb(); } } else // in whatif now { if (RadioButtonList3.Items[0].Selected) { //savewehatif classE1_1.dowhatif_all_end(); classE1_1.SaveWhatIfAudit(classE1_1.glngwid); } if (RadioButtonList2.Items[1].Selected) { //close whatif, start new whatif if (name1.Length == 0) { classE1_1.Close(); Master.ShowErrorMessage("Invalid name for the new What-If Scenario. Please enter a name for the optimization What-If Scenario to be created."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (WhatifExists(name1)) { classE1_1.Close(); Master.ShowErrorMessage("A What-If Scenario with the same name already exists. Please choose a different name."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } // get out of old whatif ... classE1_1.LoadBaseCase(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); // start whatif // add new whatif , get into it newwhatifid = classE1_1.addnewwhatif(name1, str1); classE1_1.glngwid = newwhatifid; classE1_1.saveWid(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); str1 = "UPDATE zstblwhatifaudit SET zstblwhatifaudit.WID = " + newwhatifid + ";"; classE1_1.runsql(str1); classE1_1.dowhatif_all_start(); Master.PassCurrentWhatifName(name1); Master.SetCurrentWhatifLabel(); SetCalculationLabels(); } WriteTableValuesToDb(); } if (CalcClass.CalculationsCancelled(HttpContext.Current.Session.SessionID)) { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); Master.ShowInfoMessage("Value Stream Modeling optimization cancelled."); return; } classE1_1.runsqlado("UPDATE zs0tblWhatif SET display = -1 WHERE WID = " + classE1_1.glngwid + ";"); // base line run ... classE1_1.calc_return = 0; ret1 = classE1_1.RunDLL(); if (ret1 == 0) { // problem in dll run str1 = do_calc_msg(classE1_1.calc_return, 1); string resultsMessage = str1; string errorsMessage = GetErrorMessage(); save_errors_results(resultsMessage, errorsMessage); MPXRunChoices.SetActiveView(viewResults); SetActiveView(2); /* todaytoday if ... public const short LAB_OVER_U = 1; * public const short EQ_OVER_U = 2; * show .... * */ txtResults.Text = resultsMessage + DbUse.toRedColor(" You need to fix the errors before starting optimization."); txtErrors.Text = errorsMessage; pnlResults.Visible = true; pnlErrors.Visible = !errorsMessage.Trim().Equals(String.Empty); classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } //-------------------------------------------------------------- str1 = do_baseline_opt_msg(classE1_1.calc_return); if (str1.Length > 0) { // "warn user about problem - not in allowed area"; //Button38.Enabled = false; // .ViewStateMode; // = Disabled; TextBox22.Rows = 8; TextBox22.Height = 128; //TextBox22.Visible = true; //Buttonr4_exe2.Visible = true; TextBox22.Text = str1; // Lucie commmented out 11-3-14 /*if (classE1_1.glngwid != 0) { * classE1_1.LoadBaseCase(); * classE1_1.dowhatif_all_start(); * * Master.PassCurrentWhatifName(""); * Master.SetCurrentWhatifLabel(); * }*/ classE1_1.Close(); MPXRunChoices.SetActiveView(PageR1); SetActiveView(0); Master.ShowErrorMessage(str1); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } val1 = get_opt_value(); // value of J at start ... if (val1 <= 0.0) { str1 = "current WIP value = 0, no optimization can be done."; TextBox22.Rows = 2; TextBox22.Height = 128; //TextBox22.Visible = true; //Buttonr4_exe2.Visible = true; TextBox22.Text = str1; classE1_1.Close(); MPXRunChoices.SetActiveView(PageR1); SetActiveView(0); Master.ShowErrorMessage("Optimization cancelled because current WIP value is 0. Production must be achieved before starting optimization."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (CalcClass.CalculationsCancelled(HttpContext.Current.Session.SessionID)) { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); Master.ShowInfoMessage("Value Stream Modeling optimization cancelled."); return; } long lastTime = currTime; currTime = DateTime.Now.Ticks; long timePerCalc = currTime - lastTime; DbUse.RunMysql("UPDATE usercalc INNER JOIN userlist ON usercalc.id = userlist.id SET calc = 2, lastCheck = " + currTime + ", timePerCalc = " + timePerCalc + " WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); //classA.Opt(long numberOfParts, long *partid, float * weight, long * optimizeLotSize, long * OptimizeTbatch, float * lotsizeValue, float * tbatchValue) classE1_1.do_opt(); string popupResult = "Lot size optimization has finished. Original WIP value was " + Convert.ToString(classE1_1.dig_round(val1, 4)) + "."; str1 = do_calc_msg(classE1_1.calc_return, 1); str1 += "<br/><br/> Original WIP value was " + Convert.ToString(classE1_1.dig_round(val1, 4)) + "."; val2 = get_opt_value(); // value of J at start ... str1 += "<br/> New WIP value is " + Convert.ToString(classE1_1.dig_round(val2, 4)) + "."; popupResult += " New WIP value is " + Convert.ToString(classE1_1.dig_round(val2, 4)) + "."; val3 = 100 * (val1 - val2) / val1; if (Math.Abs(val3) < 0.1) { val3 = 0.0; } str1 += "<br/><br/> Change in WIP value is " + classE1_1.dig_round(val3, 3) + " % decrease."; popupResult += " Change in WIP value is " + classE1_1.dig_round(val3, 3) + " % decrease."; MPXRunChoices.SetActiveView(viewResults); SetActiveView(2); string msgResults = str1; txtResults.Text = msgResults; save_errors_results(msgResults, ""); pnlResults.Visible = true; pnlErrors.Visible = false; Master.ShowInfoMessage(popupResult); } catch (Exception ex) { logFiles.ErrorLog(ex); Master.ShowErrorMessage("MPX internal error has occured. "); } finally { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); } /* long all lotsize and demand range * * start * setup whatif family for the whole ... * * loop lot size * do range for 1 paert * do loop for next part in dataset . * no more * * * start * demand loop * do range for 1 part * do loop for next part in recordset * no more ? * * do whatif new (name + number) * rundll */ /* start with just 1 part demand and lot size * * * string whatif_family; * int whatiffamily_no; * ADODB.Recordset recprod_d = null; * ADODB.Recordset recprod_l = null; * string prod_name_d; * string prod_name_l; * void strart_big_whatif() { * * string str1; * string str2; * str1= "delete zswhatif_prod _l"; * runsql(str1); * str1 = "delete zswhatif_prod_d"; * runsql(str1); * open_ado_rec(globaldb, ref recwhatif, "whatif - max family id"); * * * * * * open_ado_rec(global_db, ref recprod_l, "sdasda"); */ // xxx /* * * 2. The plan ?? * * * //doing the big whatif -- adding whatif glngwid issues * * //testing ... * // whatif reread all code and add whatif glngwid issues code ... * //do optmization stuff * * * * */ }