public void AddSupplierApplicationPartialTest()
 {
     SupplierApplication testSupplierApp2 = new SupplierApplication();
     testSupplierApp2.ApplicationDate = new DateTime();
     testSupplierApp2.CompanyDescription = "test";
     testSupplierApp2.CompanyName = "name";
     testSupplierApp2.PhoneNumber = "234-234-2341";
     testSupplierApp2.FirstName = "test";
     SupplierMang.AddASupplierApplication(testSupplierApp2);
     TestCleanupAccessor.deleteTestApplication();
 }
        /// <summary>
        /// Miguel Santana
        /// Created:  2015/04/09
        /// Handles loading of the screen with data from the list.
        /// </summary>
        /// <param name="currentSupplierApplication"></param>
        /// <param name="readOnly"></param>
        /// <exception cref="WanderingTurtleException">Occurs making components readonly.</exception>
        public AddEditPendingSupplier(SupplierApplication currentSupplierApplication, bool readOnly = false)
        {
            InitializeComponent();

            _cityStateManager.PopulateCityStateCache();
            CurrentSupplierApplication = currentSupplierApplication;
            Title = "Editing Pending Supplier: " + CurrentSupplierApplication.GetFullName;

            ReloadComboBox();
            FillComboBox();
            SetFields();

            if (readOnly) { (Content as Panel).MakeReadOnly(BtnCancel); }
        }
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/02/08
        /// Retrieves a single Supplier Application Records from the Database
        /// </summary>
        /// <param name="SupplierApplicationID">A string of the SupplierApplicationID of the Supplier Application to be fetched</param>
        /// <returns>SupplierApplication object</returns>
        public static SupplierApplication GetSupplierApplication(String SupplierApplicationID)
        {
            var currentSupplierApplication = new SupplierApplication();
            var conn = DatabaseConnection.GetDatabaseConnection();
            var cmdText = "spSelectSupplierApplication";
            var cmd = new SqlCommand(cmdText, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ApplicationID", SupplierApplicationID);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    currentSupplierApplication.ApplicationID = reader.GetInt32(0);
                    currentSupplierApplication.CompanyName = reader.GetValue(1).ToString();
                    currentSupplierApplication.CompanyDescription = !reader.IsDBNull(2) ? currentSupplierApplication.CompanyDescription = reader.GetString(2) : null;
                    currentSupplierApplication.FirstName = reader.GetValue(3).ToString();
                    currentSupplierApplication.LastName = reader.GetValue(4).ToString();
                    currentSupplierApplication.Address1 = reader.GetValue(5).ToString();
                    currentSupplierApplication.Address2 = reader.GetValue(6).ToString();
                    currentSupplierApplication.Zip = reader.GetValue(7).ToString();
                    currentSupplierApplication.PhoneNumber = reader.GetValue(8).ToString();
                    currentSupplierApplication.EmailAddress = reader.GetValue(9).ToString();
                    currentSupplierApplication.ApplicationDate = reader.GetDateTime(10);
                    currentSupplierApplication.ApplicationStatus = reader.GetValue(11).ToString();
                    currentSupplierApplication.LastStatusDate = reader.GetDateTime(12);
                    currentSupplierApplication.Remarks = !reader.IsDBNull(13) ? currentSupplierApplication.Remarks = reader.GetValue(13).ToString() : null;
                }
                else
                {
                    var ax = new ApplicationException("Supplier Application Not Found!");
                    throw ax;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return currentSupplierApplication;
        }
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/02/08
        /// Inserts a new Supplier Application Record into the Database
        /// </summary>
        /// <param name="supplierApplicationToAdd">A Supplier Application Object that contains all the information to be added</param>
        /// <returns>int reflecting number of rows affected</returns>
        public static int AddSupplierApplication(SupplierApplication supplierApplicationToAdd)
        {
            var conn = DatabaseConnection.GetDatabaseConnection();

            string cmdtext = "spInsertSupplierApplication";
            var cmd = new SqlCommand(cmdtext, conn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@CompanyName", supplierApplicationToAdd.CompanyName);
            cmd.Parameters.AddWithValue("@CompanyDescription", supplierApplicationToAdd.CompanyDescription);
            cmd.Parameters.AddWithValue("@FirstName", supplierApplicationToAdd.FirstName);
            cmd.Parameters.AddWithValue("@LastName", supplierApplicationToAdd.LastName);
            cmd.Parameters.AddWithValue("@Address1", supplierApplicationToAdd.Address1);
            cmd.Parameters.AddWithValue("@Address2", supplierApplicationToAdd.Address2);
            cmd.Parameters.AddWithValue("@Zip", supplierApplicationToAdd.Zip);
            cmd.Parameters.AddWithValue("@PhoneNumber", supplierApplicationToAdd.PhoneNumber);
            cmd.Parameters.AddWithValue("@EmailAddress", supplierApplicationToAdd.EmailAddress);
            cmd.Parameters.AddWithValue("@ApplicationDate", supplierApplicationToAdd.ApplicationDate);
            cmd.Parameters.AddWithValue("@ApplicationStatus", supplierApplicationToAdd.ApplicationStatus);
            cmd.Parameters.AddWithValue("@LastStatusDate", supplierApplicationToAdd.LastStatusDate);
            cmd.Parameters.AddWithValue("@Remarks", supplierApplicationToAdd.Remarks);

            var rowsAffected = 0;

            try
            {
                conn.Open();
                rowsAffected = (int)cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return rowsAffected;
        }
 /// <summary>
 /// Matt Lapka
 /// Created: 2015/02/08
 /// Add a single Supplier Application Record to the database
 /// Throws any exceptions caught by the DAL
 /// </summary>
 /// <remarks>
 /// Pat Banks
 /// Updated:  2015/04/11
 /// Added logic for returning the result of the operations to the presentation layer
 /// </remarks>
 /// <param name="newSupplier">Supplier object containing the information of the supplier to be added</param>
 /// <returns>An int reflecting the number of rows affected</returns>
 public SupplierResult AddASupplierApplication(SupplierApplication newSupplierApp)
 {
     try
     {
         return SupplierApplicationAccessor.AddSupplierApplication(newSupplierApp) == 1 ? SupplierResult.Success : SupplierResult.NotAdded;
     }
     catch (ApplicationException ex)
     {
         return ex.Message == "Concurrency Violation" ? SupplierResult.ChangedByOtherUser : SupplierResult.DatabaseError;
     }
     catch (Exception)
     {
         return SupplierResult.DatabaseError;
     }
 }
        private void Setup(string CompName)
        {
            //set up supplier
            testSupplier = new Supplier();
            testSupplier.CompanyName = CompName;
            testSupplier.FirstName = "FirstBlab";
            testSupplier.LastName = "LastBlab";
            testSupplier.Address1 = "255 East West St";
            testSupplier.Address2 = "APT 1";
            testSupplier.Zip = "50229";
            testSupplier.PhoneNumber = "575-542-8796";
            testSupplier.EmailAddress = "*****@*****.**";
            testSupplier.ApplicationID = 999;
            testSupplier.SupplyCost = (decimal)((60) / 100);
            testSupplier.Active = true;

            //setup Supplier application
            testSupplierApp = new SupplierApplication();
            testSupplierApp.ApplicationDate = new DateTime(2005, 2, 3);
            testSupplierApp.CompanyName = "Awsome Tours";
            testSupplierApp.CompanyDescription = "tours of awsomeness";
            testSupplierApp.PhoneNumber = "575-542-8796";
            testSupplierApp.FirstName = "Test";
            testSupplierApp.Address1 = "255 East West St";
            testSupplierApp.LastName = "blabla";
            testSupplierApp.Zip = "50229";
            testSupplierApp.ApplicationID = 999;
            testSupplierApp.EmailAddress = "*****@*****.**";
            testSupplierApp.Address2 = "";
            testSupplierApp.ApplicationDate = new DateTime(2005, 2, 2);
            testSupplierApp.ApplicationStatus = "pending";
            testSupplierApp.LastStatusDate = new DateTime(2005, 2, 1);
            testSupplierApp.Remarks = "";
        }
 public void RetrieveSupplierApplicationWorkingTest()
 {
     supplierAppID = "100";
     testSupplierAppRetrieval = SupplierMang.RetrieveSupplierApplication(supplierAppID);
     Assert.IsNotNull(testSupplierAppRetrieval);
     TestCleanupAccessor.deleteTestApplication();
 }
 public void RetrieveSupplierApplicationNullIDTest()
 {
     supplierAppID = null;
     testSupplierAppRetrieval = SupplierMang.RetrieveSupplierApplication(supplierAppID);
     Assert.IsNull(testSupplierAppRetrieval);
     TestCleanupAccessor.deleteTestApplication();
 }
 public void AddSupplierApplicationEmptyTest()
 {
     SupplierApplication SupplierAppEmpty = new SupplierApplication();
     SupplierMang.AddASupplierApplication(SupplierAppEmpty);
     TestCleanupAccessor.deleteTestApplication();
 }
        public void EditSupplierApplicationWorkingTest()
        {
            Setup("EditSupAppWorking");
            SupplierApplication testSupplierApp2 = testSupplierApp;
            testSupplierApp2.CompanyName = "Awsomest Tours";
            testSupplierApp2.CompanyDescription = "tours of epicness";
            testSupplierApp2.LastName = "blabla";
            testSupplierApp2.Zip = "50229";
            testSupplierApp2.EmailAddress = "*****@*****.**";
            testSupplierApp2.Address2 = "";
            testSupplierApp.ApplicationDate = new DateTime(2005, 2, 2);
            testSupplierApp.ApplicationStatus = "pending";
            testSupplierApp.LastStatusDate = new DateTime(2005, 2, 1);
            testSupplierApp.Remarks = "";

            SupplierMang.EditSupplierApplication(testSupplierApp, testSupplierApp2);
            testSupplierApp = testSupplierApp2;
            TestCleanupAccessor.DeleteTestSupplier(testSupplier);
        }
 public void EditSupplierApplicationPartialTest()
 {
     SupplierApplication testSupplierAppPartial = new SupplierApplication();
     testSupplierAppPartial.CompanyName = "test";
     testSupplierAppPartial.ApplicationID = 1;
     testSupplierAppPartial.PhoneNumber = "234-234-2341";
     testSupplierAppPartial.FirstName = "test";
     SupplierMang.EditSupplierApplication(testSupplierAppPartial, testSupplierAppPartial);
 }
 public void EditSupplierApplicationEmptyTest()
 {
     SupplierApplication testSupplierAppEmpty = new SupplierApplication();
     SupplierMang.EditSupplierApplication(testSupplierAppEmpty, testSupplierAppEmpty);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Pat Banks
        /// Created:  2015/04/11
        /// Returns the result of approving a supplier application and adds records to the Supplier Table and SupplierLogin tables
        /// </summary>
        /// <param name="oldSupplierApp">The SupplierApplication object to be updated</param>
        /// <param name="updatedSupplierApp">The SupplierApplication object with the updated information</param>
        /// <param name="userName">The username of the Supplier</param>
        /// <param name="supplyCost">The supplier's portion of ticket proceeds</param>
        /// <returns>An enumerated result depicting pass or fail</returns>
        public SupplierResult ApproveSupplierApplication(SupplierApplication oldSupplierApp, SupplierApplication updatedSupplierApp, string userName, decimal supplyCost)
        {
            try
            {
                PasswordManager myPass = new PasswordManager();
                string password = myPass.supplierHash(userName, "Password#1");
                //Approving
                //update db with approval, add supplier record, add supplier login
                int numRows = SupplierApplicationAccessor.UpdateSupplierApplication(oldSupplierApp, updatedSupplierApp, userName, supplyCost, password);

                if (numRows == 3)
                {
                    //refresh cache
                    DataCache._currentSupplierList = SupplierAccessor.GetSupplierList();
                    DataCache._SupplierListTime = DateTime.Now;
                    return SupplierResult.Success;
                }
                return SupplierResult.ChangedByOtherUser;
            }
            catch (SqlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Pat Banks
        /// Created:  2015/04/11
        /// Adds a new supplier from an application with supply cost in the supplier table
        /// Adds User name to the supplier login table.
        /// </summary>
        /// <param name="oldApplication">The SupplierApplication object/record to be updated</param>
        /// <param name="newApplication">The SupplierApplication object with the updated information for the record</param>
        /// <param name="userName">The username for the supplier whose application is being updated</param>
        /// <param name="supplyCost">The updated supply cost</param>
        /// <returns>number of rows affected</returns>
        public static int UpdateSupplierApplication(SupplierApplication oldApplication, SupplierApplication newApplication, string userName, decimal supplyCost, string password)
        {
            var conn = DatabaseConnection.GetDatabaseConnection();
            var cmdText = "spInsertSupplierFromApplication";
            var cmd = new SqlCommand(cmdText, conn);
            var rowsAffected = 0;

            // set command type to stored procedure and add parameters
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserName", userName);
            cmd.Parameters.AddWithValue("@SupplyCost", supplyCost);

            cmd.Parameters.AddWithValue("@CompanyName", newApplication.CompanyName);
            cmd.Parameters.AddWithValue("@CompanyDescription", newApplication.CompanyDescription);
            cmd.Parameters.AddWithValue("@FirstName", newApplication.FirstName);
            cmd.Parameters.AddWithValue("@LastName", newApplication.LastName);
            cmd.Parameters.AddWithValue("@Address1", newApplication.Address1);
            cmd.Parameters.AddWithValue("@Address2", newApplication.Address2);
            cmd.Parameters.AddWithValue("@Zip", newApplication.Zip);
            cmd.Parameters.AddWithValue("@PhoneNumber", newApplication.PhoneNumber);
            cmd.Parameters.AddWithValue("@EmailAddress", newApplication.EmailAddress);
            cmd.Parameters.AddWithValue("@ApplicationDate", newApplication.ApplicationDate);
            cmd.Parameters.AddWithValue("@ApplicationStatus", newApplication.ApplicationStatus);
            cmd.Parameters.AddWithValue("@LastStatusDate", newApplication.LastStatusDate);
            cmd.Parameters.AddWithValue("@Remarks", newApplication.Remarks);

            cmd.Parameters.AddWithValue("@originalApplicationID", oldApplication.ApplicationID);

            cmd.Parameters.AddWithValue("@originalCompanyName", oldApplication.CompanyName);
            cmd.Parameters.AddWithValue("@originalCompanyDescription", oldApplication.CompanyDescription);
            cmd.Parameters.AddWithValue("@originalFirstName", oldApplication.FirstName);
            cmd.Parameters.AddWithValue("@originalLastName", oldApplication.LastName);
            cmd.Parameters.AddWithValue("@originalAddress1", oldApplication.Address1);
            cmd.Parameters.AddWithValue("@originalAddress2", oldApplication.Address2);
            cmd.Parameters.AddWithValue("@originalZip", oldApplication.Zip);
            cmd.Parameters.AddWithValue("@originalPhoneNumber", oldApplication.PhoneNumber);
            cmd.Parameters.AddWithValue("@originalEmailAddress", oldApplication.EmailAddress);
            cmd.Parameters.AddWithValue("@originalApplicationDate", oldApplication.ApplicationDate);
            cmd.Parameters.AddWithValue("@originalApplicationStatus", oldApplication.ApplicationStatus);
            cmd.Parameters.AddWithValue("@originalLastStatusDate", oldApplication.LastStatusDate);
            cmd.Parameters.AddWithValue("@originalRemarks", oldApplication.Remarks);
            cmd.Parameters.AddWithValue("@password", password);

            try
            {
                conn.Open();
                rowsAffected = cmd.ExecuteNonQuery();

                if (rowsAffected == 0)
                {
                    throw new ApplicationException("Concurrency Violation");
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return rowsAffected;
        }
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/02/08
        /// Retrieves a list of all Supplier Application Records from the Database
        /// </summary>
        /// <remarks>
        /// Rose Steffensmeier
        /// Updated: 2015/04/03
        /// added param to input so that stored procedure will work, param does not affect the actual
        /// </remarks>
        /// <returns>List of SupplierApplication objects</returns>
        public static List<SupplierApplication> GetSupplierApplicationList()
        {
            var ApplicationList = new List<SupplierApplication>();
            var conn = DatabaseConnection.GetDatabaseConnection();
            var cmdText = "spSelectAllSupplierApplication";
            var cmd = new SqlCommand(cmdText, conn);
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var currentSupplierApplication = new SupplierApplication();

                        currentSupplierApplication.ApplicationID = (int)reader.GetValue(0);
                        currentSupplierApplication.CompanyName = reader.GetValue(1).ToString();
                        currentSupplierApplication.CompanyDescription = !reader.IsDBNull(2) ? currentSupplierApplication.CompanyDescription = reader.GetValue(2).ToString() : null;
                        currentSupplierApplication.FirstName = reader.GetValue(3).ToString();
                        currentSupplierApplication.LastName = reader.GetValue(4).ToString();
                        currentSupplierApplication.Address1 = reader.GetValue(5).ToString();
                        currentSupplierApplication.Address2 = reader.GetValue(6).ToString();
                        currentSupplierApplication.Zip = reader.GetValue(7).ToString();
                        currentSupplierApplication.PhoneNumber = reader.GetValue(8).ToString();
                        currentSupplierApplication.EmailAddress = reader.GetValue(9).ToString();
                        currentSupplierApplication.ApplicationDate = (DateTime)reader.GetValue(10);
                        currentSupplierApplication.ApplicationStatus = reader.GetValue(11).ToString();
                        currentSupplierApplication.LastStatusDate = reader.GetDateTime(12);
                        currentSupplierApplication.Remarks = !reader.IsDBNull(13) ? currentSupplierApplication.Remarks = reader.GetValue(13).ToString() : null;

                        ApplicationList.Add(currentSupplierApplication);
                    }
                }
                else
                {
                    var ex = new ApplicationException("No Supplier Applications Found!");
                    throw ex;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return ApplicationList;
        }
 /// <summary>
 /// Miguel Santana
 /// Created:  2015/04/15
 /// opens pending supplier dialog
 /// </summary>
 /// <param name="selectedItem"></param>
 /// <param name="readOnly"></param>
 private void OpenPendingSupplier(SupplierApplication selectedItem = null, bool readOnly = false)
 {
     try
     {
         if (selectedItem == null)
         {
             if (new AddEditPendingSupplier().ShowDialog() == false) return;
             LoadPendingSuppliers();
         }
         else
         {
             if (new AddEditPendingSupplier(selectedItem, readOnly).ShowDialog() == false) return;
             if (readOnly) return;
             LoadPendingSuppliers();
         }
     }
     catch (Exception ex)
     {
         throw new WanderingTurtleException(this, ex);
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/02/08
        /// Updates a Supplier Application Record
        /// Throws any exceptions caught by the DAL
        /// </summary>
        /// <remarks>
        /// Pat Banks
        /// Updated:  2015/04/11
        /// Added logic for returning the result of the operations to the presentation layer
        /// </remarks>
        /// <param name="newSupplier">Supplier object containing the new information of the supplier</param>
        /// <param name="oldSupplier">Supplier object containing the current information of the supplier to be matched to salve concurrency problems</param>
        /// <returns>An int reflecting the of rows affected</returns>
        public SupplierResult EditSupplierApplication(SupplierApplication oldSupplierApp, SupplierApplication updatedSupplierApp)
        {
            try
            {
                if (updatedSupplierApp.ApplicationStatus.Equals(ApplicationStatus.Pending.ToString()))
                {
                    //just editing application - still Pending
                    //update db with new info not related to approval
                    int numRows = SupplierApplicationAccessor.UpdateSupplierApplication(oldSupplierApp, updatedSupplierApp);

                    if (numRows == 1)
                    {
                        RetrieveSupplierApplicationList();
                        return SupplierResult.Success;
                    }
                    return SupplierResult.ChangedByOtherUser;
                }
                //Rejecting the application
                if (updatedSupplierApp.ApplicationStatus.Equals(ApplicationStatus.Rejected.ToString()))
                {
                    //update db with rejection
                    int numRows = SupplierApplicationAccessor.UpdateSupplierApplication(oldSupplierApp, updatedSupplierApp);

                    return numRows == 1 ? SupplierResult.Success : SupplierResult.ChangedByOtherUser;
                }
                return SupplierResult.NotChanged;
            }
            catch (ApplicationException ex)
            {
                return ex.Message == "Concurrency Violation." ? SupplierResult.ChangedByOtherUser : SupplierResult.DatabaseError;
            }
            catch (Exception)
            {
                return SupplierResult.DatabaseError;
            }
        }
        /// <summary>
        /// Kelsey Blount 
        /// Created 2015/04/07
        /// submits data to bll for supplier application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmitApplication_Click(object sender, EventArgs e)
        {
            clearBorderColors();
            int errorCount = 0;
            lblFinish.Text = "";
            //Validate
            if (validateText(txtCompanyName, "Please enter a company name")) errorCount++;
            if (validateName(txtFirstName, "Please enter your first name")) errorCount++;
            if (validateName(txtLastName, "Please enter your second name")) errorCount++;
            if (validateText(txtAddress, "Please enter your address")) errorCount++;
            //check zips
            bool goodZip = false;
            foreach (var zip in zips)
            {
                if (txtZip.Text == zip.Zip)
                {
                    goodZip = true;
                }
            }
            if (!goodZip)
            {
                txtZip.ToolTip = "Please enter a valid Zip Code";
                txtZip.BorderColor = Color.Red;
                errorCount++;
            }

            if (validateText(txtDescription, "Please enter your description")) errorCount++;
            if (!txtEmail.Text.ValidateEmail())
            {
                txtEmail.ToolTip = "Please enter a valid e-mail";
                txtEmail.BorderColor = Color.Red;
                errorCount++;
            }
            else
            {
                txtEmail.ToolTip = "";
                txtEmail.BorderColor = Color.Empty;
            }
            if (!txtPhoneNumber.Text.ValidatePhone())
            {
                txtPhoneNumber.ToolTip = "Please enter a valid phone number";
                txtPhoneNumber.BorderColor = Color.Red;
            }
            else
            {
                txtPhoneNumber.ToolTip = "";
                txtPhoneNumber.BorderColor = Color.Empty;
            }

            if (errorCount > 0)
            {
                showError("You have " + errorCount + " errors that need to be fixed.");
                return;
            }
            else
            {
                //reset border colors
                clearBorderColors();

                try
                {
                    //create new Suppler Application
                    SupplierApplication application = new SupplierApplication(txtCompanyName.Text, txtDescription.Text, txtFirstName.Text, txtLastName.Text, txtAddress.Text, txtAddress2.Text, txtZip.Text, txtPhoneNumber.Text, txtEmail.Text, DateTime.Now);
                    SupplierResult result = ApplicationManager.AddASupplierApplication(application);

                    if (result==SupplierResult.Success)
                    {
                        showError("Thank you for your Application!<br /> We will be in contact once we have reviewed the information. ");
                        clearForm();
                    }
                }
                catch (Exception ex)
                {
                    showError(ex.Message);
                }
            }
        }