Exemplo n.º 1
0
        public bool CheckCurrentOrder()
        {
            var temp = CurrentOrder.IsEmpty();

            if (temp)
            {
                AllOrders.Remove(CurrentOrder);
                CurrentOrder = new Order(CurrentUser);
                AllOrders.Add(CurrentOrder);
            }
            return(temp);
        }
Exemplo n.º 2
0
 public void GetOrders()
 {
     Orders.Clear();
     AllOrders.Clear();
     foreach (Client c in Clients)
     {
         if (!(c.Orders is null))
         {
             foreach (Order o in c.Orders)
             {
                 AllOrders.Add(o);
                 Orders.Add(o);
             }
         }
     }
 }
        public static bool UserHasOrder(User u)
        {
            List <Order> AllOrders = new List <Order>();

            string ConnectionString = @"Data Source=(local);Initial Catalog=Zadatak_1;Integrated Security=True;";

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                SqlCommand query = new SqlCommand("select * from tblOrder", conn);
                conn.Open();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query);
                DataTable      dataTable      = new DataTable();
                sqlDataAdapter.Fill(dataTable);

                if (AllOrders == null)
                {
                    AllOrders = new List <Order>();
                }

                foreach (DataRow row in dataTable.Rows)
                {
                    Order o = new Order
                    {
                        Id             = int.Parse(row[0].ToString()),
                        User           = new User(int.Parse(row[1].ToString())),
                        OrderTimeStamp = (DateTime)row[2],
                        Price          = int.Parse(row[3].ToString()),
                        Approved       = (bool)row[4]
                    };
                    AllOrders.Add(o);
                }
            }

            foreach (Order o in AllOrders)
            {
                if (u.Id == o.User.Id && o.Approved == false)
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"You already have order (Order Id: {o.Id}, Price: {o.Price}) with pending approval, please try again latter.", "Notification");
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool ChangeUser(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("User is NULL.", nameof(user));
            }

            var tempOrd = AllOrders.FirstOrDefault(o => o.CurrentUser.Name == user.Name);

            if (tempOrd == null)
            {
                CurrentOrder  = new Order(user);
                CurrentUser   = user;
                CurrentBasket = new Dictionary <Goods, int>();
                AllOrders.Add(CurrentOrder);
                AllBaskets.Add(CurrentUser, CurrentBasket);
            }

            else
            {
                foreach (var item in AllOrders)
                {
                    if (item.CurrentUser.Name == user.Name)
                    {
                        CurrentOrder = item;
                        CurrentUser  = item.CurrentUser;
                    }
                }
                foreach (var item in AllBaskets)
                {
                    if (item.Key.Name == user.Name)
                    {
                        CurrentBasket = item.Value;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        public void CheckOrders(object obj, EventArgs args)
        {
            var temp = new List <Order>(AllOrders.ToArray());

            foreach (var item in temp)
            {
                if (item.IsEmpty())
                {
                    if (item == CurrentOrder)
                    {
                        CurrentOrder = new Order(CurrentUser);
                        AllOrders.Remove(item);
                        AllOrders.Add(CurrentOrder);
                    }
                    else
                    {
                        AllOrders.Remove(item);
                        var order = new Order(item.CurrentUser);
                        AllOrders.Add(order);
                    }
                }
            }
        }
Exemplo n.º 6
0
 public Order(string customerName, Estimate estimateDetails)
 {
     CustomerName    = customerName;
     EstimateDetails = estimateDetails;
     AllOrders.Add(this);
 }