예제 #1
0
    public void buttonr1_a_click(Object sender, System.EventArgs e)
    {
        LogFiles logFiles = new LogFiles(this.username);

        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;
        }
        CreateRunFile();

        int ret;

        try {
            classE1_1.Open();
            classE1_1.SetBasicModelInfo(); //  sets glngwid etc.

            classE1_1.calc_return = 0;     //0 - none, 1 labor, 2 eq over util, 4 warnings 8 errors


            //-----------------------------------------------------------------

            // count all whatifs to be calculated and write it to the main mysql database
            ADODB.Recordset recWhatifs  = new ADODB.Recordset();
            bool            recOpened   = DbUse.OpenAdoRec(classE1_1.globaldb, recWhatifs, "SELECT tblWhatIf.*, tblWhatIf.recalc  FROM tblWhatIf WHERE FamilyID = 0;");
            int             totalCalc   = 1;
            int             currentCalc = 0;
            while (!recWhatifs.EOF)
            {
                totalCalc++;
                recWhatifs.MoveNext();
            }
            DbUse.CloseAdoRec(recWhatifs);


            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 = " + totalCalc + ", calc = " + currentCalc + ", lastCheck = " + DateTime.Now.Ticks + ", cancel = 0 WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';");
            //////////////////////////////////////////////////////////////////////////////////////

            classE1_1.global_runalldone  = false;
            classE1_1.global_initwid     = classE1_1.glngwid;
            classE1_1.errorMessageGlobal = "";

            while (classE1_1.global_runalldone == false)
            {
                classE1_1.calc_return = 0;
                classE1_1.runall_from_display();
            }


            if (classE1_1.global_initwid != classE1_1.glngwid)
            {
                if (classE1_1.global_initwid != 0)
                {
                    classE1_1.LoadBaseCase();
                    ret = classE1_1.LoadWhatIf(classE1_1.global_initwid);
                }
                else
                {
                    classE1_1.LoadBaseCase();
                }
            }
            ;


            //-----------------------------------------------------------------

            MPXRunChoices.SetActiveView(viewResults);
            SetActiveView(2);
            if ((classE1_1.calc_return & CalcClass.ERR_FLAG) > 0)
            {
                resultsMessage = do_calc_msg(classE1_1.calc_return, 0);
            }
            else
            {
                resultsMessage = do_calc_msg(classE1_1.calc_return, 1);
            }

            /*  todaytoday    if ...  public const short LAB_OVER_U = 1;
             *            public const short EQ_OVER_U = 2;
             *   show ....
             *
             */
            string errorsMessage = GetErrorMessage();
            txtResults.Text = resultsMessage;
            txtErrors.Text  = errorsMessage;
            save_errors_results(resultsMessage, errorsMessage);
            pnlResults.Visible = true;
            pnlErrors.Visible  = !errorsMessage.Trim().Equals(String.Empty);


            classE1_1.runsqlado("UPDATE zs0tblWhatif SET display = -1 WHERE WID = " + classE1_1.glngwid + ";");
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
            Master.ShowErrorMessage("MPX internal error has occured. " + classE1_1.errorMessageGlobal);
        }
        classE1_1.Close();
        DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';");
        DeleteRunFile();
        logFiles.RunEndLog();
    }
    public static CalculationResult CalculateResults(ClassF classE1_1)
    {
        LogFiles logFiles = new LogFiles(classE1_1.username);

        if (DbUse.InRunProcess(classE1_1.varlocal, true))
        {
            logFiles.DuplicateRunEndLog();
            throw new Exception("Cannot start verification and calculations. The verification and calculations are still in process from the previous run. Please wait.");
        }


        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 = 1, calc = 1, lastCheck = " + DateTime.Now.Ticks + ", cancel = 0 WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';");
        DbUse.CreateRunFile(classE1_1.varlocal, classE1_1.username);
        classE1_1.Open();
        classE1_1.SetBasicModelInfo(); //  sets glngwid etc.

        classE1_1.calc_return = 0;     //0 - none, 1 labor, 2 eq over util, 4 warnings 8 errors

        string errorsMessage  = "";
        string resultsMessage = "";

        try
        {
            classE1_1.RunDLL();
            if (!classE1_1.errorMessageGlobal.Equals(""))
            {
                string errorMessageGlobal = classE1_1.errorMessageGlobal;
                classE1_1.errorMessageGlobal = "";
                throw new Exception("The calculations were unsuccessful. " + errorMessageGlobal);
            }

            if ((classE1_1.calc_return & CalcClass.ERR_FLAG) > 0)
            {
                resultsMessage = do_calc_msg(classE1_1.calc_return, 0);
            }
            else
            {
                resultsMessage = do_calc_msg(classE1_1.calc_return, 1);
            }
            errorsMessage = GetErrorMessage(classE1_1);
            save_errors_results(classE1_1, resultsMessage, errorsMessage);
            classE1_1.runsqlado("UPDATE zs0tblWhatif SET display = -1 WHERE WID = " + classE1_1.glngwid + ";");
            classE1_1.Close();
        }
        catch (Exception ex)
        {
            logFiles.ErrorLog(ex);
            classE1_1.Close();
            DbUse.DeleteRunFile(classE1_1.varlocal, classE1_1.username);
            logFiles.RunEndLog();
            DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';");
            throw new Exception("MPX internal error has occured in calculations. Cannot calculate results. " + classE1_1.errorMessageGlobal);
        }
        DbUse.DeleteRunFile(classE1_1.varlocal, classE1_1.username);
        DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';");

        logFiles.RunEndLog();
        CalculationResult calcResult = new CalculationResult(resultsMessage, errorsMessage);

        return(calcResult);
    }