Пример #1
0
        public void Allarm(string DateTime, string Number, string Message)
        {
            if (this.dataGridView1.InvokeRequired)
            {
                SetNewAllarm stc = new SetNewAllarm(Allarm);
                this.Invoke(stc, new object[] { DateTime, Number, Message });
            }
            else
            {
                smartrack pp = mainFrm.searchDevice(Number);

                dataGridView1.Rows.Add();
                if (pp != null)
                {
                    DataGridViewImageCell displayCell = null;
                    displayCell       = (DataGridViewImageCell)dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[0];
                    displayCell.Value = Image.FromFile(pp.image);

                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[1].Value = DateTime;
                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[2].Value = pp.Description + " (" + Number + ")";
                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[3].Value = Message;
                }
                else
                {
                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[1].Value = DateTime;
                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[2].Value = "(" + Number + ")";
                    dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[3].Value = Message;
                }
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            MapPoint.Map map = mainFrm.frmMapPoint.Map.ActiveMap;

            map.ActiveRoute.Clear();

            frmDriver frm = new frmDriver();

            frm.loadProfileAutomatic(mainFrm.CURRENT_DRIVER_PROFILE, map.ActiveRoute.DriverProfile);

            MapPoint.Location start = null;


            if (mainFrm.listBox1.SelectedIndex > -1)
            {
                smartrack p = mainFrm.sm_array[mainFrm.listBox1.SelectedIndex];
                start = map.GetLocation(p.Lat, p.Lon, map.Altitude);
            }

            map.ActiveRoute.Waypoints.Add(start, "Partenza");
            map.ActiveRoute.Waypoints.Add(currentLocation, "Arrivo");

            map.ActiveRoute.DriverProfile.IncludeRestStops = true;
            try
            {
                map.ActiveRoute.Calculate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (map.ActiveRoute.IsCalculated)
            {
                addNewPOI(txtDestination.Text);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (olnyAdd == false)
            {
                //***************** associo l'obiettivo al mezzo ******************
                if (mainFrm.listBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("Per associare un bersaglio è necessario selezionare prima il mezzo.");
                    return;
                }
                smartrack sm = mainFrm.searchDevicebyDescription(mainFrm.listBox1.SelectedItem.ToString());
                //sm.Bersaglio = currentLocation;

                string bersaglio = currentLocation.Name + "|" + currentLocation.Latitude + "|" + currentLocation.Longitude;

                sm.SetBersaglio(bersaglio);
                mainFrm.deviceCtrl1.refreshStatus();

                if (MessageBox.Show(this, "Bersaglio associato. Visualizzo anche l'itinerario?", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MapPoint.Map map = mainFrm.frmMapPoint.Map.ActiveMap;
                    map.ActiveRoute.Clear();

                    frmDriver frm = new frmDriver();
                    frm.loadProfileAutomatic(mainFrm.CURRENT_DRIVER_PROFILE, map.ActiveRoute.DriverProfile);

                    MapPoint.Location start = null;

                    mainFrm.frmMapPoint.Map.Units = MapPoint.GeoUnits.geoKm;
                    if (mainFrm.listBox1.SelectedIndex > -1)
                    {
                        smartrack p = mainFrm.sm_array[mainFrm.listBox1.SelectedIndex];
                        start = map.GetLocation(p.Lat, p.Lon, map.Altitude);
                    }

                    map.ActiveRoute.Waypoints.Add(start, "Partenza");
                    map.ActiveRoute.Waypoints.Add(currentLocation, "Arrivo");
                    try
                    {
                        map.ActiveRoute.Calculate();
                        map.ActiveRoute.Application.ItineraryVisible = false;

                        string Reso = "Viaggio da: " + start.Name + " a " + currentLocation.Name + "\r\n";

                        Reso += "Totale Km: " + map.ActiveRoute.Distance + ". Durata prevista tragitto: " + Math.Ceiling((map.ActiveRoute.DrivingTime * 24 * 60)) + " minuti.\r\n";
                        Reso += @"Costo totale (stimato in base al profilo di guida): " + Math.Round(map.ActiveRoute.Cost, 2) + "€";
                        if (!String.IsNullOrEmpty(mainFrm.CURRENT_DRIVER_PROFILE))
                        {
                            Reso += "\r\nProfilo di guida selezionato: " + System.IO.Path.GetFileName(mainFrm.CURRENT_DRIVER_PROFILE);
                        }
                        else
                        {
                            Reso += "\r\nProfilo di guida selezionato: nessuno";
                        }

                        if (MessageBox.Show(this, Reso + "\nAssocio l'obiettivo e salvo l'informazione?", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                            {
                                using (StreamWriter wr = new StreamWriter(saveFileDialog1.FileName, true))
                                {
                                    wr.WriteLine("**************************************");
                                    wr.WriteLine(Reso);
                                    wr.WriteLine("**************************************");
                                }
                            }

                            /* //***************** associo l'obiettivo al mezzo ******************
                             * smartrack sm = mainFrm.searchDevicebyDescription(mainFrm.listBox1.SelectedItem.ToString());
                             * sm.Bersaglio = currentLocation;
                             * mainFrm.deviceCtrl1.refreshStatus();*/
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Impossibile associare il bersaglio. Possibile causa:" + ex.Message);
                    }
                }
                this.Close();
            }
            else
            {
                this.Close();
            }
        }
Пример #4
0
 public void setDevice(smartrack dev)
 {
     this.device = dev;
     refreshStatus();
 }
Пример #5
0
        private void ElaboraSoste()
        {
            double RADIUS = 0.1;

            if (mainFrm.listBox1.SelectedItems.Count > 0)
            {
                if (mainFrm.listBox1.SelectedItems.Count == 1)
                {
                    mainFrm.updateConnectionString();
                    SqlConnection myConnection = new SqlConnection(mainFrm.connectionString);
                    myConnection.Open();
                    string     Upd = "UPDATE Position SET DateTime = REPLACE(DateTime,'.',':');";
                    SqlCommand cmd = new SqlCommand(Upd, myConnection);
                    cmd.ExecuteNonQuery();
                    myConnection.Close();

                    smartrack num = mainFrm.searchDevicebyDescription(mainFrm.listBox1.SelectedItems[0].ToString());

                    string base_sql = @"SELECT ID, Vehicle, Position, DateTime FROM Position ";

                    string data;
                    string data2;
                    data  = dateDal.Value.Month + "/" + dateDal.Value.Day + "/" + dateDal.Value.Year;
                    data2 = dateAl.Value.Month + "/" + dateAl.Value.Day + "/" + dateAl.Value.Year;

                    string SQL = "WHERE (CONVERT(DATETIME, DateTime, 103) > '" + data + "') AND (CONVERT(DATETIME, DateTime, 103) < '" + data2 + "') AND Vehicle = '" + num.device_number + "'";

                    SqlDataAdapter      da = new SqlDataAdapter(base_sql + SQL, myConnection);
                    System.Data.DataSet ds = new System.Data.DataSet();
                    da.Fill(ds, "pos");

                    string first_valid = "";
                    string last_valid  = "";
                    double Km          = 0;
                    if (ds.Tables["pos"].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables["pos"].Rows.Count; i++)
                        {
                            string position  = "";
                            string position2 = "";

                            Km = 0;
                            while (Km <= RADIUS)
                            {
                                try
                                {
                                    position  = ds.Tables["pos"].Rows[i]["Position"].ToString();
                                    position2 = ds.Tables["pos"].Rows[i + 1]["Position"].ToString();
                                }
                                catch { break; }

                                Km = calcolaKm(position, position2);
                                if (Km <= RADIUS)
                                {
                                    if (first_valid == "")
                                    {
                                        first_valid = ds.Tables["pos"].Rows[i]["DateTime"].ToString();
                                    }
                                }
                                else
                                {
                                    if (first_valid != "")
                                    {
                                        last_valid = ds.Tables["pos"].Rows[i]["DateTime"].ToString();
                                    }
                                }
                                i++;
                            }

                            if (first_valid != "" && last_valid != "")
                            {
                                DateTime        tempo1     = DateTime.Parse(first_valid);
                                DateTime        tempo2     = DateTime.Parse(last_valid);
                                System.TimeSpan diffResult = tempo2.Subtract(tempo1);
                                if (diffResult.Minutes >= int.Parse(mainFrm.TEMPO_SOSTA))
                                {
                                    listBox1.Items.Add("Sosta dal: " + first_valid + " al " + last_valid + ". Tempo:" + diffResult.Minutes + " min.");
                                }
                                first_valid = last_valid = "";
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
 public void setDevice(smartrack dev)
 {
     this.device = dev;
     refreshStatus();
 }
Пример #7
0
 public MapUtils(smartrack device, Form1 mainFrm)
 {
     this.device = device;
     this.mainFrm = mainFrm;
 }
Пример #8
0
 public bool saveDevices(smartrack[] sm_array)
 {
     try
     {
         //Save the class
         //Stream myFileStream = File.Create(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + @"\text.txt");
         Stream myFileStream = File.Create(path + @"vehicle");
         BinaryFormatter serializer = new BinaryFormatter();
         serializer.Serialize(myFileStream, sm_array);
         myFileStream.Close();
         return true;
     }
     catch
     {
         return false;
     }
 }
Пример #9
0
 public void saveDevice(smartrack dev, int Index)
 {
     sm_array[Index] = dev;
     saveDevices(sm_array);
 }
Пример #10
0
        private void nuovoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new_device d = new new_device();
            DialogResult res = d.ShowDialog();
            if (res == DialogResult.OK)
            {
                int i = 0;
                for (i = 0; i < sm_array.Length; i++)
                    if (sm_array[i] == null) break;

                sm_array[i] = new smartrack(port, d.textBox1.Text);
                sm_array[i].image = d.textBox2.Text;
                sm_array[i].Description = d.textBox3.Text;
                saveDevices(sm_array);
                sm_array = loadDevices(port);

                listBox1.Items.Clear();
                // checkedListBox1.Items.Clear();
                if (sm_array != null)
                {
                    foreach (smartrack t in sm_array)
                    {
                        if (t != null)
                        {
                            //listBox1.Items.Add(t.device_number);
                            listBox1.Items.Add(t.Description);
                        }
                    }
                }
                else
                    sm_array = new smartrack[int.MaxValue / 1024];
            }
        }
Пример #11
0
        private void importaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Per l'importazione del file csv ricordarsi di inserire:\r\n1° Riga: Password di default\r\n2° Riga: Modello predefinito di periferica\r\n3° Riga: Path dell'immagine di default.\r\nRestanti righe: Nome;ID;Targa;NTelefonico.");
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fname = openFileDialog1.FileName;

                for (int i = 0; i < sm_array.Length; i++)
                {
                    if(sm_array[i] != null)
                        sm_array[i] = null;
                }
                saveDevices(sm_array);
                loadDevices();

                using (StreamReader rd = new StreamReader(fname))
                {
                    int i = 0;
                    string passwd = rd.ReadLine();
                    string type = rd.ReadLine();
                    string default_image = rd.ReadLine();
                    while (!rd.EndOfStream)
                    {
                        string[] curr = rd.ReadLine().Split(';');
                        if (sm_array[i] == null)
                            sm_array[i] = new smartrack(port, "");
                        sm_array[i].Description = curr[0]+"/"+curr[1];
                        sm_array[i].device_number = "+39" + curr[3].Replace("/", "");
                        sm_array[i].Targa = curr[2].Replace(" ", "");
                        sm_array[i].devicePassword = passwd;
                        sm_array[i].DeviceType = type;
                        sm_array[i].Bersaglio = null;
                        sm_array[i].image = default_image;
                        i++;
                    }
                }
                saveDevices(sm_array);
                loadDevices();
            }
        }
Пример #12
0
 public MapUtils(smartrack device, Form1 mainFrm)
 {
     this.device  = device;
     this.mainFrm = mainFrm;
 }
Пример #13
0
        /*
         *  SELECT     ID, Vehicle, Position, DateTime
         *  FROM         Position
         *  WHERE     (CONVERT(DATETIME, DateTime, 103) > '01/01/2010') AND (CONVERT(DATETIME, DateTime, 103) < '01/02/2010') AND Vehicle = " + num.device_number + "'";
         */


        private void ElaboraStorico()
        {
            if (mainFrm.listBox1.SelectedItems.Count > 0)
            {
                if (mainFrm.listBox1.SelectedItems.Count == 1)
                {
                    mainFrm.updateConnectionString();
                    SqlConnection myConnection = new SqlConnection(mainFrm.connectionString);
                    myConnection.Open();
                    string     Upd = "UPDATE Position SET DateTime = REPLACE(DateTime,'.',':');";
                    SqlCommand cmd = new SqlCommand(Upd, myConnection);
                    cmd.ExecuteNonQuery();
                    myConnection.Close();

                    smartrack num = mainFrm.searchDevicebyDescription(mainFrm.listBox1.SelectedItems[0].ToString());

                    string base_sql = @"SELECT ID, Vehicle, Position, DateTime FROM Position ";

                    for (int mese = 1; mese < 13; mese++)
                    {
                        string data;
                        string data2;

                        if (mese.ToString().Length == 1)
                        {
                            data = "0" + mese + "/01/" + textBox1.Text;
                        }
                        else
                        {
                            data = mese + "/01/" + textBox1.Text;
                        }

                        if ((mese + 1) < 13)
                        {
                            if ((mese + 1).ToString().Length == 1)
                            {
                                data2 = "0" + (mese + 1) + "/01/" + textBox1.Text;
                            }
                            else
                            {
                                data2 = (mese + 1) + "/01/" + textBox1.Text;
                            }
                        }
                        else
                        {
                            data2 = "01/01/" + (int.Parse(textBox1.Text) + 1).ToString();
                        }

                        string SQL = "WHERE (CONVERT(DATETIME, DateTime, 103) > '" + data + "') AND (CONVERT(DATETIME, DateTime, 103) < '" + data2 + "') AND Vehicle = '" + num.device_number + "'";

                        SqlDataAdapter      da = new SqlDataAdapter(base_sql + SQL, myConnection);
                        System.Data.DataSet ds = new System.Data.DataSet();
                        da.Fill(ds, "pos");

                        double Km = 0;
                        if (ds.Tables["pos"].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables["pos"].Rows.Count; i++)
                            {
                                string position  = "";
                                string position2 = "";
                                try
                                {
                                    position  = ds.Tables["pos"].Rows[i]["Position"].ToString();
                                    position2 = ds.Tables["pos"].Rows[i + 1]["Position"].ToString();
                                }
                                catch { break; }

                                Km += calcolaKm(position, position2);
                            }
                            MesiKm[mese] = Km;
                        }
                        else
                        {
                            MesiKm[mese] = 0;
                        }
                    }
                }
            }
        }