using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StekloMaster
{
    public partial class Form13 : Form
    {
        public Form13()
        {
            InitializeComponent();
        }
        string putin = "";

        private void Form13_Load(object sender, EventArgs e)
        {
            if (Application.StartupPath.IndexOf("comp") != -1)
            {
                putin = Application.StartupPath.Substring(0, Application.StartupPath.IndexOf("\\comp"));
            }
            else
            {
                putin = Application.StartupPath;
            }
            obntovar();
            obnuslug();
            obnviddekor();
            obnforma();
            obnvar();
            loadkriv();
            prymobr();
            loadvirez();
            loaddirka();
            loadzakdirka();
            loadmater();
            comboBox8.SelectedIndex = 0;
            comboBox1.SelectedIndex = 0;
        }

        #region Товары
        private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox6.Text == "")
                return;
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                {
                    listBox3.BeginUpdate();
                    listBox3.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            if (comboBox6.Text != "Все")
                            {
                                if (tmp[2] != comboBox6.Text)
                                    continue;
                            }
                            listBox3.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " - " + tmp[1] + " руб." });
                        }

                    }
                    if (listBox3.Items.Count != 0)
                        listBox3.SelectedIndex = 0;
                    listBox3.EndUpdate();
                }
            }
            catch { listBox3.EndUpdate(); }
        }
        private void obntovar()
        {
            try
            {
                StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv");
                string k = sr.ReadToEnd();
                sr.Close();
                string postav = "";
                comboBox6.BeginUpdate();
                comboBox6.Items.Clear();
                comboBox6.Items.AddRange(new object[] { "Все" });
                comboBox3.BeginUpdate();
                comboBox3.Items.Clear();
                comboBox3.Items.AddRange(new object[] { "Другая" });

                string[] wordr = k.Split('\n');
                foreach (string word in wordr)
                {
                    if (word != "" && word != null)
                    {
                        string tmp = word.Replace("\r", "");
                        string[] a1 = tmp.Split('|');
                        if (postav.IndexOf("<" + a1[2] + ">") == -1)
                        {
                            comboBox6.Items.AddRange(new object[] { a1[2] });
                            comboBox3.Items.AddRange(new object[] { a1[2] });
                            postav += "<" + a1[2] + ">";
                        }
                    }
                }
                comboBox6.EndUpdate();
                comboBox6.SelectedIndex = 0;
                comboBox3.EndUpdate();
                comboBox3.SelectedIndex = 0;
            }
            catch
            {
                comboBox6.EndUpdate();
                comboBox3.EndUpdate();
            }
        }
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox1.Enabled = (comboBox3.Text == "Другая");
        }
        private void button5_Click(object sender, EventArgs e)
        {
            int g = listBox3.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox3.SelectedItem.ToString().Substring(0, listBox3.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\tovar.akv", s, Encoding.UTF8);
                    listBox3.Items.RemoveAt(listBox3.SelectedIndex);
                    listBox3.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }
        private void button14_Click(object sender, EventArgs e)
        {
            if (comboBox6.Text == "Все")
            {
                if (listBox3.SelectedIndex != 0)
                {
                    int c = 0;
                    string str33 = "";
                    string s = "";
                    string up = "";
                    string down = "";
                    int g = listBox3.SelectedIndex;
                    try
                    {
                        using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                        {
                            while ((str33 = sr.ReadLine()) != null)
                            {
                                if (c == listBox3.SelectedIndex - 1)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    if (c == listBox3.SelectedIndex)
                                    {
                                        down = str33;
                                        s += "ВнИз\r\n";
                                    }
                                    else
                                    {
                                        s += str33 + "\r\n";
                                    }
                                }
                                c++;
                            }
                            sr.Close();
                            s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                            File.WriteAllText(putin + "\\data\\skinali\\tovar.akv", s, Encoding.UTF8);
                            if (comboBox6.SelectedIndex != 0)
                                comboBox6.SelectedIndex = 0;
                            else
                                comboBox6_SelectedIndexChanged(null, null);
                        }
                    }
                    catch { }
                    listBox3.SelectedIndex = g - 1;
                    c = 0;
                    str33 = null;
                    s = null;
                    up = null;
                    down = null;
                    g = 0;
                }
            }
        }
        private void button13_Click(object sender, EventArgs e)
        {
            if (comboBox6.Text == "Все")
            {
                if (listBox3.SelectedIndex != listBox3.Items.Count - 1)
                {
                    int c = 0;
                    string str33 = "";
                    string s = "";
                    string up = "";
                    string down = "";
                    int g = listBox3.SelectedIndex;
                    try
                    {
                        using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                        {
                            while ((str33 = sr.ReadLine()) != null)
                            {
                                if (c == listBox3.SelectedIndex + 1)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    if (c == listBox3.SelectedIndex)
                                    {
                                        up = str33;
                                        s += "ВвЕрХ\r\n";
                                    }
                                    else
                                    {
                                        s += str33 + "\r\n";
                                    }
                                }
                                c++;
                            }
                            sr.Close();
                            s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                            File.WriteAllText(putin + "\\data\\skinali\\tovar.akv", s, Encoding.UTF8);
                            if (comboBox6.SelectedIndex != 0)
                                comboBox6.SelectedIndex = 0;
                            else
                                comboBox6_SelectedIndexChanged(null, null);
                        }
                    }
                    catch { }
                    listBox3.SelectedIndex = g + 1;
                    c = 0;
                    str33 = null;
                    s = null;
                    up = null;
                    down = null;
                    g = 0;
                }
            }
        }
        private void button12_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox3.SelectedItem.ToString().Substring(0, listBox3.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox7.Text = str33.Split('|')[0];
                                numericUpDown5.Value = Convert.ToInt32(str33.Split('|')[1]);
                                comboBox3.Text = str33.Split('|')[2];
                                if (str33.Split('|')[3] == "p")
                                {
                                    comboBox8.SelectedIndex = 0;
                                }
                                if (str33.Split('|')[3] == "s")
                                {
                                    comboBox8.SelectedIndex = 1;
                                }
                                if (str33.Split('|')[3] == "c")
                                {
                                    comboBox8.SelectedIndex = 2;
                                }
                            }
                            catch { }
                            comboBox6.Enabled = false;
                            listBox3.Enabled = false;
                            panel8.Enabled = false;
                            button16.Visible = true;
                            button15.Visible = true;
                            button17.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }
        private void button15_Click(object sender, EventArgs e)
        {
            comboBox6.Enabled = true;
            listBox3.Enabled = true;
            panel8.Enabled = true;
            button16.Visible = false;
            button15.Visible = false;
            button17.Visible = true;

            textBox7.Text = "";
            numericUpDown5.Value = 100;
            textBox1.Text = "";
        }
        private void button16_Click(object sender, EventArgs e)
        {
            if (textBox7.Text != "")
            {
                int g = listBox3.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox3.SelectedItem.ToString().Substring(0, listBox3.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox7.Text.Replace("|", "/") + "|" + numericUpDown5.Value + "|";
                                if (textBox1.Enabled)
                                    s += textBox1.Text;
                                else
                                    s += comboBox3.Text;
                                if (comboBox8.SelectedIndex == 0)
                                    s += "|p";
                                if (comboBox8.SelectedIndex == 1)
                                    s += "|s";
                                if (comboBox8.SelectedIndex == 2)
                                    s += "|c";
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\tovar.akv", s, Encoding.UTF8);
                        button15_Click(null, null);
                        obntovar();

                    }
                }
                catch { }
                c = 0;
                listBox3.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }
        private void button17_Click(object sender, EventArgs e)
        {
            if (textBox7.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\tovar.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox7.Text.Replace("|", "/") + "|" + numericUpDown5.Value + "|";
                if (textBox1.Enabled)
                    s += textBox1.Text;
                else
                    s += comboBox3.Text;
                if (comboBox8.SelectedIndex == 0)
                    s += "|p";
                if (comboBox8.SelectedIndex == 1)
                    s += "|s";
                if (comboBox8.SelectedIndex == 2)
                    s += "|c";
                s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\tovar.akv", s, Encoding.UTF8);
                obntovar();
                textBox7.Text = "";
                numericUpDown5.Value = 100;
                textBox1.Text = "";

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }
        #endregion

        #region Услуги
        private void obnuslug()
        {
            try
            {
                StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv");
                string k = sr.ReadToEnd();
                sr.Close();
                string postav = "";
                comboBox4.BeginUpdate();
                comboBox4.Items.Clear();
                comboBox4.Items.AddRange(new object[] { "Все" });
                comboBox2.BeginUpdate();
                comboBox2.Items.Clear();
                comboBox2.Items.AddRange(new object[] { "Другая" });

                string[] wordr = k.Split('\n');
                foreach (string word in wordr)
                {
                    if (word != "" && word != null)
                    {
                        string tmp = word.Replace("\r", "");
                        string[] a1 = tmp.Split('|');
                        if (postav.IndexOf("<" + a1[2] + ">") == -1)
                        {
                            comboBox4.Items.AddRange(new object[] { a1[2] });
                            comboBox2.Items.AddRange(new object[] { a1[2] });
                            postav += "<" + a1[2] + ">";
                        }
                    }
                }
                comboBox4.EndUpdate();
                comboBox4.SelectedIndex = 0;
                comboBox2.EndUpdate();
                comboBox2.SelectedIndex = 0;
            }
            catch
            {
                comboBox4.EndUpdate();
                comboBox2.EndUpdate();
            }
        }
        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox4.Text == "")
                return;
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                {
                    listBox1.BeginUpdate();
                    listBox1.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            if (comboBox4.Text != "Все")
                            {
                                if (tmp[2] != comboBox6.Text)
                                    continue;
                            }
                            listBox1.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " - " + tmp[1] + " руб." });
                        }

                    }
                    if (listBox1.Items.Count != 0)
                        listBox1.SelectedIndex = 0;
                    listBox1.EndUpdate();
                }
            }
            catch { listBox1.EndUpdate(); }
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox2.Enabled = (comboBox2.Text == "Другая");
        }
        private void button4_Click(object sender, EventArgs e)
        {
            int g = listBox1.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox1.SelectedItem.ToString().Substring(0, listBox1.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\uslugi.akv", s, Encoding.UTF8);
                    listBox1.Items.RemoveAt(listBox1.SelectedIndex);
                    listBox1.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }
        private void button8_Click(object sender, EventArgs e)
        {
            if (comboBox4.Text == "Все")
            {
                if (listBox1.SelectedIndex != 0)
                {
                    int c = 0;
                    string str33 = "";
                    string s = "";
                    string up = "";
                    string down = "";
                    int g = listBox1.SelectedIndex;
                    try
                    {
                        using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                        {
                            while ((str33 = sr.ReadLine()) != null)
                            {
                                if (c == listBox1.SelectedIndex - 1)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    if (c == listBox1.SelectedIndex)
                                    {
                                        down = str33;
                                        s += "ВнИз\r\n";
                                    }
                                    else
                                    {
                                        s += str33 + "\r\n";
                                    }
                                }
                                c++;
                            }
                            sr.Close();
                            s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                            File.WriteAllText(putin + "\\data\\skinali\\uslugi.akv", s, Encoding.UTF8);
                            if (comboBox4.SelectedIndex != 0)
                                comboBox4.SelectedIndex = 0;
                            else
                                comboBox4_SelectedIndexChanged(null, null);
                        }
                    }
                    catch { }
                    listBox1.SelectedIndex = g - 1;
                    c = 0;
                    str33 = null;
                    s = null;
                    up = null;
                    down = null;
                    g = 0;
                }
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            if (comboBox4.Text == "Все")
            {
                if (listBox1.SelectedIndex != listBox1.Items.Count - 1)
                {
                    int c = 0;
                    string str33 = "";
                    string s = "";
                    string up = "";
                    string down = "";
                    int g = listBox1.SelectedIndex;
                    try
                    {
                        using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                        {
                            while ((str33 = sr.ReadLine()) != null)
                            {
                                if (c == listBox1.SelectedIndex + 1)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    if (c == listBox1.SelectedIndex)
                                    {
                                        up = str33;
                                        s += "ВвЕрХ\r\n";
                                    }
                                    else
                                    {
                                        s += str33 + "\r\n";
                                    }
                                }
                                c++;
                            }
                            sr.Close();
                            s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                            File.WriteAllText(putin + "\\data\\skinali\\uslugi.akv", s, Encoding.UTF8);
                            if (comboBox4.SelectedIndex != 0)
                                comboBox4.SelectedIndex = 0;
                            else
                                comboBox4_SelectedIndexChanged(null, null);
                        }
                    }
                    catch { }
                    listBox1.SelectedIndex = g + 1;
                    c = 0;
                    str33 = null;
                    s = null;
                    up = null;
                    down = null;
                    g = 0;
                }
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox1.SelectedItem.ToString().Substring(0, listBox1.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox3.Text = str33.Split('|')[0];

                                numericUpDown1.Value = Convert.ToInt32(str33.Split('|')[1]);
                                comboBox2.Text = str33.Split('|')[2];
                                if (str33.Split('|')[3] == "p")
                                {
                                    comboBox1.SelectedIndex = 0;
                                }
                                if (str33.Split('|')[3] == "s")
                                {
                                    comboBox1.SelectedIndex = 1;
                                }
                                if (str33.Split('|')[3] == "c")
                                {
                                    comboBox1.SelectedIndex = 2;
                                }
                                if (str33.Split('|')[3] == "m")
                                {
                                    comboBox1.SelectedIndex = 3;
                                }
                            }
                            catch { }
                            comboBox4.Enabled = false;
                            listBox1.Enabled = false;
                            panel1.Enabled = false;
                            button2.Visible = true;
                            button1.Visible = true;
                            button3.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            comboBox4.Enabled = true;
            listBox1.Enabled = true;
            panel1.Enabled = true;
            button2.Visible = false;
            button1.Visible = false;
            button3.Visible = true;

            textBox3.Text = "";
            numericUpDown1.Value = 100;
            textBox2.Text = "";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text != "")
            {
                int g = listBox1.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox1.SelectedItem.ToString().Substring(0, listBox1.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox3.Text.Replace("|", "/") + "|" + numericUpDown1.Value + "|";
                                if (textBox2.Enabled)
                                    s += textBox2.Text;
                                else
                                    s += comboBox2.Text;
                                if (comboBox1.SelectedIndex == 0)
                                    s += "|p";
                                if (comboBox1.SelectedIndex == 1)
                                    s += "|s";
                                if (comboBox1.SelectedIndex == 2)
                                    s += "|c";
                                if (comboBox1.SelectedIndex == 3)
                                    s += "|m";
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\uslugi.akv", s, Encoding.UTF8);
                        button1_Click(null, null);
                        obnuslug();

                    }
                }
                catch { }
                c = 0;
                listBox1.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox3.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\uslugi.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox3.Text.Replace("|", "/") + "|" + numericUpDown1.Value + "|";
                if (textBox2.Enabled)
                    s += textBox2.Text;
                else
                    s += comboBox2.Text;
                if (comboBox1.SelectedIndex == 0)
                    s += "|p";
                if (comboBox1.SelectedIndex == 1)
                    s += "|s";
                if (comboBox1.SelectedIndex == 2)
                    s += "|c";
                if (comboBox1.SelectedIndex == 3)
                    s += "|m";
                s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\uslugi.akv", s, Encoding.UTF8);
                obnuslug();
                textBox3.Text = "";
                numericUpDown1.Value = 100;
                textBox2.Text = "";

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }
        #endregion

        #region Виды декорирования

        private void obnviddekor()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                {
                    listBox2.BeginUpdate();
                    listBox2.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox2.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " - " + tmp[1] + " руб." });
                        }

                    }
                    if (listBox2.Items.Count != 0)
                        listBox2.SelectedIndex = 0;
                    listBox2.EndUpdate();
                }
            }
            catch { listBox2.EndUpdate(); }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex != listBox2.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox2.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox2.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox2.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dekor.akv", s, Encoding.UTF8);
                        obnviddekor();
                    }
                }
                catch { }
                listBox2.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox2.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox2.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox2.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dekor.akv", s, Encoding.UTF8);
                        obnviddekor();
                    }
                }
                catch { }
                listBox2.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            int g = listBox2.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox2.SelectedItem.ToString().Substring(0, listBox2.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\dekor.akv", s, Encoding.UTF8);
                    listBox2.Items.RemoveAt(listBox2.SelectedIndex);
                    listBox2.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button21_Click(object sender, EventArgs e)
        {
            if (textBox4.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox4.Text.Replace("|", "/") + "|" + numericUpDown2.Value + "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\dekor.akv", s, Encoding.UTF8);
                obnviddekor();
                textBox4.Text = "";
                numericUpDown2.Value = 100;

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox2.SelectedItem.ToString().Substring(0, listBox2.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox4.Text = str33.Split('|')[0];

                                numericUpDown2.Value = Convert.ToInt32(str33.Split('|')[1]);
                            }
                            catch { }
                            listBox2.Enabled = false;
                            panel2.Enabled = false;

                            button19.Visible = true;
                            button20.Visible = true;
                            button21.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button19_Click(object sender, EventArgs e)
        {
            listBox2.Enabled = true;
            panel2.Enabled = true;

            button19.Visible = false;
            button20.Visible = false;
            button21.Visible = true;

            textBox4.Text = "";
            numericUpDown2.Value = 100;
        }

        private void button20_Click(object sender, EventArgs e)
        {
            if (textBox4.Text != "")
            {
                int g = listBox2.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox2.SelectedItem.ToString().Substring(0, listBox2.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dekor.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox4.Text.Replace("|", "/") + "|" + numericUpDown2.Value + "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\dekor.akv", s, Encoding.UTF8);
                        button19_Click(null, null);
                        obnviddekor();

                    }
                }
                catch { }
                c = 0;
                listBox2.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        #endregion

        #region Форма

        private void obnforma()
        {
            StreamReader sr = new StreamReader(putin + "\\data\\skinali\\forma.akv");
            richTextBox1.Text = sr.ReadToEnd();
            sr.Close();
        }

        private void button22_Click(object sender, EventArgs e)
        {
            File.WriteAllText(putin + "\\data\\skinali\\forma.akv", richTextBox1.Text, Encoding.UTF8);
        }

        #endregion

        #region Варианты обработки

        private void obnvar()
        {
            StreamReader sr = new StreamReader(putin + "\\data\\skinali\\variant.akv");
            richTextBox2.Text = sr.ReadToEnd();
            sr.Close();
        }

        private void button23_Click(object sender, EventArgs e)
        {
            File.WriteAllText(putin + "\\data\\skinali\\variant.akv", richTextBox2.Text, Encoding.UTF8);
        }


        #endregion

        #region Криволинейная обработка
        void loadkriv()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                {
                    listBox4.BeginUpdate();
                    listBox4.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox4.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0]});
                        }

                    }
                    if (listBox4.Items.Count != 0)
                        listBox4.SelectedIndex = 0;
                    listBox4.EndUpdate();
                }
            }
            catch { listBox4.EndUpdate(); }
        }

        private void button29_Click(object sender, EventArgs e)
        {
            if (listBox4.SelectedIndex != listBox4.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox4.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox4.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox4.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\kosobrabotka.akv", s, Encoding.UTF8);
                        loadkriv();
                    }
                }
                catch { }
                listBox4.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button30_Click(object sender, EventArgs e)
        {
            if (listBox4.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox4.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox4.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox4.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\kosobrabotka.akv", s, Encoding.UTF8);
                        loadkriv();
                    }
                }
                catch { }
                listBox4.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button27_Click(object sender, EventArgs e)
        {
            int g = listBox4.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox4.SelectedItem.ToString().Substring(0, listBox4.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\kosobrabotka.akv", s, Encoding.UTF8);
                    listBox4.Items.RemoveAt(listBox4.SelectedIndex);
                    listBox4.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button26_Click(object sender, EventArgs e)
        {
            if (textBox5.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox5.Text.Replace("|", "/") + "|";
                for (int h = 0; h < dataGridView4.Rows.Count; h++)
                {
                    s += dataGridView4.Rows[h].Cells[0].Value + "!" + dataGridView4.Rows[h].Cells[1].Value + "~";
                } 
                s+="\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\kosobrabotka.akv", s, Encoding.UTF8);
                loadkriv();
                textBox5.Text = "";
                dataGridView4.Rows.Clear();

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        private void button28_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox4.SelectedItem.ToString().Substring(0, listBox4.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox5.Text = str33.Split('|')[0];


                                dataGridView4.Rows.Clear();
                                string[] bd2 = str33.Split('|')[1].Split('~');
                                foreach (string s in bd2)
                                {
                                    if (s != "")
                                    {
                                        string[] f = s.Split('!');
                                        int i = dataGridView4.Rows.Count;
                                        dataGridView4.Rows.Add();
                                        for (int h = 0; h < 2; h++)
                                            dataGridView4.Rows[i].Cells[h].Value = f[h];
                                    }
                                }
                            }
                            catch { }
                            listBox4.Enabled = false;
                            panel3.Enabled = false;

                            button25.Visible = true;
                            button24.Visible = true;
                            button26.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button24_Click(object sender, EventArgs e)
        {
            listBox4.Enabled = true;
            panel3.Enabled = true;

            button25.Visible = false;
            button24.Visible = false;
            button26.Visible = true;

            textBox5.Text = "";
            dataGridView4.Rows.Clear();
        }

        private void button25_Click(object sender, EventArgs e)
        {
            if (textBox5.Text != "")
            {
                int g = listBox4.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox4.SelectedItem.ToString().Substring(0, listBox4.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\kosobrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox5.Text.Replace("|", "/") + "|";
                                for (int h = 0; h < dataGridView4.Rows.Count; h++)
                                {
                                    s += dataGridView4.Rows[h].Cells[0].Value + "!" + dataGridView4.Rows[h].Cells[1].Value + "~";
                                } 
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\kosobrabotka.akv", s, Encoding.UTF8);
                        button24_Click(null, null);
                        loadkriv();

                    }
                }
                catch { }
                c = 0;
                listBox4.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        private void button72_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dataGridView4.Rows.Count;
                dataGridView4.Rows.Add();
                dataGridView4.Rows[i].Cells[0].Value = numericUpDown21.Value;
                dataGridView4.Rows[i].Cells[1].Value = numericUpDown20.Value;
            }
            catch { }
        }

        private void button73_Click(object sender, EventArgs e)
        {
            if (dataGridView4.CurrentRow == null) return;
            dataGridView4.Rows.RemoveAt(dataGridView4.CurrentRow.Index);
        }

        #endregion

        #region Прямолинейная обработка
        void prymobr()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                {
                    listBox5.BeginUpdate();
                    listBox5.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox5.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0]});
                        }

                    }
                    if (listBox5.Items.Count != 0)
                        listBox5.SelectedIndex = 0;
                    listBox5.EndUpdate();
                }
            }
            catch { listBox5.EndUpdate(); }
        }

        private void button36_Click(object sender, EventArgs e)
        {
            if (listBox5.SelectedIndex != listBox5.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox5.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox5.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox5.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\obrabotka.akv", s, Encoding.UTF8);
                        prymobr();
                    }
                }
                catch { }
                listBox5.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button37_Click(object sender, EventArgs e)
        {
            if (listBox5.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox5.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox5.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox5.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\obrabotka.akv", s, Encoding.UTF8);
                        prymobr();
                    }
                }
                catch { }
                listBox5.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button34_Click(object sender, EventArgs e)
        {
            int g = listBox5.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox5.SelectedItem.ToString().Substring(0, listBox5.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\obrabotka.akv", s, Encoding.UTF8);
                    listBox5.Items.RemoveAt(listBox5.SelectedIndex);
                    listBox5.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button33_Click(object sender, EventArgs e)
        {
            if (textBox6.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox6.Text.Replace("|", "/") + "|";
                for (int h = 0; h < dataGridView5.Rows.Count; h++)
                {
                    s += dataGridView5.Rows[h].Cells[0].Value + "!" + dataGridView5.Rows[h].Cells[1].Value + "~";
                }
                s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\obrabotka.akv", s, Encoding.UTF8);
                prymobr();
                textBox6.Text = "";
                dataGridView5.Rows.Clear();

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        private void button35_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox5.SelectedItem.ToString().Substring(0, listBox5.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox6.Text = str33.Split('|')[0];

                                dataGridView5.Rows.Clear();
                                string[] bd2 = str33.Split('|')[1].Split('~');
                                foreach (string s in bd2)
                                {
                                    if (s != "")
                                    {
                                        string[] f = s.Split('!');
                                        int i = dataGridView5.Rows.Count;
                                        dataGridView5.Rows.Add();
                                        for (int h = 0; h < 2; h++)
                                            dataGridView5.Rows[i].Cells[h].Value = f[h];
                                    }
                                }
                            }
                            catch { }
                            listBox5.Enabled = false;
                            panel4.Enabled = false;

                            button31.Visible = true;
                            button32.Visible = true;
                            button33.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button31_Click(object sender, EventArgs e)
        {
            listBox5.Enabled = true;
            panel4.Enabled = true;

            button32.Visible = false;
            button31.Visible = false;
            button33.Visible = true;

            textBox6.Text = "";
            dataGridView5.Rows.Clear();
        }

        private void button32_Click(object sender, EventArgs e)
        {
            if (textBox6.Text != "")
            {
                int g = listBox5.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox5.SelectedItem.ToString().Substring(0, listBox5.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\obrabotka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox6.Text.Replace("|", "/") + "|";
                                for (int h = 0; h < dataGridView5.Rows.Count; h++)
                                {
                                    s += dataGridView5.Rows[h].Cells[0].Value + "!" + dataGridView5.Rows[h].Cells[1].Value + "~";
                                }
                                s += "\r\n";

                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\obrabotka.akv", s, Encoding.UTF8);
                        button31_Click(null, null);
                        prymobr();

                    }
                }
                catch { }
                c = 0;
                listBox5.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        #endregion

        #region Вырезы
        private void loadvirez()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                {
                    listBox6.BeginUpdate();
                    listBox6.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox6.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " - " + tmp[1] + " мм." });
                        }

                    }
                    if (listBox6.Items.Count != 0)
                        listBox6.SelectedIndex = 0;
                    listBox6.EndUpdate();
                }
            }
            catch { listBox6.EndUpdate(); }
        }

        private void button43_Click(object sender, EventArgs e)
        {
            if (listBox6.SelectedIndex != listBox6.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox6.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox6.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox6.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\virez.akv", s, Encoding.UTF8);
                        loadvirez();
                    }
                }
                catch { }
                listBox6.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button44_Click(object sender, EventArgs e)
        {
            if (listBox6.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox6.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox6.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox6.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\virez.akv", s, Encoding.UTF8);
                        loadvirez();
                    }
                }
                catch { }
                listBox6.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button41_Click(object sender, EventArgs e)
        {
            int g = listBox6.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox6.SelectedItem.ToString().Substring(0, listBox6.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\virez.akv", s, Encoding.UTF8);
                    listBox6.Items.RemoveAt(listBox6.SelectedIndex);
                    listBox6.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button40_Click(object sender, EventArgs e)
        {
            if (textBox8.Text != "")
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\virez.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox8.Text.Replace("|", "/") + "|" + numericUpDown6.Value + "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\virez.akv", s, Encoding.UTF8);
                loadvirez();
                textBox8.Text = "";
                numericUpDown6.Value = 100;

            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }

        private void button42_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox6.SelectedItem.ToString().Substring(0, listBox6.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox8.Text = str33.Split('|')[0];

                                numericUpDown6.Value = Convert.ToInt32(str33.Split('|')[1]);
                            }
                            catch { }
                            listBox6.Enabled = false;
                            panel5.Enabled = false;

                            button38.Visible = true;
                            button39.Visible = true;
                            button40.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button38_Click(object sender, EventArgs e)
        {
            listBox6.Enabled = true;
            panel5.Enabled = true;

            button39.Visible = false;
            button38.Visible = false;
            button40.Visible = true;

            textBox8.Text = "";
            numericUpDown6.Value = 100;
        }

        private void button39_Click(object sender, EventArgs e)
        {
            if (textBox8.Text != "")
            {
                int g = listBox6.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox6.SelectedItem.ToString().Substring(0, listBox6.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\virez.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox8.Text.Replace("|", "/") + "|" + numericUpDown6.Value + "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\virez.akv", s, Encoding.UTF8);
                        button38_Click(null, null);
                        loadvirez();

                    }
                }
                catch { }
                c = 0;
                listBox6.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Название не может быть пустым!"); }
        }
        #endregion

        #region Дырка
        private void loaddirka()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                {
                    listBox7.BeginUpdate();
                    listBox7.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox7.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " мм." });
                        }

                    }
                    if (listBox7.Items.Count != 0)
                        listBox7.SelectedIndex = 0;
                    listBox7.EndUpdate();
                }
            }
            catch { listBox7.EndUpdate(); }
        }

        private void button50_Click(object sender, EventArgs e)
        {
            if (listBox7.SelectedIndex != listBox7.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox7.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox7.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox7.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dirka.akv", s, Encoding.UTF8);
                        loaddirka();
                    }
                }
                catch { }
                listBox7.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button51_Click(object sender, EventArgs e)
        {
            if (listBox7.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox7.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox7.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox7.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dirka.akv", s, Encoding.UTF8);
                        loaddirka();
                    }
                }
                catch { }
                listBox7.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button48_Click(object sender, EventArgs e)
        {
            int g = listBox7.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox7.SelectedItem.ToString().Substring(0, listBox7.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\dirka.akv", s, Encoding.UTF8);
                    listBox7.Items.RemoveAt(listBox7.SelectedIndex);
                    listBox7.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button53_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dataGridView1.Rows.Count;
                dataGridView1.Rows.Add();
                dataGridView1.Rows[i].Cells[0].Value = numericUpDown8.Value;
                dataGridView1.Rows[i].Cells[1].Value = numericUpDown9.Value;
                dataGridView1.Rows[i].Cells[2].Value = numericUpDown10.Value;
            }
            catch { }
        }

        private void button52_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null) return;
            dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
        }

        private void button47_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count != 0)
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += numericUpDown7.Value + "|";
                for (int h = 0; h < dataGridView1.Rows.Count; h++ )
                {
                    s += dataGridView1.Rows[h].Cells[0].Value + "-" + dataGridView1.Rows[h].Cells[1].Value + "-" + dataGridView1.Rows[h].Cells[2].Value + "~";
                }
                    s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\dirka.akv", s, Encoding.UTF8);
                loaddirka();

                numericUpDown7.Value = 100;
                numericUpDown8.Value = 100;
                numericUpDown9.Value = 100;
                dataGridView1.Rows.Clear();
                numericUpDown10.Value = 100;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }

        private void button49_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox7.SelectedItem.ToString().Substring(0, listBox7.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                numericUpDown7.Value = Convert.ToInt32(str33.Split('|')[0]);
                                dataGridView1.Rows.Clear();
                                     string[] bd2 =  str33.Split('|')[1].Split('~');
                                     foreach (string s in bd2)
                                     {
                                         if (s != "")
                                         {
                                             string[] f = s.Split('-');
                                             int i = dataGridView1.Rows.Count;
                                             dataGridView1.Rows.Add();
                                             for (int h = 0; h < 3; h++)
                                                 dataGridView1.Rows[i].Cells[h].Value = f[h];
                                         }
                                     }

                            }
                            catch { }
                            listBox7.Enabled = false;
                            panel6.Enabled = false;

                            button45.Visible = true;
                            button46.Visible = true;
                            button47.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button45_Click(object sender, EventArgs e)
        {
            listBox7.Enabled = true;
            panel6.Enabled = true;

            button45.Visible = false;
            button46.Visible = false;
            button47.Visible = true;

            numericUpDown7.Value = 100;
            numericUpDown8.Value = 100;
            numericUpDown9.Value = 100;
            numericUpDown10.Value = 100;
            dataGridView1.Rows.Clear();
        }

        private void button46_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count != 0)
            {
                int g = listBox7.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox7.SelectedItem.ToString().Substring(0, listBox7.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirka.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += numericUpDown7.Value + "|";
                                for (int h = 0; h < dataGridView1.Rows.Count; h++)
                                {
                                    s += dataGridView1.Rows[h].Cells[0].Value + "-" + dataGridView1.Rows[h].Cells[1].Value + "-" + dataGridView1.Rows[h].Cells[2].Value + "~";
                                }
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\dirka.akv", s, Encoding.UTF8);
                        button45_Click(null, null);
                        loaddirka() ;

                    }
                }
                catch { }
                c = 0;
                listBox7.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }
        #endregion

        #region Закаленная дырка
        private void loadzakdirka()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                {
                    listBox8.BeginUpdate();
                    listBox8.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox8.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0] + " мм." });
                        }

                    }
                    if (listBox8.Items.Count != 0)
                        listBox8.SelectedIndex = 0;
                    listBox8.EndUpdate();
                }
            }
            catch { listBox8.EndUpdate(); }
        }

        private void button61_Click(object sender, EventArgs e)
        {
            if (listBox8.SelectedIndex != listBox8.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox8.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox8.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox8.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dirkazak.akv", s, Encoding.UTF8);
                        loadzakdirka();
                    }
                }
                catch { }
                listBox8.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button62_Click(object sender, EventArgs e)
        {
            if (listBox8.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox8.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox8.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox8.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\dirkazak.akv", s, Encoding.UTF8);
                        loadzakdirka();
                    }
                }
                catch { }
                listBox8.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button59_Click(object sender, EventArgs e)
        {
            int g = listBox8.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox8.SelectedItem.ToString().Substring(0, listBox8.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\dirkazak.akv", s, Encoding.UTF8);
                    listBox8.Items.RemoveAt(listBox8.SelectedIndex);
                    listBox8.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button54_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dataGridView2.Rows.Count;
                dataGridView2.Rows.Add();
                dataGridView2.Rows[i].Cells[0].Value = numericUpDown13.Value;
                dataGridView2.Rows[i].Cells[1].Value = numericUpDown12.Value;
                dataGridView2.Rows[i].Cells[2].Value = numericUpDown11.Value;
            }
            catch { }
        }

        private void button55_Click(object sender, EventArgs e)
        {
            if (dataGridView2.CurrentRow == null) return;
            dataGridView2.Rows.RemoveAt(dataGridView2.CurrentRow.Index);
        }

        private void button58_Click(object sender, EventArgs e)
        {
            if (dataGridView2.Rows.Count != 0)
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += numericUpDown14.Value + "|";
                for (int h = 0; h < dataGridView2.Rows.Count; h++)
                {
                    s += dataGridView2.Rows[h].Cells[0].Value + "-" + dataGridView2.Rows[h].Cells[1].Value + "-" + dataGridView2.Rows[h].Cells[2].Value + "~";
                }
                s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\dirkazak.akv", s, Encoding.UTF8);
                loadzakdirka();

                numericUpDown11.Value = 100;
                numericUpDown12.Value = 100;
                numericUpDown13.Value = 100;
                dataGridView2.Rows.Clear();
                numericUpDown14.Value = 100;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }

        private void button60_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox8.SelectedItem.ToString().Substring(0, listBox8.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                numericUpDown14.Value = Convert.ToInt32(str33.Split('|')[0]);
                                dataGridView2.Rows.Clear();
                                string[] bd2 = str33.Split('|')[1].Split('~');
                                foreach (string s in bd2)
                                {
                                    if (s != "")
                                    {
                                        string[] f = s.Split('-');
                                        int i = dataGridView2.Rows.Count;
                                        dataGridView2.Rows.Add();
                                        for (int h = 0; h < 3; h++)
                                            dataGridView2.Rows[i].Cells[h].Value = f[h];
                                    }
                                }

                            }
                            catch { }
                            listBox8.Enabled = false;
                            panel7.Enabled = false;

                            button56.Visible = true;
                            button57.Visible = true;
                            button58.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button56_Click(object sender, EventArgs e)
        {
            listBox8.Enabled = true;
            panel7.Enabled = true;

            button56.Visible = false;
            button57.Visible = false;
            button58.Visible = true;

            numericUpDown11.Value = 100;
            numericUpDown12.Value = 100;
            numericUpDown13.Value = 100;
            numericUpDown14.Value = 100;
            dataGridView2.Rows.Clear();
        }

        private void button57_Click(object sender, EventArgs e)
        {
            if (dataGridView2.Rows.Count != 0)
            {
                int g = listBox8.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox8.SelectedItem.ToString().Substring(0, listBox8.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\dirkazak.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += numericUpDown14.Value + "|";
                                for (int h = 0; h < dataGridView2.Rows.Count; h++)
                                {
                                    s += dataGridView2.Rows[h].Cells[0].Value + "-" + dataGridView2.Rows[h].Cells[1].Value + "-" + dataGridView2.Rows[h].Cells[2].Value + "~";
                                }
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\dirkazak.akv", s, Encoding.UTF8);
                        button56_Click(null, null);
                        loadzakdirka();

                    }
                }
                catch { }
                c = 0;
                listBox8.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }
        #endregion

        #region Материалы
        private void loadmater()
        {
            int c = 0;
            string str33 = "";
            try
            {
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                {
                    listBox9.BeginUpdate();
                    listBox9.Items.Clear();
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if (str33 != "" && str33 != null)
                        {
                            c++;
                            string[] tmp = str33.Replace("\r", "").Split('|');
                            listBox9.Items.AddRange(new object[] { c.ToString() + ". " + tmp[0]  });
                        }

                    }
                    if (listBox9.Items.Count != 0)
                        listBox9.SelectedIndex = 0;
                    listBox9.EndUpdate();
                }
            }
            catch { listBox9.EndUpdate(); }
        }

        private void button70_Click(object sender, EventArgs e)
        {
            if (listBox9.SelectedIndex != listBox9.Items.Count - 1)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox9.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox9.SelectedIndex + 1)
                            {
                                down = str33;
                                s += "ВнИз\r\n";
                            }
                            else
                            {
                                if (c == listBox9.SelectedIndex)
                                {
                                    up = str33;
                                    s += "ВвЕрХ\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\material.akv", s, Encoding.UTF8);
                        loadmater();
                    }
                }
                catch { }
                listBox9.SelectedIndex = g + 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button71_Click(object sender, EventArgs e)
        {
            if (listBox9.SelectedIndex != 0)
            {
                int c = 0;
                string str33 = "";
                string s = "";
                string up = "";
                string down = "";
                int g = listBox9.SelectedIndex;
                try
                {
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if (c == listBox9.SelectedIndex - 1)
                            {
                                up = str33;
                                s += "ВвЕрХ\r\n";
                            }
                            else
                            {
                                if (c == listBox9.SelectedIndex)
                                {
                                    down = str33;
                                    s += "ВнИз\r\n";
                                }
                                else
                                {
                                    s += str33 + "\r\n";
                                }
                            }
                            c++;
                        }
                        sr.Close();
                        s = s.Replace("ВвЕрХ", down).Replace("ВнИз", up);
                        File.WriteAllText(putin + "\\data\\skinali\\material.akv", s, Encoding.UTF8);
                        loadmater();
                    }
                }
                catch { }
                listBox9.SelectedIndex = g - 1;
                c = 0;
                str33 = null;
                s = null;
                up = null;
                down = null;
                g = 0;
            }
        }

        private void button68_Click(object sender, EventArgs e)
        {
            int g = listBox9.SelectedIndex;
            int c = 0;
            string str33 = "";
            string s = "";
            try
            {
                string nom = listBox9.SelectedItem.ToString().Substring(0, listBox9.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() != nom)
                        {
                            s += str33 + "\r\n";
                        }
                        c++;
                    }
                    sr.Close();
                    File.WriteAllText(putin + "\\data\\skinali\\material.akv", s, Encoding.UTF8);
                    listBox9.Items.RemoveAt(listBox9.SelectedIndex);
                    listBox9.SelectedIndex -= 1;
                }
            }
            catch { }
            c = 0;
            str33 = null;
            s = null;
        }

        private void button63_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dataGridView3.Rows.Count;
                dataGridView3.Rows.Add();
                dataGridView3.Rows[i].Cells[0].Value = numericUpDown17.Value;
                dataGridView3.Rows[i].Cells[1].Value = numericUpDown16.Value;
                dataGridView3.Rows[i].Cells[2].Value = numericUpDown15.Value;
                dataGridView3.Rows[i].Cells[3].Value = numericUpDown18.Value;
                dataGridView3.Rows[i].Cells[4].Value = numericUpDown19.Value;
            }
            catch { }
        }

        private void button64_Click(object sender, EventArgs e)
        {
            if (dataGridView3.CurrentRow == null) return;
            dataGridView3.Rows.RemoveAt(dataGridView3.CurrentRow.Index);
        }

        private void button67_Click(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count != 0)
            {
                StreamReader Sr = new StreamReader(putin + "\\data\\skinali\\material.akv", Encoding.UTF8);
                string s = Sr.ReadToEnd();
                Sr.Close();
                Sr = null;

                s += textBox9.Text.Replace("|","/") + "|";
                for (int h = 0; h < dataGridView3.Rows.Count; h++)
                {
                    s += dataGridView3.Rows[h].Cells[0].Value + "!" + dataGridView3.Rows[h].Cells[1].Value + "!" + dataGridView3.Rows[h].Cells[2].Value +"!"+ dataGridView3.Rows[h].Cells[3].Value +"!" + dataGridView3.Rows[h].Cells[4].Value+"~";
                }
                s += "\r\n";

                File.WriteAllText(putin + "\\data\\skinali\\material.akv", s, Encoding.UTF8);
                loadmater();

                numericUpDown17.Value = 100;
                numericUpDown16.Value = 100;
                numericUpDown15.Value = 100;
                numericUpDown19.Value = 100;
                dataGridView3.Rows.Clear();
                numericUpDown18.Value = 100;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }

        private void button69_Click(object sender, EventArgs e)
        {
            int c = 0;
            string str33 = "";
            try
            {
                string nom = listBox9.SelectedItem.ToString().Substring(0, listBox9.SelectedItem.ToString().IndexOf("."));
                using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                {
                    while ((str33 = sr.ReadLine()) != null)
                    {
                        if ((c + 1).ToString() == nom)
                        {
                            try
                            {
                                textBox9.Text =str33.Split('|')[0];
                                dataGridView3.Rows.Clear();
                                string[] bd2 = str33.Split('|')[1].Split('~');
                                foreach (string s in bd2)
                                {
                                    if (s != "")
                                    {
                                        string[] f = s.Split('!');
                                        int i = dataGridView3.Rows.Count;
                                        dataGridView3.Rows.Add();
                                        for (int h = 0; h < 5; h++)
                                            dataGridView3.Rows[i].Cells[h].Value = f[h];
                                    }
                                }

                            }
                            catch { }
                            listBox9.Enabled = false;
                            panel9.Enabled = false;

                            button66.Visible = true;
                            button65.Visible = true;
                            button67.Visible = false;
                            break;
                        }
                        c++;
                    }
                    sr.Close();
                }
            }
            catch { }
            c = 0;
            str33 = null;
        }

        private void button65_Click(object sender, EventArgs e)
        {
            listBox9.Enabled = true;
            panel9.Enabled = true;

            button65.Visible = false;
            button66.Visible = false;
            button67.Visible = true;

            numericUpDown17.Value = 100;
            numericUpDown16.Value = 100;
            numericUpDown15.Value = 100;
            numericUpDown18.Value = 100;
            numericUpDown19.Value = 100;
            dataGridView3.Rows.Clear();
            textBox9.Text = "";
        }

        private void button66_Click(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count != 0)
            {
                int g = listBox9.SelectedIndex;
                int c = 0;
                string str33 = "";
                string s = "";
                try
                {
                    string nom = listBox9.SelectedItem.ToString().Substring(0, listBox9.SelectedItem.ToString().IndexOf("."));
                    using (StreamReader sr = new StreamReader(putin + "\\data\\skinali\\material.akv"))
                    {
                        while ((str33 = sr.ReadLine()) != null)
                        {
                            if ((c + 1).ToString() != nom)
                            {
                                s += str33 + "\r\n";
                            }
                            else
                            {
                                s += textBox9.Text.Replace("|", "/") + "|";
                                for (int h = 0; h < dataGridView3.Rows.Count; h++)
                                {
                                    s += dataGridView3.Rows[h].Cells[0].Value + "!" + dataGridView3.Rows[h].Cells[1].Value + "!" + dataGridView3.Rows[h].Cells[2].Value + "!" + dataGridView3.Rows[h].Cells[3].Value + "!" + dataGridView3.Rows[h].Cells[4].Value + "~";
                                }
                                s += "\r\n";
                            }
                            c++;
                        }
                        sr.Close();
                        File.WriteAllText(putin + "\\data\\skinali\\material.akv", s, Encoding.UTF8);
                        button65_Click(null, null);
                        loadmater();

                    }
                }
                catch { }
                c = 0;
                listBox9.SelectedIndex = g;
                str33 = null;
                s = null;
            }
            else { MessageBox.Show("Ценообразование не может быть пустым!"); }
        }

        #endregion

        private void button74_Click(object sender, EventArgs e)
        {
            try
            {
                int i = dataGridView5.Rows.Count;
                dataGridView5.Rows.Add();
                dataGridView5.Rows[i].Cells[0].Value = numericUpDown4.Value;
                dataGridView5.Rows[i].Cells[1].Value = numericUpDown3.Value;
            }
            catch { }
        }

        private void button75_Click(object sender, EventArgs e)
        {
            if (dataGridView5.CurrentRow == null) return;
            dataGridView5.Rows.RemoveAt(dataGridView5.CurrentRow.Index);
        }

    }
}
