private void search_but_Click(object sender, EventArgs e) { dgvsearch.Rows.Clear(); dgvsearch.Columns.Clear(); sday = searchday_com.Text.ToLower(); switch (searchtimeslot_com.SelectedIndex + 1) { case 1: stime = 'a'; break; case 2: stime = 'b'; break; case 3: stime = 'c'; break; case 4: stime = 'd'; break; case 5: stime = 'e'; break; case 6: stime = 'f'; break; case 7: stime = 'g'; break; case 8: stime = 'h'; break; case 9: stime = 'i'; break; case 10: stime = 'j'; break; } if (searchprof_rad.Checked == true) { String[] prof_load = new String[200]; String[] prof_rem = new String[200]; cb = new SqlCommand("Select name from professors", con); int count = 0; con.Open(); sdr = cb.ExecuteReader(); while (sdr.Read()) { prof_load[count] = sdr.GetString(0); count++; } con.Close(); cb = new SqlCommand("select name from professor_tt where " + sday + " = 1 and " + stime + " = 1;", con); count = 0; con.Open(); sdr = cb.ExecuteReader(); while (sdr.Read()) { prof_rem[count] = sdr.GetString(0); count++; } con.Close(); var listCommon = prof_load.Except(prof_rem); dgvsearch.Columns.Add("Name", "Name"); foreach (String s in listCommon) { dgvsearch.Rows.Add(s); } } else if (searchclass_rad.Checked == true) { String[] class_load = new String[200]; String[] class_rem = new String[200]; cb = new SqlCommand("Select classroom_code from classrooms where classroom_description = 'Classroom' ;", con); int count = 0; con.Open(); sdr = cb.ExecuteReader(); while (sdr.Read()) { class_load[count] = sdr.GetString(0); count++; } con.Close(); cb = new SqlCommand("select class_code from classroom_tt where " + sday + " = 1 and " + stime + " = 1 and class_desc = 'Classroom' ;", con); count = 0; con.Open(); sdr = cb.ExecuteReader(); while (sdr.Read()) { class_rem[count] = sdr.GetString(0); count++; } con.Close(); var listCommon = class_load.Except(class_rem); dgvsearch.Columns.Add("Name", "Name"); foreach (String s in listCommon) { dgvsearch.Rows.Add(s); } } }
/// <summary> /// Makes sure that the passed attributes are a subset of the passed elements /// </summary> /// <param name="attr">What will be checked as a subset</param> /// <param name="elements">What will be checked as a parent set</param> /// <returns>True if the attributes are a subset, false elsewise</returns> public bool AttrsSubsetOfFieldNames(String[] attr, GBaseElement[] elements) { return !attr.Except(GBaseElementsToStrings(elements)).Any(); // If the set difference doesn't have any elements (they are same) return true, else fails }
public static String CodifyFormulae(String[] formulae, String[] initializedVars, String[] ёvars) { var formulaeProps = formulae.ToDictionary( f => f.Substring(0, f.IndexOf("=")).Trim(), f => f.Substring(f.IndexOf("=") + 1).Trim()); formulaeProps.Remove("С50"); // С50=У50*С4/М1 var formulaeCodegen = formulaeProps.ToDictionary( kvp => kvp.Key, kvp => String.Format(FormulaTemplate, kvp.Key, "(" + kvp.Value + ").ToString(CultureInfo.InvariantCulture)")); var variableProps = formulae.Select(f => Extractor.DetectVariablesInFormula(f)).Flatten().Concat(initializedVars).Distinct(); variableProps = variableProps.Except(formulaeProps.Keys).Except("округл".AsArray()).Except("удельныйвесэлемента".AsArray()); var variableCodegen = variableProps.ToDictionary(v => v, v => String.Format(VariableTemplate, v)); var ёvarProps = ёvars.Except(variableProps).Except(formulaeProps.Keys); var ёvarCodegen = ёvarProps.ToDictionary(v => v, v => String.Format(ЁVarTemplate, v)); Trace.WriteLine(String.Empty); Trace.WriteLine(String.Format("formulae = [{0}]", formulaeCodegen.Keys.OrderBy(v => v).StringJoin())); Trace.WriteLine(String.Format("get/set vars = [{0}]", variableCodegen.Keys.OrderBy(v => v).StringJoin())); Trace.WriteLine(String.Format("readonly ёvars = [{0}]", ёvarCodegen.Keys.OrderBy(v => v).StringJoin())); var codegen = formulaeCodegen.Concat(variableCodegen).Concat(ёvarCodegen).OrderBy(kvp => kvp.Key) .Select(kvp => kvp.Value).StringJoin(Environment.NewLine).Indent(2); codegen = codegen.Replace("Parse(округл)", "Math.Floor"); codegen = codegen.Replace("*Parse(удельныйвесэлемента),(/100)", ""); return String.Format(RepositoryTemplate, codegen); }