コード例 #1
0
ファイル: Admin.aspx.cs プロジェクト: szab100/bracelet
    protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        int         index    = Convert.ToInt32(e.CommandArgument);
        GridViewRow gvRow    = gvUsers.Rows[index];
        string      userName = gvRow.Cells[0].Text;

        using (braceletEntities context = new braceletEntities())
        {
            switch (e.CommandName)
            {
            case "ForceMeasure":
                // TODO: insert actionQueue
                ActionQueue action = new ActionQueue();
                action.UserID      = context.aspnet_Users.Where(o => o.UserName == userName).FirstOrDefault().UserId;
                action.Description = "Manuális mérés indítás";
                action.Status      = (short)CommonNames.ActionStatus.New;
                action.Action      = (short)CommonNames.ActionType.ForceMeasure;
                action.Created     = DateTime.Now;
                context.ActionQueues.AddObject(action);
                context.SaveChanges();

                // Inform user
                LabelPopupMessage.Text      = "Az akció ütemezése sikeresen megtörtént!";
                LabelPopupMessage.ForeColor = Color.Green;
                ModalPopupExtender1.Enabled = true;
                ModalPopupExtender1.Show();
                break;

            default:
                break;
            }
        }
    }
コード例 #2
0
    public bool StoreMeasure(MobileMeasure p_measure, Credentials credentials)
    {
        // If credentials not valid --> return false
        if (!Membership.ValidateUser(credentials.UserName, credentials.Password))
        {
            return(false);
        }

        // If we are here, credentials are fine, let's store this measure
        try
        {
            Measure measure = new Measure();

            measure.Acceleration = p_measure.Acceleration;
            measure.BloodOxygen  = p_measure.BloodOxygen;
            measure.Pulse        = p_measure.Pulse;
            measure.Temperature  = p_measure.Temperature;
            measure.SensorID     = p_measure.SensorID;

            // Try to get measured date
            if (p_measure.Measured != null)
            {
                measure.Measured = p_measure.Measured;
            }
            else
            {
                measure.Measured = DateTime.Now;
            }

            // Set missing values
            measure.UserID   = (Guid)Membership.GetUser(credentials.UserName).ProviderUserKey;
            measure.Received = DateTime.Now;

            // Store
            using (braceletEntities context = new braceletEntities())
            {
                context.Measures.AddObject(measure);
                context.SaveChanges();
            }

            return(true);
        }
        catch (Exception)
        {
            // If something went wrong..
            return(false);
        }
    }
コード例 #3
0
    public int IsActionQueued(Credentials credentials)
    {
        // If credentials not valid --> return false
        if (!Membership.ValidateUser(credentials.UserName, credentials.Password))
        {
            return(-1);
        }

        try
        {
            using (braceletEntities context = new braceletEntities())
            {
                // Get uncompleted actions
                ActionQueue q = context.ActionQueues.Where(o => o.aspnet_Users.UserName == credentials.UserName && (CommonNames.ActionStatus)o.Status == CommonNames.ActionStatus.New).FirstOrDefault();

                // There's a queue
                if (q != null)
                {
                    // Set completed
                    q.Completed = DateTime.Now;
                    q.Status    = (short)CommonNames.ActionStatus.Completed;

                    // Save changes to DB
                    context.SaveChanges();

                    // Return proper value (by action)
                    switch ((CommonNames.ActionType)q.Action)
                    {
                    case CommonNames.ActionType.ForceMeasure:
                        return((int)CommonNames.ActionType.ForceMeasure);

                    default:
                        return(0);
                    }
                }
            }

            // Nothing to do
            return(-1);
        }
        catch (Exception e)
        {
            return(-1);
        }
    }
コード例 #4
0
    public bool UploadRecording(UploadFile file, int eventID, Credentials credentials)
    {
        // If credentials not valid --> return false
        if (!Membership.ValidateUser(credentials.UserName, credentials.Password))
        {
            return(false);
        }

        try
        {
            // Save file
            String     fileName   = credentials.UserName + "-" + file.FileName;
            FileStream FileStream = new FileStream("C:\\BraceletRecordings\\" + fileName, FileMode.Create);
            byte[]     fileBytes  = Convert.FromBase64String(file.File);
            FileStream.Write(fileBytes, 0, fileBytes.Length);
            FileStream.Close();
            FileStream.Dispose();

            // Insert Recording
            using (braceletEntities context = new braceletEntities())
            {
                Recording r = new Recording();

                Event e = context.Events.Where(o => o.ID == eventID).FirstOrDefault();
                r.FileName = fileName;
                if (e != null)
                {
                    r.Event = e;
                }
                r.Uploaded = DateTime.Now;
                r.UserID   = (Guid)Membership.GetUser(credentials.UserName).ProviderUserKey;

                context.Recordings.AddObject(r);
                context.SaveChanges();

                // Everything is OK
                return(true);
            }
        }
        catch (Exception)
        {
            // Something went wrong..
            return(false);
        }
    }
コード例 #5
0
    public int RaiseEvent(MobileEvent mobEvent, Credentials credentials)
    {
        // If credentials not valid --> return false
        if (!Membership.ValidateUser(credentials.UserName, credentials.Password))
        {
            return(-1);
        }

        try
        {
            // Create new Event
            Event newEvent = new Event();
            newEvent.EventCode         = (short)mobEvent.EventCode;
            newEvent.Description       = mobEvent.Description;
            newEvent.Level             = (short)mobEvent.Level;
            newEvent.PositionLatitude  = mobEvent.Latitude;
            newEvent.PositionLongitude = mobEvent.Longitude;

            // Set missing values
            newEvent.UserID = (Guid)Membership.GetUser(credentials.UserName).ProviderUserKey;
            newEvent.Raised = DateTime.Now;

            // If we are here, credentials are fine, let's store this event
            using (braceletEntities context = new braceletEntities())
            {
                // Store
                newEvent.Status = (int)CommonNames.EventStatus.New;
                context.Events.AddObject(newEvent);

                context.SaveChanges();

                // Return OK
                return(newEvent.ID);
            }
        }
        catch (Exception)
        {
            // If something went wrong
            return(-1);
        }
    }
コード例 #6
0
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        // Save values
        if (Page.IsValid)
        {
            using (braceletEntities context = new braceletEntities())
            {
                bool newTolerance = false;
                bool noAction     = false;

                Tolerance tol = context.Tolerances.Where(o => o.aspnet_Users.UserName == UserName).FirstOrDefault();
                if (tol == null)
                {
                    newTolerance = true;
                    tol          = new Tolerance();
                    tol.UserID   = context.aspnet_Users.Where(o => o.UserName == UserName).FirstOrDefault().UserId;
                }

                string selectedType = DropDownToleranceType.SelectedValue;
                double low          = 0;
                double high         = 0;

                // Try to parse values
                if (TextBoxLow.Visible)
                {
                    double.TryParse(TextBoxLow.Text, out low);
                }
                double.TryParse(TextBoxHigh.Text, out high);

                switch (selectedType)
                {
                case "acc":
                    tol.AccelerationTolerance = high;
                    break;

                case "blox":
                    tol.BloodOxygenToleranceLow  = low;
                    tol.BloodOxygenToleranceHigh = high;
                    break;

                case "temp":
                    tol.TempToleranceLow  = low;
                    tol.TempToleranceHigh = high;
                    break;

                case "pulse":
                    tol.PulseToleranceLow  = (int)low;
                    tol.PulseToleranceHigh = (int)high;
                    break;

                default:
                    noAction = true;
                    break;
                } // End of switch(..)

                // Save user's tolerance
                if (newTolerance)
                {
                    context.Tolerances.AddObject(tol);
                }
                context.SaveChanges();

                if (!noAction)
                {
                    MessageLabel.Text      = "A új toleranciamaszk értékek sikeresen elmentve.";
                    MessageLabel.ForeColor = Color.Green;
                }
            } // End of using(..)
        }
    }
コード例 #7
0
    protected void GridViewEvents_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        //// Only handle our custom commands here!
        if (e.CommandName.Equals("Handle") || e.CommandName.Equals("Position") || e.CommandName.Equals("DownloadRecording"))
        {
            int         index   = Convert.ToInt32(e.CommandArgument);
            GridViewRow gvRow   = ((GridView)sender).Rows[index];
            Int32       eventID = (Int32)GridViewEvents.DataKeys[index].Value;

            using (braceletEntities context = new braceletEntities())
            {
                switch (e.CommandName)
                {
                case "Handle":
                    Event ev = context.Events.Where(o => o.ID == eventID).First();
                    ev.Status = (byte)CommonNames.EventStatus.Handled;
                    ev.Note   = ((TextBox)gvRow.FindControl("TextBoxHandle")).Text;
                    context.SaveChanges();
                    GridViewEvents.DataBind();
                    GridViewPanel.Update();
                    break;

                case "Position":
                    Event evSelected = context.Events.Where(o => o.ID == eventID).First();
                    GMapHolder.Visible = true;

                    // Set selected row
                    GridView gv = (GridView)sender;
                    gv.SelectedIndex = index;

                    // Add GUI controls
                    GMap.addGMapUI(new GMapUI());

                    // Set center point
                    if (evSelected.PositionLatitude != null && evSelected.PositionLongitude != null)
                    {
                        GMap.setCenter(new GLatLng(evSelected.PositionLatitude.Value, evSelected.PositionLongitude.Value));
                    }

                    // Set zoom level
                    GMap.GZoom = 15;

                    // Add center marker
                    GMap.resetMarkers();
                    if (evSelected.PositionLatitude != null && evSelected.PositionLongitude != null)
                    {
                        GMap.addGMarker(new GMarker(new GLatLng(evSelected.PositionLatitude.Value, evSelected.PositionLongitude.Value)));
                    }
                    break;

                case "DownloadRecording":
                    if (HttpContext.Current.User.IsInRole("Administrator"))
                    {
                        Recording rec = context.Recordings.Where(o => o.EventID == eventID).FirstOrDefault();

                        if (rec != null)
                        {
                            FileStream fStream = null;
                            try
                            {
                                String fileName = "C:\\BraceletRecordings\\" + rec.FileName;

                                HttpResponse r = HttpContext.Current.Response;
                                Response.ContentType = "audio/mpeg";
                                Response.AppendHeader("Content-Disposition", "attachment; filename=" + rec.FileName);
                                fStream = new FileStream(fileName, FileMode.Open);
                                fStream.CopyTo(Response.OutputStream);
                                Response.End();
                            }
                            catch (IOException ex)
                            {
                                throw new IOException("Cannot find the selected recording.", ex);
                            }
                            finally
                            {
                                // Always close the fileStream
                                if (fStream != null)
                                {
                                    fStream.Close();
                                }
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        } // End of If(e.commandName.Equals("..") || ...)
    }