Example #1
0
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            // We check to make sure we have legitimate data inputs
            Boolean isTitleValid       = (!string.IsNullOrWhiteSpace(tb_title.Text));
            Boolean isDescriptionValid = (!string.IsNullOrWhiteSpace(tb_description.Text));
            Boolean isTechnicianValid  = (Convert.ToInt32(ddl_technicians.SelectedValue) > 0);
            Boolean isProductValid     = (!string.IsNullOrWhiteSpace(ddl_products.SelectedValue));

            Boolean allValid = (isDescriptionValid && isProductValid && isTechnicianValid && isTitleValid);

            // If all input is valid, we create a new Incident and add it to our data model
            if (allValid)
            {
                Incident newIncident = new Incident();

                newIncident.CustomerID  = Convert.ToInt32(ddl_customers.SelectedValue);
                newIncident.ProductCode = ddl_products.SelectedValue;
                newIncident.TechID      = Convert.ToInt32(ddl_technicians.SelectedValue);
                newIncident.DateOpened  = DateTime.Now;
                newIncident.DateClosed  = null;
                newIncident.Title       = tb_title.Text;
                newIncident.Description = tb_description.Text;

                TechSupportContext newContext = new TechSupportContext();

                newContext.addIncident(newIncident);

                // We make sure any error messages are no longer visible, inform the user of success, and clear the textboxes
                hideAllErrorMessages();
                lbl_submitted.ForeColor = System.Drawing.Color.Black;
                lbl_submitted.Text      = "Incident \"" + tb_title.Text + "\" has been added.";
                tb_title.Text           = "";
                tb_description.Text     = "";

                // The following code is for making sure that the open incident drop down list
                // and the accordion refresh when the data has been altered.
                // I feel like there must be a better way to handle this, but this is what I have for now.
                List <Incident> incident = newContext.returnIncidents(Convert.ToInt32(ddl_customers.SelectedValue));
                List <SportsPro.Models.Incident> openIncidents = newContext.getOpenIncidents();
                Accd_Incident_View.DataSource    = incident;
                ddl_openIncidents.DataSource     = openIncidents;
                ddl_openIncidents.DataValueField = "IncidentID";
                ddl_openIncidents.DataTextField  = "IncidentID";

                ddl_openIncidents.DataBind();
                Accd_Incident_View.DataBind();
            }
            else
            {
                // If there is a problem with one of the inputs, we display the appropriate error messages
                if (!isTitleValid)
                {
                    lbl_titleError.Visible = true;
                }
                if (!isDescriptionValid)
                {
                    lbl_descError.Visible = true;
                }
                if (!isTechnicianValid)
                {
                    lbl_technicianError.Visible = true;
                }
                if (!isProductValid)
                {
                    lbl_productsError.Visible = true;
                }

                lbl_submitted.ForeColor = System.Drawing.Color.Red;
                lbl_submitted.Text      = "Please enter all information correctly";
            }
        }