private void LoadPersonInfo(string username) { Users u = new Users(); UsersManage umg = new UsersManage(); u = umg.Getuser(username); if (u.TrueName.ToString() != "") { truename.Text = u.TrueName; } if (u.UserType.ToString() != "") { Role.Text = u.UserType; } }
protected void Button2_Click(object sender, EventArgs e) { if (Session["username"] == null) { Function.CheckIstimeout(); } else { UsersManage umg = new UsersManage(); int sucess = 0; int faild = 0; SMS sms = new SMS(); SendSMS ssm = GetSMSConf(); sms.Number = ""; string recivers = ""; string recivername = ""; if (phonebooklist.SelectedValue.ToString() != "") { DataTable dt = umg.getalluser(Convert.ToInt32(phonebooklist.SelectedValue)); if (dt.Rows.Count > 0) { if (dt.Rows.Count == 1) { sms.Number = dt.Rows[0]["phone"].ToString(); recivers = dt.Rows[0]["TrueName"].ToString().Trim(); recivername += dt.Rows[0]["UserName"].ToString().Trim(); } else { for (int i = 0; i < dt.Rows.Count; i++) { sms.Number += dt.Rows[i]["phone"].ToString().Trim() + "|"; recivers += dt.Rows[i]["TrueName"].ToString().Trim() + "、"; recivername += dt.Rows[i]["UserName"].ToString().Trim() + "+"; } } } } else { if (CheckBoxList1.Items.Count == 1) { sms.Number = umg.Getuser(CheckBoxList1.Items[0].Value.ToString().Trim()).Phone; } else { for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected) { sms.Number += umg.Getuser(CheckBoxList1.Items[i].Value.ToString().Trim()).Phone + "|"; recivers += CheckBoxList1.Items[i].Text.ToString().Trim() + "、"; recivername += CheckBoxList1.Items[i].Value.ToString().Trim() + "+"; } } } } if (sms.Number.ToString().Trim() != "") { sms.Scon = SMSContent.Text.ToString(); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint Ipe = new IPEndPoint(IPAddress.Parse(ssm.Ip), int.Parse(ssm.Port)); try { socket.Connect(Ipe); if (socket.Connected) { MemoryStream stream = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, sms); stream.Flush(); byte[] smsbyte = stream.ToArray(); socket.Send(smsbyte); byte[] reciver = new byte[128]; socket.Receive(reciver); string reciverstring = Encoding.Default.GetString(reciver).ToString().Trim(); if (Convert.ToBoolean(reciverstring)) { sucess++; } else { faild++; } } if (sucess > 0) { NoticesManager nmg = new NoticesManager(); nmg.AddNotices("", Session["username"].ToString(), recivers.Substring(0, recivers.Length - 1), SMSContent.Text.ToString(), DateTime.Now, "短信", 0, recivername.Substring(0, recivername.Length - 1)); ScriptManager.RegisterClientScriptBlock(this.UpdatePanel2, UpdatePanel2.GetType(), "", "alert('短信接发送成功')", true); SMSContent.Text = ""; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { CheckBoxList1.Items[i].Selected = false; } } } catch (Exception ex) { throw ex; } } else { ScriptManager.RegisterClientScriptBlock(this.UpdatePanel2, UpdatePanel2.GetType(), "", "alert('短信接收者为空')", true); } } }