/// <summary>
        /// Set Grid Data source
        /// </summary>
        /// <param name="addRow"></param>
        /// <param name="deleteRow"></param>e
        private void BindGrid()
        {
            Non_perm_structureBLL BLLobj = new Non_perm_structureBLL();

            grdNPS.DataSource = BLLobj.GetNPS(Convert.ToInt32(Session["HH_ID"]));
            grdNPS.DataBind();
        }
 /// <summary>
 /// Set edit mode for edit comand
 /// Delete data from the database for delete comand
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void grdUsers_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "EditRow")
     {
         ViewState["NONPERM_STRUCTUREID"] = e.CommandArgument;
         // lnkViewPhoto.Visible = true;
         popupData();
         GetNPS1();
         SetUpdateMode(true);
     }
     else if (e.CommandName == "DeleteRow")
     {
         string NonPermanentStructureID = e.CommandArgument.ToString();
         Non_perm_structureBLL BLLobj   = new Non_perm_structureBLL();
         BLLobj.Delete(NonPermanentStructureID);
         SetUpdateMode(false);
         BindGrid();
         clearfields();
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('Data deleted successfully');", true);
     }
 }
        /// <summary>
        /// To save details to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int count = 0;
            Non_perm_structureBLL   BLLobj = new Non_perm_structureBLL();
            NonPermanentStructureBO BOobj  = null;

            if (Convert.ToInt32(ViewState["NONPERM_STRUCTUREID"]) > 0)
            {
                // update

                string uID  = Session["USER_ID"].ToString();
                string hhid = Session["HH_ID"].ToString();
                try
                {
                    if (photoFileUpload.HasFile)
                    {
                        NonPermanentStructureBO BOobj1 = new NonPermanentStructureBO();
                        byte[] fileBytes = photoFileUpload.FileBytes;
                        BOobj1.NonPermanentStructureID = Convert.ToInt32(IDTextBox1.Text);
                        BOobj1.HouseholdID             = Convert.ToInt32(hhid);
                        BOobj1.UpdatedBy = Convert.ToInt32(uID);
                        BOobj1.Photo     = fileBytes;


                        Non_perm_structureBLL pBLLobj = new Non_perm_structureBLL();
                        count = pBLLobj.Updatephoto(BOobj1);
                    }

                    BOobj = new NonPermanentStructureBO();

                    BOobj.NonPermanentStructureID = Convert.ToInt32(ViewState["NONPERM_STRUCTUREID"]);

                    BOobj.StructureTypeID      = Convert.ToInt32(buildingtypeDropDownList.SelectedValue);
                    BOobj.CategoryID           = Convert.ToInt32(categoryDropDownList.SelectedValue);
                    BOobj.StructureConditionID = Convert.ToInt32(conditionDropDownList.SelectedValue);
                    BOobj.OccupantStatusID     = Convert.ToInt32(occupantstatusDropDownList.SelectedValue.ToString());
                    if (noofroomsTextBox.Text != string.Empty)
                    {
                        BOobj.NoOfRooms = Convert.ToInt32(noofroomsTextBox.Text);
                    }
                    else
                    {
                        BOobj.NoOfRooms = 0;
                    }
                    //BOobj.NoOfRooms = Convert.ToInt32(noofroomsTextBox.Text.ToString().Trim());
                    if (surfaceareaTextBox.Text != string.Empty)
                    {
                        BOobj.SurfaceArea = Convert.ToDecimal(surfaceareaTextBox.Text);
                    }
                    else
                    {
                        BOobj.SurfaceArea = 0;
                    }
                    //BOobj.SurfaceArea = Convert.ToInt32(surfaceareaTextBox.Text.ToString().Trim());
                    BOobj.OtherStructureType  = otherspecifyTextBox.Text.ToString().Trim();
                    BOobj.DimensionLength     = Convert.ToInt32(lengthTextBox.Text.ToString().Trim());
                    BOobj.DimensionWidth      = Convert.ToInt32(widthTextBox.Text.ToString().Trim());
                    BOobj.OtherOccupantStatus = occupantstatusTextBox.Text.ToString().Trim();
                    BOobj.CreatedBy           = Convert.ToInt32(uID);;


                    if (RadioButton1.Checked == true)
                    {
                        BOobj.Owner = "Self";
                        //RadioButton2.Checked = false;
                    }
                    else if (RadioButton2.Checked == true)
                    {
                        BOobj.Owner     = "Other";
                        BOobj.OwnerName = otherTextBox.Text;
                    }

                    if (RadioButton3.Checked == true)
                    {
                        BOobj.Occupant = "Self";
                        //RadioButton2.Checked = false;
                    }
                    else if (RadioButton4.Checked == true)
                    {
                        BOobj.Occupant          = "Other";
                        BOobj.OtherOccupantName = otherselfoccupantTextBox.Text.ToString();
                        //RadioButton1.Checked = false;
                    }
                    //if (photoFileUpload.HasFile)
                    //{
                    //    byte[] fileBytes = photoFileUpload.FileBytes;

                    //    if (fileBytes != null)
                    //    {
                    //        BOobj.Photo = fileBytes;
                    //    }

                    //}

                    BLLobj = new Non_perm_structureBLL();
                    count  = BLLobj.EditNPS(BOobj);
                    projectFrozen();

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Updated", "ShowUpdateMessage('');", true);
                    clearfields();
                    BindGrid();
                    SetUpdateMode(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                finally
                {
                    BLLobj = null;
                }
            }
            else
            {
                // insert
                string uID  = Session["USER_ID"].ToString();
                string hhid = Session["HH_ID"].ToString();
                //try
                //{
                BOobj = new NonPermanentStructureBO();

                BOobj.StructureTypeID = Convert.ToInt32(buildingtypeDropDownList.SelectedValue.ToString());
                if (otherspecifyTextBox.Text != string.Empty)
                {
                    BOobj.OtherStructureType = otherspecifyTextBox.Text;
                }
                else
                {
                    BOobj.OtherStructureType = "";
                }

                BOobj.CategoryID           = Convert.ToInt32(categoryDropDownList.SelectedValue.ToString());
                BOobj.StructureConditionID = Convert.ToInt32(conditionDropDownList.SelectedValue.ToString());

                BOobj.OccupantStatusID    = Convert.ToInt32(occupantstatusDropDownList.SelectedValue.ToString());
                BOobj.OtherOccupantStatus = occupantstatusTextBox.Text.ToString().Trim();
                if (lengthTextBox.Text != string.Empty)
                {
                    BOobj.DimensionLength = Convert.ToDecimal(lengthTextBox.Text);
                }
                else
                {
                    BOobj.DimensionLength = Convert.ToDecimal(0);
                }

                if (widthTextBox.Text != string.Empty)
                {
                    BOobj.DimensionWidth = Convert.ToDecimal(widthTextBox.Text);
                }
                else
                {
                    BOobj.DimensionWidth = Convert.ToDecimal(0);
                }

                if (noofroomsTextBox.Text != string.Empty)
                {
                    BOobj.NoOfRooms = Convert.ToInt32(noofroomsTextBox.Text);
                }
                else
                {
                    BOobj.NoOfRooms = 0;
                }
                if (surfaceareaTextBox.Text != string.Empty)
                {
                    BOobj.SurfaceArea = Convert.ToDecimal(surfaceareaTextBox.Text);
                }
                else
                {
                    BOobj.SurfaceArea = 0;
                }

                if (RadioButton1.Checked == true || (RadioButton1.Checked == false && RadioButton2.Checked == false))
                {
                    BOobj.Owner = "Self";
                }
                else if (RadioButton2.Checked == true)
                {
                    BOobj.Owner     = "Other";
                    BOobj.OwnerName = otherTextBox.Text.ToString();
                }

                if (RadioButton3.Checked == true || (RadioButton3.Checked == false && RadioButton4.Checked == false))
                {
                    BOobj.Occupant = "Self";
                }
                else if (RadioButton4.Checked == true)
                {
                    BOobj.Occupant          = "Other";
                    BOobj.OtherOccupantName = otherselfoccupantTextBox.Text.ToString();
                }

                if (photoFileUpload.HasFile)
                {
                    byte[] fileBytes = photoFileUpload.FileBytes;

                    if (fileBytes != null)
                    {
                        BOobj.Photo = fileBytes;
                    }
                }

                if (photoFileUpload.HasFile)
                {
                    byte[] fileBytes = photoFileUpload.FileBytes;

                    if (fileBytes != null)
                    {
                        BOobj.Photo = fileBytes;
                    }
                }

                BOobj.CreatedBy   = Convert.ToInt32(uID);
                BOobj.HouseholdID = Convert.ToInt32(hhid);

                Non_perm_structureBLL structureBLLobj = new Non_perm_structureBLL();
                count = structureBLLobj.Insert(BOobj);
                clearfields();
                BindGrid();
                SetUpdateMode(false);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "ShowSaveMessage('');", true);

                //}
                //catch (Exception ex)
                //{
                //    throw ex;
                //}

                //finally
                //{
                //    BLLobj = null;
                //}
            }
            ChangeRequestStatusNonPermStr();
            projectFrozen();
        }
        /// <summary>
        /// To fetch details and assign to textbox
        /// </summary>
        private void GetNPS1()
        {
            Non_perm_structureBLL BLLobj = new Non_perm_structureBLL();
            int NonPermanentStructureID  = 0;

            if (ViewState["NONPERM_STRUCTUREID"] != null)
            {
                NonPermanentStructureID = Convert.ToInt32(ViewState["NONPERM_STRUCTUREID"]);
            }

            NonPermanentStructureBO BOobj = new NonPermanentStructureBO();

            BOobj = BLLobj.GetNPSId(NonPermanentStructureID);

            IDTextBox1.Text = BOobj.NonPermanentStructureID.ToString();

            noofroomsTextBox.Text    = BOobj.NoOfRooms.ToString();
            lengthTextBox.Text       = BOobj.DimensionLength.ToString();
            widthTextBox.Text        = BOobj.DimensionWidth.ToString();
            surfaceareaTextBox.Text  = BOobj.SurfaceArea.ToString();
            otherspecifyTextBox.Text = BOobj.OtherStructureType.ToString();

            otherTextBox.Enabled = false;
            if (BOobj.Owner == "Self")
            {
                RadioButton1.Checked = true;
            }
            else
            {
                RadioButton2.Checked = true;
                otherTextBox.Enabled = true;
                otherTextBox.Text    = BOobj.OwnerName.ToString();
            }


            otherselfoccupantTextBox.Enabled = false;
            if (BOobj.Occupant == "Self")
            {
                RadioButton3.Checked = true;
            }
            else
            {
                RadioButton4.Checked             = true;
                otherselfoccupantTextBox.Enabled = true;
                otherselfoccupantTextBox.Text    = BOobj.OtherOccupantName.ToString();
            }


            buildingtypeDropDownList.ClearSelection();
            if (buildingtypeDropDownList.Items.FindByValue(BOobj.StructureTypeID.ToString()) != null)
            {
                buildingtypeDropDownList.Items.FindByValue(BOobj.StructureTypeID.ToString()).Selected = true;
            }

            occupantstatusDropDownList.ClearSelection();
            if (occupantstatusDropDownList.Items.FindByValue(BOobj.OccupantStatusID.ToString()) != null)
            {
                occupantstatusDropDownList.Items.FindByValue(BOobj.OccupantStatusID.ToString()).Selected = true;
            }


            categoryDropDownList.ClearSelection();
            if (categoryDropDownList.Items.FindByValue(BOobj.CategoryID.ToString()) != null)
            {
                categoryDropDownList.Items.FindByValue(BOobj.CategoryID.ToString()).Selected = true;
            }

            conditionDropDownList.ClearSelection();
            if (conditionDropDownList.Items.FindByValue(BOobj.StructureConditionID.ToString()) != null)
            {
                conditionDropDownList.Items.FindByValue(BOobj.StructureConditionID.ToString()).Selected = true;
            }
        }