Ejemplo n.º 1
0
        public static string CreateOrder(Order ord)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);

            String sql = "INSERT INTO [Order] VALUES(@OrderID ,@CustomerID, @ProductID, @Address, @Amount, @OrderDate, @SupplierID)";

            //if there is an error with the data it will catch the exception and display an error
            try
            {
                if (ord.Product.ProductID > 0)
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(sql, connection);

                    command.Parameters.Add("@OrderID", SqlDbType.Int);
                    command.Parameters["@OrderID"].Value = ord.OrderID;

                    command.Parameters.Add("@CustomerID", SqlDbType.Int);
                    command.Parameters["@CustomerID"].Value = ord.CustomerID;

                    command.Parameters.Add("@ProductID", SqlDbType.Int);
                    command.Parameters["@ProductID"].Value = ord.Product.ProductID;

                    command.Parameters.Add("@Address", SqlDbType.NVarChar);
                    command.Parameters["@Address"].Value = ord.Address;

                    command.Parameters.Add("@Amount", SqlDbType.Float);
                    command.Parameters["@Amount"].Value = ord.Amount;

                    command.Parameters.Add("@OrderDate", SqlDbType.DateTime);
                    command.Parameters["@OrderDate"].Value = ord.Date;

                    command.Parameters.Add("@SupplierID", SqlDbType.Int);
                    command.Parameters["@SupplierID"].Value = ord.SupplierID;

                    command.ExecuteNonQuery();
                    connection.Close();
                    return "complete";
                }
                else
                    return "ProductID <= 0 for some reason - OrderMapper";

            }
            catch (SqlException sqlEx)
            {
                return (sqlEx.Message);
            }
        }
Ejemplo n.º 2
0
        public static string GetOrderID(Order ord)
        {
            int oID = 0;
            string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            SqlDataReader reader;
            SqlCommand cmd = new SqlCommand("SELECT OrderID FROM [Order] WHERE OrderID = (SELECT MAX(OrderID) FROM [Order])", con);
            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    oID = Convert.ToInt32(reader["OrderID"]);
                    oID++;
                }
                reader.Close();
                ord.OrderID = oID;

            }
            catch (SqlException sqlEx)
            {
                return (sqlEx.Message);
            }
            finally
            {
                con.Close();
            }
            return "complete";
        }
Ejemplo n.º 3
0
        public static string RemoveProduct(Order ord, int pID)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);

            String sql = "DELETE FROM [Order] WHERE [OrderID] = @OrderID AND [ProductID] = @ProductID";

            //if there is an error with the data it will catch the exception and display an error
            try
            {
                if (ord.Product.ProductID > 0)
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(sql, connection);

                    command.Parameters.Add("@OrderID", SqlDbType.Int);
                    command.Parameters["@OrderID"].Value = ord.OrderID;

                    command.Parameters.Add("@ProductID", SqlDbType.Int);
                    command.Parameters["@ProductID"].Value = pID;

                    command.ExecuteNonQuery();
                    connection.Close();
                    return "remove product completed";
                }
                else
                    return "ProductID < 1 - remove product";

            }
            catch (SqlException sqlEx)
            {
                return (sqlEx.Message);
            }
        }
Ejemplo n.º 4
0
        public static string EditOrder(Order ord)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);

            String sql = "UPDATE [Order] SET CustomerID = @CustomerID, ProductID = @ProductID," +
                                "Address = @Address, Amount = @Amount,  OrderDate = @OrderDate, SupplierID = @SupplierID WHERE OrderID = @OrderID)";

            //if there is an error with the data it will catch the exception and display an error
            try
            {
                if (ord.Product.ProductID > 0)
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(sql, connection);

                    command.Parameters.Add("@CustomerID", SqlDbType.Int);
                    command.Parameters["@CustomerID"].Value = ord.CustomerID;

                    command.Parameters.Add("@ProductID", SqlDbType.Int);
                    command.Parameters["@ProductID"].Value = ord.Product.ProductID;

                    command.Parameters.Add("@Address", SqlDbType.NVarChar);
                    command.Parameters["@Address"].Value = ord.Address;

                    command.Parameters.Add("@Amount", SqlDbType.Float);
                    command.Parameters["@Amount"].Value = ord.Amount;

                    command.Parameters.Add("@OrderDate", SqlDbType.DateTime);
                    command.Parameters["@OrderDate"].Value = ord.Date;

                    command.Parameters.Add("@SupplierID", SqlDbType.Int);
                    command.Parameters["@SupplierID"].Value = ord.SupplierID;

                    command.ExecuteNonQuery();
                    connection.Close();
                }

            }
            catch (SqlException sqlEx)
            {
                return (sqlEx.Message);
            }
            return "Edit Order COmpleted";
        }
 public override void applyDiscount(Order ord)
 {
     ord.Amount = ord.Amount * disc;
 }
Ejemplo n.º 6
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {//Convert.ToInt32(lstProducts.SelectedValue), Convert.ToInt32(txtPrice.Text), 1)
                sessionCust = (Customer)Session["CustObj"];
                newProduct = new StandardProduct(Convert.ToInt32(lstProducts.SelectedValue), Convert.ToDouble(txtPrice.Text), lstProducts.SelectedItem.Text, 1);
                ProductDiscount pd = new ProductDiscount(newProduct);
                if (sessionCust != null)
                {
                    Response.Write("Calculating Individual Product DIscount - " + pd.applyDiscount() + "/" + newProduct.Price + " Pid = " + newProduct.ProductID + "\n");
                    newOrder = new Order(
                    sessionCust.CustomerID,
                    newProduct,
                    1,
                    txtAddress.Text,
                    pd.applyDiscount() * Convert.ToInt32(txtQuantity.Text),
                    DateTime.Now);
                    newOrder.CreateOrder();

                    Response.Write("Order processed!!\n\n\n\n");
                    btnOrder.Enabled = false;
                    btnAddOrder.Enabled = true;
                    btnViewOrder.Enabled = true;
                    Response.Write("Calculating Customer Discount - " + newOrder.Amount +
                        "/" + (Convert.ToDouble(txtPrice.Text) * Convert.ToInt32(txtQuantity.Text)) + "\n");
                    Session["OrderObj"] = newOrder;
                }
                else
                    Response.Write("No customer is in session, please log in");

            }
        }
 override public void applyDiscount(Order ord)
 {
     ord.Amount = ord.Amount * disc;
 }
Ejemplo n.º 8
0
 public abstract void applyDiscount(Order ord);