Example #1
0
        private void btnAddEditActionSale_Click(object sender, RoutedEventArgs e)
        {
            ActionSaleDAO actionSaleDAO = new ActionSaleDAO();

            if (mode == Mode.ADD)
            {
                ActionSale actionSale = new ActionSale()
                {
                    Name      = tbName.Text.Trim(),
                    Discount  = decimal.Parse(tbDiscount.Text.Trim()),
                    StartDate = dpStartDate.SelectedDate.Value.Date,
                    EndDate   = dpEndDate.SelectedDate.Value.Date
                };
                MainWindow.actionSalesList.Add(actionSale);
                actionSaleDAO.Add(actionSale);
            }
            else
            {
                actionSale.Name      = tbName.Text.Trim();
                actionSale.Discount  = decimal.Parse(tbDiscount.Text.Trim());
                actionSale.StartDate = dpStartDate.SelectedDate.Value.Date;
                actionSale.EndDate   = dpEndDate.SelectedDate.Value.Date;

                actionSaleDAO.Update(actionSale);
            }

            Close();
        }
 private void tbSearchActions_TextChanged(object sender, TextChangedEventArgs e)
 {
     actionSalesView.Filter = x =>
     {
         ActionSale asale = x as ActionSale;
         return(asale.Name.ToLower().Contains(tbSearchActions.Text.ToLower().Trim()));
     };
 }
        public ObservableCollection <Furniture> GetAll()
        {
            ObservableCollection <Furniture> furniture = new ObservableCollection <Furniture>();

            string commandText = @"SELECT * FROM Furniture WHERE Deleted = 0";

            //Treba mi SqlConnection, SqlCommand i DataReader

            using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["FurnitureStore"].ConnectionString))
            {
                con.Open();
                SqlCommand command = con.CreateCommand();
                command.CommandText = commandText;

                SqlDataReader dataReader = command.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        int           id              = (int)dataReader["Id"];
                        string        name            = (string)dataReader["Name"];
                        int           quantity        = (int)(Int16)dataReader["Quantity"];
                        decimal       price           = (decimal)dataReader["Price"];
                        int           furnitureTypeId = (int)dataReader["FurnitureTypeId"];
                        FurnitureType furnitureType   = new FurnitureTypeDAO().Get(furnitureTypeId);
                        int           actionSaleId;
                        try
                        {
                            actionSaleId = (int)dataReader["ActionSaleId"];
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                            actionSaleId = -1;
                        }
                        ActionSale actionSale = actionSaleId == -1 ? null : new ActionSaleDAO().Get(actionSaleId);
                        bool       deleted    = (bool)dataReader["Deleted"];

                        furniture.Add(new Furniture()
                        {
                            Id            = id,
                            Name          = name,
                            Quantity      = quantity,
                            Price         = price,
                            FurnitureType = furnitureType,
                            ActionSale    = actionSale,
                            Deleted       = deleted
                        });
                    }
                }
                dataReader.Close();
            }
            return(furniture);
        }
        private void btnDeleteActionSale_Click(object sender, RoutedEventArgs e)
        {
            ActionSale actionSale = (ActionSale)dgActionSales.SelectedItem;

            if (MessageBox.Show($"Are you sure you want to delete : {actionSale.Name} ?", "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                actionSalesList.Remove(actionSale);
                actionSalesView.Refresh();

                new ActionSaleDAO().Delete(actionSale);
            }
        }
        public Furniture Get(int furnitureId)
        {
            string commandText = @"SELECT * FROM Furniture WHERE Id = @Id";

            using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["FurnitureStore"].ConnectionString))
            {
                con.Open();
                SqlCommand command = con.CreateCommand();
                command.CommandText = commandText;
                command.Parameters.Add(new SqlParameter("@Id", furnitureId));

                using (SqlDataReader dataReader = command.ExecuteReader())
                {
                    if (dataReader.Read())
                    {
                        int           id              = (int)dataReader["Id"];
                        string        name            = (string)dataReader["Name"];
                        int           quantity        = (int)(Int16)dataReader["Quantity"];
                        decimal       price           = (decimal)dataReader["Price"];
                        int           furnitureTypeId = (int)dataReader["FurnitureTypeId"];
                        FurnitureType furnitureType   = new FurnitureTypeDAO().Get(furnitureTypeId);
                        int           actionSaleId;
                        try
                        {
                            actionSaleId = (int)dataReader["ActionSaleId"];
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                            actionSaleId = -1;
                        }
                        ActionSale actionSale = actionSaleId == -1 ? null : new ActionSaleDAO().Get(actionSaleId);
                        bool       deleted    = (bool)dataReader["Deleted"];

                        return(new Furniture()
                        {
                            Id = id,
                            Name = name,
                            Quantity = quantity,
                            Price = price,
                            FurnitureType = furnitureType,
                            ActionSale = actionSale,
                            Deleted = deleted
                        });
                    }
                }
                return(null);
            }
        }
Example #6
0
        public ActionSaleWindow(ActionSale actionSale, Mode mode = Mode.ADD)
        {
            InitializeComponent();
            this.actionSale = actionSale;
            this.mode       = mode;

            if (mode == Mode.EDIT)
            {
                tbName.DataContext           = actionSale;
                tbDiscount.DataContext       = actionSale;
                dpStartDate.DataContext      = actionSale;
                dpEndDate.DataContext        = actionSale;
                btnAddEditActionSale.Content = "Edit";
            }
        }