<%@ page language="C#" autoeventwireup="true" masterpagefile="AdminIndexMaster.master" inherits="HL_Admin_Admin_AddSkin, WebApp_deploy" title="网站风格管理" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
function ResizeImage(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if(state!='complete') {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW; b=dH/MaxH;
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}

function ShowImage(obj){
    document.getElementById('previewImage').innerHTML ="预览<br><img src=\""+obj.value+"\" width=100 height=100 onload=\"ResizeImage(this, 100, 100);\" align=absmiddle>";
}

function selectskinpath(objvalue){
    pathobj = document.getElementById("FormView1_Skin_SavePath");
    if(objvalue=="Index"){
        pathobj.value = "/Index/";
    }else if(objvalue=="Member"){
        pathobj.value = "/Member/";
    }else if(objvalue=="Basic"){
        pathobj.value = "/Basic/";
    }else if(objvalue=="Special"){
        pathobj.value = "/Special/";
    }else if(objvalue=="Shop"){
        pathobj.value = "/Shop/";
    }else if(objvalue=="Product"){
        pathobj.value = "/Product/";
    }else if(objvalue=="Class"){
        pathobj.value = "/Class/";
    }else if(objvalue=="Customer"){
        pathobj.value = "/Customer/";
    }
    
}

function rebuildlist()
{ 
//    var labelDiv=document.getElementById("css_edit_div");
//    if(labelDiv==null)return;
//    var textObj=document.getElementById("FormView1_Skin_css");
//    labelDiv.innerHTML = "";
//    var tmbody = textObj.value;
//    tmbody = tmbody.replace(/\n/g,"");
//   
//    var regExp = /\..*?\}/gi;
//    var arr
//    while((arr = regExp.exec(tmbody)) != null)
//    {  
//        if(arr[0]!=null && arr[0]!="")
//        {     
//            var regExp2 = /(\..*?)\{/gi;
//            var css_name=regExp2.exec(arr[0]);
//            if(css_name!=null && css_name!="")
//            {
//               var labelspan = "<div class='label_square' style='width:150px' onclick='selectlabel(" + arr.index + "," + arr.lastIndex + "); return false'>" + css_name[1] + "</div>"; 
//               labelDiv.innerHTML += labelspan;
//            }   
//        }
//    }
}
        
function selectlabel(begin,end)
{
    begin = parseInt(begin);
    end = parseInt(end);
    if(begin != end)
    {
        var textObj=document.getElementById("FormView1_Skin_css");
        var rng = textObj.createTextRange();
        rng.moveEnd("character",-textObj.value.length);
        rng.moveStart("character",-textObj.value.length);
        rng.collapse(true); 
        rng.moveEnd("character",end);
        rng.moveStart("character",begin); 
        rng.select();
    }
}

function modifyCss()
{
    var target =document.getElementById('FormView1_Skin_css');
    target.focus();
    var link;
    var ret;
    var rnd=Math.random();
    link= "Admin_CssParamter.aspx?rnd="+rnd;
    var  isIE = document.all?true:false;
    if(isIE)
    {    
       ret =window.showModalDialog(link,'','dialogWidth:600px; dialogHeight:650px; help: no; scroll: auto; status: no; edge: sunken;');  
    }
    else
    {
       ret=window.open(link,'newWin','modal=yes,width=600px,height=650px,resizable=no,scrollbars=no');

    } 
    if (ret != null)
    {
        if (ret.replace(/^\s+|\s+$/g,"") == "")
        {
            alert("不能输入空值");
        }
        else
        {
            target.focus();
            var tarobj = document.selection.createRange();
            tarobj.text = ret;
        }
    }
   
}

</script>

      <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"  DefaultMode="Edit" Width="100%" DataKeyNames="SkinID">
         <EditItemTemplate>
           <table class="nick"> 
                <tr>
                      <td colspan="2" class="tit">修改风格</td>
                  </tr>                  
                  <tr>
                      <td class="ltd">风格名称：</td>
                      <td class="rtd"><asp:TextBox ID="SkinName" runat="server" Text='<%#Bind("SkinName") %>' />
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="名称不能空" ControlToValidate="SkinName"/></td>
                  </tr>
                  <tr>
                      <td class="ltd">风格类型：</td>
                      <td class="rtd">
                          <asp:DropDownList ID="Skin_Type" runat="server" SelectedValue='<%# Bind("SkinType") %>'>
                             <asp:ListItem Text="首页风格" Value="Index" />
                             <asp:ListItem Text="商城基本风格" Value="Basic" />
                             <asp:ListItem Text="会员中心风格" Value="Member" />                             
                             <asp:ListItem Text="商品风格" Value="Product" />
                             <asp:ListItem Text="商品分类风格" Value="Class" />
                             <asp:ListItem Text="专题风格" Value="Special" />
                             <asp:ListItem Text="店铺风格" Value="Shop" />
                             <asp:ListItem Text="自定义风格" Value="Customer" />
                          </asp:DropDownList>
                          <input type="button" value="刷新风格CSS列表" onclick="rebuildlist()" />
                        <%--  <input type="button" value="打开CSS样式编辑器" onclick="modifyCss()" />--%>
                      </td>
                  </tr>                
                  <tr>
                      <td class="ltd">风格内容：</td>
                      <td class="rtd">
                        <div style="float:left"><asp:TextBox ID="Skin_css" runat="server" Height="300px" 
                            TextMode="MultiLine" Width="450px" CssClass="TextBoxStyle"/></div>
                        </td>
                  </tr>
                  <tr>
                      <td class="ltd">所属方案：</td>
                      <td class="rtd"><asp:TextBox ID="Skin_ProjectName" ReadOnly="true" runat="server" Width="150"  Text='<%# Bind("ProjectName") %>' /> 
                      <asp:RequiredFieldValidator ID="rfv1" runat="server" ErrorMessage="名称不能空" ControlToValidate="Skin_ProjectName"/>
                      </td>
                  </tr>
                  <tr>
                      <td class="ltd">文件保存路径：</td>
                      <td class="rtd">/Skin<%=SkinDir %><asp:TextBox ID="Skin_SavePath" runat="server" Width="200" Text='<%# Bind("SkinPath") %>' />
                       <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="保存路径不能空" ControlToValidate="Skin_SavePath"/>
                      </td>
                  </tr>
                   <tr>
                      <td class="ltd">风格预览图：</td>
                      
                      <td class="rtd">
                         <div style="float:left"><asp:FileUpload ID="FileUpload1" runat="server" /></div>
                         
                         <div id="previewImage"  style="text-align:center; width:100px; height:100px; border:solid 1px gray; float:right;">
                           <asp:Image ID="previewImgShow" runat="server"  ImageUrl='<%# Eval("SkinPreviewImg") %>' Width="80px" Height="100px" />
                         </div>
                         
                    </td>
                  </tr>
                   <tr>
                      <td class="ltd">设为默认：</td>
                      <td class="rtd"><asp:CheckBox ID="IsDefault" runat="server" Checked='<%# Bind("IsDefault") %>' /></td>
                  </tr>
               <tr>
                  <td class="btm" colspan="2">
                      <asp:Button OnClick="onUpdateSkin"  runat="server" Text="修 改" />
                      <input type="reset" name="butreset" value="重 置" />
                      <input name="clae" type="button" value="取 消" onclick="window.close();" />
                  </td>
               </tr>
            </table>
        </EditItemTemplate>      
         <InsertItemTemplate>
              <table class="nick">
                  <tr>
                      <td colspan="2" class="tit">添加风格</td>
                  </tr>                  
                  <tr>
                      <td class="ltd">风格名称：</td>
                      <td class="rtd"><asp:TextBox ID="SkinName" runat="server" Text='<%#Bind("SkinName") %>' />
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="名称不能空" ControlToValidate="SkinName"/>
                      </td>
                  </tr>
                  <tr>
                      <td class="ltd">风格类型：</td>
                      <td class="rtd">
                          <asp:DropDownList ID="Skin_Type" runat="server" SelectedValue='<%# Bind("SkinType") %>' onchange="return selectskinpath(this.value)">
                             <asp:ListItem Text="首页风格" Value="Index" />
                             <asp:ListItem Text="商城基本风格" Value="Basic" />
                             <asp:ListItem Text="会员中心风格" Value="Member" />                             
                             <asp:ListItem Text="商品风格" Value="Product" />
                             <asp:ListItem Text="商品分类风格" Value="Class" />
                             <asp:ListItem Text="自定义风格" Value="Customer" />
                             <asp:ListItem Text="专题风格" Value="Special" />
                             <asp:ListItem Text="店铺风格" Value="Shop" />
                          </asp:DropDownList>
                          <input type="button" value="刷新风格CSS列表" onclick="rebuildlist()" />
                        <%--  <input type="button" value="打开CSS样式编辑器" onclick="modifyCss()" />--%>
                       
                      </td>
                  </tr>
                  <tr>
                      <td class="ltd">风格内容：</td>
                      <td class="rtd"><asp:TextBox ID="Skin_css" runat="server" Height="300px" Text='<%# Bind("SKIN_CSS") %>'
                            TextMode="MultiLine" Width="460px" CssClass="TextBoxStyle"/>
                      </td>
                  </tr>
                  <tr>
                      <td class="ltd">Css文件名：</td>
                      <td class="rtd"><asp:TextBox ID="Skin_ProjectName" runat="server" Width="150" Text='<%# Bind("ProjectName") %>' />.css
                      <asp:RequiredFieldValidator ID="rfv1" runat="server" ErrorMessage="名称不能空" ControlToValidate="Skin_ProjectName"/>
                      </td>
                  </tr>
                  <tr>
                      <td class="ltd">保存到目录：</td>
                      <td class="rtd" >/Skin<%=SkinDir %><asp:TextBox ID="Skin_SavePath" runat="server" Width="200" Text='<%# Bind("SkinPath") %>'/> 默认即可
                       </td>
                  </tr>
                  <tr>
                      <td class="ltd">风格预览图：</td>
                      <td class="rtd">
                         <div style="float:left"><asp:FileUpload ID="FileUpload1" runat="server" /></div>
                         <div id="previewImage"  style="text-align:center; width:100px; height:100px; border:solid 1px gray; float:right;">
                           缩微图
                         </div>
                    </td>
                  </tr>
                   <tr>
                      <td class="ltd">设为默认：</td>
                      <td class="rtd"><asp:CheckBox ID="IsDefault" runat="server" Checked='<%# Bind("IsDefault") %>' /></td>
                  </tr>
                  <tr>
                      <td class="btm" colspan="2">
                          <asp:Button OnClick="onAddSkin" runat="server" Text="添 加" ID="Button1" />
                          <input type="reset" name="butreset" value="重 置" />
                          <input name="clae" type="button" value="取 消" onclick="window.close();" />
                      </td>
                  </tr>
              </table>
	      <table class="adminlist"></table>
          </InsertItemTemplate>
    </asp:FormView>
    
    <script type="text/javascript">rebuildlist();</script>
    
         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetSkinBySkinID"
            TypeName="HoWave.Web.SkinBll" OnInit="ObjectDataSource1_Init">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="0"  Name="SkinID" QueryStringField="SkinID"  Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    
</asp:Content>
