private void misvalOkbut_Click(object sender, RoutedEventArgs e) { List <string> mvlist = new List <string>(); string mtyp = ""; bool validentry = true; if (noMisvalRadio.IsChecked == true) { mtyp = "none"; //string[] mvs = { "", "", "" }; //misvals = mvs; } if (discreteMisvalRadio.IsChecked == true) { mtyp = "three";//+mval1+"-"+mval2+"-"+mval3; string mval1 = misval1.Text; string mval2 = misval2.Text; string mval3 = misval3.Text; string[] mvs = { mval1, mval2, mval3 }; //misvals = mvs; if ((misval1.Text.Length < 1 && misval2.Text.Length < 1 && misval3.Text.Length < 1)) { MessageBox.Show("At Least one Discrete value must be provided."); validentry = false; } else { foreach (string s in mvs)//Add non blank values to list { if (s.Length > 0) { mvlist.Add(s); } } } } if (rangeMisvalRadio.IsChecked == true) { mtyp = "range+1";//+low+"-"+high+"-"+discrete; string low = rangeLow.Text; string high = rangeHigh.Text; string discrete = rangeDiscrete.Text; string[] mvs = { low, high, discrete }; //misvals = mvs; if ((rangeLow.Text.Length < 1 || rangeHigh.Text.Length < 1)) { MessageBox.Show("Range must be provided."); validentry = false; } else { foreach (string s in mvs)//Add non blank values to list { if (s.Length > 0) { mvlist.Add(s); } } } } _misvaltype = mtyp; /// Validations /// foreach (string t in mvlist)//Fields must numeric only { Int32 temp; if (!Int32.TryParse(t, out temp))//can check other data types here in future enhancement { validentry = false; break; } } /// Popup window hides /// if (validentry) { misvals = mvlist; //assigning new missing values. Or say current missing values that user selected if (isMissingModified()) // if missing values or types has been modified. { OKClicked = true; isModified = true; //MessageBox.Show("Modified!"); } else { OKClicked = false; isModified = false; //MessageBox.Show("Not Modified!"); } MissingValuesDialog.GetWindow(this).Close(); } else { if (mvlist.Count > 0) { MessageBox.Show("Not a valid data type."); } } }
private void misvalCancelbut_Click(object sender, RoutedEventArgs e) { OKClicked = false; isModified = false; MissingValuesDialog.GetWindow(this).Close(); }
private void missingValueDialog() { MissingValuesDialog mv = new MissingValuesDialog(); int i = 0; rowid = variableGrid.CurrentCell.Row.DataItem.ToString();//gender foreach (var v in ds.Variables)//search for col name { if (v.Name.Equals(rowid))//if colname is found { //mv.vartype = v.DataType;//Data type of column. Can be used for validation in popup. if (v.MissType == null) v.MissType = "none"; //replace null with "none" if (!v.MissType.Equals("none")) { //foreach (var mvls in v.Missing)//get missing values for a column //{ // if (mvls.ToString().IndexOf('=') > 0) // mvals[i] = mvls.ToString();//setting missing values one by one // else // { // mvals[i] = mvls.ToString(); // } // i++; //} mv.misvals = v.Missing;//this must come before setting mv.mistype mv.oldmisvals = v.Missing;//keeping an original copy for tracing changes } mv.mistype = v.MissType;// missing type. "none", "three", "range+1" mv.oldMisType = v.MissType;//keeping an original copy for tracing changes break; } } mv.ShowDialog(); //check if values are changed and then set ds.Changed = true; if (mv.OKClicked && mv.isModified)//missing changed { //mvals = null; //mtype = mv.mistype; //if (!mv.mistype.Equals("none")) mvals = mv.misvals; ///change UI side dataset //// foreach (var v in ds.Variables)//search for col name { if (v.Name.Equals(rowid))//if colname is found { v.Missing.Clear(); if (!mv.mistype.Equals("none")) { v.Missing.AddRange(mv.misvals); } v.MissType = mv.mistype;// missing type. "none", "three", "range+1" break; } } // Fllowing 3 lines can be removed ... just for display //// //string mvals = ""; //foreach (string st in mv.misvals) mvals = mvals + ":" + st; //MessageBox.Show("Ty:" + mv.mistype + ":" + mvals); //set this new list of levels to R for update. IAnalyticsService analyticServ = LifetimeService.Instance.Container.Resolve<IAnalyticsService>(); analyticServ.ChangeMissingVals(rowid, "Missing", mv.misvals, mv.mistype, ds.Name); ds.Changed = true; } mv.Close();//release resources held by this popup //variableGrid.Refresh(); refreshDataGrid(); variableGrid.Refresh(); }