Example #1
0
        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();
                    }
                }

            }
        }
        public ReceptEngine(MainForm mForm, String receptName)
        {
            mainForm = mForm;
            Recept findRecept = new Recept();

            foreach (var recept in mainForm.ReceptList)
            {
                if(recept.NameRecept.Equals(receptName))
                {
                    findRecept = recept;
                    break;
                }
            }

            String rec = findRecept.TextRecept.Replace("newline", "\r\n");
            mainForm.setReceptText(rec);

            //TODO: необязательные ингредиенты в конце списка
            String ingredients = "";
            foreach (var rp in mainForm.PrList)
            {
                if(rp.IdR.Equals(findRecept.IdRecept))
                {
                    if (ingredients.Length>0)
                    {
                        ingredients += ", ";
                    }
                    ingredients += (getIngr(rp.IdP, rp.Kolvo + " " + rp.Ei)).ToLower();

                }
            }
            mainForm.setReceptIng(ingredients);

            if (findRecept.TypeRecept.Equals(""))
            {
                mainForm.setReceptType("");
            }
            else
            {
                mainForm.setReceptType(mainForm.RtDict.getValueByKey(findRecept.TypeRecept));
            }
        }
Example #3
0
        private void readRecepts()
        {
            ReceptList = new List<Recept>();
            String line;
            var file = new System.IO.StreamReader("Recept", Encoding.UTF8);
            while ((line = file.ReadLine()) != null)
            {
                Recept rNew = new Recept();
                String[] parsRec = line.Split('|');
                rNew.IdRecept = parsRec[0];
                rNew.NameRecept = parsRec[1];
                rNew.TextRecept = parsRec[2];
                try
                {
                    rNew.TypeRecept = parsRec[3];
                }
                catch (Exception e)
                {
                    rNew.TypeRecept = "";
                }

                listBox1.Items.Add(parsRec[1]);
                ReceptList.Add(rNew);
            }
            file.Close();
        }