zoukankan      html  css  js  c++  java
  • Microsoft Dynamics CRM 2011 表单OnSave(ExecutionObj)、OnChange、PageOnLoad事件理解

    一、OnLoad

    function PageOnLoad() {
    //隐藏现有的lable和lookup框,替换成自定义的按钮选择框
    if (document.getElementById("new_returninfoid_d")) {
    document.getElementById("new_returninfoid_d").style.display = "none";
    }
    document.getElementById("new_returninfoid_c").innerHTML = document.getElementById("new_returninfoid_c").innerHTML + "<TABLE ><TBODY><TR><TD class="ms-crm-FieldLabel-LeftAlign"><BUTTON accessKey=I id=btnRun1 class="ms-crm-Button" onclick=\"ReturninfoSelect();\">选择退料部品(<U>I</U>)</BUTTON> </TD></TR></TBODY></TABLE>";
    var labelList = document.getElementsByTagName("label");
    for (var index in document.getElementsByTagName("label")) {
    if (document.getElementsByTagName("label")[index].innerText == "退料单明细") {
    document.getElementsByTagName("label")[index].style.display = "none";
    }
    }
    }

     

    /*
    描述:部品更换单明细窗体上的 选择退料部品按钮
    在更换单明细中选择退料单,过滤条件为与更换单网点关联的新件不良换货类型的、
    并且已更换数量小于收货数量的退料单。
    自动带出退货部品代码、退货部品SN号、单价。
    */
    function ReturninfoSelect() {
    var replaceShopId = getPartsReplaceShopId();
    var new_returns_sys_materialid = Xrm.Page.getAttribute("new_returns_sys_materialid"); //字段:退货部品代码
    var new_return_snnum = Xrm.Page.getAttribute("new_return_snnum"); //退货部品S/N号
    var new_price = Xrm.Page.getAttribute("new_price"); //单价
    var new_returninfoid = Xrm.Page.getAttribute("new_returninfoid"); //退料单明细
    if (replaceShopId != null) {
    var url = "/ISV/Sharp_BatchSelect/ReturnpartsSelect.aspx?replaceShopId=" + replaceShopId;
    }
    var dialoghw = "dialogheight=455px;dialogwidth=500px;status=yes;scroll=no";
    var returnValue = window.showModalDialog(url, null, dialoghw);
    if (returnValue != null && typeof (returnValue) != undefined) {
    var ls = returnValue.split('%');
    if (ls.length > 0) {
    if (ls[0] != "") {
    var entityReference = getEntityReferenceObject(ls[0], "new_sys_material", ls[1])
    new_returns_sys_materialid.setValue(entityReference);
    new_returns_sys_materialid.fireOnChange();
    new_returns_sys_materialid.setSubmitMode("always");
    }

    new_return_snnum.setValue(ls[2]);
    new_return_snnum.setSubmitMode("always");

    if (ls[3] != "") {
    new_price.setValue(parseFloat(ls[3]));
    }
    else {
    new_price.setValue(null);
    }
    new_price.setSubmitMode("always");

    if (ls[4] != "") {
    var entityReference = getEntityReferenceObject(ls[4], "new_returninfo", ls[5])
    new_returninfoid.setValue(entityReference);
    new_returninfoid.setSubmitMode("always");
    }
    }
    }
    }

    1.ReturnpartsSelect页面代码:

    C#:保存:

    /// <summary>
    /// 确定按钮按下后的事件处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
    Boolean isChecked = false;
    string strReturn = string.Empty;
    //获取选取个数
    foreach (GridViewRow gr in ReturnpartsGridView.Rows)
    {
    if (gr.FindControl("cbSelected") != null)
    {
    CheckBox ch = (CheckBox)gr.FindControl("cbSelected");
    if (ch.Checked)
    {
    isChecked = true;
    // 部品ID
    string new_sys_materialid = ReturnpartsGridView.DataKeys[gr.DataItemIndex].Value.ToString();
    // 部品名称
    string new_sys_materialName = (gr.FindControl("lblName") as Label).Text;

    //单据编号
    string new_sys_materialName1 = (gr.FindControl("lblName1") as Label).Text;
    // S/N号
    string new_snnum = (gr.FindControl("lblSnNum") as Label).Text;
    // 价格
    string new_price = (gr.FindControl("lblPrice") as Label).Text;

    //退料单明细
    string new_returninfoid = (gr.FindControl("lblNewReturninfoId") as Label).Text;

    //退料单名称
    string news_name = (gr.FindControl("lblNewsName") as Label).Text;

    strReturn = new_sys_materialid + "%" + new_sys_materialName + "%" + new_snnum + "%" + new_price + "%" + new_returninfoid + "%" + news_name;
    break;
    }
    }
    }
    if (!isChecked)
    {
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Check", "alert('请选择部品!');", true);
    return;
    }

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Check", "setReturnValue('" + strReturn + "');", true);
    }

    html:

    <asp:GridView ID="ReturnpartsGridView" runat="server" AutoGenerateColumns="False"
    DataKeyNames="MaterialId">
    <HeaderStyle CssClass="Freezing"/>
    <Columns>
    <asp:TemplateField>
    <HeaderStyle Width="20px" BackColor="#D9D9D9" />
    <ItemStyle Width="20px" />
    <ItemTemplate>
    <asp:CheckBox ID="cbSelected" runat="server" onclick="change_check(this)"/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="单据编号" HeaderStyle-Font-Size="13px">
    <ItemStyle Width="150px" />
    <ItemTemplate>
    <asp:Label ID="lblName1" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="退料单部品" HeaderStyle-Font-Size="13px">
    <ItemStyle Width="150px" />
    <ItemTemplate>
    <asp:Label ID="lblName" runat="server" Text='<%#Eval("MaterialCode") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="S/N号" HeaderStyle-Font-Size="13px">
    <ItemStyle Width="150px" />
    <ItemTemplate>
    <asp:Label ID="lblSnNum" runat="server" Text='<%#Eval("SnNumber") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="单价" HeaderStyle-Font-Size="13px">
    <ItemStyle Width="110px" HorizontalAlign="Right" />
    <ItemTemplate>
    <asp:Label ID="lblPrice" runat="server" Text='<%#Eval("Price") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="退料单明细" HeaderStyle-Font-Size="13px" visible="false">
    <ItemStyle Width="110px" HorizontalAlign="Right" />
    <ItemTemplate>
    <asp:Label ID="lblNewReturninfoId" runat="server" Text='<%#Eval("NewReturninfoId") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="退料单明细的名称" HeaderStyle-Font-Size="13px" Visible ="false">
    <ItemStyle Width="110px" HorizontalAlign="Right" />
    <ItemTemplate>
    <asp:Label ID="lblNewsName" runat="server" Text='<%#Eval("NewsName") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle BackColor="#D9D9D9" />
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    二、OnSave

    CRM 2011 当出现条件不满足的时候,需要在PageOnSave事件里面传一个参数 ExecutionObj 参数时候,请注意

     alert提示信息后面必须紧跟ExecutionObj.getEventArgs().preventDefault();不然点击保存记录的时候,会出发其他事件,从而使ExecutionObj.getEventArgs().preventDefault()失效。具体如下:

    比如://表单OnSave事件

    function PageOnSave(ExecutionObj) {

    var newshipsysmaterial = Xrm.Page.getAttribute("new_ship_sys_material"); //getAttribute:发货部品代码
    var serverPath = Xrm.Page.context.getServerUrl(); //获取路径
    var new_shipped_snnum = Xrm.Page.getControl("new_shipped_snnum"); //获取发货部品S/N号
    var entityName = "new_sys_material"; //物料实体
    var newproductlinecode = "";
    if (newshipsysmaterial != undefined && newshipsysmaterial.getValue()[0].id != "" && newshipsysmaterial.getValue()[0].id != null) {
    var retrieveResult =
    retrieveMultipleEntity(serverPath,
    entityName,
    "new_sys_product_line_new_sys_material/new_product_line_code",
    "new_sys_materialId eq (guid'" + newshipsysmaterial.getValue()[0].id + "') and statecode/Value eq 0",
    "", "new_sys_product_line_new_sys_material", "", "");
    }
      if (retrieveResult == null || retrieveResult.statusText != "OK") {
         alert("查询失败" + "(" + retrieveResult.response + ")");
        return;
    }
    var new_product_line_code_arr = "";
    new_product_line_code_arr = retrieveResult.response.results;
    if (new_product_line_code_arr.length == 0) return;
    if (new_product_line_code_arr[0].new_sys_product_line_new_sys_material == null) return;
    newproductlinecode = new_product_line_code_arr[0].new_sys_product_line_new_sys_material.new_product_line_code;
    if (newproductlinecode != null && newproductlinecode == "R1LK") {
    new_shipped_snnum.setValue(null);
    new_shipped_snnum.setDisabled(false); //可编辑
    1.alert("该发货部品的产品线代码的值为液晶屏,发货部品S/N号需要手动输入!");
    2.ExecutionObj.getEventArgs().preventDefault();

    如果在1,2之间加入new_shipped_snnum.setDisabled(false); //可编辑

    变成 

    1.alert("该发货部品的产品线代码的值为液晶屏,发货部品S/N号需要手动输入!");
    new_shipped_snnum.setDisabled(false); //可编辑
    2.ExecutionObj.getEventArgs().preventDefault();

    那么点击保存,时,该保存功能就失效了。

    }

    }

    三、onChange

    var returnssysmaterialid = Xrm.Page.getAttribute("new_returns_sys_materialid");
    new_returns_sys_materialid.fireOnChange();//触发字段new_returns_sys_materialid的onChange事件3
    new_returns_sys_materialid.setSubmitMode("always");

    3.//onchange事件
    function newreturnssysmaterialidOnChange() {
    ..//处理逻辑
    }

     



     

  • 相关阅读:
    为动态添加的元素,绑定click事件
    Struts报错NoSuchMethodException的解决方法
    Struts报错ObjectNotFoundException的解决方法
    HTML通知、新闻等文字列表的无缝滚动效果
    HTML通过使用JS动态显示table内容
    CentOS下整合Apache与Tomcat的一种方法
    Centos下Apache整合Tomcat访问报Forbidden 403 错误的解决方法
    从Google趋势来看五大联赛在世界范围内的影响力
    Java实现多线程的三种方法
    DataGrid中插入Combobox选择框
  • 原文地址:https://www.cnblogs.com/allenhua/p/3043799.html
Copyright © 2011-2022 走看看