﻿/**
 * 类名: oLoginWin 
 * 描述: 登录窗口
 **/
 oDownLoadFilesWin=function()
 {    
    var wWidth = (Ext.lib.Dom.getViewWidth())/1.5;
    var wHeight = (Ext.lib.Dom.getViewHeight())/1.5;
    FilesWin = new Ext.Window({
        width:wWidth,
        height:wHeight,
        frame: true,
        //autoScroll:true,
        layout:"form",
        iconCls:"addicon",	
//        tbar:Floweditbar,	
        resizable:false,//不可以随意改变大小	
        draggable:true,//是否可以拖动
        collapsible:true, //允许缩放条
        closeAction : 'hide',
        closable:true,        
        modal: 'true', //弹出模态窗体
        buttonAlign:"right",
        html: "<iframe id='flowframe' src='WebAppJs/Business/Files/DownLoad.aspx' frameborder='0' width='100%' height='"+wHeight+"' ></iframe>"
       
         
    }); 

 },
oLoginWin = function(){

    var tpl = new Ext.XTemplate(
        '<tpl for="."><div class="cb_UnitItem">',               
            '<span>{unitname}</span>',    //unitname 单位名称             
        '</div></tpl>'
    );
    
//    var store = new Ext.data.Store({
//        proxy : new Ext.data.HttpProxy({url:oGlobal_Var.sAjaxUrl}),
//        reader : new Ext.data.JsonReader({
//            root:'sys_unit', //表名称
//            totalProperty:"sys_unit_rowscount", //总记录数
//            fields : ['unitid','unitname','unitusercode','mnemonics'] //绑定的字段
//        }),
//        baseParams:{
//            Class:"UnitWebMethod", //提交的类名称
//            Method:"GetUnitGrid"   //提交的方法名称             
//        }
//    });

    var databasestore=new Ext.data.Store({ 
        proxy: new Ext.data.HttpProxy({
        url:"WebApp/Core/RequestServicePage.aspx?Class=Login&Method=GetDataBaseInfo",        
        method:"GET"
        }),
        reader: new Ext.data.JsonReader({
        root: 'database'
        },[
            {name: 'dbname'},
            {name: 'connectionstring'}  
        ])

    });
    
//    var combobox = new Ext.form.ComboBox({
//        id : 'lg_UnitName',
//        fieldLabel : '登录单位',
//        emptyText : '--请选择--',                        
//        triggerAction: 'all',
//        editable : true,
//        store : store,
//        displayField : "unitname",
//        valueField : "unitid",      
//        hiddenName:'lg_UnitId',
//        minChars : 2,
//        width:220,     
//        minListWidth:250,  
//        loadingText: '正在搜索...',
//        pageSize:oGlobal_Var.nCBPageSize,   
//        lazyRender:true,
//        tpl:tpl,
//        itemSelector: 'div.cb_UnitItem'                        
//    });
                    
    this.oLW_FormPanel = new Ext.form.FormPanel({
        frame: true,
        bodyStyle: 'padding:0px 0px 0px 0px',      
        labelAlign: 'right',   
        labelWidth: 60,
        width:400,   
        height:180,
        
        defaults:{
                anchor: '95%'
        },
        
        items:[{},{},{
            layout:"form",
            width:280,
            labelWidth:52,
            items:[
                    new Ext.form.ComboBox({
                    fieldLabel:'年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度',
                    store: databasestore,
                    typeAhead: true,               
                    forceSelection: true,
                    triggerAction: 'all',
                    emptyText:'--年度--',
                    selectOnFocus:true,
                    width:270,
                    editable: false, 
                    allowBlank:false, 
                    blankText:'请选择年度', 
                    id:'dbname',
                    mode: 'remote',
                    displayField:'dbname',
                    valueField: 'connectionstring',
                    name :'connectionstring',
                    hiddenName:'connectionstring'
                    })
                 ]},{},{
            layout:"form",
            width:280,
            labelWidth:52,
            items:[{
                xtype:"textfield",
                fieldLabel:"登录用户",
                width:270,
                name:"lg_UserId",
                value:fnGetCookie("UserID"),
                allowBlank:false,
                blankText:"用户名称不能为空!"
              }]
          },{},{
            layout:"form",
            width:280,
            labelWidth:52,
            items:[{
                xtype:"textfield",
                inputType:"password",
                width:270,
                fieldLabel:"登录密码",
                name:"userpsd"
              }]
          }]
    });
    oLoginWin.superclass.constructor.call(this,{
        title       :  '用户登录',
        width       :  400,
		height      :  250,
		layout      :  "form",
		closable    :  false,        
		modal       :  true, 
		buttonAlign :  "right"
    });
};

Ext.extend( oLoginWin , Ext.Window, {
    /**
     * 初始化窗口事件
     * 窗体创建时触发该事件
     */      
    initComponent : function(){
        this.add(this.oLW_FormPanel);  
        this.addButton({text:'公共文件下载区',minWidth:140},this.fnDownLoadFiles,this);
        this.addButton({text:'确定',minWidth:70},this.fnConfirmLogin,this);
        this.addButton({text:'重置',minWidth:70},this.fnResetLogin,this);
        this.addButton({text:'取消',minWidth:70},this.fnCancelLogin,this);
    },
    
    /**
     * 初始化表单信息
     * 如果项目登录用户信息保留时,执行该事件
     * config = {
     *      lg_UserId     : 'userid',
     *      lg_UnitName   : 'unitid',
     *      lg_UnitId     : 'unitname',
     *      lg_date    : 'lgdate' 
     * }
    **/    
    fnInitFormPanel : function(config){
        this.oLW_FormPanel.form.setValues(config);
    },
    
    /**
     *  确定按钮事件
     *  提交 登录信息
    **/
    fnConfirmLogin : function(){    
        var oThis = this;
        if ( oThis.oLW_FormPanel.getForm().isValid() ){
            oThis.oLW_FormPanel.form.submit({
                url       : "WebApp/Core/RequestServicePage.aspx?Class=Login&Method=UserValidate",
                method    : 'POST',
                params    : {
                    sUserid:  oThis.oLW_FormPanel.getForm().findField("lg_UserId").el.dom.value,
                    sPswd:  oThis.oLW_FormPanel.getForm().findField("userpsd").el.dom.value,
                    sDBInfo:  oThis.oLW_FormPanel.getForm().findField("dbname").value,
                    sDBYear:  oThis.oLW_FormPanel.getForm().findField("dbname").lastSelectionText.replace("年","")
                },
                waitTitle : '提示',
                waitMsg   : '系统正在验证用户,请稍后...',
                success   : function(form,action){
                
                    oThis.fnHideWin();
                    Ext.get("DesktopBody").mask("正在初始化系统桌面,请稍后...",'x-mask-loading'); 
                    document.location.href = 'index.aspx';
                    
                },
                failure   : function(form,action){
                var msg = Ext.decode(action.response.responseText);
                    Ext.MessageBox.alert("警告",msg.errMsg);
                }
            });
        }
    },    /**
     *  公共文件下载区
    **/
    fnDownLoadFiles : function(){    
        if ( FilesWin == null)
            oDownLoadFilesWin();
        FilesWin.show();
    },
    
    /**
     *  取消按钮事件
     *  取消登录
    **/
    fnCancelLogin : function(){
        this.fnHideWin();
    },
    
    /**
     *  重置按钮事件
     *  重置表单
    **/
    fnResetLogin : function(){
        this.oLW_FormPanel.form.reset();
    },
    
    /**
     * 显示登录窗口
     */ 
    fnShowWin : function(){
        this.show();
    },
    
    /**
     * 隐藏登录窗口
     */ 
    fnHideWin : function(){
        this.hide();
    }
});


/**
 * 类名: oSetPswdWin 
 * 描述: 密码修改窗口
 **/
oSetPswdWin = function(){
    this.oPswd_FormPanel = new Ext.form.FormPanel({
        frame:true,
        bodyStyle: 'padding:0px 0px 0px 0px',      
        labelStyle: 'text-align : left',   
        labelWidth: 80,
        width:300,
        height:160,
        defaults:{
            anchor: '95%'
    },
    
    items:[{},{},{
            xtype:'textfield',                 
            inputType:'password',            
            fieldLabel:'原登录密码',
            name:"oldPsWd"
            //allowBlank:false,               
           // blankText:'原登录密码不能为空'
        },{
            xtype:'textfield', 
            inputType:'password',            
            fieldLabel:'新登录密码',
            name:"newPsWd"
            //allowBlank:false,
            //blankText:'新登录密码不能为空'  
        }]
    });
    oSetPswdWin.superclass.constructor.call(this,{
        title         : '密码修改',
        width         : 300,
        height        : 180,
        layout        : 'form',        
        closable      : false,        
	    modal         : true,  
	    buttonAlign   : "right"
    });

};

Ext.extend( oSetPswdWin , Ext.Window, {
    /**
     * 初始化窗口事件
     * 窗体创建时触发该事件
     */      
    initComponent : function(){
        this.add(this.oLW_FormPanel);  
        this.addButton({text:'确定',minWidth:70},this.fnConfirmSet,this);
        this.addButton({text:'取消',minWidth:70},this.fnCancelSet,this);
    },
    
    /**
     *  确定按钮事件
     *  提交 修改密码信息
    **/
    fnConfirmSet : function(){
        
        var oThis = this;
        if( oThis.oPswd_FormPanel.getForm().isValid() ){                   
            oThis.oPswd_FormPanel.form.submit({
                url        : oGlobal_Var.sAjaxUrl,
                method     : "POST",
                params     : {
                    Class    : "UserWebMethod",
                    Method   : "UpdatePassWord"                                
                },
                waitTitle  :  '提示',
                waitMsg    :  '系统正在修改用户密码,请稍后...',
                success    : function(form,action){   
                    Ext.MessageBox.alert("提示","密码修改成功!下次登录请用新密码!");          
                    oThis.fnHideWin();  
                },
                failure    : function(form,action)
                {
                    Ext.MessageBox.alert("警告","修改失败!原密码错误,或连接数据库失败!");
                }   
           });  
        }
    },
    
    /**
     *  确定取消事件
     *  取消 修改密码操作
    **/
    fnCancelSet : function(){
        this.oThis.oPswd_FormPanel.form.reset();
        this.fnHideWin();
    },
    
    /**
     * 显示登录窗口
     */ 
    fnShowWin : function(){
        this.show();
    },
    
    /**
     * 隐藏登录窗口
     */ 
    fnHideWin : function(){
        this.hide();
    }
});

/**
 * 修改密码事件处理
 *
 **/
//function UpdatePassWord()
//{
//    var psdWin = new oSetPswdWin();
//    psdWin.show();
//}

var PsWdWin = null;
var PsWdForm = null;

UpdatePassWord = function(){
    
    if ( PsWdWin == null )
    {
        PsWdForm = new Ext.form.FormPanel({
            frame:true,
            bodyStyle: 'padding:0px 0px 0px 0px',      
            labelStyle: 'text-align : left',   
            labelWidth: 80,
            width:300,
            height:160,
            defaults:{
                anchor: '95%'
        },
        
        items:[{},{},{
                xtype:'textfield',                 
                inputType:'password',            
                fieldLabel:'原登录密码',
                name:"oldPsWd"
                //allowBlank:false,               
                //blankText:'原登录密码不能为空!'
            },{
                xtype:'textfield', 
                inputType:'password',            
                fieldLabel:'新登录密码',
                name:"newPsWd",
                allowBlank:false,
                blankText:'新登录密码不能为空!'  
            }]
        });
        
        PsWdWin = new Ext.Window({
            title:'密码修改',
            width:300,
            height:180,
            layout:'form',
            iconCls:"addicon",
            closable:false,        
		    modal: true, //弹出模态窗体
		    buttonAlign:"right",
		    
		    items:[PsWdForm],
		
		    buttons:[{
                text: "确定",
                minWidth:70,
                handler: function(){
                    if( PsWdForm.getForm().isValid() ){                   
                        PsWdForm.form.submit({
                            url: "WebApp/Core/RequestServicePage.aspx?Class=Login&Method=UpdatePsw", 
                            method: "POST",
                            waitTitle:'提示',
                            waitMsg:'系统正在修改用户密码,请稍后...',
                            success: function(form,action){   
                                Ext.MessageBox.alert("提示","密码修改成功!下次登录请用新密码!");          
                                PsWdWin.hide();  
                                form.reset();
                            },
                            failure:function(form,action)
                            {
                                Ext.MessageBox.alert("提示","修改失败!原密码错误,或连接数据库失败!");
                            }   
                       });
                   }
                }
            },{
	            text:"取消",
	            minWidth:70,
	            handler:function()
	            {
	                PsWdForm.form.reset();	
	                PsWdWin.hide();
	            }
	        }]
        });
    }
    
    PsWdWin.show(); 
    
};