Пример #1
0
        public static void downloadAuthenCode()
        {
            int                    total          = 0;
            int                    success        = 0;
            AuthenCodeDao          dao            = new AuthenCodeDao();
            int                    StationID      = Convert.ToInt16(ManageLOG.getValueFromRegistry(Configurations.AppRegName, "StationID"));
            List <ModelAuthenCode> listAccessCode = dao.Select("", StationID);

            if (listAccessCode != null)
            {
                total = listAccessCode.Count;
                logger.Debug("# Start Download [AUTHENCODE] from server.");

                foreach (ModelAuthenCode model in listAccessCode)
                {
                    List <ModelAuthenCode> tmp = dao.SelectOffine(" Where ath_code='" + model.ath_code + "'", StationID);
                    if (tmp != null)
                    {
                        if (tmp.Count > 0)
                        {
                        }
                        else
                        {
                            if (dao.InsertOffline(model))
                            {
                                success++;
                            }
                        }
                    }
                }
                logger.Debug("# Summary=> Total Download total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Download data from server.");
            }
        }
Пример #2
0
        public static void downloadStation()
        {
            String              StationID = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "StationID");
            int                 total     = 0;
            int                 success   = 0;
            StationDao          dao       = new StationDao();
            List <ModelStation> lists     = dao.Select("");

            if (lists != null)
            {
                total = lists.Count;
                logger.Debug("# Start download [STATION] from server.");

                foreach (ModelStation model in lists)
                {
                    List <ModelStation> tmp = dao.SelectOffine(" Where id='" + model.id + "'");
                    if (tmp != null)
                    {
                        if (tmp.Count > 0)
                        {
                        }
                        else
                        {
                            if (dao.InsertOffine(model))
                            {
                                success++;
                            }
                        }
                    }
                }
                logger.Debug("# Summary=> Total Download total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Download data from server.");
            }
        }
Пример #3
0
        //open connection to database
        //public bool OpenConnection()
        //{
        //    try
        //    {
        //        connection.Open();
        //        return true;
        //    }
        //    catch (MySqlException ex)
        //    {
        //        switch (ex.Number)
        //        {
        //            case 0:
        //                MessageBox.Show("Cannot connect to server.  Contact administrator");
        //                break;
        //            case 1042:
        //                //MessageBox.Show("Cannot connect to server.  The System will work on offine mode");
        //                break;
        //            case 1045:
        //                MessageBox.Show("Invalid username/password, please try again");
        //                break;
        //        }
        //        return false;
        //    }
        //}

        //Close connection
        //public bool CloseConnection()
        //{
        //    try
        //    {
        //        connection.Close();
        //        return true;
        //    }
        //    catch (MySqlException ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        return false;
        //    }
        //}

        #endregion

        #region "SQLITE CONNECTION"
        //public bool OpenOffineConnection()
        //{
        //    try
        //    {
        //        connectionOffine.Open();
        //        return true;
        //    }
        //    catch (MySqlException ex)
        //    {
        //        switch (ex.Number)
        //        {
        //            case 0:
        //                MessageBox.Show("Cannot connect to server.  Contact administrator");
        //                break;
        //            case 1042:
        //                //MessageBox.Show("Cannot connect to server.  The System will work on offine mode");
        //                break;
        //            case 1045:
        //                MessageBox.Show("Invalid username/password, please try again");
        //                break;
        //        }
        //        return false;
        //    }
        //}

        //public bool CloseOffineConnection()
        //{
        //    try
        //    {
        //        connectionOffine.Close();
        //        return true;
        //    }
        //    catch (MySqlException ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        return false;
        //    }
        //}
        #endregion

        public static bool IsServerConnected()
        {
            //string serverDbIP = Configurations.MysqlStr.Split(';')[0].Split('=')[1];
            //PingReply pingReply;
            //using (var ping = new Ping())
            //    pingReply = ping.Send(serverDbIP);
            //var available = pingReply.Status == IPStatus.Success;

            string conStr = ManageLOG.deCode(ManageLOG.getValueFromRegistry("WiFi Management", "CON"));

            try
            {
                using (MySqlConnection conn = new MySqlConnection(conStr))
                {
                    conn.Open();
                    return(true);
                }
            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                case 0:
                    //MessageBox.Show("Cannot connect to server.  Contact administrator");

                    break;

                case 1042:
                    //MessageBox.Show("Cannot connect to server.  The System will work on offine mode");
                    break;

                case 1045:
                    //MessageBox.Show("Invalid username/password, please try again");
                    break;
                }
                return(false);
            }
            //return available;
        }
Пример #4
0
        public static void downloadGroup()
        {
            String            StationID = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "StationID");
            int               total     = 0;
            int               success   = 0;
            GroupDao          dao       = new GroupDao();
            List <ModelGroup> lists     = dao.Select("");

            if (lists != null)
            {
                total = lists.Count;
                logger.Debug("# Start download [GROUP] from server.");

                foreach (ModelGroup model in lists)
                {
                    List <ModelGroup> tmp = dao.SelectOffine(" Where group_code='" + model.group_code + "'");
                    if (tmp != null)
                    {
                        if (tmp.Count > 0)
                        {
                        }
                        else
                        {
                            //logger.Debug(">>"+model.id+","+model.group_code);
                            if (model.id > 0)
                            {
                                if (dao.InsertOffline(model))
                                {
                                    success++;
                                }
                            }
                        }
                    }
                }
                logger.Debug("# Summary=> Total Download total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Download data from server.");
            }
        }
Пример #5
0
        public static void transfer2Server()
        {
            int total   = 0;
            int success = 0;

            TransactionDao          dao       = new TransactionDao();
            int                     StationID = Convert.ToInt16(ManageLOG.getValueFromRegistry(Configurations.AppRegName, "StationID"));
            String                  cri       = " Where t.LoungePlace=" + StationID;
            List <ModelTransaction> lists     = dao.SelectOffine(cri + " order by t.update_date desc", StationID);

            if (lists != null)
            {
                total = lists.Count;
                logger.Debug("# Start Transfer data to server.");
                logger.Debug("Local transaction have " + lists.Count + " records.");
                if (lists.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ModelTransaction model in lists)
                    {
                        bool result = dao.Insert(model, StationID);
                        if (result)
                        {
                            logger.Debug("Local transaction have " + lists.Count + " records.");
                            //Delete local data when transfer to ser success.
                            if (dao.DeleteOffline(model, StationID))
                            {
                                success++;
                            }
                        }
                    }
                }
                logger.Debug("# Summary=> Total transfer total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Transfer data to server.");
            }
        }
Пример #6
0
        public static void downloadUsers()
        {
            String           StationID      = ManageLOG.getValueFromRegistry(Configurations.AppRegName, "StationID");
            int              total          = 0;
            int              success        = 0;
            UserDao          dao            = new UserDao();
            List <ModelUser> listAccessCode = dao.Select(" Where u.station_id=" + StationID);

            if (listAccessCode != null)
            {
                total = listAccessCode.Count;
                logger.Debug("# Start Download [USER] from server.");

                foreach (ModelUser model in listAccessCode)
                {
                    List <ModelUser> tmp = dao.SelectOffine(" Where user_name='" + model.user_name + "'");
                    if (tmp != null)
                    {
                        if (tmp.Count > 0)
                        {
                        }
                        else
                        {
                            if (dao.InsertOffline(model))
                            {
                                success++;
                            }
                        }
                    }
                }


                logger.Debug("# Summary=> Total Download total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Download data from server.");
            }
            StaffDao          staffDao  = new StaffDao();
            List <ModelStaff> listStaff = staffDao.Select(" Where staff_station=" + StationID);

            if (listStaff != null)
            {
                total = listStaff.Count;
                logger.Debug("# Start Download [STAFF PROFILE] from server.");

                foreach (ModelStaff model in listStaff)
                {
                    List <ModelStaff> tmp = staffDao.SelectOffline(" Where staff_name='" + model.staff_name + "'");
                    if (tmp != null)
                    {
                        if (tmp.Count > 0)
                        {
                        }
                        else
                        {
                            if (staffDao.InsertOffline(model))
                            {
                                success++;
                            }
                        }
                    }
                }



                logger.Debug("# Summary=> Total Download total: " + total + " success: " + success + " fail: " + (total - success));
                logger.Debug("# End Download data from server.");
            }
        }