private void button1_Click(object sender, EventArgs e) { if(textBox1.Text.Length>0 && textBox3.Text.Length>0 && listBox1.Items.Count>0) { if (newReceptProducts.Count != 0) { if (comboBox1.SelectedIndex > -1) { Recept recept = new Recept(); recept.IdRecept = Guid.NewGuid().ToString(); recept.NameRecept = textBox1.Text; recept.TextRecept = textBox3.Text.Replace("\r\n", "newline"); recept.TypeRecept = mainForm.RtDict.getKeyByValue(comboBox1.SelectedItem.ToString().Trim()); mainForm.ReceptList.Add(recept); foreach (var listItem in listBox1.Items) { PR pr = new PR(); pr.IdP = listItem.ToString().Split('|')[0]; pr.IdR = recept.IdRecept; pr.Kolvo = listItem.ToString().Split('|')[2]; pr.Ei = listItem.ToString().Split('|')[3]; pr.Obyaz = listItem.ToString().Split('|')[4]; mainForm.PrList.Add(pr); } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Recept")) { foreach (var rcpt in mainForm.ReceptList) { file.WriteLine(rcpt.IdRecept + "|" + rcpt.NameRecept + "|" + rcpt.TextRecept + "|" + rcpt.TypeRecept); } file.Close(); } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"PR")) { foreach (var pr in mainForm.PrList) { file.WriteLine(pr.IdP + "|" + pr.IdR + "|" + pr.Kolvo + "|" + pr.Ei + "|" + pr.Obyaz); } file.Close(); } mainForm.Init(); Close(); } } } }
private void readPR() { PrList = new List<PR>(); String line; var file = new System.IO.StreamReader("PR", Encoding.UTF8); while ((line = file.ReadLine()) != null) { PR rNew = new PR(); String[] parsRec = line.Split('|'); rNew.IdP = parsRec[0]; rNew.IdR = parsRec[1]; rNew.Kolvo = parsRec[2]; rNew.Ei = parsRec[3]; rNew.Obyaz = parsRec[4]; PrList.Add(rNew); } file.Close(); }