Пример #1
0
        public void UpdateTask(ModelTask mtask)
        {
            Excel.Application xlApp     = new Excel.Application();
            Excel.Workbook    workBook  = xlApp.Workbooks.Open(filePath);
            Excel.Worksheet   workSheet = workBook.Worksheets[2];
            Excel.Range       range     = workSheet.UsedRange.Columns["A", Type.Missing];
            int rowCount = range.Rows.Count;

            try
            {
                for (int i = 2; i <= rowCount; i++)
                {
                    if (workSheet.Cells[i, "B"] != null && workSheet.Cells[i, "B"].Value != null && mtask.TaskId == workSheet.Cells[i, "B"].Value.ToString())
                    {
                        MainWindow window = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
                        workSheet.Cells[i, "A"].Value = window.txtTicket.Text.ToString();
                        workSheet.Cells[i, "B"].Value = mtask.TaskId;
                        workSheet.Cells[i, "C"].Value = mtask.TaskTitle;
                        workSheet.Cells[i, "D"].Value = mtask.TaskDescription;
                        workSheet.Cells[i, "E"].Value = mtask.TaskType;
                        workSheet.Cells[i, "F"].Value = mtask.State;
                        workSheet.Cells[i, "G"].Value = mtask.Priority;
                        workSheet.Cells[i, "H"].Value = mtask.AssignedTo;
                        workSheet.Cells[i, "I"].Value = mtask.Efforts;
                        workSheet.Cells[i, "J"].Value = mtask.PlannedStartDate;
                        workSheet.Cells[i, "K"].Value = mtask.PlannedEndDate;
                        workSheet.Cells[i, "L"].Value = mtask.ActualStartDate;
                        workSheet.Cells[i, "M"].Value = mtask.ActualEndDate;
                    }
                }
                workBook.Save();
                workBook.Close();

                xlApp.Quit();
                GC.Collect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                workBook.Save();
                workBook.Close();
                xlApp.Quit();
                GC.Collect();
            }
        }
Пример #2
0
        public List <ModelTask> GetTaskList(string userId, bool isAdmin)
        {
            Excel.Application xlApp    = new Excel.Application();
            List <ModelTask>  taskList = new List <ModelTask>();

            Excel.Workbook  workBook     = xlApp.Workbooks.Open(filePath);
            Excel.Worksheet workSheet    = workBook.Worksheets[2];
            Excel.Worksheet workSheetEmp = workBook.Worksheets[3];
            Excel.Range     range        = workSheet.UsedRange.Columns["A", Type.Missing];
            int             rowCount     = range.Rows.Count;

            Excel.Range raEmp       = workSheetEmp.UsedRange.Columns["A", Type.Missing];
            int         rowCountemp = raEmp.Rows.Count;

            try
            {
                for (int i = 2; i <= rowCount; i++)
                {
                    ModelTask tasks = new ModelTask();
                    if (workSheet.Cells[i, "A"] != null && workSheet.Cells[i, "A"].Value != null)
                    {
                        tasks.TicketNumber = workSheet.Cells[i, "A"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "B"] != null && workSheet.Cells[i, "B"].Value != null)
                    {
                        tasks.TaskId = workSheet.Cells[i, "B"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "C"] != null && workSheet.Cells[i, "C"].Value != null)
                    {
                        tasks.TaskTitle = workSheet.Cells[i, "C"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "D"] != null && workSheet.Cells[i, "D"].Value != null)
                    {
                        tasks.TaskDescription = workSheet.Cells[i, "D"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "E"] != null && workSheet.Cells[i, "E"].Value != null)
                    {
                        tasks.TaskType = workSheet.Cells[i, "E"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "F"] != null && workSheet.Cells[i, "F"].Value != null)
                    {
                        tasks.State = workSheet.Cells[i, "F"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "G"] != null && workSheet.Cells[i, "G"].Value != null)
                    {
                        tasks.Priority = workSheet.Cells[i, "G"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "H"] != null && workSheet.Cells[i, "H"].Value != null)
                    {
                        for (int j = 2; j <= rowCountemp; j++)
                        {
                            if (workSheetEmp.Cells[j, "B"] != null && workSheetEmp.Cells[j, "B"].Value != null)
                            {
                                if (workSheetEmp.Cells[j, "B"].Value.ToString() == workSheet.Cells[i, "H"].Value.ToString())
                                {
                                    tasks.AssignedTo = workSheetEmp.Cells[j, "A"].Value.ToString();
                                }
                            }
                        }
                    }
                    if (workSheet.Cells[i, "I"] != null && workSheet.Cells[i, "I"].Value != null)
                    {
                        tasks.Efforts = workSheet.Cells[i, "I"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "J"] != null && workSheet.Cells[i, "J"].Value != null)
                    {
                        tasks.PlannedStartDate = workSheet.Cells[i, "J"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "K"] != null && workSheet.Cells[i, "K"].Value != null)
                    {
                        tasks.PlannedEndDate = workSheet.Cells[i, "K"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "L"] != null && workSheet.Cells[i, "L"].Value != null)
                    {
                        tasks.ActualStartDate = workSheet.Cells[i, "L"].Value.ToString();
                    }
                    if (workSheet.Cells[i, "M"] != null && workSheet.Cells[i, "M"].Value != null)
                    {
                        tasks.ActualEndDate = workSheet.Cells[i, "M"].Value.ToString();
                    }
                    taskList.Add(tasks);
                }
                workBook.Close();
                xlApp.Quit();
                GC.Collect();
                return(taskList);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(null);
        }
        //Method to update an existing task
        public void UpdateTaskData(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dropdownState.SelectedItem.ToString() == "COMPLETED")
                {
                    if (string.IsNullOrWhiteSpace(txtASD.Text) && string.IsNullOrWhiteSpace(txtAED.Text))
                    {
                        MessageBox.Show("Please enter Actual Start and End dates");
                    }
                    else
                    {
                        ModelTask model = new ModelTask();
                        model.TicketNumber    = txtTicket.Text.ToString();
                        model.TaskId          = txtTaskId.Text.ToString();
                        model.TaskTitle       = txtTaskTitle.Text.ToString();
                        model.TaskDescription = txtTaskDesc.Text.ToString();
                        model.TaskType        = dropdownTaskType.SelectedItem.ToString();
                        model.State           = dropdownState.SelectedItem.ToString();
                        model.Priority        = dropdownPriority.SelectedItem.ToString();
                        model.AssignedTo      = id;
                        model.Efforts         = txtEfforts.Text.ToString();
                        if (txtPED.Text.ToString() != "dd/mm/yyyy" && txtPSD.Text.ToString() != "dd/mm/yyyy")
                        {
                            model.PlannedStartDate = txtPSD.Text.ToString();
                            model.PlannedEndDate   = txtPED.Text.ToString();
                        }
                        if (txtASD.Text.ToString() != "dd/mm/yyyy" && txtAED.Text.ToString() != "dd/mm/yyyy")
                        {
                            model.ActualStartDate = txtASD.Text.ToString();
                            model.ActualEndDate   = txtAED.Text.ToString();
                            helpers.UpdateTask(model);
                            MessageBox.Show("Details Updated Successfully");
                            txtTicket.Text    = "";
                            txtTaskId.Text    = "";
                            txtTaskTitle.Text = "";
                            txtTaskDesc.Text  = "";
                            txtEfforts.Text   = "";
                            txtPSD.Text       = "";
                            txtPED.Text       = "";
                            txtASD.Text       = "";
                            txtAED.Text       = "";
                            Reload();
                        }
                        else
                        {
                            MessageBox.Show("Please enter Actual Start and End Dates");
                        }
                    }
                }
                else
                {
                    ModelTask model = new ModelTask();
                    model.TicketNumber     = txtTicket.Text.ToString();
                    model.TaskId           = txtTaskId.Text.ToString();
                    model.TaskTitle        = txtTaskTitle.Text.ToString();
                    model.TaskDescription  = txtTaskDesc.Text.ToString();
                    model.TaskType         = dropdownTaskType.SelectedItem.ToString();
                    model.State            = dropdownState.SelectedItem.ToString();
                    model.Priority         = dropdownPriority.SelectedItem.ToString();
                    model.AssignedTo       = id;
                    model.Efforts          = txtEfforts.Text.ToString();
                    model.PlannedStartDate = txtPSD.Text.ToString();
                    model.PlannedEndDate   = txtPED.Text.ToString();
                    if (txtASD.Text.ToString() != "dd/mm/yyyy" && txtAED.Text.ToString() != "dd/mm/yyyy")
                    {
                        model.ActualStartDate = txtASD.Text.ToString();
                        model.ActualEndDate   = txtAED.Text.ToString();
                    }
                    else
                    {
                        model.ActualStartDate = "";
                        model.ActualEndDate   = "";
                    }
                    helpers.UpdateTask(model);
                    MessageBox.Show("Details Updated Successfully");
                    txtTicket.Text    = "";
                    txtTaskId.Text    = "";
                    txtTaskTitle.Text = "";
                    txtTaskDesc.Text  = "";

                    txtEfforts.Text = "";
                    txtPSD.Text     = "";
                    txtPED.Text     = "";
                    txtASD.Text     = "";
                    txtAED.Text     = "";
                    Reload();
                }
            }
            catch
            {
                MessageBox.Show("Something went wrong");
            }
        }