/*
* 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_Admin_2 : 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)
    {
        bllAdmin.CheckIsLogin("User");
        if (!string.IsNullOrEmpty(Request.QueryString["UserId"]))
        {
            try
            {
                UserId = int.Parse(Request.QueryString["UserId"]);
            }
            catch { }
        }
        AjaxPro.Utility.RegisterTypeForAjax(typeof(B_Linkage));
        AjaxPro.Utility.RegisterTypeForAjax(typeof(B_Common));
        modelSite=bllSite.GetModel();
        RowInfo=bllInfo.GetInfo("D_User_Business","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_Business", dt);
            RowInfo=bllInfo.GetInfo("D_User_Business","UserId",UserId);
            #endregion
        }

        if (!Page.IsPostBack)
        {
            CssName.Attributes.Add("href", "../css/skin/" + Function.GetCssName() + "/css.css");
            P_Go.ImageUrl = "../css/skin/" + Function.GetCssName() + "/images/p_go.gif";
            LitModelName.Text="<a href='UserList.aspx?ModelId=2'>企业会员</a>";
            FilePicPath.Text="user|0";
            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_Industry=new DataTable();
            dt_Industry=bllDictionary.GetList(12);
            if(dt_Industry.Rows.Count>0)
            {
                for(int i=0;i<dt_Industry.Rows.Count;i++)
                {
                    DianCMS_Industry.Items.Add(new ListItem(dt_Industry.Rows[i]["Text"].ToString(), dt_Industry.Rows[i]["Value"].ToString()));
                }
                DianCMS_Industry.Items[0].Selected = true;
            }
            dt_Industry.Dispose();
            dt_Industry.Clear();

            DataTable dt_Size=new DataTable();
            dt_Size=bllDictionary.GetList(13);
            if(dt_Size.Rows.Count>0)
            {
                for(int i=0;i<dt_Size.Rows.Count;i++)
                {
                    DianCMS_Size.Items.Add(new ListItem(dt_Size.Rows[i]["Text"].ToString(), dt_Size.Rows[i]["Value"].ToString()));
                }
                DianCMS_Size.Items[0].Selected = true;
            }
            dt_Size.Dispose();
            dt_Size.Clear();

            DataTable dt_Capital=new DataTable();
            dt_Capital=bllDictionary.GetList(21);
            if(dt_Capital.Rows.Count>0)
            {
                for(int i=0;i<dt_Capital.Rows.Count;i++)
                {
                    DianCMS_Capital.Items.Add(new ListItem(dt_Capital.Rows[i]["Text"].ToString(), dt_Capital.Rows[i]["Value"].ToString()));
                }
                DianCMS_Capital.Items[0].Selected = true;
            }
            dt_Capital.Dispose();
            dt_Capital.Clear();



            if(UserId!=0)
            {
                GetShow();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Exists();
        string s_Name="";
        if(Id!=0)
        {
            s_Name=RowInfo["Name"].ToString();
        }
        string s_ShortName="";
        if(Id!=0)
        {
            s_ShortName=RowInfo["ShortName"].ToString();
        }
        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_ConactName=Function.Encode(DianCMS_ConactName.Text.Trim());
        string s_Tel=Function.Encode(DianCMS_Tel.Text.Trim());
        string s_Fax=Function.Encode(DianCMS_Fax.Text.Trim());
        string s_Industry_Id="0";
        string s_Industry=string.Empty;
        try
        {
           s_Industry_Id=DianCMS_Industry.SelectedValue;
           s_Industry=DianCMS_Industry.SelectedItem.Text.Replace("┣", "").Replace("┃", "");
        }
        catch { }
        string s_Website=Function.Encode(DianCMS_Website.Text.Trim());
        string s_Size_Id="0";
        string s_Size=string.Empty;
        try
        {
           s_Size_Id=DianCMS_Size.SelectedValue;
           s_Size=DianCMS_Size.SelectedItem.Text.Replace("┣", "").Replace("┃", "");
        }
        catch { }
        string s_Capital_Id="0";
        string s_Capital=string.Empty;
        try
        {
           s_Capital_Id=DianCMS_Capital.SelectedValue;
           s_Capital=DianCMS_Capital.SelectedItem.Text.Replace("┣", "").Replace("┃", "");
        }
        catch { }
        string s_BankName=Function.Encode(DianCMS_BankName.Text.Trim());
        string s_BankUserName=Function.Encode(bllModelPicPath.DownModelPicPath(DianCMS_BankUserName.Text,"img",DownFilePicPath));

        #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] = "Name";
        drinfo[1] = s_Name;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

        drinfo = dt.NewRow();
        drinfo[0] = "ShortName";
        drinfo[1] = s_ShortName;
        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] = "ConactName";
        drinfo[1] = s_ConactName;
        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] = "Fax";
        drinfo[1] = s_Fax;
        drinfo[2] = "VarChar";
        dt.Rows.Add(drinfo);

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

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

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

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

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

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

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

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

        drinfo = dt.NewRow();
        drinfo[0] = "BankUserName";
        drinfo[1] = s_BankUserName;
        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_Business",dt,"UserId");
         Function.AdminMsg(1,"<li>成功修改资料</li><li><a href='user/UserList.aspx?ModelId=2'>返回列表</a> <a href='user/User_2.aspx?UserId="+UserId+"'>重新修改</a></li>");

    }
    private void Exists()
    {
        if(DianCMS_ConactName.Text.Trim().Length==0)
        {
            Function.AdminMsg(0,"<li>公司联系人不能为空！</li><li><a href='javascript:window.history.back()'>返回上一页</a></li>");
        }
        if(DianCMS_Tel.Text.Trim().Length==0)
        {
            Function.AdminMsg(0,"<li>公司联系电话不能为空！</li><li><a href='javascript:window.history.back()'>返回上一页</a></li>");
        }
        if (!Regex.IsMatch(DianCMS_Tel.Text.Trim(), @"((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)"))
        {
            Function.AdminMsg(0,"<li>公司联系电话输入错误</li><li><a href='javascript:window.history.back()'>返回上一页</a></li>");
        }
    }

    private void GetShow()
    {
        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_ConactName.Text=Function.Decode(RowInfo["ConactName"].ToString());
        DianCMS_Tel.Text=Function.Decode(RowInfo["Tel"].ToString());
        DianCMS_Fax.Text=Function.Decode(RowInfo["Fax"].ToString());
        DianCMS_Industry.SelectedValue=RowInfo["Industry_Id"].ToString();
        DianCMS_Website.Text=Function.Decode(RowInfo["Website"].ToString());
        DianCMS_Size.SelectedValue=RowInfo["Size_Id"].ToString();
        DianCMS_Capital.SelectedValue=RowInfo["Capital_Id"].ToString();
        DianCMS_BankName.Text=Function.Decode(RowInfo["BankName"].ToString());
        DianCMS_BankUserName.Text=Function.Decode(RowInfo["BankUserName"].ToString());
    }


}
