Exemple #1
0
 private void ItemsGrid_CommittingEdit(object sender, DataGridEndingEditEventArgs e)
 {
   _editing = false;
 }
        private void gridControl1_CommittingEdit(object sender, DataGridEndingEditEventArgs e)
        {
            string s = gridControl1.CurrentCell.Text;
            UAReturn result = null;

            if (s.Trim() == "" || s.Trim() == "<NA>") s = "";//22Jun2015 blanks will be converted to NAs  

            //MessageBox.Show("CommittingEdit new row in data grid." + e.Row.Index + ":" + e.Column.Index + ":" + e.Column.Name + ":" + s);

            ///// Modifying R side data in Dataset ////////
            IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>();

            //19Sep2014 Get R side varname(diff set of valid chars for defining vars) of a variable in C#
            string RVarName = GetRVarName(e.Column.Name);
            int varidx = GetRVarNameIndex(RVarName);
            
            if (isnewdatarow)//Add new row
            {
                //19Sep2014 result=analyticServ.AddNewDatagridRow(e.Column.Name, s, e.Row.Index, ds.Name);
                //result = analyticServ.AddNewDatagridRow(RVarName, s, e.Row.Index, ds.Name);//19ep2014
                //isnewdatarow = false;
            }
            else //Edit existing
            {
                //Check if Dataclass(and Da taType) is right and then decide to skip this value if it does not match to the column type
                if (s.Trim().Length > 0 &&  !IsNumericStr(s) &&
                    ( ( ds.Variables[varidx].DataClass.Equals("numeric") && ds.Variables[varidx].DataType== DataColumnTypeEnum.Integer) ||
                    (ds.Variables[varidx].DataClass.Equals("numeric") && ds.Variables[varidx].DataType == DataColumnTypeEnum.Double) ||
                    (ds.Variables[varidx].DataClass.Equals("integer") && ds.Variables[varidx].DataType == DataColumnTypeEnum.Integer)
                    ))
                {
                    //Non numeric typled in numeric field
                    //Clean the cell
                    gridControl1.CancelEdit();
                    string msg = "Invalid value, you have entered a non-numeric value for a numeric variable. If you want to enter a non-numeric values make this variable a factor and enter non-numeric levels";
                    MessageBox.Show(msg, "Warning", MessageBoxButton.OK);
                    s = "";
                    return;
                }

                //19Sep2014 result=analyticServ.EditDatagridCell(e.Column.Name, s, e.Row.Index, ds.Name);
                result = analyticServ.EditDatagridCell(RVarName, s, e.Row.Index, ds.Name);//19Sep2014
            }
            ds.Changed = true;
            //refreshDataGrid();
            ///08Jul2013 Show Error/Warning in output window if any.
            //if(result!=null && result.Data != null)
            //    SendErrorWarningToOutput(result);
            
        }
Exemple #3
0
 private void ContactsGrid_CancelingEdit(object sender, DataGridEndingEditEventArgs e)
 {
     _editing = false;
 }
        //bool committedVarCell = false;
        private void variableGrid_CommittingEdit(object sender, DataGridEndingEditEventArgs e)
        {
            //if (committedVarCell)
            //{
            //    e.Cancel = true;
            //    return;
            //}
            //committedVarCell = true;
            // //on cell Edit and clicking elsewhere gives the info about edited cell
            List<string> colLevels = null;
            string cellVal = variableGrid.CurrentCell.Text;//eg..Male or Female
            string cellValue = cellVal != null ? cellVal.Replace("'", @"\'").Replace("\"", @"\'") : string.Empty;
            //string cellValue = cellVal != null ? cellVal.Replace("'", @"\'") : string.Empty;
            if (cellValue == null || cellValue.Trim().Length < 1) //Do not create new variable row if variable name is not provided
            {
                //method1 variableGrid.RemoveRow(variableGrid.CurrentRow.Index);

                //variableGrid.RaiseEvent();
                return;
            }
            //rowid = variableGrid.CurrentCell.Row.DataItem.ToString();//eg..gender // should be captured when we click on cell
            string colid = variableGrid.CurrentCell.Column.Header.ToString();//eg..Label
            switch (e.Column.Name)
            {
                case "Name":
                    break;
                case "DataType":
                    if (colid.Equals("DataType")) colid = "Type"; // colid must match with R side property name. Else it will not work
                    //MessageBox.Show(selectedData);
                    if (cellValue.Equals("String")) cellValue = "character";
                    if (cellValue.Equals("Numeric") || cellValue.Equals("Int") || cellValue.Equals("Float") || cellValue.Equals("Double")) cellValue = "numeric";
                    if (cellValue.Equals("Bool")) cellValue = "logical";
                    break;
                case "Width":
                    break;
                case "Decimals":
                    break;
                case "Label":
                    break;
                case "Values": 
                    colid = "Levels"; // "Levels"  new property name in R code
                    break;

                case "Missing":
                    break;
                case "Columns":
                    break;
                case "Alignment": 
                    colid = "Align"; // "Align" new property name in R code
                    C1.WPF.DataGrid.DataGridComboBoxColumn col = e.Column as C1.WPF.DataGrid.DataGridComboBoxColumn;
                    C1.WPF.C1ComboBox combo = e.EditingElement as C1.WPF.C1ComboBox;
                    string value = combo.Text;
                    break;
                case "Measure":
                    colLevels = getLevels();

                    break;
                case "Role":
                    break;
                default:
                    break;

            }

            ///// Modifying R side Dataset ////////
            IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>();
            if (rowid == null)//new row
            {
                int rowindex = 0;//variableGrid.CurrentRow.Index;
                string datagridcolval = ".";//default value for new col in datagrid view.
                // add new row cellValue is new colname
                analyticServ.addNewVariable(cellValue, datagridcolval, rowindex, ds.Name);


                //// Insert on UI side dataset ///
                DataSourceVariable var = new DataSourceVariable();
                // string RecCount = (this.Variables.Count + 1).ToString();//add 1 because its 0 based
                // int insertrowindex = variableGrid.SelectedIndex;
                 var.Name = cellValue; //////// Check Problem for manually appending new Var at the end
                 DS.Variables.Add(var);
                //this.Variables.Insert(rowindex, var);
                //DS.Variables.Insert(rowindex, var);//one more refresh needed. I guess
                //renumberRowHeader(variableGrid);
            }
            else
            {//edit existing row
                UAReturn retval = analyticServ.EditVarGrid(ds.Name, rowid, colid, cellValue, colLevels);
                retval.Success = true;
                ///08Jul2013 Show Error/Warning in output window if any.
                //if (retval != null && retval.Data != null)
                //    SendErrorWarningToOutput(retval);
            }
            //variableGrid. = cellValue;
            //MessageBox.Show("[R:"+rowid + "] [C:" + colid + "] [V:" + cellValue + "] [DS:" + ds.Name+"]");
            ds.Changed = true;
            if (e.Column.Name.Equals("Name"))
            refreshDataGrid();
            //arrangeVarGridCols();//rearrange the var-grid cols

        }