public bool convertDataToXml(F_SSO_SendDataForm formModel)
        {
            try {
                XmlDocument    xmlDoc         = new XmlDocument();
                XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                XmlElement     root           = xmlDoc.DocumentElement;

                xmlDoc.InsertBefore(xmlDeclaration, root);

                XmlElement elementBody = xmlDoc.CreateElement(string.Empty, "SSOMessageSubsidy", string.Empty);

                xmlDoc.AppendChild(elementBody);
                elementBody.SetAttribute("xmlns", "urn:th:sso:xsd:subsidy:1");
                elementBody.SetAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#");


                string[] lines      = File.ReadAllLines(formModel.server_path_decode);
                string   firstLine  = lines[0]; // gets the first line from file. //#####   FOR CONTROL.
                string   secondLine = lines[1]; // gets the second line from file. //#####   FOR ACCOUNT BRANCH CONTROL.

                lines = lines.Skip(2).ToArray();

                //########################################################  SET Control.
                SubsidyControl subsidyControl = new SubsidyControl();
                subsidyControl.setSubsidyControl(firstLine);

                SubsidySsoAccountBranchControl accountBranchControl = new SubsidySsoAccountBranchControl();
                accountBranchControl.setSubsidySsoAccountBranchControl(secondLine);

                XmlElement documentHeader              = this.createDocumentHeader(xmlDoc, subsidyControl);                                  // SET HEADER.
                XmlElement documentDetail              = xmlDoc.CreateElement(string.Empty, "DocumentDetail", string.Empty);
                XmlElement documentPartyInformation    = this.createDocumentPartyInformation(xmlDoc, subsidyControl);                        // SET PartyInformation.
                XmlElement documentEmployerInformation = this.createDocumentEmployerInformation(subsidyControl);                             // SET EmployerInformation.
                XmlElement documentSubsidyInformation  = this.createDocumentSubsidyInformation(subsidyControl, accountBranchControl, lines); // SET SubsidyInformation.
                XmlElement documentPaymentInformation  = this.createDocumentPaymentInformation(subsidyControl);                              // SET PaymentInformation.


                documentDetail.AppendChild(documentPartyInformation);
                documentDetail.AppendChild(documentDetail.OwnerDocument.ImportNode(documentEmployerInformation, true));
                documentDetail.AppendChild(documentDetail.OwnerDocument.ImportNode(documentSubsidyInformation, true));
                documentDetail.AppendChild(documentDetail.OwnerDocument.ImportNode(documentPaymentInformation, true));

                elementBody.AppendChild(documentHeader);
                elementBody.AppendChild(documentDetail);

                //########################################################  END SET Control.

                string pathSaveXml = formModel.server_path_xml;
                try {
                    //string xmlFileName = pathSaveXml + "/" + formModel.server_file_name.Split('.')[0] + ".xml";
                    //string xmlFileName = formModel.server_file_name.Split('.')[0] + ".xml";

                    //######################################    SET SsoClass.

                    ssoClass.SEND_STATUS   = "0";
                    ssoClass.SEND_RESPONSE = "";

                    string inv_no = ssoClass.getSsoInvNo();
                    ssoClass.XML_PATH = "XML_SEND/1/" + DateTime.Now.ToString("yyyy_MM");
                    ssoClass.XML_NAME = ssoClass.generateXmlFileName();
                    ssoClass.insertDataSsoDataSend();
                    //ssoClass.XML_NAME = xmlFileName;

                    string xmlFilePathToSso = formModel.server_path_plugins + "/" + ssoClass.XML_PATH;

                    if (!Directory.Exists(xmlFilePathToSso))
                    {
                        Directory.CreateDirectory(xmlFilePathToSso);
                    }


                    xmlDoc.Save(formModel.server_path_xml + "/" + ssoClass.XML_NAME);
                    xmlDoc.Save(xmlFilePathToSso + "/" + ssoClass.XML_NAME);

                    string appPath = formModel.server_path_send_exe;
                    //ProcessStartInfo processInfo = new ProcessStartInfo(appPath);
                    //Process process = Process.Start(processInfo);

                    string       arr           = ssoClass.REF_NO_TEXT + "| " + inv_no + "| " + ssoClass.XML_PATH + "/" + ssoClass.XML_NAME;
                    const string argsSeparator = "|";
                    string       args          = string.Join(argsSeparator, arr);

                    Process.Start(appPath, args.Replace(" | ", " "));
                    //string url = WebConfigurationManager.AppSettings["GENiusWebServiceCoreData"];

                    //HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url+ "/sendDataToSSO_Subsidy_1_10");
                    //Debug.WriteLine("xxxxxxxxxx");
                }
                catch (Exception ex) {
                    Debug.WriteLine(ex);
                    return(false);
                }
                return(true);
            }
            catch (Exception ex) {
                Debug.WriteLine(ex);
                return(false);
            }
        }
        private XmlElement createDocumentSubsidyInformation(SubsidyControl subsidyControl, SubsidySsoAccountBranchControl accountBranchControl, string[] lines)
        {
            SubsidyInformation subsidyInformation = new SubsidyInformation();

            subsidyInformation.SubsidyRate  = subsidyControl.subsidyRate;
            subsidyInformation.SubsidyMonth = "--" + subsidyControl.subsidyMonth + "--";
            subsidyInformation.SubsidyYear  = subsidyControl.subsidyYear;
            //subsidyInformation.TotalWageAmount = subsidyControl.totalWageAmount;
            subsidyInformation.TotalWageAmount = new TotalWageAmount {
                totalWageAmount = subsidyControl.totalWageAmount, currencyID = "THB"
            };
            subsidyInformation.TotalEmployeeSubsidyAmount = new TotalEmployeeSubsidyAmount {
                totalEmployeeSubsidyAmount = subsidyControl.totalEmployeeSubsidyAmount, currencyID = "THB"
            };
            subsidyInformation.TotalEmployerSubsidyAmount = new TotalEmployerSubsidyAmount {
                totalEmployerSubsidyAmount = subsidyControl.totalEmployerSubsidyAmount, currencyID = "THB"
            };
            subsidyInformation.TotalSubsidyAmount = new TotalSubsidyAmount {
                totalSubsidyAmount = subsidyControl.totalSubsidyAmount, currencyID = "THB"
            };
            subsidyInformation.TotalEmployeeNumber = subsidyControl.totalNumberOfEmployee;

            //########################  Set Data SsoClass.
            ssoClass.SUBSIDY_RATE          = subsidyControl.subsidyRate;
            ssoClass.SUBSIDY_MONTH         = subsidyControl.subsidyMonth;
            ssoClass.SUBSIDY_YEAR          = subsidyControl.subsidyYear;
            ssoClass.TOTAL_WAGE_AMOUNT     = subsidyControl.totalWageAmount;
            ssoClass.TOTAL_EMPLOYEE_AMOUNT = subsidyControl.totalEmployeeSubsidyAmount;
            ssoClass.TOTAL_EMPLOYER_AMOUNT = subsidyControl.totalEmployerSubsidyAmount;
            ssoClass.TOTAL_EMPLOYER_NO     = subsidyControl.totalNumberOfEmployee;
            //########################  BranchInformation.
            BranchInformation branchInformation = new BranchInformation();

            branchInformation.branchItem                       = new BranchItem();
            branchInformation.branchItem.ItemNumber            = "1";
            branchInformation.branchItem.SSOBranchCode         = accountBranchControl.ssoAccountBranch;
            branchInformation.branchItem.TotalBranchWageAmount = new TotalBranchWageAmount {
                totalBranchWageAmount = accountBranchControl.totalBranchWageAmount, currencyID = "THB"
            };
            branchInformation.branchItem.TotalBranchEmployeeSubsidyAmount = new TotalBranchEmployeeSubsidyAmount {
                totalBranchEmployeeSubsidyAmount = accountBranchControl.totalBranchEmployeeSubsidyAmount, currencyID = "THB"
            };
            branchInformation.branchItem.TotalBranchEmployerSubsidyAmount = new TotalBranchEmployerSubsidyAmount {
                totalBranchEmployerSubsidyAmount = accountBranchControl.totalBranchEmployerSubsidyAmount, currencyID = "THB"
            };
            branchInformation.branchItem.TotalBranchSubsidyAmount = new TotalBranchSubsidyAmount {
                totalBranchSubsidyAmount = accountBranchControl.totalBranchSubsidyAmount, currencyID = "THB"
            };
            branchInformation.branchItem.TotalBranchEmployeeNumber = accountBranchControl.totalBranchNumberOfEmployee;
            //branchInformation.branchItem.TotalBranchEmployeeNumber = "1";
            //########################  ItemInformation
            ItemInformation itemInformation = new ItemInformation();

            int countLine = 1;
            List <SubsidyItem> subsidySsoDetails = new List <SubsidyItem>();

            foreach (string line in lines)
            {
                SubsidySsoDetail subsidySsoDetail = new SubsidySsoDetail();
                subsidySsoDetail.setSubsidySsoDetail(line);

                SubsidyItem subsidyItem = new SubsidyItem();
                subsidyItem.ItemNumber = countLine.ToString();
                subsidyItem.WageAmount = new WageAmount {
                    wageAmount = subsidySsoDetail.wageAmount, currencyID = "THB"
                };
                subsidyItem.SubsidyAmount = new SubsidyAmount {
                    subsidyAmount = subsidySsoDetail.employeeSubsidyAmount, currencyID = "THB"
                };
                //subsidyItem.WageAmount = new WageAmount { wageAmount = "20000", currencyID = "THB" };
                // subsidyItem.SubsidyAmount = new SubsidyAmount { subsidyAmount = "750", currencyID = "THB" };
                subsidyItem.LastEntry = subsidySsoDetail.lastEntry;

                subsidyItem.employeeInformation                  = new EmployeeInformation();
                subsidyItem.employeeInformation.EmployeeID       = subsidySsoDetail.employeeIdCard;
                subsidyItem.employeeInformation.EmployeeTitle    = subsidySsoDetail.employeeTitle;
                subsidyItem.employeeInformation.EmployeeName     = subsidySsoDetail.employeeName;
                subsidyItem.employeeInformation.EmployeeLastName = subsidySsoDetail.employeeLastName;

                subsidySsoDetails.Add(subsidyItem);
                countLine++;
            }
            itemInformation.subsidyItem = subsidySsoDetails;

            subsidyInformation.branchInformation = branchInformation;
            subsidyInformation.branchInformation.branchItem.itemInformation = itemInformation;
            //subsidyInformation.branchInformation = new BranchInformation();



            XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();

            xmlSerializerNamespaces.Add("", "");

            XmlDocument   xmlDocument   = new XmlDocument();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SubsidyInformation));

            using (XmlWriter writer = xmlDocument.CreateNavigator().AppendChild()) {
                xmlSerializer.Serialize(writer, subsidyInformation, xmlSerializerNamespaces);
            }
            return(xmlDocument.DocumentElement);
        }