public void Add(FileClass data)
        {
            var list = new List <FileClass>()
            {
                data
            };

            foreach (var item in list)
            {
                FileList.Add(item);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Apply button click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applyButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (discountTxtBox.Text == String.Empty)
                {
                    discountTxtBox.Text = "0";
                }

                // Validation.
                var warranty = warrantyDropdown.Text == @"Available";
                var status   = statusDropdown.Text == @"Available";
                if (!double.TryParse(firstCostTxtBox.Text, out var cost) || cost < 0)
                {
                    throw new ArgumentException("Invalid code. The code must be greater than 0 but less than max value");
                }
                if (!int.TryParse(amountTxtBox.Text, out var amount) || amount < 0 || amount >= int.MaxValue)
                {
                    throw new ArgumentException("Invalid amount. The amount must be greater than 0 but less than max value");
                }
                if (!int.TryParse(discountTxtBox.Text, out var discount) || discount < 0 || discount > 100)
                {
                    throw new ArgumentException("Invalid discount. The discount must be greater than 0 but less than 100");
                }

                // Creating file variable.
                var file = new FileClass
                {
                    Name        = nameTxtBox.Text,
                    Code        = codeTxtBox.Text,
                    UCN         = ucnTxtBox.Text,
                    Company     = companyTxtBox.Text,
                    Country     = countryDropdown.Text,
                    Amount      = amount,
                    Cost        = cost,
                    Currency    = currencyDropdown.Text,
                    Warranty    = warranty,
                    Status      = status,
                    Discount    = discount,
                    PictureBox  = imageFileBox.AccessibleDescription,
                    Description = descriptionTxtBox.Text
                };
                // Event handler.
                Program.CallBackMy.CallbackEventHandler(file, true);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
 /// <summary>
 /// This method receiving class and boolean variable.
 /// </summary>
 /// <param name="file">New Product Class</param>
 /// <param name="isClosed">Boolean variable</param>
 void GetData(FileClass file, bool isClosed)
 {
     fileClasses  = file;
     isClosedForm = isClosed;
 }