use "maint.vd" use "xaserver.vd" use "xaserverarg.vd" use "profit.vd" use "xcell.vd" use "vbind.vd" use "publiccode.vd" use "xpagecontrol.vd" class PaymentTermEdit : public maint { xdwtable dw_base; xdwtable dw_p; xcell dw_cell; string sCryno; int OnAddrow() { dw_p = dw_base.FindDwTable("line"); int i; double dDueAmount = 0; double dPercnet = 100; for (i = 1 ; i <= dw_p.GetRowCount();i++) { dDueAmount = dw_p.GetItemDouble(i,"DueAmount"); if (dDueAmount > 0) break; dPercnet = dPercnet - dw_p.GetItemDouble(i,"DuePercent"); } int irow = dw_p.InsertRow(0); dw_p.SetItemString(irow,"SeqNo",irow.toString()); if (dDueAmount <= 0) dw_p.SetItemDouble(irow,"DuePercent",dPercnet); return 1; } int OnDeleterow() { dw_p = dw_base.FindDwTable("line"); int row2 = dw_p.GetRow(); if (row2 < 1) return 0; dw_p.DeleteRow(row2); return 1; } string OnCreateTxt() { //dw_1.AcceptText(); //²»Äܼӻᱨ´í int irow; //int icnt = dw_1.GetRowCount(); dw_p = dw_base.FindDwTable("line"); int icnt = dw_p.GetRowCount(); if (icnt < 1) return ""; string sTxt; //double dPercnet = 100; for (irow = 1;irow <= icnt ;irow ++) { string sPaymentMethod = dw_p.GetItemString(irow,"PaymentMethod"); //Ö§¸¶·½Ê½ //string sDueDays = dw_p.GetItemDisplayString(irow,"DueDays"); string sDueDays = dw_p.GetItemString(irow,"DueDays"); //ÆÚÏÞ string sDuePercent = dw_p.GetItemString(irow,"DuePercent"); //±ÈÀý string sDueAmount = dw_p.GetItemString(irow,"DueAmount"); //½ð¶î if (!sPaymentMethod || sPaymentMethod == "") sTxt = sTxt + ""; if (!sDueDays || sDueDays == "") sTxt = sTxt + ""; else { if (sDueDays == "-1") sDueDays = " IN ADVANCE"; else if (sDueDays == "0") sDueDays = " AT SIGHT"; else { if (sPaymentMethod == "T/T") sDueDays = " WITHIN "+sDueDays + " DAYS AFTER SHIPMENT"; else sDueDays = " AT "+sDueDays + " DAYS"; } if (!sDuePercent || sDuePercent == "") { if (!sDueAmount || sDueAmount == "") sTxt = sTxt + ""; else { sTxt = sTxt + sCryno + " " + sDueAmount + " " + sPaymentMethod + sDueDays + ";"; } } else { if (sDuePercent.find(".",0) >= 0) { while (sDuePercent.right(1) == "0") { sDuePercent = sDuePercent.left(sDuePercent.length() - 1); } if (sDuePercent.right(1) == ".") sDuePercent = sDuePercent.left(sDuePercent.length() - 1); } sTxt = sTxt + sDuePercent + "% " + sPaymentMethod+ sDueDays + ";"; } } } sTxt = sTxt.mid(0,sTxt.length() - 1); if (sTxt != "") sTxt = sTxt + "."; return sTxt; } int OnOk() { dw_base.AcceptText(); //ÅжÏÊÇ·ñÓбØÊäֵΪ¿Õ dw_p = dw_base.FindDwTable("line"); double dPercnet = 0; double dAmount = 0; if (dw_p) { int i; for (i=1;i <= dw_p.GetRowCount();i++) { string seqNo = dw_p.GetItemString(i,"SeqNo"); string sPaymentMethod = dw_p.GetItemString(i,"PaymentMethod"); string sDueDays = dw_p.GetItemString(i,"DueDays"); string sDuePercent = dw_p.GetItemString(i,"DuePercent"); dPercnet = dPercnet + sDuePercent.toDouble(); string sDueAmount = dw_p.GetItemString(i,"DueAmount"); dAmount = dAmount + sDueAmount.toDouble(); if (!seqNo) seqNo = ""; if (!sPaymentMethod) sPaymentMethod = ""; if (!sDueDays) sDueDays = ""; if (!sDuePercent) sDuePercent = ""; if (!sDueAmount) sDueAmount = ""; dw_p.SetItemString(i,"SeqNo",i.toString()); string sChargeAll = sPaymentMethod + sDueDays + sDuePercent + sDueAmount; if (sChargeAll != "") { if (sPaymentMethod == "") { alert("Ö§¸¶·½Ê½²»ÄÜΪ¿Õ£¡"); return 0; } if (sDueDays == "") { alert("ÆÚÏÞ²»ÄÜΪ¿Õ£¡"); return 0; } } } } //°Ù·Ö±ÈУÑé if (dw_p.GetRowCount() <= 1 && sChargeAll == "") {} else { if (dPercnet != 100) { if (dAmount <= 0) { alert("±ÈÂʲ»µÈÓÚ100£¡"); return 0; } } } string sTxt = OnCreateTxt(); dw_base.SetItemString(1,"PaymentTermEx",sTxt); //CloseWindow(); return 1; } int OnItemChanged(ref TNotifyEvent evt,int p) { ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); string colname=hdr.colname; string value = hdr.data; int row = hdr.row; if (colname == "DueDays") { xdwtable dw; dw = dw_base.FindDwTable("line"); if (dw) { string sPaymentMethod = dw.GetItemString(row,"PaymentMethod"); if (value == "0") { if (sPaymentMethod == "T/T") { //alert("´ËÖ§¸¶·½Ê½ÆÚÏÞ²»ÄÜΪ 0 £¨AT SIGHT£©"); //return -1; } } else if (value == "-1") { if (sPaymentMethod != "T/T") { alert("´ËÖ§¸¶·½Ê½ÆÚÏÞ²»ÄÜΪ -1£¨IN ADVANCE£©"); return -1; } } } } //Éú³ÉÖ§¸¶Ìõ¿îÎı¾ if (colname == "PaymentMethod" || colname == "DueDays" || colname == "DuePercent" || colname == "DueAmount") { string sTxt = OnCreateTxt(); dw_base.SetItemString(1,"Description",sTxt); } return 1; } int OnClick(ref TNotifyEvent evt,int p) { ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); string value = hdr.data; string colname = hdr.colname; int row = hdr.row; xaserverarg arg=new xaserverarg; arg.setNativePointer(arg.CreateInstance()); //alert(row.toString()); xdwtable dw; dw = dw_base.FindDwTable("line"); //alert(colname); if (dw) { if (colname == "DuePercent") { int i; int icnt = dw.GetRowCount(); if (icnt < 1) return 0; double dDueAmount = 0; for (i = 1 ; i <= icnt ; i++) { dDueAmount = dw.GetItemDouble(i,"DueAmount"); if (dDueAmount > 0) break; } dw_cell.setNativePointer(dw_base.QueryItem("ixcell")); if (dDueAmount > 0) { dw.SetColumnProp("DuePercent","cellprotect","±£»¤");//±£»¤ÖÐÎĹæ¸ñ } else { dw.SetColumnProp("DuePercent","cellprotect","²»±£»¤");//±£»¤ÖÐÎĹæ¸ñ } } if (colname == "DueAmount") { int j; int jcnt = dw.GetRowCount(); if (jcnt < 1) return 0; double dDuePercent = 0; for (j = 1 ; j <= jcnt ; j++) { dDuePercent = dw.GetItemDouble(j,"DuePercent"); if (dDuePercent > 0) break; } if (dDuePercent > 0) { dw.SetColumnProp("DueAmount","cellprotect","±£»¤");//±£»¤ÖÐÎĹæ¸ñ } else { dw.SetColumnProp("DueAmount","cellprotect","²»±£»¤");//±£»¤ÖÐÎĹæ¸ñ } } } return 1; } //±£´æÊ¼þ int OnSave() { if(OnOk()<1)return 0; dw_base = GetControl("dw_base"); dw_base.AcceptText(); //dw_bank.AcceptText(); xml x = new xml; xaserverarg arg = new xaserverarg; x.setNativePointer(xml::CreateInstance()); dw_base.DwUpdateAllTo(x.GetXmlDoc()); //dw_bank.DwUpdateAllTo(x.GetXmlDoc()); //alert(x.GetXml()); arg.setNativePointer(arg.CreateInstance()); arg.AddArg("content",x.GetXml()); arg.AddArg("dbmap","FND_PaymentTerm.dbmap"); //return 0; if (getUrl("/sale/data/PaymentTerm/entity/company/save",arg.GetString(),x) != 1) { alert("±£´æÊ§°Ü!"); return 0; } else { //alert(x.GetXml()); if(x.GetXmlDoc().selectSingleNode("error")) { alert("±£´æ³ö´í2!"); return 0; } arg.AddArg("ret","Ok"); xwin::MessageBox(GetHWND(),"±£´æ³É¹¦£¡","Ìáʾ",0); //alert("±£´æ³É¹¦"); dw_base.ResetUpdateStatus(); //dw_bank.ResetUpdateStatus(); //xwin::SendMessage(parenthwnd, 0x401, "maintsave", 0);//֪ͨlist´°¿Ú¸üÐÂÊý¾Ý } //alert("±£´æ³É¹¦"); dw_base.Redraw(); //dw_bank.Redraw(); CloseWindow(); return 0; } int OnCmdDispatch(string comdid) { //alert(comdid); if(comdid=="xmOk") OnSave(); else if(comdid=="addrow") OnAddrow(); else if(comdid=="deleterow") OnDeleterow(); //else if(comdid=="AddRow") OnAddRow(); //else if(comdid=="InsertRow") OnInsertRow(); //else if(comdid=="DeleteRow")OnDeleteRow(); return 1; } //°´Å¥Ê¼þ int OnXCommand(ref TXCommandEvent evt,int p) { return OnCmdDispatch(evt.pStrID); } int OnAttachEvent() { //°´Å¥Ê¼þ AttachEvent("WM_XCOMMAND",OnXCommand); //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ //AttachEvent("WM_SETFOCUS",OnSetFocus); AttachEvent("dw_base","DWV_ITEMCHANGED",OnItemChanged); AttachEvent("dw_base","DWV_CLICKED",OnClick); } int OnRetrieve() { if(GetParam()) { int p = GetParam(); xaserverarg args = new xaserverarg; args.setNativePointer(p); string id = args.GetArgString("EntityID"); //alert(id); if(id=="new") { //OnAddNew(); } else { xml x = new xml; x.setNativePointer(xml::CreateInstance()); if(getUrl("/sale/data/PaymentTerm/entity/base12", args.GetString(), x) != 1) { alert("´íÎó"); return -1; } //alert(x.GetXml()); dw_base.Retrieve(x); //dw_bank.Retrieve(x); dw_base.Redraw(); //dw_bank.Redraw(); } } return 1; } int onload() { //maint::onload(); //maint::onloaded(); dw_base = GetControl("dw_base"); dw_cell = new xcell; dw_cell.setNativePointer(dw_base.QueryItem("ixcell")); dw_base.openUrl("/sale/view/Payment/template/Payment/maint"); //alert("1233"); OnRetrieve(); OnAttachEvent(); //dw_base = GetControl("dw_base"); } int onloaded() { //maint::onloaded(); //alert("response"); //dw_base = GetControl("dw_base"); //dw_cell = new xcell; //dw_cell.setNativePointer(dw_base.QueryItem("ixcell")); return -1; } };