protected void btnConfirm_Click(object sender, EventArgs e) { if (tbReason.Text == "") { lblMsg.Text = "Please enter revoke reason!"; } else { int ID = System.Convert.ToInt32(lblDeviceID.Text); using (var db = new FacilityReservationKioskEntities()) { Device device = db.Devices.Find(ID); //Modify fields device.Status = "REV"; device.RejectedOrRevokedDateTime = DateTime.Now; device.RejectedOrRevokedReason = tbReason.Text; db.SaveChanges(); } lblMsg.Text = "Device revoked successfully"; } }
protected void btnSearch_Click(object sender, EventArgs e) { if (txtSearch.Text == "") { using (var db = new FacilityReservationKioskEntities()) { //Basic select query from a single table var Search = from b in db.Devices select new { b.DeviceID, b.DeviceGeneratedUniqueID, b.Status, b.Description, b.ApprovedDateTime, b.RejectedOrRevokedDateTime, b.RejectedOrRevokedReason }; //Loop through to print out GridViewSearch.DataSource = Search.ToList(); GridViewSearch.DataBind(); } } else { { int search = System.Convert.ToInt32(txtSearch.Text); using (var db = new FacilityReservationKioskEntities()) { //Basic select query from a single table var Search = from b in db.Devices where b.DeviceID == search orderby b.DeviceID select new { b.DeviceID, b.DeviceGeneratedUniqueID, b.Status, b.ApprovedDateTime, b.RejectedOrRevokedDateTime, b.RejectedOrRevokedReason, b.Description }; //Loop through to print out GridViewSearch.DataSource = Search.ToList(); GridViewSearch.DataBind(); } } } }
protected void btnConfirm_Click(object sender, EventArgs e) { if (tbDescription.Text == "") { lblUpdate.Text = "Please enter description!"; } else { int ID = System.Convert.ToInt32(lblDeviceID.Text); using (var db = new FacilityReservationKioskEntities()) { //Load up and update try { Device device = db.Devices.Find(ID); //Modify fields device.Description = tbDescription.Text; device.DepartmentID = ddlDepartment.SelectedValue.ToString(); device.DefaultDepartmentFilterID = System.Convert.ToInt32(tbDefaultFilter.Text); device.Status = "APP"; device.ApprovedDateTime = DateTime.Now; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. //throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } lblUpdate.Text = "Update Successfully"; } } }
protected void Page_Load(object sender, EventArgs e) { lblDeviceID.Text = Request.QueryString["searchID"]; int ID = System.Convert.ToInt32(lblDeviceID.Text); using (var db = new FacilityReservationKioskEntities()) { //Basic select query from a single table var device = db.Devices.Find(ID); //Loop through to print out tbDescription.Text = device.Description; ddlDepartment.Text = device.DepartmentID; tbFilter.Text = device.DefaultDepartmentFilterID.ToString(); } }
protected void btnUpdate_Click(object sender, EventArgs e) { int ID = System.Convert.ToInt32(lblDeviceID.Text); using (var db = new FacilityReservationKioskEntities()) { Device device = db.Devices.Find(ID); //Modify fields device.Description = tbDescription.Text; device.DepartmentID = ddlDepartment.SelectedValue.ToString(); device.DefaultDepartmentFilterID = System.Convert.ToInt32(tbFilter.Text); db.SaveChanges(); } lbUpdate.Text = "Records update successfully"; }
protected void Page_Load(object sender, EventArgs e) { string Message; string id = ""; string pk = ""; //To get the string and register device string UniqueID = Request.QueryString["UniqueID"]; string PublicKey = Request.QueryString["PublicKey"]; if (UniqueID != "" && UniqueID!= null && PublicKey != "" && PublicKey!= null) { using (var db = new FacilityReservationKioskEntities()) { //Load up and update var registration = from b in db.Devices where b.DeviceGeneratedUniqueID == UniqueID && (b.Status == "APP" || b.Status == "NEW") && b.PublicKey == PublicKey select new { id = b.DeviceGeneratedUniqueID.ToString(), pk = b.PublicKey.ToString() }; if (registration.Count() > 0) { Response.Write("{"); Response.Write(" Result: \"ERROR\","); Response.Write(" Message: \"This iPad have already been registered in the system database, please wait for approval.\""); Response.Write("}"); } else { var register = new Device { Status = "NEW", DeviceGeneratedUniqueID = UniqueID, PublicKey = PublicKey }; db.Devices.Add(register); try { db.SaveChanges(); Response.Write("{"); Response.Write(" Result: \"OK\","); Response.Write(" Message: \"This iPad have been registered in the system database, awaiting for approval\""); Response.Write("}"); // } catch (Exception ex) { Message = ex.Message; //returns ok/error message to caller Response.Write("{"); Response.Write(" Result: \"ERROR\","); Response.Write(" Message: \"" + Message + "\""); Response.Write("}"); //Response.End(); } } Response.End(); } } }