Exemplo n.º 1
0
        private void F_Sheet_Load(object sender, EventArgs e)
        {
            projectRepository = ProjectRepository.getInstance();
            c_project.DataSource = projectRepository.projects;
            c_project.DisplayMember = "projectName";
            c_project.ValueMember = "number";

            if (projectRepository.currentScreenMode == ProjectRepository.screenMode.editMode)
            {
                this.oldSheet = projectRepository.selectedSheet;

                c_project.SelectedValue = projectRepository.selectedSheet.job.task.project.number;
                this.comboBox1_SelectedIndexChanged(sender,e);

                c_task.SelectedValue = projectRepository.selectedSheet.job.task.number;
                this.c_task_SelectedIndexChanged(sender, e);

                c_job.SelectedValue = projectRepository.selectedSheet.job.number;

                dt_start_date.Value = projectRepository.selectedSheet.start.Date;
                dt_start_time.Value = projectRepository.selectedSheet.start;

                dt_end_date.Value = projectRepository.selectedSheet.end.Date;
                dt_end_time.Value = projectRepository.selectedSheet.end;

                tb_note.Text = projectRepository.selectedSheet.note;
            }
        }
Exemplo n.º 2
0
        public void idleManage(object sender, EventArgs e, Form1 form)
        {
            if (form.isCurrentlySheetActive() || isInPause)
            {
                Double idle = this.tmrIdle_Tick(sender, e);

                int paramIdleTime = Properties.Settings.Default.idelTime;

                //900000 = 15 min
                if (idle >= (paramIdleTime * 60) && isInPause == false)
                {
                    isInPause = true;
                    form.setDebutMessage("in pause now");

                    //Save current sheet to restart it
                    this.lastSheet = ProjectRepository.getInstance().actualSheet;

                    //Stop current sheet
                    form.stopCurrentSheet(paramIdleTime);
                }

                if (isInPause)
                {
                    if (idle > currentIdleTime)
                    {
                        currentIdleTime = idle;
                        form.setDebutMessage("in pause: currentIdle = " + currentIdleTime.ToString());
                    }
                    else {
                        DateTime startActive = new DateTime();
                        startActive = DateTime.Today.Add(Properties.Settings.Default.activeTimeFrom);

                        DateTime stopActive = new DateTime();
                        stopActive = DateTime.Today.Add(Properties.Settings.Default.activeTimeTo);

                        currentIdleTime = 0;

                        if (DateTime.Now.CompareTo(startActive) >= 0 && DateTime.Now.CompareTo(stopActive) <= 0)
                        {

                            isInPause = false;
                            form.setDebutMessage("out of pause");
                            //Restart last sheet
                            Sheet actualSheet = new Sheet();
                            actualSheet.start = DateTime.Now;
                            actualSheet.job = lastSheet.job;
                            actualSheet.job.task = lastSheet.job.task;

                            form.startSheet(actualSheet);
                        }
                        else
                        {
                            isInPause = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public bool Equals(Sheet p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (start == p.start) && (end == p.end) && (job.number == p.job.number);
        }
Exemplo n.º 4
0
        public void startSheet(Sheet actualSheet)
        {
            projectRepository.actualSheet = actualSheet;
            t_active_task.Text = actualSheet.job.task.project.number + " - " + actualSheet.job.task.number + " " + actualSheet.job.task.name + " - " + actualSheet.job.number + " " + actualSheet.job.name;
            t_title_active.Text = "Active job:";
            this.passedTime = new TimeSpan(0, 0, 0);

            t_time.Text = this.passedTime.ToString();

            timer1.Interval = 1000;
            timer1.Start();

            t_start.Enabled = false;
            t_stop.Enabled = true;

            projectRepository.loadDailyTime(dateTimePicker1.Value);
            this.displayDataGrid(dateTimePicker1.Value);
        }
Exemplo n.º 5
0
        private void b_ok_Click(object sender, EventArgs e)
        {
            Sheet newSheet = new Sheet()
            {
                job = (Job)c_job.SelectedItem,
                start = (dt_start_date.Value.Date).Add(dt_start_time.Value.TimeOfDay),
                end = (dt_end_date.Value.Date).Add(dt_end_time.Value.TimeOfDay),
                note = tb_note.Text
            };

              if (projectRepository.currentScreenMode == ProjectRepository.screenMode.newMode)
               {
                projectRepository.addSheet(newSheet);
            }
            else if (projectRepository.currentScreenMode == ProjectRepository.screenMode.editMode)
            {
                projectRepository.updateSheet(newSheet, oldSheet);

            }
            this.Close();
        }
        public void updateSheet(Sheet newSheet, Sheet oldSheet)
        {
            if (sheets.Count(s => s == oldSheet) == 0)
            {
                MessageBox.Show("No sheet exists with this number on this project", "Error", MessageBoxButtons.OK);
                return;
            }

            DateTime jobDate = oldSheet.start;
            FileStream fs = new FileStream(FileRepository.getInstance().appData + jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml", FileMode.Open, FileAccess.ReadWrite);
            XmlDocument tsfile = new XmlDocument();

            tsfile.Load(fs);
            fs.Close();

            foreach (XmlElement sheetElem in tsfile.SelectSingleNode(@"TimeSheet").ChildNodes)
            {
                //TODO: test if the childNode is really a sheet
                Decimal v_sheet_job_id = Decimal.Parse(sheetElem.GetAttribute("ma"));
                DateTime v_sheet_start = DateTime.Parse(sheetElem.SelectSingleNode("start").FirstChild.Value);
                DateTime v_sheet_stop = DateTime.Parse(sheetElem.SelectSingleNode("end").FirstChild.Value);
                String v_sheet_note = (sheetElem.SelectSingleNode("note").FirstChild == null ? null : sheetElem.SelectSingleNode("note").FirstChild.Value);

                Sheet loadedSheet = new Sheet() { job = this.findJobFromId(v_sheet_job_id), start = v_sheet_start, end = v_sheet_stop, note = v_sheet_note };

                if (oldSheet == loadedSheet)
                {
                    XmlNode rootNode = tsfile.SelectSingleNode(@"/TimeSheet");

                    XmlElement newSheetNode = tsfile.CreateElement("", "sheet", "");
                    newSheetNode.SetAttribute("ma", newSheet.job.number.ToString());

                    XmlNode startAttr = tsfile.CreateNode(XmlNodeType.Element, "start", "");
                    startAttr.InnerText = newSheet.start.ToShortDateString()+ " " + newSheet.start.ToLongTimeString();
                    newSheetNode.AppendChild(startAttr);

                    XmlNode endAttr = tsfile.CreateNode(XmlNodeType.Element, "end", "");
                    endAttr.InnerText = newSheet.end.ToShortDateString()+ " " + newSheet.end.ToLongTimeString();
                    newSheetNode.AppendChild(endAttr);

                    XmlNode noteAttr = tsfile.CreateNode(XmlNodeType.Element, "note", "");
                    noteAttr.InnerText = newSheet.note;
                    newSheetNode.AppendChild(noteAttr);

                    rootNode.ReplaceChild(newSheetNode, sheetElem);
                    break;
                }

            }
            this.fileSave(tsfile, jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml");

            this.loadMonthXml(jobDate.Month, jobDate.Year);
        }
        public IList<Sheet> loadMonthXmlSheets(Int32 month, Int32 year)
        {
            sheets = new List<Sheet>();

            if (File.Exists(FileRepository.getInstance().appData + year.ToString("0000") + month.ToString("00") + @".xml"))
            {
                FileStream fs = new FileStream(FileRepository.getInstance().appData + year.ToString("0000") + month.ToString("00") + @".xml", FileMode.Open, FileAccess.ReadWrite);
                XmlDocument tsfile = new XmlDocument();
                tsfile.Load(fs);

                try
                {

                    foreach (XmlElement sheet in tsfile.SelectSingleNode(@"TimeSheet").ChildNodes)
                    {
                        Decimal v_sheet_job_id = Decimal.Parse(sheet.GetAttribute("ma"));
                        DateTime v_sheet_start = DateTime.Parse(sheet.SelectSingleNode("start").FirstChild.Value);
                        DateTime v_sheet_stop = DateTime.Parse(sheet.SelectSingleNode("end").FirstChild.Value);
                        String v_sheet_note = (sheet.SelectSingleNode("note").FirstChild == null ? null : sheet.SelectSingleNode("note").FirstChild.Value);

                        Sheet loadedSheet = new Sheet() { start = v_sheet_start, end = v_sheet_stop, note = v_sheet_note };
                        loadedSheet.job = findJobFromId(v_sheet_job_id);

                        this.sheets.Add(loadedSheet);

                    }

                }
                catch (Exception)
                {
                    Console.WriteLine("error");
                    throw;
                }

                fs.Close();
            }
            return sheets;
        }
        public void deleteSheet(Sheet sheet)
        {
            if (sheets.Count(s => s == sheet) == 0)
                {
                    MessageBox.Show("No sheet exists with this number on this project", "Error", MessageBoxButtons.OK);
                    return;
                }

                DateTime jobDate = sheet.start;
                FileStream fs = new FileStream(FileRepository.getInstance().appData + jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml", FileMode.Open, FileAccess.ReadWrite);
                XmlDocument tsfile = new XmlDocument();

                    tsfile.Load(fs);
                    fs.Close();

                    foreach (XmlElement sheetElem in tsfile.SelectSingleNode(@"TimeSheet").ChildNodes)
                    {
                        //TODO: test if the childNode is really a sheet
                        Decimal v_sheet_job_id = Decimal.Parse(sheetElem.GetAttribute("ma"));
                        DateTime v_sheet_start = DateTime.Parse(sheetElem.SelectSingleNode("start").FirstChild.Value);
                        DateTime v_sheet_stop = DateTime.Parse(sheetElem.SelectSingleNode("end").FirstChild.Value);
                        String v_sheet_note = (sheetElem.SelectSingleNode("note").FirstChild == null ? null : sheetElem.SelectSingleNode("note").FirstChild.Value);

                        Sheet loadedSheet = new Sheet() {job = this.findJobFromId(v_sheet_job_id), start = v_sheet_start, end = v_sheet_stop, note = v_sheet_note };

                        if (sheet == loadedSheet)
                        {
                            tsfile.SelectSingleNode(@"TimeSheet").RemoveChild(sheetElem);
                            break;
                        }

                    }
                    this.fileSave(tsfile, jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml");

                this.loadMonthXml(jobDate.Month, jobDate.Year);
        }
        public void addSheet(Sheet sheet)
        {
            DateTime jobDate = sheet.start;
            FileStream fs;
            if (!File.Exists(FileRepository.getInstance().appData + jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml"))
            {
                fs = File.Create(FileRepository.getInstance().appData + jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml");

                StreamWriter m_streamWriter = new StreamWriter(fs);
                // Write to the file using StreamWriter class
                m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
                m_streamWriter.WriteLine(@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>");
                m_streamWriter.WriteLine(@"<TimeSheet>");
                m_streamWriter.WriteLine(@"</TimeSheet>");
                m_streamWriter.Flush();
                fs.Close();

            }

            fs = new FileStream(FileRepository.getInstance().appData + jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml", FileMode.Open, FileAccess.ReadWrite);
            XmlDocument tsfile = new XmlDocument();
            tsfile.Load(fs);

            try
            {
                XmlNode rootNode = tsfile.SelectSingleNode(@"/TimeSheet");
                XmlElement sheetNode = tsfile.CreateElement("", "sheet", "");
                sheetNode.SetAttribute("ma", sheet.job.number.ToString());

                XmlNode startAttr = tsfile.CreateNode(XmlNodeType.Element, "start", "");
                startAttr.InnerText = sheet.start.ToShortDateString()+ " " + sheet.start.ToLongTimeString();
                sheetNode.AppendChild(startAttr);

                XmlNode endAttr = tsfile.CreateNode(XmlNodeType.Element, "end", "");
                endAttr.InnerText = sheet.end.ToShortDateString()+ " " + sheet.end.ToLongTimeString();
                sheetNode.AppendChild(endAttr);

                XmlNode noteAttr = tsfile.CreateNode(XmlNodeType.Element, "note", "");
                noteAttr.InnerText = sheet.note;
                sheetNode.AppendChild(noteAttr);

                rootNode.AppendChild(sheetNode);
                fs.Close();
                this.fileSave(tsfile, jobDate.Year.ToString("0000") + jobDate.Month.ToString("00") + @".xml");

            }
            catch (Exception)
            {
                Console.WriteLine("error");
                throw;
            }

            this.loadMonthXml(jobDate.Month, jobDate.Year);
        }
Exemplo n.º 10
0
        private void t_start_Click_1(object sender, EventArgs e)
        {
            Sheet actualSheet = new Sheet();
            actualSheet.start = DateTime.Now;
            actualSheet.job = projectRepository.findJobFromSelectedNode();

            this.startSheet(actualSheet);
        }
Exemplo n.º 11
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (timer1.Enabled)
            {
                this.stopCurrentSheet();
            }

            projectRepository.selectedNode = e.Node;

            if (projectRepository.selectedNode.Level == 2)
            {
                Sheet actualSheet = new Sheet();
                actualSheet.start = DateTime.Now;
                actualSheet.job = projectRepository.findJobFromSelectedNode();

                this.startSheet(actualSheet);
            }
        }
Exemplo n.º 12
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                Sheet selectedSheet = new Sheet();
                selectedSheet.job = projectRepository.findJobFromId(Decimal.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()));
                selectedSheet.start = dateTimePicker1.Value.Date + TimeSpan.Parse(dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString());
                if (dataGridView1.Rows[e.RowIndex].Cells[7].Value != null)
                    selectedSheet.end = dateTimePicker1.Value.Date + TimeSpan.Parse(dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString());

                projectRepository.selectedSheet = projectRepository.sheets.SingleOrDefault(s => s == selectedSheet);
            }
        }