Beispiel #1
0
        /// <summary>
        /// set table/grid/listview properties for the user-selected column menu item SetResponse.
        /// pick this variable as the response variable, and if the previous response variable was a 
        /// transform, delete it from the table and unhide its original column.  Further, if
        /// independent variable transforms are present in the table remove them from the table (with 
        /// user permission)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void SetResponse(object sender, EventArgs e)
        {
            gridutils = new Utilities.GridUtils(dgv); //otherwise getting error at line 838

            DialogResult dlgr = DialogResult.Yes;
            if (hasTCols())
            {
                dlgr = MessageBox.Show("Changing response variable results in removal of created columns; Proceed (Y?N)",
                "Are you sure you want to continue?", MessageBoxButtons.YesNo);
            }

            if (dlgr == DialogResult.Yes)
            {
                //save this 'cause we're maybe screwing with indicies by removing columns
                strSelectedColName = dt.Columns[intSelectedColIndex].Caption;

                //maintain attributes
                utils.setAttributeValue(dt.Columns[intSelectedColIndex], VBCommon.Globals.DEPENDENTVAR, true);
                utils.setAttributeValue(dt.Columns[intResponseVarColIndex], VBCommon.Globals.DEPENDENTVAR, false);

                //filter transformed cols
                if (hasTCols()) dt = tableutils.filterTcols(dt);

                if (utils.testValueAttribute(dt.Columns[strResponseVarColName], VBCommon.Globals.DEPENDENTVARIBLETRANSFORM))
                {
                    dt.Columns.Remove(dt.Columns[strResponseVarColName].Caption);
                    dt.AcceptChanges();
                    gridutils.unHideHiddenCols(dgv, dt);

                    updateListView(listvals.NHIDDENCOLS, --intNhiddencols);
                }

                intResponseVarColIndex = dt.Columns.IndexOf(strSelectedColName);
                strResponseVarColName = dt.Columns[intResponseVarColIndex].Caption;

                gridutils.maintainGrid(dgv, dt, intSelectedColIndex, strResponseVarColName);

                //count iv columns and update list
                int nonivs = intNhiddencols > 0 ? 3 : 2;
                intNivs = dt.Columns.Count - nonivs;
                updateListView(listvals.NIVS, intNivs);
                //and rv name
                updateListView(listvals.RVCOLNAME, strResponseVarColName);

                state = dtState.dirty;
                NotifyContainer();
            }
        }
Beispiel #2
0
        // response variable transform log10
        public void log10T(object o, EventArgs e)
        {
            //can only transform the response variable and the response variable can not be a transformed ME or and interacted ME
            double[] newvals = new double[dt.Rows.Count];

            string newcolname = "LOG10[" + dt.Columns[intSelectedColIndex].Caption + "]";
            performTOperation(dt, newcolname, intSelectedColIndex, newvals);
            dt.Columns[newcolname].ExtendedProperties[VBCommon.Globals.DEPENDENTVARIBLEDEFINEDTRANSFORM] = VBCommon.DependentVariableTransforms.Log10.ToString();

            intResponseVarColIndex = dt.Columns.IndexOf(newcolname);
            strResponseVarColName = dt.Columns[intResponseVarColIndex].Caption;

            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #3
0
 // response variable transform power(exp)
 public void powerT(object o, EventArgs e)
 {
     frmPowerExponent frmExp = new frmPowerExponent(dt, intSelectedColIndex);
     DialogResult dlgr = frmExp.ShowDialog();
     if (dlgr != DialogResult.Cancel)
     {
         double[] newvals = new double[dt.Rows.Count];
         newvals = frmExp.TransformedValues;
         if (frmExp.TransformMessage != "")
         {
             MessageBox.Show("Cannot Power transform variable. " + frmExp.TransformMessage, "VB Transform Rule", MessageBoxButtons.OK);
             return;
         }
         string sexp = frmExp.Exponent.ToString("n2");
         string newcolname = "POWER" + "[" + sexp + "," + dt.Columns[intSelectedColIndex].Caption + "]";
         performTOperation(dt, newcolname, intSelectedColIndex, newvals);
         dt.Columns[newcolname].ExtendedProperties[VBCommon.Globals.DEPENDENTVARIBLEDEFINEDTRANSFORM] = VBCommon.DependentVariableTransforms.Power.ToString() + "," + sexp;
         depVarTransform = VBCommon.DependentVariableTransforms.Power;
         dblPowerTransformExp = Convert.ToDouble(sexp);
         state = dtState.dirty;
         NotifyContainer();
     }
 }
Beispiel #4
0
        // set grid/listview properties for the user-selected row menu item Enable
        // note that there are no table row extended properties - row status is tracked
        // in the dtRowInformation class
        public void EnableRow(object sender, EventArgs e)
        {
            dtRI.setRowStatus(dt.Rows[intSelectedRowIndex][0].ToString(), true);
            for (int c = 0; c < dgv.Columns.Count; c++)
            {
                if (!dtCI.getColStatus(dgv.Columns[c].Name.ToString())) continue;
                dgv[c, intSelectedRowIndex].Style.ForeColor = Color.Black;
            }

            updateListView(listvals.NDISABLEDROWS, --intNdisabledrows);
            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #5
0
        // response variable transform natural log
        public void lnT(object o, EventArgs e)
        {
            double[] newvals = new double[dt.Rows.Count];

            string newcolname = "LN[" + dt.Columns[intSelectedColIndex].Caption + "]";
            performTOperation(dt, newcolname, intSelectedColIndex, newvals);
            dt.Columns[newcolname].ExtendedProperties[VBCommon.Globals.DEPENDENTVARIBLEDEFINEDTRANSFORM] = VBCommon.DependentVariableTransforms.Ln.ToString();
            depVarTransform = VBCommon.DependentVariableTransforms.Ln;
            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #6
0
        public void EnableAllRows(object sender, EventArgs e)
        {
            for (int r = 0; r < dt.Rows.Count; r++)
            {
                dtRI.setRowStatus(dt.Rows[r][0].ToString(), true);
            }

            for (int r = 0; r < dgv.Rows.Count; r++)
            {
                for (int c = 0; c < dgv.Columns.Count; c++)
                {
                    if (!dtCI.getColStatus(dgv.Columns[c].Name.ToString())) continue;
                    dgv[c, r].Style.ForeColor = Color.Black;
                }
            }

            intNdisabledrows = 0;
            updateListView(listvals.NDISABLEDROWS, intNdisabledrows);
            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #7
0
        // set table/grid/listview properties for the user-selected column menu item Enable
        public void EnableCol(object sender, EventArgs e)
        {
            string cn = dt.Columns[intSelectedColIndex].Caption;
            dtCI.setColStatus(dt.Columns[intSelectedColIndex].ColumnName.ToString(), true);
            dt.Columns[intSelectedColIndex].ExtendedProperties[VBCommon.Globals.ENABLED] = true;
            updateListView(listvals.NDISABLEDCOLS, --intNdisabledcols);
            updateListView(listvals.NIVS, ++intNivs);
            gridutils.enableGridCol(dgv, intSelectedColIndex, dt);

            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #8
0
 // set grid/listview properties for the user-selected row menu item Disable
 // note that there are no table row extended properties - row status is tracked
 // in the dtRowInformation class
 public void DisableRow(object sender, EventArgs e)
 {
     dtRI.setRowStatus(dt.Rows[intSelectedRowIndex][0].ToString(), false);
     for (int c = 0; c < dgv.Columns.Count; c++)
     {
         dgv[c, intSelectedRowIndex].Style.ForeColor = Color.Red;
     }
     updateListView(listvals.NDISABLEDROWS, ++intNdisabledrows);
     state = dtState.dirty;
     NotifyContainer();
 }
Beispiel #9
0
        public void EnableAllCols(object sender, EventArgs e)
        {
            for (int c = 1; c < dt.Columns.Count; c++)
            {
                dtCI.setColStatus(dt.Columns[c].Caption, true);
                dt.Columns[c].ExtendedProperties[VBCommon.Globals.ENABLED] = true;
                gridutils.enableGridCol(dgv, c, dt);
            }

            intNdisabledcols = 0;
            updateListView(listvals.NDISABLEDCOLS, intNdisabledcols);

            int intNonivs = intNhiddencols > 0 ? 3 : 2;
            intNivs = dt.Columns.Count - intNonivs;
            updateListView(listvals.NIVS, intNivs);
            state = dtState.dirty;
            NotifyContainer();
        }
Beispiel #10
0
 //done editing, accept changes
 public void dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     dgv.EndEdit();
     dt.Rows[e.RowIndex][e.ColumnIndex] = dgv[e.ColumnIndex, e.RowIndex].Value;
     dt.AcceptChanges();
     state = dtState.dirty;
     NotifyContainer();
 }
Beispiel #11
0
        // delete the select column
        public void DeleteCol(object o, EventArgs e)
        {
            if (dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.TRANSFORM) ||
                dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.OPERATION) ||
                dt.Columns[intSelectedColIndex].ExtendedProperties.ContainsKey(VBCommon.Globals.DECOMPOSITION))
            {
                dtCI.removeColumnFromDic(dt.Columns[intSelectedColIndex].Caption);

                int gridpos = dgv.FirstDisplayedScrollingColumnIndex;
                dt.Columns.Remove(dt.Columns[intSelectedColIndex].Caption);

                dt.AcceptChanges();

                gridutils.maintainGrid(dgv, dt, intSelectedColIndex, strResponseVarColName);

                dgv.DataSource = dt;
                dgv.FirstDisplayedScrollingColumnIndex = gridpos;
                updateListView(listvals.NCOLS, dt.Columns.Count);
                updateListView(listvals.NIVS, --intNivs);

                state = dtState.dirty;
                NotifyContainer();
            }
        }
Beispiel #12
0
        public void defineTransformForRV(object o, EventArgs e)
        {
            //menu response from right click, determine which transform was selected
            MenuItem mi = (MenuItem)o;
            string transform = mi.Text;
            if (transform == VBCommon.DependentVariableTransforms.Power.ToString())
            {
                frmPowerExponent frmExp = new frmPowerExponent(dt, intSelectedColIndex);
                DialogResult dlgr = frmExp.ShowDialog();
                if (dlgr != DialogResult.Cancel)
                {
                    string sexp = frmExp.Exponent.ToString("n2");
                    transform += "," + sexp;
                    depVarTransform = VBCommon.DependentVariableTransforms.Power;
                    dblPowerTransformExp = Convert.ToDouble(sexp);
                    dt.Columns[intSelectedColIndex].ExtendedProperties[VBCommon.Globals.DEPENDENTVARIBLEDEFINEDTRANSFORM] = transform;
                    state = dtState.dirty;
                    NotifyContainer();
                }
            }
            else
            {
                if (String.Compare(transform, "Log10", true) == 0)
                    depVarTransform = VBCommon.DependentVariableTransforms.Log10;
                else if (String.Compare(transform, "Ln", true) == 0)
                    depVarTransform = VBCommon.DependentVariableTransforms.Ln;
                else if (String.Compare(transform, "none", true) == 0)
                    depVarTransform = VBCommon.DependentVariableTransforms.none;

                dt.Columns[intSelectedColIndex].ExtendedProperties[VBCommon.Globals.DEPENDENTVARIBLEDEFINEDTRANSFORM] = transform;
                state = dtState.dirty;
                NotifyContainer();
            }
        }
Beispiel #13
0
        public void UnTransform(object o, EventArgs e)
        {
            //can only untransform response variable (only one transformable)
            //unhide the original response variable
            //remove the transformed column
            DialogResult dlgr = DialogResult.Yes;
            if (hasTCols())
            {
                dlgr = MessageBox.Show("Datasheet contains independent variable transforms; un-transforming the dependent variable\n results in removal of created columns; Proceed (Y?N)",
                    "Are you sure you want to continue?", MessageBoxButtons.YesNo);
            }
            if (dlgr == DialogResult.Yes)
            {
                DataTable dtCopy = dt;
                dtCopy.Columns.Remove(dt.Columns[intSelectedColIndex].Caption);
                dtCopy.AcceptChanges();
                if (hasTCols())
                {
                    dtCopy = tableutils.filterTcols(dtCopy);
                }

                foreach (DataColumn c in dtCopy.Columns)
                {
                    if (!utils.testValueAttribute(c, VBCommon.Globals.HIDDEN)) continue;
                    {
                        utils.setAttributeValue(c, VBCommon.Globals.DEPENDENTVAR, true);
                        utils.setAttributeValue(c, VBCommon.Globals.HIDDEN, false);
                        intSelectedColIndex = dtCopy.Columns.IndexOf(c);
                        strResponseVarColName = dtCopy.Columns[intSelectedColIndex].Caption;
                        intResponseVarColIndex = intSelectedColIndex;

                        updateListView(listvals.NHIDDENCOLS, --intNhiddencols);
                        break;
                    }
                }

                dt = dtCopy;
                gridutils.maintainGrid(dgv, dt, intSelectedColIndex, strResponseVarColName);
                //count iv columns and update list
                int nonivs = intNhiddencols > 0 ? 3 : 2;
                intNivs = dt.Columns.Count - nonivs;
                updateListView(listvals.NIVS, intNivs);
                //and rv name
                updateListView(listvals.RVCOLNAME, strResponseVarColName);

                state = dtState.dirty;
                NotifyContainer();
            }
        }
Beispiel #14
0
        // set table/grid/listview properties for the user-selected column menu item Transform (the individual
        //transform event handlers all call this method to add the transformed values to the table as a new column,
        //hide the untransformed column.  if the previous variable was a transformed variable,
        public void transformRVValues(DataTable dt, string newcolname, int selectedColIndex, double[] newvals)
        {
            //we're only here on transform of dependent variable
            DialogResult dlgr = DialogResult.Yes;
            if (hasTCols())
            {
                dlgr = MessageBox.Show("Datasheet contains independent variable transforms; transforming the dependent variable\n results in removal of created columns; Proceed (Y?N)",
                    "Are you sure you want to continue?", MessageBoxButtons.YesNo);
            }
            if (dlgr == DialogResult.Yes)
            {
                try
                {
                    DataTable dtCopy = dt.Copy();
                    utils.setAttributeValue(dtCopy.Columns[selectedColIndex], VBCommon.Globals.DEPENDENTVAR, false);
                    string colname = dtCopy.Columns[selectedColIndex].Caption;

                    if (hasTCols())
                    {
                        dtCopy = tableutils.filterTcols(dtCopy);
                    }

                    dtCopy = tableutils.setHiddenIVstoUnhidden(dtCopy);
                    int ordinal = dtCopy.Columns.IndexOf(colname);
                    dtCopy.Columns.Add(newcolname, typeof(double));

                    for (int r = 0; r < dtCopy.Rows.Count; r++)
                        dtCopy.Rows[r][newcolname] = newvals[r];
                    dtCopy.Columns[newcolname].SetOrdinal(ordinal + 1);
                    dtCopy.AcceptChanges();
                    dtCI.addColumnNameToDic(newcolname);

                    //set properties of new rv
                    strResponseVarColName = newcolname;
                    intResponseVarColIndex = dtCopy.Columns.IndexOf(strResponseVarColName);
                    utils.setAttributeValue(dtCopy.Columns[newcolname], VBCommon.Globals.DEPENDENTVARIBLETRANSFORM, true);

                    //set properties of old one
                    utils.setAttributeValue(dtCopy.Columns[selectedColIndex], VBCommon.Globals.HIDDEN, true);

                    dt = dtCopy;
                    gridutils.maintainGrid(dgv, dt, selectedColIndex, strResponseVarColName);

                    updateListView(listvals.NHIDDENCOLS, ++intNhiddencols);
                    //count iv columns and update list
                    int nonivs = intNhiddencols > 0 ? 3 : 2;
                    intNivs = dt.Columns.Count - nonivs;
                    updateListView(listvals.NIVS, intNivs);
                    //and rv name
                    updateListView(listvals.RVCOLNAME, strResponseVarColName);

                    state = dtState.dirty;
                    NotifyContainer();
                }
                catch (DuplicateNameException e)
                {
                    MessageBox.Show("Table already contains column: " + newcolname, "Cannot Add Column to Table", MessageBoxButtons.OK);
                }
            }
        }