private List<String> Import(string file, out ExcelAccountSettings result)
 {
     IAccountSettings setingForTest;
     ExcelAccountSettings testAcc = new ExcelAccountSettings();
     Byte[] fileInByteArray = testAcc.OpenExcelFileAndReturnByteArray(new AuthorizationResult(true, loggedUser), file);
     if (fileInByteArray == null)
     {
         result = null;
         return null;
     }
     SettingsManager.AccountSettingsTest(testAcc, fileInByteArray, out setingForTest);
     if (setingForTest != null)
     {
         ExcelAccountSettings resultFromServices = (ExcelAccountSettings)setingForTest;
         ExcelAccountTemplate template = new ExcelAccountTemplate();
         template = resultFromServices.Template.FirstOrDefault();
         result = (ExcelAccountSettings)setingForTest;
         return template.AllFieldsInFile;
     }
     result = null; ;
     return null;
 }
        private void FillDataGridWithExistingMapping()
        {
            Dictionary<String, String> templateMapping = new Dictionary<String, String>();
            ExcelAccountTemplate template = userExcelFullAccount.Template.FirstOrDefault();
            if (template == null)
            {
                template = new ExcelAccountTemplate();
                FillDataGridWithEmptyMapping(template.AllFieldsInTeemplate);
                return;
            }

            templateMapping = userExcelFullAccount.Template.FirstOrDefault().Mapping;
            List<string> field = templateMapping.Values.Select(value => value).Where(str => !String.IsNullOrEmpty(str)).ToList();

            for (int i = 0; i < templateMapping.Count; i++)
            {
                if (dataGrid_mapping.Rows.Count < templateMapping.Count)
                {
                    dataGrid_mapping.Rows.Add();
                }
                DataGridViewTextBoxCell Cell_Template =
                        (DataGridViewTextBoxCell)dataGrid_mapping.Rows[i].Cells[1];
                Cell_Template.Value = templateMapping.ElementAt(i).Key;

                if (templateMapping.Count > 0)
                {
                    DataGridViewComboBoxCell comboCell_ITask = (DataGridViewComboBoxCell)dataGrid_mapping.Rows[i].Cells[0];
                    comboCell_ITask.DataSource = field;
                    comboCell_ITask.Value = templateMapping.ElementAt(i).Value;
                }
                else
                {
                    DataGridViewComboBoxCell comboCell_ITask = (DataGridViewComboBoxCell)dataGrid_mapping.Rows[i].Cells[0];
                    comboCell_ITask.DataSource = field;
                    comboCell_ITask.Value = "";

                }
            }
        }
        private ExcelAccountTemplate Acc_ExcelMapping()
        {
            ExcelAccountTemplate accEx_template;
            if (userExcelFullAccount.Template.Count > 0)
            {
                accEx_template = userExcelFullAccount.Template.FirstOrDefault();
            }
            else
            {
                accEx_template = new ExcelAccountTemplate();
            }

            for (int i = 0; i < dataGrid_mapping.Rows.Count - 1; i++)
            {
                DataGridViewComboBoxCell comboCell_file =
                        (DataGridViewComboBoxCell)dataGrid_mapping.Rows[i].Cells[0];
                DataGridViewTextBoxCell combotxtCell =
                       (DataGridViewTextBoxCell)dataGrid_mapping.Rows[i].Cells[1];
                String cellValue = comboCell_file.Value.ToString();
                String fieldValue = combotxtCell.Value.ToString();
                cellValue = cellValue ?? "";

                if (fieldValue == "TaskID")
                {
                    accEx_template.TaskID = cellValue;
                    continue;
                }
                if (fieldValue == "SubtaskType")
                {
                    accEx_template.SubtaskType = cellValue;
                    continue;
                }
                if (fieldValue == "Summary")
                {
                    accEx_template.Summary = cellValue;
                    continue;
                }
                if (fieldValue == "Description")
                {
                    accEx_template.Description = cellValue;
                    continue;
                }
                if (fieldValue == "Status")
                {
                    accEx_template.Status = cellValue;
                    continue;
                }
                if (fieldValue == "Priority")
                {
                    accEx_template.Priority = cellValue;
                    continue;
                }
                if (fieldValue == "Project")
                {
                    accEx_template.Project = cellValue;
                    continue;
                }
                if (fieldValue == "CreatedDate")
                {
                    accEx_template.CreatedDate = cellValue;
                    continue;
                }
                if (fieldValue == "CreatedBy")
                {
                    accEx_template.CreatedBy = cellValue;
                    continue;
                }
                if (fieldValue == "LinkToTracker")
                {
                    accEx_template.LinkToTracker = cellValue;
                    continue;
                }
                if (fieldValue == "Source")
                {
                    accEx_template.Source = Sources.Excel;
                    continue;
                }
                if (fieldValue == "Estimation")
                {
                    accEx_template.Estimation = cellValue;
                    continue;
                }
                if (fieldValue == "TargetVersion")
                {
                    accEx_template.TargetVersion = cellValue;
                    continue;
                }
                if (fieldValue == "Comments")
                {
                    accEx_template.Comments = cellValue;
                    continue;
                }
                if (fieldValue == "TaskParent")
                {
                    accEx_template.TaskParent = cellValue;
                    continue;
                }
                if (fieldValue == "Assigned")
                {
                    accEx_template.Assigned = cellValue;
                    continue;
                }
            }
            return accEx_template;
        }
        private void btnSaveSettings_Click(object sender, EventArgs e)
        {
            if (txtNewTemplateName.Text.Trim() != String.Empty && rtxtMapping.Text.Trim() != String.Empty)
            {
                ExcelAccountTemplate accEx_template = new ExcelAccountTemplate();

                accEx_template = Acc_ExcelMapping();
                accEx_template.TemplateName = txtNewTemplateName.Text.Trim();
                userExcelFullAccount.Template.Add(accEx_template);
                if (SettingsManager.SaveOrUpdateAccount(userExcelFullAccount))
                {
                    ExcelSynchronizer.UpdateWatchibleFiles();
                    ExcelTab.SelectTab(Settings);
                    RefreshMapSetting();
                    btn_AddNewExcelTemplate.Enabled = false;
                    btn_delete_template.Enabled = true;

                    dataGrid_mapping.RowCount = 1;
                    dataGrid_mapping.Rows[0].Visible = true;  //не обязательно (если в datagridview не скрывается срока)
                    for (int i = 0; i < dataGrid_mapping.ColumnCount; i++)
                    {
                        dataGrid_mapping[i, 0].Value = null;
                    }
                }
            }
            else
            {
                label5.Show();
                label5.Text = "Please enter token name and mapping!";
                label5.ForeColor = Color.Red;
            }
        }
        private void btnChekMapping_Click(object sender, EventArgs e)
        {
            IAccountSettings testAccRessult;
            ExcelAccountSettings testAcc = new ExcelAccountSettings();
            ExcelAccountTemplate accEx_template = new ExcelAccountTemplate();

            accEx_template = Acc_ExcelMapping();
            accEx_template.TemplateName = txtNewTemplateName.Text.Trim();

            testAcc.Template.Add(accEx_template);
            if (SettingsManager.AccountSettingsTest(testAcc, testAcc.OpenExcelFileAndReturnByteArray(new AuthorizationResult(true, loggedUser),
                cmbTokens.SelectedItem.ToString()), out testAccRessult))
            {
                btnSaveSettings.Enabled = true;
                label5.Hide();
            }
            else
            {
                btnSaveSettings.Enabled = false;
                label5.Show();
                label5.Text = "Cant read from file!";
                label5.ForeColor = Color.Red;
            }
        }
Example #6
0
        public IAccountSettings TestAccount(IAccountSettings testAccount)
        {
            currentAccount = (ExcelAccountSettings)testAccount;

            if (currentAccount.Template.Count > 0)
            {
                currentAccount.TestResult = TryReadTasksFromFile();
                return currentAccount;
            }
            else
            {
                ExcelAccountTemplate newTemplate = new ExcelAccountTemplate();
                newTemplate.AllFieldsInFile = GetAllColumnsName(OpenExcelFromByteArray());

                if (newTemplate.AllFieldsInFile.Count > 0)
                {
                    currentAccount.TestResult = true;
                    currentAccount.Template.Add(newTemplate);
                }
                else
                {
                    currentAccount.TestResult = false;
                }

                return currentAccount;
            }
        }