Error 1053: Please give the solution for the following code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Threading;
namespace ServiceCIS
{
public partial class Service1 : ServiceBase
{
private String MotherFirstName = null;
private string FatherFirstName = null;
private string MotherEmailId = null;
private string FatherEmailId = null;
private string SampleCode = null;
private string CustomerCode = null;
private int DueAmount = 0;
private int InvoiceAmount = 0;
private String Date_BeforeOneMonth;
private DateTime DDate_BeforeOneMonth;
private String Date_BeforeOneWeek;
private DateTime DDate_BeforeOneWeek;
private String Date_DueDate;
private string Date_OTPBOW;
private DateTime Ddate;
private string PaymentStatus = null;
private string Mgr_EmailId = null;
private Boolean Flag_BeforeOneMonth;
private Boolean Flag_BeforeOneWeek;
private Boolean Flag_OnDueDate;
private String CurrentDate = DateTime.Today.ToShortDateString();
private DateTime CDate = DateTime.Today.Date;
private DateTime Date_OTPBOWD;
private string InvoiceType = null;
private string date1;
private string date2;
private DateTime Date_ODRBOW;
private DateTime Date_OverDueReminder;
private DateTime DateOfTermination;
private string StringDateOfTermination;
private Boolean Flag_TOS;
private string CustomerStatus;
private DateTime Date_RenewalOfTerm;
private string Accounant_Email_IAF;
private DateTime InvoiceAlertDate_IAF;
private string PaymentStatus_IAF;
private string SampleCode_IAF;
private string SampleCode_PDCAlert = null;
private int Chequeno_PDCAlert;
private int ChequeAmount_PDCAlert;
private string ChequeStatus_PDCAlert = null;
private string Reason_PDCAlert = null;
private string MotherName_PDCAlert = null;
private string FatherName_PDCAlert = null;
private string MotherEmailId_PDCAlert = null;
private string FatherEmailId_PDCAlert = null;
private DateTime ChequeDate_PDCAlert;
private DateTime Cheque_Date_BOD_PDCAlert;
private string Cheque_BankName_PDCAlert = null;
private string Accountant_EmailId_PDCAlert = null;
private bool Flag_Clearance;
private bool Flag_Honoured;
private bool Flag_Dishonoured;


Service1 obj = new Service1();

public static DataTable Execute(String strsql)
{
SqlConnection obj = new SqlConnection("Data Source=.;initial catalog=Db_CIS1;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter(strsql, obj);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
public static void Update(string strsql)
{
SqlConnection obj = new SqlConnection("Data Source=.;Initial Catalog=Db_CIS1;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter(strsql, obj);
DataSet ds = new DataSet();
sda.Fill(ds);
}

public void SendEmail_InvoiceAlert_Accountant(string Message)
{
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("cskpl.ssm@gmail.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential("cskpl.ssm@gmail.com", "ssm@cskpl"); // [4] Added this. Note, first parameter is NOT string.
smtp.Host = "smtp.gmail.com";
//mail.To.Add(new MailAddress("sagar.m@polyclonebio.com"));
mail.To.Add(new MailAddress(Accounant_Email_IAF));
mail.IsBodyHtml = true;
mail.Body = Message;
smtp.Send(mail);

}

public Service1()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("EmailSource"))
{
System.Diagnostics.EventLog.CreateEventSource("EmailSource", "EmailLog");
}
eventLogEmail.Source = "EmailSource";
eventLogEmail.Log = "EmailLog";
}

protected override void OnStart(string[] args)
{
Thread t = new Thread(new ThreadStart(SomeTask));
}
private void SomeTask()
{
string QueryForInvoiceAlert = "select * from InvoiceAlert_Accountant";
string QueryForEmailID_Accountant = "select EmailID,EmpFirstName from EmployeeDetails where EmpType=Accountant";
DataTable dt2 = Service1.Execute(QueryForInvoiceAlert);
string test1 = "check date" + CDate;
System.IO.File.WriteAllText(@"F:PolycloneCheck1.txt", test1);
foreach (System.Data.DataRow r in dt2.Rows)
{
InvoiceAlertDate_IAF = Convert.ToDateTime(r["Date_InvoiceAlert"]);
string test = "check date" + InvoiceAlertDate_IAF+CDate;
System.IO.File.WriteAllText(@"F:PolycloneCheck2.txt", test);
SampleCode_IAF = r["SampleCode"].ToString();
if (InvoiceAlertDate_IAF == CDate)
{
DataTable dt3 = Service1.Execute(QueryForEmailID_Accountant);
foreach (System.Data.DataRow row1 in dt3.Rows)
{
Accounant_Email_IAF = row1["EmailID"].ToString();
string Accountant_FirstName = row1["EmpFirstName"].ToString();
string st = "<html><body>" +
"Date : " + CurrentDate + "</br> REMINDER NOTICE:</br> " +
"Dear" +Accountant_FirstName+",</br> Please generate invoice for the sample"+SampleCode_IAF;
obj.SendEmail_InvoiceAlert_Accountant(st);

}
}

}
}


protected override void OnStop()
{
EventLog.WriteEntry("My Simple Service Stopped");
}
}
}

View the full article
 
Back
Top