예제 #1
0
        public MainForm(bool account)
        {
            InitializeComponent();
            this.timer = new System.Windows.Forms.Timer();
            this.timer.Interval = 20; 
            this.timer.Tick += OnTimerFired;
            this.timer.Start();
            trafficMonitor = TrafficMonitor.Instance;
            this.AutoScroll = true;
            panel3.Size = new Size(840, 630);
            panel3.AutoSize = false;
            Visible(true);
            panel3.Paint += (s, e) => PaintPanel(e);
            InvalidateEvent.InvalidatePanel += () => panel3.Invalidate();
            pointsDictionary = FillPointsDictionary();
            idDictionary = FillIdDIctionary();
            this.btn_Pause.Enabled = false;
            this.btn_Pause.BackColor = Color.Gray;
            this.EnableToolTip();
            btn_StartStop.Image = Properties.Resources.start;
            btn_Pause.Image = Properties.Resources.pause;
            openConnection = new Account();
            trafficMonitor.User = new Account("", "");
            InitializeMenuBar();
            this.richTextBox1.Text += "Here we will record all your steps ☺!\n";

        }
예제 #2
0
 public ModifyIntersectionForm(BaseIntersection intersection)
 {
     InitializeComponent();
     trafficMonitor = TrafficMonitor.Instance;
     this.numLeftLane.Enabled = false;
     this.numRightLane.Enabled = false;
     this.numLowerLane.Enabled = false;
     this.numUpperLane.Enabled = false;
     GetIntersection(intersection);
     GetPedestrians();
     tbIntervalPedestrians.Text = 1.ToString();
     this.pedestrianTimer = new Timer();
     enableToolTip();
     this.richTextBox1.Text += "Here we will record all your steps ☺!\n";
     this.GetTrafficLightPicture();
     this.CheckForSensors();
    
 }
예제 #3
0
 /// <summary>
 /// Saves the changes from a <see cref="TrafficMonitor"/> to a binary file.
 /// </summary>
 /// <param name="trafficMonitor">The object that needs to be serialized.</param>
 /// <param name="path">The path where the file will be saved.</param>
 public static void SaveToFile(TrafficMonitor trafficMonitor, string path)
 {
     using (var fileStream = new FileStream(path, FileMode.OpenOrCreate))
     {
         var binFormatter = new BinaryFormatter();
         binFormatter.Serialize(fileStream, trafficMonitor);
     }
 }
예제 #4
0
파일: Account.cs 프로젝트: rosendanew/ProCP
        /// <summary>
        /// Saves the file to the local disk and the upload it to the database.
        /// </summary>
        /// <param name="filename">The name of the file</param>
        /// <param name="tr">The traffic object to be serialized</param>
        /// <param name="user">The username</param>
        /// <param name="path">The path on the local disk to create the file</param>
        public void saveFile(string filename, TrafficMonitor tr, string user, string path)
        {
         
                TrafficMonitor.SaveToFile(tr, path);
                try
                {
                    MySqlCommand cmd = new MySqlCommand("INSERT INTO user_files(FileName, Username, File) VALUES ('" + filename + "','" + user + "',@File) ", connection);

                    System.IO.FileStream fs =
                new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                    Byte[] b = new Byte[fs.Length];
                    fs.Read(b, 0, b.Length);
                    fs.Close();
                    MySqlParameter P = new MySqlParameter("@File", MySqlDbType.VarBinary, b.Length,
                     ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, b);
                    cmd.Parameters.Add(P);
                    connection.Open();
                    if (cmd.ExecuteNonQuery() == 1)
                        MessageBox.Show("Your file has been stored successfully");
                    connection.Close();
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            
        }
예제 #5
0
 private void LoadFromDb(string sender)
 {
     SaveFileDialog myDialog = new SaveFileDialog();
     myDialog.Title = "Save simulation";
     myDialog.DefaultExt = ".XML";
     if (myDialog.ShowDialog() == DialogResult.OK & myDialog.FileName != null)
     {
         trafficMonitor = openConnection.LoadFile(trafficMonitor.User.Name, sender, myDialog.FileName);
     }
     this.panel3.Invalidate();
 }
예제 #6
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Do you want to save your changes?", "Save?", MessageBoxButtons.YesNo);
            if (dialog == DialogResult.Yes)
            {
                saveToolStripMenuItem.PerformClick();
                OpenFileDialog load = new OpenFileDialog();
                if (load.ShowDialog() == DialogResult.OK)
                {
                    load.Title = "Load from file";
                    filePath = load.FileName;
                    trafficMonitor = TrafficMonitor.Load(load.FileName);
                    this.richTextBox1.Text += DateTime.Now + " " + load.FileName + " has been loaded\n";

                }
            }
            else if (dialog == DialogResult.No)
            {
                OpenFileDialog load = new OpenFileDialog();
                if (load.ShowDialog() == DialogResult.OK)
                {
                    filePath = load.FileName;
                    load.Title = "Load from file";
                    trafficMonitor = TrafficMonitor.Load(load.FileName);
                    panel3.Invalidate();
                }
            }
        }