private void dgvPerfomance_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex >= 2)
            {
                if (Global.SecurityOperations.CanModifySimulationPerformance(m_strNetworkID, m_strSimulationID))
                {
                    if (dgvPerfomance.Rows[e.RowIndex].Cells[0].Value == null)
                    {
                        Global.WriteOutput("Error: Select a performance attribute before editing the performance equation or criteria.");
                        return;
                    }

                    String strAttribute = dgvPerfomance.Rows[e.RowIndex].Cells[0].Value.ToString();
                    if (strAttribute.Trim().Length == 0)
                    {
                        Global.WriteOutput("Error: Select a performance attribute before editing the performance equation or criteria.");
                        return;
                    }

                    String strCriteria = "";
                    if (e.ColumnIndex == 2)
                    {
                        Performance performance = (Performance)dgvPerfomance.Rows[e.RowIndex].Tag;
                        if (performance == null)
                        {
                            performance = new Performance();
                        }
                        FormEditEquation formEditEquation = new FormEditEquation(performance);


                        if (formEditEquation.ShowDialog() == DialogResult.OK)
                        {
                            dgvPerfomance.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = performance.Equation;
                            dgvPerfomance.Update();
                        }
                    }
                    else if (e.ColumnIndex == 3)
                    {
                        if (dgvPerfomance.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                        {
                            strCriteria = dgvPerfomance.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                        }
                        FormAdvancedSearch formAdvancedSearch = new FormAdvancedSearch(m_strNetwork, m_hashAttributeYear, strCriteria, true);
                        if (formAdvancedSearch.ShowDialog() == DialogResult.OK)
                        {
                            dgvPerfomance[e.ColumnIndex, e.RowIndex].Value = formAdvancedSearch.GetWhereClause();
                        }
                        dgvPerfomance.Update();
                    }
                }
            }
        }
        private void editEquationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvPerfomance.SelectedCells == null)
            {
                return;
            }

            int    nRow         = dgvPerfomance.SelectedCells[0].RowIndex;
            String strEquation  = dgvPerfomance[2, nRow].Value.ToString();
            String strAttribute = dgvPerfomance[0, nRow].Value.ToString();


            FormEditEquation formEditEquation = new FormEditEquation(strEquation, strAttribute);

            if (formEditEquation.ShowDialog() == DialogResult.OK)
            {
                dgvPerfomance.Rows[nRow].Cells[2].Value = formEditEquation.Equation;
                dgvPerfomance.Update();
            }
        }
Beispiel #3
0
        private void ORACLEdgvCalculatedCellDoubleClick(DataGridViewCellEventArgs e)
        {
            int    nRow    = e.RowIndex;
            int    nColumn = e.ColumnIndex;
            String strID   = "";

            if (nColumn == 0)            //Edit equations
            {
                String strEquation   = "";
                String isFunctionTag = "0";
                bool   isFunction    = false;
                if (dgvCalculated[nColumn, nRow].Value != null)
                {
                    strEquation   = dgvCalculated[nColumn, nRow].Value.ToString();
                    isFunctionTag = dgvCalculated[0, nRow].Tag.ToString();
                    if (isFunctionTag == "1")
                    {
                        isFunction = true;
                    }
                }
                FormEditEquation formEditEquation = new FormEditEquation(strEquation, false, isFunction);
                formEditEquation.CalculatedField = true;
                if (formEditEquation.ShowDialog() == DialogResult.OK)
                {
                    if (formEditEquation.IsFunction)
                    {
                        dgvCalculated[0, nRow].Tag = "1";
                    }
                    else
                    {
                        dgvCalculated[0, nRow].Tag = "0";
                    }

                    dgvCalculated[e.ColumnIndex, e.RowIndex].Value = formEditEquation.Equation;
                    if (dgvCalculated.Rows[nRow].Tag == null)                     //Insert new
                    {
                        dgvCalculated.Rows.Add();
                        try
                        {
                            strEquation = formEditEquation.Equation;
                            String strInsert = "INSERT INTO ATTRIBUTES_CALCULATED (ATTRIBUTE_,EQUATION,ISFUNCTION)VALUES('" + this.Attribute + "','" + strEquation + "','" + dgvCalculated[0, nRow].Tag.ToString() + "')";
                            DBMgr.ExecuteNonQuery(strInsert);
                            dgvCalculated.Rows[nRow].Tag       = DBMgr.GetCurrentAutoIncrement("ATTRIBUTES_CALCULATED").ToString();
                            dgvCalculated[nColumn, nRow].Value = strEquation;
                            dgvCalculated.Update();
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Inserting EQUATION for Calculated Fields." + exception.Message);
                        }
                    }
                    else                     //Update existing
                    {
                        try
                        {
                            strEquation = formEditEquation.Equation;
                            strID       = dgvCalculated.Rows[nRow].Tag.ToString();
                            string strUpdate = "UPDATE ATTRIBUTES_CALCULATED SET EQUATION='" + strEquation + "', ISFUNCTION='" + dgvCalculated[0, nRow].Tag.ToString() + "' WHERE ID_='" + strID + "'";
                            DBMgr.ExecuteNonQuery(strUpdate);
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Updating EQUATION for Calculated Fields." + exception.Message);
                        }
                    }
                }
            }
            else             // Edit criteria
            {
                String strCriteria = "";
                if (dgvCalculated[nColumn, nRow].Value != null)
                {
                    strCriteria = dgvCalculated[nColumn, nRow].Value.ToString();
                }
                FormAdvancedSearch formAdvancedSearch = new FormAdvancedSearch(strCriteria);
                if (formAdvancedSearch.ShowDialog() == DialogResult.OK)
                {
                    //SqlParameter param0 = new SqlParameter("@criteria", SqlDbType.VarBinary, -1);
                    dgvCalculated[e.ColumnIndex, e.RowIndex].Value = formAdvancedSearch.Query;
                    if (dgvCalculated.Rows[nRow].Tag == null)                     //Insert new
                    {
                        try
                        {
                            strCriteria = formAdvancedSearch.Query;
                            dgvCalculated[nColumn, nRow].Value = strCriteria;
                            strCriteria = strCriteria.Replace("'", "|");
                            string strInsert = "INSERT INTO ATTRIBUTES_CALCULATED (ATTRIBUTE_,EQUATION,CRITERIA)VALUES('" + this.Attribute + "','','" + strCriteria + "')";
                            DBMgr.ExecuteNonQuery(strInsert);
                            dgvCalculated.Rows[nRow].Tag = DBMgr.GetCurrentAutoIncrement("ATTRIBUTES_CALCULATED");
                            dgvCalculated.Rows.Add();
                            dgvCalculated.Update();
                            dgvCalculated.Refresh();
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Inserting Criteria for Calculated Fields." + exception.Message);
                        }
                    }
                    else                     //Update existing
                    {
                        try
                        {
                            strCriteria = formAdvancedSearch.Query;
                            dgvCalculated[nColumn, nRow].Value = strCriteria;
                            strCriteria = strCriteria.Replace("'", "|");
                            strID       = dgvCalculated.Rows[nRow].Tag.ToString();
                            string strUpdate = "UPDATE ATTRIBUTES_CALCULATED SET CRITERIA='" + strCriteria + "' WHERE ID_='" + strID + "'";
                            DBMgr.ExecuteNonQuery(strUpdate);
                            dgvCalculated.Update();
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Updating CRITERIA for Calculated Fields." + exception.Message);
                        }
                    }
                }
            }
            dgvCalculated.Update();
        }
Beispiel #4
0
 private void dataGridViewCompoundTreatmentElements_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     // Extent column or Quantity column
     if (e.ColumnIndex != -1)
     {
         // Select only one element at a time for editing
         if (dataGridViewCompoundTreatmentElements.SelectedCells.Count == 1)
         {
             // If the selected cell contains data
             if (e.RowIndex != -1)
             {
                 CompoundTreatmentElement selectedCompoundElement = (CompoundTreatmentElement)dataGridViewCompoundTreatmentElements["colCompoundTreatmentElement", e.RowIndex].Value;
                 if (selectedCompoundElement != null)
                 {
                     if (dataGridViewCompoundTreatmentElements.Columns["colExtent"].Index == e.ColumnIndex)
                     {
                         // Extent column selected
                         FormEditEquation formEditCompoundElementEquation = new FormEditEquation(selectedCompoundElement.ExtentEquation.m_expression, _effectedTreatmentAttribute);
                         if (formEditCompoundElementEquation.ShowDialog() == DialogResult.OK)
                         {
                             selectedCompoundElement.ExtentEquation.m_expression = formEditCompoundElementEquation.Equation;
                             dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementEquation.Equation;
                         }
                     }
                     if (dataGridViewCompoundTreatmentElements.Columns["colQuantity"].Index == e.ColumnIndex)
                     {
                         // Quantity column selected
                         FormEditEquation formEditCompoundElementEquation = new FormEditEquation(selectedCompoundElement.Quantity.m_expression, _effectedTreatmentAttribute);
                         if (formEditCompoundElementEquation.ShowDialog() == DialogResult.OK)
                         {
                             selectedCompoundElement.Quantity.m_expression = formEditCompoundElementEquation.Equation;
                             dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementEquation.Equation;
                         }
                     }
                     if (dataGridViewCompoundTreatmentElements.Columns["colCriteria"].Index == e.ColumnIndex)
                     {
                         // Criteria column selected
                         FormAdvancedSearch formEditCriteria = new FormAdvancedSearch(selectedCompoundElement.CriteriaEquation.Criteria);
                         if (formEditCriteria.ShowDialog() == DialogResult.OK)
                         {
                             selectedCompoundElement.CriteriaEquation.Criteria = formEditCriteria.GetWhereClause();
                             dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCriteria.GetWhereClause();
                         }
                     }
                     if (dataGridViewCompoundTreatmentElements.Columns["colCost"].Index == e.ColumnIndex)
                     {
                         // Cost column selected
                         FormEditEquation formEditCompoundElementExtent = new FormEditEquation(selectedCompoundElement.CostEquation.m_expression, _effectedTreatmentAttribute);
                         if (formEditCompoundElementExtent.ShowDialog() == DialogResult.OK)
                         {
                             selectedCompoundElement.CostEquation.m_expression = formEditCompoundElementExtent.Equation;
                             dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementExtent.Equation;
                         }
                     }
                 }
             }
             else
             {
                 if (dataGridViewCompoundTreatmentElements.Columns["colExtent"].Index == e.ColumnIndex)
                 {
                     // Extent column selected
                     FormEditEquation formEditCompoundElementEquation = new FormEditEquation("", _effectedTreatmentAttribute);
                     if (formEditCompoundElementEquation.ShowDialog() == DialogResult.OK)
                     {
                         dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementEquation.Equation;
                     }
                 }
                 if (dataGridViewCompoundTreatmentElements.Columns["colQuantity"].Index == e.ColumnIndex)
                 {
                     // Quantity column selected
                     FormEditEquation formEditCompoundElementEquation = new FormEditEquation("", _effectedTreatmentAttribute);
                     if (formEditCompoundElementEquation.ShowDialog() == DialogResult.OK)
                     {
                         dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementEquation.Equation;
                     }
                 }
                 if (dataGridViewCompoundTreatmentElements.Columns["colCriteria"].Index == e.ColumnIndex)
                 {
                     // Criteria column selected
                     FormAdvancedSearch formEditCriteria = new FormAdvancedSearch("");
                     if (formEditCriteria.ShowDialog() == DialogResult.OK)
                     {
                         dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCriteria.GetWhereClause();
                     }
                 }
                 if (dataGridViewCompoundTreatmentElements.Columns["colCost"].Index == e.ColumnIndex)
                 {
                     // Cost column selected
                     FormEditEquation formEditCompoundElementExtent = new FormEditEquation("", _effectedTreatmentAttribute);
                     if (formEditCompoundElementExtent.ShowDialog() == DialogResult.OK)
                     {
                         dataGridViewCompoundTreatmentElements[e.ColumnIndex, e.RowIndex].Value = formEditCompoundElementExtent.Equation;
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
        private void MSSQLdgvCalculatedCellDoubleClick(DataGridViewCellEventArgs e)
        {
            int    nRow    = e.RowIndex;
            int    nColumn = e.ColumnIndex;
            String strID   = "";

            if (nColumn == 0)            //Edit equations
            {
                String strEquation   = "";
                String isFunctionTag = "0";
                bool   isFunction    = false;
                if (dgvCalculated[nColumn, nRow].Value != null)
                {
                    strEquation = dgvCalculated[nColumn, nRow].Value.ToString();
                }
                FormEditEquation formEditEquation = new FormEditEquation(strEquation, false, isFunction);
                formEditEquation.CalculatedField = true;
                if (formEditEquation.ShowDialog() == DialogResult.OK)
                {
                    if (dgvCalculated.Rows[nRow].Tag == null)                     //Insert new
                    {
                        try
                        {
                            strEquation = formEditEquation.Equation;
                            dgvCalculated.Rows.Add();
                            String     strInsert = "INSERT INTO ATTRIBUTES_CALCULATED (ATTRIBUTE_,EQUATION,ISFUNCTION)VALUES('" + this.Attribute + "','" + strEquation + "','0')";
                            SqlCommand command   = new SqlCommand(strInsert, DBMgr.NativeConnectionParameters.SqlConnection);
                            command.ExecuteNonQuery();

                            String  strIdentity = "SELECT IDENT_CURRENT ('ATTRIBUTES_CALCULATED') FROM ATTRIBUTES_CALCULATED";
                            DataSet ds          = DBMgr.ExecuteQuery(strIdentity);
                            strIdentity = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                            dgvCalculated.Rows[nRow].Tag       = strIdentity;
                            dgvCalculated[nColumn, nRow].Value = strEquation;
                            dgvCalculated.Update();
                            dgvCalculated[e.ColumnIndex, e.RowIndex].Value = formEditEquation.Equation;
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Inserting EQUATION for Calculated Fields." + exception.Message);
                        }
                    }
                    else                     //Update existing
                    {
                        try
                        {
                            strEquation = formEditEquation.Equation;

                            strID = dgvCalculated.Rows[nRow].Tag.ToString();
                            String     strUpdate = "UPDATE ATTRIBUTES_CALCULATED SET EQUATION='" + strEquation + "', ISFUNCTION='0' WHERE ID_='" + strID + "'";
                            SqlCommand command   = new SqlCommand(strUpdate, DBMgr.NativeConnectionParameters.SqlConnection);
                            command.ExecuteNonQuery();
                            dgvCalculated[e.ColumnIndex, e.RowIndex].Value = formEditEquation.Equation;
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Updating EQUATION for Calculated Fields." + exception.Message);
                        }
                    }
                }
            }
            else             // Edit criteria
            {
                String strCriteria = "";
                if (dgvCalculated[nColumn, nRow].Value != null)
                {
                    strCriteria = dgvCalculated[nColumn, nRow].Value.ToString();
                }
                FormAdvancedSearch formAdvancedSearch = new FormAdvancedSearch(strCriteria);

                if (formAdvancedSearch.ShowDialog() == DialogResult.OK)
                {
                    dgvCalculated[nColumn, nRow].Value = formAdvancedSearch.Query;
                    SqlParameter param0 = new SqlParameter("@criteria", SqlDbType.VarBinary, -1);
                    if (dgvCalculated.Rows[nRow].Tag == null)                     //Insert new
                    {
                        try
                        {
                            strCriteria = formAdvancedSearch.Query;
                            dgvCalculated[nColumn, nRow].Value = strCriteria;
                            strCriteria = strCriteria.Replace("'", "|");
                            String     strInsert = "INSERT INTO ATTRIBUTES_CALCULATED (ATTRIBUTE_,EQUATION,CRITERIA)VALUES('" + this.Attribute + "','','" + strCriteria + "')";
                            SqlCommand command   = new SqlCommand(strInsert, DBMgr.NativeConnectionParameters.SqlConnection);
                            command.ExecuteNonQuery();

                            String  strIdentity = "SELECT IDENT_CURRENT ('ATTRIBUTES_CALCULATED') FROM ATTRIBUTES_CALCULATED";
                            DataSet ds          = DBMgr.ExecuteQuery(strIdentity);
                            strIdentity = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                            dgvCalculated.Rows[nRow].Tag = strIdentity;
                            dgvCalculated.Rows.Add();
                            dgvCalculated.Update();
                            dgvCalculated.Refresh();
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Inserting Criteria for Calculated Fields." + exception.Message);
                        }
                    }
                    else                     //Update existing
                    {
                        try
                        {
                            strCriteria = formAdvancedSearch.Query;
                            dgvCalculated[nColumn, nRow].Value = strCriteria;
                            strCriteria = strCriteria.Replace("'", "|");
                            strID       = dgvCalculated.Rows[nRow].Tag.ToString();
                            String     strUpdate = "UPDATE ATTRIBUTES_CALCULATED SET CRITERIA='" + strCriteria + "' WHERE ID_='" + strID + "'";
                            SqlCommand command   = new SqlCommand(strUpdate, DBMgr.NativeConnectionParameters.SqlConnection);
                            command.ExecuteNonQuery();
                            dgvCalculated.Update();
                        }
                        catch (Exception exception)
                        {
                            Global.WriteOutput("Error: Updating CRITERIA for Calculated Fields." + exception.Message);
                        }
                    }
                }
            }
            dgvCalculated.Update();
        }