using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text.RegularExpressions;
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 TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model.Enum;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Admin.DataBase
{
    public partial class Replace : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkPower("D_6");

                new ModelManage().BindDDL(DDL_Model, "");

                DDL_Model.SelectedIndex = 0;


                new ClassManage().BindDDL(DDL_Class, Class_BindOption.NoLink, "所有栏目", int.Parse(DDL_Model.SelectedValue));

                new ModelManage().GetFields(LB_Field, int.Parse(DDL_Model.SelectedValue));

            }
        }
        protected void DDL_Model_SelectedIndexChanged(object sender, EventArgs e)
        {
            new ClassManage().BindDDL(DDL_Class, Class_BindOption.NoLink, "所有栏目", int.Parse(DDL_Model.SelectedValue));

            new ModelManage().GetFields(LB_Field, int.Parse(DDL_Model.SelectedValue));
        }
        protected void BT_OK_Click(object sender, EventArgs e)
        {
            if (LB_Field.SelectedIndex == -1)
            {
                MsgBox.Alert("请选择字段", UpdatePanel1);
                return;
            }
            if (TB_OldString.Text.Length == 0)
            {
                MsgBox.Alert("请输入“原字符”。", UpdatePanel1);
                return;
            }
            MyStringBuilder Fields = new MyStringBuilder();
            foreach (ListItem li in LB_Field.Items)
            {
                if (li.Selected)
                {
                    Fields.Append(li.Text + ",");
                }
            }
            Fields.TrimEnd();

            new FieldManage().RepalceString(int.Parse(DDL_Model.SelectedValue), DDL_Class.SelectedValue, Fields.ToString(), TB_OldString.Text.Trim(), TB_NewString.Text.Trim(), RBL_ReplaceType.SelectedIndex);

            MsgBox.Alert("执行完毕。", UpdatePanel1);
        }


    }
}