Пример #1
0
        public void LoadAccessouries()
        {
            DBLists.AccessouriesList = new List <Accessouries>();
            DBBuf.AccessouriesBuf    = new Accessouries();
            SqlConnection connection = new SqlConnection(Connection.connectionString);

            try
            {
                connection.Open();

                ImageList imageList = new ImageList();
                imageList.ImageSize = new Size(60, 50);
                Bitmap emptyImage = new Bitmap(60, 50);
                using (Graphics gr = Graphics.FromImage(emptyImage))
                {
                    gr.Clear(Color.White);
                }
                listViewAccessouries.SmallImageList = imageList;

                SqlCommand command = new SqlCommand();
                command.CommandText = "SELECT * FROM Accessories";
                command.Connection  = connection;
                SqlDataReader reader = command.ExecuteReader();
                int           i      = 0;
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        long   id        = reader.GetInt64(0);
                        string Type      = reader.GetString(1);
                        string Position  = reader.GetString(2);
                        long   Amount    = reader.GetInt64(3);
                        long   Cost      = reader.GetInt64(4);
                        string ImagePath = reader.GetString(5);

                        if (ImagePath != "" && ImagePath != "-")
                        {
                            imageList.Images.Add(new Bitmap(ImagePath));
                        }
                        else
                        {
                            imageList.Images.Add(emptyImage);
                        }

                        Accessouries Element      = new Accessouries(id, Type, Position, Amount, Cost, ImagePath);
                        string[]     Accessouries = { "", Type, Position, Convert.ToString(Cost), Convert.ToString(Amount) };

                        ListViewItem lvi = new ListViewItem(Accessouries);
                        lvi.ImageIndex = i;
                        i++;
                        DBLists.AccessouriesList.Add(Element);
                        listViewAccessouries.Items.Add(lvi);
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        public void LoadRecommendedAccessories()
        {
            SqlConnection connection = new SqlConnection(Connection.connectionString);

            try
            {
                connection.Open();

                ImageList imageList = new ImageList();
                imageList.ImageSize = new Size(60, 50);
                Bitmap emptyImage = new Bitmap(60, 50);
                using (Graphics gr = Graphics.FromImage(emptyImage))
                {
                    gr.Clear(Color.White);
                }
                listViewRecommended.SmallImageList = imageList;

                SqlCommand command = new SqlCommand();
                if (DBBuf.ClothesTypeBuf.Purpose == "Рубашка")
                {
                    command.CommandText = "SELECT * FROM Accessories WHERE Type != 'Пиджачный воротник' AND Position = 'Воротник' OR " +
                                          "Position = 'Рукава' OR Position = 'Грудь' OR Type = 'Пуговицы'";
                }
                else if (DBBuf.ClothesTypeBuf.Purpose == "Пиджак")
                {
                    command.CommandText = "SELECT * FROM Accessories WHERE Type = 'Пиджачный воротник' OR " +
                                          "Position = 'Рукава' OR Type LIKE '%карман%' OR Type = 'Пуговицы'";
                }
                else if (DBBuf.ClothesTypeBuf.Purpose == "Жилет")
                {
                    command.CommandText = "SELECT * FROM Accessories WHERE Position = 'Воротник' OR " +
                                          "Type LIKE '%карман%' OR Type = 'Пуговицы' OR Type = 'Крючки'";
                }
                else if (DBBuf.ClothesTypeBuf.Purpose == "Брюки")
                {
                    command.CommandText = "SELECT * FROM Accessories WHERE Position = 'Левый бок' OR Position = 'Правый бок' OR " +
                                          "Type = 'Пуговицы' OR Type = 'Молния'";
                }
                else
                {
                    command.CommandText = "SELECT * FROM Accessories WHERE Type = 'Пуговицы' OR Type = 'Молния'";
                }

                command.Connection = connection;
                DBLists.AccessouriesListSupport = new List <Accessouries>();

                SqlDataReader reader = command.ExecuteReader();
                int           i      = 0;
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        long   Id          = reader.GetInt64(0);
                        string Type        = reader.GetString(1);
                        string Position    = reader.GetString(2);
                        long   Amount      = reader.GetInt64(3);
                        long   CostPerUnit = reader.GetInt64(4);
                        string ImagePath   = reader.GetString(5);

                        if (ImagePath != "" && ImagePath != "-")
                        {
                            imageList.Images.Add(new Bitmap(ImagePath));
                        }
                        else
                        {
                            imageList.Images.Add(emptyImage);
                        }

                        Accessouries Element     = new Accessouries(Id, Type, Position, Amount, CostPerUnit, ImagePath);
                        string[]     Accessories =
                        { "", Type, Convert.ToString(Position), Convert.ToString(Amount), Convert.ToString(CostPerUnit) };
                        ListViewItem lvi = new ListViewItem(Accessories);
                        lvi.ImageIndex = i;
                        i++;
                        listViewRecommended.Items.Add(lvi);

                        DBLists.AccessouriesListSupport.Add(Element);
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        public void AddChangeAccessorie()
        {
            SqlConnection connection = new SqlConnection(Connection.connectionString);

            try
            {
                SqlCommand command = new SqlCommand();
                connection.Open();
                command.Connection = connection;

                if (listViewAccessouries.SelectedIndices.Count == 1)
                {
                    long index = listViewAccessouries.Items.IndexOf(listViewAccessouries.SelectedItems[0]);
                    index = DBLists.AccessouriesList[Convert.ToInt32(index)].Id;
                    DBBuf.AccessouriesBuf.Id = index;
                    Accessouries SupportAccessourie = new Accessouries();
                    SqlParameter commandParameter;

                    command.CommandText =
                        "UPDATE Accessories SET Type=@type, Position=@position, Amount=@amount, Cost_per_unit=@cost, " +
                        "ImagePath=@image WHERE ID=@id";


                    foreach (Accessouries Element in DBLists.AccessouriesList)
                    {
                        if (Element.Id == index)
                        {
                            SupportAccessourie = new Accessouries(Element.Id, Element.Type, Element.Position,
                                                                  Element.Amount, Element.CostPerUnit, Element.ImagePath);
                        }
                    }

                    if (textBoxType.Text != "")
                    {
                        commandParameter = new SqlParameter("type", textBoxType.Text);
                        command.Parameters.Add(commandParameter);
                    }
                    else
                    {
                        commandParameter = new SqlParameter("type", SupportAccessourie.Type);
                        command.Parameters.Add(commandParameter);
                    }

                    if (textBoxPosition.Text != "")
                    {
                        commandParameter = new SqlParameter("position", textBoxPosition.Text);
                        command.Parameters.Add(commandParameter);
                    }
                    else
                    {
                        commandParameter = new SqlParameter("position", SupportAccessourie.Position);
                        command.Parameters.Add(commandParameter);
                    }

                    if (textBoxAmount.Text != "")
                    {
                        long amount = Convert.ToInt64(textBoxAmount.Text);
                        commandParameter = new SqlParameter("amount", Convert.ToInt64(textBoxAmount.Text));
                        command.Parameters.Add(commandParameter);
                    }
                    else
                    {
                        commandParameter = new SqlParameter("amount", SupportAccessourie.Amount);
                        command.Parameters.Add(commandParameter);
                    }

                    if (textBoxCost.Text != "")
                    {
                        long cost = Convert.ToInt64(textBoxCost.Text);
                        commandParameter = new SqlParameter("cost", Convert.ToInt64(textBoxCost.Text));
                        command.Parameters.Add(commandParameter);
                    }
                    else
                    {
                        commandParameter = new SqlParameter("cost", SupportAccessourie.CostPerUnit);
                        command.Parameters.Add(commandParameter);
                    }

                    if (DBBuf.AccessouriesBuf.ImagePath != "")
                    {
                        commandParameter = new SqlParameter("image", DBBuf.AccessouriesBuf.ImagePath);
                        command.Parameters.Add(commandParameter);
                    }
                    else
                    {
                        commandParameter = new SqlParameter("image", SupportAccessourie.ImagePath);
                        command.Parameters.Add(commandParameter);
                    }

                    command.Parameters.Add(new SqlParameter("id", DBBuf.AccessouriesBuf.Id));
                }
                else
                {
                    long amount = Convert.ToInt64(textBoxAmount.Text);
                    long cost   = Convert.ToInt32(textBoxCost.Text);
                    command.CommandText =
                        "INSERT INTO Accessories (Type, Position, Amount, Cost_per_unit, ImagePath) " +
                        "VALUES (@type, @position, @amount, @cost, @imagePath)";
                    SqlParameter AccessoriesType = new SqlParameter("@type", textBoxType.Text);
                    command.Parameters.Add(AccessoriesType);
                    SqlParameter AccessoriesPosition = new SqlParameter("@position", textBoxPosition.Text);
                    command.Parameters.Add(AccessoriesPosition);
                    SqlParameter AccessoriesAmount = new SqlParameter("@amount", Convert.ToInt64(textBoxAmount.Text));
                    command.Parameters.Add(AccessoriesAmount);
                    SqlParameter AccessoriesCost = new SqlParameter("@cost", Convert.ToInt64(textBoxCost.Text));
                    command.Parameters.Add(AccessoriesCost);

                    if (DBBuf.AccessouriesBuf.ImagePath == "")
                    {
                        SqlParameter AccessoriesImage = new SqlParameter("@imagePath", "-");
                        command.Parameters.Add(AccessoriesImage);
                    }
                    else
                    {
                        SqlParameter AccessoriesImage = new SqlParameter("@imagePath", DBBuf.AccessouriesBuf.ImagePath);
                        command.Parameters.Add(AccessoriesImage);
                    }
                }

                command.ExecuteReader();
                listViewAccessouries.Items.Clear();
                LoadAccessouries();
            }
            catch (SqlException)
            {
                MessageBox.Show("Заполните все поля.", "", MessageBoxButtons.OK);
            }
            catch (FormatException)
            {
                MessageBox.Show("Введите целое число.", "", MessageBoxButtons.OK);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Заполните хотя бы одно поле.", "", MessageBoxButtons.OK);
            }
        }