private void EnabledRemoveButton()
        {
            List <RibbonButton> listRibbonButton = CustomerObject.GetLogicalChildCollection <RibbonButton>(this);

            foreach (RibbonButton rbtn in listRibbonButton)
            {
                if (rbtn.Name.Contains("btnContentRemove"))
                {
                    string[] tag = rbtn.Tag.ToString().SplitByDelimiter("#");

                    DsNhomCap itemNhomCap = lstNhomCap[Convert.ToInt32(tag[0].Replace("NhomCap", ""))];
                    if (Convert.ToInt32(tag[1]) == (itemNhomCap.LstCap.Count - 1))
                    {
                        rbtn.IsEnabled = true;
                    }
                    else
                    {
                        rbtn.IsEnabled = false;
                    }
                }
                else if (rbtn.Name.Contains("btnRemove"))
                {
                    if (Convert.ToInt32(rbtn.Tag.ToString()) == (lstNhomCap.Count - 1))
                    {
                        rbtn.IsEnabled = true;
                    }
                    else
                    {
                        rbtn.IsEnabled = false;
                    }
                }
            }
        }
        private void addGroup(string txtTu = "", string txtDen = "")
        {
            int ind = 0;

            if (!lstNhomCap.IsNullOrEmpty() && lstNhomCap.Count > 0)
            {
                ind = lstNhomCap.Count;
            }
            else
            {
                lstNhomCap = new List <DsNhomCap>();
            }

            DsNhomCap nhomCap = new DsNhomCap();

            nhomCap.MaNhomCap = "NhomCap" + ind;

            string groupBox = "";

            groupBox += "\n" + "    <ribbon:RibbonButton Grid.Row=\"" + ind + "\" Grid.Column=\"0\" VerticalAlignment=\"Top\" Name=\"btnRemove" + ind + "\" Tag=\"" + ind + "\" SmallImageSource=\"pack://application:,,,/Utilities.Common;component/Images/Action/detail_delete.png\" Width=\"30\" />";
            groupBox += "\n" + "    <GroupBox Name=\"grbGroup" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" Grid.Row=\"" + ind + "\" Grid.Column=\"1\" Header=\"Nhóm " + (ind + 1) + "\" VerticalAlignment=\"Stretch\">";
            //groupBox += "\n" + "         <ScrollViewer VerticalScrollBarVisibility=\"Auto\">";
            groupBox += "\n" + "            <Grid>";
            groupBox += "\n" + "                <Grid.RowDefinitions>";
            groupBox += "\n" + "                    <RowDefinition Height=\"30\" />";
            groupBox += "\n" + "                </Grid.RowDefinitions>";
            groupBox += "\n" + "                <Grid.ColumnDefinitions>";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"50\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"*\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"80\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"2*\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"100\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"2*\" />";
            groupBox += "\n" + "                    <ColumnDefinition Width=\"50\" />";
            groupBox += "\n" + "                </Grid.ColumnDefinitions>";
            //groupBox += "\n" + "                <StackPanel Orientation=\"Horizontal\" Grid.ColumnSpan=\"6\">";
            groupBox += "\n" + "                    <Label Margin=\"5,0,0,0\" Grid.Row=\"0\" Grid.Column=\"0\" HorizontalAlignment=\"Right\" Content=\"Từ:\" />";
            groupBox += "\n" + "                    <TextBox Margin=\"3\" Grid.Row=\"0\" Grid.Column=\"1\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Left\" Name=\"txtTu" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" Text=\"" + txtTu + "\" Width=\"120\"  />";
            groupBox += "\n" + "                    <Label Margin=\"5,0,0,0\" Grid.Row=\"0\" Grid.Column=\"2\" HorizontalAlignment=\"Right\" Content=\"Đến:\" />";
            groupBox += "\n" + "                    <TextBox Margin=\"3\" Grid.Row=\"0\" Grid.Column=\"3\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Left\" Name=\"txtDen" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" Text=\"" + txtDen + "\" Width=\"120\"  />";
            //groupBox += "\n" + "                </StackPanel>";
            groupBox += "\n" + "                <ribbon:RibbonButton Margin=\"3\" Grid.Row=\"0\" Grid.Column=\"6\" Name=\"btnAddContent" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" SmallImageSource=\"pack://application:,,,/Utilities.Common;component/Images/Action/detail_add.png\" Width=\"30\" />";
            groupBox += "\n" + "                ControlContent";// Tạo các Control bên trong Group
            groupBox += "\n" + "            </Grid>";
            //groupBox += "\n" + "         </ScrollViewer>";
            groupBox += "\n" + "    </GroupBox>";

            nhomCap.StrGroupBox = groupBox;
            lstNhomCap.Add(nhomCap);
        }
        private void addCap(string maNhomCap, string maCap = "", string value = "")
        {
            DsNhomCap nhomCap = lstNhomCap.FirstOrDefault(n => n.MaNhomCap.Equals(maNhomCap));

            if (!nhomCap.IsNullOrEmpty())
            {
                string nsd  = "";
                string nnsd = "";
                if (!value.IsNullOrEmptyOrSpace())
                {
                    string[] objNSD  = value.SplitByDelimiter(";")[0].SplitByDelimiter(",");
                    string[] objNNSD = value.SplitByDelimiter(";")[1].SplitByDelimiter(",");
                    foreach (string str in objNSD)
                    {
                        nsd += str + ",";
                    }
                    foreach (string str in objNNSD)
                    {
                        nnsd += str + ",";
                    }
                    if (!nsd.IsNullOrEmptyOrSpace())
                    {
                        nsd = nsd.Substring(0, nsd.Length - 1);
                    }
                    if (!nnsd.IsNullOrEmptyOrSpace())
                    {
                        nnsd = nnsd.Substring(0, nnsd.Length - 1);
                    }
                }
                int ind = 0;
                if (!nhomCap.LstCap.IsNullOrEmpty() && nhomCap.LstCap.Count > 0)
                {
                    ind = nhomCap.LstCap.Count;
                }
                string strCap = "";
                strCap += "\n" + "            <Label Margin=\"5,0,0,0\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"0\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Right\" Content=\"Cấp:\" />";
                strCap += "\n" + "            <uc:AutoCompleteTextBox DelayTime=\"100\" Threshold=\"2\" Margin=\"3\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"1\" VerticalAlignment=\"Top\" x:Name=\"txtMaCap" + nhomCap.MaNhomCap + "_" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" HorizontalAlignment=\"Stretch\" Text=\"" + maCap + "\" />";
                strCap += "\n" + "            <Label Margin=\"5,0,0,0\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"2\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Right\" Content=\"NSD:\" />";
                strCap += "\n" + "            <uc:AutoCompleteTextBox DelayTime=\"100\" Threshold=\"2\" Margin=\"3\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"3\" VerticalAlignment=\"Top\" x:Name=\"txtCapNhomCapNSD" + nhomCap.MaNhomCap + "_" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" HorizontalAlignment=\"Stretch\" Text=\"" + nsd + "\" />";
                strCap += "\n" + "            <Label Margin=\"5,0,0,0\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"4\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Right\" Content=\"Nhóm NSD:\" />";
                strCap += "\n" + "            <uc:AutoCompleteTextBox DelayTime=\"100\" Threshold=\"2\" Margin=\"3\" Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"5\" VerticalAlignment=\"Top\" x:Name=\"txtCapNhomCapNNSD" + nhomCap.MaNhomCap + "_" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "\" HorizontalAlignment=\"Stretch\" Text=\"" + nnsd + "\" />";
                strCap += "\n" + "            <ribbon:RibbonButton Grid.Row=\"" + (ind + 1) + "\" Grid.Column=\"6\" Name=\"btnContentRemove" + nhomCap.MaNhomCap + "_" + ind + "\" Tag=\"" + nhomCap.MaNhomCap + "#" + ind + "\" SmallImageSource=\"pack://application:,,,/Utilities.Common;component/Images/Action/detail_delete.png\" Width=\"30\" />";
                if (nhomCap.LstCap.IsNullOrEmpty())
                {
                    nhomCap.LstCap = new List <string>();
                }
                nhomCap.LstCap.Add(strCap);
                nhomCap.StrGroupBox = nhomCap.StrGroupBox.Replace("<Grid.RowDefinitions>", "<Grid.RowDefinitions>\n" + "                <RowDefinition Height=\"30\" />");
            }
        }
        private void btnContentRemove_Click(object sender, RoutedEventArgs e)
        {
            RibbonButton btnContentRemove = (RibbonButton)sender;

            string[] tag = btnContentRemove.Tag.ToString().SplitByDelimiter("#");

            DsNhomCap itemNhomCap = lstNhomCap[Convert.ToInt32(tag[0].Replace("NhomCap", ""))];

            itemNhomCap.LstCap.RemoveAt(Convert.ToInt32(tag[1]));
            itemNhomCap.StrGroupBox = itemNhomCap.StrGroupBox.Replace("<Grid.RowDefinitions>\n" + "                <RowDefinition Height=\"30\" />", "<Grid.RowDefinitions>");
            string strMain = strGridMain;

            ShowForm(strMain);
        }