public Parametr_Window(StructOfProduct person) :
            base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            Initialize(person);
        }
        protected void OnTreeviewAllProductCursorChanged(object sender, EventArgs e)
        {
            TreePath[] f = treeview_AllProduct.Selection.GetSelectedRows();

            _SelectProduct = _AllProduct [f [0].Indices [0]];
            SetGotStructOfPruduct(_AllProduct[f [0].Indices[0]]);
        }
        public bool Write_newProduct(StructOfProduct product)
        {
            bool resalt = true;

            try
            {
                // WHITOUT COUNT BECAUSE COUNT 0 BY START CONFIG IN DB
                command.CommandType = CommandType.Text;
                command.CommandText = "INSERT INTO product_t(code ,id_producer ,name_product , id_type_counter ,price_for_one ,parametr ,parametr_value ,count_value )" +
                                      " VALUES('" + product.Number + "','" + product.Id_producer + "','" + product.Name + "','" + product.Id_typeCount + "','" + product.PriceForOne + "','" + product.Parametr + "','" + product.ValueParametr + "','" + 0 + "')";

                connection.Open();

                command.ExecuteNonQuery();
            }
            catch (Exception)
            {
                resalt = false;
            }

            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(resalt);
        }
        private void AddNewItemToDeletelist(StructOfProduct productsList)
        {
            _DataForDelete.Add(productsList);
            _ForDelete.Clear();

            for (int i = 0; i < _DataForDelete.Count; i++)
            {
                _ForDelete.AppendValues(_DataForDelete [i].Number, _DataForDelete [i].Name, _DataForDelete [i].TypeCount, _DataForDelete [i].Count.ToString());
            }
        }
 private void Initialize(StructOfProduct person)
 {
     tb_Code.Text          = person.Number;
     tb_Name.Text          = person.Name;
     tb_Producer.Text      = person.Produser;
     tb_Parametr.Text      = person.Parametr;
     tb_ParametrValue.Text = person.ValueParametr;
     tb_TypeCount.Text     = person.TypeCount;
     tb_Count.Text         = person.Count.ToString();
     tb_PriceForOne.Text   = person.PriceForOne;
 }
 private void SetGotStructOfPruduct(StructOfProduct product)
 {
     try
     {
         tb_Name_ForInsert.Text = product.Name;
         tb_Code_ForInsert.Text = product.Number;
     }
     catch
     {
     }
 }
        private void SetDataForDelete(StructOfProduct productsList)
        {
            Validation validation = new Validation();

            if (!validation.ExistInList(_DataForDelete, productsList))
            {
                AddNewItemToDeletelist(productsList);
            }
            else
            {
                MessageBox.Show("Товар с таким нонером уже есть в списке");
            }
        }
        public Change_Window(List <StructOfProduct> allProducts, StructOfProduct selectProduct, string nameDataBase, Bufer bufer) :
            base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            _AllProduct    = allProducts;
            _SelectProduct = selectProduct;

            buf = bufer;

            Initialize(nameDataBase);

            SetGotStructOfPruduct(selectProduct);
        }
        public bool ExistInList(List <StructOfProduct> productsList, StructOfProduct lineForInsert)
        {
            bool ansver = false;

            foreach (StructOfProduct product in productsList)
            {
                if (product.Number == lineForInsert.Number)
                {
                    ansver = true;
                }
            }

            return(ansver);
        }
        // PRODUCT TABLE
        private StructOfProduct Get_Product(int id_labe)
        {
            StructOfProduct product = new StructOfProduct();
            int             id_1    = 0;
            int             id_2    = 0;


            try
            {
                command.CommandText = "SELECT * FROM product_t WHERE id_product=" + id_labe + "";
                command.CommandType = CommandType.Text;

                connection.Open();

                NpgsqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    product.ID     = Convert.ToInt32(reader["id_product"].ToString());
                    product.Number = reader["code"].ToString();
                    product.Name   = reader["name_product"].ToString();

                    id_1 = Convert.ToInt32(reader["id_producer"].ToString());
                    id_2 = Convert.ToInt32(reader["id_type_counter"].ToString());

                    product.PriceForOne   = reader["price_for_one"].ToString();
                    product.Parametr      = reader["parametr"].ToString();
                    product.ValueParametr = reader["parametr_value"].ToString();
                    product.Count         = Convert.ToInt32(reader["count_value"].ToString());
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            product.Produser  = Get_ProducerByID(id_1);
            product.TypeCount = Get_TypeOfCount_ByID(id_2);

            return(product);
        }
        //ACTIONS

        protected void OnBnAddItemClicked(object sender, EventArgs e)
        {
            Validation validation = new Validation();

            if (!validation.IsEmpty(tb_CodeProduct.Text) && !validation.IsEmpty(tb_CodeProduct.Text) && !validation.IsEmpty(tb_Producer.Text) &&
                !validation.IsEmpty(tb_TypeCounting.Text) && !validation.IsEmpty(tb_PriceForOne.Text) && !validation.IsEmpty(tb_ParametrProduct.Text) &&
                !validation.IsEmpty(tb_ParametrValue.Text))
            {
                if (!validation.ExistInList(_ExistProduct, tb_CodeProduct.Text))
                {
                    WriteTo_DB writer = new WriteTo_DB(nameDB, buf);

                    StructOfProduct product = new StructOfProduct();

                    product.Number        = tb_CodeProduct.Text;
                    product.Name          = tb_NameProduct.Text;
                    product.Id_producer   = writer.Get_Or_Set_IdOfProducer(tb_Producer.Text);
                    product.Id_typeCount  = writer.Get_Or_Set_IdOfTypeCount(tb_TypeCounting.Text);
                    product.Parametr      = tb_ParametrProduct.Text;
                    product.ValueParametr = tb_ParametrValue.Text;
                    product.PriceForOne   = tb_PriceForOne.Text;

                    if (writer.Write_newProduct(product))
                    {
                        MessageBox.Show("Товар успешно добавлен");
                    }
                    else
                    {
                        MessageBox.Show("повторите попытку");
                    }
                }
                else
                {
                    MessageBox.Show("Товар с таким номером уже есть");
                }
            }
            else
            {
                MessageBox.Show("Не все поля заполнены. Заполните и повторите попытку");
            }
        }
        public List <StructOfProduct> Search(string filtr, ParametrFiltr param)
        {
            List <StructOfProduct> products = new List <StructOfProduct> ();

            try
            {
                switch (param)
                {
                case ParametrFiltr.Code:
                    command.CommandText = "SELECT * FROM product_t WHERE code LIKE '%" + filtr + "%'";
                    break;

                case ParametrFiltr.ProductName:
                    command.CommandText = "SELECT * FROM product_t WHERE name_product LIKE '%" + filtr + "%'";
                    break;

                case ParametrFiltr.Parametr:
                    command.CommandText = "SELECT * FROM product_t WHERE parametr LIKE '%" + filtr + "%'";
                    break;

                default:
                    command.CommandText = "SELECT * FROM product_t";
                    break;
                }

                command.CommandType = CommandType.Text;

                connection.Open();

                NpgsqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    StructOfProduct product = new StructOfProduct();

                    product.ID     = Convert.ToInt32(reader["id_product"].ToString());
                    product.Number = reader["code"].ToString();
                    product.Name   = reader["name_product"].ToString();

                    product.Id_producer  = Convert.ToInt32(reader["id_producer"].ToString());
                    product.Id_typeCount = Convert.ToInt32(reader["id_type_counter"].ToString());

                    product.PriceForOne   = reader["price_for_one"].ToString();
                    product.Parametr      = reader["parametr"].ToString();
                    product.ValueParametr = reader["parametr_value"].ToString();
                    product.Count         = Convert.ToInt32(reader["count_value"].ToString());

                    products.Add(product);
                }
            }

            catch
            {
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            foreach (StructOfProduct product in products)
            {
                product.Produser  = Get_ProducerByID(product.Id_producer);
                product.TypeCount = Get_TypeOfCount_ByID(product.Id_typeCount);
            }



            return(products);
        }