public string Send_Emergency_sms(string Phone, DataTable da) { try { string str = "התגלו חוסרים בעובדים במהלך קביעת סידור העבודה. אנא התחבר לאתר בדחיפות"; SMS_Message sm = new SMS_Message(Phone, da.Rows[0]["Phone"].ToString().Replace("-", ""), str); if (sms_left > 0) { if (sm.Check_Message()) { if (!sm.Send()) { return("bgcolor='#FF7777' align='center'>נכשל(שגיאה)"); } sms_left--; sms_list.Add(sm); } else { return("bgcolor='#FF7777' align='center'>נכשל(לא חוקי)"); } } else { return("bgcolor='#FF7777' align='center'>נכשל(אין הודעות)"); } return("bgcolor='#99FF99' align='center' >נשלח"); //sucsses } catch (Exception) { return("bgcolor='#FF7777' align='center'>נכשל");//fail } }
public bool SendMessage(SMS_Message Message, SMS_Config SMSConfig, List <SMS_ConfigParam> SMSParams, out int smsResponseNumber) { bool success = false; CompilationSection compilationSection = (CompilationSection)System.Configuration.ConfigurationManager.GetSection(@"system.web/compilation"); try { if (!compilationSection.Debug) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(SMSConfig.Url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; string postData = string.Empty; List <string> postDataParams = new List <string>(); // "mobile=" + SMSConfig.UserName + "&password="******"&numbers=" + Message.PhoneNumber + "&sender=" + SMSConfig.SenderName + "&msg=" + ConvertToUnicode(Message.TextMessage) + "&applicationType=59"; foreach (var param in SMSParams.Where(p => p.IsStatic == true)) { postDataParams.Add(param.Key + "=" + param.Value); } postData = string.Join("&", postDataParams); postData += "&" + SMSConfig.MessageParamName + "=" + ConvertToUnicode(Message.TextMessage); postData += "&" + SMSConfig.NumberParamName + "=" + Message.PhoneNumber; req.ContentLength = postData.Length; StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(postData); stOut.Close(); // Do the request to get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); //var ou = stIn.ReadToEnd(); //var t = ou; smsResponseNumber = Int32.Parse(stIn.ReadToEnd()); stIn.Close(); if (smsResponseNumber == SMSConfig.SuccessResponseNumber) { success = true; } } else { smsResponseNumber = 0; } } catch (Exception) { smsResponseNumber = 0; //_SMSMessageRepository.Save(Message); //_unitOfWork.Submit(); } return(success); }
public static App.CustomModels.SendSmsStatus SendSms(String telephoneNumber, String messageText) { String userName = ConfigReader.TextAnywhereClientID; String password = ConfigReader.TextAnywhereClientPassword; String[] serviceReplyArray = null; String serviceReply = String.Empty; ///Create the Web Service Object for Sending SMS _SmsService = new SMSService.TextAnywhere_SMS(); if (IsSmsServiceRunning()) { if (ConfigReader.SendSmsToClient) { OMMDataContext context = new OMMDataContext(); SMS_Message smsMessageRef = context.dalSMSMessagesInsert(String.Empty, DateTime.Now).SingleOrDefault(); //SMSService.TextAnywhere_SMS smsService = new SMSService.TextAnywhere_SMS(); serviceReply = _SmsService.SendSMSEx(userName, password, smsMessageRef.Client_Ref, ConfigReader.BILLING_REF, (int)CONNECTION_TYPES.LOW_VOLUME, ConfigReader.ORIGINATOR, (int)ORIGINATOR_TYPES.NAME, telephoneNumber, messageText, 0, (int)REPLY_TYPES.NONE, String.Empty); } // Extract return codes serviceReplyArray = serviceReply.Split(COMMA_SEPARATOR); if (serviceReplyArray.Length != 1) //receivers.Count) { _ErrorMessage = "Unable to send SMS message. SMS Service did not return the expected response."; } } App.CustomModels.SendSmsStatus reply = new App.CustomModels.SendSmsStatus(); if (String.IsNullOrEmpty(_ErrorMessage)) { reply.StatusID = 1; reply.Message = telephoneNumber; } else { reply.StatusID = -1; reply.Message = _ErrorMessage; } return(reply); }
protected void Button1_Click(object sender, EventArgs e) { SMS_Message ss = new SMS_Message(TextBox2.Text, TextBox1.Text, TextBox3.Text); if (ss.Check_Message()) { if (ss.Send()) { Label1.Text = "ההודעה נשלחה בהצלחה"; ADO.ExecuteNonQuery("Update Options Set Num_Of_SMS=" + (int.Parse(ADO.GetFullTable("Options", "ID=29").Rows[0]["Num_Of_SMS"].ToString()) - 1) + " Where ID=29"); } else { Label1.Text = "שליחת ההודעה נכשלה"; } } else { Label1.Text = "הודעה לא תקינה"; } }
public int InsertNewMessage(string PhoneNumber, string TxtMessage) { var _EntitiesContext = new QVMobileApplicationEntities(); SMS_Message MessageObj = new SMS_Message(); MessageObj.PhoneNumber = PhoneNumber; MessageObj.TextMessage = TxtMessage; MessageObj.IsSent = false; MessageObj.CreationDate = DateTime.Now; _EntitiesContext.SMS_Message.Add(MessageObj); var ret = _EntitiesContext.SaveChanges(); if (ret > 0) { return(MessageObj.ID); } else { return(0); } }
public string Send_Shifts_sms(string Phone, string Worker_Name, DataTable da) { try { string str = Get_Shifts_String(Worker_Name); if (str.Length == 6) { return("bgcolor='#FF7777' align='center'>נכשל(אין משמרות)"); // no shifts } if (str.Length > 70) { //Split_Messages List <SMS_Message> msgs = new List <SMS_Message>(); string str2 = ""; while (str.Length > 70) { str2 = str.Substring(0, 70); while (str2[str2.Length - 1] != '<') { str2 = str2.Remove(str2.Length - 1, 1); } str2 = str2.Remove(str2.Length - 1, 1); msgs.Add(new SMS_Message(Phone, da.Rows[0]["Phone"].ToString().Replace("-", ""), str2)); str = str.Replace(str2, ""); str = str.Remove(str.Length - 4, 4); } SMS_Message sm = new SMS_Message(Phone, da.Rows[0]["Phone"].ToString().Replace("-", ""), str); if (sms_left > 0) { if (sm.Check_Message()) { if (!sm.Send()) { return("bgcolor='#FF7777' align='center'>נכשל(שגיאה)"); } sms_left--; sms_list.Add(sm); } else { return("bgcolor='#FF7777' align='center'>נכשל(לא חוקי)"); } } else { return("bgcolor='#FF7777' align='center'>נכשל(אין הודעות)"); } if (sms_left >= msgs.Count) { foreach (SMS_Message ss in msgs) { if (ss.Check_Message()) { if (!ss.Send()) { return("bgcolor='#FF7777' align='center'>נכשל(שגיאה)"); } sms_left--; sms_list.Add(ss); } else { return("bgcolor='#FF7777' align='center'>נכשל(לא חוקי)"); } } } else { return("bgcolor='#FF7777' align='center'>נכשל(אין הודעות)"); } return("bgcolor='#99FF99' align='center' >נשלח(" + (msgs.Count + 1) + " הודעות)");//sucsses } else { SMS_Message sm = new SMS_Message(Phone, da.Rows[0]["Phone"].ToString().Replace("-", ""), str); if (sms_left > 0) { if (sm.Check_Message()) { if (!sm.Send()) { return("bgcolor='#FF7777' align='center'>נכשל(שגיאה)"); } sms_left--; sms_list.Add(sm); } else { return("bgcolor='#FF7777' align='center'>נכשל(לא חוקי)"); } } else { return("bgcolor='#FF7777' align='center'>נכשל(אין הודעות)"); } return("bgcolor='#99FF99' align='center' >נשלח");//sucsses } } catch (Exception) { return("bgcolor='#FF7777' align='center'>נכשל");//fail } }
private static bool SendFinalMessage(Message message, IList <TelephoneNumber> receivers) { //String BILLING_REF = ConfigReader.BILLING_REF; //String ORIGINATOR = ConfigReader.ORIGINATOR; ///Generate a New Message Reference by Executing a Stored Procedure (dalSMSMessagesInsert) as in Win App. ///[Note: Don't Know Why We are Doing This] SMS_Message smsMessageRef = _DataContext.dalSMSMessagesInsert(String.Empty, DateTime.Now).SingleOrDefault(); String userName = ConfigReader.TextAnywhereClientID; String password = ConfigReader.TextAnywhereClientPassword; String[] WSSendSMSReplyArray = null; String WSSendSmsReply = String.Empty; //String[] returnCodePair = null; System.Text.StringBuilder sb = new System.Text.StringBuilder(10); // Check recipients list not empty if (receivers.Count <= 0) { return(false); } // Check SMS Service is running if (!IsSmsServiceRunning()) { return(false); } // Build Comma Separated destination number list foreach (TelephoneNumber mrr in receivers) { if (sb.Length > 0) { sb.Append(COMMA_SEPARATOR); } sb.Append(mrr.Number); } if (ConfigReader.SendSmsToClient) { //SMSService.TextAnywhere_SMS smsService = new SMSService.TextAnywhere_SMS(); WSSendSmsReply = _SmsService.SendSMSEx(userName, password, smsMessageRef.Client_Ref, ConfigReader.BILLING_REF, (int)CONNECTION_TYPES.LOW_VOLUME, ConfigReader.ORIGINATOR, (int)ORIGINATOR_TYPES.NAME, sb.ToString(), message.Text, 0, (int)REPLY_TYPES.NONE, String.Empty); } // Extract return codes WSSendSMSReplyArray = WSSendSmsReply.Split(COMMA_SEPARATOR); if (WSSendSMSReplyArray.Length != receivers.Count) { _ErrorMessage = "Unable to send SMS message. SMS Service did not return the expected response."; return(false); } else { ///After Successfully Sending Message Set Message status to delivered message.Delivered = true; _DataContext.SubmitChanges(); } return(true); }