Jump to content
Tuts 4 You

Time diff calulate in c++


SuperJackAbcd

Recommended Posts

SuperJackAbcd
#pragma once

namespace CppCLR_WinformsProject1 {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^ label1;
    protected:
    private: System::Windows::Forms::Label^ label2;
    private: System::Windows::Forms::Label^ label3;
    private: System::Windows::Forms::TextBox^ textBox1;
    private: System::Windows::Forms::TextBox^ textBox2;
    private: System::Windows::Forms::Button^ button2;
    private: System::Windows::Forms::Button^ button3;
    private: System::Windows::Forms::Button^ button1;
    private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
    private: System::Windows::Forms::GroupBox^ groupBox1;
    private: System::Windows::Forms::RadioButton^ radioButton3;
    private: System::Windows::Forms::RadioButton^ radioButton2;
    private: System::Windows::Forms::RadioButton^ radioButton1;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
            this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
            this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
            this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
            this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
            this->groupBox1->SuspendLayout();
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(37, 88);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(38, 17);
            this->label1->TabIndex = 1;
            this->label1->Text = L"File1";
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(40, 142);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(38, 17);
            this->label2->TabIndex = 2;
            this->label2->Text = L"File2";
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(367, 207);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(48, 17);
            this->label3->TabIndex = 3;
            this->label3->Text = L"Result";
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(124, 88);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(395, 22);
            this->textBox1->TabIndex = 4;
            // 
            // textBox2
            // 
            this->textBox2->Location = System::Drawing::Point(124, 142);
            this->textBox2->Name = L"textBox2";
            this->textBox2->Size = System::Drawing::Size(395, 22);
            this->textBox2->TabIndex = 5;
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(527, 88);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(75, 23);
            this->button2->TabIndex = 6;
            this->button2->Text = L"Browse";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(527, 140);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(75, 23);
            this->button3->TabIndex = 7;
            this->button3->Text = L"Browse";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(444, 260);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 8;
            this->button1->Text = L"Calulate";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // openFileDialog1
            // 
            this->openFileDialog1->FileName = L"openFileDialog1";
            // 
            // groupBox1
            // 
            this->groupBox1->Controls->Add(this->radioButton3);
            this->groupBox1->Controls->Add(this->radioButton2);
            this->groupBox1->Controls->Add(this->radioButton1);
            this->groupBox1->Location = System::Drawing::Point(124, 181);
            this->groupBox1->Name = L"groupBox1";
            this->groupBox1->Size = System::Drawing::Size(200, 132);
            this->groupBox1->TabIndex = 9;
            this->groupBox1->TabStop = false;
            this->groupBox1->Text = L"groupBox1";
            // 
            // radioButton1
            // 
            this->radioButton1->AutoSize = true;
            this->radioButton1->Checked = true;
            this->radioButton1->Location = System::Drawing::Point(19, 22);
            this->radioButton1->Name = L"radioButton1";
            this->radioButton1->Size = System::Drawing::Size(106, 21);
            this->radioButton1->TabIndex = 0;
            this->radioButton1->TabStop = true;
            this->radioButton1->Text = L"Create Time";
            this->radioButton1->UseVisualStyleBackColor = true;
            // 
            // radioButton2
            // 
            this->radioButton2->AutoSize = true;
            this->radioButton2->Location = System::Drawing::Point(19, 50);
            this->radioButton2->Name = L"radioButton2";
            this->radioButton2->Size = System::Drawing::Size(97, 21);
            this->radioButton2->TabIndex = 1;
            this->radioButton2->TabStop = true;
            this->radioButton2->Text = L"Write Time";
            this->radioButton2->UseVisualStyleBackColor = true;
            // 
            // radioButton3
            // 
            this->radioButton3->AutoSize = true;
            this->radioButton3->Location = System::Drawing::Point(19, 81);
            this->radioButton3->Name = L"radioButton3";
            this->radioButton3->Size = System::Drawing::Size(109, 21);
            this->radioButton3->TabIndex = 2;
            this->radioButton3->TabStop = true;
            this->radioButton3->Text = L"Access Time";
            this->radioButton3->UseVisualStyleBackColor = true;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(614, 337);
            this->Controls->Add(this->groupBox1);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->textBox2);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label1);
            this->Name = L"Form1";
            this->Text = L"TimeDiff";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->groupBox1->ResumeLayout(false);
            this->groupBox1->PerformLayout();
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {


        openFileDialog1->ShowDialog();

        textBox1->Text = openFileDialog1->FileName;
    }
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {


    openFileDialog1->ShowDialog();

    textBox2->Text = openFileDialog1->FileName;

}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    System::IO::FileInfo^ f1 = gcnew System::IO::FileInfo(textBox1->Text);
    System::IO::FileInfo^ f2 = gcnew System::IO::FileInfo(textBox2->Text);

    TimeSpan t;
    String ^s;


    if (radioButton1->Checked) {
        //create time

        DateTime d1 = f1->CreationTime;

        DateTime d2 = f2->CreationTime;


        t = d2 - d1;

        s = "create";
    }
    else if(radioButton2->Checked){


        DateTime d1 = f1->LastWriteTime;

        DateTime d2 = f2->LastWriteTime;


         t = d2 - d1;


         s = "write";

    }
    else {

        DateTime d1 = f1->LastAccessTime;

        DateTime d2 = f2->LastAccessTime;

        t = d2 - d1;
        //TimeSpan t = d2 - d1;

        s = "access";


    }

    label3->Text = String::Format("Diff in {0}  : {1} min", s, t.Minutes) ;


    

}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
}

 

ConsoleApplication122.exe

Edited by SuperJackAbcd
i re-upload new version.
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...