private void AddDataSupplier_Click(object sender, RoutedEventArgs e) { SupplierController CallSupplier = new SupplierController(); if (SupplierNameTextBox.Text.Length == 0 && SupplierPhoneTextBox.Text.Length == 0 && SupplierAddressTextBox.Text.Length == 0) { SupplierNameErrorMessage.Text = "You Must Enter Supplier Name!"; SupplierAddressErrorMessage.Text = "You Must Enter Supplier Address!"; SupplierPhoneErrorMessage.Text = "You Must Enter Supplier Phone Number!"; SupplierNameTextBox.Focus(); SupplierAddressTextBox.Focus(); SupplierPhoneTextBox.Focus(); } else if (SupplierNameTextBox.Text.Length == 0 && SupplierAddressTextBox.Text.Length == 0) { SupplierNameErrorMessage.Text = "You Must Enter Supplier Name!"; SupplierAddressErrorMessage.Text = "You Must Enter Supplier Address!"; SupplierNameTextBox.Focus(); SupplierAddressTextBox.Focus(); } else if (SupplierNameTextBox.Text.Length == 0 && SupplierPhoneTextBox.Text.Length == 0) { SupplierPhoneErrorMessage.Text = "You Must Enter Supplier Phone Number!"; SupplierNameErrorMessage.Text = "You Must Enter Supplier Name!"; SupplierNameTextBox.Focus(); SupplierPhoneTextBox.Focus(); } else if (SupplierAddressTextBox.Text.Length == 0 && SupplierPhoneTextBox.Text.Length == 0) { SupplierAddressErrorMessage.Text = "You Must Enter Supplier Address!"; SupplierPhoneErrorMessage.Text = "You Must Enter Supplier Phone Number!"; SupplierAddressTextBox.Focus(); SupplierPhoneTextBox.Focus(); } else if (SupplierPhoneTextBox.Text.Length == 0) { SupplierPhoneErrorMessage.Text = "You Must Enter Supplier Phone Number!"; SupplierPhoneTextBox.Focus(); } else if (SupplierAddressTextBox.Text.Length == 0) { SupplierAddressErrorMessage.Text = "You Must Enter Supplier Address!"; SupplierAddressTextBox.Focus(); } else if (SupplierNameTextBox.Text.Length == 0) { SupplierNameErrorMessage.Text = "You Must Enter Supplier Name!"; SupplierNameTextBox.Focus(); } else { string Sname = SupplierNameTextBox.Text; string Saddress = SupplierAddressTextBox.Text; string Sphone = SupplierPhoneTextBox.Text; CallSupplier.AddSupplier(Sname, Saddress, Sphone); } }
private void Add_Click(object sender, RoutedEventArgs e) { if (controller.AddSupplier(Supplier) > 0) { lbSuppliers.ItemsSource = null; lbSuppliers.ItemsSource = controller.GetSuppliers(); lbSuppliers.ScrollIntoView(lbSuppliers.Items[lbSuppliers.Items.Count - 1]); MessageBox.Show("成功"); } else { MessageBox.Show("失败"); } }
protected void AddSupplier_Click(object sender, EventArgs e) { try { //TODO: Validation //Create a Supplier object from the data in the form Supplier item = new Supplier(); item.CompanyName = CompanyName.Text; item.ContactName = ContactName.Text; if (!string.IsNullOrWhiteSpace(ContactTitle.Text)) { item.ContactTitle = ContactTitle.Text; } if (!string.IsNullOrWhiteSpace(Region.Text)) { item.Region = Region.Text; //nullable } if (!string.IsNullOrWhiteSpace(PostalCode.Text)) { item.PostalCode = PostalCode.Text; } item.Address = Address.Text; item.City = City.Text; if (!string.IsNullOrWhiteSpace(Fax.Text)) { item.Fax = Fax.Text;//nullable } item.Country = CountryDropDown.Text;//From a drop down item.Phone = Phone.Text; item.Email = Email.Text; //Send to BLL var controller = new SupplierController(); int newSupplierID = controller.AddSupplier(item); //Update form and give feedback BindSupplierDropDown(); //New supplier SupplierDropDown.SelectedValue = newSupplierID.ToString(); CurrentSupplier.Text = newSupplierID.ToString(); ShowMessage("Supplier has been added", STYLE_SUCCESS); } catch (Exception ex) { ShowMessage(ex.Message, STYLE_WARNING); } }
protected void AddSupplier_Click(object sender, EventArgs e) { try { //TODO: 0) VALIDATION // 1) Create a Supplier object from the data in the form Supplier item = new Supplier(); item.CompanyName = CompanyName.Text; item.ContactName = ContactName.Text; if (!string.IsNullOrWhiteSpace(ContactTitle.Text)) { item.ContactTitle = ContactTitle.Text; //nullable } item.Email = Email.Text; item.Address = Address.Text; item.City = City.Text; if (!string.IsNullOrWhiteSpace(Region.Text)) { item.Region = Region.Text; } if (!string.IsNullOrWhiteSpace(PostalCode.Text)) { item.PostalCode = PostalCode.Text; } item.Phone = Phone.Text; if (!string.IsNullOrWhiteSpace(Fax.Text)) { item.Fax = Fax.Text; } item.Country = CountryDropDown.SelectedValue; // 2) Send the data to the BLL var controller = new SupplierController(); int newSupplierId = controller.AddSupplier(item); // 3) Update the form and give feedback to the user BindSupplierDropDown(); //because there's a new supplier now SupplierDropDown.SelectedValue = newSupplierId.ToString(); CurrentSupplier.Text = newSupplierId.ToString(); ShowMessage("Supplier has been added.", STYLE_SUCCESS); } catch (Exception ex) { ShowMessage(ex.Message, STYLE_WARNING); } }
public void CreateSupplierTest() { var controller = new SupplierController(new LoggerStub <SupplierController>()); List <Supplier> suppliers = controller.Search("Test Supplier").Result as List <Supplier>; var no = string.Format("{0:000}", suppliers.Count); var supplier = new Supplier { Name = "Test Supplier", SupplierCode = $"TEST-SUPPLIER-CODE-{no}" }; var supplierId = controller.AddSupplier(supplier.Name, supplier.SupplierCode).Result; Assert.IsNotNull(supplierId, "Failed to create supplier"); var dataSupplier = controller.GetSupplier(supplier.SupplierCode).Result; Assert.IsNotNull(dataSupplier, "Could not read supplier from Database"); Assert.AreEqual(supplier.Name, dataSupplier.Name, "Supplier Name Corrupted on Save"); Assert.AreEqual(supplier.SupplierCode, dataSupplier.SupplierCode, "Supplier Code Corrupted on Save"); }
public void AddProductToSupplierTest() { var controller = new SupplierController(new LoggerStub <SupplierController>()); List <Supplier> suppliers = controller.Search("Test Supplier").Result as List <Supplier>; var no = string.Format("{0:000}", suppliers.Count); var supplier = new Supplier { Name = "Test Supplier", SupplierCode = $"TEST-SUPPLIER-CODE-{no}" }; var supplierId = controller.AddSupplier(supplier.Name, supplier.SupplierCode).Result; Assert.IsNotNull(supplierId, "Failed to create supplier"); var dataSupplier = controller.GetSupplier(supplier.SupplierCode).Result; Assert.IsNotNull(dataSupplier, "Could not read supplier from Database"); Assert.AreEqual(supplier.Name, dataSupplier.Name, "Supplier Name Corrupted on Save"); Assert.AreEqual(supplier.SupplierCode, dataSupplier.SupplierCode, "Supplier Code Corrupted on Save"); var productController = new ProductController(new LoggerStub <ProductController>()); var supplierControl = new SupplierController(new LoggerStub <SupplierController>()); var products = productController.SearchProducts(string.Empty, true).Result as List <Product>; var c = string.Format("{0:000}", products.Count); Assert.IsTrue(!string.IsNullOrEmpty(supplier.Name), "Supplier has no name"); Assert.IsTrue(!string.IsNullOrEmpty(supplier.SupplierCode), "Supplier has no supplier code"); var product = new AddProductToSupplierModel { Description = "Test product", Price = "59.99", ProductCode = $"TEST-PRODUCT-CODE-{c}", SupplierId = supplier.Id.ToString() }; Guid productId = productController.AddProductToSupplier(product).Result; Assert.IsNotNull(productId, "Failed to add prodcut to supplier"); Assert.AreNotEqual(productId, Guid.Empty, "Product ID is empty GUID"); }