示例#1
0
 public void OnSessionChosen(SessionListObject slo)
 {
     //raises the event
     if (SessionChosen != null)
     {
         SessionChosen(this, new SessionEventArgs() { sessionListObject=slo});
     }
 }
        public List<SessionListObject> getAllSessionListsForUser(int userId)
        {
            List<SessionListObject> myList = new List<SessionListObject>();
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["museum.Properties.Settings.museumConnectionString"].ConnectionString))
                {
                    connection.Open();
                    string query = "SELECT * FROM SessionList WHERE userId = " + userId;
                    SqlCommand command = new SqlCommand(query, connection);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var sessionListObject = new SessionListObject();
                            sessionListObject.id = (int)reader["id"];
                            sessionListObject.userId = (int)reader["UserId"];
                            sessionListObject.sessionName = (string)reader["SessionName"];

                            byte[] tempArray = (byte[])reader["Session"];
                            //sessionListObject.sessionList = (List<SessionObject>)reader["Session"];
                            if (tempArray != null)
                            {
                                MemoryStream ms = new MemoryStream(tempArray);
                                BinaryFormatter binForm = new BinaryFormatter();
                                sessionListObject.sessionList = (List<SessionObject>)binForm.Deserialize(ms);
                            }
                            myList.Add(sessionListObject);
                        }
                    }
                }
            }
            catch (SqlException sql)
            {
                MessageBox.Show("The SessionList could not be entered " + sql);
            }
            return myList;
        }
示例#3
0
        private void stopVisitSessionRecordingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Globals.sessionStarted == true)
            {

                if (Globals.sessionObjectList.Count() == 0)
                {
                    MessageBox.Show("You did not visit any exhibit. Please try again.");
                }
                else
                {
                    //we borrow the input messagebox from visualbasic. Quick and dirty solution in cases like this, when we do not want to build a new class.
                    string input = Microsoft.VisualBasic.Interaction.InputBox("Visit Session Name", "Please write a name for your visit session.", "Name", 0);

                    //If the user clicks Cancel, a zero-length string is returned
                    if (input == "")
                    {
                        MessageBox.Show("The visit session was not recorded");
                        //reseting
                        Globals.sessionStarted = false;
                        Globals.sessionStarted = false;
                        recordbtn.Image = Properties.Resources.Record_Normal_icon;
                        recordLabel.Text = "Record";
                        recordLabel.ForeColor = Color.Black;
                        Globals.sessionObjectList.Clear();
                    }
                    else
                    {
                        /*sets the global static variable started equal to false, so as to stop recording and keeps the list in the database*/
                        Globals.sessionStarted = false;
                        SessionListObjectDAO sessionListObjectDAO = new SessionListObjectDAO();

                        SessionListObject slo = new SessionListObject();
                        slo.userId = Globals.currentUser.id;
                        slo.sessionList = Globals.sessionObjectList;
                        slo.sessionName = input;
                        sessionListObjectDAO.InsertSessionListObject(slo);
                        //reset the flag
                        Globals.sessionStarted = false;
                        //reset the toolstrip button
                        recordbtn.Image = Properties.Resources.Record_Normal_icon;
                        recordLabel.Text = "Record";
                        recordLabel.ForeColor = Color.Black;
                        //resset the sessionObjectList
                        Globals.sessionObjectList.Clear();
                    }
                }
            }
        }
        public void InsertSessionListObject(SessionListObject slo)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["museum.Properties.Settings.museumConnectionString"].ConnectionString))
                {
                    connection.Open();
                    /******************************************************************/
                    MemoryStream memStream = new MemoryStream();
                    //StreamWriter sw = new StreamWriter(memStream);
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(memStream,slo.sessionList);

                    //sw.Write(slo.sessionList);
                    /************************************************************************/
                    string query = "INSERT INTO SessionList (UserId,Session,SessionName) VALUES(@userId,@session,@sessionname)";
                    SqlCommand command = new SqlCommand(query,connection);
                    command.Parameters.AddWithValue("@userId", slo.userId);
                    command.Parameters.AddWithValue("@sessionname", slo.sessionName);

                    //command.Parameters.Add("@session", SqlDbType.VarBinary, Int32.MaxValue);

                    command.Parameters.AddWithValue("@session", memStream.GetBuffer());

                    command.ExecuteNonQuery();
                }
            }
            catch (SqlException sql)
            {
                MessageBox.Show("The SessionList could not be entered " + sql);
            }
        }