Ejemplo n.º 1
0
        private void btnAddShipper_Click(object sender, EventArgs e)
        {
            try
            {
                Shipper item = new Shipper()
                {
                    CompanyName = tboCompanyName.Text,
                    Phone = tboPhone.Text
                };

                var mgr = new NorthwindManager();
                item.ShipperID = mgr.AddShipper(item);
                //Give some feedback to the user...
                // - Update my combo-box
                PopulateShippersComboBox();
                // - My combo-box has the right shipper selected
                cboShippers.SelectedValue = item.ShipperID;
                // - Display the id fo the addd shipper
                tboShipperID.Text = item.ShipperID.ToString();
            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 private void btnDeleteShipper_Click(object sender, EventArgs e)
 {
     try
     {
         int temp;
         if (int.TryParse(tboShipperID.Text, out temp))
         {
             var data = new Shipper() { ShipperID = temp };
             var mgr = new NorthwindManager();
             mgr.DeleteShipper(data);
             //feedback to user
             PopulateShippersComboBox();
             //clear the form textboxes
             tboShipperID.Text = "";
             tboCompanyName.Text = "";
             tboPhone.Text = "";
         }
         else
         {
             MessageBox.Show("Please lookup a shipper before trying to delete.");
         }
     }
     catch (Exception ex)
     {
         //TODO: Log the exception
         Program.LogMessage(ex.Message);
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 3
0
 private void fmViewRegions_Load(object sender, EventArgs e)
 {
     //Populate the ComboBox
     NorthwindManager manager = new NorthwindManager();
     var data = manager.GetRegions();
     cboRegions.DataSource = data;
     cboRegions.DisplayMember = "RegionDescription";
     cboRegions.ValueMember = "RegionID";
 }
Ejemplo n.º 4
0
        private void fmProductSalesForm_Load(object sender, EventArgs e)
        {
            List<ProductSaleSummary> list = new NorthwindManager().GetProductSaleSummaries();

            reportViewer1.LocalReport.DataSources.Clear();  //clear report

            //NOTE: reportViewer1.LocalReport.ReportEmbeddedResource =  "<application namespace>.[optional <folder>].<filename.rdlc>"
            reportViewer1.LocalReport.ReportEmbeddedResource = "DesktopApp.Reports.ProductSalesReport.rdlc";

            Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("ProductSalesDataSet", list);  //set the datasource
            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = list;

            reportViewer1.LocalReport.Refresh();
            this.reportViewer1.RefreshReport();
        }
Ejemplo n.º 5
0
        public void Should_Delete_Product()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Product()
            {
                ProductName = "Double Double",
                UnitsInStock = 777
            };

            expected.ProductID = sut.AddProduct(expected);

            //Act
            sut.DeleteProduct(expected);

            //Assert
            Shipper actual = sut.GetShipper(expected.ProductID);
            Assert.Null(actual);
        }
Ejemplo n.º 6
0
        public void Should_Add_Product()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Product()
            {
                ProductName = "Double Double",
                UnitsInStock = 777
            };

            //Act
            var actualId = sut.AddProduct(expected);

            //Assert
            Assert.True(actualId > 0);
            Product actual = sut.GetProduct(actualId);
            Assert.Equal(expected.ProductName, actual.ProductName);
            Assert.Equal(expected.UnitsInStock, actual.UnitsInStock);
            Assert.Equal(actualId, actual.ProductID);
        }
Ejemplo n.º 7
0
        public void Should_Add_Shipper()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Shipper()
            {
                CompanyName = "Montgomery Scott's Transporter Service",
                Phone = "780.555.1212"
            };

            //Act
            var actualId = sut.AddShipper(expected);

            //Assert
            Assert.True(actualId > 0);
            Shipper actual = sut.GetShipper(actualId);
            Assert.Equal(expected.CompanyName, actual.CompanyName);
            Assert.Equal(expected.Phone, actual.Phone);
            Assert.Equal(actualId, actual.ShipperID);
        }
Ejemplo n.º 8
0
 public ShipperController()
 {
     Northwind = new NorthwindManager();
 }
Ejemplo n.º 9
0
        public void Should_Update_Product(Product existing)
        {
            //Arrange
            existing.UnitsInStock = 777;
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            existing.UnitsInStock = 999;

            //Act
            sut.UpdateProduct(existing);

            //Assert
            var actual = sut.GetProduct(existing.ProductID);
            Assert.NotNull(actual);
            Assert.Equal(existing.ProductName, actual.ProductName);
            Assert.Equal(existing.UnitsInStock, actual.UnitsInStock);
        }
Ejemplo n.º 10
0
 private void PopulateShippersComboBox()
 {
     NorthwindManager manager = new NorthwindManager();
     var data = manager.ListShippers();
     //Use a 'fake' data item at top of list for the message
     data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[Select a Shipper]" });
     cboShippers.DataSource = data;
     cboShippers.DisplayMember = "CompanyName";
     cboShippers.ValueMember = "ShipperID";
     //cboShippers.Items.Insert(0, "[Select a Shipper]");
     cboShippers.SelectedIndex = 0; //first item in the combobox
 }
Ejemplo n.º 11
0
        private void btnUpdateShipper_Click(object sender, EventArgs e)
        {
            try
            {
                int shipperId;
                if (int.TryParse(tboShipperID.Text, out shipperId))
                {
                    //Do the update
                    var info = new Shipper()
                    {
                        ShipperID = shipperId,
                        CompanyName = tboCompanyName.Text,
                        Phone = tboPhone.Text
                    };

                    var mgr = new NorthwindManager();
                    mgr.UpdateShipper(info);
                    PopulateShippersComboBox();
                    cboShippers.SelectedValue = info.ShipperID;
                }

                else
                {
                    MessageBox.Show("Please lookup a shipper before trying to update.");
                }
            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 12
0
        private void btnLookupShipper_Click(object sender, EventArgs e)
        {
            try
            {
                //Get data from form
                if (cboShippers.SelectedIndex <= 0)
                {
                    MessageBox.Show("Please select a shipper.");
                }
                else
                {
                    int shipperId = Convert.ToInt32(cboShippers.SelectedValue);

                    NorthwindManager mgr = new NorthwindManager();
                    Shipper data = mgr.GetShipper(shipperId);

                    //Unpack the data
                    tboShipperID.Text = data.ShipperID.ToString();
                    tboCompanyName.Text = data.CompanyName;
                    tboPhone.Text = data.Phone;
                }
            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                MessageBox.Show("Error: " + ex.Message, "Error Loading Form", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 13
0
        public void Should_Delete_Shipper()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Shipper()
            {
                CompanyName = "Montgomery Scott's Transporter Service",
                Phone = "780.555.1212"
            };

            expected.ShipperID = sut.AddShipper(expected);

            //Act
            sut.DeleteShipper(expected);

            //Assert
            Shipper actual = sut.GetShipper(expected.ShipperID);
            Assert.Null(actual);
        }
Ejemplo n.º 14
0
        public void Should_Update_Shipper(Shipper existing)
        {
            //Arrange
            existing.Phone = "780.999.999";
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            existing.Phone = "780.555.1212";

            //Act
            sut.UpdateShipper(existing);

            //Assert
            var actual = sut.GetShipper(existing.ShipperID);
            Assert.NotNull(actual);
            Assert.Equal(existing.CompanyName, actual.CompanyName);
            Assert.Equal(existing.Phone, actual.Phone);
        }