///<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 ZhangDanHeXiao_Edit() {

	 var self=this;
	 var requestor= new PBWindow();
	 var dw_2= new DataWindow( requestor );
	 var cb_Exit= new CommandButton( requestor );
	 var st_Ye= new StaticText( requestor );
	 var dw_1= new DataWindow( requestor );

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

		 if(requestor == null ) requestor= new PBWindow();
		 requestor.Attach(win);
		 if(dw_2 == null ) dw_2= new DataWindow( requestor );
		 dw_2.Attach( win.Control( "dw_2") ); 
		 if(cb_Exit == null ) cb_Exit= new CommandButton( requestor );
		 cb_Exit.Attach( win.Control( "cb_Exit") ); 
		 if(st_Ye == null ) st_Ye= new StaticText( requestor );
		 st_Ye.Attach( win.Control( "st_Ye") ); 
		 if(dw_1 == null ) dw_1= new DataWindow( requestor );
		 dw_1.Attach( win.Control( "dw_1") ); 

		 if(typeof(self.PostOpen)=="function") 
			 win.AttachEvent("window","PostOpen",self.PostOpen); 

		 if(typeof(self.ClickedMx)=="function") 
			 win.AttachEvent("dw_2","Clicked",self.ClickedMx); 

		 if(typeof(self.EditChangedMx)=="function") 
			 win.AttachEvent("dw_2","EditChanged",self.EditChangedMx); 

		 if(typeof(self.GetFocusDw)=="function") 
			 win.AttachEvent("dw_2","GetFocus",self.GetFocusDw); 

		 if(typeof(self.ItemChangedMx)=="function") 
			 win.AttachEvent("dw_2","ItemChanged",self.ItemChangedMx); 

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

		 if(typeof(self.DoubleClickedTop)=="function") 
			 win.AttachEvent("dw_1","DoubleClicked",self.DoubleClickedTop); 

		 if(typeof(self.EditChangedTop)=="function") 
			 win.AttachEvent("dw_1","EditChanged",self.EditChangedTop); 

		 if(typeof(self.GetFocusDw)=="function") 
			 win.AttachEvent("dw_1","GetFocus",self.GetFocusDw); 

		 if(typeof(self.ItemChangedTop)=="function") 
			 win.AttachEvent("dw_1","ItemChanged",self.ItemChangedTop); 

	 }

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

		 dw_2.Detach(); dw_2=null; 
		 cb_Exit.Detach(); cb_Exit=null; 
		 st_Ye.Detach(); st_Ye=null; 
		 dw_1.Detach(); dw_1=null; 
		 requestor.Detach(); requestor=null; 

		 setTimeout(CollectGarbage, 100); 
	 }

	 //以上代码由设计器自动生成,请不要手工修改
	 //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改

	 var curParDw = "";
    var CurKhye = 0;

    var webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceCaiWu.ashx");

    this.PostOpen = function () {
        CurKhxje = parseFloat(requestor.GetParm("CurKhxje"));
        st_Ye.SetText(CurKhxje + "");
        dw_2.Modify(" DataWindow.Readonly=yes");
    }

    this.SetDataWindow = function (dw) {
        curParDw = dw;
    }

    //#region 作废

//    this.Add = function () {
//        var CurRow = dw_1.InsertRow(0);
//        webReq.Invoke("GetHXSJPzh", "FunctionID=" + FunctionID);
//        if (webReq.StatusCode() == 200) {
//            curPzh = webReq.ResponseText();
//            dw_1.SetItem(CurRow, "pzh", curPzh);
//            dw_1.SetItem(CurRow, "kdr", CurUserId);
//            dw_1.Modify(" kdrxm.text='" + CurUserId + "' ");
//            st_Ye.SetText("0");
//            cbx_XsSydj.SetVisible(false);

//            dw_1.SetItem(CurRow, "hxzdje", 0);
//            dw_1.SetItem(CurRow, "skje", 0);
//            dw_1.SetItem(CurRow, "sjye", 0);

//            dw_3.Reset();
//        } else {
//            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
//            return;
//        }
//    }

//    this.Edit = function () {
//        dw_1.Modify(" bmbh.protect='1' gysbh.protect='1' ");
//        dw_2.SetFilter(" flag='1' ");
//        dw_2.Filter();
//        curPzh = requestor.GetParm("CurPzh");

//        dw_khye.Retrieve(dw_1.GetItemString(1, "gysbh"), dw_1.GetItemString(1, "bmbh"));
//        CurKhye = dw_khye.GetItemNumber(1, "kyye");
//        st_Ye.SetText(CurKhye + "");
//    }

//    this.GetFocusDw = function () {
//        dw_1.AcceptText();
//        dw_2.AcceptText();
//    }

//    this.ItemChangedTop = function (row, dwoName, data) {
//        if (dwoName == "bmbh") {
//            dw_1.GetChild("bmbh", dwc);
//            var curRow = dwc.Find(" bmbh='" + data + "' ", 1, dwc.RowCount());
//            dw_1.SetItem(dw_1.GetRow(), "bmmc", dwc.GetItemString(curRow, "bmmc"));
//            var gysbh = dw_1.GetItemString(1, "gysbh");
//            if (gysbh != "") {
//                dw_khye.Retrieve(gysbh, data);
//                CurKhye = dw_khye.GetItemNumber(1, "kyye");
//                st_Ye.SetText(CurKhye + "");
//                dw_2.RetrieveEx(" cw_yfkzd.gysbh='" + gysbh + "' and  cw_yfkzd.bmbh='" + data + "'");
//            }
//        } else if (dwoName == "gysbh") {
//            dw_1.GetChild("gysbh", dwc);
//            var curRow = dwc.Find(" gysbh='" + data + "' ", 1, dwc.RowCount());
//            dw_1.SetItem(dw_1.GetRow(), "gysmc", dwc.GetItemString(curRow, "gysmc"));
//            var bmbh = dw_1.GetItemString(1, "bmbh");

//            if (bmbh != "") {
//                dw_khye.Retrieve(data, bmbh);
//                CurKhye = dw_khye.GetItemNumber(1, "kyye");
//                st_Ye.SetText(CurKhye + "");
//                dw_2.RetrieveEx(" cw_yfkzd.gysbh='" + data + "' and  cw_yfkzd.bmbh='" + bmbh + "'");
//            }
//        }
//    }

//    this.ItemChangedMx = function (row, dwoName, data) {
//        if (dwoName == "bchxje") {
//            var NumData = parseFloat(data);
//            var curFzje = dw_2.GetItemNumber(row, dwoName);
//            if (CurKhye - (NumData - curFzje) < 0) {
//                if (requestor.MessageBox("提示", "供应商余额不足，是否仍要核销？", ICON.Question, BUTTON.YesNo) == 2) {
//                    dw_2.SetItem(row, dwoName, curFzje);
//                    return 1;
//                }
//                CurKhye = CurKhye - (NumData - curFzje);
//                st_Ye.SetText(CurKhye + "");
//                dw_1.SetItem(1, "hxzdje", dw_1.GetItemNumber(1, "hxzdje") + (NumData - curFzje));
//                dw_2.SetItem(row, "sqje", dw_2.GetItemNumber(row, "sqje") - (NumData - curFzje));
//            } else {
//                CurKhye = CurKhye - (NumData - curFzje);
//                st_Ye.SetText(CurKhye + "");
//                dw_1.SetItem(1, "hxzdje", dw_1.GetItemNumber(1, "hxzdje") + (NumData - curFzje));
//                dw_2.SetItem(row, "sqje", dw_2.GetItemNumber(row, "sqje") - (NumData - curFzje));
//            }
//            if (dw_2.GetItemNumber(row, "bchxje") + dw_2.GetItemNumber(row, "zrje") != 0) {
//                dw_2.SetItem(row, "flag", "1");
//            } else {
//                dw_2.SetItem(row, "flag", "0");
//            }
//        } else if (dwoName == "zrje") {
//            var NumData = parseFloat(data);
//            var curFzje = dw_2.GetItemNumber(row, dwoName);
//            dw_1.SetItem(1, "hxzdje", dw_1.GetItemNumber(1, "hxzdje") + (NumData - curFzje));
//            dw_2.SetItem(row, "sqje", dw_2.GetItemNumber(row, "sqje") - (NumData - curFzje));
//            if (dw_2.GetItemNumber(row, "bchxje") + dw_2.GetItemNumber(row, "zrje") != 0) {
//                dw_2.SetItem(row, "flag", "1");
//            } else {
//                dw_2.SetItem(row, "flag", "0");
//            }
//        }
//    }

//    this.ClickedMx = function (x, y, row, dwoName) {
//        if (dwoName == "flag") {
//            var flag = dw_2.GetItemString(row, dwoName);
//            var curFzje = dw_2.GetItemNumber(row, "bchxje");
//            var NumData = 0;
//            if (flag != "1") {
//                NumData = dw_2.GetItemNumber(row, "zdje") - dw_2.GetItemNumber(row, "zrje") - dw_2.GetItemNumber(row, "yhxje");
//            }
//            if (CurKhye - (NumData - curFzje) < 0) {
//                if (requestor.MessageBox("提示", "供应商余额不足，是否仍要核销？", ICON.Question, BUTTON.YesNo) == 2) {
//                    return 1;
//                }
//                dw_2.SetItem(row, "bchxje", NumData);
//                CurKhye = CurKhye - (NumData - curFzje);
//                st_Ye.SetText(CurKhye + "");
//                dw_1.SetItem(1, "hxzdje", dw_1.GetItemNumber(1, "hxzdje") + (NumData - curFzje));
//                dw_2.SetItem(row, "sqje", dw_2.GetItemNumber(row, "sqje") - (NumData - curFzje));
//            } else {
//                dw_2.SetItem(row, "bchxje", NumData);
//                CurKhye = CurKhye - (NumData - curFzje);
//                st_Ye.SetText(CurKhye + "");
//                dw_1.SetItem(1, "hxzdje", dw_1.GetItemNumber(1, "hxzdje") + (NumData - curFzje));
//                dw_2.SetItem(row, "sqje", dw_2.GetItemNumber(row, "sqje") - (NumData - curFzje));
//            }
//            if (flag == "1") {
//                dw_2.SetItem(row, dwoName, "0");
//            } else {
//                dw_2.SetItem(row, dwoName, "1");
//            }
//            dw_2.AcceptText();
//            return 1;
//        }
//    }

//    this.Ok = function () {
//        dw_1.AcceptText();
//        dw_2.AcceptText();
//        var curHxzdje = dw_2.GetItemNumber(1, "sumbchxje");

//        var dw1Change = dw_1.GetChanges();
//        var dw2Change = dw_2.GetChanges();
//        if ((dw1Change + dw2Change) == "") {
//            requestor.MessageBox("提示", "没有数据修改！", ICON.Information);
//            return;
//        }
//        dw_1.SetItem(1, "skje", curHxzdje);
//        dw_3.ResetUpdate();
//        var rowCount = dw_2.RowCount();
//        var hxrq = dw_1.GetItemDate(1, "kdrq");
//        var curHxje = 0;
//        var curZrje = 0;
//        var curRow = 0;
//        var mxdh = 1;
//        if (curEditModel == "ADD") {
//            for (var i = 1; i <= rowCount; i++) {
//                curHxje = dw_2.GetItemNumber(i, "bchxje");
//                curZrje = dw_2.GetItemNumber(i, "zrje");
//                if (curHxje + curZrje != 0) {
//                    curRow = dw_3.InsertRow(0);
//                    dw_3.SetItem(curRow, "pzh", curPzh);
//                    dw_3.SetItem(curRow, "mxdh", mxdh + "");
//                    mxdh += 1;
//                    dw_3.SetItem(curRow, "zdbh", dw_2.GetItemString(i, "zdbh"));
//                    dw_3.SetItem(curRow, "hxzdje", curHxje);
//                    dw_3.SetItem(curRow, "zrje", curZrje);
//                    dw_3.SetItem(curRow, "hxr", CurUserId);
//                    dw_3.SetItem(curRow, "hxrq", hxrq);
//                }
//            }
//        } else if (curEditModel == "EDIT") {
//            var curMaxMxdh = dw_3.GetItemString(dw_3.RowCount(), "mxdh");
//            if (curMaxMxdh != "") {
//                mxdh = parseInt(curMaxMxdh) + 1;
//            }
//            for (var i = 1; i <= rowCount; i++) {
//                curHxje = dw_2.GetItemNumber(i, "bchxje");
//                curZrje = dw_2.GetItemNumber(i, "zrje");
//                var zdbh = dw_2.GetItemString(i, "zdbh");
//                curRow = dw_3.Find(" zdbh='" + zdbh + "' ", 1, dw_3.RowCount());
//                if (curHxje + curZrje != 0) {
//                    if (curRow > 0) {
//                        dw_3.SetItem(curRow, "hxzdje", curHxje);
//                        dw_3.SetItem(curRow, "zrje", curZrje);
//                        dw_3.SetItem(curRow, "hxr", CurUserId);
//                        dw_3.SetItem(curRow, "hxrq", hxrq);
//                    } else {
//                        curRow = dw_3.InsertRow(0);
//                        dw_3.SetItem(curRow, "pzh", curPzh);
//                        dw_3.SetItem(curRow, "mxdh", mxdh + "");
//                        mxdh += 1;
//                        dw_3.SetItem(curRow, "zdbh", dw_2.GetItemString(i, "zdbh"));
//                        dw_3.SetItem(curRow, "hxzdje", curHxje);
//                        dw_3.SetItem(curRow, "zrje", curZrje);
//                        dw_3.SetItem(curRow, "hxr", CurUserId);
//                        dw_3.SetItem(curRow, "hxrq", hxrq);
//                    }
//                } else {
//                    if (curRow > 0) {
//                        dw_3.DeleteRow(curRow);
//                    }
//                }
//            }
//        }
//        dw_3.AcceptText();
//        var dw1Object = dw_1.GetDataObject();
//        dw1Change = dw_1.GetChanges();
//        var dw3Object = dw_3.GetDataObject();
//        var dw3Change = dw_3.GetChanges();
//        if (dw_3.RowCount() < 1) {
//            requestor.MessageBox("提示", "没有数据需要保存！", ICON.Information);
//            return;
//        }
//        webReq.Invoke("HeXiaoSave", "dw1Object=" + dw1Object + "&dw1Change=" + dw1Change + "&dw2Object=" + dw3Object + "&dw2Change=" + dw3Change);
//        if (webReq.StatusCode() == 200) {
//            requestor.MessageBox("提示", "保存成功！", ICON.Information);
//            if (curEditModel == "ADD") {
//                dw_1.Reset();
//                dw_1.ResetUpdate();
//                dw_2.Reset();
//                dw_2.ResetUpdate();
//                dw_3.Reset();
//                dw_3.ResetUpdate();
//                self.Add();
//            } else {
//                dw_1.ResetUpdate();
//                dw_2.ResetUpdate();
//                dw_3.ResetUpdate();
//            }
//        } else {
//            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
//        }
//        return 1;
//    }

//    this.XsSydj = function (ch) {
//        if (ch) {
//            dw_2.SetFilter("");
//        } else {
//            dw_2.SetFilter(" flag='1' ");
//        }
//        dw_2.Filter();
//    }
    //#endregion
    this.Exit = function () {
        requestor.Close();
    }
}