コード例 #1
0
        }// end method

        /// <summary>
        /// Button to make the transportation data be sent to the SQL DataBase.
        /// </summary>
        private void SqlWindow(object sender, RoutedEventArgs e)
        {
            var linqToSqlConnection = new LinqToSqlConnection();
            var dataClassesDataContext = linqToSqlConnection.DataClassesDataContext;
            try
            {
                var transportationDataLog = new TransportationDatum
                {
                    Name_of_Seller = _transportationDataModel.Seller,
                    Number_of_Bags = _transportationDataModel.NumberOfBags,
                    Price = _transportationDataModel.Price,
                    Quality = _transportationDataModel.Quality,
                    Shipment_Number = _transportationDataModel.ShipmentNumber,
                    Total_Cost = _transportationDataModel.Result,
                    Truck_Company = _transportationDataModel.TruckingCompany,
                    Weight = _transportationDataModel.Weight,
                    Freight_Charges = _transportationDataModel.FreightCharges,
                    Date_of_Arrival = _transportationDataModel.DateOfArrival,
                };

                dataClassesDataContext.TransportationDatums.InsertOnSubmit(transportationDataLog);

                dataClassesDataContext.SubmitChanges();

                MessageBox.Show("The transportation data has been successfully inserted!");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Data Unsuccessfully inserted" + "\n" + exception);
            }// end try-catch block
        }// end method
        private void InsertSalesData()
        {
            var linqToSqlConnection    = new LinqToSqlConnection();
            var dataClassesDataContext = linqToSqlConnection.DataClassesDataContext;

            try
            {
                var salesDatum = new SalesDatum()
                {
                    Name_of_Buyer  = SalesDataModel.BuyerName,
                    Weight_per_Bag = SalesDataModel.WeightPerBag == BagWeight.Forty ? "40" : "57",
                    Price_per_Bag  = SalesDataModel.PricePerBag,
                    Number_of_Bags = SalesDataModel.NumberOfBags,
                    Total_Cost     = SalesDataModel.TotalCost,
                    Payment_Method = SalesDataModel.PaymentMethod == MethodOfPayment.Cash ? "Cash" : "Debit",
                    Date_of_Sale   = SalesDataModel.DateOfSale?.ToString("yyyy/MM/dd")
                };
                dataClassesDataContext.SalesDatums.InsertOnSubmit(salesDatum);
                dataClassesDataContext.SubmitChanges();
                MessageBox.Show("The sales data has been successfully inserted!");
            }
            catch (Exception e)
            {
                MessageBox.Show("The sales data was unsuccessfully inserted.\nError: " + e.Message);
                throw;
            }
        }
        /// <summary>
        /// Sums up the yearly numerical data displaying it as a messagebox.
        /// </summary>
        /// <param name="sender">Object sender.</param>
        /// <param name="e">Event handler.</param>
        private void SummationYearlyData(object sender, RoutedEventArgs e)
        {
            var linqToSqlConnection = new LinqToSqlConnection();
            var transportationDatumTable = linqToSqlConnection.TransportationDatumTable;

            decimal weightTotal = 0;
            decimal priceTotal = 0;
            int numberOfBagsTotal = 0;
            decimal freightChargesTotal = 0;
            decimal costsTotal = 0;


            foreach (var transportationDatum in transportationDatumTable)
            {
                var compare = transportationDatum.Date_of_Arrival.Split('-');
                if (YearSelect.Text.Equals(compare[0]))
                {
                    weightTotal += decimal.Parse(transportationDatum.Weight);
                    priceTotal += decimal.Parse(transportationDatum.Price);
                    numberOfBagsTotal += int.Parse(transportationDatum.Number_of_Bags);
                    freightChargesTotal += decimal.Parse(transportationDatum.Freight_Charges);
                    costsTotal += decimal.Parse(transportationDatum.Total_Cost);
                }// end if
            }// end loop
            if (string.IsNullOrWhiteSpace(YearSelect.Text.ToString()))
            {
                MessageBox.Show("No year has been selected to view!");
                return;
            }
            if (costsTotal == 0)
            {
                MessageBox.Show("No data of the selected year of " + YearSelect.Text + " was found");
                return;
            }
            else
            {
                MessageBox.Show(
                  "Summary of " + YearSelect.Text.ToString() + " Transportation Data:" + "\n" + "Total weight: " + weightTotal + "\n" + "Total price: " + priceTotal +
                  "\n" + "Total Number of Bags: " + numberOfBagsTotal + "\n" + "Total Freight Charges: " + freightChargesTotal +
                  "\n" + "Total Costs: " + costsTotal);
            }
        }// end method