Esempio n. 1
0
    public static object UpdateLinkedBuildingPermits(List <BuildingPDirty> updateParams)
    {
        try
        {
            int rowsInserted = 0;

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

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

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

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

            return(rowsInserted);
        }
        catch (Exception)
        {
            return("serverError");
        }
    }
        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). ", "");
            }
        }