Пример #1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            using (var db = new AzureNOLBContext())
            {
                var location = db.Locations
                               .Where(x => x.StreetAddress == txtStreetAddress.Text.Trim() &&
                                      x.City == txtCity.Text.Trim() &&
                                      x.State == txtState.Text.Trim() &&
                                      x.Floor == txtFloor.Text.Trim() &&
                                      x.RoomNumber == txtRoom.Text.Trim())
                               .SingleOrDefault();

                if (location == null)
                {
                    location = new Location
                    {
                        City          = txtCity.Text.Trim(),
                        Floor         = txtFloor.Text.Trim(),
                        RoomNumber    = txtRoom.Text.Trim(),
                        StreetAddress = txtStreetAddress.Text.Trim(),
                        State         = txtState.Text.Trim()
                    };
                }

                var newRequest = new Request
                {
                    TypeOfEmergency         = hdnTypeOfEmergency.Value,
                    NumberOfPeople          = int.TryParse(hdnNumOfPeople.Value, out int numOfPeople) ? numOfPeople : 0,
                    NumberOfImmobilePeople  = int.TryParse(hdnNumOfImmobilePeople.Value, out int numOfImmobile) ? numOfImmobile : 0,
                    InjuriesOrOtherInfo     = txtInjuriesOrSpecialInfo.Text,
                    AccessibleOutsideWindow = cbOutsideWindow.Checked,
                    FirstName   = txtFirstName.Text,
                    LastName    = txtLastName.Text,
                    PhoneNumber = txtPhone.Text,
                    Latitude    = decimal.TryParse(txtLatitude.Text, out decimal latitude) ? latitude : 0.0M,
                    Longitude   = decimal.TryParse(txtLongitude.Text, out decimal longitude) ? longitude : 0.0M,
                    Location    = location
                };

                var datetime         = DateTimeOffset.Parse(hdnDateTime.Value);
                var adjustedDatetime = datetime.AddHours(int.Parse(hdnTimeOffset.Value));
                newRequest.TimeStamp = adjustedDatetime;

                db.Requests.Add(newRequest);
                db.SaveChanges();

                lblMessage.Text = "Request Successfully Submitted.";

                hdnDateTime.Value        = DateTimeOffset.Now.ToString();
                hdnTypeOfEmergency.Value = "Unknown";
            }
        }
        protected void RequestDataList_OnItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "ClearRequest")
            {
                var id = int.Parse(e.CommandArgument.ToString());

                using (var db = new AzureNOLBContext())
                {
                    var item = db.Requests.SingleOrDefault(x => x.RequestID == id);

                    if (item == null)
                    {
                        return;
                    }
                    else
                    {
                        item.Cleared = true;
                        db.SaveChanges();
                    }
                }
            }
        }
Пример #3
0
        protected void btnSubmit_ClickQR(object sender, EventArgs e)
        {
            //Creates New Instance of a QR
            using (var qrCode = new QRCodeGenerator())
            {
                var qrCodeString = GenerateQrCodeString();
                //Append URL to qrCode
                var dataURL = qrCode.CreateQrCode(qrCodeString, QRCodeGenerator.ECCLevel.Q);
                using (var code = new QRCode(dataURL))
                {
                    //Images qrCode and determines dimmensions
                    var imgBarCode = new System.Web.UI.WebControls.Image
                    {
                        Height = 400,
                        Width  = 400
                    };
                    using (Bitmap bitMap = code.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            bitMap.Save(ms, ImageFormat.Png);
                            var byteImage = ms.ToArray();
                            imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                        }
                        PlaceHolder1.Controls.Add(imgBarCode);
                        SetAddressLabel();
                    }
                    //Images qrCode and determines dimmensions
                    var imgBarCodePrint = new System.Web.UI.WebControls.Image
                    {
                        Height = 800,
                        Width  = 800
                    };
                    using (Bitmap bitMap = code.GetGraphic(20))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            bitMap.Save(ms, ImageFormat.Png);
                            var byteImage = ms.ToArray();
                            imgBarCodePrint.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                        }
                        PlaceHolder2.Controls.Add(imgBarCodePrint);
                        SetAddressLabel();
                    }
                }
            }

            using (var db = new AzureNOLBContext())
            {
                var location = db.Locations
                               .Where(x => x.StreetAddress == txtStreetAddress.Text.Trim() &&
                                      x.City == txtCity.Text.Trim() &&
                                      x.State == txtState.Text.Trim() &&
                                      x.Floor == txtFloor.Text.Trim() &&
                                      x.RoomNumber == txtRoom.Text.Trim())
                               .SingleOrDefault();

                if (location == null)
                {
                    location = new Location
                    {
                        City          = txtCity.Text.Trim(),
                        Floor         = txtFloor.Text.Trim(),
                        RoomNumber    = txtRoom.Text.Trim(),
                        StreetAddress = txtStreetAddress.Text.Trim(),
                        State         = txtState.Text.Trim()
                    };

                    db.Locations.Add(location);
                    db.SaveChanges();
                }
            }
        }