using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Spaces;
using Spaces.Controls;
public partial class Manage_UserFileSet : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindSettings();
    }
    private void BindSettings()
    {
        SiteSettings sets = Globals.GetSiteSettings();
        if (sets.PhotoSpaceSize>0)
            txtAlbumSize.Text = (sets.PhotoSpaceSize/1024).ToString();
        else
        txtAlbumSize.Text = sets.PhotoSpaceSize.ToString();
      
        txtUpFileSize.Text = (sets.MaxDiskFileLength / 1024).ToString();
        if (sets.AllowExts=="*")
        txtAllowFileExt.Text = sets.AllowExts;
        else
        txtAllowFileExt.Text = sets.AllowExts.Replace(",","\n");
    }
    protected void buttonUpdate_Click(object sender, EventArgs e)
    {
        SiteSettings sets = Globals.GetSiteSettings();
        long diskFileLength = GetLong(txtUpFileSize.Text);
        if (diskFileLength != -1 && diskFileLength<1024000)
            sets.MaxDiskFileLength = diskFileLength * 1024;

        long photoSize = GetLong(txtAlbumSize.Text);
        if (photoSize != -1 && photoSize < 10240000)
            sets.PhotoSpaceSize = photoSize * 1024;
        string[] exts = txtAllowFileExt.Text.Trim().Split('\n');
       
        if (exts.Length > 0)
        { StringBuilder sb = new StringBuilder();
            foreach (string s in exts)
            {
                if (s.Trim() == string.Empty)
                    continue;
                sb.Append(s.Trim().ToLower() + ",");
            }
            sb.Remove(sb.Length - 1, 1);
            sets.AllowExts = sb.ToString();
        }
        else
        {
            sets.AllowExts = "*";
        }
        
        sets.Save();
        Message.Text = Msg.GetMsg("成功修改站点设置！");
    }
    long GetLong(string str)
    {
        try {
            return long.Parse(str);
        }
        catch {
            return -1;
        }
    
    }
}
