示例#1
0
        protected void uploadButton_Click(object sender, EventArgs e)
        {
            string photoPath = "";

            if (uploadPhoto.HasFile)
            {
                photoPath = CreatePhotoUploadPath() + "/" + Misc.CreateUniqueFileName() + Path.GetExtension(uploadPhoto.FileName);

                try
                {
                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(uploadPhoto.FileContent))
                    {
                        if (image != null)
                        {
                            using (Bitmap bitmap = new Bitmap(image, 100, 120))
                            {
                                bitmap.Save(Fetch.MapPath(PathUtil.ResolveUrl(photoPath)), ImageFormat.Jpeg);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    Terminator.End("上传照片出错,可能是图片体积过大,或者不是图片格式文件。");
                    return;
                }
            }

            HostTag hostTag = HostTag.GetById(_id);

            //删除旧文件
            try
            {
                string oldPath = hostTag.ImagePath;
                if (oldPath != null)
                {
                    File.Delete(Fetch.MapPath(PathUtil.ResolveUrl(hostTag.ImagePath)));
                }
            }
            catch (Exception)
            {
            }
            hostTag.ImagePath = photoPath;
            //更新数据库
            HostTag.UpdateHostTag(hostTag);
            //TagUser.UpdatePhotoUrl(_id, photoPath);

            Terminator.Redirect(Fetch.CurrentUrl);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            NetRadio.Data.User oUser = NetRadio.Data.User.SelectByUserName(me.Name);
            if (oUser.Role >= (int)UserRole.Admin)
            {
                isAdmin = true;
            }

            if (!Page.IsPostBack)
            {
                AjaxUtil.RegisterClientScript(typeof(__TagUser), this.Page);

                int    _tagId;
                string _tagMac = null;

                using (AppDataContext db = new AppDataContext())
                {
                    var position = db.HostTagGroupStatus.SingleOrDefault(h => h.HostId == _id && h.HostGroupId == (int)TagUserType.Position);
                    if (position == null)
                    {
                        Terminator.End("记录不存在。");
                    }

                    _tagId = position.TagId;
                    var tag = Tag.Select(_tagId);
                    if (tag != null)
                    {
                        _tagMac = tag.TagMac;
                    }

                    currentTagId.Value = _tagId.ToString();
                    tagMac.Text        = _tagMac;
                    userId.Value       = position.HostId.ToString();

                    name.Text = newName.Text = position.HostName;

                    memo.Text = newMemo.Text = Strings.TextEncode(position.Description);



                    if (!isAdmin)
                    {
                        changeMemo.Visible   = false;
                        deleteButton.Visible = false;
                    }
                }


                if (!LocatingServiceUtil.IsAvailable() || !isAdmin)
                {
                    //changeTag.Visible = false;
                    clearAllEvents.Visible            = false;
                    locatingServiceDownMarker.Visible = true;
                }
                else
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(_tagMac))
                        {
                            TagStatusView tagStatus = LocatingServiceUtil.Instance <IServiceApi>().SelectTagStatus(_tagMac);
                            if (tagStatus != null)
                            {
                                batteryInsufficient.Text = Misc.GetEventStatusDescription(tagStatus.BatteryInsufficientStatus);
                                batteryReset.Text        = Misc.GetEventStatusDescription(tagStatus.BatteryResetStatus);
                                buttonPressed.Text       = Misc.GetEventStatusDescription(tagStatus.ButtonPressedStatus);
                                eventUpdateTime.Value    = tagStatus.EventUpdateTime;

                                clearBatteryInsufficient.Visible = tagStatus.BatteryInsufficientStatus != (byte)EventStatus.Cleared;
                                clearBatteryReset.Visible        = tagStatus.BatteryResetStatus != (byte)EventStatus.Cleared;
                                clearButtonPressed.Visible       = tagStatus.ButtonPressedStatus != (byte)EventStatus.Cleared;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }