/// <summary> /// Attempts to match a known kiosk based on the IP address of the client. /// </summary> private void GetKioskType(Kiosk kiosk, RockContext rockContext) { if (kiosk.KioskType != null) { DeviceService deviceService = new DeviceService(rockContext); //Load matching device and update or create information var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault(); //create new device to match our kiosk if (device == null) { device = new Device(); device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id; device.Name = kiosk.Name; deviceService.Add(device); } device.LoadAttributes(); device.IPAddress = kiosk.IPAddress; device.Locations.Clear(); foreach (var loc in kiosk.KioskType.Locations.ToList()) { device.Locations.Add(loc); } device.PrintFrom = kiosk.PrintFrom; device.PrintToOverride = kiosk.PrintToOverride; device.PrinterDeviceId = kiosk.PrinterDeviceId; rockContext.SaveChanges(); if (PageParameter("DateTime").AsDateTime().HasValue) { device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime")); } else { device.SetAttributeValue("core_device_DebugDateTime", ""); } device.SaveAttributeValues(rockContext); CurrentKioskId = device.Id; CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList(); CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId; CurrentCheckInState = null; CurrentWorkflow = null; Session["KioskTypeId"] = kiosk.KioskType.Id; Session["KioskMessage"] = kiosk.KioskType.Message; KioskDevice.Remove(device.Id); SaveState(); NavigateToNextPage(); } else { ltDNS.Text = kiosk.Name; pnlMain.Visible = true; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Device Device; var rockContext = new RockContext(); DeviceService DeviceService = new DeviceService(rockContext); AttributeService attributeService = new AttributeService(rockContext); int DeviceId = int.Parse(hfDeviceId.Value); if (DeviceId == 0) { Device = new Device(); DeviceService.Add(Device); } else { Device = DeviceService.Get(DeviceId); } Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue); if (Device.Location == null) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if (!Device.IsValid) { // Controls will render the error messages return; } rockContext.SaveChanges(); NavigateToParentPage(); }
public IHttpActionResult AddDevice(List <base_sbxx> entitys) { try { DeviceService ds = new DeviceService(); var ret = ds.Add(entitys); if (ret != null) { return(Json(new { code = 1, msg = "数据保成功" })); } else { return(Json(new { code = 0, msg = "数据保存失败" })); } } catch (Exception) { throw; } }
/// <summary> /// 提交添加 /// </summary> private bool SubmintAdd() { LHDevice its = new LHDevice { FCode = txtFCode.Text.Trim(), FName = txtFName.Text.Trim(), FSpec = txtFSpec.Text.Trim(), FSpell = ChineseSpell.MakeSpellCode(txtFName.Text.Trim(), "", SpellOptions.FirstLetterOnly).ToUpper(), FFlag = 1, //分类 FCateId = ProjectItem.FSParent, FSubCateId = ProjectItem.FId, //FCompanyId = CurrentUser.AccountComId, //FUnit = ddlUnit.SelectedValue.Trim(), FQty = Convert.ToDecimal(txtFQty.Text.Trim()), FMemo = txtFMemo.Text.Trim(),//备注 FCompanyId = CurrentUser.AccountComId, //FFlag = 0, FInstallDate = txtFInstallDate.SelectedDate, //ProjectItem.FFlag = 1, FParms = txtFParms.Text, FPurchaseDate = txtFPurchaseDate.SelectedDate, FStatus = Convert.ToInt32(ddlStatus.SelectedValue), FUser = txtFUser.Text, //单位 FUnit = ddlUnit.SelectedValue, FInspectionCycle = txtFInspectionCycle.Text, FInstallByName = ddlFInstallByName.SelectedValue //FPurchasePrice = Convert.ToDecimal(txtFPurchasePrice.Text.Trim()), //FSalesPrice = Convert.ToDecimal(txtFSalesPrice.Text.Trim()) }; return(DeviceService.Add(its)); }
private Kiosk ConfigureKiosk() { var rockContext = new RockContext(); var kioskTypeId = ddlCampus.SelectedValue.AsInteger(); var kioskType = KioskTypeCache.Get(kioskTypeId); var kioskName = "Mobile:" + kioskType.Name.RemoveAllNonAlphaNumericCharacters(); var mobileUserCategory = CategoryCache.Get(org.secc.FamilyCheckin.Utilities.Constants.KIOSK_CATEGORY_MOBILEUSER); var kioskService = new KioskService(rockContext); var kiosk = kioskService.Queryable("KioskType") .Where(k => k.Name == kioskName) .FirstOrDefault(); if (kiosk == null) { kiosk = new Kiosk { Name = kioskName, CategoryId = mobileUserCategory.Id, Description = "Automatically created mobile Kiosk" }; kioskService.Add(kiosk); } kiosk.KioskTypeId = kioskType.Id; rockContext.SaveChanges(); DeviceService deviceService = new DeviceService(rockContext); //Load matching device and update or create information var device = deviceService.Queryable("Location").Where(d => d.Name == kioskName).FirstOrDefault(); var dirty = false; //create new device to match our kiosk if (device == null) { device = new Device(); device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id; device.Name = kioskName; deviceService.Add(device); device.PrintFrom = PrintFrom.Client; device.PrintToOverride = PrintTo.Default; dirty = true; } var deviceLocationIds = device.Locations.Select(l => l.Id); var ktLocationIds = kioskType.Locations.Select(l => l.Id); var unmatchedDeviceLocations = deviceLocationIds.Except(ktLocationIds).Any(); var unmatchedKtLocations = ktLocationIds.Except(deviceLocationIds).Any(); if (unmatchedDeviceLocations || unmatchedKtLocations) { LocationService locationService = new LocationService(rockContext); device.Locations.Clear(); foreach (var loc in kioskType.Locations.ToList()) { var location = locationService.Get(loc.Id); device.Locations.Add(location); } dirty = true; } if (this.IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE)) { device.LoadAttributes(); if (PageParameter("datetime").IsNotNullOrWhiteSpace()) { device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime")); } else { device.SetAttributeValue("core_device_DebugDateTime", ""); } } if (dirty) { rockContext.SaveChanges(); device.SaveAttributeValues(rockContext); KioskDevice.Remove(device.Id); } LocalDeviceConfig.CurrentKioskId = device.Id; LocalDeviceConfig.CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList(); LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId; CurrentCheckInState = null; CurrentWorkflow = null; var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"]; if (kioskTypeCookie == null) { kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId"); } kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1); kioskTypeCookie.Value = kiosk.KioskType.Id.ToString(); this.Page.Response.Cookies.Set(kioskTypeCookie); Session["KioskTypeId"] = kioskType.Id; SaveState(); return(kiosk); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Page.Validate(); Device device = null; nbGeoFence.Visible = false; var rockContext = new RockContext(); var deviceService = new DeviceService(rockContext); var attributeService = new AttributeService(rockContext); var locationService = new LocationService(rockContext); int deviceId = hfDeviceId.Value.AsInteger(); if (deviceId != 0) { device = deviceService.Get(deviceId); } if (device == null) { // Check for existing var existingDevice = deviceService.Queryable() .Where(d => d.Name == tbName.Text) .FirstOrDefault(); if (existingDevice != null) { nbDuplicateDevice.Text = string.Format("A device already exists with the name '{0}'. Please use a different device name.", existingDevice.Name); nbDuplicateDevice.Visible = true; } else { device = new Device(); deviceService.Add(device); } } if (device != null) { device.Name = tbName.Text; device.Description = tbDescription.Text; device.IPAddress = tbIpAddress.Text; device.DeviceTypeValueId = dvpDeviceType.SelectedValueAsInt().Value; device.PrintToOverride = ( PrintTo )System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue); device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); device.PrintFrom = ( PrintFrom )System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue); device.IsActive = cbIsActive.Checked; device.HasCamera = cbHasCamera.Checked; device.CameraBarcodeConfigurationType = ddlCameraBarcodeConfigurationType.SelectedValue.ConvertToEnumOrNull <CameraBarcodeConfiguration>(); if (device.Location == null) { device.Location = new Location(); } // Custom validation checking string errorMessage = string.Empty; if (!geopFence.IsGeoFenceValid(out errorMessage)) { geopFence.RequiredErrorMessage = "error"; nbGeoFence.Visible = true; nbGeoFence.Text = errorMessage; return; } device.Location.GeoPoint = geopPoint.SelectedValue; device.Location.GeoFence = geopFence.SelectedValue; device.LoadAttributes(rockContext); avcAttributes.GetEditValues(device); if (!device.IsValid || !Page.IsValid) { // Controls will render the error messages return; } // Remove any deleted locations foreach (var location in device.Locations .Where(l => !Locations.Keys.Contains(l.Id)) .ToList()) { device.Locations.Remove(location); } // Add any new locations var existingLocationIDs = device.Locations.Select(l => l.Id).ToList(); foreach (var location in locationService.Queryable() .Where(l => Locations.Keys.Contains(l.Id) && !existingLocationIDs.Contains(l.Id))) { device.Locations.Add(location); } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); device.SaveAttributeValues(rockContext); }); Rock.CheckIn.KioskDevice.Remove(device.Id); NavigateToParentPage(); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Device Device = null; var rockContext = new RockContext(); var deviceService = new DeviceService(rockContext); var attributeService = new AttributeService(rockContext); var locationService = new LocationService(rockContext); int DeviceId = int.Parse(hfDeviceId.Value); if (DeviceId != 0) { Device = deviceService.Get(DeviceId); } if (Device == null) { // Check for existing var existingDevice = deviceService.Queryable() .Where(d => d.Name == tbName.Text) .FirstOrDefault(); if (existingDevice != null) { nbDuplicateDevice.Text = string.Format("A device already exists with the name '{0}'. Please use a different device name.", existingDevice.Name); nbDuplicateDevice.Visible = true; } else { Device = new Device(); deviceService.Add(Device); } } if (Device != null) { Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue); if (Device.Location == null) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if (!Device.IsValid || !Page.IsValid) { // Controls will render the error messages return; } // Remove any deleted locations foreach (var location in Device.Locations .Where(l => !Locations.Keys.Contains(l.Id)) .ToList()) { Device.Locations.Remove(location); } // Add any new locations var existingLocationIDs = Device.Locations.Select(l => l.Id).ToList(); foreach (var location in locationService.Queryable() .Where(l => Locations.Keys.Contains(l.Id) && !existingLocationIDs.Contains(l.Id))) { Device.Locations.Add(location); } rockContext.SaveChanges(); Rock.CheckIn.KioskDevice.Flush(Device.Id); NavigateToParentPage(); } }
private void ActivateKiosk(Kiosk kiosk, bool logout) { RockContext rockContext = new RockContext(); DeviceService deviceService = new DeviceService(rockContext); KioskService kioskService = new KioskService(rockContext); //The kiosk can come in a variety of states. //Get a fresh version with our context to avoid context errors. kiosk = kioskService.Get(kiosk.Id); //Load matching device and update or create information var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault(); //create new device to match our kiosk if (device == null) { device = new Device(); device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id; device.Name = kiosk.Name; deviceService.Add(device); } device.LoadAttributes(); device.IPAddress = kiosk.IPAddress; device.Locations.Clear(); foreach (var loc in kiosk.KioskType.Locations.ToList()) { device.Locations.Add(loc); } device.PrintFrom = kiosk.PrintFrom; device.PrintToOverride = kiosk.PrintToOverride; device.PrinterDeviceId = kiosk.PrinterDeviceId; rockContext.SaveChanges(); if (PageParameter("DateTime").AsDateTime().HasValue) { device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime")); } else { device.SetAttributeValue("core_device_DebugDateTime", ""); } device.SaveAttributeValues(rockContext); LocalDeviceConfig.CurrentKioskId = device.Id; LocalDeviceConfig.CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList(); LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId; CurrentCheckInState = null; CurrentWorkflow = null; var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"]; if (kioskTypeCookie == null) { kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId"); } kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1); kioskTypeCookie.Value = kiosk.KioskType.Id.ToString(); this.Page.Response.Cookies.Set(kioskTypeCookie); Session["KioskTypeId"] = kiosk.KioskType.Id; Session["KioskMessage"] = kiosk.KioskType.Message; //Clean things up so we have the freshest possible version. KioskTypeCache.Remove(kiosk.KioskTypeId ?? 0); KioskDevice.Remove(device.Id); Dictionary <string, string> pageParameters = new Dictionary <string, string>(); if (kiosk.KioskType.Theme.IsNotNullOrWhiteSpace() && !GetAttributeValue("Manual").AsBoolean()) { LocalDeviceConfig.CurrentTheme = kiosk.KioskType.Theme; pageParameters.Add("theme", LocalDeviceConfig.CurrentTheme); } if (logout) { pageParameters.Add("logout", "true"); } SaveState(); NavigateToNextPage(pageParameters); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Device Device; var rockContext = new RockContext(); var deviceService = new DeviceService(rockContext); var attributeService = new AttributeService(rockContext); var locationService = new LocationService(rockContext); int DeviceId = int.Parse(hfDeviceId.Value); if (DeviceId == 0) { Device = new Device(); deviceService.Add(Device); } else { Device = deviceService.Get(DeviceId); } Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue); if (Device.Location == null) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if (!Device.IsValid || !Page.IsValid) { // Controls will render the error messages return; } // Remove any deleted locations foreach (var location in Device.Locations .Where(l => !Locations.Keys.Contains(l.Id)) .ToList()) { Device.Locations.Remove(location); } // Add any new locations var existingLocationIDs = Device.Locations.Select(l => l.Id).ToList(); foreach (var location in locationService.Queryable() .Where(l => Locations.Keys.Contains(l.Id) && !existingLocationIDs.Contains(l.Id))) { Device.Locations.Add(location); } rockContext.SaveChanges(); NavigateToParentPage(); }