Ejemplo n.º 1
0
        /// <summary>
        /// ���û��Ķ�Ѷ��¼��ʾ��datagrid��
        /// </summary>
        protected void BindGrid(string Username,string DispType)
        {
            SMS sm = new SMS();
            SqlDataReader dr = null;
            if(DispType=="1") //�ҵ����Ľ���
            {
                try
                {
                    dr = sm.GetMyReceive(Username);
                    dgMsgList.DataSource = UDS.Components.Tools.ConvertDataReaderToDataTable(dr).DefaultView;
                    dgMsgList.DataBind();
                }
                catch
                {
                    Server.Transfer("../Error.aspx");
                }
            }

            if(DispType=="2") //��������
            {
                try
                {
                    dr = sm.GetMySent(Username);
                    dgMsgList.DataSource = UDS.Components.Tools.ConvertDataReaderToDataTable(dr).DefaultView;
                    dgMsgList.DataBind();
                }
                catch
                {
                    Server.Transfer("../Error.aspx");
                }

            }

            switch (DispType)
            {
                case "1":
                    dgMsgList.Columns[2].Visible = false; //�������ռ���
                    break;
                case "2":
                    dgMsgList.Columns[1].Visible = false; //�������ռ���
                    this.btnRead .Visible = false;         //�������İ�ť
                    this.btnDelete .Visible = false;       //����ɾ����ť
                    break;
                default:
                    break;
            }

            sm = null;
            dr = null;
        }
Ejemplo n.º 2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            string Username		 = (Request.QueryString["Username"]!=null)?Request.QueryString["Username"].ToString():Request.Cookies["Username"].Value.ToString();
            string DispType		 = (Request.QueryString["DispType"]!=null)?Request.QueryString["DispType"].ToString():"1";

            string result = Request.Params["result"];

            if(!Page.IsPostBack)
            {
                if (string.IsNullOrEmpty(result))
                {
                    BindGrid(Username, DispType);
                    Session["MsgDispType"] = DispType;
                    this.btnDelete.Attributes["onclick"] = "javascript:return confirm('��ȷ��Ҫɾ����?');";
                }
                else
                {
                    SMS sm = new SMS();
                    SqlDataReader dreader = null;
                    try
                    {
                        dreader = sm.GetMyReceive(Username);

                        DataTable dt = dreader.ToDataTable(true);

                        List<UDSSMS> retList = new List<UDSSMS>();

                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr.IsNull("isread") || !bool.Parse(dr["isread"].ToString()))
                            {
                                UDSSMS sms = new UDSSMS()
                                {
                                    Id = dr["ID"].ToString(),
                                    Content = dr["content"].ToString(),
                                    IsRead = dr.IsNull("isread") ? false : bool.Parse(dr["isread"].ToString()),
                                    ReceiverRealName = dr["ReceiverRealName"].ToString(),
                                    Sender = dr["sender"].ToString(),
                                    SenderRealName = dr["senderrealname"].ToString(),
                                    SendTime = DateTime.Parse(dr["sendtime"].ToString()).ToString(),
                                    Type = dr["type"].ToString()
                                };

                                retList.Add(sms);
                            }
                        }

                        var jsonSer = new Newtonsoft.Json.JsonSerializer();
                        StringWriter sw = new StringWriter();
                        using (JsonWriter jw = new JsonTextWriter(sw))
                        {
                            jw.Formatting = Formatting.Indented;

                            jsonSer.Serialize(jw, retList);
                        }

                        string content = sw.ToString();
                        Response.Clear();
                        Response.ContentType = "application/json";
                        sw.Close();
                        Response.Write(content);
                        //HttpContext.Current.ApplicationInstance.CompleteRequest();
                    }
                    catch (Exception eX)
                    {
                        if (null != dreader)
                        {
                            if (!dreader.IsClosed)
                            {
                                dreader.Close();
                            }
                        }

                        Response.StatusCode = 400;
                        Response.ContentType = "text/html";
                        Response.Write(eX.Message);
                        //HttpContext.Current.ApplicationInstance.CompleteRequest();

                    }
                    finally
                    {
                        Response.End();
                    }
                }
            }
        }