using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

using System.Xml;
using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Admin.Member
{
    public partial class Member_Setting : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            L_Path.Text = Config.SiteName + " → 会员管理 → 会员设置 ";
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkPower("S_5");

                new MemberRoleManage().BindDropDownList(DDL_MemberRole);
                if (DDL_MemberRole.Items.Count < 1)
                {
                    MsgBox.Alert("请先设置会员角色", UpdatePanel1);
                }
                try
                {
                    ReadMemberConfigXML();
                }
                catch (Exception Ex)
                {
                    MsgBox.Alert(Ex.Message.Replace(@"\", @"\\"), UpdatePanel1);
                }
            }
        }

        #region Member
        private void ReadMemberConfigXML()
        {
            CB_IsReg.Checked = MemberConfig.IsReg;
            CB_IsAdminCheck.Checked = MemberConfig.IsAdminCheck;
            //NTB_JianYan.Text = MemberConfig.JianYan.ToString();
            //NTB_DianShu.Text = MemberConfig.DianShu.ToString();
            //NTB_JingBi.Text = MemberConfig.JingBi.ToString();
            NTB_JianYanHuiLv.Text = MemberConfig.JianYanHuiLv.ToString();
            NTB_JingBiHuiLv.Text = MemberConfig.JingBiHuiLv.ToString();
            TB_JingBiMingCheng.Text = MemberConfig.JingBiMingCheng.ToString();
            NTB_Point.Text = MemberConfig.Point.ToString();
            NTB_Coin.Text = MemberConfig.Coin.ToString();
            DDL_MemberRole.SelectedValue = MemberConfig.MemberRoleID.ToString();
            TB_Payment.Text = MemberConfig.Payment;
        }
        private void WriteMemberConfigXML()
        {
            MemberConfig.IsReg = CB_IsReg.Checked;
            MemberConfig.IsAdminCheck = CB_IsAdminCheck.Checked;
            //MemberConfig.JianYan = int.Parse(NTB_JianYan.Text);
            //MemberConfig.DianShu = int.Parse(NTB_DianShu.Text);
            //MemberConfig.JingBi = int.Parse(NTB_JingBi.Text);
            MemberConfig.JianYanHuiLv = Convert.ToDouble(NTB_JianYanHuiLv.Text);
            MemberConfig.JingBiHuiLv = Convert.ToDouble(NTB_JingBiHuiLv.Text);
            MemberConfig.JingBiMingCheng = TB_JingBiMingCheng.Text;
            MemberConfig.Point = int.Parse(NTB_Point.Text);
            MemberConfig.Coin = int.Parse(NTB_Coin.Text);
            MemberConfig.MemberRoleID = int.Parse(DDL_MemberRole.SelectedValue);
            MemberConfig.Payment = TB_Payment.Text;
        }
        #endregion

        protected void BT_Save_Click(object sender, EventArgs e)
        {
            MyStringBuilder ErrMsg = new MyStringBuilder();
            try
            {
                WriteMemberConfigXML();
            }
            catch
            {

                ErrMsg.Append("保存错误！");
            }
            if (ErrMsg.ToString().Length == 0)
            {
                MsgBox.Alert("操作完成！", UpdatePanel1);
            }
            else
            {
                MsgBox.Alert(ErrMsg.ToString(), UpdatePanel1);
            }
        }
    }
}
