コード例 #1
0
        //Выход с формы
        private void pictureBoxExit_Click(object sender, EventArgs e)
        {
            var fWarehouseman = new FormWarehouseman();

            fWarehouseman.Show();
            Hide();
        }
コード例 #2
0
        //Выход из формы
        private void pictureBoxExit_Click(object sender, EventArgs e)
        {
            switch (whoEnter)
            {
            case "Edit":
            {
                var fWarehouseman = new FormWarehouseman();
                fWarehouseman.Show();
                Hide();
            }; break;

            default: { Hide(); }; break;
            }
        }
コード例 #3
0
        //Авторизация
        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (AllValid())
            {
                var loginInfo = (from user in ClassGetContext.context.Users
                                 join worker in ClassGetContext.context.Workers on user.idWorker equals worker.idWorker
                                 where user.login == tbLogin.Text && user.password == tbPassword.Text
                                 select new { worker.position, worker.idWorker }).FirstOrDefault();

                if (loginInfo != null)
                {
                    ClassActiveUser.WorkerId = loginInfo.idWorker;

                    switch (loginInfo.position)
                    {
                    case "Продавец-консультант":
                    {
                        var formSales = new FormSales();
                        formSales.Show();
                        break;
                    }

                    case "Кладовщик":
                    {
                        var formWarehouseman = new FormWarehouseman();
                        formWarehouseman.Show();
                        break;
                    }
                    }
                    Hide();
                }
                else
                {
                    MessageBox.Show("Такого пользователя не существует, проверьте введенные вами данные");
                }
            }
            else
            {
                MessageBox.Show("Не все данные введены");
            }
        }
コード例 #4
0
        //Изменение информации о книге
        private void btnEditBook_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(tbNameBook.Text) && !string.IsNullOrWhiteSpace(tbYearOfPublishing.Text) &&
                !string.IsNullOrWhiteSpace(tbISBN.Text) && !string.IsNullOrWhiteSpace(cbAgeLimit.Text) &&
                !string.IsNullOrWhiteSpace(cbCoverType.Text) && !string.IsNullOrWhiteSpace(richTextBoxDescription.Text) &&
                !string.IsNullOrWhiteSpace(cbPublishing.Text) && numericUpDownPageCount.Value > 0 &&
                tableAuthor.RowCount > 0 && tableGenre.RowCount > 0)
            {
                using (SqlConnection connection = ClassConnection.SqlConnection())
                {
                    connection.Open();

                    SqlCommand commandUpdate = new SqlCommand(@"UPDATE [Book]
                    SET Book.name = @nameBook, Book.yearOfPublishing = @yearOfPublishing, 
                    Book.pageCount = @pageCount, Book.ageLimit = @ageLimit,
                    Book.ISBN = @ISBN, Book.cover = @cover, Book.coverType = @coverType,
                    Book.description = @description, Book.idPublishing = @idPublishing              
                    WHERE Book.idBook = '" + idBook + "'", connection);

                    commandUpdate.Parameters.AddWithValue("@nameBook", tbNameBook.Text);
                    commandUpdate.Parameters.AddWithValue("@yearOfPublishing", Convert.ToInt32(tbYearOfPublishing.Text));
                    commandUpdate.Parameters.AddWithValue("@pageCount", Convert.ToInt32(numericUpDownPageCount.Value));
                    commandUpdate.Parameters.AddWithValue("@ageLimit", cbAgeLimit.Text);
                    commandUpdate.Parameters.AddWithValue("@ISBN", tbISBN.Text);
                    commandUpdate.Parameters.AddWithValue("@cover", newPath);
                    commandUpdate.Parameters.AddWithValue("@coverType", cbCoverType.Text);
                    commandUpdate.Parameters.AddWithValue("@description", richTextBoxDescription.Text);
                    commandUpdate.Parameters.AddWithValue("@idPublishing", cbPublishing.SelectedValue);

                    commandUpdate.ExecuteNonQuery();

                    SqlCommand commDeleteGenre = new SqlCommand(@"DELETE FROM [BookGenre] WHERE idBook = " + idBook + "", connection);
                    commDeleteGenre.ExecuteNonQuery();

                    SqlCommand commDeleteAuthor = new SqlCommand(@"DELETE FROM [BookAuthor] WHERE idBook = " + idBook + "", connection);
                    commDeleteAuthor.ExecuteNonQuery();

                    foreach (DataGridViewRow row in tableGenre.Rows)
                    {
                        SqlCommand commInsertGenre = new SqlCommand(@"INSERT INTO [BookGenre] 
                        (idBook, idGenre) VALUES (" + idBook + ", " + Convert.ToInt32(row.Cells[0].Value) + ")", connection);
                        commInsertGenre.ExecuteNonQuery();
                    }
                    foreach (DataGridViewRow row in tableAuthor.Rows)
                    {
                        SqlCommand commInsertAuthor = new SqlCommand(@"INSERT INTO [BookAuthor] 
                        (idBook, idAuthor) VALUES (" + idBook + ", " + Convert.ToInt32(row.Cells[0].Value) + ")", connection);
                        commInsertAuthor.ExecuteNonQuery();
                    }

                    MessageBox.Show("Информация о книге успешно изменена!");
                    var fWarehouseman = new FormWarehouseman();
                    fWarehouseman.Show();
                    Hide();
                }
            }
            else
            {
                MessageBox.Show("Не все поля заполены!");
            }
        }