/*
* DianCMS v6.2.0 文件生成内核
* QQ:5176500 965447940 Email:diancms@qq.com 微信:18980660337
* 中国国家版权局著作权登记号：2012SR104783
* 页面生成时间：2017/6/5 17:50:10
* Copyright (c) 2009-2017 DianCMS. All rights reserved.
* 成都砺寒软件有限公司
*/

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using D.BLL;
using D.Model;
using D.Common;
public partial class Csc_aspx_User_1 : System.Web.UI.Page
{
    private B_Admin bllAdmin = new B_Admin();
    private B_Column bllColumn = new B_Column();
    private B_Dictionary bllDictionary = new B_Dictionary();
    private M_Column modelColumn = new M_Column();
    private B_Model bllModel = new B_Model();
    private B_User bllUser = new B_User();
    private M_User modelUser = new M_User();
    private B_UserModel bllUserModel = new B_UserModel();
    private M_UserModel modelUserModel = new M_UserModel();
    private B_FilterWord bllFilterWord = new B_FilterWord();
    private B_InsideLink bllInsideLink = new B_InsideLink();
    private B_Site bllSite = new B_Site();
    private M_Site modelSite = new M_Site();
    private B_SiteUser bllSiteUser = new B_SiteUser();
    private M_SiteUser modelSiteUser = new M_SiteUser();
    private B_UserGroup bllUserGroup = new B_UserGroup();
    private M_UserGroup modelUserGroup = new M_UserGroup();
    private B_Tag bllTag=new B_Tag();
    private M_Tag modelTag=new M_Tag();
    private int UserId = 0;
    private B_UpLoadPic bllUploadPic = new B_UpLoadPic();
    private int Id = 1;
    private B_Info bllInfo = new B_Info();
    private DataRow RowInfo = null;
    private B_ModelPicPath bllModelPicPath = new B_ModelPicPath();
    private string DownFilePicPath="user";
    protected void Page_Load(object sender, EventArgs e)
    {
        bllUser.CheckIsLogin();
        modelUser=bllUser.GetLoginModel();
        if(modelUser==null)
        {
            Function.UserMsg(0,"<li>登录失效，请重新登录</li><li><a href='Login.aspx'>重新登录</a> <a href='" + Param.ApplicationRootPath + "/'>返回网站首页</a></li>");
        }
        modelUserGroup = bllUserGroup.GetModel(modelUser.UserGroupId);
        if(modelUserGroup==null)
        {
            Function.UserMsg(0,"<li>用户组不存在，登录失效</li><li><a href='Login.aspx'>重新登录</a> <a href='" + Param.ApplicationRootPath + "/'>返回网站首页</a></li>");
        }
        if(modelUserGroup.ModelId!=1)
        {
            Function.UserMsg(0,"<li>您不属于该用户模型</li><li><a href='javascript:window.history.back()'>返回上一页</a> <a href='Login.aspx'>重新登录</a> <a href='" + Param.ApplicationRootPath + "/'>返回网站首页</a></li>");
        }
        UserId=modelUser.UserId;
        AjaxPro.Utility.RegisterTypeForAjax(typeof(B_Linkage));
        AjaxPro.Utility.RegisterTypeForAjax(typeof(B_Common));
        modelSite=bllSite.GetModel();
        RowInfo=bllInfo.GetInfo("D_User_Person","UserId",UserId);
        if(RowInfo==null)
        {
            #region
            //往相应注册模型中写入数据
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("FieldName", typeof(string)));
            dt.Columns.Add(new DataColumn("FieldValue", typeof(string)));
            dt.Columns.Add(new DataColumn("FieldData", typeof(string)));
            DataRow drUser = dt.NewRow();
            drUser = dt.NewRow();
            drUser[0] = "UserId";
            drUser[1] = UserId;
            drUser[2] = "Integer";
            dt.Rows.Add(drUser);
            bllModel.AddInfoModel("D_User_Person", dt);
            RowInfo=bllInfo.GetInfo("D_User_Person","UserId",UserId);
            #endregion
        }

        if (!Page.IsPostBack)
        {
            CssName.Attributes.Add("href", "" + B_User.GetCssName(modelUser) + "");
            P_Go.ImageUrl = "images/control_fastforward_blue.gif";
            FilePicPath.Text="user|0";
            DataTable dt_Sex=new DataTable();
            dt_Sex=bllDictionary.GetList(1);
            if(dt_Sex.Rows.Count>0)
            {
                for(int i=0;i<dt_Sex.Rows.Count;i++)
                {
                    DianCMS_Sex.Items.Add(new ListItem(dt_Sex.Rows[i]["Text"].ToString(), dt_Sex.Rows[i]["Value"].ToString()));
                }
                DianCMS_Sex.Items[0].Selected = true;
            }
            dt_Sex.Dispose();
            dt_Sex.Clear();

            DianCMS_Birthday.Text=DateTime.Now.AddDays(0).ToString("yyyy-MM-dd");
            DataTable dt_Certificate=new DataTable();
            dt_Certificate=bllDictionary.GetList(4);
            if(dt_Certificate.Rows.Count>0)
            {
                for(int i=0;i<dt_Certificate.Rows.Count;i++)
                {
                    DianCMS_Certificate.Items.Add(new ListItem(dt_Certificate.Rows[i]["Text"].ToString(), dt_Certificate.Rows[i]["Value"].ToString()));
                }
                DianCMS_Certificate.Items[0].Selected = true;
            }
            dt_Certificate.Dispose();
            dt_Certificate.Clear();

            DataTable dt_Province=new DataTable();
            dt_Province=bllDictionary.GetList(10);
            if(dt_Province.Rows.Count>0)
            {
                for(int i=0;i<dt_Province.Rows.Count;i++)
                {
                    DianCMS_Province.Items.Add(new ListItem(dt_Province.Rows[i]["Text"].ToString(), dt_Province.Rows[i]["Id"].ToString()));
                }
                DianCMS_Province.Items[0].Selected = true;
            }
            dt_Province.Dispose();
            dt_Province.Clear();
            DataTable dt_UserFavor=new DataTable();
            dt_UserFavor=bllDictionary.GetList(11);
            if(dt_UserFavor.Rows.Count>0)
            {
                for(int i=0;i<dt_UserFavor.Rows.Count;i++)
                {
                    DianCMS_UserFavor.Items.Add(new ListItem(dt_UserFavor.Rows[i]["Text"].ToString(), dt_UserFavor.Rows[i]["Value"].ToString()));
                }
            }
            dt_UserFavor.Dispose();
            dt_UserFavor.Clear();


            if(UserId!=0)
            {
                GetShow();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Exists();
        string s_RealName=Function.Encode(DianCMS_RealName.Text.Trim());
        string s_Sex_Id="0";
        string s_Sex=string.Empty;
        try
        {
           s_Sex_Id=DianCMS_Sex.SelectedValue;
           s_Sex=DianCMS_Sex.SelectedItem.Text.Replace("┣", "").Replace("┃", "");
        }
        catch { }
        string s_Birthday=DianCMS_Birthday.Text.Trim();
        string s_Certificate_Id="0";
        string s_Certificate=string.Empty;
        try
        {
           s_Certificate_Id=DianCMS_Certificate.SelectedValue;
           s_Certificate=DianCMS_Certificate.SelectedItem.Text.Replace("┣", "").Replace("┃", "");
        }
        catch { }
        string s_CerTificateCode=Function.Encode(DianCMS_CerTificateCode.Text.Trim());
        string s_Province=DianCMS_Province.SelectedItem.Text;
        string s_Province_Id=DianCMS_Province.SelectedValue;
        string s_City_Id=Request.Form["DianCMS_City"];
        string s_City=string.Empty;
        if(s_City_Id!="0")
        {
            s_City=bllDictionary.GetModel(int.Parse(s_City_Id)).Text;
        }
        string s_Area_Id=Request.Form["DianCMS_Area"];
        string s_Area=string.Empty;
        if(s_Area_Id!="0")
        {
            s_Area=bllDictionary.GetModel(int.Parse(s_Area_Id)).Text;
        }
        string s_Address=Function.Encode(DianCMS_Address.Text.Trim());
        string s_PostCode=Function.Encode(DianCMS_PostCode.Text.Trim());
        string s_Tel=Function.Encode(DianCMS_Tel.Text.Trim());
        string s_Mobile=Function.Encode(DianCMS_Mobile.Text.Trim());
        string s_HomePage=Function.Encode(DianCMS_HomePage.Text.Trim());
        string s_QQ=Function.Encode(DianCMS_QQ.Text.Trim());
        string s_MSN=Function.Encode(DianCMS_MSN.Text.Trim());
        string s_SelfIntro=Function.Encode(bllModelPicPath.DownModelPicPath(DianCMS_SelfIntro.Text,"img",DownFilePicPath));
        string s_UserFavor="";
        string s_UserFavor_Id="|";
        if (DianCMS_UserFavor.Items.Count > 0)
        {
            for (int i = 0; i < DianCMS_UserFavor.Items.Count; i++)
            {
                if (DianCMS_UserFavor.Items[i].Selected)
                {
                    s_UserFavor_Id += DianCMS_UserFavor.Items[i].Value + "|";
                    s_UserFavor += DianCMS_UserFavor.Items[i].Text + ",";
                }
            }
        }
        if (s_UserFavor.StartsWith(","))
        {
            s_UserFavor = s_UserFavor.Substring(1, s_UserFavor.Length - 1);
        }
        
        if (s_UserFavor.EndsWith(","))
        {
            s_UserFavor = s_UserFavor.Substring(0, s_UserFavor.Length - 1);
        }

        #region
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("FieldName", typeof(string)));
        dt.Columns.Add(new DataColumn("FieldValue", typeof(string)));
        dt.Columns.Add(new DataColumn("FieldData", typeof(string)));
        DataRow drinfo = null;
        drinfo = dt.NewRow();
        drinfo[0] = "RealName";
        drinfo[1] = s_RealName;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Sex";
        drinfo[1] = s_Sex;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Sex_Id";
        drinfo[1] = s_Sex_Id;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Birthday";
        drinfo[1] = s_Birthday;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Certificate";
        drinfo[1] = s_Certificate;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Certificate_Id";
        drinfo[1] = s_Certificate_Id;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "CerTificateCode";
        drinfo[1] = s_CerTificateCode;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Province";
        drinfo[1] = s_Province;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Province_Id";
        drinfo[1] = s_Province_Id;
        drinfo[2] = "Integer";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "City";
        drinfo[1] = s_City;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "City_Id";
        drinfo[1] = s_City_Id;
        drinfo[2] = "Integer";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Area";
        drinfo[1] = s_Area;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Area_Id";
        drinfo[1] = s_Area_Id;
        drinfo[2] = "Integer";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Address";
        drinfo[1] = s_Address;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "PostCode";
        drinfo[1] = s_PostCode;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Tel";
        drinfo[1] = s_Tel;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "Mobile";
        drinfo[1] = s_Mobile;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "HomePage";
        drinfo[1] = s_HomePage;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "QQ";
        drinfo[1] = s_QQ;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "MSN";
        drinfo[1] = s_MSN;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "SelfIntro";
        drinfo[1] = s_SelfIntro;
        drinfo[2] = "LongVarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "UserFavor";
        drinfo[1] = s_UserFavor;
        drinfo[2] = "LongVarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "UserFavor_Id";
        drinfo[1] = s_UserFavor_Id;
        drinfo[2] = "LongVarChar";
        dt.Rows.Add(drinfo);


        drinfo = dt.NewRow();
        drinfo[0] = "UserId";
        drinfo[1] = UserId;
        drinfo[2] = "Integer";
        dt.Rows.Add(drinfo);
        #endregion
         //修改信息
         bllModel.UpdateInfoModel("D_User_Person",dt,"UserId");
         Function.UserMsg(1,"<li>成功修改资料</li><li><a href='Welcome.aspx'>返回后台首页</a> <a href='User_1.aspx?UserId="+UserId+"'>重新修改</a></li>");

    }
    private void Exists()
    {
    }

    private void GetShow()
    {
        DianCMS_RealName.Text=Function.Decode(RowInfo["RealName"].ToString());
        DianCMS_Sex.SelectedValue=RowInfo["Sex_Id"].ToString();
        try
        {
           DianCMS_Birthday.Text=DateTime.Parse(RowInfo["Birthday"].ToString()).ToString("yyyy-MM-dd");
        }
        catch
        {
           DianCMS_Birthday.Text=RowInfo["Birthday"].ToString();
        }
        DianCMS_Certificate.SelectedValue=RowInfo["Certificate_Id"].ToString();
        DianCMS_CerTificateCode.Text=Function.Decode(RowInfo["CerTificateCode"].ToString());
        DianCMS_Province.SelectedValue=RowInfo["Province_Id"].ToString();
        if (RowInfo["Province_Id"].ToString() != "0" && RowInfo["Province_Id"].ToString() != "")
        {
            DataTable _dt_Province = new DataTable();
            _dt_Province = bllDictionary.GetList(int.Parse(RowInfo["Province_Id"].ToString()));
            for (int i = 0; i < _dt_Province.Rows.Count; i++)
            {
                DianCMS_City.Items.Add(new ListItem(_dt_Province.Rows[i]["Text"].ToString(), _dt_Province.Rows[i]["Id"].ToString()));
            }
            DianCMS_City.SelectedValue = RowInfo["City_Id"].ToString();
            if (RowInfo["City_Id"].ToString() != "0" && RowInfo["City_Id"].ToString() != "")
            {
                DataTable _dt_City = new DataTable();
                _dt_City = bllDictionary.GetList(int.Parse(RowInfo["City_Id"].ToString()));
                for (int i = 0; i < _dt_City.Rows.Count; i++)
                {
                    DianCMS_Area.Items.Add(new ListItem(_dt_City.Rows[i]["Text"].ToString(), _dt_City.Rows[i]["Id"].ToString()));
                }
                DianCMS_Area.SelectedValue = RowInfo["Area_Id"].ToString();
            }
        }
        DianCMS_Address.Text=Function.Decode(RowInfo["Address"].ToString());
        DianCMS_PostCode.Text=Function.Decode(RowInfo["PostCode"].ToString());
        DianCMS_Tel.Text=Function.Decode(RowInfo["Tel"].ToString());
        DianCMS_Mobile.Text=Function.Decode(RowInfo["Mobile"].ToString());
        DianCMS_HomePage.Text=Function.Decode(RowInfo["HomePage"].ToString());
        DianCMS_QQ.Text=Function.Decode(RowInfo["QQ"].ToString());
        DianCMS_MSN.Text=Function.Decode(RowInfo["MSN"].ToString());
        DianCMS_SelfIntro.Text=Function.Decode(RowInfo["SelfIntro"].ToString());
        for (int i = 0; i < DianCMS_UserFavor.Items.Count; i++)
        {
            if(RowInfo["UserFavor_Id"].ToString().IndexOf("|"+DianCMS_UserFavor.Items[i].Value+"|")!=-1)
            {
                DianCMS_UserFavor.Items[i].Selected=true;
            }
        }
    }


}
