public List<FFM> FillListBoxFFM(string Occupation)
        {
            List<FFM> messageList = new List<FFM>();
            string line;
            Boolean Blok;
            Blok = false;
            int FirstLastLine = 0;
            int bir = 0;
            string aPartLine = "";
            string aPartLineNext = "";
            string[] split;

            string FlightIdentifierV = "";
            int DayOfMonthV = 0;
            string MonthOfOperationV = "";
            string TimeOfScheduledDepartureV = "";
            string AircraftRegistrationV = "";
            int MessageSequenceNumber = 1;
            string FlightKind = "";
            string Destination = "";
            string occupationAinymaly = "";

            try
            {

                //MessageRCV-нің соңына дейін бару
                while (readerFFM.Peek() >= 0)
                {

                    if (readerFFM.ReadLine() == Occupation)
                    {
                        while (readerFFM.Peek() >= 0)
                        {
                            if (readerFFM.ReadLine().Length == 0)
                            {
                                break;
                            }
                        }
                        break;
                    }
                }

                while ((line = readerFFM.ReadLine()) != null)
                {
                    if (line == "FFM/8" || line == "FFM/5")
                    {
                        Blok = true;
                        FlightIdentifierV = "";
                        DayOfMonthV = 0;
                        aPartLine = "";
                        MonthOfOperationV = "";
                        TimeOfScheduledDepartureV = "";
                        AircraftRegistrationV = "";
                        //MessageSequenceNumber = 1;
                        FlightKind = "";
                        Destination = "";
                        FirstLastLine = 1;
                    }
                    else if (line.Length == 0)
                    {
                        Blok = false;
                    }
                    else if (Blok)
                    {
                        if (line.IndexOf("/") != -1 && line.StartsWith(MessageSequenceNumber + "/") && FirstLastLine == 1)
                        {

                            string[] splitF = line.Split('/');
                            foreach (string s in splitF)
                            {
                                if (s.Trim() != "")
                                {
                                    if (AircraftRegistrationV == "" & bir == 4)
                                    {
                                        AircraftRegistrationV = s;
                                        bir = 5;
                                    }

                                    if (Destination == "" & bir == 3)
                                    {
                                        Destination = s;
                                        bir = 4;
                                    }

                                    if (DayOfMonthV == 0 & bir == 2)
                                    {
                                        DayOfMonthV = Convert.ToInt32(s.Substring(0, 2));
                                        MonthOfOperationV = s.Substring(2, 3);
                                        if (s.Length == 9) TimeOfScheduledDepartureV = s.Substring(5, 4); else TimeOfScheduledDepartureV = "";
                                        bir = 3;
                                    }

                                    if (FlightIdentifierV == "" & bir == 1)
                                    {
                                        FlightIdentifierV = s;
                                        bir = 2;
                                    }

                                    if (MessageSequenceNumber == 1 & bir == 0)
                                    {
                                        MessageSequenceNumber = Convert.ToInt32(s);
                                        bir = 1;
                                    }

                                    Console.WriteLine(s);

                                }
                            }

                            FirstLastLine = 2;
                        }
                        else if (line.StartsWith("TSE") && !line.Contains("NIL") && FirstLastLine == 2)
                        {

                            FirstLastLine = 3;
                            FlightKind = "Arrival";
                            Destination = "TSE";
                        }
                        else if (line.StartsWith("TSE") && line.Contains("NIL") && FirstLastLine == 2)
                        {
                            Blok = false;
                        }
                        else if (!line.StartsWith("-TSE") && line.IndexOf("/") != -1 && FirstLastLine == 2 && MessageSequenceNumber == 1) //Ұшуға дайындалу бірақ қазір сөндірулі
                        { //Әзірге LDM барлық авакомпания жібермейінше 2 - 20 деп қойылд
                            aPartLine = line;
                            FirstLastLine = 3;
                            FlightKind = "Departure";
                            Destination = line.Substring(1, 3);
                        }
                        //     else if (line.IndexOf("-") != -1 && line.IndexOf("/") != -1 && FirstLastLine <= 4)
                        else if (Regex.IsMatch(line, @"^\d{3}-\d{8}[a-zA-Z]{6}/[a-zA-Z]\d{1,4}[a-zA-Z][\d\.]{1,8}([a-zA-Z]{2}[\d\.]{1,10})?([a-zA-Z]{2}\d{1,2})?([a-zA-Z]\d{1,4})?/.{1,15}(/[a-zA-Z]{3})?$") && FirstLastLine <= 4)
                        {
                            aPartLine = aPartLine + "\n" + line;
                            FirstLastLine = 4;
                        }
                        else if (FirstLastLine <= 4 && line.StartsWith("LAST"))
                        {
                            FFM messageFFM = new FFM();
                            messageFFM.MessageIdentifier = FlightKind;
                            messageFFM.Registration = AircraftRegistrationV;
                            messageFFM.MonthOfOperation = MonthOfOperationV;
                            messageFFM.FlightIdentifier = FlightIdentifierV;
                            messageFFM.DayOfOperation = DayOfMonthV;
                            //messageLDM.MessageIdentifier = aPartLine;
                            Blok = false;
                            FirstLastLine = 0;

                            if (MessageSequenceNumber > 1)
                            {
                                aPartLine = aPartLineNext + aPartLine;
                                split = aPartLine.Split('\n');
                            } else split = aPartLine.Split('\n');

                            mYfUNVFFM(split, messageFFM);
                            messageList.Add(messageFFM);
                            MessageSequenceNumber = 1;
                        } else  if (FirstLastLine <= 4 && line.StartsWith("CONT"))
                        {
                            MessageSequenceNumber = MessageSequenceNumber + 1;
                            aPartLineNext = aPartLineNext +  aPartLine;
                        }

                    }
                    else if (line.StartsWith("Message RCV"))
                    {
                        SaveOccupation(line, "FFM");
                        occupationAinymaly = line;
                    }
                }

                return messageList;
            }
            catch (Exception)
            {

                WriteMyLOG("Update Failed FFM Flight: " + occupationAinymaly);
                WriteMyErrorLOG("Update Failed FFM Flight: " + occupationAinymaly);
                return messageList;
                //throw;
            }
            finally
            {
                if (readerFFM != null)
                {
            //                    readerFFM.Close();
            //                    readerFFM.Dispose();
                }
            }
        }
        public List<FFM> FillListBoxFFMfromAMS(SelectedFlights selF)
        {
            List<FFM> messageList = new List<FFM>();
            try
            {
                command2.CommandText = "SELECT *  FROM [AMSDatawarehouse].[amsdwView].[factmovement_TableAttribute_4]  where Id = " + selF.FlightId;

                connection2.Open();

                using (SqlDataReader dr = command2.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (dr.Read())
                    {
                        FFM selFFM = new FFM();
                        //selFlight.FlightATO = dr["ATO"].ToString().Equals("") ? dr["scheduledTime"].ToString() : dr["ACTUAL"].ToString();
                        selFFM.FlightIdentifier = dr["Id"].ToString();
                        selFFM.Pieces = dr["Oryn"].ToString();
                        selFFM.Weight = dr["Weight"].ToString();
                        selFFM.Goods = dr["Remarks"].ToString();
                        selFFM.AwbSerialNumber = dr["AWB Number"].ToString();
                        selFFM.VolumeCode = dr["Measument type"].ToString();
                        selFFM.Volume = dr["Measument Value"].ToString();
                        selFFM.Origin = dr["Origin IATA"].ToString();
                        selFFM.Destination = dr["Destination IATA"].ToString();
                        selFFM.ShipmentDescriptionCode = dr["AWB Types"].ToString();

                            //selFlight.Departure_FFM_NTS1 = Convert.ToBoolean(dr["Departure_UPDATE FFM"]);
                            //Sdhed = dataUshipKelu.Hour*100 + dataUshipKelu.Minute; //hhmm
                            //int Ushu = dr["R1ADT"].ToString().Equals("") ? Convert.ToInt32(dr["R1STD"]) : Convert.ToInt32(dr["R1ADT"]);
                       messageList.Add(selFFM);
                    }
                }
                if (command2.CommandText.StartsWith("UPDATE"))
                {
                    command2.Connection.Open();
                    command2.ExecuteNonQuery();
                    //messageList.Add(command.CommandText);
                }
                return messageList;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (connection2 != null)
                {
                    connection2.Close();
                }

            }
        }
        private void mYfUNVFFM(string[] split1, FFM messageFFM)
        {
            int bir = 0;
            string stinfff;
            string[] split;
            for (int i = 0; i < split1.Length; i++)
            {
                stinfff = split1[i];
                split = stinfff.Split('/');
                //messageFFM.MessageSequenceNumber = 0;
                messageFFM.AirlineAWBIdentification = "";
                messageFFM.ShipmentDescriptionCode = "";
                messageFFM.Goods = "";
                messageFFM.FieldArray = i;
                bir = 0;
                foreach (string s in split)
                {
                    if (s.Trim() != "")
                    {
                        if (messageFFM.Goods == "" & bir == 2)
                        {
                            messageFFM.Goods = s;
                            messageFFM.GoodsArr.SetValue(s, i);
                            bir = 3;
                        }

                        if (messageFFM.ShipmentDescriptionCode == "" & bir == 1)
                        {

                            string[] w = SplitWords(s);

                                messageFFM.ShipmentDescriptionCode = w[1];
                                messageFFM.ShipmentDescriptionCodeArr.SetValue(w[1], i);

                                messageFFM.Pieces = (Convert.ToInt32(messageFFM.Pieces) + Convert.ToInt32(w[2])).ToString();
                                messageFFM.PiecesArr.SetValue(w[2],i);

                                messageFFM.WeightCode = w[3];
                                messageFFM.WeightCodeArr.SetValue(w[3], i);

                                messageFFM.Weight = (Convert.ToDouble(messageFFM.Weight) + Convert.ToDouble(w[4])).ToString();
                                messageFFM.WeightArr.SetValue(w[4], i);

                                messageFFM.VolumeCode = w[5];
                                messageFFM.VolumeCodeArr.SetValue(w[5], i);

                                messageFFM.Volume = (Convert.ToDouble(messageFFM.Volume) + Convert.ToDouble(w[6])).ToString();
                                messageFFM.VolumeArr.SetValue(w[6],i);

                                Console.WriteLine(s);

                            bir = 2;
                        }

                        if (messageFFM.AirlineAWBIdentification == "")
                        {
                            messageFFM.AirlineAWBIdentification = s.Substring(0, 3);
                            messageFFM.AirlineAWBIdentificationArr.SetValue(s.Substring(0, 3), i);

                            messageFFM.AwbSerialNumber = s.Substring(4, 8);
                            messageFFM.AwbSerialNumberArr.SetValue(s.Substring(4, 8), i);

                            messageFFM.AwbOrigin = s.Substring(12, 3);
                            messageFFM.AwbOriginArr.SetValue(s.Substring(12, 3), i);

                            messageFFM.AwbDestination = s.Substring(15, 3);
                            messageFFM.AwbDestinationArr.SetValue(s.Substring(15, 3), i);

                            bir = 1;
                        }

                        Console.WriteLine(s);
                    }
                }
            }
        }