static public void SendSms(string smsnumber, string smsmsg) { StatMailing theMailing = new StatMailing(); theMailing.Name_task = "ARMSMS_" + smsnumber; theMailing.Msg = smsmsg; theMailing.SmsList = smsnumber; theMailing.TypeID = 3; // 3 - Уведомления theMailing.Save(); return; }
// Создает рассылку для списка телефонов, разделенных запятой public uint AddWithSmsList(StatMailing theMailing) { DBConnection conn = new DBConnection(); try { conn.Open(); OracleDataAdapter DataAdapter = new OracleDataAdapter(); OracleCommand Command = new OracleCommand(); Command.Connection = conn.Connection; Command.CommandText = "PKG_WEB.add_task"; Command.CommandType = System.Data.CommandType.StoredProcedure; OracleTransaction Transaction; Transaction = conn.Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); Command.Transaction = Transaction; OracleParameter p_name = new OracleParameter("name_", OracleType.VarChar, theMailing.Name_task.Length); p_name.Direction = ParameterDirection.Input; p_name.Value = theMailing.Name_task; Command.Parameters.Add(p_name); OracleParameter p_type = new OracleParameter("type_", OracleType.Int32, 4); p_type.Direction = ParameterDirection.Input; p_type.Value = theMailing.TypeID; Command.Parameters.Add(p_type); OracleParameter p_user = new OracleParameter("user_id_", OracleType.Int32, 4); p_user.Direction = ParameterDirection.Input; p_user.Value = UserModel.CurrentUserId; Command.Parameters.Add(p_user); OracleParameter p_out = new OracleParameter("RETURN_VALUE", OracleType.Int32); p_out.Direction = ParameterDirection.ReturnValue; Command.Parameters.Add(p_out); try { Command.ExecuteNonQuery(); } catch (Exception ex) { Transaction.Rollback(); throw new Exception(ex.Message.ToString()); } OracleCommand CommandAddSms = new OracleCommand(); CommandAddSms.Transaction = Transaction; CommandAddSms.Connection = conn.Connection; CommandAddSms.CommandText = "PKG_WEB.add_to_task"; CommandAddSms.CommandType = System.Data.CommandType.StoredProcedure; OracleParameter p_phone2 = new OracleParameter("phone_", OracleType.VarChar, 20); p_phone2.Direction = ParameterDirection.Input; CommandAddSms.Parameters.Add(p_phone2); OracleParameter p_text2 = new OracleParameter("text_", OracleType.VarChar, theMailing.Msg.Length); p_text2.Direction = ParameterDirection.Input; p_text2.Value = theMailing.Msg; CommandAddSms.Parameters.Add(p_text2); OracleParameter p_task2 = new OracleParameter("task_id", OracleType.Int32, 4); p_task2.Direction = ParameterDirection.Input; p_task2.Value = p_out.Value; CommandAddSms.Parameters.Add(p_task2); OracleParameter p_user2 = new OracleParameter("user_id_", OracleType.Int32, 4); p_user2.Direction = ParameterDirection.Input; p_user2.Value = UserModel.CurrentUserId; CommandAddSms.Parameters.Add(p_user2); OracleParameter p_started = new OracleParameter("started_", OracleType.DateTime, 4); p_started.Direction = ParameterDirection.Input; p_started.Value = theMailing.Started; CommandAddSms.Parameters.Add(p_started); OracleParameter p_out2 = new OracleParameter("RETURN_VALUE", OracleType.Int32); p_out2.Direction = ParameterDirection.ReturnValue; CommandAddSms.Parameters.Add(p_out2); try { theMailing.SmsList = theMailing.SmsList.Replace(',', ';'); string[] words = theMailing.SmsList.Split(';'); foreach (string word in words) { if (word.Length == 0) { continue; } SendEmailToAbonent(theMailing.Name_task + "\n\n" + theMailing.Msg, word); p_phone2.Value = word.PadRight(10); CommandAddSms.ExecuteNonQuery(); } Transaction.Commit(); } catch (Exception ex) { Transaction.Rollback(); throw new Exception(ex.Message.ToString()); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { conn.Connection.Dispose(); conn.Connection.Close(); } return(0); }