private void SendLiteFSU()
        {
            List<SelectedFlights> flightList = new List<SelectedFlights>();
            Broker b = new Broker();
            flightList = b.FillListBoxSelectedFlightsFFMfromAMS("FSULITE", 1);

            String CsOG = "";
            foreach (var item in flightList)
            {
                List<FFM> ffmList = new List<FFM>();
                ffmList = b.FillListBoxFFMfromAMS(item);

                //Толтырамыз
                string text1, copyEmail, emailCC;
                text1 = b.LoadFFMBlank("fsu_lite_blank_email");
                emailCC = "";
                copyEmail = "";
                string[] split;
                if (item.Email.Contains(","))
                {

                    split = item.Email.Split(',');
                    for (int i = 1; i < split.Length; i++)
                    {
                        emailCC = emailCC + "," + split[i];
                    }
                    copyEmail = split[0];
                    emailCC = emailCC.Substring(1, emailCC.Length - 1); //Үтірді өшіру
                }
                else if (item.Email.Equals("")) continue;
                else copyEmail = item.Email;

                text1 = text1.Replace("PS102", item.FlightIdentifier);
                text1 = text1.Replace("27MAY", item.FlightSDO.ToString("ddMMM").ToUpper());
                text1 = text1.Replace("1930", item.FlightSTO.ToString("HHmm"));
                text1 = text1.Replace("URGAU", item.Registration);
                text1 = text1.Replace("[DESTINATION]", item.Destination);
                text1 = text1.Replace("[CARGOCOUNT]", item.CountCargo.ToString());
                text1 = text1.Replace("[CARGOWEIGHT]", item.WeightCargo.ToString());
                text1 = text1.Replace("[MAILCOUNT]", item.CountMail.ToString());
                text1 = text1.Replace("[MAILWEIGHT]", item.WeightMail.ToString());

                string textFFM = "";
                foreach (var itemf in ffmList) //555-92050641SVOTSE/T5K38MC0.53/COURIER CARGO/ XPS
                {
                    textFFM = textFFM + itemf.AwbSerialNumber + itemf.Origin + itemf.Destination + "/T" + itemf.Pieces + "K" + itemf.Weight + "MC" + itemf.Volume + "/" + itemf.Goods + Environment.NewLine;
                    if (itemf.ShipmentDescriptionCode.Trim().Length > 0)
                    {
                        textFFM = textFFM + itemf.ShipmentDescriptionCode + Environment.NewLine;
                    }
                }

                text1 = text1.Replace("[text]", textFFM);
                text1 = text1 + "LAST";
                b.WriteMyLOG("SEND Flight FSULITE: Start send email");
                //Жібереміз Почтамен
                try
                {
                    SendMail(_SmtpServer, _SysMail, _SysMailPassword, copyEmail, emailCC, "FSU LITE TSE", text1);
                }
                catch (Exception e)
                {
                    b.WriteMyLOG("SEND Flight FSULITE:" + e);
                }

                XNamespace am = "http://www.sita.aero/ams6-xml-api-messages";
                XNamespace ad = "http://www.sita.aero/ams6-xml-api-datatypes";
                XElement root = null;
                root = new XElement(am + "Envelope",
                        new XAttribute(XNamespace.Xmlns + "amsx-messages", "http://www.sita.aero/ams6-xml-api-messages"),
                        new XAttribute("apiVersion", "1.2"),
                        new XAttribute(XNamespace.Xmlns + "amsx-datatypes", "http://www.sita.aero/ams6-xml-api-datatypes"),
                        new XElement(am + "Content",
                            new XElement(am + "FlightUpdateRequest",
                                new XElement(am + "FlightId",
                                    new XElement(ad + "FlightKind", "Departure"),
                                    new XElement(ad + "AirlineDesignator", item.CIata, new XAttribute("codeContext", "IATA")),
                                    new XElement(ad + "FlightNumber", item.FlightNumber),
                                    new XElement(ad + "ScheduledDate", item.FlightSDO.ToString("yyyy-MM-dd")),
                                    new XElement(ad + "AirportCode", "TSE", new XAttribute("codeContext", "IATA"))
                                    ),
                                new XElement(am + "FlightUpdates",
                                    new XElement(am + "Update", "True", new XAttribute("propertyName", "KC_LITE_FSU"))
                                )
                            )
                        ));

                messageQueue1.Path = queuePath;
                System.Messaging.Message testMgs = new System.Messaging.Message();
                testMgs.Body = root;
                if (emulationMode == "Real") messageQueue1.Send(testMgs);
                CsOG = CsOG + " " + root.ToString();
            }
            b.WriteMyLOG("SEND Flight FSULITE: " + CsOG);
            b.CloseReader();
            this.timerKezegi = "FSU14";
            // eventLog1.WriteEntry("SUCCESS Updated Send FFM");
        }
        private void SendFFM()
        {
            List<SelectedFlights> flightList = new List<SelectedFlights>();
            Broker b = new Broker();
            flightList = b.FillListBoxSelectedFlightsFFMfromAMS("FFM", 1);

            String CsOG = "";
            foreach (var item in flightList)
            {
                List<FFM> ffmList = new List<FFM>();
                ffmList = b.FillListBoxFFMfromAMS(item);

                //Толтырамыз
                string text1;
                text1 = b.LoadFFMBlank("ffm_blank");
                text1 = text1.Replace("TSEAPXH", item.TypeBADDRESS);
                text1 = text1.Replace("PS102", item.FlightIdentifier);
                text1 = text1.Replace("27MAY", item.FlightSDO.ToString("ddMMM").ToUpper());
                text1 = text1.Replace("1930", item.FlightSTO.ToString("HHmm"));
                text1 = text1.Replace("URGAU", item.Registration);
                text1 = text1.Replace("[DESTINATION]", item.Destination);

                string textFFM = "";
                foreach (var itemf in ffmList) //555-92050641SVOTSE/T5K38MC0.53/COURIER CARGO/ XPS
                {
                    textFFM = textFFM + itemf.AwbSerialNumber + itemf.Origin + itemf.Destination+ "/T" + itemf.Pieces + "K" + itemf.Weight + "MC" + itemf.Volume + "/" + itemf.Goods + Environment.NewLine;
                    if (itemf.ShipmentDescriptionCode.Trim().Length > 0)
                    {
                        textFFM = textFFM + itemf.ShipmentDescriptionCode + Environment.NewLine;
                    }
                }

                text1 = text1.Replace("[text]", textFFM);
                text1 = text1 + "LAST";
                //Cақтаймыз
                SaveFFM(text1, "FFM2");

                //Жібереміз
                try
                {
                    FTPClient ftp = new FTPClient(_RemoteHostFids, _RemoteLoginFids, _RemotePasswordFids);
                    // ftp.Download("LDM.txt", AppDomain.CurrentDomain.BaseDirectory + "LDM.txt");
                    string[] array1 = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.SND");
                    foreach (string name in array1)
                    {
                        Console.WriteLine(name);
                        byte pervyi = 1;
                        while (true)
                        {
                            try
                            {
                                ftp.UploadFile(name);
                                break;
                            }
                            catch (Exception e)
                            {
                                if (pervyi == 1)
                                {
                                    eventLog1.WriteEntry("Работа остановилась связи копированием " + e.ToString());
                                    pervyi = 2;
                                }
                                Thread.Sleep(10000);
                            }
                        }
                        if (pervyi == 2)
                            eventLog1.WriteEntry("Работа возобновилась");
                        File.Delete(name);
                    }

                }
                catch (IOException copyError)
                {
                    eventLog1.WriteEntry(copyError.Message);
                    throw;
                }

                XNamespace am = "http://www.sita.aero/ams6-xml-api-messages";
                XNamespace ad = "http://www.sita.aero/ams6-xml-api-datatypes";
                XElement root = null;
                root = new XElement(am + "Envelope",
                        new XAttribute(XNamespace.Xmlns + "amsx-messages", "http://www.sita.aero/ams6-xml-api-messages"),
                        new XAttribute("apiVersion", "1.2"),
                        new XAttribute(XNamespace.Xmlns + "amsx-datatypes", "http://www.sita.aero/ams6-xml-api-datatypes"),
                        new XElement(am + "Content",
                            new XElement(am + "FlightUpdateRequest",
                                new XElement(am + "FlightId",
                                    new XElement(ad + "FlightKind", "Departure"),
                                    new XElement(ad + "AirlineDesignator", item.CIata, new XAttribute("codeContext", "IATA")),
                                    new XElement(ad + "FlightNumber", item.FlightNumber),
                                    new XElement(ad + "ScheduledDate", item.FlightSDO.ToString("yyyy-MM-dd")),
                                    new XElement(ad + "AirportCode", "TSE", new XAttribute("codeContext", "IATA"))
                                    ),
                                new XElement(am + "FlightUpdates",
                                    new XElement(am + "Update", "True", new XAttribute("propertyName", "ffm_is_send"))
                                )
                            )
                        ));

                messageQueue1.Path = queuePath;
                System.Messaging.Message testMgs = new System.Messaging.Message();
                testMgs.Body = root;
                if (emulationMode == "Real") messageQueue1.Send(testMgs);
                CsOG = CsOG + " " + root.ToString();
            }
            b.WriteMyLOG("SEND Flight FFM: " + CsOG);
            b.CloseReader();
            this.timerKezegi = "FSULITE";
            // eventLog1.WriteEntry("SUCCESS Updated Send FFM");
        }
        private void SendFSU()
        {
            List<SelectedFlights> flightList = new List<SelectedFlights>();
            Broker b = new Broker();
            flightList = b.FillListBoxSelectedFlightsFFMfromAMS("FSU14", 1);
            int sou = 0;
            String CsOG = "";
            foreach (var selF in flightList)
            {
                List<FFM> ffmList = new List<FFM>();
                ffmList = b.FillListBoxFFMfromAMS(selF);

                //Толтырамыз
                string text1 = "";
                sou = 0;
                string textFFM, copyEmail, emailCC = "";
                foreach (var item in ffmList) //555-92050641SVOTSE/T5K38MC0.53/COURIER CARGO/ XPS
                {
                    textFFM = "";

                    sou++;
                    text1 = "";
                    text1 = b.LoadFFMBlank("fsu_blank");
                    text1 = text1.Replace("TSEAPXH", selF.TypeBADDRESS);

                    //text1 = text1.Replace("[EMAIL]", selF.EmailCargo);
                    text1 = text1.Replace("PS102", selF.FlightIdentifier);
                    text1 = text1.Replace("27MAY", selF.FlightSDO.ToString("ddMMM").ToUpper());
                    text1 = text1.Replace("[DESTINATION]", selF.Destination);
                    text1 = text1.Replace("[CARGOCOUNT]", item.Pieces.ToString());
                    text1 = text1.Replace("[CARGOWEIGHT]", item.Weight.ToString());
                    text1 = text1.Replace("[FSA89]", selF.TypeTimeIndicator.ToString());
                    text1 = text1.Replace("[TIME_DEP]", selF.DepTime.ToString());
                    text1 = text1.Replace("[TIME_ARR]", selF.ArrTime.ToString());
                    text1 = text1.Replace("[FSA72]", selF.DayChangeIndicator.ToString());
                    textFFM = textFFM + Environment.NewLine + item.AwbSerialNumber + item.Origin + item.Destination + "/T" + item.Pieces + "K" + item.Weight;
                    text1 = text1.Replace("[FSUAWB]", textFFM);
                    //Cақтаймыз
                    SaveFFM(text1, "FSU14-" + Convert.ToString(sou));

                    if (selF.EmailCargo.Length > 0)
                    {
                        b.WriteMyLOG("SEND Flight FSU: Start send email");
                        //Жібереміз Почтамен
                        emailCC = "";
                        copyEmail = "";
                        string[] split;
                        if (selF.EmailCargo.Contains(","))
                        {

                            split = selF.EmailCargo.Split(',');
                            for (int i = 1; i < split.Length; i++)
                            {
                                emailCC = emailCC + "," + split[i];
                            }
                            copyEmail = split[0];
                            emailCC = emailCC.Substring(1, emailCC.Length - 1); //Үтірді өшіру
                        }
                        else if (selF.EmailCargo.Equals("")) continue;
                        else copyEmail = selF.EmailCargo;
                        b.WriteMyLOG("SEND Flight FSU: copyEmail:" + copyEmail + " emailCC:" + emailCC);
                        try
                        {
                            SendMail(_SmtpServer, _SysMail, _SysMailPassword, copyEmail, emailCC, "FSU TSE", text1.Substring(text1.IndexOf("FSU/14"), text1.Length - text1.IndexOf("FSU/14")));
                        }
                        catch (Exception e)
                        {
                            b.WriteMyLOG("SEND Flight FSU:" + e);
                        }
                    }

                }

                //Жібереміз
                try
                {
                    FTPClient ftp = new FTPClient(_RemoteHostFids, _RemoteLoginFids, _RemotePasswordFids);
                    // ftp.Download("LDM.txt", AppDomain.CurrentDomain.BaseDirectory + "LDM.txt");
                    string[] array1 = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.SND");
                    foreach (string name in array1)
                    {
                        Console.WriteLine(name);
                        byte pervyi = 1;
                        while (true)
                        {
                            try
                            {
                                ftp.UploadFile(name);
                                break;
                            }
                            catch (Exception e)
                            {
                                if (pervyi == 1)
                                {
                                    eventLog1.WriteEntry("Работа остановилась связи копированием " + e.ToString());
                                    pervyi = 2;
                                }
                                Thread.Sleep(10000);
                            }
                        }
                        if (pervyi == 2)
                            eventLog1.WriteEntry("Работа возобновилась");
                        File.Delete(name);
                    }

                }
                catch (IOException copyError)
                {
                    eventLog1.WriteEntry(copyError.Message);
                    throw;
                }

                XNamespace am = "http://www.sita.aero/ams6-xml-api-messages";
                XNamespace ad = "http://www.sita.aero/ams6-xml-api-datatypes";
                XElement root = null;
                root = new XElement(am + "Envelope",
                        new XAttribute(XNamespace.Xmlns + "amsx-messages", "http://www.sita.aero/ams6-xml-api-messages"),
                        new XAttribute("apiVersion", "1.2"),
                        new XAttribute(XNamespace.Xmlns + "amsx-datatypes", "http://www.sita.aero/ams6-xml-api-datatypes"),
                        new XElement(am + "Content",
                            new XElement(am + "FlightUpdateRequest",
                                new XElement(am + "FlightId",
                                    new XElement(ad + "FlightKind", "Departure"),
                                    new XElement(ad + "AirlineDesignator", selF.CIata, new XAttribute("codeContext", "IATA")),
                                    new XElement(ad + "FlightNumber", selF.FlightNumber),
                                    new XElement(ad + "ScheduledDate", selF.FlightSDO.ToString("yyyy-MM-dd")),
                                    new XElement(ad + "AirportCode", "TSE", new XAttribute("codeContext", "IATA"))
                                    ),
                                new XElement(am + "FlightUpdates",
                                    new XElement(am + "Update", "True", new XAttribute("propertyName", "FSU"))
                                )
                            )
                        ));

                messageQueue1.Path = queuePath;
                System.Messaging.Message testMgs = new System.Messaging.Message();
                testMgs.Body = root;
                if (emulationMode == "Real") messageQueue1.Send(testMgs);
                CsOG = CsOG + " " + root.ToString();
            }
            b.WriteMyLOG("SEND Flight FSU14 count(" + Convert.ToString(sou) +")" + CsOG);
            b.CloseReader();
            this.timerKezegi = "LDM";
        }
        private void button6_Click(object sender, EventArgs e)
        {
            string _RemoteHost = "ftp://10.10.10.2/out/";
            string _RemoteLogin = "******";
            string _RemotePassword = "******";

            List<SelectedFlights> flightList = new List<SelectedFlights>();
            Broker b = new Broker();
            flightList = b.FillListBoxSelectedFlightsFFMfromAMS("FSULITE", 1);

            String CsOG = "";
            foreach (var item in flightList)
            {
                List<FFM> ffmList = new List<FFM>();
                ffmList = b.FillListBoxFFMfromAMS(item);

                //Толтырамыз
                string text1 = "=PRIORITY\nQU\n=DESTINATION TYPE B\nSTX,TSEAPXH\n=ORIGIN\nTSEDBXH\n= TEXT\nFFM/8\n1/PS102/27MAY1930/KBP/URGAU\nTSE\nLAST";
                text1 = text1.Replace("TSEAPXH", item.TypeBADDRESS);
                text1 = text1.Replace("PS102", item.FlightIdentifier);
                text1 = text1.Replace("27MAY", item.FlightSDO.ToString("ddMMM"));
                text1 = text1.Replace("1930", item.FlightSTO.ToString("HHmm"));
                text1 = text1.Replace("KBP", item.Destination);
                text1 = text1.Replace("KBP", item.Destination);
                text1 = text1.Replace("URGAU", item.Registration);

                string textFFM = "";
                foreach (var itemf in ffmList) //555-92050641SVOTSE/T5K38MC0.53/COURIER CARGO/ XPS
                {
                    textFFM = textFFM + itemf.AwbSerialNumber + item.Destination + "TSE/T" + itemf.Pieces + "K" + itemf.Weight + "MC" + itemf.Volume + "/" + itemf.Goods + "/" + itemf.ShipmentDescriptionCode + "\n";
                }

                text1 = text1.Insert(text1.IndexOf("TSE\n") + 4, textFFM);

                //Cақтаймыз
                SaveFFM(text1, "FFM2");

                //Жібереміз
                try
                {
                    FTPClient ftp = new FTPClient(_RemoteHost, _RemoteLogin, _RemotePassword);
                    // ftp.Download("LDM.txt", AppDomain.CurrentDomain.BaseDirectory + "LDM.txt");
                    string[] array1 = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.SND");
                    foreach (string name in array1)
                    {
                        Console.WriteLine(name);
                        ftp.UploadFile(name);
                        File.Delete(name);
                    }

                }
                catch (IOException copyError)
                {
                    throw;
                }

                XNamespace am = "http://www.sita.aero/ams6-xml-api-messages";
                XNamespace ad = "http://www.sita.aero/ams6-xml-api-datatypes";
                XElement root = null;
                root = new XElement(am + "Envelope",
                        new XAttribute(XNamespace.Xmlns + "amsx-messages", "http://www.sita.aero/ams6-xml-api-messages"),
                        new XAttribute("apiVersion", "1.2"),
                        new XAttribute(XNamespace.Xmlns + "amsx-datatypes", "http://www.sita.aero/ams6-xml-api-datatypes"),
                        new XElement(am + "Content",
                            new XElement(am + "FlightUpdateRequest",
                                new XElement(am + "FlightId",
                                    new XElement(ad + "FlightKind", "Departure"),
                                    new XElement(ad + "AirlineDesignator", item.CIata, new XAttribute("codeContext", "IATA")),
                                    new XElement(ad + "FlightNumber", item.FlightIdentifier.Substring(2, item.FlightIdentifier.Length - 2)),
                                    new XElement(ad + "ScheduledDate", item.FlightSDO.ToString("yyyy-MM-dd")),
                                    new XElement(ad + "AirportCode", "TSE", new XAttribute("codeContext", "IATA"))
                                    ),
                                new XElement(am + "FlightUpdates",
                                    new XElement(am + "Update", "True", new XAttribute("propertyName", "ffm_is_send"))
                                )
                            )
                        ));

                //messageQueue1.Path = queuePath;
                //System.Messaging.Message testMgs = new System.Messaging.Message();
                //testMgs.Body = root;
                //if (emulationMode == "Real") messageQueue1.Send(testMgs);
                CsOG = CsOG + " " + root.ToString();
            }
            b.WriteMyLOG("SEND Flight FFM: " + CsOG);
            b.CloseReader();
        }