private void BindResourceEmployeeInfoNew()
        {
            try
            {
                IList <ListViewDataItem> list = lvCRMContactList.Items;

                if (list != null && list.Count > 0)
                {
                    foreach (ListViewDataItem lvdi in list)
                    {
                        CheckBox chkSelectResourceLV = (CheckBox)lvdi.FindControl("chkSelectResourceLV");

                        if (chkSelectResourceLV.Checked == true)
                        {
                            Int64    resourceIDLV, resourceCategoryIDLV;
                            Int64?   resourceTypeID;
                            String   resourceName, resourceDesignation, resourceCompany, resourceMobileNo, resourceEmail, addressLine1, addressLine2;
                            DateTime?resourceDOB;


                            Label lblResourceIDLV          = (Label)lvdi.FindControl("lblResourceIDLV");
                            Label lblResourceCategoryIDLV  = (Label)lvdi.FindControl("lblResourceCategoryIDLV");
                            Label lblResourceNameLV        = (Label)lvdi.FindControl("lblResourceNameLV");
                            Label lblResourceDesignationLV = (Label)lvdi.FindControl("lblResourceDesignationLV");
                            Label lblResourceCompanyLV     = (Label)lvdi.FindControl("lblResourceCompanyLV");
                            Label lblResourceMobileNoLV    = (Label)lvdi.FindControl("lblResourceMobileNoLV");
                            Label lblResourceEmailLV       = (Label)lvdi.FindControl("lblResourceEmailLV");
                            Label lblAddressLine1          = (Label)lvdi.FindControl("lblAddressLine1");
                            Label lblAddressLine2          = (Label)lvdi.FindControl("lblAddressLine2");
                            Label lblResourceTypeIDLV      = (Label)lvdi.FindControl("lblResourceTypeIDLV");
                            Label lblResourceDOBLV         = (Label)lvdi.FindControl("lblResourceDOBLV");

                            Int64.TryParse(lblResourceIDLV.Text, out resourceIDLV);
                            Int64.TryParse(lblResourceCategoryIDLV.Text, out resourceCategoryIDLV);

                            resourceName        = lblResourceNameLV.Text.Trim();
                            resourceDesignation = lblResourceDesignationLV.Text.Trim();
                            resourceCompany     = lblResourceCompanyLV.Text.Trim();
                            resourceMobileNo    = lblResourceMobileNoLV.Text.Trim();
                            resourceEmail       = lblResourceEmailLV.Text.Trim();
                            if (!lblResourceTypeIDLV.Text.Trim().IsNullOrEmpty())
                            {
                                resourceTypeID = Int64.Parse(lblResourceTypeIDLV.Text.Trim());
                            }
                            else
                            {
                                resourceTypeID = null;
                            }

                            if (lblResourceDOBLV.Text.Trim().IsNotNullOrEmpty())
                            {
                                resourceDOB = MiscUtil.ParseToDateTime(lblResourceDOBLV.Text);
                            }
                            else
                            {
                                resourceDOB = null;
                            }

                            if (lblAddressLine1.Text.Trim().IsNotNullOrEmpty())
                            {
                                addressLine1 = lblAddressLine1.Text.Trim();
                            }
                            else
                            {
                                addressLine1 = null;
                            }

                            if (lblAddressLine2.Text.Trim().IsNotNullOrEmpty())
                            {
                                addressLine2 = lblAddressLine2.Text.Trim();
                            }
                            else
                            {
                                addressLine2 = null;
                            }


                            CRMContactList_CustomEntity cRMContactList_CustomEntity = new CRMContactList_CustomEntity();

                            cRMContactList_CustomEntity.ResourceID          = resourceIDLV;
                            cRMContactList_CustomEntity.ResourceCategoryID  = resourceCategoryIDLV.ToString();
                            cRMContactList_CustomEntity.ResourceName        = resourceName;
                            cRMContactList_CustomEntity.ResourceCompany     = resourceCompany;
                            cRMContactList_CustomEntity.ResourceDesignation = resourceDesignation;
                            cRMContactList_CustomEntity.ResourceEmail       = resourceEmail;
                            cRMContactList_CustomEntity.AddressLine1        = addressLine1;
                            cRMContactList_CustomEntity.AddressLine2        = addressLine2;
                            cRMContactList_CustomEntity.ResourceDOB         = resourceDOB;
                            cRMContactList_CustomEntity.ResourceTypeID      = (Int64)resourceTypeID;
                            //Check Existing Item

                            var employeeList = (from s in IssueCRMContactList_CustomEntityList
                                                where s.ResourceID == resourceIDLV && s.ResourceCategoryID == resourceCategoryIDLV.ToString()
                                                select s);
                            if (employeeList == null || employeeList.Count() <= 0)
                            {
                                IssueCRMContactList_CustomEntityList.Add(cRMContactList_CustomEntity);
                            }
                        }

                        else if (chkSelectResourceLV.Checked == false)
                        {
                            Int64 resourceIDLV, resourceCategoryIDLV;

                            Label lblResourceIDLV         = (Label)lvdi.FindControl("lblResourceIDLV");
                            Label lblResourceCategoryIDLV = (Label)lvdi.FindControl("lblResourceCategoryIDLV");

                            Int64.TryParse(lblResourceIDLV.Text, out resourceIDLV);
                            Int64.TryParse(lblResourceCategoryIDLV.Text, out resourceCategoryIDLV);



                            var item = from s in IssueCRMContactList_CustomEntityList
                                       where s.ResourceID == resourceIDLV && s.ResourceCategoryID == resourceCategoryIDLV.ToString()
                                       select s;

                            if (item != null && item.Count() > 0)
                            {
                                //Check Deleted Employee.
                                CRMContactList_CustomEntity di = (from d in IssueCRMContactList_CustomEntityList
                                                                  where d.ResourceID == resourceIDLV && d.ResourceCategoryID == rfvResourceCategoryID.ToString()
                                                                  select d).First();
                                //Delete Here.
                                if (di != null)
                                {
                                    IssueCRMContactList_CustomEntityList.Remove(di);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void SaveBDProcessAssignedResourceEntity()
        {
            if (IsValid)
            {
                try
                {
                    BDProcessAssignedResourceEntity bDProcessAssignedResourceEntity = BuildBDProcessAssignedResourceEntity();

                    Int64 result = -1;

                    if (bDProcessAssignedResourceEntity.IsNew)
                    {
                        result = FCCBDProcessAssignedResource.GetFacadeCreate().Add(bDProcessAssignedResourceEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(BDProcessAssignedResourceEntity.FLD_NAME_ProcessAssignedResourceID, bDProcessAssignedResourceEntity.ProcessAssignedResourceID.ToString(), SQLMatchType.Equal);
                        result = FCCBDProcessAssignedResource.GetFacadeCreate().Update(bDProcessAssignedResourceEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        BDProcessAssignedResourceMapEntity bDProcessAssignedResourceMapEntity = CurrentBDProcessAssignedResourceMapEntity;

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(BDProcessAssignedResourceMapEntity.FLD_NAME_ProcessAssignedResourceID, result.ToString(), SQLMatchType.Equal);
                        IList <BDProcessAssignedResourceMapEntity> mappedItemsFromDB = FCCBDProcessAssignedResourceMap.GetFacadeCreate().GetIL(null, null, String.Empty, fe, DatabaseOperationType.LoadWithFilterExpression);
                        IList <CRMContactList_CustomEntity>        tempAddList       = new List <CRMContactList_CustomEntity>();

                        if (mappedItemsFromDB != null && mappedItemsFromDB.Count > 0)
                        {
                            foreach (BDProcessAssignedResourceMapEntity ent in mappedItemsFromDB)
                            {
                                CRMContactList_CustomEntity cRMContactList_CustomEntity = new CRMContactList_CustomEntity();
                                cRMContactList_CustomEntity.ResourceID          = ent.ReferenceID;
                                cRMContactList_CustomEntity.ResourceCategoryID  = ent.ResourceCategoryID.ToString();
                                cRMContactList_CustomEntity.ResourceName        = ent.ResourceName;
                                cRMContactList_CustomEntity.ResourceDesignation = ent.ResourceDesignation;
                                cRMContactList_CustomEntity.ResourceEmail       = ent.ResourceEmail;
                                cRMContactList_CustomEntity.AddressLine1        = ent.AddressLine1;
                                cRMContactList_CustomEntity.AddressLine2        = ent.AddressLine2;
                                cRMContactList_CustomEntity.ResourceMobileNo    = ent.ResourceMobileNo;
                                Int64 resourceTypeID = 0;
                                Int64.TryParse(ent.ResourceTypeID.ToString(), out resourceTypeID);
                                cRMContactList_CustomEntity.ResourceTypeID  = resourceTypeID;
                                cRMContactList_CustomEntity.ResourceCompany = ent.ResourceCompany;
                                tempAddList.Add(cRMContactList_CustomEntity);
                            }
                        }

                        IList <CRMContactList_CustomEntity> finalAddList    = IssueCRMContactList_CustomEntityList.Except(tempAddList, new CustomerComparer()).ToList();
                        IList <CRMContactList_CustomEntity> finalDeleteList = tempAddList.Except(IssueCRMContactList_CustomEntityList, new CustomerComparer()).ToList();

                        foreach (CRMContactList_CustomEntity ent in finalAddList)
                        {
                            bDProcessAssignedResourceMapEntity.ProcessAssignedResourceID = result;
                            bDProcessAssignedResourceMapEntity.ResourceCategoryID        = Int64.Parse(ent.ResourceCategoryID.ToString());
                            bDProcessAssignedResourceMapEntity.ReferenceID         = ent.ResourceID;
                            bDProcessAssignedResourceMapEntity.ResourceName        = ent.ResourceName;
                            bDProcessAssignedResourceMapEntity.ResourceDesignation = ent.ResourceDesignation;
                            bDProcessAssignedResourceMapEntity.ResourceEmail       = ent.ResourceEmail;
                            bDProcessAssignedResourceMapEntity.ResourceMobileNo    = ent.ResourceMobileNo;
                            bDProcessAssignedResourceMapEntity.AddressLine1        = ent.AddressLine1;
                            bDProcessAssignedResourceMapEntity.AddressLine2        = ent.AddressLine2;
                            Int64 resourceTypeID = 0;
                            Int64.TryParse(ent.ResourceTypeID.ToString(), out resourceTypeID);
                            bDProcessAssignedResourceMapEntity.ResourceTypeID  = resourceTypeID;
                            bDProcessAssignedResourceMapEntity.ResourceCompany = ent.ResourceCompany;
                            bDProcessAssignedResourceMapEntity.Remarks         = txtRemarks.Text.Trim();

                            FCCBDProcessAssignedResourceMap.GetFacadeCreate().Add(bDProcessAssignedResourceMapEntity, DatabaseOperationType.Add, TransactionRequired.No);
                        }

                        foreach (CRMContactList_CustomEntity ent in finalDeleteList)
                        {
                            String fe1 = SqlExpressionBuilder.PrepareFilterExpression(BDProcessAssignedResourceMapEntity.FLD_NAME_ReferenceID, ent.ResourceID.ToString(), SQLMatchType.Equal);
                            String fe2 = SqlExpressionBuilder.PrepareFilterExpression(BDProcessAssignedResourceMapEntity.FLD_NAME_ResourceCategoryID, ent.ResourceCategoryID, SQLMatchType.Equal);

                            String fe_delete = SqlExpressionBuilder.PrepareFilterExpression(fe1, SQLJoinType.AND, fe2);

                            FCCBDProcessAssignedResourceMap.GetFacadeCreate().Delete(bDProcessAssignedResourceMapEntity, fe_delete, DatabaseOperationType.Delete, TransactionRequired.No);
                        }

                        if (!bDProcessAssignedResourceEntity.IsNew)
                        {
                            //_ProcessAssignedResourceID = 0;
                            //_BDProcessAssignedResourceEntity = new BDProcessAssignedResourceEntity();
                        }

                        _ProcessAssignedResourceID = result;
                        PrepareEditView();
                        BindBDProcessAssignedResourceMapList();

                        if (bDProcessAssignedResourceEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Process Assigned Resource Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Process Assigned Resource Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (bDProcessAssignedResourceEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Process Assigned Resource Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Process Assigned Resource Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }