Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                if (WebApiClient.EFileNameAvailability(txtFileName.Text))
                {
                    bool   isSuccess = false;
                    string EFileCopyDirectoryPath = ConfigurationSettings.AppSettings.Get("EFileCopyDirectoryPath").ToString() + "\\" + (cbCategory.SelectedItem as ComboBoxItem).Text;
                    string FileSQLPath            = ConfigurationSettings.AppSettings.Get("EFileSQLPath").ToString() + "/" + (cbCategory.SelectedItem as ComboBoxItem).Text;

                    ElectronicFile eFile = new ElectronicFile()
                    {
                        FileName = txtFileName.Text,
                        Path     = FileSQLPath + "/" + Path.GetFileName(txtPath.Text),

                        FileType = new ElectronicFileType()
                        {
                            ElectronicFileTypeId = int.Parse((cbCategory.SelectedItem as ComboBoxItem).Value.ToString())
                        }
                    };

                    isSuccess = WebApiClient.AddElectronicFile(eFile);

                    if (isSuccess)
                    {
                        MessageBox.Show((cbCategory.SelectedItem as ComboBoxItem).Text + " has been added");
                        File.Copy(txtPath.Text, Path.Combine(EFileCopyDirectoryPath, Path.GetFileName(txtPath.Text)), true);
                    }
                }
                else
                {
                    MessageBox.Show((cbCategory.SelectedItem as ComboBoxItem).Text + " already exist by that name");
                }

                if (!this.DesignMode)
                {
                    list = GetPagedListAsync();

                    btnPrevious.Enabled          = list.HasPreviousPage;
                    btnNext.Enabled              = list.HasNextPage;
                    dgElectronicFiles.DataSource = list.Select(o => new { Name = o.FileName, Type = o.FileType.Name, Format = o.Path.Substring(o.Path.LastIndexOf('.') + 1) }).ToList();
                    lblPageCount.Text            = string.Format("Page {0}/{1}", pageNumber, list.PageCount);
                }
            }
        }