//得到所有的投诉
        public List<Complemaint> GetAllComplemaints()
        {
            ISingleResult<getAllComplaintResult> result = dc.getAllComplaint();
            List<Complemaint> complemaintList = new List<Complemaint>();

            foreach (getAllComplaintResult complaint in result)
            {
                Complemaint newComplemaint = new Complemaint();
                newComplemaint.commodityId = complaint.commodityid.Value;
                newComplemaint.content = complaint.content;
                newComplemaint.ID = complaint.id;
                newComplemaint.state = (MessageState)complaint.state.Value;

                // 获得目的用户信息
                ISingleResult<getUserByUserNameResult> resultTo = dc.getUserByUserName(complaint.userto);
                RegistedUser complaintToUser = new RegistedUser();
                foreach (getUserByUserNameResult userTo in resultTo)
                {
                    complaintToUser.Address = userTo.address;
                    complaintToUser.City = userTo.city;
                    complaintToUser.Email = userTo.email;
                    complaintToUser.NickName = userTo.nickname;
                    //complaintToUser.Password = null;
                    complaintToUser.Phone = userTo.phone;
                    complaintToUser.Portrait = userTo.portraitPath;
                    //complaintToUser.School =
                    complaintToUser.UserName = userTo.id;
                    // UserZoneStyle otherStyle = new UserZoneStyle();
                    //otherStyle.ID = null;
                    // otherStyle.FileUrl = userTo.zonestyleid;
                    //complaintToUser.ZoneStyle = otherStyle;
                }
                newComplemaint.userTo = complaintToUser;

                ///////////////
                //获取发件人信息
                ISingleResult<getUserByUserNameResult> resultFrom = dc.getUserByUserName(complaint.userfrom);
                RegistedUser complaintFromUser = new RegistedUser();
                foreach (getUserByUserNameResult userFrom in resultFrom)
                {
                    complaintFromUser.Address = userFrom.address;
                    complaintFromUser.City = userFrom.city;
                    complaintFromUser.Email = userFrom.email;
                    complaintFromUser.NickName = userFrom.nickname;
                    //complaintFromUser.Password = null;
                    complaintFromUser.Phone = userFrom.phone;
                    complaintFromUser.Portrait = userFrom.portraitPath;
                    //complaintFromUser.School =
                    complaintFromUser.UserName = userFrom.id;
                    // UserZoneStyle otherStyle = new UserZoneStyle();
                    //otherStyle.ID = null;
                    // otherStyle.FileUrl = userFrom.zonestyleid;
                    //complaintFromUser.ZoneStyle = otherStyle;
                }
                newComplemaint.userFrom = complaintFromUser;
                //////////////////////
                complemaintList.Add(newComplemaint);
            }
            return complemaintList;
        }
Exemplo n.º 2
0
        //提交注册
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            CommonUser CommonUserForReg = new CommonUser();
            CommonUserForReg.UserService = new UserServiceClasses.CommonUserService();

            RegistedUser WannaRegister = new RegistedUser();
            WannaRegister.UserName = this.UserName.Text.Trim();
            WannaRegister.Password = this.Password.Text;
            WannaRegister.Email = this.Email.Text.Trim();
            WannaRegister.Phone = this.Phone.Text.Trim();
            WannaRegister.City = this.City.Text.Trim();
            WannaRegister.School = this.School1.Text.Trim();
            WannaRegister.NickName = this.NickName.Text.Trim();
            WannaRegister.Address = this.Address.Text.Trim();
            WannaRegister.Portrait = "";
            WannaRegister.ZoneStyle = new UserZoneStyle();
            WannaRegister.ZoneStyle.ID = "1";
            WannaRegister.ZoneStyle.FileUrl = "qqq";
            WannaRegister.Userservice = new UserServiceClasses.RegisterUserService();

            if(CommonUserForReg.UserService.Registe(WannaRegister))
            {
                //Response.Write("<script>alert('注册成功')</script>");
                Session["UserType"] = "NonPaymentRegisterUser";
                Session["User"] = WannaRegister;
                //Server.Transfer("../../WebPage/Default.aspx");
                Response.Redirect("../../WebPage/Default.aspx");
                //Response.Write("<script>alert('注册成功')</script>");
            }
            else
            {
               Response.Write("<script>alert('注册失败  此用户名已经被使用')</script>");
            }
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if ((Session["BadBoy"] != null) && (Session["TheCommodity"] != null))
            {
                RegistedUser Sender = new RegistedUser();
                Sender = (RegistedUser)Session["User"];
                Sender.Userservice = new RegisterUserService();

                SoftwareClassDesign.Information.Complemaint com = new Information.Complemaint();
                Commodity tt = new Commodity();
                tt = (Commodity)Session["TheCommodity"];
                com.commodityId = tt.ID;
                com.content = this.SendTheComTextBox.Text;
                com.messageType = MessageType.Complemaint;
                com.state = MessageState.Unread;
                com.userFrom = Sender;
                com.userTo = (RegistedUser)Session["BadBoy"];

                if (Sender.Userservice.PublishComplemaint(com))
                {
                    Response.Write("<script>alert('发送成功')</script>");
                    Server.Transfer("../../WebPage/Default.aspx");
                }
                else
                {
                    Response.Write("<script>alert('发送失败')</script>");
                }
            }
            else
            {
                Response.Redirect("../../WebPage/Default.aspx");
            }
        }
        protected void initPage()
        {
            RegistedUser MySelf = new RegistedUser();
            MySelf = (RegistedUser)Session["User"];
            MySelf.Userservice = new UserServiceClasses.RegisterUserService();
            List<Message> PublishMessageList =  MySelf.Userservice.GetUserUreadPublicMessages(MySelf.UserName);
            Panel single = new Panel();
            foreach (Message singleMessage in PublishMessageList)
            {

                HyperLink MessageFrom = new HyperLink();
                MessageFrom.Text = singleMessage.userFrom.NickName;
                MessageFrom.NavigateUrl = "~/WebPage/UserOwnZonePage/UserOwnZonePage/UserOwnZonePage.aspx?VisitedUserID=" + singleMessage.userFrom.UserName; ;
                single.Controls.Add(MessageFrom);
                Label MessageCon = new Label();
                MessageCon.Text = singleMessage.content;
                single.Controls.Add(MessageCon);

                ImageButton deleteButton = new ImageButton();
                deleteButton.ImageUrl = "~/newpng/Trash.png";
                deleteButton.Height = new Unit(48);
                deleteButton.ID = singleMessage.ID.ToString();
                deleteButton.OnClientClick += "DeleteItem";
                deleteButton.Click += new ImageClickEventHandler(deleteButton_Click);
                single.Controls.Add(deleteButton);

            }
            this.ALLPublicMessage.Controls.Add(single);
        }
        protected void IniUserInformation()
        {
            this.UserInfoBeforeLogin.Visible = false;
            this.UserInfoAfterLogin.Visible = false;
            //NULL表示这个sesson是新近
            if (Session["User"] == null)
            {
                Session["UserType"] = "CommonUser";
                CommonUser temp = new CommonUser();
                temp.UserService = new CommonUserService();
                Session["User"] = temp;
                this.UserInfoBeforeLogin.Visible = true;
                this.UserInfoAfterLogin.Visible = false;
            }
            else if (Session["UserType"].ToString() == "CommonUser")
            {
                this.UserInfoBeforeLogin.Visible = true;
                this.UserInfoAfterLogin.Visible = false;
            }
            else
            {
                this.UserInfoBeforeLogin.Visible = false;
                this.UserInfoAfterLogin.Visible = true;
                //到得到用户的信息
                RegistedUser RegisterUserForGetInfo = new RegistedUser();
                RegisterUserForGetInfo = (RegistedUser)Session["User"];
                RegisterUserForGetInfo.Userservice = new RegisterUserService();
                this.HTuserName.Text = RegisterUserForGetInfo.NickName;
                this.HTuserName.NavigateUrl = "~/WebPage/UserMainPages/UserMainPage/UserMainPage.aspx";

                int messageCount = 0;
                Dictionary<MessageType, int> dic = new Dictionary<MessageType, int>();
                dic  =  RegisterUserForGetInfo.Userservice.GetUserUreadMessagesNum(RegisterUserForGetInfo.UserName);
                foreach (KeyValuePair<MessageType,int> singleDic in dic)
                {
                    messageCount += singleDic.Value;

                }
                if (messageCount == 0)
                {
                    this.HLMessageNumber.Visible = false;
                }
                else
                {
                    this.HLMessageNumber.Visible = true;
                    this.HLMessageNumber.Text = "您有新短消息";
                    //跳到收件箱页面
                    this.HLMessageNumber.NavigateUrl = "~/WebPage/UserMainPages/UserMainPage/UserMainPage.aspx";
                }
            }
        }
        //添加评论
        protected void AddComment_Click(object sender, EventArgs e)
        {
            if (Session["UserType"].ToString() != "CommonUser")
            {
                if (this.CommentTextBox.Text != "")
                {
                    CommonUserForInfo.UserService = new CommonUserService();
                    RegistedUser temp = new RegistedUser();
                    temp = (RegistedUser)Session["User"];
                    temp.Userservice = new RegisterUserService();

                    Comment newComment =new Comment();
                    //Message newMessage = new Message();
                    newComment.content = this.CommentTextBox.Text;
                    newComment.ID = System.Guid.NewGuid();
                    newComment.messageType = MessageType.comment;
                    newComment.state = MessageState.Unread;
                    newComment.userFrom = CommonUserForInfo.UserService.GetOtherUserInfo(temp.UserName);
                    //temp.UserName;
                    newComment.userTo = SellerUser;
                    newComment.registedUserID = TheCommodity.UserName;
                    newComment.commodityId = TheCommodity.ID;
                    List<Comment> singleComment = new List<Comment>();
                    singleComment.Add(newComment);
                    //成功插入消息

                   // if (temp.//.PublishMessage(singleMessage))
                    if(temp.Userservice.PublicComments(singleComment))
                    {
                        InitPageInfo();
                        this.AddComment2.Visible = false;
                        this.CommentTextBox.Text = "";
                        this.Label5.Text = "您已经成功插入评论";
                    }
                    else
                    {
                        this.Label5.Text = "评论插入失败";
                    }
                }
                else
                {
                    Response.Write("<script>alert('评论内容不为空')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('请先登录')</script>");

            }
        }
        //用于相应相应的商品删除
        void deleteButton_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            string a = (sender as ImageButton).ID;
            RegistedUser MySelf = new RegistedUser();
            MySelf = (RegistedUser)Session["User"];
            MySelf.Userservice = new UserServiceClasses.RegisterUserService();
            List<Message> comList =  MySelf.Userservice.GetUserUreadPublicMessages(MySelf.UserName);//MySelf.Userservice.GetUserUreadPublicMessages(MySelf.UserName);

            for (int i = 0; i < comList.Count; i++)
            {
                if (comList[i].ID.ToString().Equals(a))
                {

                    comList.Remove(comList[i]);
                }
            }
            initPage();
        }
        //商品加入到收藏
        protected void AddToFarviteButton_Click(object sender, ImageClickEventArgs e)
        {
            //这个商品的热度加1
            if (Session["UserType"].ToString() != "CommonUser")
            {
                SoftwareClassDesign.UserServiceClasses.SystemService.AddCommoditypopularityByID(TheCommodity.ID);
                RegistedUser tempRegisterUserForAdd = new RegistedUser();
                tempRegisterUserForAdd = (RegistedUser)Session["User"];
                tempRegisterUserForAdd.Userservice = new RegisterUserService();
                if (tempRegisterUserForAdd.Userservice.AddCollectItem(tempRegisterUserForAdd.UserName, TheCommodity.ID))
                {
                    this.ADDedInformation.Text = "成功添加到收藏";
                }
                else
                {
                    this.ADDedInformation.Text = "添加到收藏失败";
                }
            }
            else
            {
                Response.Write("<script>alert('请先登录')</script>");

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ADDedInformation.Text = "";
            CommonUserForInfo.UserService = new CommonUserService();
            string str = Request.QueryString["commodityID"];
            if (!IsPostBack)
            {
                if (str == null)
                {
                    Response.Redirect("../../WebPage/Default.aspx");
                }
                else
                {
                    //商品的热度加1
                    Guid comID = new Guid(str);
                    SoftwareClassDesign.UserServiceClasses.SystemService.AddCommoditypopularityByID(comID);
                    TheCommodity = CommonUserForInfo.UserService.GetCommodityByID(comID);
                    Session["TheCommodity"] = TheCommodity;
                }
            }
            TheCommodity = (Commodity)Session["TheCommodity"];

            //的到数据后 在用初始函数进行填充

            SellerUser = CommonUserForInfo.UserService.GetOtherUserInfo(TheCommodity.UserName);
            SellerUser.Userservice = new RegisterUserService();

            Session["BadBoy"] = SellerUser;
            commodityList = CommonUserForInfo.UserService.GetOtherUserCommodity(SellerUser.UserName);
            InitPageInfo();//填充
        }
        //更新用户信息25  ok
        public bool UpdateUserInfo(RegistedUser User)
        {
            bool IsSucceed = false;
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                if(User is NonPaymentRegisterUser)
                {
                    DBAccessor.updateRegistedUser(User.UserName, User.Password, User.NickName, User.Email, User.Phone, User.ZoneStyle.ID, User.Portrait, User.City, User.School, User.Address,1,0,null);
                }
                else if (User is PaymentRegisterUser)
                {
                    PaymentRegisterUser user = (PaymentRegisterUser)User;
                    DBAccessor.updateRegistedUser(user.UserName, user.Password, user.NickName, user.Email, user.Phone, user.ZoneStyle.ID, user.Portrait, user.City, user.School, user.Address, 2, user.PayAmount,user.paymentEndTime);
                }
                IsSucceed = true;
            }
            catch (Exception e)
            {
                IsSucceed = false;
            }

            return IsSucceed;
        }
        //搜索注册用户22 Ok
        public List<RegistedUser> SearchRegisterUser(String Keyword)
        {
            List<RegistedUser> RegistedUserList = new List<RegistedUser>();
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                ISingleResult<searchRegistedUserResult> resultList = DBAccessor.searchRegistedUser(Keyword);
                if (resultList != null)
                {
                    foreach (searchRegistedUserResult result in resultList)
                    {
                        RegistedUser User = new RegistedUser();
                        User.UserName = result.id;
                        User.NickName = result.nickname;
                        User.Email = result.email;
                        User.Phone = result.phone;
                        User.School = result.school;
                        User.City = result.city;
                        User.Address = result.address;
                        User.Portrait = result.portraitPath;
                        User.ZoneStyle = new UserZoneStyle();
                        User.ZoneStyle.ID = result.zonestyleid;
                        String StyleFileUrl = "";
                        DBAccessor.getStylePathByUser(User.UserName, ref StyleFileUrl);
                        User.ZoneStyle.FileUrl = StyleFileUrl;

                        RegistedUserList.Add(User);
                    }
                }
            }
            catch (Exception e)
            {

            }
            return RegistedUserList;
        }
        //获得用户的好友列表23 Ok
        public List<RegistedUser> GetAllAttentioners(String UserName)
        {
            List<RegistedUser> RegistedUserList = new List<RegistedUser>();
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                ISingleResult<getAttentionByUserResult> resultList = DBAccessor.getAttentionByUser(UserName);

                foreach (getAttentionByUserResult result in resultList)
                {
                    RegistedUser attentioner = new RegistedUser();
                    attentioner.UserName = result.id;
                    attentioner.NickName = result.nickname;
                    attentioner.Email = result.email;
                    attentioner.Phone = result.phone;
                    attentioner.School = result.school;
                    attentioner.City = result.city;
                    attentioner.Address = result.address;
                    attentioner.Portrait = result.portraitPath;
                    attentioner.ZoneStyle = new UserZoneStyle();
                    attentioner.ZoneStyle.ID = result.zonestyleid;
                    String StyleFileUrl = "";
                    DBAccessor.getStylePathByUser(attentioner.UserName,ref StyleFileUrl);
                    attentioner.ZoneStyle.FileUrl = StyleFileUrl;

                    //加入要返回的列表中
                    RegistedUserList.Add(attentioner);
                }
            }
            catch (Exception e)
            {
            }

            return RegistedUserList;
        }
        //用户注册
        public bool Registe(RegistedUser registedUser)
        {
            Boolean IsFine = true;
            try
            {
                dc.insertUser(registedUser.UserName, registedUser.Password, registedUser.NickName, registedUser.Email, registedUser.Phone, registedUser.ZoneStyle.ID, registedUser.Portrait, registedUser.City, registedUser.School, registedUser.Address);
                IsFine = true;
            }
            catch (Exception e)
            {

                IsFine = false;
            }

            return IsFine;
        }
        //验证登陆用户
        public RegistedUser Login(string userName, string passWord)
        {
            // RegistedUser RightUser = new RegistedUser();
            bool? flag = false;
            ISingleResult<isRegistedResult> result = dc.isRegisted(userName,passWord,ref flag);
            if (flag == false)
            {
                RegistedUser  temp = new RegistedUser();
                temp.UserName = "";
                //RightUser = null;
                return temp;
            }
            else
            {
                foreach (isRegistedResult user in result)
                {
                    if (user.type == 1)
                    {
                        NonPaymentRegisterUser NoPayUser = new NonPaymentRegisterUser();
                        NoPayUser.Address = user.address;
                        NoPayUser.City = user.city;
                        NoPayUser.Email = user.email;
                        NoPayUser.NickName = user.nickname;
                        NoPayUser.Phone = user.phone;
                        NoPayUser.Portrait = user.portraitPath;
                        NoPayUser.School = user.school;
                        NoPayUser.UserName = user.id;
                        UserZoneStyle otherStyle = new UserZoneStyle();
                        otherStyle.ID = null;
                        otherStyle.FileUrl = user.zonestyleid;
                        NoPayUser.ZoneStyle = otherStyle;
                        NoPayUser.UserName = user.id;
                        NoPayUser.Userservice = new RegisterUserService();
                        NoPayUser.UserService = new NonPaymentUserService();
                        return NoPayUser;
                    }
                    else if(user.type ==2)
                    {
                        PaymentRegisterUser payUser = new PaymentRegisterUser();
                        payUser.Address = user.address;
                        payUser.City = user.city;
                        payUser.Email = user.email;
                        payUser.NickName = user.nickname;
                        payUser.Phone = user.phone;
                        payUser.Portrait = user.portraitPath;
                        payUser.School = user.school;
                        payUser.UserName = user.id;
                        UserZoneStyle otherStyle = new UserZoneStyle();
                        otherStyle.ID = null;
                        otherStyle.FileUrl = user.zonestyleid;
                        payUser.ZoneStyle = otherStyle;
                        payUser.UserName = user.id;

                        return payUser;
                    }
                }
            }
            return null;
        }
 //通过用户id的到别的用户的实例
 public RegistedUser GetOtherUserInfo(string userName)
 {
     ISingleResult<getUserByUserNameResult> result = dc.getUserByUserName(userName);
     RegistedUser otherUser = new RegistedUser();
     foreach(getUserByUserNameResult user in result)
     {
         otherUser.Address = user.address;
         otherUser.City = user.city;
         otherUser.Email = user.email;
         otherUser.NickName = user.nickname;
         //otherUser.Password = null;
         otherUser.Phone = user.phone;
         otherUser.Portrait = user.portraitPath;
         otherUser.School = user.school;
         otherUser.UserName = user.id;
         UserZoneStyle otherStyle = new UserZoneStyle();
         otherStyle.ID = null;
         otherStyle.FileUrl = user.zonestyleid;
         otherUser.ZoneStyle = otherStyle;
     }
     return otherUser;
 }