public void Login() { int emplId = -1; IoMap map = ViewManager.CurrentMap; if (int.TryParse(map.GetInput <string>("Employee.Id"), out emplId)) { Employee auth = new Employee(); auth.EmployeeId = int.Parse(map.GetInput <string>("Employee.Id")); Employee match = DataAccess.FromPrimaryKey <Employee>(emplId); if (match != null && PasswordSecurity.PasswordStorage.VerifyPassword(map.GetInput <string>("Employee.Password"), match.HashedPassword)) { Auth.User = match; LogicManager.TryPerformAction(match.Role.DefaultView); } else { map.Reset(); map.SetInput("Employee.Id", emplId); ViewManager.ShowFlash("Invalid credentials", FlashMessageType.Bad); ViewManager.Show("Login", map); } } else { map.Reset(); ViewManager.ShowFlash("Please enter your employee ID", FlashMessageType.Bad); ViewManager.Show("Login", map); } }
/// <summary> /// Fills this IOutput from a given IO map /// </summary> /// <param name="map">The map to fill from</param> public void Fill(IoMap map) { if (map.HasOutput(Name)) { Value = map.GetOutput <object>(Name); } }
protected override void LoadMyViewContext(IoMap map) { //Pulling from the session Employee instance = map.GetInput <Employee>("Employee.Info"); if (instance != null) { //Setting the inputs on load map.SetInput("Employee.FirstName", instance.FirstName); map.SetInput("Employee.LastName", instance.LastName); map.SetInput("Employee.Email", instance.Email); map.SetInput("Employee.Phone", instance.Phone); map.SetInput("Employee.SIN", instance.SIN); map.SetInput("Employee.Role", instance.Role); map.SetInput("Address.Street", instance.HomeAddress.StreetAddress); map.SetInput("Address.Country", instance.HomeAddress.Country); map.SetInput("Address.State", instance.HomeAddress.State); map.SetInput("Address.City", instance.HomeAddress.City); map.SetInput("Address.PostalCode", instance.HomeAddress.PostalCode); map.SetInput("Address.AptNum", instance.HomeAddress.ApartmentNumber); map.SetInput("Employee", instance); map.SetInput <Employee>("Employee.Info", null); } }
/// <summary> /// Handles checking to see if the employee data entry on the input map is valid /// </summary> /// <param name="employee">The employee instance to validate</param> /// <param name="reason">The reference to the reason for failure</param> /// <returns>True if validation was successful, false if otherwise</returns> public static bool Validate(string prefix, ref string reason) { bool result = true; if (string.IsNullOrEmpty(prefix)) { prefix = ""; } else { prefix += "."; } IoMap map = ViewManager.CurrentMap; string fName = map.GetInput <string>(prefix + "FirstName"); string lName = map.GetInput <string>(prefix + "LastName"); string sin = map.GetInput <string>(prefix + "SIN"); string phone = map.GetInput <string>(prefix + "Phone"); string email = map.GetInput <string>(prefix + "Email"); long tempVal = -1; if (string.IsNullOrWhiteSpace(fName) || fName.Length < 2) { result = false; reason += "First name must be at least 2 characters" + Environment.NewLine; } if (string.IsNullOrWhiteSpace(lName) || lName.Length < 2) { result = false; reason += "Last name must be at least 2 characters" + Environment.NewLine; } if (string.IsNullOrWhiteSpace(sin) || sin.Length != 9) { result = false; reason += "SIN must be exactly 9 characters" + Environment.NewLine; } else if (!long.TryParse(sin, out tempVal)) { result = false; reason += "SIN must be numeric" + Environment.NewLine; } if (string.IsNullOrWhiteSpace(phone) || phone.Replace(" ", "").Length < 10) { result = false; reason += "Phone # must be at least 10 characters" + Environment.NewLine; } else if (!long.TryParse(phone.Replace(" ", "").Replace("-", ""), out tempVal)) { result = false; reason += "Phone # must be numeric" + Environment.NewLine; } return(result); }
public void Update() { IoMap map = ViewManager.CurrentMap; string msg = ""; if (!Validate("Employee", ref msg) || Validations.ValidateAddressFromMap(map, "Address", ref msg) == null) { ViewManager.ShowFlash(string.Format("Error updating Employee:\n{0}", msg), FlashMessageType.Bad); ViewManager.Show("ViewEditEmployee", map); } else { Employee employee = map.GetInput <Employee>("Employee"); employee.FirstName = map.GetInput <string>("Employee.FirstName"); employee.LastName = map.GetInput <string>("Employee.LastName"); employee.SIN = map.GetInput <string>("Employee.SIN"); employee.Email = map.GetInput <string>("Employee.Email"); employee.Phone = long.Parse(map.GetInput <string>("Employee.Phone").Replace(" ", "").Replace("-", "")); employee.DateJoined = DateTime.Now; employee.HashedPassword = null; employee.HomeAddress.StreetAddress = map.GetInput <string>("Address.Street"); employee.HomeAddress.Country = map.GetInput <string>("Address.Country"); employee.HomeAddress.State = map.GetInput <string>("Address.State"); employee.HomeAddress.PostalCode = map.GetInput <string>("Address.PostalCode"); employee.HomeAddress.City = map.GetInput <string>("Address.City"); int aptNum = -1; if (int.TryParse(map.GetInput <string>("Address.AptNum"), out aptNum)) { employee.HomeAddress.ApartmentNumber = aptNum; } else { employee.HomeAddress.ApartmentNumber = null; } employee.HomeAddress = employee.HomeAddress; employee.Role = map.GetInput <EmployeeRole>("Employee.Role"); if (DataAccess.Update(employee, false, true) > 0) { employee = DataAccess.Match(employee)[0]; ViewManager.ShowFlash(string.Format("Employee has sucessfully been updated"), FlashMessageType.Good); Logger.Log(LogLevel.Info, "Updated employee with ID {0}", employee.EmployeeId); map.Reset(); ViewManager.Show("EmployeeSearch", map); } else { ViewManager.ShowFlash("Failed to update employee:\n" + DataAccess.Database.LastFailReason.Message, FlashMessageType.Bad); Logger.Log(LogLevel.Error, DataAccess.Database.LastFailReason.Message); ViewManager.Show("AddEmployee", map); } } }
public void Insert() { IoMap map = ViewManager.CurrentMap; string msg = ""; if (!Validate(ref msg)) { ViewManager.ShowFlash(string.Format("Error Adding Block:\n{0}", msg), FlashMessageType.Bad); ViewManager.Show("AddBlocks", map); } else { if (Session.Get <List <Product> >("AddingProducts") == null) { ViewManager.ShowFlash("Please select at least one product to order", FlashMessageType.Neutral); return; } else { Block block = new Block(); block.Title = map.GetInput <string>("Block.Title"); block.SeriesId = map.GetInput <BlockSeries>("Block.Series"); block.ShipByDate = map.GetInput <DateTime>("Block.ShipByDate"); block.Description = map.GetInput <string>("Block.Description"); if (DataAccess.Insert(block)) { map.Reset(); block = DataAccess.Match(block)[0]; List <Product> products = Session.Get <List <Product> >("AddingProducts"); for (int index = 0; index < products.Count; index++) { BlockItem item = new BlockItem(); item.BlockId = block; item.ProducId = products[index]; item.Quantity = 1; DataAccess.Insert(item); } Session.Set <List <Product> >("AddingProducts", null); ViewManager.ShowFlash(string.Format("Block added with ID: {0}", block.BlockId), FlashMessageType.Good); Logger.Log(LogLevel.Info, "Added block with ID {0}", block.BlockId); ViewManager.Show("AddBlocks", map); } else { ViewManager.ShowFlash("Failed to add block: \n" + DataAccess.Database.LastFailReason.Message, FlashMessageType.Bad); Logger.Log(LogLevel.Error, DataAccess.Database.LastFailReason.Message); ViewManager.Show("AddBlocks", map); } } } }
public void Insert() { IoMap map = ViewManager.CurrentMap; string msg = ""; if (!Validate("", ref msg) || Validations.ValidateAddressFromMap(map, "Address", ref msg) == null) { ViewManager.ShowFlash(string.Format("Error Adding Employee:\n{0}", msg), FlashMessageType.Bad); ViewManager.Show("AddEmployee", map); } else { Employee employee = new Employee(); employee.FirstName = map.GetInput <string>("FirstName"); employee.LastName = map.GetInput <string>("LastName"); employee.SIN = map.GetInput <string>("SIN"); employee.Email = map.GetInput <string>("Email"); employee.Phone = long.Parse(map.GetInput <string>("Phone").Replace(" ", "").Replace("-", "")); employee.DateJoined = DateTime.Now; employee.HashedPassword = PasswordSecurity.PasswordStorage.CreateHash(employee.SIN); Address address = new Address(); address.StreetAddress = map.GetInput <string>("Address.StreetAddress"); address.Country = map.GetInput <string>("Address.Country"); address.State = map.GetInput <string>("Address.State"); address.PostalCode = map.GetInput <string>("Address.PostalCode"); address.City = map.GetInput <string>("Address.City"); int aptNum = -1; if (int.TryParse(map.GetInput <string>("Address.AptNum"), out aptNum)) { address.ApartmentNumber = aptNum; } else { address.ApartmentNumber = null; } employee.HomeAddress = address; employee.Role = map.GetInput <EmployeeRole>("Role"); if (DataAccess.Insert(employee)) { employee = DataAccess.Match(employee)[0]; ViewManager.ShowFlash(string.Format("Employee added with ID: {0}\nTheir password will be their SIN until they change it.", employee.EmployeeId), FlashMessageType.Good); Logger.Log(LogLevel.Info, "Added employee with ID {0}", employee.EmployeeId); ViewManager.Show("AddEmployee", map); } else { ViewManager.ShowFlash("Failed to add employee:\n" + DataAccess.Database.LastFailReason.Message, FlashMessageType.Bad); Logger.Log(LogLevel.Error, DataAccess.Database.LastFailReason.Message); ViewManager.Show("AddEmployee", map); } } }
public void Populate(IoMap map) { map.SetInput(__GetName("Street"), txtStreet.Text); map.SetInput(__GetName("PostalCode"), txtPostalCode.Text); map.SetInput(__GetName("AptNum"), txtAptNum.Text); map.SetInput(__GetName("City"), cbCity.Text); map.SetInput(__GetName("Country"), cbCountry.Text); map.SetInput(__GetName("State"), cbState.Text); }
public void ChangePassword() { IoMap map = ViewManager.CurrentMap; if (map.HasInput <string>("OldPassword")) { string oldPass = map.GetInput <string>("OldPassword"); if (map.HasInput <string>("NewPassword")) { string newPass = map.GetInput <string>("NewPassword"); if (map.HasInput <string>("ConfirmPassword")) { string confirmPass = map.GetInput <string>("ConfirmPassword"); if (PasswordSecurity.PasswordStorage.VerifyPassword(oldPass, (Auth.User as Employee).HashedPassword)) { if (newPass.Equals(confirmPass)) { if (Validations.ValidatePassword(newPass)) { Employee auth = (Auth.User as Employee); auth.HashedPassword = PasswordSecurity.PasswordStorage.CreateHash(newPass); DataAccess.Update(auth); Auth.User = auth; ViewManager.ShowFlash("Password has been updated!", FlashMessageType.Good); ViewManager.GotoPrevious(); return; } else { ViewManager.ShowFlash("Password does not meet strength requirements", FlashMessageType.Bad); ViewManager.Show("UpdatePassword"); return; } } else { ViewManager.ShowFlash("New password and confirm password do not match", FlashMessageType.Bad); ViewManager.Show("UpdatePassword"); return; } } else { ViewManager.ShowFlash("Old Password does not match", FlashMessageType.Bad); ViewManager.Show("UpdatePassword"); return; } } } } ViewManager.ShowFlash("Not enough input for action", FlashMessageType.Bad); }
/// <summary> /// Fills this IInput from a given IO map /// </summary> /// <param name="map">The map to fill from</param> public void Fill(IoMap map) { if (map.HasInput(Name)) { Value = map.GetInput <object>(Name); } else { myControl.Text = ""; } }
/// <summary> /// Fills this IInput from a given IO map /// </summary> /// <param name="map">The map to fill from</param> public void Fill(IoMap map) { if (map.HasInput <bool>(Name)) { myControl.Checked = map.GetInput <bool>(Name); } else { myControl.Checked = false; } }
/// <summary> /// Fills this IInput from a given IO map /// </summary> /// <param name="map">The map to fill from</param> public void Fill(IoMap map) { if (map.HasInput(Name)) { Value = map.GetInput <object>(Name); } else if (myControl.Items.Count > 0) { myControl.SelectedIndex = 0; } }
protected override void LoadMyViewContext(IoMap map) { Outputs.First(X => X.Name == "Block.Genre").Fill(map); cbGenre.SelectedIndex = cbGenre.Items.Count > 0 ? 0 : -1; Genre genre = cbGenre.Items.Count == 0 ? DataAccess.SelectAll <Genre>().FirstOrDefault() : cbGenre.SelectedItem as Genre; if (genre != null) { map.SetOutput("Data", DataAccess.Execute(Resources.SelectSeriesInfoQuery, new [] { new QueryParam("genreId", QueryParamType.Integer) }, new object[] { genre.GenreId })); } }
protected override void LoadMyViewContext(IoMap map) { dgvItems.Rows.Clear(); List <Model.Product> items = Session.Get <List <Model.Product> >("AddingProducts"); if (map.HasInput <Model.Block>("Block.Input")) { if (items == null) { Session.Set("AddingProducts", new List <Model.Product>()); items = Session.Get <List <Model.Product> >("AddingProducts"); } Model.Block block = map.GetInput <Model.Block>("Block.Input"); map.SetInput <Model.Block>("Block.Input", null); map.SetInput("Block", block); Model.BlockItem toMatch = new Model.BlockItem(); toMatch.BlockId = block; Model.BlockItem[] matches = DataAccess.Match(toMatch); for (int index = 0; index < matches.Length; index++) { items.Add(DataAccess.FromPrimaryKey <Model.Product>(matches[index].ProducId.ProductId)); } map.SetInput("Block.Title", block.Title); map.SetInput("Block.Description", block.Description); map.SetInput("Block.Series", block.SeriesId); map.SetInput("Block.ShipByDate", block.ShipByDate); } if (items != null) { for (int index = 0; index < items.Count; index++) { DataGridViewRow row = dgvItems.Rows[dgvItems.Rows.Add()]; row.Cells["pId"].Value = items[index].ProductId; row.Cells["pName"].Value = items[index].Name; row.Cells["pWidth"].Value = items[index].Width; row.Cells["pHeight"].Value = items[index].Height; row.Cells["pDepth"].Value = items[index].Depth; row.Cells["pDescription"].Value = items[index].Description; } } map.SetOutput("AllProducts", DataAccess.Execute("select * from tblproduct")); }
public void Fill(IoMap map) { ViewManager.PopulateFromQuery(cbState, DataAccess.Execute("select state from tbladdress group by state order by state")); ViewManager.PopulateFromQuery(cbCountry, DataAccess.Execute("select country from tbladdress group by country order by country")); ViewManager.PopulateFromQuery(cbCity, DataAccess.Execute("select city from tbladdress group by city order by city")); txtStreet.Text = map.GetInput <string>(__GetName("Street")); txtPostalCode.Text = map.GetInput <string>(__GetName("PostalCode")); txtAptNum.Text = map.GetInput <string>(__GetName("AptNum")); cbCity.Text = map.GetInput <string>(__GetName("City")); cbCountry.Text = map.GetInput <string>(__GetName("Country")); cbState.Text = map.GetInput <string>(__GetName("State")); }
public void Push(IoMap io) { //Pack the IoMap byte[] map = io.Pack(); /*Debug.Log(map[0] + " " + map[1] + " " + map[2] + " " + map[3]+ " " + map[4] + " " + map[5] + " " + map[6] + " " + map[7] + " " + * map[8] + " " + map[9] + " " + map[10] + " " + map[11] + " " + map[12] + " " + map[13] + " " + map[14] + " " + map[15] + " " + * map[16] + " " + map[17] + " " + map[18] + " " + map[19] + " " + map[20] + " " + map[21] + " " + map[22] + " " + map[23] + " " + * map[24] + " " + map[25]); */ //Send the Packet Send(map); }
protected override void LoadMyViewContext(IoMap map) { Order order = map.GetInput <Order>("Order.Selected"); if (order != null) { map.SetOutput("Items", DataAccess.Execute(Resources.SelectProductInfo, new[] { new QueryParam("orderId", QueryParamType.Integer) }, new object[] { order.OrderId.Value })); map.SetOutput("OrderID", order.OrderId.Value); map.SetOutput("OrderBy", order.OrderedBy); map.SetOutput("OrderDate", order.DateOrdered.Value.ToLongDateString()); map.SetOutput("OrderSupp", order.SupplierId.Company); map.SetOutput("OrderCost", DataAccess.Execute(string.Format("select Sum(lineitem.batchcost) as TotalCost from tblorderlineitem as lineitem where orderid={0}", order.OrderId.Value)).Row["TotalCost"]); } }
/// <summary> /// Loads this view with the given IoMap /// </summary> /// <param name="map">The IoMap to load the view with</param> public void LoadView(IoMap map) { // Let child classes hook into our loadview LoadMyViewContext(map); // Iterate over outputs and fill them from the map for (int index = 0; index < Outputs.Count; index++) { Outputs[index].Fill(map); } // Iterate over inputs and fill them from the map for (int index = 0; index < Inputs.Count; index++) { Inputs[index].Fill(map); } }
protected override void LoadMyViewContext(IoMap map) { dgvExtraProduct.Rows.Clear(); List <Product> items = Session.Get <List <Product> >("AddingProducts"); if (items != null) { for (int index = 0; index < items.Count; index++) { DataGridViewRow row = dgvExtraProduct.Rows[dgvExtraProduct.Rows.Add()]; row.Cells["iName"].Value = items[index].Name; row.Cells["iQuantity"].Value = items[index].Stock; row.Cells["iDescription"].Value = items[index].Description; } } }
/// <summary> /// Displays the view to the user /// </summary> /// <param name="control">The view to display</param> public void ShowView(ViewBase control, IoMap map) { for (int index = 0; index < myContentPanel.Controls.Count; index++) { myContentPanel.Controls[index].Hide(); } control.Anchor = AnchorStyles.None; control.Left = (myContentPanel.Width / 2) - (control.Width / 2); control.Top = (myContentPanel.Height / 2) - (control.Height / 2); if (!myContentPanel.Controls.Contains(control)) { myContentPanel.Controls.Add(control); } control.LoadView(map); control.Show(); CurrentView = control; }
protected override void LoadMyViewContext(IoMap map) { dgvOrder.Rows.Clear(); List <OrderLineitem> items = Session.Get <List <OrderLineitem> >("WorkingOrderItems"); decimal totalCost = 0; if (items != null) { for (int index = 0; index < items.Count; index++) { DataGridViewRow row = dgvOrder.Rows[dgvOrder.Rows.Add()]; row.Cells["ProdName"].Value = items[index].ProductId.Name; row.Cells["Quantity"].Value = items[index].Quantity; row.Cells["Price"].Value = items[index].BatchCost; totalCost += items[index].BatchCost.Value; } } }
protected override void LoadMyViewContext(IoMap map) { dgvItems.Rows.Clear(); List <Model.Product> items = Session.Get <List <Model.Product> >("AddingProducts"); if (items != null) { for (int index = 0; index < items.Count; index++) { DataGridViewRow row = dgvItems.Rows[dgvItems.Rows.Add()]; row.Cells["pId"].Value = items[index].ProductId; row.Cells["pName"].Value = items[index].Name; row.Cells["pWidth"].Value = items[index].Width; row.Cells["pHeight"].Value = items[index].Height; row.Cells["pDepth"].Value = items[index].Depth; row.Cells["pDescription"].Value = items[index].Description; } } map.SetOutput("AllProducts", DataAccess.Execute("select * from tblproduct")); }
public void InsertExtraProduct() { IoMap map = ViewManager.CurrentMap; if (Session.Get <List <Model.Product> >("AddingProducts") == null) { Session.Set("AddingProducts", new List <Model.Product>()); } List <Model.Product> items = Session.Get <List <Model.Product> >("AddingProducts"); if (map.HasInput <Model.Product>("ProductToAdd")) { items.Add(map.GetInput <Model.Product>("ProductToAdd")); map.SetInput <Model.Product>("ProductToAdd", null); ViewManager.Show("AddBlocks", map); } else { ViewManager.ShowFlash("Please select a product to add", FlashMessageType.Neutral); } }
void FixedUpdate() { //If we are server do nothing if ((client != null && client.enabled) || NoNetwork) { var map = new IoMap(); map.RT = Input.GetAxis("Throttle"); map.LeftAxisVertical = Input.GetAxis("Vertical"); map.LeftAxisHorizontal = Input.GetAxis("Horizontal"); map.A = Input.GetButton("Fire1"); map.B = Input.GetButton("Fire2"); if (NoNetwork) { Push(map); } else { client.Push(map); } } }
public static bool Validate(ref string reason) { bool result = true; IoMap map = ViewManager.CurrentMap; string title = map.GetInput <string>("Block.Title"); DateTime shipDate = map.GetInput <DateTime>("Block.ShipByDate"); string description = map.GetInput <string>("Block.Description"); BlockSeries series = map.GetInput <BlockSeries>("Block.Series"); if (string.IsNullOrWhiteSpace(title) || title.Length < 3) { result = false; reason += "Title must be at least 3 characters" + Environment.NewLine; } if (shipDate == default(DateTime)) { result = false; reason += "Ship Date must be filled" + Environment.NewLine; } if (string.IsNullOrWhiteSpace(description)) { result = false; reason += "Description must be filled" + Environment.NewLine; } if (series == null) { result = false; reason += "A series must be selected" + Environment.NewLine; } return(result); }
protected override void LoadMyViewContext(IoMap map) { map.SetOutput("AllEmployees", DataAccess.SelectAll <Employee>()); }
/// <summary> /// Fills this IOutput from a given IO map /// </summary> /// <param name="map">The map to fill from</param> public void Fill(IoMap map) { ViewManager.PopulateList <T, ComboBox>(myControl); }
protected override void LoadMyViewContext(IoMap map) { IQueryResult result = DataAccess.Execute("select * from tblcustomers"); map.SetOutput("Customers", result); }
/// <summary> /// Populates an IOMap from this input /// </summary> /// <param name="map">The map to populate</param> public void PopulateMap(IoMap currentMap) { currentMap.SetInput(Name, myControl.Value); }
public void InsertProduct() { IoMap map = ViewManager.CurrentMap; string companyName = map.GetInput <string>("Company.Name"); string companyPhone = map.GetInput <string>("Company.Phone"); string contactFirstName = map.GetInput <string>("Contact.FirstName"); string contactLastName = map.GetInput <string>("Contact.LastName"); string contactEmail = map.GetInput <string>("Contact.Email"); string error = ""; if (companyName == null || string.IsNullOrWhiteSpace(companyName)) { error += "You must enter a company name\n"; } if (companyPhone == null || string.IsNullOrWhiteSpace(companyPhone)) { error += "You must enter a company phone number\n"; } if (string.IsNullOrWhiteSpace(contactFirstName)) { error += "You must enter a contact first name\n"; } if (string.IsNullOrWhiteSpace(contactLastName)) { error += "You must enter a contact last name\n"; } if (string.IsNullOrWhiteSpace(contactEmail)) { error += "You must enter a contact email address\n"; } Validations.ValidateAddressFromMap(map, "Address", ref error); companyPhone = Validations.ValidatePhone(companyPhone, ref error); if (error == "") { Supplier supplier = new Supplier(); supplier.Company = companyName; supplier.Phone = long.Parse(companyPhone); supplier.ContactFirstName = contactFirstName; supplier.ContactLastName = contactLastName; supplier.ContactEmail = contactEmail; Address address = new Address(); address.StreetAddress = map.GetInput <string>("Address.Street"); address.Country = map.GetInput <string>("Address.Country"); address.State = map.GetInput <string>("Address.State"); address.PostalCode = map.GetInput <string>("Address.PostalCode"); address.City = map.GetInput <string>("Address.City"); int aptNum = -1; if (int.TryParse(map.GetInput <string>("Address.AptNum"), out aptNum)) { address.ApartmentNumber = aptNum; } else { address.ApartmentNumber = null; } supplier.Address = address; if (DataAccess.Insert(supplier)) { map.Reset(); ViewManager.ShowFlash("Supplier has been added.", FlashMessageType.Good); ViewManager.Show("AddSupplier"); } else { ViewManager.ShowFlash("Failed to add supplier: \n" + DataAccess.Database.LastFailReason.Message, FlashMessageType.Bad); return; } } else { ViewManager.ShowFlash("Failed to add supplier: \n" + error, FlashMessageType.Bad); return; } }