static void Main(string[] args) { Sum homework = new Sum(); // For sum of numbers Console.WriteLine("Enter First Number: "); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Second Number: "); int num2 = int.Parse(Console.ReadLine()); bool result = homework.SumOfNum(num1, num2); //calling first method if (result) { Console.WriteLine($"Sum of {num1} and {num2} is greater than 500. So, the result is {result}"); } else { Console.WriteLine($"Sum of {num1} and {num2} is not greater than 500. So, the result is {result}"); } // For calculating the result PointCalculation Points = new PointCalculation(); Console.WriteLine("Enter the number of wins: "); int wins = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the number of Draws: "); int draws = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the number of losses: "); int losses = int.Parse(Console.ReadLine()); int points = Points.CalculatePoints(wins, draws, losses); Console.WriteLine($"Team played {wins+draws+losses} matches and earned total of{points} points."); // For generating the results Question3 Shortname = new Question3(); Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); string initials = Shortname.GetInitials(name); Console.WriteLine($"Your initial is {initials}"); }
protected void submitButton_Click(object sender, EventArgs e) { #region Event Attendance // Logging event attendance string codeValue = Logic.Code.SanitizeCode(codeEntryField.Text); codeEntryField.Text = codeValue; int patronId = ((Patron)Session[SessionKey.Patron]).PID; var pointsAward = new AwardPoints(patronId); if (codeValue.Length == 0) { new SessionTools(Session).AlertPatron("Please enter a code.", PatronMessageLevels.Danger, "remove"); return; } else { // verify event code was not previously redeemed if (PatronPoints.HasRedeemedKeywordPoints(patronId, codeValue)) { new SessionTools(Session).AlertPatron("You've already redeemed this code!", PatronMessageLevels.Warning, "exclamation-sign"); return; } // get event for that code, get the # points var ds = Event.GetEventByEventCode(codeValue); if (ds.Tables[0].Rows.Count == 0) { new SessionTools(Session).AlertPatron("Sorry, that's an invalid code.", PatronMessageLevels.Warning, "exclamation-sign"); return; } var EID = (int)ds.Tables[0].Rows[0]["EID"]; var evt = Event.GetEvent(EID); var points = evt.NumberPoints; //var newPBID = 0; var earnedBadges = pointsAward.AwardPointsToPatron(points: points, reason: PointAwardReason.EventAttendance, eventCode: codeValue, eventID: EID); if (!string.IsNullOrWhiteSpace(earnedBadges)) { new SessionTools(Session).EarnedBadges(earnedBadges); } string userMessage = null; // set message and earned badges string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points); if (string.IsNullOrEmpty(earnedMessage)) { userMessage = "<strong>Excellent!</strong> Your secret code has been recorded."; } else { userMessage = string.Format("<strong>Excellent!</strong> Your secret code has been recorded. <strong>{0}</strong>", earnedMessage); } new SessionTools(Session).AlertPatron(userMessage, PatronMessageLevels.Success, "barcode"); this.codeEntryField.Text = string.Empty; } #endregion }
protected void submitButton_Click(object sender, EventArgs e) { #region Event Attendance // Logging event attendance string codeValue = Logic.Code.SanitizeCode(codeEntryField.Text); codeEntryField.Text = codeValue; int patronId = (int)ViewState["SubmitAsPatronId"]; var pointsAward = new AwardPoints(patronId); var patron = Patron.FetchObject(patronId); var patronName = DisplayHelper.FormatName(patron.FirstName, patron.LastName, patron.Username); if (codeValue.Length == 0) { Session[SessionKey.PatronMessage] = "Please enter a code."; Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger; Session[SessionKey.PatronMessageGlyphicon] = "remove"; return; } else { // verify event code was not previously redeemed if (PatronPoints.HasRedeemedKeywordPoints(patronId, codeValue)) { Session[SessionKey.PatronMessage] = string.Format("{0} has already redeemed this code!", patronName); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } // get event for that code, get the # points var ds = Event.GetEventByEventCode(codeValue); if (ds.Tables[0].Rows.Count == 0) { Session[SessionKey.PatronMessage] = "Sorry, that's an invalid code."; Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } var EID = (int)ds.Tables[0].Rows[0]["EID"]; var evt = Event.GetEvent(EID); var points = evt.NumberPoints; //var newPBID = 0; var earnedBadges = pointsAward.AwardPointsToPatron(points: points, reason: PointAwardReason.EventAttendance, eventCode: codeValue, eventID: EID); // don't show badge earnings to the parent //if(!string.IsNullOrWhiteSpace(earnedBadges)) { // new SessionTools(Session).EarnedBadges(earnedBadges); //} // set message and earned badges string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points, patronName); if (string.IsNullOrEmpty(earnedMessage)) { Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded for {0}.", patronName); } else { Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded. <strong>{0}</strong>", earnedMessage); } Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success; Session[SessionKey.PatronMessageGlyphicon] = "barcode"; this.codeEntryField.Text = string.Empty; } #endregion }
protected void SubmitActivity() { var txtCount = readingActivityField.Text.Trim(); var intCount = 0; if (txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0) { Session[SessionKey.PatronMessage] = "You must enter how much you've read as a positive whole number."; Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger; Session[SessionKey.PatronMessageGlyphicon] = "remove"; return; } var selectedActivityType = activityTypeSelector.SelectedValue; // check that we aren't over the max int maxAmountForLogging = 0; switch (int.Parse(selectedActivityType)) { case 0: maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt(); break; case 1: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt(); break; //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt(); // break; case 3: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt(); break; default: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt(); break; } if (intCount > maxAmountForLogging) { Session[SessionKey.PatronMessage] = string.Format("That's an awful lot of reading! You can only submit {0} {1} at a time.", maxAmountForLogging, ((ActivityType)int.Parse(selectedActivityType)).ToString()); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } var patronId = ((Patron)Session[SessionKey.Patron]).PID; var programGameId = int.Parse(ViewState["ProgramGameId"].ToString()); var pa = new AwardPoints(patronId); var points = 0; // convert pages/minutes/etc. to points var pc = new ProgramGamePointConversion(); pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue)); // round up to ensure they get at least 1 point decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount; points = (int)Math.Ceiling(computedPoints); // ensure they aren't over teh day total var allPointsToday = PatronPoints.GetTotalPatronPoints(patronId, DateTime.Now); int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt(); if (intCount + allPointsToday > maxPointsPerDayForLogging) { Session[SessionKey.PatronMessage] = "Sorry but you have already reached the maximum amount of points that you can log in a day. Keep reading and come back tomorrow!"; Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } var earnedBadges = pa.AwardPointsToPatron(points: points, reason: PointAwardReason.Reading, MGID: 0, readingActivity: (ActivityType)pc.ActivityTypeId, readingAmount: intCount, author: authorField.Text, title: titleField.Text); // clear out the form var bookButton = activityTypeSelector.Items.Count == 1 && int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books; if (!bookButton) { readingActivityField.Text = string.Empty; } authorField.Text = string.Empty; titleField.Text = string.Empty; // set message and earned badges string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points); if (string.IsNullOrEmpty(earnedMessage)) { Session[SessionKey.PatronMessage] = "<strong>Good job!</strong> Your reading activity has been logged."; } else { Session[SessionKey.PatronMessage] = string.Format("<strong>Good job!</strong> Your reading activity has been logged. <strong>{0}</strong>", earnedMessage); } Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success; Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up"; new SessionTools(Session).EarnedBadges(earnedBadges); }
protected void SubmitActivity() { var txtCount = readingActivityField.Text.Trim(); var intCount = 0; if (txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0) { Session[SessionKey.PatronMessage] = StringResources.getString("readinglog-entry-invalid"); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger; Session[SessionKey.PatronMessageGlyphicon] = "remove"; return; } var selectedActivityType = activityTypeSelector.SelectedValue; // check that we aren't over the max int maxAmountForLogging = 0; switch (int.Parse(selectedActivityType)) { case 0: maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt(); break; case 1: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt(); break; //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt(); // break; case 3: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt(); break; default: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt(); break; } if (intCount > maxAmountForLogging) { Session[SessionKey.PatronMessage] = string.Format(StringResources.getString("readinglog-entry-limit"), maxAmountForLogging, ((ActivityType)int.Parse(selectedActivityType)).ToString()); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } var patronId = ((Patron)Session[SessionKey.Patron]).PID; var programGameId = int.Parse(ViewState[ProgramGameIdKey].ToString()); var pa = new AwardPoints(patronId); var points = 0; // convert pages/minutes/etc. to points var pc = new ProgramGamePointConversion(); pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue)); // round up to ensure they get at least 1 point decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount; points = (int)Math.Ceiling(computedPoints); // ensure they aren't over teh day total var allPointsToday = PatronPoints.GetTotalPatronPointsOnDate(patronId, DateTime.Now); int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt(); if (intCount + allPointsToday > maxPointsPerDayForLogging) { Session[SessionKey.PatronMessage] = StringResources.getString("readinglog-daily-limit"); Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning; Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign"; return; } var review = ""; if (ViewState[PatronCanReviewKey] as bool? == true) { review = reviewField.Text; } var earnedBadges = pa.AwardPointsToPatron(points: points, reason: PointAwardReason.Reading, MGID: 0, readingActivity: (ActivityType)pc.ActivityTypeId, readingAmount: intCount, author: authorField.Text, title: titleField.Text, review: review); // clear out the form var bookButton = activityTypeSelector.Items.Count == 1 && int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books; if (!bookButton) { readingActivityField.Text = string.Empty; } authorField.Text = string.Empty; titleField.Text = string.Empty; reviewField.Text = string.Empty; // set message and earned badges string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points); if (string.IsNullOrEmpty(earnedMessage)) { Session[SessionKey.PatronMessage] = "<strong>Good job!</strong> Your reading activity has been logged."; } else { Session[SessionKey.PatronMessage] = string.Format("<strong>Good job!</strong> Your reading activity has been logged. <strong>{0}</strong>", earnedMessage); } Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success; Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up"; new SessionTools(Session).EarnedBadges(earnedBadges); }