public override void Execute() { int intervalMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["IntervalMinutes"].ToString()); string FileOutPut = ConfigurationManager.AppSettings["FileOutPut"].ToString(); //string userName = ConfigurationManager.AppSettings["SmsUserName"]; //string password = ConfigurationManager.AppSettings["SmsPassword"]; //log4net.Config.XmlConfigurator.Configure(); string userName = ConfigurationManager.AppSettings["SmsUserName"]; string password = ConfigurationManager.AppSettings["SmsPassword"]; SendSMS sendSMS = new SendSMS(userName, password); while (true) { try { if (Ultility.CheckConnectionSQL()) { Ultility.syncSentCash(sendSMS); Ultility.LogFile("-----------", FileOutPut); Thread.Sleep(intervalMinutes * 1000 * 60); // start continue after intervalMinutes } else { Thread.Sleep(2 * 1000 * 60); // nếu không connect được SQL thì nghỉ 2 phút, sau đó connect lại } } catch (Exception ex) { Ultility.LogFile("----- Begin Sending SMS ----- Stop services: " + ex.Message, FileOutPut); break; } } }
public static void syncSentCash(SendSMS sendSMS) { //sendSMS.SendSPAM("0909070481", "test gui tin nhan cash 1"); IRepository<VFS_CheckSMSSent> repoVFS_CheckSMSSent = new VFS_CheckSMSSentRepository(); VFS_CheckSMSSent VFS_CheckSMSSent = new VFS_CheckSMSSent(); VFS_TransactionDayRepository repoVFS_VFS_TransactionDay = new VFS_TransactionDayRepository(); IList<VFS_TransactionDay> listVFS_VFS_TransactionDay = repoVFS_VFS_TransactionDay.listTransactionDayFromSP(); if (listVFS_VFS_TransactionDay == null) // nếu bút toán ngoại bảng ngày hiện tại không có dữ liệu, tức là đã tạo ngày mới // và lúc này xóa đi dữ liệu cho việc gửi tin { // xóa tin nhan da gui cho ngay moi repoVFS_CheckSMSSent.Delete(VFS_CheckSMSSent); // delete all data in VFS_CheckSMSSent LogFile("Delete for new day", FileOutPut); return; } foreach (var item in listVFS_VFS_TransactionDay) { if (item.CorAccount.Substring(0, 3) == "112") // nop rut tien tai khoan 112 { if (item.Debit == "C") { if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "Nop tien: " + string.Format("{0,0:N0}", item.CreditAmount) + " vao tai khoan " + item.AccountId); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "Nop tien: " + string.Format("{0,0:N0}", item.CreditAmount) + " vao tai khoan " + item.AccountId, FileOutPut); } } else { //send sms rut 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "Rut tien: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "Rut tien: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId, FileOutPut); } } } // nop rut qua trung gian if (item.CorAccount == "3388110005") // rut qua Trading Online { //send sms rut 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "Rut tien qua Trading Online: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "Rut tien qua Trading Online: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId, FileOutPut); } } if (item.CorAccount == "1362110002" || item.CorAccount == "3362110002") // KH nop o HCM <=> HN { if (item.Debit == "D") { //send sms nop 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "KH rut: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "KH rut: " + string.Format("{0,0:N0}", item.DebitAmount) + " tu tai khoan " + item.AccountId, FileOutPut); } } else { //send sms nop 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "KH nop: " + string.Format("{0,0:N0}", item.CreditAmount) + " vao tai khoan " + item.AccountId); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "KH nop: " + string.Format("{0,0:N0}", item.CreditAmount) + " vao tai khoan " + item.AccountId, FileOutPut); } } } // chuyen khoan qua lai tai khoan Cash <=> margin if (item.CorAccount.Substring(0, 3) == "094" && (item.CorAccount.Substring(4, 6) != item.AccountId.Substring(4, 6))) // nop rut tien tai khoan 112 { if (item.Debit == "D") { //send sms rut 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "Da chuyen so tien: " + string.Format("{0,0:N0}", item.DebitAmount) + " cho tai khoan " + item.CorAccount); } LogFile(numbermobile + "----- Begin Sending SMS -----" + "Da chuyen so tien: " + string.Format("{0,0:N0}", item.DebitAmount) + " cho tai khoan " + item.CorAccount, FileOutPut); } } else { //send sms nop 112 if (checkSendSMS(item.Id)) { string numbermobile = getMobileCustomer(item.AccountId.Replace("K", "C")); if (numbermobile.Length <= 11) { //send sms sendSMS.SendSPAM(numbermobile, "Nhan tien tu tai khoan: " + item.CorAccount + " so tien: " + string.Format("{0,0:N0}", item.CreditAmount)); } LogFile(getMobileCustomer(item.AccountId.Replace("K", "C")) + "----- Begin Sending SMS -----" + "Nhan tien tu tai khoan: " + item.CorAccount + " so tien:" + string.Format("{0,0:N0}", item.CreditAmount), FileOutPut); } } } } }