public void generateCoupon(rewardMember mem) { do { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); code = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray()); expiration = DateTime.Now.AddMonths(3); } while (!valid()); if (mem != null) addToMember(mem); sendToDB(); }
public void generateCoupon(rewardMember mem) { do { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); code = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray()); expiration = DateTime.Now.AddMonths(3); } while (!valid()); if (mem != null) { addToMember(mem); } sendToDB(); }
private void addToMember(rewardMember mem) { try { using (SqlConnection openCon = new SqlConnection("Server=tcp:omsdb.database.windows.net,1433;Database=OMSDB;User ID=csce4444@omsdb;Password=Pineapple!;")) { string couponList; using (SqlCommand querySave = new SqlCommand("select * from dbo.Customers where Phone = @phone", openCon)) { querySave.Parameters.AddWithValue("@phone", mem.phoneNumber); openCon.Open(); SqlDataReader reader = querySave.ExecuteReader(); reader.Read(); couponList = (string)reader[7]; openCon.Close(); } if (couponList.Length <= 1) { couponList = code; } else { couponList += "," + code; } using (SqlCommand querySave = new SqlCommand("update dbo.Customers set DiscountCodes = @codes where Phone = @phone", openCon)) { querySave.Parameters.AddWithValue("@codes", couponList); querySave.Parameters.AddWithValue("@phone", mem.phoneNumber); openCon.Open(); querySave.ExecuteScalar(); openCon.Close(); } } } catch (Exception) { } }
private void addToMember(rewardMember mem) { try { using (SqlConnection openCon = new SqlConnection("Server=tcp:omsdb.database.windows.net,1433;Database=OMSDB;User ID=csce4444@omsdb;Password=Pineapple!;")) { string couponList; using (SqlCommand querySave = new SqlCommand("select * from dbo.Customers where Phone = @phone", openCon)) { querySave.Parameters.AddWithValue("@phone", mem.phoneNumber); openCon.Open(); SqlDataReader reader = querySave.ExecuteReader(); reader.Read(); couponList = (string)reader[7]; openCon.Close(); } if (couponList.Length <= 1) couponList = code; else couponList += "," + code; using (SqlCommand querySave = new SqlCommand("update dbo.Customers set DiscountCodes = @codes where Phone = @phone", openCon)) { querySave.Parameters.AddWithValue("@codes", couponList); querySave.Parameters.AddWithValue("@phone", mem.phoneNumber); openCon.Open(); querySave.ExecuteScalar(); openCon.Close(); } } } catch (Exception) { } }
private void submitBtn_Click(object sender, RoutedEventArgs e) { tableInterface parent = GetAncestorOfType <tableInterface>(this); bool valid = true; string message = ""; rewardMember member = new rewardMember(); // Check databse for phone number try { using (SqlConnection openCon = new SqlConnection("Server=tcp:omsdb.database.windows.net,1433;Database=OMSDB;User ID=csce4444@omsdb;Password=Pineapple!;")) { SqlCommand myCommand = new SqlCommand("SELECT * FROM dbo.Customers WHERE Phone = @phone", openCon); SqlDataAdapter sqlDa = new SqlDataAdapter(myCommand); myCommand.Parameters.AddWithValue("@phone", phoneNumber.Content.ToString()); openCon.Open(); SqlDataReader reader = myCommand.ExecuteReader(); if (!reader.HasRows) { valid = false; message = "Phone number not found."; } else { reader.Read(); member.phoneNumber = (string)reader[0]; member.firstName = (string)reader[1]; member.lastName = (string)reader[2]; member.birthDate = (DateTime)reader[3]; member.points = (int)reader[4] + 1; member.email = (string)reader[6]; member.discountCodes = (string)reader[7]; reader.Close(); myCommand = new SqlCommand("update dbo.Customers set Points = @points where Phone = @phone", openCon); myCommand.Parameters.AddWithValue("@phone", phoneNumber.Content.ToString()); myCommand.Parameters.AddWithValue("@points", member.points); myCommand.ExecuteScalar(); } openCon.Close(); } } catch (Exception) { } if (valid) { if (member.birthDate.Month == DateTime.Now.Month && member.birthDate.Day == DateTime.Now.Day) { coupon c = new coupon(); c.generateCoupon(member); member.discountCodes += "," + c.code; parent.overlay.Visibility = Visibility.Visible; parent.birthdayPopup.Visibility = Visibility.Visible; } parent.setCurrentMember(member); if (member.points >= 5) { parent.redeemGrid.Visibility = Visibility.Hidden; } parent.checkInGrid.Visibility = Visibility.Hidden; parent.welcomeGrid.Visibility = Visibility.Visible; } else { MessageBox.Show(message); } }