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 JuSNS.Model.ApiInterface;
using JuSNS.ApiInterface;
using JuSNS.Common;

namespace JuSNS.Web.dev
{
    public partial class appnew : JuSNS.UI.Page.UserPage
    {
        protected string avalExt = "jpg,gif,ico,bmp,jpeg,png";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!JuSNS.ApiInterface.Developer.IsEnabled(this.UserID))
            {
                PageError("您已经是开发者，但需要等待管理员审核", rooDir + "/dev",true);
            }
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void submit_click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                AppInfo info = new AppInfo();
                info.AppName = Request.Form["appname"];
                info.Description = Request.Form["description"];
                info.Url = Request.Form["url"];
                info.IsLock = 1;
                info.ToAdmin = 0;
                info.Mobile = string.Empty;
                info.Tel = string.Empty;
                info.Email = string.Empty;
                string apptype = Request.Form["apptype"];
                info.Type = string.IsNullOrEmpty(apptype) ? 1 : int.Parse(apptype);
                string filename = string.Empty;
                if (this.icon.HasFile)
                {
                    Public.UpdateIcon(this.icon.PostedFile, avalExt, out filename);
                    info.Icon = filename;
                }
                if (this.micon.HasFile)
                {
                    Public.UpdateIcon(this.micon.PostedFile, avalExt, out filename);
                    info.MidIcon = filename;
                }
                if (this.bicon.HasFile)
                {
                    Public.UpdateIcon(this.bicon.PostedFile, avalExt, out filename);
                    info.BigIcon = filename;
                }
                info.UserID = this.UserID;
                Developer.CreateApp(info);
                Response.Redirect("index.aspx?sucmsg=" + Server.UrlEncode("提交应用程序成功！"));
            }
        }
    }
}
