public static int Update_Terminal(DataTable table, string dest)
        {
            int count_ATM = 0;
            int count_POS = 0;

            try
            {
                foreach (DataRow row in table.Rows)
                {
                    if (dataAccess.Check_Exist_Ter(row.ItemArray[0].ToString()) == 1)//terminal da ton tai
                    {
                        if (row.ItemArray[4].ToString() == "ATM")
                        {
                            bool temp = dataAccess.Update_Terminal(row.ItemArray[0].ToString(), row.ItemArray[1].ToString(), "FCC", row.ItemArray[5].ToString());
                            if (temp == true)
                            {
                                count_ATM++;
                                dataAccess.Insert_Terminal_FromFCC(row.ItemArray[0].ToString(), row.ItemArray[1].ToString(), row.ItemArray[4].ToString()
                                                                   , row.ItemArray[5].ToString(), row.ItemArray[7].ToString(), row.ItemArray[8].ToString(), row.ItemArray[6].ToString());
                                classUpdateTerminalLogWriter.WriteLog("Update ATM: " + dest + " " + row.ItemArray[0].ToString() + " " + DateTime.Now.ToString());
                            }
                        }

                        if (row.ItemArray[4].ToString() == "POS")
                        {
                            bool   temp   = false;
                            string acc_no = dataAccess.GET_INF_ACC(row.ItemArray[9].ToString());
                            if (row.ItemArray[10].ToString() == "C")
                            {
                                string acc_temp = "''" + acc_no + "''";
                                temp = dataAccess.Update_Terminal(row.ItemArray[0].ToString(), acc_temp, "CLOSED", row.ItemArray[5].ToString());
                                if (temp == true)
                                {
                                    count_POS++;
                                    dataAccess.Insert_Terminal_FromFCC(row.ItemArray[0].ToString(), acc_no, row.ItemArray[4].ToString()
                                                                       , row.ItemArray[5].ToString(), row.ItemArray[7].ToString(), row.ItemArray[8].ToString(), row.ItemArray[6].ToString());
                                    classUpdateTerminalLogWriter.WriteLog("Close POS: " + dest + " " + row.ItemArray[0].ToString() + " " + DateTime.Now.ToString());
                                }
                            }
                            else
                            {
                                temp = dataAccess.Update_Terminal(row.ItemArray[0].ToString(), acc_no, "FCC", row.ItemArray[5].ToString());
                                if (temp == true)
                                {
                                    count_POS++;
                                    dataAccess.Insert_Terminal_FromFCC(row.ItemArray[0].ToString(), acc_no, row.ItemArray[4].ToString()
                                                                       , row.ItemArray[5].ToString(), row.ItemArray[7].ToString(), row.ItemArray[8].ToString(), row.ItemArray[6].ToString());
                                    classUpdateTerminalLogWriter.WriteLog("Update POS: " + dest + " " + row.ItemArray[0].ToString() + " " + DateTime.Now.ToString());
                                }
                            }
                        }
                    }
                    else//teminal chua ton tai
                    {
                        if (row.ItemArray[4].ToString() == "ATM")
                        {
                            bool temp2 = dataAccess.Insert_Terminal(row.ItemArray[0].ToString(), row.ItemArray[1].ToString(), row.ItemArray[4].ToString(), row.ItemArray[5].ToString());
                            if (temp2 == true)
                            {
                                count_ATM++;
                                dataAccess.Insert_Terminal_FromFCC(row.ItemArray[0].ToString(), row.ItemArray[1].ToString(), row.ItemArray[4].ToString()
                                                                   , row.ItemArray[5].ToString(), row.ItemArray[7].ToString(), row.ItemArray[8].ToString(), row.ItemArray[6].ToString());
                                classUpdateTerminalLogWriter.WriteLog("Insert ATM: " + dest + " " + row.ItemArray[0].ToString() + " " + DateTime.Now.ToString());
                            }
                        }
                        if (row.ItemArray[4].ToString() == "POS")
                        {
                            string acc_no = dataAccess.GET_INF_ACC(row.ItemArray[9].ToString());
                            string type_P = "CMS";
                            bool   temp2  = dataAccess.Insert_Terminal(row.ItemArray[0].ToString(), acc_no, type_P, row.ItemArray[5].ToString());
                            if (temp2 == true)
                            {
                                count_POS++;
                                dataAccess.Insert_Terminal_FromFCC(row.ItemArray[0].ToString(), row.ItemArray[1].ToString(), row.ItemArray[4].ToString()
                                                                   , row.ItemArray[5].ToString(), row.ItemArray[7].ToString(), row.ItemArray[8].ToString(), row.ItemArray[6].ToString());
                                classUpdateTerminalLogWriter.WriteLog("Insert POS: " + dest + " " + row.ItemArray[0].ToString() + " " + DateTime.Now.ToString());
                            }
                        }
                    }
                }

                //if(count_ATM > 0)
                //classUpdateTerminalLogWriter.WriteLog("Update " + count_ATM + " ATM :" + DateTime.Now.ToString() );
                //if (count_POS > 0)
                //classUpdateTerminalLogWriter.WriteLog("Update " + count_POS + " POS :" + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                classUpdateTerminalLogWriter.WriteLog("Error Update_Terminal(), " + ex.Message);
                return(0);
            }
            return(count_POS + count_ATM);
        }