public override bool CanByMaterial(Materials what, Materials wher) { //if Dowel || (what && wher) if((Array.IndexOf(this.accepted_material, wher)>-1) && (Array.IndexOf(this.accepted_material, what)>-1)) return true; else{ if((Array.IndexOf(this.accepted_material, Materials.Dowel)>-1) && (Array.IndexOf(this.accepted_material, what)>-1)){ Dowel dw = Calculator.DowelToScrew(this, what, wher); if(dw != null){ this.dwl = dw; this.is_doweled = dw != null; } return this.is_doweled; } } return false; }
public static void ReadDataResoursesDowels () { DowelType type; float max_avulsion_force; float max_cut_force; bool is_throughwall; bool is_selfdrill; float d; float lenght; Materials[] accepted_material; float max_a; float max_s; float[] accepted_screw_d; string s; StreamReader strr = new StreamReader(GetStreamFromResource("Summer_work.Data.Dowels.dat")); while ((s = strr.ReadLine()) != null) { if(s[0] == '#') while ((s = strr.ReadLine ()) != null && (s[0] == '#')); if(s == null) return; string t; t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); Summer_work.DowelType.TryParse<Summer_work.DowelType> (t, out type); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); max_avulsion_force = float.Parse (t); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); max_cut_force = float.Parse (t); if (s [0] == '1') is_throughwall = true; else is_throughwall = false; s = s.Remove (0, 2); if (s [0] == '1') is_selfdrill = true; else is_selfdrill = false; s = s.Remove (0, 2); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); d = float.Parse (t); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); lenght = float.Parse (t); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); //Используя регулярные выражения (pattern - что ищем, source - где ищем): int sizeOfMat = new Regex (",").Matches (t).Count; accepted_material = new Materials[sizeOfMat+1]; for (int i = 0; i < sizeOfMat; i++) { string t1 = t.Substring (0, t.IndexOf (",")); t = t.Remove (0, t.IndexOf (",") + 1); Materials.TryParse<Summer_work.Materials> (t1, out accepted_material [i]); } Materials.TryParse<Summer_work.Materials> (t, out accepted_material [sizeOfMat]); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); max_a = float.Parse (t); t = s.Substring (0, s.IndexOf (" ")); s = s.Remove (0, s.IndexOf (" ") + 1); max_s = float.Parse (t); int sizeOfScr = new Regex(";").Matches(s).Count; accepted_screw_d = new float[sizeOfScr+1]; for(int i = 0; i < sizeOfScr; i++) { string t1 = s.Substring(0, s.IndexOf(";")); s =s.Remove(0, s.IndexOf(";")+1); accepted_screw_d[i] = float.Parse(t1); } accepted_screw_d[sizeOfScr] = float.Parse(s); max_cut_force = accepted_screw_d [sizeOfScr - 1] * 5 * 100; Dowel dw = new Dowel (type, max_avulsion_force, max_cut_force, is_throughwall, is_selfdrill, d, lenght, accepted_material, max_a, max_s, accepted_screw_d); Storage.dowelsDB.Add (dw); } }