private void Button1_Click(object sender, System.EventArgs e) {
if(TextBox2.Text.Trim().Length>70) { Response.Write ("<script language='javascript'>alert('发送内容过长,请重新输入!')</script>"); } if(TextBox2.Text.Trim().Length<=70) { SqlConnection myconnect = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]); string temp1 = ""; string str = TextBox1.Text.Trim(); string [] strarr = str.Split(',',',','.','。',' '); //string mobileString = "13\\d{9}";
for(int i=0;i<strarr.Length;i++) {//a //strarr[i]; if((strarr[i].Length!=11) && (strarr[i].Trim()!="")) {//b SqlDataAdapter sqlDataAdapterbm = new SqlDataAdapter("select teamid from userteam where teamname = @teamname",myconnect); DataSet dataSetbm = new DataSet(); sqlDataAdapterbm.SelectCommand.Parameters.Add("@teamname", SqlDbType.Char, 30).Value = strarr[i].Trim(); sqlDataAdapterbm.Fill(dataSetbm,"faults"); if (dataSetbm.Tables["faults"].Rows.Count>0) { temp1 = dataSetbm.Tables["faults"].Rows[0]["teamid"].ToString().Trim(); } if (dataSetbm.Tables["faults"].Rows.Count<1) { temp1 = ""; } if(temp1 != "") {//c SqlDataAdapter sqlDataAdapterbm1 = new SqlDataAdapter("select yonghu,telph from purview1 where teamid = @teamid",myconnect); DataSet dataSetbm1 = new DataSet(); sqlDataAdapterbm1.SelectCommand.Parameters.Add("@teamid", SqlDbType.Char, 4).Value = temp1; sqlDataAdapterbm1.Fill(dataSetbm1,"faults1"); DataTable dt=dataSetbm1.Tables[0]; foreach(DataRow dr in dt.Rows) {//d //string gongsidaima=dr[0].ToString().Trim(); string yonghu=dr[0].ToString().Trim(); string shouji=dr[1].ToString().Trim(); if(yonghu!="") {//e SqlDataAdapter sqlDataAdapterbm2 = new SqlDataAdapter("select * from mobile_info where userid = @userid",sqlConnection2); DataSet dataSetbm2 = new DataSet(); sqlDataAdapterbm2.SelectCommand.Parameters.Add("@userid", SqlDbType.Char, 20).Value = yonghu; //sqlDataAdapterbm2.SelectCommand.Parameters.Add("@workno", SqlDbType.Char, 5).Value = gonghao; sqlDataAdapterbm2.Fill(dataSetbm2,"faults2");
string temp2; temp2 = dataSetbm2.Tables["faults2"].Rows[0]["mobile"].ToString().Trim(); string strinsert; strinsert = "insert into send(smid,userid,scontent,flag,destaddress)values('62257496',@userid,@scontent,'0',@destaddress)"; SqlCommand cmdinsert = new SqlCommand(strinsert,sqlConnection1); cmdinsert.Parameters.Add("@userid",name.Text.Trim()); cmdinsert.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert.Parameters.Add("@destaddress",temp2); cmdinsert.Connection.Open(); cmdinsert.ExecuteNonQuery(); cmdinsert.Connection.Close(); }//e if(yonghu=="") {//f //string shouji=dr[2].ToString().Trim(); string strinsert8; strinsert8 = "insert into send(smid,userid,scontent,flag,destaddress)values('62257496',@userid,@scontent,'0',@destaddress)"; SqlCommand cmdinsert8 = new SqlCommand(strinsert8,sqlConnection1); cmdinsert8.Parameters.Add("@userid",name.Text.Trim()); cmdinsert8.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert8.Parameters.Add("@destaddress",shouji); cmdinsert8.Connection.Open(); cmdinsert8.ExecuteNonQuery(); cmdinsert8.Connection.Close();
}//f }//d }//c
}//b if(strarr[i].Length==11) { if(strarr[i].Substring(0,2)!="13") {
} if(strarr[i].Substring(0,2)=="13") { string strinsert; strinsert = "insert into send(smid,scontent,flag,destaddress)values('62257496',@scontent,'0',@destaddress)"; SqlCommand cmdinsert = new SqlCommand(strinsert,sqlConnection1); cmdinsert.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert.Parameters.Add("@destaddress",strarr[i].Trim()); cmdinsert.Connection.Open(); cmdinsert.ExecuteNonQuery(); cmdinsert.Connection.Close(); } } }//a TextBox1.Text = ""; TextBox2.Text = ""; Response.Write ("<script language='javascript'>alert('发送成功!')</script>");
} } 帮忙改