// Phan Tach Am Tiet
        public AmTiet AmTietTelex(ref AmTiet amTiet)
        {
            string name = Path.GetFileName(amTiet.Path);

            string[] parts = name.Split('.');
            if (parts.Count <string>() > 1)
            {
                amTiet.Unicode = parts[0];
            }
            return(amTiet);
        }
// Update Info for list word
        public void UpdateVanTrongAmTiet()
        {
            for (int i = 0; i < _listAmTiet.Count; i++)
            {
                AmTiet amTiet = _listAmTiet[i];
                if (string.IsNullOrEmpty(amTiet.Unicode))
                {
                    AmTietTelex(ref amTiet);
                }
                PhanTichAmTiet(ref amTiet);
            }
        }
        public string PhanTichAmChinh(AmTiet amTiet, ref string van)
        {
            foreach (YeuToAmTiet amChinh in _listAmChinh)
            {
                string tmp = string.Copy(van);
                if (tmp.EndsWith(amChinh.AmTo))
                {
                    if (amChinh.ContainRequired != null && amChinh.ContainRequired.Count > 0)
                    {
                        foreach (string contain in amChinh.ContainRequired)
                        {
                            if (tmp.EndsWith(contain))
                            {
                                if (amChinh.PrefixRequired != null && amChinh.PrefixRequired.Count > 0)
                                {
                                    foreach (string pre in amChinh.PrefixRequired)
                                    {
                                        if (amTiet.PhuAmDau == pre)
                                        {
                                            tmp            = tmp.Substring(0, tmp.Length - amChinh.AmTo.Length);
                                            van            = tmp;
                                            amTiet.AmChinh = amChinh.AmTo;
                                            return(amChinh.AmTo);
                                        }
                                    }
                                }
                                else
                                {
                                    tmp            = tmp.Substring(0, tmp.Length - amChinh.AmTo.Length);
                                    van            = tmp;
                                    amTiet.AmChinh = amChinh.AmTo;
                                    return(amChinh.AmTo);
                                }
                            }
                        }
                    }
                    if ((amChinh.PrefixRequired == null || (amChinh.PrefixRequired != null && amChinh.PrefixRequired.Count == 0)) &&
                        (amChinh.ContainRequired == null || (amChinh.ContainRequired != null && amChinh.ContainRequired.Count == 0)) &&
                        (amChinh.PostRequired == null || (amChinh.PostRequired != null && amChinh.PostRequired.Count == 0))
                        )
                    {
                        amTiet.AmChinh = amChinh.AmTo;
                        van            = van.Substring(0, van.Length - amTiet.AmChinh.Length);
                        return(amChinh.AmTo);
                    }
                }
            }

            Debug.WriteLine("Co Van De");
            return("-");
        }
        public static AmTiet ToAmTiet(AmTietCarrier.AmTietRow amTietRow)
        {
            AmTiet amTiet = new AmTiet();

            amTiet.AmChinh    = amTietRow.AmChinh;
            amTiet.AmCuoi     = amTietRow.AmCuoi;
            amTiet.AmDem      = amTietRow.AmDem;
            amTiet.Unicode    = amTietRow.Unicode;
            amTiet.Vietnamese = amTietRow.Vietnamese;
            amTiet.Thanh      = amTietRow.Thanh;
            amTiet.Path       = amTietRow.Path;
            amTiet.Van        = amTietRow.Van;
            amTiet.Edited     = amTietRow.Edited;
            return(amTiet);
        }
        public AmTiet PhanTichAmTiet(ref AmTiet amTiet)
        {
            if (amTiet.Edited == true)
            {
                return(amTiet);
            }

            string text = string.Copy(amTiet.Unicode);

            amTiet.Thanh    = PhanTichThanh(ref text);
            amTiet.PhuAmDau = PhanTichPhuAmDau(ref text);
            string van = string.Copy(text);

            amTiet.AmCuoi  = PhanTichAmCuoi(ref text);
            amTiet.AmChinh = PhanTichAmChinh(amTiet, ref text);

            amTiet.Van = van;
            PhanTichAmDem(amTiet, van);



            return(amTiet);
        }
        public void PhanTichAmDem(AmTiet amTiet, string van)
        {
            string fullAmTiet = string.Copy(amTiet.Unicode);

            string fullWithoutPhuAmCuoi = van;

            foreach (YeuToAmTiet amDem in _listAmDem)
            {
                if (amDem.ContainRequired != null && amDem.ContainRequired.Count > 0)
                {
                    foreach (string contain in amDem.ContainRequired)
                    {
                        if (StartWith(fullWithoutPhuAmCuoi, contain))
                        {
                            if (amDem.PostRequired != null && amDem.PostRequired.Count > 0)
                            {
                                foreach (string post in amDem.PostRequired)
                                {
                                    if (StartWith(fullWithoutPhuAmCuoi, post))
                                    {
                                        amTiet.AmDem = amDem.AmTo;
                                    }
                                }
                            }
                            else
                            {
                                amTiet.AmDem = amDem.AmTo;
                            }
                        }

                        if (fullAmTiet.EndsWith(contain))
                        {
                            if (amDem.PostRequired != null && amDem.PostRequired.Count > 0)
                            {
                                foreach (string post in amDem.PostRequired)
                                {
                                    if (StartWith(fullAmTiet, post))
                                    {
                                        amTiet.AmDem = amDem.AmTo;
                                    }
                                }
                            }
                            else
                            {
                                amTiet.AmDem = amDem.AmTo;
                            }
                        }
                    }
                }

                if (amDem.PrefixRequired != null && amDem.PrefixRequired.Count > 0)
                {
                    foreach (string pre in amDem.PrefixRequired)
                    {
                        if (amTiet.PhuAmDau == pre && StartWith(fullWithoutPhuAmCuoi, amDem.AmTo))
                        {
                            amTiet.AmDem = amDem.AmTo;
                        }
                    }
                }
            }
        }
// Parser File XML
        public void ParserListWord(XmlDocument doc)
        {
            XmlNode node = doc.SelectSingleNode("Root/List");

            if (node != null)
            {
                _listAmTiet.Clear();
                XmlNodeList listWords = node.SelectNodes("Word");
                foreach (XmlNode word in listWords)
                {
                    AmTiet amTiet = new AmTiet();
                    if (word != null && word.Attributes != null)
                    {
                        if (word.Attributes["Path"] != null)
                        {
                            amTiet.Path = word.Attributes["Path"].Value;
                        }

                        if (word.Attributes["w"] != null)
                        {
                            amTiet.Vietnamese = word.Attributes["w"].Value;
                        }

                        if (word.Attributes["PhuAmDau"] != null)
                        {
                            amTiet.PhuAmDau = word.Attributes["PhuAmDau"].Value;
                        }

                        if (word.Attributes["AmDem"] != null)
                        {
                            amTiet.AmDem = word.Attributes["AmDem"].Value;
                        }

                        if (word.Attributes["AmChinh"] != null)
                        {
                            amTiet.AmChinh = word.Attributes["AmChinh"].Value;
                        }

                        if (word.Attributes["AmCuoi"] != null)
                        {
                            amTiet.AmCuoi = word.Attributes["AmCuoi"].Value;
                        }

                        if (word.Attributes["Thanh"] != null)
                        {
                            amTiet.Thanh = word.Attributes["Thanh"].Value;
                        }

                        if (word.Attributes["Unicode"] != null)
                        {
                            amTiet.Unicode = word.Attributes["Unicode"].Value;
                        }

                        if (word.Attributes["Van"] != null)
                        {
                            amTiet.Van = word.Attributes["Van"].Value;
                        }

                        if (word.Attributes["Edited"] != null)
                        {
                            amTiet.Edited = Convert.ToBoolean(word.Attributes["Edited"].Value);
                        }
                        else
                        {
                            amTiet.Edited = false;
                        }


                        if (string.IsNullOrEmpty(amTiet.Unicode))
                        {
                            AmTietTelex(ref amTiet);
                        }

                        _listAmTiet.Add(amTiet);
                    }
                }
                _listAmTiet = _listAmTiet.OrderBy(x => x.Path).ToList <AmTiet>();
            }
        }