private bool IsEqual(ProductGoogleCustomLabelGroupMappingOverviewModel item1, ProductGoogleCustomLabelGroupMappingOverviewModel item2)
        {
            PropertyInfo[] properties1 = item1.GetType().GetProperties();
            PropertyInfo[] properties2 = item2.GetType().GetProperties();
            object         value1;
            object         value2;

            Type type    = item1.GetType();
            bool isEqual = false;

            for (int i = 0; i < properties1.Length; i++)
            {
                value1 = properties1[i].GetValue(item1, null);
                value2 = properties2[i].GetValue(item2, null);

                if (value1 != null && value2 != null)
                {
                    isEqual = value1.Equals(value2);
                }

                if (!isEqual)
                {
                    break;
                }
            }

            return(isEqual);
        }
        protected void gvCustomLabels_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var group = (ProductGoogleCustomLabelGroupMappingOverviewModel)e.Row.DataItem;
                ProductGoogleCustomLabelGroupMappingOverviewModel chosenGroup = null;

                if (ExistInChosenGroups(group))
                {
                    chosenGroup = ChosenCustomLabelGroups.Find(delegate(ProductGoogleCustomLabelGroupMappingOverviewModel item)
                    {
                        return(item.ProductId == group.ProductId);
                    });
                }

                CheckBox cb = e.Row.FindControl("cbChosen") as CheckBox;

                if (chosenGroup != null)
                {
                    TextBox txtCustomLabel1 = e.Row.FindControl("txtCustomLabel1") as TextBox;
                    TextBox txtCustomLabel2 = e.Row.FindControl("txtCustomLabel2") as TextBox;
                    TextBox txtCustomLabel3 = e.Row.FindControl("txtCustomLabel3") as TextBox;
                    TextBox txtCustomLabel4 = e.Row.FindControl("txtCustomLabel4") as TextBox;
                    TextBox txtCustomLabel5 = e.Row.FindControl("txtCustomLabel5") as TextBox;

                    TextBox txtValue1 = e.Row.FindControl("txtValue1") as TextBox;
                    TextBox txtValue2 = e.Row.FindControl("txtValue2") as TextBox;
                    TextBox txtValue3 = e.Row.FindControl("txtValue3") as TextBox;
                    TextBox txtValue4 = e.Row.FindControl("txtValue4") as TextBox;
                    TextBox txtValue5 = e.Row.FindControl("txtValue5") as TextBox;

                    cb.Checked = true;

                    txtCustomLabel1.Text = chosenGroup.CustomLabel1;
                    txtCustomLabel2.Text = chosenGroup.CustomLabel2;
                    txtCustomLabel3.Text = chosenGroup.CustomLabel3;
                    txtCustomLabel4.Text = chosenGroup.CustomLabel4;
                    txtCustomLabel5.Text = chosenGroup.CustomLabel5;

                    txtValue1.Text = chosenGroup.Value1;
                    txtValue2.Text = chosenGroup.Value2;
                    txtValue3.Text = chosenGroup.Value3;
                    txtValue4.Text = chosenGroup.Value4;
                    txtValue5.Text = chosenGroup.Value5;
                }
            }
        }
        private bool ExistInNotChosenGroups(ProductGoogleCustomLabelGroupMappingOverviewModel group)
        {
            bool exist = false;

            for (int j = 0; j < NotChosenCustomLabelGroups.Count; j++)
            {
                exist = IsEqual(NotChosenCustomLabelGroups[j], group);

                if (!exist)
                {
                    exist = NotChosenCustomLabelGroups[j].ProductId == group.ProductId;
                }

                if (exist)
                {
                    break;
                }
            }

            return(exist);
        }
        private void SetChosenGroups(ProductGoogleCustomLabelGroupMappingOverviewModel group, bool chosen)
        {
            if (group != null)
            {
                if (chosen)
                {
                    if (ExistInChosenGroups(group))
                    {
                        ChosenCustomLabelGroups.RemoveAll(delegate(ProductGoogleCustomLabelGroupMappingOverviewModel arg)
                        {
                            return(arg.ProductId == group.ProductId);
                        });
                    }

                    ChosenCustomLabelGroups.Add(group);
                    NotChosenCustomLabelGroups.RemoveAll(delegate(ProductGoogleCustomLabelGroupMappingOverviewModel arg)
                    {
                        return(arg.ProductId == group.ProductId);
                    });
                }
                else
                {
                    ChosenCustomLabelGroups.RemoveAll(delegate(ProductGoogleCustomLabelGroupMappingOverviewModel arg)
                    {
                        return(arg.ProductId == group.ProductId);
                    });

                    if (ExistInNotChosenGroups(group))
                    {
                        NotChosenCustomLabelGroups.RemoveAll(delegate(ProductGoogleCustomLabelGroupMappingOverviewModel arg)
                        {
                            return(arg.ProductId == group.ProductId);
                        });
                    }

                    NotChosenCustomLabelGroups.Add(group);
                }
            }
        }
        private ProductGoogleCustomLabelGroupMappingOverviewModel BuildGroup(int productId, GridViewRow row)
        {
            TextBox txtCustomLabel1 = row.FindControl("txtCustomLabel1") as TextBox;
            TextBox txtCustomLabel2 = row.FindControl("txtCustomLabel2") as TextBox;
            TextBox txtCustomLabel3 = row.FindControl("txtCustomLabel3") as TextBox;
            TextBox txtCustomLabel4 = row.FindControl("txtCustomLabel4") as TextBox;
            TextBox txtCustomLabel5 = row.FindControl("txtCustomLabel5") as TextBox;

            TextBox txtValue1 = row.FindControl("txtValue1") as TextBox;
            TextBox txtValue2 = row.FindControl("txtValue2") as TextBox;
            TextBox txtValue3 = row.FindControl("txtValue3") as TextBox;
            TextBox txtValue4 = row.FindControl("txtValue4") as TextBox;
            TextBox txtValue5 = row.FindControl("txtValue5") as TextBox;

            var overviewGroup = new ProductGoogleCustomLabelGroupMappingOverviewModel();

            overviewGroup.ProductId = productId;

            if (string.IsNullOrEmpty(txtCustomLabel1.Text.Trim()) == false)
            {
                overviewGroup.CustomLabel1 = txtCustomLabel1.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtCustomLabel2.Text.Trim()) == false)
            {
                overviewGroup.CustomLabel2 = txtCustomLabel2.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtCustomLabel3.Text.Trim()) == false)
            {
                overviewGroup.CustomLabel3 = txtCustomLabel3.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtCustomLabel4.Text.Trim()) == false)
            {
                overviewGroup.CustomLabel4 = txtCustomLabel4.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtCustomLabel5.Text.Trim()) == false)
            {
                overviewGroup.CustomLabel5 = txtCustomLabel5.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtValue1.Text.Trim()) == false)
            {
                overviewGroup.Value1 = txtValue1.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtValue2.Text.Trim()) == false)
            {
                overviewGroup.Value2 = txtValue2.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtValue3.Text.Trim()) == false)
            {
                overviewGroup.Value3 = txtValue3.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtValue4.Text.Trim()) == false)
            {
                overviewGroup.Value4 = txtValue4.Text.Trim();
            }

            if (string.IsNullOrEmpty(txtValue5.Text.Trim()) == false)
            {
                overviewGroup.Value5 = txtValue5.Text.Trim();
            }

            return(overviewGroup);
        }