Beispiel #1
0
        private void PanelLogin_OnSubmitEventHandler (object sender, RoutedEventArgs e) {
            //Validation
            panelLogin.ErrorNote = "";
            if (String.IsNullOrEmpty(panelLogin.CompanyUsername)) {
                panelLogin.ErrorNote = "Company field is empty.";
                return;
            }
            if (String.IsNullOrEmpty(panelLogin.Username)) {
                panelLogin.ErrorNote = "Username field is empty.";
                return;
            }
            if (String.IsNullOrEmpty(panelLogin.Password)) {
                panelLogin.ErrorNote = "Password field is empty.";
                return;
            }

            user = new User();
            company = new Company();
            company.Username = panelLogin.CompanyUsername;
            user.Username = panelLogin.Username;
            user.Password = Cryptography.md5(panelLogin.Password);
            user.RememberMe = panelLogin.RememberMe;

            ThreadPool.QueueUserWorkItem(new WaitCallback(run));
        }
Beispiel #2
0
 public FormMain(Company company, User user, List<Company> companies, Database database) {
     this.company = company;
     this.user = user;
     this.companies = companies;
     this.database = database;
     InitializeComponent();
 }
Beispiel #3
0
 public UserItem(User user) {
     this.user = user;
 }
Beispiel #4
0
        public FormMain (Company company, User user, Database database) {
            InitializeComponent();
            this.user = user;
            this.database = database;
            this.company = company;

            server = new Server();
            server.Name = "Realtime";
            server.Ip = Settings.Default.webServiceIp;
            server.PortCommand = 8001;
            server.PortHttp = Settings.Default.webServicePort;


            loadMap();
            loadDefaultLayout();
        }
Beispiel #5
0
        //public void fillPois(Company company, User user) {
        //    ConcurrentQueue<Poi> pois = new ConcurrentQueue<Poi>();
        //    try {
        //        mysqlConnection = new MySqlConnection(database.getConnectionString());

        //        mysqlConnection.Open();

        //        string sql =
        //            "SELECT * " +
        //            "FROM cmp_" + company.DatabaseName + ".poi_" + user.DatabaseName + ";";

        //        MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);

        //        MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

        //        if (!mySqlDataReader.HasRows) {
        //            mySqlDataReader.Dispose();
        //        } else {
        //            while (mySqlDataReader.Read()) {
        //                Poi poi = new Poi();
        //                poi.Id = mySqlDataReader.GetInt32("poi_id");
        //                poi.Name = mySqlDataReader.GetString("poi_name");
        //                poi.Description = mySqlDataReader.GetString("poi_desc");
        //                poi.Image = mySqlDataReader.GetString("poi_img");


        //                string latitude = mySqlDataReader.GetString("poi_lat");
        //                string longitude = mySqlDataReader.GetString("poi_lon");

        //                if(String.IsNullOrEmpty(latitude) || String.IsNullOrEmpty(longitude)) {
        //                    poi.Coordinate = new Coordinate(0.0f, 0.0f);
        //                } else {
        //                    poi.Coordinate = new Coordinate(double.Parse(latitude), double.Parse(longitude));
        //                }

        //                pois.Enqueue(poi);
        //            }

        //            user.Pois = pois;
        //            mySqlDataReader.Dispose();
        //        }
        //    } catch (MySqlException mySqlException) {
        //        throw new QueryException(1, mySqlException.Message);
        //    } catch (QueryException queryException) {
        //        throw queryException;
        //    } catch (Exception exception) {
        //        throw new QueryException(1, exception.Message);
        //    } finally {
        //        mysqlConnection.Close();
        //    }
        //}

        public void fillUsers (Company company, User user) {
            ConcurrentQueue<User> users = new ConcurrentQueue<User>();
            try {
                mysqlConnection = new MySqlConnection(database.getConnectionString());

                mysqlConnection.Open();

                string sql = "";

                if (user.AccessLevel == 1 || user.AccessLevel == 2) {
                    sql =
                    "SELECT * " +
                    "FROM cmp_" + company.DatabaseName + ".usrs " +
                    "WHERE cmp_" + company.DatabaseName + ".usrs.upriv >= " + user.AccessLevel.ToString() + ";";
                } else {
                    sql =
                    "SELECT * " +
                    "FROM cmp_" + company.DatabaseName + ".usrs " +
                    "WHERE cmp_" + company.DatabaseName + ".usrs.upriv = " + user.AccessLevel.ToString() + " and " +
                    "cmp_" + company.DatabaseName + ".usrs.uname = '" + user.Username + "';";
                }

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);

                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                if (!mySqlDataReader.HasRows) {
                    mySqlDataReader.Dispose();
                    throw new QueryException(1, "Users table is empty.");
                } else {
                    while (mySqlDataReader.Read()) {
                        User userSubordinate = new User();
                        userSubordinate.Id = mySqlDataReader.GetInt32("uid");
                        userSubordinate.Username = mySqlDataReader.GetString("uname");
                        userSubordinate.Password = mySqlDataReader.GetString("upass");
                        userSubordinate.Email = mySqlDataReader.GetString("uemail");
                        userSubordinate.Main = mySqlDataReader.GetString("umain");
                        userSubordinate.AccessLevel = int.Parse(mySqlDataReader.GetString("upriv"));
                        userSubordinate.Timezone = mySqlDataReader.GetString("utimezone");
                        userSubordinate.IsActive = mySqlDataReader.GetString("uactive").Equals("1");
                        userSubordinate.DatabaseName = mySqlDataReader.GetString("udbs");

                        if (!String.IsNullOrEmpty(mySqlDataReader.GetString("uexpiredate"))) {
                            string dateTime = (mySqlDataReader.GetString("uexpiredate"));
                            if (!String.IsNullOrEmpty(dateTime)) {
                                DateTime parsedDate = SubStandard.dateTime(dateTime);
                                userSubordinate.DateTimeExpired = parsedDate;
                            }
                        } else {
                            userSubordinate.DateTimeExpired = new DateTime(2050, 01, 01);
                        }

                        if (!String.IsNullOrEmpty(mySqlDataReader.GetString("ucreatedate"))) {
                            string dateTime = mySqlDataReader.GetString("ucreatedate");
                            if (!String.IsNullOrEmpty(dateTime)) {
                                DateTime parsedDate = SubStandard.dateTime(dateTime);
                                userSubordinate.DateTimeCreated = parsedDate;
                            }
                        } else {
                            userSubordinate.DateTimeCreated = new DateTime(2010, 01, 01);
                        }
                        users.Enqueue(userSubordinate);
                    }
                    mySqlDataReader.Dispose();
                }

            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }
            company.Users = users;
        }
Beispiel #6
0
        public void getUser (Company company, User user) {
            try {
                mysqlConnection = new MySqlConnection(database.getConnectionString());

                mysqlConnection.Open();

                string sql =
                    "SELECT * " +
                    "FROM cmp_" + company.DatabaseName + ".usrs " +
                    "WHERE " +
                    "cmp_" + company.DatabaseName + ".usrs.uname = @sUsername AND " +
                    "cmp_" + company.DatabaseName + ".usrs.upass = @sPassword;";

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);
                mySqlCommand.Parameters.AddWithValue("@sUsername", user.Username);
                mySqlCommand.Parameters.AddWithValue("@sPassword", user.Password);

                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                if (!mySqlDataReader.HasRows) {
                    mySqlDataReader.Dispose();
                    throw new QueryException(1, "Username or Password does not exist.");
                } else {
                    mySqlDataReader.Read();

                    user.Id = mySqlDataReader.GetInt32("uid");
                    user.Username = mySqlDataReader.GetString("uname");
                    user.Password = mySqlDataReader.GetString("upass");
                    user.Email = mySqlDataReader.GetString("uemail");
                    user.Main = mySqlDataReader.GetString("umain");
                    user.AccessLevel = int.Parse(mySqlDataReader.GetString("upriv"));
                    user.Timezone = mySqlDataReader.GetString("utimezone");
                    user.IsActive = mySqlDataReader.GetString("uactive").Equals("1");
                    user.DatabaseName = mySqlDataReader.GetString("udbs");

                    if (!String.IsNullOrEmpty(mySqlDataReader.GetString("uexpiredate"))) {
                        string dateTime = (mySqlDataReader.GetString("uexpiredate"));
                        if (!String.IsNullOrEmpty(dateTime)) {
                            DateTime parsedDate = SubStandard.dateTime(dateTime);
                            user.DateTimeExpired = parsedDate;
                        }
                    } else {
                        user.DateTimeExpired = new DateTime(2050, 01, 01);
                    }

                    if (!String.IsNullOrEmpty(mySqlDataReader.GetString("ucreatedate"))) {
                        string dateTime = mySqlDataReader.GetString("ucreatedate");
                        if (!String.IsNullOrEmpty(dateTime)) {
                            DateTime parsedDate = SubStandard.dateTime(dateTime);
                            user.DateTimeCreated = parsedDate;
                        }
                    } else {
                        user.DateTimeCreated = new DateTime(2010, 01, 01);
                    }
                    mySqlDataReader.Dispose();
                }

            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }
        }