コード例 #1
0
        public void GetStoreInfo()
        {
            string sqlExpression = "SELECT store_name, store_logo FROM store WHERE store_id = '" + CustBag.storeSelected + "'";

            using (SqlConnection connection = new SqlConnection(SignIn.connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);

                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            storeName = reader.GetValue(0).ToString();
                        }

                        if (!reader.IsDBNull(1))
                        {
                            storeLogo         = (byte[])reader.GetValue(1);
                            logoPreview.Image = MainShop.ByteArrayToImage(storeLogo);
                        }
                    }
                }

                connection.Close();
            }
        }
コード例 #2
0
        public void GetPhoto()
        {
            string sqlExpression = "SELECT product_photo FROM product WHERE product_id = '" + CustBag.prodSelected + "'";

            using (SqlConnection connection = new SqlConnection(SignIn.connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);

                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            Byte[] photo = (byte[])reader.GetValue(0);
                            prodPic.Image = MainShop.ByteArrayToImage(photo);
                        }
                    }
                }

                connection.Close();
            }
        }
コード例 #3
0
        public void GetDataForGrid()
        {
            for (int m = 0; m < numOfRows; m++)
            {
                if (m != numOfRows - 1)
                {
                    temp += id[m] + ", ";
                }
                else
                {
                    temp += id[m];
                }
            }

            string sqlExpression =
                "SELECT DISTINCT dbo.product.product_code, dbo.product.product_name, dbo.product.product_info, " +
                "dbo.gender.gender_name, dbo.category.category_name, dbo.subcategory.subcategory_name, " +
                "dbo.product.product_photo, dbo.price.product_price, dbo.store.store_id, dbo.product.product_id " +
                "FROM dbo.product INNER JOIN " +
                "dbo.category_gender ON dbo.product.category_gender_id = dbo.category_gender.category_gender_id INNER JOIN " +
                "dbo.cat_subcategory ON dbo.category_gender.cat_subcat_id = dbo.cat_subcategory.cat_subcat_id INNER JOIN " +
                "dbo.category ON dbo.cat_subcategory.category_id = dbo.category.category_id INNER JOIN " +
                "dbo.subcategory ON dbo.cat_subcategory.subcategory_id = dbo.subcategory.subcategory_id INNER JOIN " +
                "dbo.gender ON dbo.category_gender.gender_id = dbo.gender.gender_id INNER JOIN " +
                "dbo.product_size ON dbo.product_size.product_id = dbo.product.product_id INNER JOIN " +
                "dbo.product_address ON dbo.product_address.product_size_id = dbo.product_size.product_size_id INNER JOIN " +
                "dbo.price ON dbo.price.product_id = dbo.product.product_id INNER JOIN " +
                "dbo.store_address ON dbo.store_address.store_address_id = dbo.product_address.store_address_id INNER JOIN " +
                "dbo.store ON dbo.store_address.store_id = dbo.store.store_id " +
                "WHERE (dbo.product.product_id IN (" + temp + ")) AND dbo.price.product_price IN " +
                "(SELECT product_price FROM price " +
                "WHERE version_date IN (SELECT MAX(version_date) FROM price GROUP BY product_id))" + extendSql + "";

            prodInfo = new string[numOfRows, 9];
            picArray = new List <Image>();

            int i = 0;

            using (SqlConnection connection = new SqlConnection(SignIn.connectionString))
            {
                connection.Open();

                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        prodInfo[i, 0] = reader.GetValue(0).ToString();
                        prodInfo[i, 1] = reader.GetValue(1).ToString();
                        prodInfo[i, 2] = reader.GetValue(2).ToString();
                        prodInfo[i, 3] = reader.GetValue(3).ToString();
                        prodInfo[i, 4] = reader.GetValue(4).ToString();
                        prodInfo[i, 5] = reader.GetValue(5).ToString();
                        prodInfo[i, 6] = reader.GetValue(7).ToString();
                        prodInfo[i, 7] = reader.GetValue(8).ToString();
                        prodInfo[i, 8] = reader.GetValue(9).ToString();

                        if (!reader.IsDBNull(6))
                        {
                            prodPicByte = (byte[])reader.GetValue(6);
                            picArray.Add(MainShop.ByteArrayToImage(prodPicByte));
                        }

                        i++;
                    }
                }
                reader.Close();
                connection.Close();
            }
        }
コード例 #4
0
        private void LogInButton_Click(object sender, EventArgs e)

        {
            if (tbPhoneLog.Text.Length == 0)
            {
                MessageBox.Show("Введите номер телефона!");
            }
            else if (tbPasswordLog.Text.Length == 0 || tbPasswordLog.Text == "Пароль")
            {
                MessageBox.Show("Введите пароль!");
            }
            else
            {
                userLogin = tbPhoneLog.Text;
                userPW    = tbPasswordLog.Text;

                // запрос для поиска логина и пароля пользователя
                string sqlExpression = "SELECT cust_id, cust_phone AS phone, cust_password AS pw, " +
                                       "cust_role AS role, cust_name AS name FROM customer WHERE cust_phone = '"
                                       + userLogin + "' AND cust_password = '******' UNION ALL SELECT store_id, " +
                                       "store_code AS phone, store_password AS pw, store_role AS role, store_name AS name" +
                                       " FROM store WHERE store_code = '" + userLogin + "' AND store_password = '******'";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    // подключение к базе
                    connection.Open();
                    SqlCommand    command = new SqlCommand(sqlExpression, connection);
                    SqlDataReader reader  = command.ExecuteReader();

                    // условие, что запрос не пустой
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string role = reader.GetValue(3).ToString();
                            userName = reader.GetValue(4).ToString();

                            userID = Convert.ToInt32(reader.GetValue(0));

                            if (role == "Продавец")
                            {
                                MessageBox.Show("Вы вошли в свой аккаунт, " + userName);

                                MainShop MainShop = new MainShop();
                                MainShop.Show();
                            }
                            else if (role == "Покупатель")
                            {
                                MessageBox.Show("Вы вошли в свой аккаунт, " + userName);

                                MainCust MainCust = new MainCust();
                                MainCust.Show();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неверный логин или пароль.");
                        this.Height          = 200; // изменение размера формы
                        tbGoToSignIn.Visible = true;
                    }
                    // закрытие подключения
                    connection.Close();
                    reader.Close();
                }
            }
        }