Esempio n. 1
0
 public Order_itemModel()
 {
     _order_item    = new Order_item();
     _currencyModel = new CurrencyModel();
     _itemModel     = new ItemModel();
     _nbPackages    = 1;
 }
Esempio n. 2
0
        public List <Order_item> getAll()
        {
            List <Order_item> orders = new List <Order_item>();
            Order_item        order_item;

            using (MySqlConnection connection = new MySqlConnection(connStr))
                using (MySqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM order_item";
                    connection.Open();
                    MySqlDataReader dataReader = command.ExecuteReader();
                    while (dataReader.Read())
                    {
                        order_item = new Order_item();
                        order_item.order_item_ID = int.Parse(dataReader["orderItem_ID"]
                                                             .ToString());
                        order_item.order_ID   = int.Parse(dataReader["order_ID"].ToString());
                        order_item.product_ID = int.Parse(dataReader["product_ID"].ToString());
                        order_item.quantity   = int.Parse(dataReader["quantity"].ToString());
                        order_item.old_price  = double.Parse(dataReader["old_price"].ToString());
                        orders.Add(order_item);
                    }
                    dataReader.Close();
                }
            return(orders);
        }
Esempio n. 3
0
        public void CreateOrderItemTest()
        {
            List <string> errors = new List <string>();

            //create new order first to get a new order id

            Orders order = new Orders();

            order.order_id     = 1;
            order.customer_id  = 1;
            order.grand_total  = 0;
            order.tax_total    = 0;
            order.subtotal     = order.grand_total + order.tax_total;
            order.date_created = new DateTime();
            order.condition    = 'a';

            int id = DALOrders.CreateOrder(order, ref errors);


            Assert.AreEqual(0, errors.Count);
            Assert.AreNotEqual(-1, id);

            //now safe to create new order item

            Order_item oi = new Order_item();

            order.order_id = id;

            oi.order_id             = id;
            oi.product_variation_id = 10;
            oi.quantity             = 100;
            oi.sale_price           = 15.8F;
            oi.tax = 0.0875F;

            int result = DALOrder_item.CreateOrderItem(order, oi, ref errors);

            Assert.AreEqual(1, result);
            Assert.AreEqual(0, errors.Count);

            Order_item temp = DALOrder_item.ReadOrderItem(id, 10, ref errors);

            Assert.AreEqual(0, errors.Count);

            Assert.AreEqual(temp.order_id, id);
            Assert.AreEqual(temp.product_variation_id, 10);
            Assert.AreEqual(temp.quantity, oi.quantity);
            Assert.AreEqual(temp.sale_price, oi.sale_price);
            Assert.AreEqual(temp.tax, oi.tax);
            Assert.AreEqual(temp.condition, 'a');

            Orders temp2 = DALOrders.ReadOrder(id, ref errors);

            Assert.AreEqual(1580, temp2.subtotal);
            Assert.AreEqual(138.25, temp2.tax_total);
            Assert.AreEqual(1718.25, temp2.grand_total);
            Assert.AreEqual('a', temp.condition);
        }
Esempio n. 4
0
        public static List <Order_item> ReadOrderItems(int o, ref List <string> errors)
        {
            List <Order_item> oil   = null;
            Order_item        order = null;

            SqlConnection conn = new SqlConnection(connection_string);

            try
            {
                string strSQL = "read_order_items";

                SqlDataAdapter mySA = new SqlDataAdapter(strSQL, conn);
                mySA.SelectCommand.CommandType = CommandType.StoredProcedure;
                mySA.SelectCommand.Parameters.Add(new SqlParameter("@order_id", SqlDbType.Int));

                mySA.SelectCommand.Parameters["@order_id"].Value = o;

                DataSet myDS = new DataSet();

                mySA.Fill(myDS);

                if (myDS.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                oil = new List <Order_item>();

                for (int i = 0; i < myDS.Tables[0].Rows.Count; i++)
                {
                    order                      = new Order_item();
                    order.order_id             = int.Parse(myDS.Tables[0].Rows[i]["order_id"].ToString());
                    order.product_variation_id = int.Parse(myDS.Tables[0].Rows[i]["product_variation_id"].ToString());
                    order.tax                  = float.Parse(myDS.Tables[0].Rows[i]["tax"].ToString());
                    order.quantity             = int.Parse(myDS.Tables[0].Rows[i]["quantity"].ToString());
                    order.sale_price           = int.Parse(myDS.Tables[0].Rows[i]["sale_price"].ToString());
                    order.condition            = char.Parse(myDS.Tables[0].Rows[i]["condition"].ToString());

                    oil.Add(order);
                }

                return(oil);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
            finally
            {
                conn.Dispose();
                conn = null;
            }


            return(oil);
        }
Esempio n. 5
0
 private void order_items_grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (order_items_grid.CurrentCell.ColumnIndex == 3)
     {
         Order_item temp = new Order_item();
         temp.order_item_ID = (int)(order_items_grid.CurrentRow.Cells[4].Value);
         (new OrderItem_BL()).delete(temp);
         updateBag();
     }
 }
    public IActionResult ProductAdd(Order_itemsRequest order_item)
    {
        var order_itemAdd = new Order_item()
        {
            Order_id = order_item.Order_id, Product_id = order_item.Product_id, Quantity = order_item.Quantity
        };

        Order_items.Add(order_itemAdd);
        return(Ok(new { data = Order_items }));
    }
Esempio n. 7
0
 public void delete(Order_item obj)
 {
     using (MySqlConnection connection = new MySqlConnection(connStr))
         using (MySqlCommand command = connection.CreateCommand())
         {
             command.CommandText = "DELETE FROM order_item WHERE orderItem_ID = @order_item_ID";
             command.Parameters.AddWithValue("@order_item_ID", obj.order_item_ID);
             connection.Open();
             command.ExecuteNonQuery();
         }
 }
    public IActionResult PutById(int id)
    {
        Products product       = product.Find(id);
        var      order_itemPut = new Order_item()
        {
            Order_id = order_item.Order_id, Product_id = order_item.Product_id, Quantity = order_item.Quantity
        };

        Order_items.Add(order_itemPut);
        return(Ok(new { data = Order_items }));
    }
Esempio n. 9
0
        public async Task <List <Order_item> > searchOrder_itemAsync(Order_item Order_item, ESearchOption filterOperator)
        {
            List <Order_item> result = new List <Order_item>();

            try
            {
                result = await DAC.DALOrder.searchOrder_itemAsync(Order_item, filterOperator);
            }
            catch (Exception ex) { Log.error(ex.Message, EErrorFrom.ORDER); }
            return(result);
        }
Esempio n. 10
0
        private void submit_Click(object sender, EventArgs e)
        {
            Order_item orderItem = new Order_item();

            orderItem.order_ID   = currentOrder.order_ID;
            orderItem.product_ID = currentProduct.product_ID;
            orderItem.quantity   = (int)amountPicker.Value;
            orderItem.old_price  = currentProduct.price;

            (new OrderItem_BL()).add(orderItem);
        }
Esempio n. 11
0
    public IActionResult DeleteById(int id)
    {
        Order_item order_item = order_item.Find(id);

        if (order_item == null)
        {
            return(HttpNotFound());
        }
        Order_item.Remove(order_item);
        Order_item.SaveChanges();
        return(Ok(new { data = Order_items }));
    }
Esempio n. 12
0
        public async Task <List <Order_item> > searchOrder_itemAsync(Order_item Order_item, ESearchOption filterOperator)
        {
            List <Order_item> result = new List <Order_item>();

            try
            {
                result = (await _channel.get_filter_order_itemAsync(_companyName, Order_item.Order_itemTypeToFilterArray(filterOperator))).ArrayTypeToOrder_item();
            }
            catch (FaultException) { Dispose(); throw; }
            catch (CommunicationException) { _channel.Abort(); throw; }
            catch (TimeoutException) { _channel.Abort(); }
            return(result);
        }
Esempio n. 13
0
        private void addItemToLVLastGroup(Order_item order_item)
        {
            int     lastInd = ordersLV.Groups.Count - 1;
            Product product = (new Product_BL()).getById(order_item.product_ID);

            ListViewItem item = new ListViewItem(product.name);

            item.SubItems.Add(order_item.old_price.ToString());
            item.SubItems.Add(order_item.quantity.ToString());
            sum += order_item.old_price * order_item.quantity;

            ordersLV.Items.Add(item).Group = ordersLV.Groups[lastInd];
        }
Esempio n. 14
0
 public void add(Order_item obj)
 {
     using (MySqlConnection connection = new MySqlConnection(connStr))
         using (MySqlCommand command = connection.CreateCommand())
         {
             command.CommandText = "INSERT INTO shop.order_item (order_ID,product_ID,quantity) VALUES (@order_ID,@product_ID,@quantity)";
             command.Parameters.AddWithValue("@order_ID", obj.order_ID);
             command.Parameters.AddWithValue("@product_ID", obj.product_ID);
             command.Parameters.AddWithValue("@quantity", obj.quantity);
             connection.Open();
             command.ExecuteNonQuery();
         }
 }
Esempio n. 15
0
 public void update(Order_item obj)
 {
     using (MySqlConnection connection = new MySqlConnection(connStr))
         using (MySqlCommand command = connection.CreateCommand())
         {
             command.CommandText = "UPDATE order_item SET order_ID=@order_ID,product_ID=@product_ID,quantity=@quantity WHERE order_item_ID=@order_item_ID";
             command.Parameters.AddWithValue("@order_ID", obj.order_ID);
             command.Parameters.AddWithValue("@product_ID", obj.product_ID);
             command.Parameters.AddWithValue("@quantity", obj.quantity);
             command.Parameters.AddWithValue("@order_item_ID", obj.order_item_ID);
             connection.Open();
             command.ExecuteNonQuery();
         }
 }
Esempio n. 16
0
 public IActionResult Post(Order_item order_item)
 {
     order_item = new Order_item {
         OrderId   = order_item.OrderId,
         ProductId = order_item.ProductId,
         Quantity  = order_item.Quantity
     };
     _context.Order_item.Add(order_item);
     _context.SaveChanges();
     return(Ok(new {
         message = "success send data",
         status = true,
         data = order_item
     }));
 }
Esempio n. 17
0
        public void ReadOrderItemTest()
        {
            List <string> errors = new List <string>();

            Order_item temp = null;

            temp = DALOrder_item.ReadOrderItem(16, 1, ref errors);
            Assert.AreEqual(0, errors.Count);

            Assert.AreEqual(16, temp.order_id);
            Assert.AreEqual(1, temp.product_variation_id);
            Assert.AreEqual(49, temp.quantity);
            Assert.AreEqual(42, temp.sale_price);
            Assert.AreEqual(0, temp.tax);
            Assert.AreEqual('a', temp.condition);
        }
Esempio n. 18
0
        public static int UpdateOrderItem(Order_item oi, ref List <string> errors)
        {
            SqlConnection conn = new SqlConnection(connection_string);

            try
            {
                string strSQL = "update_order_item";

                SqlDataAdapter mySA = new SqlDataAdapter(strSQL, conn);
                mySA.SelectCommand.CommandType = CommandType.StoredProcedure;
                mySA.SelectCommand.Parameters.Add(new SqlParameter("@order_id", SqlDbType.Int));

                mySA.SelectCommand.Parameters["@order_id"].Value = oi.order_id;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@product_variation_id", SqlDbType.Int));

                mySA.SelectCommand.Parameters["@product_variation_id"].Value = oi.product_variation_id;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Int));

                mySA.SelectCommand.Parameters["@quantity"].Value = oi.quantity;

                DataSet myDS = new DataSet();

                mySA.Fill(myDS);


                if (myDS.Tables[0].Rows.Count == 0)
                {
                    return(0);
                }

                return(1);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
            finally
            {
                conn.Dispose();
                conn = null;
            }

            return(0);
        }
Esempio n. 19
0
        private void dgvItemsOrdered_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            DataGridViewRow dr = this.dgvItemsOrdered.Rows[e.RowIndex];
            Order_item      selectedOrderItem = dr.DataBoundItem as Order_item;

            DialogResult dialog = MessageBox.Show("Are you sure you want to delete this order?", "Delete?", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                _order_items.Remove(selectedOrderItem);
                Customers_provider.removeItemFromOrder(selectedOrderItem);
                updateOrderList();
            }
            else if (dialog == DialogResult.No)
            {
            }
        }
Esempio n. 20
0
        public long add(Order_item obj)
        {
            long res;

            using (MySqlConnection connection = new MySqlConnection(connStr))
                using (MySqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = @"INSERT INTO shop.order_item (order_ID,product_ID,quantity,old_price) VALUES (@order_ID,@product_ID,@quantity,@old_price)";
                    command.Parameters.AddWithValue("@order_ID", obj.order_ID);
                    command.Parameters.AddWithValue("@product_ID", obj.product_ID);
                    command.Parameters.AddWithValue("@quantity", obj.quantity);
                    command.Parameters.AddWithValue("@old_price", obj.old_price);
                    connection.Open();
                    command.ExecuteNonQuery();
                    res = command.LastInsertedId;
                }
            return(res);
        }
Esempio n. 21
0
        public int LoadOrder_item(Order_item order_item)
        {
            var dataFoundList = new Order_item {
                ID = order_item.ID
            }.filterDataTableToOrder_itemType(ESearchOption.AND);

            if (dataFoundList.Count != 0)
            {
                DALHelper.getDataTableFromSqlCEQuery(DALHelper.getUpdateSqlText(OREDER_ITEMTABLENAME, DALHelper.getColumDictionary(order_item)));
            }
            else
            {
                DALHelper.getDataTableFromSqlCEQuery(DALHelper.getInsertSqlText(OREDER_ITEMTABLENAME, DALHelper.getColumDictionary(order_item)));
            }
            return(new Order_item {
                ID = order_item.ID
            }.filterDataTableToOrder_itemType(ESearchOption.AND).Count);
        }
Esempio n. 22
0
        private void addRow(Order_item order_item)
        {
            Product product = (new Product_BL())
                              .getById(order_item.product_ID);

            double price = product.price * order_item.quantity;

            sum += price;

            DataGridViewRow row = (DataGridViewRow)order_items_grid.Rows[0].Clone();

            row.Cells[0].Value = product.name;
            row.Cells[1].Value = product.price + "*" + order_item.quantity;
            row.Cells[2].Value = order_item.quantity;
            row.Cells[3].Value = Properties.Resources.Rubbish;
            row.Cells[4].Value = order_item.order_item_ID;
            row.Cells[5].Value = order_item.product_ID;
            order_items_grid.Rows.Add(row);
        }
Esempio n. 23
0
        public static int UpdateOrderItem(Orders order, Order_item oi, ref List <string> errors)
        {
            if (order == null || oi == null)
            {
                errors.Add("Order cannot be null");
            }
            if (errors.Count > 0)
            {
                return(-1);
            }
            if (order.order_id <= 0 || oi.order_id <= 0)
            {
                errors.Add("Invalid order id");
            }
            if (oi.product_variation_id < 0)
            {
                errors.Add("Invalid product variation id");
            }
            if (oi.tax < 0)
            {
                errors.Add("Invalid tax range");
            }
            if (oi.quantity < 0)
            {
                errors.Add("Invalid quantity");
            }
            if (oi.sale_price < 0)
            {
                errors.Add("Invalid sale price");
            }
            if (oi.condition != 'a' && oi.condition != 'd')
            {
                errors.Add("Invalid order item condition");
            }


            if (errors.Count > 0)
            {
                return(-1);
            }

            return(DALOrders.UpdateOrder(order, ref errors));
        }
Esempio n. 24
0
        public static int CreateOrderItem(Orders order, Order_item oi, ref List <string> errors)
        {
            SqlConnection conn = new SqlConnection(connection_string);

            try
            {
                string strSQL = "create_order_item";

                SqlDataAdapter mySA = new SqlDataAdapter(strSQL, conn);
                mySA.SelectCommand.CommandType = CommandType.StoredProcedure;
                mySA.SelectCommand.Parameters.Add(new SqlParameter("@order_id", SqlDbType.Int));
                mySA.SelectCommand.Parameters["@order_id"].Value = order.order_id;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@product_variation_id", SqlDbType.Int));
                mySA.SelectCommand.Parameters["@product_variation_id"].Value = oi.product_variation_id;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@tax", SqlDbType.Float));
                mySA.SelectCommand.Parameters["@tax"].Value = oi.tax;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Int));
                mySA.SelectCommand.Parameters["@quantity"].Value = oi.quantity;

                mySA.SelectCommand.Parameters.Add(new SqlParameter("@condition", SqlDbType.Char));
                mySA.SelectCommand.Parameters["@condition"].Value = oi.condition;

                DataSet myDS = new DataSet();

                mySA.Fill(myDS);

                return(1);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e.ToString());
            }
            finally
            {
                conn.Dispose();
                conn = null;
            }
            return(-1);
        }
Esempio n. 25
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Boolean    add;
            Product    item     = (Product)cbxItem.SelectedItem;
            int        quantity = int.Parse(cbxQuantity.SelectedItem.ToString());
            Order_item order    = new Order_item();

            order.order_number = int.Parse(txtOrderNumber.Text);
            order.product_id   = item.product_id;
            order.product_desc = item.product_description;
            order.quantity     = quantity;

            add = Customers_DataAccess.Customers_provider.addItemToOrder(order);

            if (add)
            {
                _order_items.Add(order);
                updateOrderList();
            }
        }
Esempio n. 26
0
        public Order_item getById(int id)
        {
            Order_item order_item = new Order_item();

            using (MySqlConnection connection = new MySqlConnection(connStr))
                using (MySqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM order_item WHERE order_item.order_item_ID=@order_item_ID";
                    command.Parameters.AddWithValue("@order_item_ID", id);
                    connection.Open();
                    MySqlDataReader dataReader = command.ExecuteReader();
                    dataReader.Read();
                    order_item.order_item_ID = id;
                    order_item.order_ID      = int.Parse(dataReader["order_ID"].ToString());
                    order_item.product_ID    = int.Parse(dataReader["product_ID"].ToString());
                    order_item.quantity      = int.Parse(dataReader["quantity"].ToString());
                    dataReader.Close();
                }
            return(order_item);
        }
Esempio n. 27
0
 public int AddOrder_item(object[] value)
 {
     try
     {
         Order_item order = new Order_item();
         order.order_id   = int.Parse(value[0].ToString());
         order.product_id = int.Parse(value[1].ToString());
         order.code       = value[2].ToString();
         order.qty        = int.Parse(value[3].ToString());
         order.price      = double.Parse(value[4].ToString());
         order.size       = value[5].ToString();
         order.color      = value[6].ToString();
         db.Order_items.InsertOnSubmit(order);
         db.SubmitChanges();
         return(order.id);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
        public ActionResult Create(Orders order)
        {
            try
            {
                List <ShoppingCart> listCart = (List <ShoppingCart>)Session["Cart"];
                db.Orders.Add(order);
                db.SaveChanges();

                foreach (ShoppingCart cart in listCart)
                {
                    Order_item orderItem = new Order_item()
                    {
                        OrderID   = order.Id,
                        ProductID = cart.Product.Id,
                        Quantity  = cart.Quantity
                    };
                    db.Order_item.Add(orderItem);
                    db.SaveChanges();
                }
                Session.Remove("Cart");

                Order_details orderDetails = new Order_details()
                {
                    Order    = order,
                    StatusID = 1
                };
                db.Order_details.Add(orderDetails);
                db.SaveChanges();

                // tutaj wyslac na strone ze zamowienie zostalo zlozone i ze liste zamowien mozna zobaczyc np. w profilu
                // i oczywisice zrobic trzeba w profilu mozliwosc zobaczenia zamowien
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
            catch
            {
                // Error - Trzeba zrobic strone dla View ze blad wystapil albo jakas ogolna ze blad wystapil
                // bo jak teraz wywali errora gdzies to zwroci ze ta strona nie istnieje :P
                return(View());
            }
        }
Esempio n. 29
0
        public void UpdateOrderItemTest()
        {
            List <string> errors = new List <string>();

            //update exist record
            Order_item oi = new Order_item();

            oi.order_id             = 1;
            oi.product_variation_id = 32;
            oi.quantity             = 13;

            int result = DALOrder_item.UpdateOrderItem(oi, ref errors);

            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(1, result);

            Order_item temp2 = null;

            temp2 = DALOrder_item.ReadOrderItem(1, 32, ref errors);
            Assert.AreEqual(1, temp2.order_id);
            Assert.AreEqual(32, temp2.product_variation_id);
            Assert.AreEqual(13, temp2.quantity);
            Assert.AreEqual(18.99F, temp2.sale_price);
            Assert.AreEqual(0F, temp2.tax);
            Assert.AreEqual('a', temp2.condition);

            //check subtotal, grand total, tax total update
            Orders temp = DALOrders.ReadOrder(1, ref errors);

            Assert.AreEqual(0, errors.Count);

            Assert.AreEqual(2260.81F, temp.subtotal);
            Assert.AreEqual(545F, temp.customer_id);
            Assert.AreEqual(2260.81F, temp.grand_total);
            Assert.AreEqual(0F, temp.tax_total);
            Assert.AreEqual('a', temp.condition);
        }
Esempio n. 30
0
 public int UpdateOrder(Orders o, Order_item oi, ref List <string> errors)
 {
     return(BLOrder_item.UpdateOrderItem(o, oi, ref errors));
 }