mardi 2 février 2016

C# - duplicated output for start date in date range iteration

I am trying to make simple app and got stuck. User chooses start date from date picker1 28.01.2015 and end date picker2 29.01.2015 then marks what he/she wants via checkboxes and presses button. The output in console should look similar to this depending on what is marked.

tar zxcvf /.../c/folder/folder/$HOSTNAME.20150128.log;zxcvf /.../c/folder/folder/$HOSTNAME.20150129.log`

but instead date picked as start date is returned twice in console and I have no idea what is wrong:

zxcvf /.../c/folder/folder/$HOSTNAME.20150128.log;zxcvf /.../c/folder/folder/$HOSTNAME.20150128.log;zxcvf /.../c/folder/folder/$HOSTNAME.20150129.log 

Code below:

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;
using Renci.SshNet;
using System.Configuration;

namespace TestApp
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            GlobalMethods configRead = new GlobalMethods();
            configRead.ConfigRead();
        }

...

        private void button1_Click(object sender, EventArgs e)
        {
            GlobalMethods configRead = new GlobalMethods();
            configRead.ConfigRead();
            GlobalMethods dateIterator = new GlobalMethods();
            dateIterator.Iterator();
            GlobalVariables.comminit = null;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                GlobalVariables.cLM = true;
            }
            else if (!checkBox1.Checked)
            {
                GlobalVariables.cLM = false;
            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            GlobalVariables.dateStart = dateTimePicker1.Value;

        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            GlobalVariables.dateEnd = dateTimePicker2.Value;
            //string endDate = dateTimePicker2.Value.ToString("yyyyMMdd"); 
        }

    }
    public static class GlobalVariables
    {
        // Log variables below
        public static Boolean mLM;
        public static Boolean cLM;
        public static Boolean hLM;
        public static Boolean pLM;
        public static Boolean prLM;
        public static Boolean compressMarked = true;
        public static String iterate;
        public static String comminit;
        public static String pH;
        public static String pP;
        public static String pC;
        public static String ppP;
        public static String pM;
        // Time variables below
        public static DateTime dateStart = DateTime.Now;
        public static DateTime dateEnd = DateTime.Now; 
    }

    public class Instructions
    {

        public static String hLl()
        {
            if (GlobalVariables.compressMarked)
            {
                return "tar zxcvf " + GlobalVariables.pH + "$HOSTNAME." + GlobalVariables.iterate + ".log;";
            }
            else { return "wget " + GlobalVariables.pH + "$HOSTNAME." + GlobalVariables.iterate + ".log;"; }
        }

...

        public static String commandsBath()
        {

            if (GlobalVariables.mLM == true)
            {
                GlobalVariables.comminit += mLl();


            }

            if (GlobalVariables.cLM == true)
            {
                GlobalVariables.comminit += cLl();

            }


            if (GlobalVariables.hLM == true)
            {
                GlobalVariables.comminit += hLl();

            }


            if (GlobalVariables.pLM == true)
            {
                GlobalVariables.comminit += pLl();

            }


            if (GlobalVariables.prLM == true)
            {
                GlobalVariables.comminit += pLlp();

            }

            return GlobalVariables.comminit;

        }
    }
    public class GlobalMethods
    {

       public void Iterator()
        {
            for (DateTime i = GlobalVariables.dateStart; i <= GlobalVariables.dateEnd; i = i.AddDays(1))
{
                string iterated = i.ToString("yyyyMMdd");
                GlobalVariables.iterate = iterated;
            }
        }
        public void ConfigRead()
        {
...
        }
        public void ConfigWrite()
        {
...
        }

    } 

}

Hopefully someone can help.

Aucun commentaire:

Enregistrer un commentaire