Exemplo n.º 1
0
        private void AddRecetteButton_Click(object sender, RoutedEventArgs e)
        {
            AddRecetteControl control = (AddRecetteControl)this.ContentHolder.Content;
            List <Object>     values  = new List <Object>();

            try
            {
                DatePicker controlFirst = (DatePicker)control.FindName("date");
                String     date         = controlFirst.SelectedDate.Value.ToString("dd/MM/yyyy");
                values.Add(date);

                ComboBox controlSecond = (ComboBox)control.FindName("mode");
                String   mode          = ((ComboBoxItem)controlSecond.SelectedItem).Content.ToString();
                values.Add(mode);

                TextBox controlThird = (TextBox)control.FindName("libelle");
                String  libelle      = controlThird.Text;
                if (String.IsNullOrEmpty(libelle.Trim()))
                {
                    throw new Exception();
                }
                values.Add(libelle);

                ComboBox controlFourth = (ComboBox)control.FindName("provenance");
                String   provenance    = ((ComboBoxItem)controlFourth.SelectedItem).Content.ToString();
                values.Add(provenance);

                TextBox controlFifth = (TextBox)control.FindName("montant");
                String  montant      = controlFifth.Text;
                if (String.IsNullOrEmpty(montant.Trim()))
                {
                    throw new Exception();
                }
                values.Add(Decimal.Parse(montant));
            }
            catch
            {
                values.Clear();
                MessageBox.Show("You have to set all items.", "Erreur");
            }

            try
            {
                this.excel.AddRecette(values);
            }
            catch (Exception exception)
            {
                MessageBox.Show(String.Format("Unable to add recette ({0}).", exception.Message), "Erreur");
            }
            finally
            {
                this.ContentHolder.Content = new LogoControl();
            }
        }
Exemplo n.º 2
0
        private void MenuItemAddRecette_Click(object sender, RoutedEventArgs e)
        {
            if (!this.excel.IsOpen)
            {
                MessageBox.Show("First, you have to create or open the Excel file.", "Erreur");

                return;
            }

            try
            {
                AddRecetteControl control = new AddRecetteControl();
                control.AddRecetteButtonClicked += new AddRecetteControl.AddRecetteButtonClickHandler(AddRecetteButton_Click);
                this.ContentHolder.Content       = control;
            }
            catch (Exception exception)
            {
                MessageBox.Show(String.Format("Unable to add a recette ({0}).", exception.Message), "Erreur");
            }
        }