Exemple #1
0
    public static object InsertBuildingPermit(List <BuildingPDirty> insertParams)
    {
        try
        {
            int rowsInserted = 0;

            Validator validator = new Validator(insertParams[0]);

            if (validator.AllAreValid)
            {
                BuildingPDirty buildingPDirty = insertParams[0];
                buildingPDirty.PassedValidation = true;

                BuildingP           buildingP           = new BuildingP(insertParams[0]);
                BuildingPCollection buildingPCollection = new BuildingPCollection();
                buildingPCollection.BuildingPList.Add(buildingP);

                DataA dataA = new DataA();
                rowsInserted = dataA.InsertPermitData(buildingPCollection);
            }
            else
            {
                return("inputsInvalid");
            }

            return(rowsInserted);
        }
        catch (Exception)
        {
            return("serverError");
        }
    }
        protected void SubmitButtonClick(object sender, EventArgs e)
        {
            try
            {
                BuildingPDirty buildingPDirty = new BuildingPDirty(
                    tbxApplicantFirstName.Value,
                    tbxApplicantLastName.Value,
                    tbxSquareFeet.Value,
                    tbxHeightInFeet.Value,
                    tbxStartDate.Value,
                    tbxEstimatedEndDate.Value,
                    tbxAddress.Value,
                    tbxCity.Value,
                    tbxZip.Value,
                    ddlRemodelOrNewConstruction.SelectedValue);

                Validator validatorSubmission = new Validator(buildingPDirty);

                if (!validatorSubmission.AllAreValid)
                {
                    buildingPDirty.PassedValidation = false;
                    ToggleInputValidationMessages(validatorSubmission);
                }
                else
                {
                    buildingPDirty.PassedValidation = true;

                    BuildingP buildingP = new BuildingP(buildingPDirty);
                    ToggleInputValidationMessages(validatorSubmission);

                    BuildPCollection buildingPCollection = new BuildPCollection();
                    buildingPCollection.BuildingPList.Add(buildingP);

                    DataA dataA = new DataA();

                    if (dataA.InsertPermitData(buildingPCollection) == 1)
                    {
                        insertFeedback.InnerHtml =
                            "<span style='color:green;font-weight:bold;'>Application submitted</span>";
                    }
                    else
                    {
                        insertFeedback.InnerHtml =
                            "<span style='color:red;font-weight:bold;'>Application submission failed. Please try again.</span>";
                    }

                    LoadPermits();
                }
            }
            catch (Exception ex)
            {
                this.ReportExceptions(ex, "Error while saving new permit. ", "");
            }
        }
        public Validator(BuildingPDirty buildingPDirty)
        {
            GenericValidator genericValidator = new GenericValidator();

            int permitIdInt = 0;

            if (buildingPDirty.PermitId == "")
            {
                isPermitIdValid = true;
            }
            else if (int.TryParse(buildingPDirty.PermitId, out permitIdInt) && permitIdInt > 0 &&
                     permitIdInt < int.MaxValue)
            {
                isPermitIdValid = true;
            }
            else
            {
                isPermitIdValid = false;
            }

            isApplicantFirstNameValid = genericValidator.MinMaxStringLengthValidation(
                1,
                true,
                40,
                true,
                buildingPDirty.ApplicantFirstName);

            isApplicantLastNameValid = genericValidator.MinMaxStringLengthValidation(
                1,
                true,
                40,
                true,
                buildingPDirty.ApplicantLastName);

            areSquareFeetValid = genericValidator.MinMaxRangeValidationFloat(
                500,
                true,
                40000,
                false,
                buildingPDirty.SquareFeet);

            isHeightValid = genericValidator.MinMaxRangeValidationFloat(10, true, 95, false, buildingPDirty.Height);

            DateTime startDate = new DateTime();

            if (DateTime.TryParse(buildingPDirty.ConstructionStartDate, out startDate))
            {
                if (startDate < DateTime.Today.Date)
                {
                    isStartDateValid = false;
                }
            }
            else
            {
                isStartDateValid = false;
            }

            if (buildingPDirty.EstimatedCompletionDate != "")
            {
                DateTime estimatedEndDate = new DateTime();
                if (DateTime.TryParse(buildingPDirty.EstimatedCompletionDate, out estimatedEndDate))
                {
                    if (!(isStartDateValid && (estimatedEndDate > startDate)))
                    {
                        isEstimatedEndDateValid = false;
                    }
                }
                else
                {
                    isEstimatedEndDateValid = false;
                }
            }

            isAddressValid = genericValidator.MinMaxStringLengthValidation(1, true, 49, true, buildingPDirty.Address);

            isCityValid = genericValidator.MinMaxStringLengthValidation(1, true, 49, true, buildingPDirty.City);

            isZipValid = genericValidator.ZipCodeRegexValidation(buildingPDirty.Zip);

            if (buildingPDirty.RemodelOrNewConstruction.ToLower() != "r" &&
                buildingPDirty.RemodelOrNewConstruction.ToLower() != "n")
            {
                isZipValid = false;
            }

            if (
                !(isPermitIdValid && isApplicantFirstNameValid && isApplicantLastNameValid && areSquareFeetValid &&
                  isHeightValid && isStartDateValid && isEstimatedEndDateValid && isAddressValid && isCityValid &&
                  isZipValid && isRemodelOrNewConstructionValid))
            {
                allAreValid = false;
            }
        }
        public void SaveOrEditRows(object sender, EventArgs e)
        {
            try
            {
                if (dgPermits.Items.Count > 0)
                {
                    Button btn         = (Button)sender;
                    string senderValue = btn.Text;

                    if (senderValue == "Edit")
                    {
                        cancelButton.Enabled = true;
                        saveButton.Enabled   = true;
                    }

                    BuildingPDirtyCollection buildingPDirtyCollection = new BuildingPDirtyCollection();

                    foreach (DataGridItem row in dgPermits.Items)
                    {
                        var cbx = row.FindControl("CheckBox1");

                        if (cbx is CheckBox)
                        {
                            CheckBox cb = (CheckBox)cbx;
                            if (cb.Checked)
                            {
                                BuildingPDirty buildingPDirtySave = new BuildingPDirty();

                                foreach (var c in row.Cells)
                                {
                                    if (c is TableCell)
                                    {
                                        TableCell t = (TableCell)c;

                                        foreach (var ctl in t.Controls)
                                        {
                                            if (ctl is TextBox)
                                            {
                                                TextBox tb = (TextBox)ctl;

                                                if (senderValue == "Edit")
                                                {
                                                    tb.Enabled = true;
                                                }
                                                else if (senderValue == "Save")
                                                {
                                                    string tbId = tb.ID;

                                                    switch (tbId)
                                                    {
                                                    case "PermitIDCell":
                                                        buildingPDirtySave.PermitIdStr = tb.Text;
                                                        break;

                                                    case "FirstNameCell":
                                                        buildingPDirtySave.ApplicantFirstNameStr = tb.Text;
                                                        break;

                                                    case "LastNameCell":
                                                        buildingPDirtySave.ApplicantLastNameStr = tb.Text;
                                                        break;

                                                    //case "RemodelOrNewCell":
                                                    //    buildingPDirtySave.RemodelOrNewConstructionStr = tb.Text;
                                                    //    break;
                                                    case "AddressCell":
                                                        buildingPDirtySave.AddressStr = tb.Text;
                                                        break;

                                                    case "CityCell":
                                                        buildingPDirtySave.CityStr = tb.Text;
                                                        break;

                                                    case "ZIPCell":
                                                        buildingPDirtySave.ZipStr = tb.Text;
                                                        break;

                                                    case "SquareFeetCell":
                                                        buildingPDirtySave.SquareFeetStr = tb.Text;
                                                        break;

                                                    case "HeightCell":
                                                        buildingPDirtySave.HeightInFeetStr = tb.Text;
                                                        break;

                                                    case "StartDateCell":
                                                        buildingPDirtySave.StartDateStr = tb.Text;
                                                        break;

                                                    case "EndDateCell":
                                                        buildingPDirtySave.EstimatedEndDateStr = tb.Text;
                                                        break;
                                                    }
                                                }
                                            }
                                            else if (ctl is DropDownList)
                                            {
                                                DropDownList ddl = (DropDownList)ctl;
                                                if (senderValue == "Edit")
                                                {
                                                    ddl.Enabled = true;
                                                }
                                                else if (senderValue == "Save")
                                                {
                                                    if (ddl.ID == "RemodelOrNewCell")
                                                    {
                                                        buildingPDirtySave.RemodelOrNewConstructionStr = ddl.SelectedValue;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                if (senderValue == "Save")
                                {
                                    buildingPDirtyCollection.BuildingPDirtyList.Add(buildingPDirtySave);
                                }
                            }
                        }
                    }

                    if (senderValue == "Save")
                    {
                        BuildPCollection buildPCollection = new BuildPCollection();

                        foreach (BuildingPDirty buildingPDirty in buildingPDirtyCollection.BuildingPDirtyList)
                        {
                            Validator validatorSave = new Validator(buildingPDirty);
                            if (validatorSave.AllAreValid)
                            {
                                buildingPDirty.PassedValidation = true;
                                BuildingP buildingP = new BuildingP(buildingPDirty);
                                buildPCollection.BuildingPList.Add(buildingP);
                            }
                        }

                        DataA dataA = new DataA();

                        if (dataA.UpdatePermitData(buildPCollection) > 0)
                        {
                            insertFeedback.InnerHtml = "<span style='color:green;font-weight:bold;'>Changes Saved</span>";
                        }
                        else
                        {
                            insertFeedback.InnerHtml =
                                "<span style='color:red;font-weight:bold;'>Errors while saving. Please try again.</span>";
                        }

                        LoadPermits();
                    }
                }
            }
            catch (Exception ex)
            {
                this.ReportExceptions(ex, "Error while saving or editing permit(s). ", "");
            }
        }
Exemple #5
0
    public static object SearchLinkedBuildingPermits(List <BuildingPDirty> searchParams)
    {
        string firstName = searchParams[0].ApplicantFirstName;
        string lastName  = searchParams[0].ApplicantLastName;

        try
        {
            //BuildingPCollection linkedBuildingPermitsCollection = new BuildingPCollection();
            BuildingPDirtyCollection linkedBuildingPermitsCollection = new BuildingPDirtyCollection();

            if (firstName.Length < 41 && lastName.Length < 41)
            {
                DataA     dataA = new DataA();
                DataTable linkedBuildingPermits = dataA.SearchBuildingPermits(firstName, lastName);

                if (linkedBuildingPermits.Rows.Count > 0)
                {
                    foreach (DataRow r in linkedBuildingPermits.Rows)
                    {
                        BuildingPDirty buildingPDirty = new BuildingPDirty();
                        buildingPDirty.ApplicantFirstName    = r["ApplicantFirstName"].ToString();
                        buildingPDirty.ApplicantLastName     = r["ApplicantLastName"].ToString();
                        buildingPDirty.SquareFeet            = r["SquareFeet"].ToString();
                        buildingPDirty.Height                = r["Height"].ToString();
                        buildingPDirty.ConstructionStartDate = r["StartDate"].ToString();
                        if (r["EndDate"].ToString() == DateTime.MaxValue.ToString())
                        {
                            buildingPDirty.EstimatedCompletionDate = "";
                        }
                        else
                        {
                            //DateTime endDateLong = DateTime.Parse(r["EndDate"].ToString());
                            buildingPDirty.EstimatedCompletionDate = r["EndDate"].ToString();
                        }
                        buildingPDirty.Address = r["Address"].ToString();
                        buildingPDirty.City    = r["City"].ToString();
                        buildingPDirty.Zip     = r["Zip"].ToString();
                        buildingPDirty.RemodelOrNewConstruction = r["RemodelOrNewConstruction"].ToString();
                        buildingPDirty.PermitId = r["PermitID"].ToString();
                        //buildingPDirty.PassedValidation = true;
                        //BuildingP buildingP = new BuildingP(buildingPDirty);
                        linkedBuildingPermitsCollection.BuildingPDirtyList.Add(buildingPDirty);
                    }
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return("firstNameOrLastNameTooLong");
            }

            return(linkedBuildingPermitsCollection);
        }
        catch (Exception)
        {
            return("serverError");
        }
    }
Exemple #6
0
 public Validator(BuildingPDirty buildingPDirty)
 {
     this.Validate(buildingPDirty);
 }