///<reference path="/Scripts/ExtPB_Net.js" />
///<reference path="/Scripts/MyExtPB.js" />
///<reference path="/Scripts/ExtPB_Dll_Pb_Http.js" />
///<reference path="/Scripts/MyExtPb_Input.js" />

function W_CG_HZ_Base() {

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var st_title = new StaticText(requestor);
    var dw_temp = new DataWindow(requestor);
    var dw_format = new DataWindow(requestor);
    var dw_list = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ContextMenuStrip1 = new ContextMenu(requestor);

    if (typeof (this.bind) == "function") var baseBind = this.bind;
    this.bind = function (win) {
        self.Instance = win;
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (st_title == null) st_title = new StaticText(requestor);
        st_title.Attach(win.Control("st_title"));
        if (dw_temp == null) dw_temp = new DataWindow(requestor);
        dw_temp.Attach(win.Control("dw_temp"));
        if (dw_format == null) dw_format = new DataWindow(requestor);
        dw_format.Attach(win.Control("dw_format"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ContextMenuStrip1 == null) ContextMenuStrip1 = new ContextMenu(requestor);
        ContextMenuStrip1.Attach(win.Control("ContextMenuStrip1"));

        if (typeof (self.Query) == "function")
            win.AttachEvent("btn_Query", "Clicked", self.Query);

        if (typeof (self.print) == "function")
            win.AttachEvent("btn_Print", "Clicked", self.print);

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_Exit", "Clicked", self.Exit);

        if (typeof (self.ReportSave) == "function")
            win.AttachEvent("xxxxxxaToolStripMenuItem", "Clicked", self.ReportSave);

        if (typeof (self.ReportOp) == "function")
            win.AttachEvent("列格式保存ToolStripMenuItem", "Clicked", self.ReportOp);

        if (typeof (self.ReportClare) == "function")
            win.AttachEvent("清空当前窗口所有格式ToolStripMenuItem", "Clicked", self.ReportClare);

    }

    if (typeof (this.unbind) == "function") var baseUnBind = this.unbind;
    this.unbind = function () {
        self.Instance = null;
        if (typeof (this.Release) == "function") this.Release();
        if (typeof (baseUnBind) == "function") baseUnBind();

        st_title.Detach(); st_title = null;
        dw_temp.Detach(); dw_temp = null;
        dw_format.Detach(); dw_format = null;
        dw_list.Detach(); dw_list = null;
        tb_1.Detach(); tb_1 = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    
    //#region  变量定义
    var ChildDWCheckValue = "";
    var curCdbh = "";
    var curUserId = "";
    var curBbmc = "";
    webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceForDwSyndax.ashx");
    var curW_Base_Report_Open_Mx = new W_Base_Report_Open_Mx();
    //#endregion  

    //#region  报表格式保存
    this.ReportSave = function () {
        dw_format.Reset();
        var curChildDWCheckValue = ChildDWCheckValue;
        if (curChildDWCheckValue.length > 1) {
            curChildDWCheckValue = curChildDWCheckValue.substring(0, curChildDWCheckValue.length - 1);
         
            var tempValue = curChildDWCheckValue.split(",");
          
            for (var i = 0; i < tempValue.length; i++) {
        
                var curRows = dw_format.InsertRow(0);
                dw_format.SetItem(curRows, 'cdbh', curCdbh);
                dw_format.SetItem(curRows, 'yhbh', curUserId);
                dw_format.SetItem(curRows, 'col', tempValue[i]);
                dw_format.SetItem(curRows, 'mrgxtj', "1");
                dw_format.SetItem(curRows, 'bbmc', curBbmc);
            }
        }

        var curGouCol = "";
        if (curUserId == "" || curBbmc == "") {
            requestor.MessageBox("提示", "请查询后再保存格式", ICON.Information);
            return;
        }
        var curColNames = "";

        //#region 列
        var colCount = dw_list.Describe("DataWindow.Column.Count");
        for (var k = 1; k <= colCount; k++) {
            var ls_col = dw_list.Describe("#" + k + ".Name"); // PB对应字段名  
            var li_row = dw_format.InsertRow(0);
            dw_format.SetItem(li_row, 'cdbh', curCdbh);
            dw_format.SetItem(li_row, 'bbmc', curBbmc);
            dw_format.SetItem(li_row, 'yhbh', curUserId);
            dw_format.SetItem(li_row, 'col', ls_col);
            dw_format.SetItem(li_row, 'col_hz', dw_list.Describe(ls_col + "_t.text"));
            dw_format.SetItem(li_row, 'col_x', parseInt(dw_list.Describe(ls_col + ".x")));
            dw_format.SetItem(li_row, 'width', parseInt(dw_list.Describe(ls_col + ".width")));
            dw_format.SetItem(li_row, 'visible', dw_list.Describe(ls_col + ".visible"));
            dw_format.SetItem(li_row, 'col_type', dw_list.Describe(ls_col + ".Coltype"));
            dw_format.SetItem(li_row, 'obj_type', dw_list.Describe(ls_col + ".type"));
            dw_format.SetItem(li_row, 'font_face', dw_list.Describe(ls_col + ".Font.Face"));
            dw_format.SetItem(li_row, 'font_height', dw_list.Describe(ls_col + ".Font.Height"));
            dw_format.SetItem(li_row, 'font_weight', dw_list.Describe(ls_col + ".Font.Weight"));
            var ls_font_italic = dw_list.Describe(ls_col + ".Font.Italic");
            if (ls_font_italic == '?') {
                ls_font_italic = '0'
            }
            dw_format.SetItem(li_row, 'font_italic', ls_font_italic)

            var ls_font_underline = dw_list.Describe(ls_col + ".Font.Underline")

            if (ls_font_underline == '?') {
                ls_font_underline = '0'
            }
            dw_format.SetItem(li_row, 'font_underline', ls_font_underline)

            ls_col_border = dw_list.Describe(ls_col + ".Border")
            dw_format.SetItem(li_row, 'col_border', ls_col_border)

            ls_color = dw_list.Describe(ls_col + ".Color")
            dw_format.SetItem(li_row, 'color', ls_color)

            ls_format = dw_list.Describe(ls_col + ".Format")
            dw_format.SetItem(li_row, 'format', ls_format)

            ls_alignment = dw_list.Describe(ls_col + ".Alignment")

            dw_format.SetItem(li_row, 'alignment', ls_alignment);

            li_tabsequence = parseInt(dw_list.Describe(ls_col + ".TabSequence"))
            dw_format.SetItem(li_row, 'tabsequence', li_tabsequence);

            ls_bg_mode = dw_list.Describe(ls_col + ".Background.Mode")
            dw_format.SetItem(li_row, 'bg_mode', ls_bg_mode)

            ls_bg_color = dw_list.Describe(ls_col + ".Background.Color")
            dw_format.SetItem(li_row, 'bg_color', ls_bg_color);


        }
        //#endregion

        //#region  计算列
        var ls_objects = dw_list.Describe("DataWindow.Objects");
        var ls_objectsArr = ls_objects.split("\t");

        for (var w = 0; w < ls_objectsArr.length; w++) {
            var ls_name = ls_objectsArr[w];
            var ls_type = dw_list.Describe(ls_name + ".type");
            var ls_band = dw_list.Describe(ls_name + ".band");
            if (ls_type == "compute" && ls_band == "detail") {
                var ls_col = ls_name;
                var li_row = dw_format.InsertRow(0);
                dw_format.SetItem(li_row, 'cdbh', curCdbh);
                dw_format.SetItem(li_row, 'bbmc', curBbmc);
                dw_format.SetItem(li_row, 'yhbh', curUserId);
                dw_format.SetItem(li_row, 'col', ls_col);

                dw_format.SetItem(li_row, 'col_hz', dw_list.Describe(ls_col + "_t.text"))

                dw_format.SetItem(li_row, 'col_x', parseInt(dw_list.Describe(ls_col + ".x")))

                dw_format.SetItem(li_row, 'width', parseInt(dw_list.Describe(ls_col + ".width")))


                dw_format.SetItem(li_row, 'visible', dw_list.Describe(ls_col + ".visible"))


                dw_format.SetItem(li_row, 'col_type', dw_list.Describe(ls_col + ".Coltype"))


                dw_format.SetItem(li_row, 'obj_type', dw_list.Describe(ls_col + ".type"))


                dw_format.SetItem(li_row, 'font_face', dw_list.Describe(ls_col + ".Font.Face"))


                dw_format.SetItem(li_row, 'font_height', dw_list.Describe(ls_col + ".Font.Height"))


                dw_format.SetItem(li_row, 'font_weight', dw_list.Describe(ls_col + ".Font.Weight"))

                var ls_font_italic = dw_list.Describe(ls_col + ".Font.Italic");
                if (ls_font_italic == '?') {
                    ls_font_italic = '0'
                }
                dw_format.SetItem(li_row, 'font_italic', ls_font_italic)

                var ls_font_underline = dw_list.Describe(ls_col + ".Font.Underline")

                if (ls_font_underline == '?') {
                    ls_font_underline = '0'
                }
                dw_format.SetItem(li_row, 'font_underline', ls_font_underline)

                ls_col_border = dw_list.Describe(ls_col + ".Border")
                dw_format.SetItem(li_row, 'col_border', ls_col_border)

                ls_color = dw_list.Describe(ls_col + ".Color")
                dw_format.SetItem(li_row, 'color', ls_color)

                ls_format = dw_list.Describe(ls_col + ".Format")
                dw_format.SetItem(li_row, 'format', ls_format)

                ls_alignment = dw_list.Describe(ls_col + ".Alignment")

                dw_format.SetItem(li_row, 'alignment', ls_alignment);

                li_tabsequence = parseInt(dw_list.Describe(ls_col + ".TabSequence"))
                dw_format.SetItem(li_row, 'tabsequence', li_tabsequence);

                ls_bg_mode = dw_list.Describe(ls_col + ".Background.Mode")
                dw_format.SetItem(li_row, 'bg_mode', ls_bg_mode)

                ls_bg_color = dw_list.Describe(ls_col + ".Background.Color")
                dw_format.SetItem(li_row, 'bg_color', ls_bg_color);

                ls_expression = dw_list.Describe(ls_col + ".Expression");
                dw_format.SetItem(li_row, 'expression', ls_expression);
            }
        }
        //#endregion

        //#region 保存

        var dwChanges = dw_format.GetChanges();
        if (dwChanges == "") {
            requestor.MessageBox("提示", "没有格式变更，不需要保存", ICON.Information);
            return;
        }
        $.ajax({
            type: "POST",
            url: "/Service/Ajax_XT.ashx",
            async: false,
            data: { curFlag: "report_format", dwObjects: dw_format.GetDataObject(), dwChanges: dwChanges, curYhbh: curUserId, curCdbh: curCdbh, curBbmc: curBbmc },
            success: function (msg) {
                if (msg == "OK") {
                    requestor.MessageBox("提示", "保存成功", ICON.Information);

                    dw_format.ResetUpdate();

                    return;
                }
                else {
                    requestor.MessageBox("提示", "出错了", ICON.StopSign);
                }
            },
            error: function (req) {
                requestor.MessageBox("提示", req.responseText, ICON.StopSign);
            }
        });
        //#endregion 
    }
    //#endregion  

    //#region 格式保存#报表格式操作
    this.ReportOp = function () {
        curW_Base_Report_Open_Mx.SetDataWindow(self, curUserId, curCdbh, curBbmc, "curParent.TongJi();");
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.Base.W_Base_Report_Open_Mx"), curW_Base_Report_Open_Mx, null);
    }
    //#endregion  

    //#region 格式保存#报表格式清空
    this.ReportClare = function () {

        for (var i = dw_format.RowCount(); i > 0; i--) {
            dw_format.DeleteRow(i)
        }

        var dwChanges = dw_format.GetChanges();
        if (dwChanges == "") {
            requestor.MessageBox("提示", "没有格式变更，不需要保存", ICON.Information);
            return;
        }
        $.ajax({
            type: "POST",
            url: "/Service/Ajax_XT.ashx",
            async: false,
            data: { curFlag: "report_format_delete", dwObjects: dw_format.GetDataObject(), dwChanges: dwChanges, curYhbh: curUserId, curCdbh: curCdbh, curBbmc: curBbmc },
            success: function (msg) {
                if (msg == "OK") {
                    requestor.MessageBox("提示", "清除成功", ICON.Information);
                    dw_format.ResetUpdate();
                    self.TongJi();
                    return;
                }
                else {
                    requestor.MessageBox("提示", "出错了", ICON.StopSign);
                }
            },
            error: function (req) {
                requestor.MessageBox("提示", req.responseText, ICON.StopSign);
            }
        });

    }
    //#endregion

    this.SetValue = function (str1, str2, str3, str4) {
       
        ChildDWCheckValue = str1;
        curBbmc = str2;
        curCdbh = str3;
        curUserId = str4;
    }

    this.Exit = function () {
        setTimeout("window.close()", 100);
    }


    var curTitleName = "";
    var curHeadString = "";
    var curFootString = "";


   

}