コード例 #1
0
        private void TabCtrlDocumentTemplate_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPage.Name == TabCrmDocumentTemplates.Name)
            {
                SetButtonLayoutTabCrmDocumentTemplates();
            }

            if (e.TabPage.Name == TabCrmDocumentTemplates.Name)
            {
                if (string.IsNullOrEmpty(TxtDirectoryPath.Text))
                {
                    ShowErrorNote(MySettings.DirectoryErrorText);
                    TabCtrlDocumentTemplate.SelectTab(TabCrmDocumentTemplates);
                }
                else
                {
                    SetButtonLayoutTabDocumentTemplate();
                }
            }
        }
コード例 #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();
            }
        }