示例#1
0
 public static void Email()
 {
     if (AllIssues != "")
     {
         var errEmail = new EmailObject()
         {
             Body = "Here Are the issues:" + AllIssues,
             To = "*****@*****.**",
             Subject = "Errors Caught"
         };
         var send = new GenerateEmail(errEmail);
     }
 }
示例#2
0
 private void Execute(bool ToBeEmailed)
 {
     //runs the process to execute queries and send results
     FormDataWrite();
     lblStatus.Text = "Executing....."; lblStatus.ForeColor = Color.DarkBlue; Update();
     ErrorHandler.AllIssues = "";
     var findSql = new FindSQL(this);
     var qryNames = findSql.QryNames;
     var sqlStrings = findSql.SqlStatements;
     var outputTypes = findSql.OutputTypes;
     //looping through all found queries
     for (int i = 0; i < qryNames.Count; i++)
     {
         string qryName = qryNames[i];
         string sqlString = sqlStrings[i];
         string outputType = outputTypes[i];
         var sqlData = new RunQuery(sqlString, qryName).sqlData;
         if (sqlData.Rows.Count > 0)
         {
             var push = new PushData(sqlData, txtFilePath.Text + qryName);
             switch (outputType)
             {
                 case "Excel":
                     push.WriteToExcel();
                     AppendToList(".xlsx");
                     break;
                 case "CSV":
                     push.WriteToCsv("|");
                     AppendToList(".csv");
                     break;
                 case "Command":
                     break;
                 default:
                     push.WriteToExcel();
                     AppendToList(".xlsx");
                     break;
             }
         }
         else if (sqlData.Rows.Count <= 0)
         {
             var ex = new Exception("The query resulted in no data");
             ErrorHandler.Handle(ex);
         }
     }
     if (ToBeEmailed) //if the email is needs to be emailed run the rest of the code
     {
         var EmlObj = new EmailObject() { To = txtTo.Text, Body = txtBody.Text, CC = txtCC.Text, Subject = txtSubject.Text };
         var GenerateEmail = new GenerateEmail(EmlObj, qryNames, txtFilePath.Text);
         if (ErrorHandler.AllIssues != "")
         {
             lblStatus.ForeColor = Color.Red; lblStatus.Text = "Sending Errors!";
             Update();
             var errMail = new EmailObject()  //create error email object;
             {
                 To = txtYourEmail.Text,
                 Subject = "SQL Sender Errors",
                 Body = ErrorHandler.AllIssues,
                 CC = txtCC.Text
             };
             var mail = new GenerateEmail(errMail);
         }
     }
     lblStatus.Text = "Ready";
     lblStatus.ForeColor = Color.Black;
     Update();
 }