Search code examples
c#dateconsole.writeline

Pin Generator - By Date Calculated - No Interaction - C#


I hoped that I could get pointed in the right direction logic wise.

Background Info

A daily pin for an application is generated using a set of calculations based off month, day, year on a schedule that is known 5 months out. This schedule manipulates which parts of the date (month, day, year) are included in the calculation as well as how it's calculated (addition, subtraction, multiplication).

Instead of opening up my calculator to calculate this pin, referring to documentation, then calculating from that documentation, I would like to make a program that would do it for me and who knows even my co-workers if they keep feeding me.

My Experience with C# or other programming: a "Hello World" experience level.

Summary of Research

*Found answers to: How to make a form in C# How to transfer info from one textbox to the other in C# How to Close an application How to get the current date. How to only get the date and not the time to show up in a textbox. How to Transfer info from one textbox to another.

*Haven't found what I'm looking for: How to parse a date from a textbox in another textbox. How to calculate the parsed information on a rotating table. How to parse a date using date time so that it can be calculated in another text box.

My Goal Make the app not require user interaction so my co-workers I share with don't get mad when they don't input in the correct method.

Adjust the app every 5 months with the needed calculations (in which I'll figure out if I can push out an update automatically instead of installing it every 5 months).

Find that tidbit of logic I'm missing so that I can build on it from there and improve this app.


The Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

 namespace Pin_Generator
{
public partial class Home : Form
{
    public Home()
    {
        InitializeComponent();
        TodayDateTextBox.Text = DateTime.Now.ToString("MM/dd/yyyy");
        TodayPasswordTextBox.Text = TodayDateTextBox.Text;

    }

    private void Home_Load(object sender, EventArgs e)
    {

    }

    private void CloseButton_Click(object sender, EventArgs e)
    {
        this.Close();
        Application.Exit();

    }


    // private void TodayPasswordTextBox_TextChanged(object sender, EventArgs e)
   // {
   //     int MM;
   //     int dd;
   //     int yyyy;


When Debug the screen shows:

Todays Date: 5/19/2015

Todays Pin: 5/19/2015

The screen should show something like: Todays Date: 5/19/2015 Todays Pin: 33289306093

I understand I still have a long way to go but I am seeing a lot of resources on how to calculate but not so much on how to calculate what I have as "Todays Date" to be transformed into a different number based off of the date. I've also just tried searching "How do I convert date into calculated string"

I think with the correct questions, I should be able to find the correct answers but so far my logic has differed and I haven't quite got the keywords down. Or it could be that I'm going about completely the wrong way, I understand that as well.

Thank you all in advance for your time and please let me know if you have any questions for me. I hope the screenshots help visualize where my mind is and hopefully I can get back on the right track with your help.


Solution

  • If you create a method like the following to calculate your PIN.

        public string CalculatePIN()
        {
            DateTime today = DateTime.Now;
            int year = today.Year;
            int month = today.Month;
            int day = today.Day;
    
            string pin = // Do some calculation using the year month and day variables.
    
            return pin;
        }
    

    you can modify your Home method to do the following...

        public Home()
        {
            InitializeComponent();
            TodayDateTextBox.Text = DateTime.Now.ToString("MM/dd/yyyy");
            TodayPasswordTextBox.Text = CalculatePIN();
        }