Example #1
0
        private bool CheckEquation()
        {
            textBoxCompile.Text = "";

            m_strEquation = textBoxEquation.Text;
            m_strEquation = m_strEquation.Trim();


            m_strEquation = ParseAsset(m_strEquation, out m_listAttributes);
            if (m_strEquation == "")
            {
                return(false);
            }

            calculate = new CalculateEvaluate.CalculateEvaluate();
            //Determines if CodeDom returns a string or a double
            if (m_strType == "STRING")
            {
                calculate.BuildFunctionClass(m_strEquation, "String", null);
            }
            else
            {
                calculate.BuildFunctionClass(m_strEquation, "double", null);
            }
            CompilerResults m_crEquation = calculate.CompileAssembly();


            if (calculate.m_listError.Count > 0)
            {
                foreach (String str in calculate.m_listError)
                {
                    textBoxCompile.Text = textBoxCompile.Text + str + "\r\n";
                }
            }

            if (textBoxCompile.Text.Length == 0)
            {
                textBoxCompile.Text = "Compilation sucessful. Results that appear in right grid calculated using default values.";
                SaveCompiledEquationToDatabase();
            }
            else
            {
                System.Media.SystemSounds.Exclamation.Play();
                return(false);
            }
            FillDefault();

            return(true);
        }
Example #2
0
        private bool CheckCalculatedField()
        {
            String strWhere = textBoxSearch.Text;

            if (strWhere.Trim() != "")
            {
                String        strCriteria   = strWhere.Trim().ToUpper();
                List <String> listAttribute = Global.ParseAttribute(strCriteria);
                foreach (String str in listAttribute)
                {
                    String strType = Global.GetAttributeType(str);
                    if (strType == "STRING")
                    {
                        String strOldValue = "[" + str + "]";
                        String strNewValue = "[@" + str + "]";
                        strCriteria = strCriteria.Replace(strOldValue, strNewValue);
                    }
                }

                m_evaluate = new CalculateEvaluate.CalculateEvaluate();
                m_evaluate.BuildTemporaryClass(strCriteria, false);
                CompilerResults m_crCriteria = null;
                try
                {
                    m_crCriteria = m_evaluate.CompileAssembly();
                }
                catch (Exception ex)
                {
                    Global.WriteOutput("Error: Compiling CRITERIA statement: " + ex.Message);
                }
                if (m_evaluate.m_listError.Count > 0 || m_crCriteria == null)
                {
                    labelResults.Visible = true;
                    labelResults.Text    = "Error: Compiling CRITERIA statement.";
                    return(false);
                }
                else
                {
                    labelResults.Visible = true;
                    labelResults.Text    = "Calculated Field Criteria statement compiled correctly.";
                }
            }
            return(true);
        }
Example #3
0
        private bool CheckQuery()
        {
            // Build select String
            String strWhere = textBoxSearch.Text;
            String strFrom  = DBOp.BuildFromStatement(m_strNetworkID, m_strSimulationID, true);

            if (strWhere.Trim() != "")
            {
                if (m_bSimulation)
                {
                    String        strCriteria   = strWhere.Trim();
                    List <String> listAttribute = Global.ParseAttribute(strCriteria);
                    foreach (String str in listAttribute)
                    {
                        String strType = Global.GetAttributeType(str);
                        if (strType == "STRING")
                        {
                            String strOldValue = "[" + str + "]";
                            String strNewValue = "[@" + str + "]";
                            strCriteria = strCriteria.Replace(strOldValue, strNewValue);
                        }
                    }

                    m_evaluate = new CalculateEvaluate.CalculateEvaluate();
                    m_evaluate.BuildTemporaryClass(strCriteria, false);
                    try
                    {
                        CompilerResults m_crCriteria = m_evaluate.CompileAssembly();
                        if (m_evaluate.m_listError.Count > 0 || m_crCriteria == null)
                        {
                            Global.WriteOutput("Error: Compiling CRITERIA statement.");
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Global.WriteOutput("Error: Compiling CRITERIA statement." + ex.Message);
                        return(false);
                    }
                }
            }



            if (strWhere.Trim() == "")
            {
                return(true);
            }

            if (m_bSimulation)
            {
                int nIndex      = 0;
                int nBeginIndex = 0;
                int nEndIndex   = 0;

                while (nBeginIndex > -1)
                {
                    nBeginIndex = strWhere.IndexOf("[", nIndex);
                    if (nBeginIndex < 0)
                    {
                        continue;
                    }

                    nEndIndex = strWhere.IndexOf("]", nBeginIndex);

                    if (nEndIndex > -1 && nBeginIndex > -1)
                    {
                        String strAttribute = strWhere.Substring(nBeginIndex + 1, nEndIndex - nBeginIndex - 1);

                        if (!m_hashAttributeYear.Contains(strAttribute.ToUpper()))
                        {
                            Global.WriteOutput("Attribute " + strAttribute + " not included in Network.");
                            return(false);
                        }
                        String str = "[" + strAttribute + "]";
                        strWhere    = strWhere.Replace(str, strAttribute);
                        nBeginIndex = 0;
                    }
                }
            }


            //oracle chokes on non-space whitespace
            Regex whiteSpaceMechanic = new Regex(@"\s+");

            strWhere = whiteSpaceMechanic.Replace(strWhere, " ");

            String strSelect = "SELECT COUNT(*)" + strFrom;

            strSelect += " WHERE ";
            strSelect += strWhere;


            DataSet ds;

            try
            {
                ds = DBMgr.ExecuteQuery(strSelect);
            }
            catch (Exception exception)
            {
                Global.WriteOutput("Error: Check query with SQL message " + exception.Message);
                return(false);
            }

            int nCount = 0;

            int.TryParse(ds.Tables[0].Rows[0].ItemArray[0].ToString(), out nCount);

            labelResults.Visible = true;
            labelResults.Text    = nCount.ToString() + " results match query.";
            return(true);
        }