Пример #1
0
                private void btnDialogOk_Click(object sender, RoutedEventArgs e)
                {
                    try
                    {
                        _station = App.WimeaApp.Stations.Add();
                        _station.Name = nameTxtBx.Text;
                        _station.Number = numberTxtBx.Text;
                        _station.Code = codeTxtBx.Text;
                        _station.Latitude = latitudeTxtBx.Text;
                        _station.Longitude = longitudeTxtBx.Text;
                        _station.Altitude = altitudeTxtBx.Text;
                        _station.Type = typeTxtBx.Text;
                        _station.Location = locationTxtBx.Text;
                        _station.Status = statusTxtCbx.Text;
                        _station.Commissioned = commissionedDatePicker.Text;
                        _station.Save();
                        this.DialogResult = true;
                    }
                    catch (Exception ex) {

                        MessageBox.Show(ex.Message.ToString());
                        return;
                    
                    }
                    
                   
                }
Пример #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();

                    }
                 
                }
            }

        }
Пример #3
0
        private string Loading_stations()
        {
            //string reply = "";
            //try
            //{
            string total = "";
            string[] lines = System.IO.File.ReadAllLines(Sending.directoryUrl + "center-" + "stations" + ".json");
            foreach (string line in lines)
            {

                total += line;
            }

            List<Station> model = JsonConvert.DeserializeObject<List<Station>>(total);

            for (int d = 0; d < model.Count; d++)
            {
                try
                {

                    s = new Station(null);
                    s.Name = model.ElementAt(d).Name;
                    s.Number = model.ElementAt(d).Number;
                    s.Code = model.ElementAt(d).Code;
                    s.Latitude = model.ElementAt(d).Latitude;
                    s.Longitude = model.ElementAt(d).Longitude;
                    s.Altitude = model.ElementAt(d).Altitude;
                    s.Type = model.ElementAt(d).Type;
                    s.Location = model.ElementAt(d).Location;
                    s.Status = model.ElementAt(d).Status;
                    s.Commissioned = model.ElementAt(d).Commissioned + " ";
                    s.Sync = "T";
                    s.Save();

                }
                catch (Exception)
                {
                    s = new Station(null);
                    s.Name = model.ElementAt(d).Name;
                    s.Number = model.ElementAt(d).Number;
                    s.Code = model.ElementAt(d).Code;
                    s.Latitude = model.ElementAt(d).Latitude;
                    s.Longitude = model.ElementAt(d).Longitude;
                    s.Altitude = model.ElementAt(d).Altitude;
                    s.Type = model.ElementAt(d).Type;
                    s.Location = model.ElementAt(d).Location;
                    s.Status = model.ElementAt(d).Status;
                    s.Commissioned = model.ElementAt(d).Commissioned + " ";
                    s.Sync = "T";
                    s.Save();

                }

            }
            return "Loaded synoptic information into local database!";

            //}
            //catch (Exception ex)
            //{

            //    MessageBox.Show(ex.Message.ToString());
            //    return "done loading metars";

            //}


        }
Пример #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (instance.SelectedItem.ToString().Contains("center"))
            {
                Sending.currentinstance = "Data center";
                Login w = new Login();
                w.Owner = Window.GetWindow(this);
                w.Show();
                this.Visibility = Visibility.Collapsed;

            }
            if (!Sending.IsInternetAvailable())
            {
                registers.Visibility = System.Windows.Visibility.Hidden;
                cancels.Visibility = System.Windows.Visibility.Hidden;

                if (station.Text != "")
                {

                    string URL = Sending.genUrl + "apicheck/check";
                    NameValueCollection formData = new NameValueCollection();
                    formData["station"] = station.Text;
                    String results = Sending.send(URL, formData);

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

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

                        name = model.Name;
                        bw.RunWorkerAsync();
                        bw.WorkerReportsProgress = true;
                        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
                        bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
                        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
                        //  tbProgress.Content = "Station already in your database";                        
                    }
                }
                else
                {

                    tbProgress.Content = "You be a data center";

                }
            }
            else { tbProgress.Content = "You require an internet connection for the initial setup"; }
        }