Пример #1
0
        //Upload_Click event handler for upload files.
        private void Upload_Click(object sender, RoutedEventArgs e)
        {
            if (da.checkMonth(WON_TEXTBOX.Text))
            {
                if (NameOfOTHER.Text.Length > 0)
                {
                    da.setOtherName(NameOfOTHER.Text);
                }
                da.setDestinationPath(WON_TEXTBOX.Text, ECN_TEXTBOX.Text, typeOfDoc, MonthOfSPR.SelectedIndex);
                validateFields();

                if (da.checkDestinationDirectory())
                {
                    if (ECN_TEXTBOX.Text.Length == 0)
                    {
                        DIAL_ANS answer = da.dialogBox("No ECN", "You didn't enter ECN, Do you want to continue?", MessageBoxButton.YesNo);
                        if (answer == DIAL_ANS.YES)
                        {
                            da.setECNFilled(true);
                        }
                        else
                        {
                            da.setECNFilled(false);
                        }
                    }
                    else
                    {
                        da.setECNFilled(true);
                    }
                    if (da.isReadyToUpload())
                    {
                        if (da.uploadFile())
                        {
                            attachmentPath.Text = da.getDestinationPath();
                            MessageBox.Show("Your file is successfully uploaded");
                            UPLOAD_BUTTON.IsEnabled = false;
                        }
                        else
                        {
                            MessageBox.Show("Upload has been cancelled");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please complete all required fields");
                    }
                }
                else
                {
                    MessageBox.Show("Please check Work Order Number or Destination Folder.");
                }
            }
            else
            {
                MessageBox.Show("Please check Work Order Number.");
            }
        }
 //uploadFile method is to validate if there is any duplications, and upload the workorder file.
 public bool uploadFile()
 {
     if (checkDestinationDirectory())
     {
         if (File.Exists(getDestinationPath()))
         {
             DIAL_ANS answer = dialogBox("Over-Writing", "File already exists, do you want to overwrite?", MessageBoxButton.YesNoCancel);
             if (answer == DIAL_ANS.YES)
             {
                 File.Copy(getSourcePath(), getDestinationPath(), true);
                 return(true);
             }
             else if (answer == DIAL_ANS.NO)
             {
                 int    nextNumber         = 1;
                 string newDestinationPath = getDestinationPath();
                 newDestinationPath = newDestinationPath.Substring(0, newDestinationPath.LastIndexOf("."));
                 while (File.Exists(newDestinationPath + ".pdf"))
                 {
                     if (newDestinationPath.EndsWith(")"))
                     {
                         newDestinationPath = newDestinationPath.Substring(0, newDestinationPath.LastIndexOf("("));
                     }
                     newDestinationPath = newDestinationPath + "(" + nextNumber++ + ")";
                 }
                 File.Copy(getSourcePath(), newDestinationPath + ".pdf", false);
                 setDestinationPath(newDestinationPath);
                 return(true);
             }
         }
         else
         {
             File.Copy(getSourcePath(), getDestinationPath(), false);
             return(true);
         }
     }
     else
     {
         MessageBox.Show("Destination Folder does not exist.");
     }
     return(false);
 }