private void json_read() { string json, path = ""; if (File.Exists("placement.json")) { string[] buf = File.ReadAllLines("placement.json"); if (buf.Length != 0) { path = "placement.json"; } else if (File.Exists("composition.json")) { buf = File.ReadAllLines("composition.json"); if (buf.Length != 0) { path = "composition.json"; } } } if (path != "") { StreamReader sr = new StreamReader(path); while (!sr.EndOfStream) { json = sr.ReadLine(); DRP p = JsonConvert.DeserializeObject <DRP>(json); newp.Add(p); } sr.Close(); for (int i = 0; i < newp.Count; i++) { res_uzel = new DRP(); res_uzel.Uzel = new int[16]; resp.Add(res_uzel); } uzel_done = new int[newp.Count]; cb_set(newp.Count); } else { MessageBox.Show("Нет входных данных! Выполните предыдущие этапы!"); } }
private void Base_Click(object sender, RoutedEventArgs e) { resp.Clear(); DRP my; UzBox.Items.Clear(); for (int i = 0; i < newp.Count; i++) { my = new DRP(); my.Name = newp[i].Name; my.Uzel = newp[i].Uzel; resp.Add(my); } UzBox.IsEnabled = true; Zagr.IsEnabled = true; // UzBox.Items[-1] = "Выберите узел"; for (int c = 0; c < resp.Count; c++) { UzBox.Items.Add("Узел: " + (c + 1)); } }
private void json_set() { newr.Clear(); newp.Clear(); U_R strok; int[] hr; for (int k = 0; k < 12; k++) { strok = new U_R(); hr = new int[12]; // strok.Name = k + 1; //for (int z = 0; z < 12; z++) // hr[z] = r_matr_json[k, z]; strok.R_str = r_matr_json; newr.Add(strok); } //prod.Uzel = new int[] { 1, 9, 10, 4, 0, 0, 6, 5,0,0,0 }; //prod.Name = 1; //prod1.Uzel = new int[] { 7, 2, 3, 13, 12, 11, 8, 0, 14 }; //prod.Name = 2; string json = JsonConvert.SerializeObject(prod); string json1 = JsonConvert.SerializeObject(prod1); StreamWriter sw = new StreamWriter("InputR_mat.json"); //sw.WriteLine(json); //sw.WriteLine(json1); //sw.Close(); //sw = new StreamWriter("testR.json"); //for (int k = 0; k < 12; k++) //{ // strok = newr[k]; string rmat = JsonConvert.SerializeObject(r_matr_json); sw.WriteLine(rmat); //} sw.Close(); newr.Clear(); StreamReader sr = new StreamReader("InputUz.json"); for (int i = 0; !sr.EndOfStream; i++) { json1 = sr.ReadLine(); DRP p = JsonConvert.DeserializeObject <DRP>(json1); newp.Add(p); } sr.Close(); sr = new StreamReader("InputR_mat.json"); for (int i = 0; !sr.EndOfStream; i++) { json1 = sr.ReadLine(); int[,] pr = JsonConvert.DeserializeObject <int[, ]>(json1); // newr.Add(pr); r_matr_json = pr; } sr.Close(); DRP my; for (int i = 0; i < newp.Count; i++) { my = new DRP(); my.Name = newp[i].Name; my.Uzel = newp[i].Uzel; resp.Add(my); } }