コード例 #1
0
ファイル: UpdateProduct.cs プロジェクト: gabsw/ecommerce
        private String getCategoryCode(String category_str)
        {
            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();
                if (con.State == ConnectionState.Open)
                {
                    SqlCommand cm1 = new SqlCommand("SELECT Code FROM ecommerce.PRODUCT_CATEGORY " +
                                                    "WHERE Name = @Name", con);
                    cm1.Parameters.Add("@Name", SqlDbType.VarChar).Value = category_str;
                    SqlDataReader rd1 = cm1.ExecuteReader();
                    rd1.Read();
                    return(rd1["Code"].ToString());
                }
                FormValidation.showError("Category cannot be empty.");
                return("");
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
                return("");
            }
            finally
            {
                con.Close();
            }
        }
コード例 #2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            String delivery_company = deliveryBox.Text;
            String seller_address   = sellerAdBox.Text;
            String buyer_address    = buyerAdBox.Text;

            DateTime dispatchDate;
            DateTime estimatedArrivalDate;

            try
            {
                dispatchDate         = Convert.ToDateTime(dispatch_date_dtp.Text);
                estimatedArrivalDate = get_Estimated_Arrival_Date(dispatchDate, hasExpressDelivery);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The dispatch date has formatting issues.");
                return;
            }


            if (!FormValidation.validateShipping(purchaseID, delivery_company, seller_address, buyer_address,
                                                 dispatchDate, estimatedArrivalDate))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd = new SqlCommand("ecommerce.sp_Create_Shipping", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@deliveryCompany", delivery_company);
                cmd.Parameters.AddWithValue("@dispatchDate", dispatchDate);
                cmd.Parameters.AddWithValue("@estimatedArrivalDate", estimatedArrivalDate);
                cmd.Parameters.AddWithValue("@purchaseID", purchaseID);
                cmd.Parameters.AddWithValue("@dispatch_address", seller_address);
                cmd.Parameters.AddWithValue("@delivery_address", buyer_address);
                cmd.ExecuteNonQuery();

                MessageBox.Show("You have ordered a new shipping!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #3
0
ファイル: UpdateDeliveryComp.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, EventArgs e)
        {
            String  name    = nameLabel.Text;
            String  phone   = PhoneBox.Text;
            String  address = AddressBox.Text;
            Boolean hasExpressDelivery;

            if (YesButton.Checked)
            {
                hasExpressDelivery = true;
            }

            else if (NoButton.Checked)
            {
                hasExpressDelivery = false;
            }

            else
            {
                FormValidation.showError("You have to check if the company provides express delivery.");
                return;
            }


            if (!FormValidation.validateDeliveryCompany(name, phone, address, hasExpressDelivery))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd1 = new SqlCommand("ecommerce.sp_Update_DeliveryCompany", con);
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@name", name);
                cmd1.Parameters.AddWithValue("@contactNumber", phone);
                cmd1.Parameters.AddWithValue("@address", address);
                cmd1.Parameters.AddWithValue("@hasExpressDelivery", hasExpressDelivery);
                cmd1.ExecuteNonQuery();

                MessageBox.Show("You have updated a delivery company!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #4
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            String cc_no           = noBox.Text;
            String cc_cvc          = cvcBox.Text;
            String billing_address = billingBox.Text;

            DateTime expiry_date;

            try
            {
                expiry_date = Convert.ToDateTime(expiry_date_dtp.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The expiry date has formatting issues.");
                return;
            }


            if (!FormValidation.validatePayment(purchaseID, amount, billing_address,
                                                cc_no, cc_cvc, expiry_date))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd = new SqlCommand("ecommerce.sp_Create_Payment", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@billingAddress", billing_address);
                cmd.Parameters.AddWithValue("@creditCardCVC", cc_cvc);
                cmd.Parameters.AddWithValue("@amount", amount);
                cmd.Parameters.AddWithValue("@creditCardNo", cc_no);
                cmd.Parameters.AddWithValue("@creditCardExpiryDate", expiry_date);
                cmd.Parameters.AddWithValue("@purchaseID", purchaseID);
                cmd.ExecuteNonQuery();


                MessageBox.Show("You have made a new payment!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #5
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            decimal debitAmount;

            try
            {
                debitAmount = Convert.ToDecimal(debitBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The debit amount must be a number.");
                return;
            }

            String iban = ibanBox.Text;

            if (!FormValidation.validateDebit(debitAmount, iban))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
                return;
            }

            try
            {
                SqlCommand cmd3 = new SqlCommand("ecommerce.sp_Create_Debit", con);
                cmd3.CommandType = CommandType.StoredProcedure;
                cmd3.Parameters.AddWithValue("@debitAmount", debitAmount);
                cmd3.Parameters.AddWithValue("@IBAN", iban);
                cmd3.Parameters.AddWithValue("@accountID", accountID);
                cmd3.ExecuteNonQuery();

                MessageBox.Show("You have performed a new debit!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Failed to make a new debit:\r\n" + ex.Message, "Failed Operation", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #6
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            decimal bidAmount;

            try
            {
                bidAmount = Convert.ToDecimal(bidBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The bid amount must be a number.");
                return;
            }

            if (!FormValidation.validateBid(bidAmount))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                // Check if bid is greater or equal to minimum valid bid

                if (bidAmount < getMinValidBid(auctionID))
                {
                    FormValidation.showError("The amount must equal or greater than the minimum valid bid.");
                    return;
                }

                SqlCommand cmd1 = new SqlCommand("ecommerce.sp_Create_Bid", con);
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@auctionID", auctionID);
                cmd1.Parameters.AddWithValue("@Amount", bidAmount);
                cmd1.Parameters.AddWithValue("@userName_Buyer", username_Buyer);
                cmd1.ExecuteNonQuery();

                MessageBox.Show("You have placed a new bid!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            bidBox.Text = "";
            this.Close();
        }
コード例 #7
0
ファイル: Fill_Purchase.cs プロジェクト: gabsw/ecommerce
        private void confirmButton_Click(object sender, EventArgs e)
        {
            Buyer_Name_Record  = buyerNameTxtBox.Text;
            Seller_Name_Record = sellerNameTxtBox.Text;
            Buyer_TIN_Record   = buyerTINTxtBox.Text;
            Seller_TIN_Record  = sellerTINTxtBox.Text;

            hasExpressDelivery = expressBttn.Checked ? true : false;

            finalPrice = getFinalPrice(auctionID, hasExpressDelivery);


            if (!FormValidation.validatePurchase(finalPrice, VAT_Record, hasExpressDelivery,
                                                 auctionID, Buyer_Name_Record, Buyer_TIN_Record, Seller_Name_Record, Seller_TIN_Record))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd1 = new SqlCommand("ecommerce.sp_Create_Purchase", con);

                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@amount", finalPrice);
                cmd1.Parameters.AddWithValue("@VAT_Record", VAT_Record);
                cmd1.Parameters.AddWithValue("@hasExpressDelivery", hasExpressDelivery);
                cmd1.Parameters.AddWithValue("@auctionID", auctionID);
                cmd1.Parameters.AddWithValue("@Buyer_Name_Record", Buyer_Name_Record);
                cmd1.Parameters.AddWithValue("@Buyer_TIN_Record", Buyer_TIN_Record);
                cmd1.Parameters.AddWithValue("@Seller_Name_Record", Seller_Name_Record);
                cmd1.Parameters.AddWithValue("@Seller_TIN_Record", Seller_TIN_Record);


                cmd1.ExecuteNonQuery();

                MessageBox.Show("You have made a new purchase!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clearText();
            this.Close();
        }
コード例 #8
0
ファイル: UpdateCat.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, EventArgs e)
        {
            decimal vat;

            try
            {
                vat = Convert.ToDecimal(VATBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("VAT must be a decimal.");
                return;
            }


            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                if (vat < 0)
                {
                    FormValidation.showError("VAT must be a positive decimal.");
                    return;
                }

                SqlCommand cm2 = new SqlCommand("ecommerce.sp_Update_Product_Category", con);
                cm2.CommandType = CommandType.StoredProcedure;
                cm2.Parameters.AddWithValue("@Code", code);
                cm2.Parameters.AddWithValue("@VAT", vat);
                cm2.ExecuteNonQuery();


                MessageBox.Show("You have updated a category!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #9
0
ファイル: AddNewReview.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, EventArgs e)
        {
            int rating;

            try
            {
                rating = Convert.ToInt32(ratingBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("Rating must be a number.");
                return;
            }

            if (!FormValidation.validateReview(rating, CommentBox.Text))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cm2 = new SqlCommand("ecommerce.sp_Create_Review", con);
                cm2.CommandType = CommandType.StoredProcedure;
                cm2.Parameters.AddWithValue("@purchaseID", purchaseID);
                cm2.Parameters.AddWithValue("@Comment", CommentBox.Text);
                cm2.Parameters.AddWithValue("@Rating", rating);
                cm2.ExecuteNonQuery();

                MessageBox.Show("You have added a new review!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #10
0
ファイル: UpdateProduct.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, EventArgs e)
        {
            String name            = NameBox.Text;
            String description     = DescriptionBox.Text;
            String categoryStr     = categoryBox.Text;
            String username_Seller = sellerLabel.Text;
            int    categoryCode    = Convert.ToInt32(getCategoryCode(categoryStr));


            // Form validation
            if (!FormValidation.validateProduct(name, description, categoryStr))
            {
                return;
            }


            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd3 = new SqlCommand("ecommerce.sp_Update_Product", con);
                cmd3.CommandType = CommandType.StoredProcedure;
                cmd3.Parameters.AddWithValue("@Code", code);
                cmd3.Parameters.AddWithValue("@Name", name);
                cmd3.Parameters.AddWithValue("@Description", description);
                cmd3.Parameters.AddWithValue("@CategoryCode", categoryCode);
                cmd3.ExecuteNonQuery();


                MessageBox.Show("You have updated a product!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #11
0
        private DateTime get_Estimated_Arrival_Date(DateTime dispatch_date, bool hasExpressDelivery)
        {
            try
            {
                dispatch_date = Convert.ToDateTime(dispatch_date_dtp.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The dispatch date has formatting issues.");
            }

            if (hasExpressDelivery)
            {
                return(dispatch_date.AddDays(2.0));
            }

            else
            {
                return(dispatch_date.AddDays(7.0));
            }
        }
コード例 #12
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            DateTime official_arrival_date;

            try
            {
                official_arrival_date = Convert.ToDateTime(arrival_date_dtp.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The date has formatting issues.");
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd = new SqlCommand("ecommerce.sp_Update_Official_Arrival_Date", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@code", shippingCode);
                cmd.Parameters.AddWithValue("@officialArrivalDate", official_arrival_date);

                cmd.ExecuteNonQuery();

                MessageBox.Show("You have entered an official arrival date!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            this.Close();
        }
コード例 #13
0
ファイル: AddNewDeliveryComp.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, EventArgs e)
        {
            String  name    = NameBox.Text;
            String  phone   = PhoneBox.Text;
            String  address = AddressBox.Text;
            Boolean hasExpressDelivery;

            if (YesButton.Checked)
            {
                hasExpressDelivery = true;
            }
            else if (NoButton.Checked)
            {
                hasExpressDelivery = false;
            }
            else
            {
                FormValidation.showError("You have to check if the company provides express delivery.");
                return;
            }


            if (!FormValidation.validateDeliveryCompany(name, phone, address, hasExpressDelivery))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                // Check if name already exists
                SqlCommand cm1 = new SqlCommand("SELECT COUNT(*) " +
                                                "FROM ecommerce.DELIVERY_COMPANY " +
                                                "WHERE name = @name", con);

                cm1.Parameters.Add("@name", SqlDbType.VarChar).Value = name;

                int qty_name = (int)cm1.ExecuteScalar();

                if (qty_name != 0)
                {
                    FormValidation.showError("This company has already been registered.");
                    return;
                }

                SqlCommand cm2 = new SqlCommand("ecommerce.sp_CreateDeliveryCompany", con);
                cm2.CommandType = CommandType.StoredProcedure;
                cm2.Parameters.AddWithValue("@name", name);
                cm2.Parameters.AddWithValue("@contactNumber", phone);
                cm2.Parameters.AddWithValue("@address", address);
                cm2.Parameters.AddWithValue("@hasExpressDelivery ", hasExpressDelivery);
                cm2.ExecuteNonQuery();

                MessageBox.Show("You have added a new delivery company!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #14
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            String userName = userNameBox.Text;
            String name     = fullNameBox.Text;
            String email    = emailBox.Text;
            String password = passwordBox.Text;
            String password_confirmation = confPWBox.Text;
            String tin         = TINBox.Text;
            String fullAddress = addressBox.Text;


            if (!FormValidation.validateUser(userName, name, email, password, password_confirmation, tin, fullAddress, false))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                // Check if username already exists
                SqlCommand cm1 = new SqlCommand("SELECT COUNT(*)" +
                                                "FROM ecommerce.[USER]" +
                                                "WHERE userName = @username", con);

                cm1.Parameters.Add("@userName", SqlDbType.VarChar).Value = userName;

                int qty_username = (int)cm1.ExecuteScalar();

                if (qty_username != 0)
                {
                    FormValidation.showError("The username you have chosen is already taken.");
                    return;
                }


                // Check if e-mail already exists
                SqlCommand cm2 = new SqlCommand("SELECT COUNT(*) " +
                                                "FROM ecommerce.[USER] " +
                                                "WHERE Email = @Email", con);

                cm2.Parameters.Add("@Email", SqlDbType.VarChar).Value = email;

                int qty_email = (int)cm2.ExecuteScalar();

                if (qty_email != 0)
                {
                    FormValidation.showError("The e-mail you have chosen is already in use.");
                    return;
                }

                SqlCommand cmd3 = new SqlCommand("ecommerce.sp_Create_Regular_User_Account", con);
                cmd3.CommandType = CommandType.StoredProcedure;
                cmd3.Parameters.AddWithValue("@userName", userName);
                cmd3.Parameters.AddWithValue("@Name", name);
                cmd3.Parameters.AddWithValue("@Email", email);
                cmd3.Parameters.AddWithValue("@Password", password);
                cmd3.Parameters.AddWithValue("@Address", fullAddress);
                cmd3.Parameters.AddWithValue("@TIN", tin);
                cmd3.ExecuteNonQuery();

                MessageBox.Show("You have added a new user!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #15
0
        private void populateListView()
        {
            SqlConnection con = DbConnectionFactory.newConnection();

            String usernameSeller  = sellerBox.Text;
            String status          = getCheckedButton();
            String search_keywords = "";
            String code            = "%";

            if (searchButtonWasClicked)
            {
                search_keywords = searchBox.Text;
            }

            if (usernameSeller == "")
            {
                usernameSeller = "%";
            }

            if (status == "All")
            {
                status = "%";
            }

            if (productCode > 0)
            {
                code = productCode.ToString();
            }

            if (!FormValidation.validateSearch(search_keywords))
            {
                return;
            }

            try
            {
                con.Open();

                SqlCommand cm1 = new SqlCommand("SELECT * " +
                                                "FROM ecommerce.UDF_SEARCH_PRODUCT_SELLER (@Keywords, @Status, @usernameSeller, @Code)", con);

                cm1.Parameters.AddWithValue("@Keywords", search_keywords);
                cm1.Parameters.AddWithValue("@Status", status);
                cm1.Parameters.AddWithValue("@usernameSeller", usernameSeller);
                cm1.Parameters.AddWithValue("@Code", code);

                SqlDataReader rd1 = cm1.ExecuteReader();


                while (rd1.Read())
                {
                    ListViewItem item = new ListViewItem(rd1["Code"].ToString());
                    item.SubItems.Add(rd1["Product_Name"].ToString());

                    String seller_username = rd1["username_Seller"].ToString();
                    item.SubItems.Add(seller_username);

                    String seller_rating = rd1["avgRating"].ToString();

                    if (sellerHasReviews(seller_username))
                    {
                        item.SubItems.Add(seller_rating);
                    }

                    else
                    {
                        item.SubItems.Add("Not Rated");
                    }

                    item.SubItems.Add(rd1["Status"].ToString());
                    item.SubItems.Add(rd1["Category_Name"].ToString());
                    item.SubItems.Add(rd1["Description"].ToString());

                    ProdSellerLV.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                searchButtonWasClicked = false;
                con.Close();
            }
        }
コード例 #16
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            int vat;

            try
            {
                vat = Convert.ToInt32(VATBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("VAT must be an integer.");
                return;
            }

            String name = NameBox.Text;


            if (!FormValidation.validateCategory(name, vat))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                // Check if name already exists
                SqlCommand cm1 = new SqlCommand("SELECT COUNT(*) " +
                                                "FROM ecommerce.PRODUCT_CATEGORY " +
                                                "WHERE Name = @Name", con);

                cm1.Parameters.Add("@Name", SqlDbType.VarChar).Value = name;

                int qty_name = (int)cm1.ExecuteScalar();

                if (qty_name != 0)
                {
                    FormValidation.showError("The name you have chosen is already taken.");
                    return;
                }

                SqlCommand cm2 = new SqlCommand("ecommerce.sp_CreateProductCategory", con);
                cm2.CommandType = CommandType.StoredProcedure;
                cm2.Parameters.AddWithValue("@Name", name);
                cm2.Parameters.AddWithValue("@VAT", vat);
                cm2.ExecuteNonQuery();

                MessageBox.Show("You have added a new category!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }
コード例 #17
0
ファイル: NewAuction.cs プロジェクト: gabsw/ecommerce
        private void submitButton_Click(object sender, System.EventArgs e)
        {
            decimal minBidAmount;

            try
            {
                minBidAmount = Convert.ToDecimal(bidBox.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The bid amount must be a number.");
                return;
            }

            DateTime begDate;

            try
            {
                begDate = Convert.ToDateTime(beginning_dtp.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The beginning date must comply with the format below.");
                return;
            }

            DateTime finishDate;

            try
            {
                finishDate = Convert.ToDateTime(finish_dtp.Text);
            }
            catch (Exception ex)
            {
                FormValidation.showError("The finish date must comply with the format below.");
                return;
            }

            if (!FormValidation.validateAuction(minBidAmount, begDate, finishDate))
            {
                return;
            }

            SqlConnection con = DbConnectionFactory.newConnection();

            try
            {
                con.Open();

                SqlCommand cmd = new SqlCommand("ecommerce.sp_Create_Auction", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ProductCode", code);
                cmd.Parameters.AddWithValue("@BeginningDate", begDate);
                cmd.Parameters.AddWithValue("@FinishDate", finishDate);
                cmd.Parameters.AddWithValue("@MinimumBid", minBidAmount);
                cmd.ExecuteNonQuery();

                MessageBox.Show("You have created a new auction!", "Successful Operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO OPEN CONNECTION TO DATABASE DUE TO THE FOLLOWING ERROR \r\n" + ex.Message, "Connection Test", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            clear_text();
            this.Close();
        }