Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int shipperId;
                if (int.TryParse(lblShipperID.Text, out shipperId))
                {
                    //do the delete...
                    var info = new Shipper()
                    {
                        ShipperID = shipperId
                    };

                    NorthwindManager mgr = new NorthwindManager();
                    mgr.DeleteShipper(info);
                    PopulateShippersComboBox();
                    cboShippers.SelectedItem = 0;

                }
                else
                {
                    MessageBox.Show("Please select a shipper before clicking [Lookup Shipper]");
                }

            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                NorthwindManager mgr = new NorthwindManager();

               int shipperId =  mgr.AddShipper(new Shipper()
                                {
                                    CompanyName=txtCompanyName.Text,
                                    Phone=txtPhone.Text
                                });

                //update the combobox
               PopulateShippersComboBox();
                //has right shipper selected
               cboShippers.SelectedValue = shipperId;
                //display id of added shipper
               lblShipperID.Text = shipperId.ToString();
            }
            catch (Exception ex)
            {
                //TODO: Log the exception
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Exemplo n.º 3
0
 private void ViewRegions_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";
 }
Exemplo n.º 4
0
        public void Should_Delete_Products()
        {
            //Arrange
            var sut = new NorthwindManager();
            var actual = new Product()
            {
                ProductName = "Product to delete"
            };
            actual.ProductID = sut.AddProduct(actual);

            //Act
            sut.DeleteProduct(actual);
            //Assert
            Product p = sut.GetProduct(actual.ProductID);

            Assert.Null(p);
        }
Exemplo n.º 5
0
        public void Should_Add_Product()
        {
            //Arrange
            var sut = new NorthwindManager();
            var product = new Product()
            {
                ProductName = "MSP Basic Product",
                Discontinued = false
            };

            //Act

            var productID = sut.AddProduct(product);
            //Assert
            Assert.True(productID > 0);
            Product actual = sut.GetProduct(productID);
            Assert.Equal(productID, actual.ProductID);
        }
Exemplo n.º 6
0
        private void ProductSalesForm_Load(object sender, EventArgs e)
        {
            List<ProductSaleSummary> list = new NorthwindManager().GetProductSaleSummaries();
            reportViewer1.LocalReport.DataSources.Clear();

            //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 datasource

            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = list;

            reportViewer1.LocalReport.Refresh();
            this.reportViewer1.RefreshReport();
        }
Exemplo n.º 7
0
        public void Should_Add_Shipper()
        {
            //Arrange
            var sut = new NorthwindManager(); // sut is short for "Situation Under Test"
            var expected = new Shipper()
            {
                CompanyName = "Tin Hoang's Transporter Service",
                Phone = "780.231.3123"
            };

            //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);
        }
Exemplo n.º 8
0
        public void Should_Update_Products(Product existing)
        {
            //Arrange
            existing.ProductName = "TIN'S OLD PRODUCT";
            var sut = new NorthwindManager();

            //Act
            sut.UpdateProduct(existing);

            //Assert
            var actual = sut.GetProduct(existing.ProductID);
            Assert.NotNull(actual);
            Assert.Equal(existing.ProductName, actual.ProductName);
        }
Exemplo n.º 9
0
        public void Should_Delete_Shipper()
        {
            //Arrange
            var sut = new NorthwindManager(); // sut is short for "Situation Under Test"
            var expected = new Shipper()
            {
                CompanyName = "Tin Hoang's Transporter Service",
                Phone = "780.231.3123"
            };

            expected.ShipperID = sut.AddShipper(expected);
            //Act
            sut.DeleteShipper(expected);

            //Assert
            Shipper actual = sut.GetShipper(expected.ShipperID);
            Assert.Null(actual);
        }
Exemplo n.º 10
0
        public void Should_Update_Shippers(Shipper existing)
        {
            //Arrange
            existing.Phone = "780.999.9998";
            var sut = new NorthwindManager();

            //Act
            sut.UpdateShipper(existing);

            //Assert
            var actual = sut.GetShipper(existing.ShipperID);
            Assert.NotNull(actual);
            Assert.Equal(existing.Phone, actual.Phone);
            Assert.Equal(existing.CompanyName, actual.CompanyName);
        }
Exemplo n.º 11
0
 public ShipperController()
 {
     Northwind = new NorthwindManager();
 }
Exemplo n.º 12
0
 private void PopulateShippersComboBox()
 {
     NorthwindManager manager = new NorthwindManager();
     var data = manager.ListShippers();
     data.Insert(0, new Shipper()
     {
         ShipperID = -1,
         CompanyName = "[Select a shipper]"
     });
     cboShippers.DataSource = data;
     cboShippers.DisplayMember = "CompanyName"; // CompanyName is a property of the Shipper class
     cboShippers.ValueMember = "ShipperID"; // ShipperID is the property that represents the Primary Key (uniquely distinguishes each shipper in the database)
     //cboShippers.Items.Insert(0, "[Select a shipper]");
     cboShippers.SelectedIndex = 0;
 }
Exemplo n.º 13
0
 private void LookupBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (cboShippers.SelectedIndex <= 0)
         {
             MessageBox.Show("Please select a shipper before clicking [Lookup Shipper]");
         }
         else
         {
             int shipperId = Convert.ToInt32(cboShippers.SelectedValue);
             NorthwindManager mgr = new NorthwindManager();
             var shipper = mgr.GetShipper(shipperId);
             if (shipper != null)
             {
                 lblShipperID.Text = shipper.ShipperID.ToString();
                 txtCompanyName.Text = shipper.CompanyName;
                 txtPhone.Text = shipper.Phone;
             }
         }
     }
     catch(Exception ex)
     {
         //TODO: Log the exception
         MessageBox.Show("Error: " + ex.Message);
     }
 }