Example #1
0
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if ((e.Cancelled == true))
            {
                this.tbProgress.Content = "Canceled!";
            }

            else if (!(e.Error == null))
            {
                this.tbProgress.Content = ("Error: " + e.Error.Message);
            }

            else
            {
                this.tbProgress.Content = "synchronised information!";

                HomeWindow w = new HomeWindow();
                w.Owner = Window.GetWindow(this);
                w.Show();
            }
        }
Example #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {

            if (_UsersList.Count < 1)
            {
                tbProgress.Content = "you have no users in your list!";

            }
            else
            {

                string usernames = ""; string roles = ""; string station = ""; 
            try {

                       usernames = _UsersList.Where(l => l.Email == EmailTxtBx.Text && l.Password == Encryption.SimpleEncrypt(passwordTxt.Password)).Select(l => l.Name).SingleOrDefault().ToString();
                       roles = _UsersList.Where(l => l.Email == EmailTxtBx.Text).Select(l => l.Role).SingleOrDefault().ToString();
                       station = _UsersList.Where(l => l.Email == EmailTxtBx.Text).Select(l => l.Station).SingleOrDefault().ToString();
              }
                catch {

                    tbProgress.Content = "invalid user!";                
                }

                if (usernames != "")
                {
                    if (roles.ToString().Contains("Observer") || roles.ToString().Contains("O/C"))
                    {
                        Sending.currentinstance = "data";
                        tbProgress.Content = "Welcome observer..........";

                        if (_stationList.Count < 1)
                        {
                            login.Visibility = System.Windows.Visibility.Hidden;
                            cancel.Visibility = System.Windows.Visibility.Hidden;
                            string URLs = Sending.genUrl + "apicheck/check";
                            NameValueCollection formDatas = new NameValueCollection();
                            formDatas["station"] = station;
                            String results = Sending.send(URLs, formDatas);

                            if (results == "F")
                            {
                                tbProgress.Content = "Invalid station";
                            }
                            else
                            {
                                tbProgress.Content = "welcome " + station;
                                Station models = JsonConvert.DeserializeObject<Station>(results);
                                //System.Diagnostics.Debug.WriteLine(model.ElementAt(d).Number);

                                _station = App.WimeaApp.Stations.Add();
                                _station.Name = models.Name;
                                _station.Number = models.Number;
                                _station.Code = models.Code;
                                _station.Latitude = models.Latitude;
                                _station.Longitude = models.Longitude;
                                _station.Altitude = models.Altitude;
                                _station.Type = models.Type;
                                _station.Location = models.Location;
                                _station.Status = models.Status + " ";
                                _station.Commissioned = DateTime.Now.Date.ToString();
                                _station.Save();

                                name = models.Name;
                                bw.RunWorkerAsync();
                                bw.WorkerReportsProgress = true;
                                bw.DoWork += new DoWorkEventHandler(bw_DoWork);
                                bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
                                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

                                Sending.currentinstance = "observer";
                                Sending.currentusername = r.Name;
                                Sending.currentstation = r.Station;
                                Sending.currentstation = station;
                                Sending.currentusername = usernames;
                                HomeWindow w = new HomeWindow();
                                w.Owner = Window.GetWindow(this);
                                w.Show();
                            }
                        }
                        else {

                            Sending.currentstation = station;
                            Sending.currentusername = usernames;
                            HomeWindow w = new HomeWindow();
                            w.Owner = Window.GetWindow(this);
                            w.Show();
                        }
                       
                    }
                    if (roles.ToString().Contains("Data") || roles.ToString().Contains("Manager"))
                    {
                        Sending.currentinstance = "center";
                        if (_stationList.Count < 1)
                        {
                            tbProgress.Content = "syncing information";
                            //syncs(Sending.genUrl + "apiuser/user/station/centers/format/json", "users", "center");
                            syncs(Sending.genUrl + "apistation/station/station/center/format/json", "stations", "center");
                            syncs(Sending.genUrl + "apielement/element/format/json", "elements", "center");
                            syncs(Sending.genUrl + "apiinstrument/instrument/format/json", "instruments", "center");
                            tbProgress.Content = "Loading to database";
                            Loading_stations();
                            Loading_elements();
                            Loading_allinstruments();
                            tbProgress.Content = "Redirecting...................";
                        }

                        Sending.currentstation = station;
                        Sending.currentusername = usernames;
                        HomeWindow w = new HomeWindow();
                        w.Owner = Window.GetWindow(this);
                        w.Show();

                    }
                 
                }
            }

        }
Example #3
0
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if ((e.Cancelled == true))
            {
                this.tbProgress.Content = "Canceled!";

            }

            else if (!(e.Error == null))
            {
                this.tbProgress.Content = ("Error: " + e.Error.Message);

            }

            else
            {
                this.tbProgress.Content = "synchronised information!";

                HomeWindow w = new HomeWindow();
                w.Owner = Window.GetWindow(this);
                w.Show();

            }
        }
Example #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (_UsersList.Count < 1)
            {
                tbProgress.Content = "you have no users in your list!";
            }
            else
            {
                string usernames = ""; string roles = ""; string station = "";
                try {
                    usernames = _UsersList.Where(l => l.Email == EmailTxtBx.Text && l.Password == Encryption.SimpleEncrypt(passwordTxt.Password)).Select(l => l.Name).SingleOrDefault().ToString();
                    roles     = _UsersList.Where(l => l.Email == EmailTxtBx.Text).Select(l => l.Role).SingleOrDefault().ToString();
                    station   = _UsersList.Where(l => l.Email == EmailTxtBx.Text).Select(l => l.Station).SingleOrDefault().ToString();
                }
                catch {
                    tbProgress.Content = "invalid user!";
                }

                if (usernames != "")
                {
                    if (roles.ToString().Contains("Observer") || roles.ToString().Contains("O/C"))
                    {
                        Sending.currentinstance = "data";
                        tbProgress.Content      = "Welcome observer..........";

                        if (_stationList.Count < 1)
                        {
                            login.Visibility  = System.Windows.Visibility.Hidden;
                            cancel.Visibility = System.Windows.Visibility.Hidden;
                            string URLs = Sending.genUrl + "apicheck/check";
                            NameValueCollection formDatas = new NameValueCollection();
                            formDatas["station"] = station;
                            String results = Sending.send(URLs, formDatas);

                            if (results == "F")
                            {
                                tbProgress.Content = "Invalid station";
                            }
                            else
                            {
                                tbProgress.Content = "welcome " + station;
                                Station models = JsonConvert.DeserializeObject <Station>(results);
                                //System.Diagnostics.Debug.WriteLine(model.ElementAt(d).Number);

                                _station              = App.WimeaApp.Stations.Add();
                                _station.Name         = models.Name;
                                _station.Number       = models.Number;
                                _station.Code         = models.Code;
                                _station.Latitude     = models.Latitude;
                                _station.Longitude    = models.Longitude;
                                _station.Altitude     = models.Altitude;
                                _station.Type         = models.Type;
                                _station.Location     = models.Location;
                                _station.Status       = models.Status + " ";
                                _station.Commissioned = DateTime.Now.Date.ToString();
                                _station.Save();

                                name = models.Name;
                                bw.RunWorkerAsync();
                                bw.WorkerReportsProgress = true;
                                bw.DoWork             += new DoWorkEventHandler(bw_DoWork);
                                bw.ProgressChanged    += new ProgressChangedEventHandler(bw_ProgressChanged);
                                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

                                Sending.currentinstance = "observer";
                                Sending.currentusername = r.Name;
                                Sending.currentstation  = r.Station;
                                Sending.currentstation  = station;
                                Sending.currentusername = usernames;
                                HomeWindow w = new HomeWindow();
                                w.Owner = Window.GetWindow(this);
                                w.Show();
                            }
                        }
                        else
                        {
                            Sending.currentstation  = station;
                            Sending.currentusername = usernames;
                            HomeWindow w = new HomeWindow();
                            w.Owner = Window.GetWindow(this);
                            w.Show();
                        }
                    }
                    if (roles.ToString().Contains("Data") || roles.ToString().Contains("Manager"))
                    {
                        Sending.currentinstance = "center";
                        if (_stationList.Count < 1)
                        {
                            tbProgress.Content = "syncing information";
                            //syncs(Sending.genUrl + "apiuser/user/station/centers/format/json", "users", "center");
                            syncs(Sending.genUrl + "apistation/station/station/center/format/json", "stations", "center");
                            syncs(Sending.genUrl + "apielement/element/format/json", "elements", "center");
                            syncs(Sending.genUrl + "apiinstrument/instrument/format/json", "instruments", "center");
                            tbProgress.Content = "Loading to database";
                            Loading_stations();
                            Loading_elements();
                            Loading_allinstruments();
                            tbProgress.Content = "Redirecting...................";
                        }

                        Sending.currentstation  = station;
                        Sending.currentusername = usernames;
                        HomeWindow w = new HomeWindow();
                        w.Owner = Window.GetWindow(this);
                        w.Show();
                    }
                }
            }
        }