Beispiel #1
0
        private void TsbtnLoadTemplates_Click(object sender, EventArgs e)
        {
            if (TxtDirectoryPath.TextLength == 0)
            {
                FbdDirectory.RootFolder   = Environment.SpecialFolder.MyComputer;
                FbdDirectory.SelectedPath = TxtDirectoryPath.Text;
                DialogResult result = FbdDirectory.ShowDialog();
                if (result == DialogResult.OK)
                {
                    TxtDirectoryPath.Text = FbdDirectory.SelectedPath + "\\";
                }
            }

            if (TxtDirectoryPath.TextLength > 0)
            {
                TsprgbLoadUpdate.Value = TsprgbLoadUpdate.Maximum;
                TsprgbLoadUpdate.Value = 25;
                TsprgbLoadUpdate.Value = TsprgbLoadUpdate.Maximum / 2;

                if (!string.IsNullOrEmpty(TxtDirectoryPath.Text) && Directory.Exists(TxtDirectoryPath.Text))
                {
                    BsCrmTemplates         = _bindingSourceService.LoadCrmTemplatesToBindingSource(BsCrmTemplates);
                    TsprgbLoadUpdate.Value = TsprgbLoadUpdate.Maximum;
                    ResetProgressBar(3500);
                    ShowInfoNote("Loading completed!");
                }
                else
                {
                    ShowErrorNote(MySettings.DirectoryErrorText);
                    TxtDirectoryPath.Focus();
                    TsprgbLoadUpdate.Value = 0;
                    //ResetProgressBar(3500);
                }
            }
        }
Beispiel #2
0
        private void btnSvDisk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(TxtDirectoryPath.Text) && Directory.Exists(TxtDirectoryPath.Text))
            {
                if (DgvCrmDocumentTemplates.SelectedRows.Count > 0)
                {
                    var stepSize = Convert.ToInt32((100 / DgvCrmDocumentTemplates.SelectedRows.Count));
                    TsprgbLoadUpdate.Value = 0;

                    //BsDocumentTemplateObject.Clear();
                    var selectedRows = DgvCrmDocumentTemplates.SelectedRows;
                    var list         = new List <DocumentTemplateModel>();

                    //create List of DgvDocumentTemplate names
                    List <List <String> > DgvDocumentTemplateNamesList = new List <List <String> >();
                    foreach (DataGridViewRow row in DgvDocumentTemplates.Rows)
                    {
                        DgvDocumentTemplateNamesList.Add(new List <string>()
                        {
                            row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString()
                        });
                    }

                    for (int i = selectedRows.Count - 1; i >= 0; i--)
                    {
                        var template = (DocumentTemplateModel)DgvCrmDocumentTemplates.SelectedRows[i].DataBoundItem;

                        if (DgvDocumentTemplateNamesList.Count > 0)
                        {
                            Boolean check = true;
                            foreach (List <String> listValue in DgvDocumentTemplateNamesList)
                            {
                                if (listValue.SequenceEqual(new List <String>()
                                {
                                    DgvCrmDocumentTemplates.SelectedRows[i].Cells[0].Value.ToString(), DgvCrmDocumentTemplates.SelectedRows[i].Cells[1].Value.ToString()
                                }))
                                {
                                    check = false;
                                }
                            }
                            if (check)
                            {
                                list.Add(template);
                                BsDocumentTemplateObject.Add(template);
                                TsprgbLoadUpdate.Value += stepSize;
                            }
                        }
                        else
                        {
                            list.Add(template);
                            BsDocumentTemplateObject.Add(template);
                            TsprgbLoadUpdate.Value += stepSize;
                        }
                    }

                    foreach (var t in list)
                    {
                        try
                        {
                            _fileOperationService.SaveFileToDisk(t);
                        }
                        catch (InvalidDirectoryException)
                        {
                            ShowErrorNote(MySettings.DirectoryErrorText);
                        }
                    }
                    TsprgbLoadUpdate.Value = TsprgbLoadUpdate.Maximum;
                    ResetProgressBar(3500);

                    //TabCtrlDocumentTemplate.SelectTab(TabDocumentTemplate);
                    TabCtrlDocumentTemplate.SelectTab(TabCrmDocumentTemplates);
                    ShowInfoNote("Save complete!");

                    //foreach (DataGridViewRow row in DgvDocumentTemplates.Rows)
                    //{
                    //    if (row.Cells["NameDataGridViewTextBoxColumn3"].Value != null)
                    //    {
                    //        row.Cells["NameDataGridViewTextBoxColumn3"].ReadOnly = true;
                    //    }
                    //    else
                    //    {
                    //        row.Cells["NameDataGridViewTextBoxColumn3"].ReadOnly = false;
                    //    }
                    //}
                }
                else // SelectedRowCount = 0
                {
                    ShowInfoNote("No templates selected!");
                }
            }
            else // txtDirectoryPath.Text == null or empty && directory exists
            {
                ShowErrorNote(MySettings.DirectoryErrorText);
                TxtDirectoryPath.Focus();
            }
        }