SAP Business One开发随手记


一、Form

1.ChooseFormList选择清单

点击输入框后面的选择按钮,弹出指定清单列表窗口,并可以选择回调数据
在这里插入图片描述
在这里插入图片描述

srf 代码

<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="206" left="241" width="120" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="26" IsAutoGenerated="0">
	<specific ChooseFromListAlias="ItemCode" ChooseFromListIsAutoFill="0" ChooseFromListUID="CFL_4" IsPassword="0" supp_zeros="0">
		<databind databound="1" table="" alias="ItemCode" />
    </specific>
</item>
<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="206" left="368" width="160" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="27" IsAutoGenerated="0">
	<specific ChooseFromListAlias="" ChooseFromListIsAutoFill="0" ChooseFromListUID="" IsPassword="0" supp_zeros="0">
    	<databind databound="1" table="" alias="ItemName" />
    </specific>
</item>

其中ChooseFromListAlias=" ItemCode"对应的是清单弹窗里的字段名称,alias="ItemCode"指代的是系统控件的别名,为了存储输入框的值,ChooseFromListUID="CFL_4"是清单弹窗的对象指向,详细用法看下文

<ChooseFromListCollection>
	<action type="add">
		<ChooseFromList UniqueID="CFL_4" ObjectType="4" MultiSelection="0" IsSystem="0" />
   	</action>
</ChooseFromListCollection>

UniqueID="CFL_4"绑定显示清单的ObjectTpye,ObjectType通过查询数据库字段ObjType可得,如下图
在这里插入图片描述

cs 代码

void B1Form_CostInit_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
{
	if (pVal.BeforeAction)
    {
    }
    else
    {
    	switch (pVal.ChooseFromListUID)
        {
        	case "CFL_4":
        		//根据当前窗体未存储在数据库中的项数据的容器名称为其赋值
            	this.CurrentForm.DataSources.UserDataSources.Item("ItemCode").Value = pVal.SelectedObjects.GetValue("ItemCode", 0).ToString().Trim();
            	this.CurrentForm.DataSources.UserDataSources.Item("ItemName").Value = pVal.SelectedObjects.GetValue("ItemName", 0).ToString().Trim();
			break;
		}
	}
}

如果弹出框绑定的字段为未存储在数据库中的字段时,类似于
<databind databound="1" table="" alias="ItemCode" />
那么千万不要忘记在Form.srf文件中为其UserDataSources进行绑定操作

<userdatasources>
	<action type="add">
    	<datasource type="9" size="50" uid="ItemCode" />
        <datasource type="9" size="254" uid="ItemName" />
    </action>
</userdatasources>

注意!!!只有将type设置为9(Short text 短文本)时才可以正常弹出清单列表,否则不显示弹出清单按钮,查看枚举类型请前往附件—BoDataType Enum(用户数据源的数据类型)

2.TabControl选项卡控件切换选项操作

srf 代码

工具箱中选择TabControl控件,拖拽至窗体中,右键选项卡可以进行添加、移除标签页
在这里插入图片描述
然后将表格控件调整成一致的大小,然后重叠堆放在一起

第一个标签上绑定的matrix控件的属性设置from_pane="0"to_pane="1"

第二个标签上绑定的matrix控件的属性设置from_pane="2"to_pane="2"

第三个标签上绑定的matrix控件的属性设置from_pane="3"to_pane="3"

以此类推…

cs 代码

void B1Form_CostInit_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
{
	if (pVal.BeforeAction)
   	{
    }
    else
   	{
    	if (pVal.ActionSuccess)
        {
        	//Tab_0
           	if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "Tab_0")
           	{
            	SBOApp.Forms.ActiveForm.Freeze(true);
                SBOApp.Forms.ActiveForm.PaneLevel = 1;
                SBOApp.Forms.ActiveForm.Freeze(false);
            }
            //Tab_1
            if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "Tab_1")
            {
            	SBOApp.Forms.ActiveForm.Freeze(true);
            	SBOApp.Forms.ActiveForm.PaneLevel = 2;
            	SBOApp.Forms.ActiveForm.Freeze(false);
            }
            //Tab_2
            if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "Tab_2")
            {
            	SBOApp.Forms.ActiveForm.Freeze(true);
            	SBOApp.Forms.ActiveForm.PaneLevel = 3;
            	SBOApp.Forms.ActiveForm.Freeze(false);
            }
    	}
  	}
}

3.单选按钮

srf 代码

<item top="123" left="269" width="70" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="122" visible="1" uid="Item_18" IsAutoGenerated="0">
	<specific caption="平均分摊">
    	<databind databound="1" table="@COST_BASIC_SETUP" alias="U_ShareWay" />
  	</specific>
</item>

cs 代码

//打开页面时初始化控件
protected override void InitializeForm(B1FormInitializePar InitPar)
{
	SAPbouiCOM.OptionBtn proTerminated = this.CurrentForm.Items.Item("Item_17").Specific;
    proTerminated.GroupWith("Item_13");
    SAPbouiCOM.OptionBtn costCenter = this.CurrentForm.Items.Item("Item_18").Specific;
   	costCenter.GroupWith("Item_28");
    SAPbouiCOM.OptionBtn priceList = this.CurrentForm.Items.Item("Item_23").Specific;
   	priceList.GroupWith("Item_22");
    SAPbouiCOM.OptionBtn material = this.CurrentForm.Items.Item("Item_24").Specific;
    material.GroupWith("Item_21");
	//将传入的单选按钮循环设置控制显示状态
   	ControlsVisibleStatus(new String[] { "Item_13", "Item_17", "Item_22", "Item_23", "Item_30" }, false);
}
//控制控件显示隐藏
private void ControlsVisibleStatus(String[] items,Boolean status) 
{
	for (int i = 0; i < items.Length; i++) 
	{
    	this.CurrentForm.Items.Item(items[i]).Visible = status;
    }
}

4.LinkedButton按钮绑定

//LinkedButton linkedObject的值是查询表中的Object或者ObjType字段的值
<item top="96" left="60" width="12" height="10" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="Item_10" right_just="0" type="116" visible="1" uid="Item_13" IsAutoGenerated="0">
	<specific linkedObject="52" LinkedObjectType="52" />
</item>

5.动态绑定ComboBox

srf 代码

//ComboBox:Form中的ComboBox控件
<item tab_order="0" top="94" left="76" width="80" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="113" visible="1" uid="Item_10" IsAutoGenerated="0"></item>

cs代码

CommonUse.ComboBox_InitialForItem(this.CurrentForm.Items.Item("Item_1"), "AbsEntry", "PeriodCat", "OACP", @"""AbsEntry"" desc");
//调用动态绑定方法
public static void ComboBox_InitialForItem(SAPbouiCOM.Item oItem, string value, string description, string table, string order = null, string where = null, bool add_empty = true)
{
    SAPbobsCOM.Recordset oRs = null;
    try
    {
        oRs = SAPBoAddon.B1Addon.B1Addon.SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
        string select = String.Format(@"select ""{0}"",""{1}"" from ""{2}""", value, description, table);
        if (!String.IsNullOrEmpty(where))
        {
            select += String.Format(" {0} ", where);
        }
        if (!String.IsNullOrEmpty(order))
        {
            select += String.Format(@" order by {0}", order);
        }
        if (oItem.Type == SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX)
        {
            string Value = string.Empty;
            string Description = string.Empty;
            oRs.DoQuery(select);
            SAPbouiCOM.ComboBox cbo = oItem.Specific as SAPbouiCOM.ComboBox;
            if (add_empty)
            {
                cbo.ValidValues.Add("", "");
            }
            for (int i = 0; i < oRs.RecordCount; i++)
            {
                Value = Convert.ToString(oRs.Fields.Item(value).Value);
                Description = oRs.Fields.Item(description).Value;
                cbo.ValidValues.Add(Value, Description);
                oRs.MoveNext();
            }
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally {
        if (oRs != null) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRs);
    }
}

6.增加菜单项并绑定点击事件

cs代码

//初始化菜单项
public static void creatMenu(SAPbouiCOM.Form CurrentForm) 
{
    try
    {
        SAPbouiCOM.MenuItem oMenuItem;
        SAPbouiCOM.Menus oMenus;
        //创建菜单参数对象
        SAPbouiCOM.MenuCreationParams oCreationPackage;

        oCreationPackage = SAPBoAddon.B1Addon.B1Addon.SBOApp.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams);

        oCreationPackage.Checked = false;
        oCreationPackage.Enabled = true;
        //菜单项的类型
        oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
        oCreationPackage.UniqueID = "journal";
        oCreationPackage.String = "(AVA)日记账";
        CurrentForm.Menu.AddEx(oCreationPackage);
    }
    catch (Exception)
    {
        throw;
    }
}
void B1Form_sys_AP_Credit_Memo_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
{
    if (!pVal.BeforeAction)
    {
        //生成右击菜单
        if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD)
        {
            BoAddonBiz_CostAccounting.AddonCs.AddMenu.creatMenu(this.CurrentForm);
        }
    }
}

//右键菜单的点击事件
public static void clickMenu(SAPbouiCOM.Form CurrentForm, String TableName)
{
    SAPbouiCOM.DBDataSource oDb = CurrentForm.DataSources.DBDataSources.Item(TableName);
    String journalId = oDb.GetValue("U_JournalEntry", 0).ToString();
    String journalType = oDb.GetValue("U_JournalType", 0).ToString();
    if (CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_OK_MODE && CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_VIEW_MODE)
    {
        SAPBoAddon.B1Addon.B1Addon.SBOApp.StatusBar.SetText("请先保存单据", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
        return;
    }
    if (!String.IsNullOrWhiteSpace(journalId) && !String.IsNullOrWhiteSpace(journalType))
    {
        SAPBoAddon.B1Addon.B1Addon.SBOApp.OpenForm(journalType.Equals("日记账分录") ? SAPbouiCOM.BoFormObjectEnum.fo_JournalPosting : SAPbouiCOM.BoFormObjectEnum.fo_JournalVoucher, "", journalId);
    }
}

SAPbouiCOM.BoMenuType.mt_STRING 含义是该菜单项没有子项,相反mt_POPUP 的含义则是带有子项的菜单项

//方法调用
void B1Form_sys_AP_Credit_Memo_frm_MenuEvent(SAPBoAddon.B1AddonBase.B1MenuEvent pVal, ref bool BubbleEvent)
{
    try
    {
        if (pVal.BeforeAction)
        {
            switch (pVal.MenuUID)
            {
                //右击菜单点击事件
                case "journal": 
                    BoAddonBiz_CostAccounting.AddonCs.AddMenu.clickMenu(this.CurrentForm, "ORPC");
                break;
            }
        }
    }
    catch (Exception ex)
    {
        SBOApp.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
    }

}

二、Matrix

1.动态绑定ComboBox

srf 代码

<item cellHeight="16" tab_order="0" titleHeight="20" top="50" left="13" width="695" height="317" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="127" visible="1" uid="mtx_0" IsAutoGenerated="0">
	<specific layout="0" SelectionMode="2">
    	<columns>
       		<action type="add">
       			//ComboBox
           		<column disp_desc="1" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="业务伙伴组" width="50" editable="1" type="113" right_just="0" uid="Col_4" sortable="0">
               		<databind databound="1" table="@LEDGER_SUB_LINE" alias="U_BPGrpCod" />
                 	<ValidValues>
                  		<action type="add" />
                 	</ValidValues>
             	</column>
       		</action>
  		</columns>
  	</specific>
</item>

cs 代码

//Field1--值对应数据库字段  Field2--描述对应数据库字段  TableName--查询表名  MtxName--表单唯一值
//ColumnIndex--字段在Matrix中的下标,下标从0开始  add_empty--可不填,默认加入一行空值
public void initComboBox(String Field1, String Field2, String TableName, String MtxName, int ColumnIndex, bool add_empty = true)
{
	string SQL_GetItemGroupCode = "select " + Field1 + "," + Field2 + " from " + TableName + "";
    SAPbobsCOM.Recordset oRs_GetItemGroupCode = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
    oRs_GetItemGroupCode.DoQuery(SQL_GetItemGroupCode);

   	SAPbouiCOM.Matrix mtx = this.CurrentForm.Items.Item(MtxName).Specific;
 	SAPbouiCOM.Column comboBox = mtx.Columns.Item(ColumnIndex);

  	int count = oRs_GetItemGroupCode.RecordCount;
   	int num = 0;

   	if (add_empty)
  	{
    	comboBox.ValidValues.Add("", "");
   	}
  	while (1 == 1)
	{
 		Object Value = oRs_GetItemGroupCode.Fields.Item(0).Value;
      	String Description = oRs_GetItemGroupCode.Fields.Item(1).Value;
     	comboBox.ValidValues.Add(Value.ToString(), Description);
   		num++;
     	if (num != count)
      	{
      		oRs_GetItemGroupCode.MoveNext();
          	continue;
       	}
       	break;
	};
  	comboBox.ExpandType = SAPbouiCOM.BoExpandType.et_DescriptionOnly;
}

comboBox.ExpandType是下拉框控件的展开类型的设置,查看枚举类型请前往附件—BoExpandType Enum(下拉框控件的展开类型)

2.绑定LinkedButton控件

srf 代码

<item cellHeight="16" tab_order="0" titleHeight="20" top="50" left="13" width="695" height="317" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="127" visible="1" uid="mtx_0" IsAutoGenerated="0">
	<specific layout="0" SelectionMode="2">
    	<columns>
       		<action type="add">
             	<column backcolor="-1" ChooseFromListAlias="AcctCode" ChooseFromListIsAutoFill="0" ChooseFromListUID="OACT5" font_size="-1" forecolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="收入科目" width="50" editable="1" type="116" right_just="0" uid="Col_19" sortable="0">
                	<databind databound="1" table="@LEDGER_SUB_LINE" alias="U_DfltIncom" />
                   	<ExtendedObject linkedObject="1" LinkedObjectType="1" />
              	</column>
       		</action>
  		</columns>
  	</specific>
</item>

LinkedButton:此时这个单元格内无数据时不显示LinkedButton按钮,有数据时才显示按钮,并且此单元格同时绑定了ChooseFormList选择事件要实现LinkedButton的重中之重是column标签内的的type类型,必须是116,详见,附件—BoFormItemTypes Enum(表单项类型)

3.Matrix的增加删除行按钮绑定

srf 代码

添加两个button,命名add和del

cs 代码

//首次加载
protected override void FormInfoSetting(B1FormSetting FormSetting)
{
    FormSetting.FormType = B1FormTypes.ado_LedgerSub;
    FormSetting.FormFileName = "AVA_LedgerSubForm.srf";
	//设置Matrix属性
    FormSetting.MaxOpenCount = -1;
    FormSetting.AutoGetObjectNextNumber = true;
    FormSetting.MatrixSetting.addButtonUID = "add";
    FormSetting.MatrixSetting.delButtonUID = "del";
    FormSetting.MatrixSetting.MtxUID = "mtx_0";
    FormSetting.MatrixSetting.TableName = "@LEDGER_SUB_LINE";
    FormSetting.MatrixSetting.TableKeyField = "LineId";
    FormSetting.MatrixSetting.PrimaryLineCol = "col_f";
    FormSetting.MatrixSetting.AutoLineKeyCol = "col_f";
    FormSetting.MatrixSetting.AutoAddNewLine = true;
    FormSetting.MatrixSetting.NotAllowNoLineSave = false;
    FormSetting.MatrixSetting.Add();
}

4.设置Matrix的行字段值(ChooseFormList事件)

private void SetDBDS(String TableName, String MtxName,String KeyColumn, String SetField, String GetField, SAPBoAddon.B1AddonBase.B1ChooseFormList pVal)
{
    SAPbouiCOM.DBDataSource dbds = this.CurrentForm.DataSources.DBDataSources.Item(TableName);
    SAPbouiCOM.Matrix mtx = this.CurrentForm.Items.Item(MtxName).Specific;
    pVal.AffectsFormMode = false;
	//这里用到了获取Matrix的当前行offset(用于对行数据进行操作)的方法
	dbds.Offset = Matrix.GetdbDsOffset(mtx, pVal.Row, KeyColumn, dbds);
    mtx.GetLineData(pVal.Row);
    dbds.SetValue(SetField, dbds.Offset, pVal.SelectedObjects.GetValue(GetField, 0).ToString());
    mtx.SetLineData(pVal.Row);
}

三、Events

1.复制从

点击 选择项目按钮,弹出指定清单列表,可以根据条件查询数据,并复制到制造费结转单据数据表格中
在这里插入图片描述
在这里插入图片描述

srf 代码

首先,创建一个按钮控件

<item top="9" left="825" width="70" height="27" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="4" visible="1" uid="8" IsAutoGenerated="0">
	<specific caption="选择科目" />
</item>

然后,创建一个数据表格,并为其绑定数据库和唯一 uid (mtx_0)

<item cellHeight="16" tab_order="0" titleHeight="20" top="60" left="6" width="905" height="390" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="127" visible="1" uid="mtx_0" IsAutoGenerated="0">
	<specific layout="0" SelectionMode="2">
    	<columns>
    		<action type="add">
	    		<column backcolor="-1" ChooseFromListIsAutoFill="0" font_size="-1" forecolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="" width="20" editable="0" type="16" right_just="0" uid="V_-1" sortable="1">
	            	<databind databound="1" table="@AVA_FCA1" alias="LineId" />
	            </column>
	            <column backcolor="-1" ChooseFromListIsAutoFill="0" font_size="-1" forecolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="科目编号" width="80" editable="1" type="16" right_just="0" uid="V_0" sortable="1">
	                 <databind databound="1" table="@AVA_FCA1" alias="U_AcctCode" />
	            </column>
	            <column backcolor="-1" ChooseFromListIsAutoFill="0" font_size="-1" forecolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="科目名称" width="160" editable="1" type="16" right_just="0" uid="V_1" sortable="1">
	                 <databind databound="1" table="@AVA_FCA1" alias="U_AcctName" />
	            </column>
	            <column backcolor="-1" ChooseFromListIsAutoFill="0" font_size="-1" forecolor="-1" text_style="0" disp_desc="0" visible="1" AffectsFormMode="1" val_on="Y" IsAutoGenerated="0" val_off="N" title="发生额" width="80" editable="1" type="16" right_just="0" uid="V_2" sortable="1">
	                 <databind databound="1" table="@AVA_FCA1" alias="U_FS" />
	            </column>
        	</action>
   		</columns>
	</specific>
</item>

接着,我们创建一个跳转清单的窗体
窗体包括了查询条件

<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="7" left="97" width="120" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="12" IsAutoGenerated="0">
	<specific ChooseFromListAlias="" ChooseFromListIsAutoFill="0" ChooseFromListUID="" IsPassword="0" supp_zeros="0">
		<databind databound="1" table="" alias="startdate" />
	</specific>
</item>
<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="28" left="97" width="120" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="13" IsAutoGenerated="0">
	<specific ChooseFromListAlias="" ChooseFromListIsAutoFill="0" ChooseFromListUID="" IsPassword="0" supp_zeros="0">
		<databind databound="1" table="" alias="enddate" />
	</specific>
</item>
<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="50" left="97" width="120" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="14" IsAutoGenerated="0">
	<specific ChooseFromListAlias="AcctCode" ChooseFromListIsAutoFill="0" ChooseFromListUID="CFL_OACT" IsPassword="0" supp_zeros="0">
		<databind databound="1" table="" alias="AcctF" />
	</specific>
</item>
<item backcolor="-1" font_size="-1" forecolor="-1" tab_order="0" text_style="0" top="70" left="97" width="120" height="14" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="16" visible="1" uid="15" IsAutoGenerated="0">
	<specific ChooseFromListAlias="AcctCode" ChooseFromListIsAutoFill="0" ChooseFromListUID="CFL_OACT1" IsPassword="0" supp_zeros="0">
		<databind databound="1" table="" alias="AcctT" />
	</specific>
</item>

查询按钮

<item top="36" left="384" width="90" height="43" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="4" visible="1" uid="16" IsAutoGenerated="0">
	<specific caption="查询" />
</item>

数据表格

<item top="94" left="8" width="512" height="253" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="128" visible="1" uid="4" IsAutoGenerated="0">
	<specific CollapseLevel="0" DataTable="DT_List" SelectionMode="1">
		<RowHeaders Width="20" />
	</specific>
</item>

选择回调按钮

<item top="355" left="8" width="65" height="19" AffectsFormMode="1" description="" disp_desc="0" enabled="1" from_pane="0" to_pane="0" linkto="" right_just="0" type="4" visible="1" uid="3" IsAutoGenerated="0">
	<specific caption="选择" />
</item>

cs 代码

首先,添加选择科目按钮的加载窗体事件

void B1Form_CostRollOut_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
{
	if (pVal.BeforeAction)
    {
    }
    else
   	{
    	if (pVal.ActionSuccess)
        {
           	if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "8")
            {
            	SAPbouiCOM.DBDataSource AVA_OFCA = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_OFCA");
	            string Endtime = AVA_OFCA.GetValue("U_enddate", 0).Trim();
	            string Starttime = AVA_OFCA.GetValue("U_startdate", 0).Trim();
				//加载窗体前的验证判断(为空则跳出程序不执行后续代码)
	            if (Starttime.ToString() == "")
	            {
	                SBOApp.StatusBar.SetText("开始时间为空", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
	                return;
	            }
	            if (Endtime.ToString() == "")
	            {
	                SBOApp.StatusBar.SetText("结束时间为空", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
	                return;
	            }
	            //生成窗体文件名称
	            string FormFileName = string.Format("{0}\\{1}Form.srf", SAPBoAddon.B1Addon.B1Addon.FolderForm, B1FormTypes.ado_FI_AccountList);
	            //加载窗体文件到SBO
	            SAPbouiCOM.Form oLinkForm = SAPBoAddon.B1Assistant.Form.LoadToSBOApplciation(FormFileName, "");
	            //为加载窗体的用户自定义字段进行赋值
	            oLinkForm.DataSources.UserDataSources.Item("FormUid").Value = this.CurrentForm.UniqueID;
	            oLinkForm.DataSources.UserDataSources.Item("enddate").Value = AVA_OFCA.GetValue("U_enddate", 0);
	            oLinkForm.DataSources.UserDataSources.Item("startdate").Value = AVA_OFCA.GetValue("U_startdate", 0);
		}
}

然后,为清单窗体的查询选择按钮绑定事件

void B1Form_AccountList_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
{
	if (pVal.BeforeAction)
    {
    }
    else
   	{
    	if (pVal.ActionSuccess)
        {
        	//查找科目
           	if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "16")
            {
            	//根据uid获取控件的值
            	SAPbouiCOM.EditText edtStartacct= this.CurrentForm.Items.Item("14").Specific;
	            SAPbouiCOM.EditText edtEndacct= this.CurrentForm.Items.Item("15").Specific;
	            string Startacct=edtStartacct.Value ;
	            string Endacct= edtEndacct.Value ;
				//根据用户自定义数据源名称获取其值
	            string et = this.CurrentForm.DataSources.UserDataSources.Item("enddate").Value;
	            string st = this.CurrentForm.DataSources.UserDataSources.Item("startdate").Value;
	            string formuid = this.CurrentForm.DataSources.UserDataSources.Item("FormUid").Value;
	           //获取父窗体的携带参数信息
	            SAPbouiCOM.Form orgForm = SBOApp.Forms.Item(formuid);
	
	            string SQL = "";
	            //根据跳转父窗体的不同执行不同的SQL语句
	            if (orgForm.TypeEx == "AVA_CostRollOut")
	            {
	                SQL = "call AVA_GetAccountList ('" + Startacct + "','" + Endacct + "','" + st.Replace(".", "-") + "','" + et.Replace(".", "-") + "','F')";
	            }
	            if (orgForm.TypeEx == "AVA_CostAllocation")
	            {
	                SQL = "call AVA_GetAccountList ('" + Startacct + "','" + Endacct + "','" + st.Replace(".", "-") + "','" + et.Replace(".", "-") + "','C')";
	            }
	            if (orgForm.TypeEx == "AVA_CostAssignment")
	            {
	                SQL = "call AVA_GetAccountList ('" + Startacct + "','" + Endacct + "','" + st.Replace(".", "-") + "','" + et.Replace(".", "-") + "','M')";
	            }
	            if (orgForm.TypeEx == "AVA_CostLost")
	            {
	                SQL = "call AVA_GetAccountList ('" + Startacct + "','" + Endacct + "','" + st.Replace(".", "-") + "','" + et.Replace(".", "-") + "','X')";
	            }
	            SAPbouiCOM.Grid Grid_0 = (SAPbouiCOM.Grid)this.CurrentForm.Items.Item("4").Specific;
	            Grid_0.DataTable.ExecuteQuery(SQL);
	            
	            //查询到数据就将第一列设置成复选框
	            if (Grid_0.DataTable.Rows.Count > 0)
	            {
	                Grid_0.Columns.Item(0).Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox;
	            }
            }
           	//选择科目
           	if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "3")
           	{
            	string formuid = this.CurrentForm.DataSources.UserDataSources.Item("FormUid").Value;
	            //判断行数据是否为空
	            SAPbouiCOM.Grid Grid_0 = (SAPbouiCOM.Grid)this.CurrentForm.Items.Item("4").Specific;
            	SAPbouiCOM.DataTable dt_0 = Grid_0.DataTable;
            	for (int GridRowCount = 0; GridRowCount < Grid_0.Rows.Count; GridRowCount++)
            	{
                	if (dt_0.GetValue("chose", GridRowCount) == "Y")
                	{
	                    if (dt_0.GetValue("FDate", GridRowCount)==null)
	                    {
	                        SBOApp.StatusBar.SetText("时间条件必须输入!", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
	                        return false;
	                    }
	                    if (dt_0.GetValue("TDate", GridRowCount) == null)
	                    {
	                        SBOApp.StatusBar.SetText("时间条件必须输入!", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
	                        return false;
	                    }
                	}
            	}
            	//根据formuid获取父窗体的数据表格对象和数据表对象
	            SAPbouiCOM.Form orgForm = SBOApp.Forms.Item(formuid);
	            SAPbouiCOM.Matrix mtx0 = orgForm.Items.Item("mtx_0").Specific;
	            SAPbouiCOM.DBDataSource AVA_FCA1 = orgForm.DataSources.DBDataSources.Item("@AVA_FCA1");
	           
	            int re=SBOApp.MessageBox("是否清除当前数据?", 2,"是", "否");
	            if (re == 1)
	            {
	                AVA_FCA1.Clear();
	                //刷新数据表格数据
	                mtx0.LoadFromDataSource();
	
	                if (orgForm.TypeEx == "AVA_CostAllocation")
	                {
	                    SAPbouiCOM.Matrix mtx1 = orgForm.Items.Item("mtx_1").Specific;
	                    SAPbouiCOM.DBDataSource AVA_FCA2 = orgForm.DataSources.DBDataSources.Item("@AVA_FCA2");
	                    AVA_FCA2.Clear();
	                    mtx1.LoadFromDataSource();
	                }
	                if (orgForm.TypeEx == "AVA_CostAssignment")
	                {
	                    SAPbouiCOM.Matrix mtx2 = orgForm.Items.Item("mtx_2").Specific;
	                    SAPbouiCOM.DBDataSource AVA_FCA3 = orgForm.DataSources.DBDataSources.Item("@AVA_FCA3");
	                    AVA_FCA3.Clear();
	                    mtx2.LoadFromDataSource();
	                }
	
	                if (orgForm.TypeEx == "AVA_CostLost")
	                {
	                    SAPbouiCOM.Matrix mtx3 = orgForm.Items.Item("mtx_3").Specific;
	                    SAPbouiCOM.DBDataSource AVA_FCA4 = orgForm.DataSources.DBDataSources.Item("@AVA_FCA4");
	                    AVA_FCA4.Clear();
	                    mtx3.LoadFromDataSource();
	                }
	            }
	
	            SAPbouiCOM.Grid Grid_0 = (SAPbouiCOM.Grid)this.CurrentForm.Items.Item("4").Specific;
	            for (int GridRowCount = 0; GridRowCount < Grid_0.Rows.Count; GridRowCount++)
	            {
	                SBOApp.SetStatusBarMessage("正在复制," + GridRowCount.ToString() + "/" + Grid_0.Rows.Count.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, false);
	                SAPbouiCOM.DataTable dt_0 = Grid_0.DataTable;
	                if (dt_0.GetValue("chose", GridRowCount)=="Y")
	                {
	                    dt_0.Rows.Offset = GridRowCount;
	                    string AcctCode = Convert.ToString(dt_0.GetValue("AcctCode", GridRowCount));
	                    string AcctName = Convert.ToString(dt_0.GetValue("AcctName", GridRowCount));
	                    string DAcctCode = Convert.ToString(dt_0.GetValue("DAcctCode", GridRowCount));
	                    string DAcctName = Convert.ToString(dt_0.GetValue("DAcctName", GridRowCount));
	                    DateTime FDate =DateTime.Parse( Convert.ToString(dt_0.GetValue("FDate", GridRowCount)) );
	                    DateTime TDate =DateTime.Parse(  Convert.ToString(dt_0.GetValue("TDate", GridRowCount)) );
	                    string fs = Convert.ToString(dt_0.GetValue("fs", GridRowCount));
	
	                    string U_WipAcctCode = Convert.ToString(dt_0.GetValue("U_WipAcctCode", GridRowCount));
	                    string U_WipAcctName = Convert.ToString(dt_0.GetValue("U_WipAcctName", GridRowCount));
	                    string U_WaAcctCode = Convert.ToString(dt_0.GetValue("U_WaAcctCode", GridRowCount));
	                    string U_WaAcctName = Convert.ToString(dt_0.GetValue("U_WaAcctName", GridRowCount));
	
	                    //空行判断
	                    if (mtx0.VisualRowCount == 0 && AVA_FCA1.Size>0)
	                    {
						}
	                    else if (mtx0.VisualRowCount == 0 && AVA_FCA1.Size == 0)
	                    {
	                        AVA_FCA1.InsertRecord(0);
	                    }
	                    else
	                    {
	                        AVA_FCA1.InsertRecord(AVA_FCA1.Size);
	                    }
	                    
	                    AVA_FCA1.SetValue("LineId", AVA_FCA1.Size-1, AVA_FCA1.Size.ToString ());
	                    AVA_FCA1.SetValue("U_AcctCode", AVA_FCA1.Size-1, AcctCode);
	                    AVA_FCA1.SetValue("U_AcctName", AVA_FCA1.Size-1, AcctName);
	                    AVA_FCA1.SetValue("U_FS", AVA_FCA1.Size-1, fs);
	                    AVA_FCA1.SetValue("U_TAcctCode", AVA_FCA1.Size-1, DAcctCode);
	                    AVA_FCA1.SetValue("U_TAcctName", AVA_FCA1.Size-1, DAcctName);
	                    AVA_FCA1.SetValue("U_TFS", AVA_FCA1.Size-1, fs);
	                    AVA_FCA1.SetValue("U_StartDate", AVA_FCA1.Size - 1, FDate.ToString("yyyyMMdd"));
	                    AVA_FCA1.SetValue("U_EndDate", AVA_FCA1.Size - 1, TDate.ToString("yyyyMMdd"));
	
	                    AVA_FCA1.SetValue("U_WipAcctCode", AVA_FCA1.Size - 1,  U_WipAcctCode);
	                    AVA_FCA1.SetValue("U_WipAcctName", AVA_FCA1.Size - 1,  U_WipAcctName);
	                    AVA_FCA1.SetValue("U_WaAcctCode", AVA_FCA1.Size - 1,  U_WaAcctCode );
	                    AVA_FCA1.SetValue("U_WaAcctName", AVA_FCA1.Size - 1,  U_WaAcctName );
	                }
	            }
	            mtx0.LoadFromDataSource();
	            this.CurrentForm.Close();
	            SBOApp.SetStatusBarMessage("完成", SAPbouiCOM.BoMessageTime.bmt_Short, false);
            }
  		}
 	}
}

Ps.因为用到了UserDataSources所以记得在Form.srf文件中添加对应的字段

2. 为系统单据增加按钮

cs代码

internal class B1Form_PurchaseOrders : B1Form
{
    internal B1Form_PurchaseOrders()
    {
        this.frm_ItemEvent += B1Form_PurchaseOrders_frm_ItemEvent;
    }

    #region Event项目事件
    private void B1Form_PurchaseOrders_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
    {
        try
        {
            if (pVal.BeforeAction)
            {
            	//当打开了一个表单时,为系统单据增加按钮事件
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD)
                {
                    AddItemsInForm();
                }
            }
            else
            {
            	//按钮被点击时的操作
                if (pVal.ItemUID == "ueItem" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    //if (this.CurrentForm.Mode != SAPbouiCOM.BoFormMode.fm_OK_MODE)
                    //{
                    //    SBOApp.StatusBar.SetText("请先保存单据", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                    //    return;
                    //}
                    SAPBoAddon.B1FormInitializePar oInit = new SAPBoAddon.B1FormInitializePar();
                    oInit.FatherFormUID = this.CurrentForm.UniqueID;
                    oInit.KeyValue = "PurchaseOrders";
                    this.ShowForm(B1FormTypes.ado_CopyFromApply, oInit);
                }
            }
        }
        catch (Exception ex) {
            SBOApp.StatusBar.SetText(ex.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
        }

    }
    #endregion

    protected override bool BeforeSaveCheckFormData()
    {
        return true;
    }

    protected override void FormEditModeChange(frmItemEditMode frmEditMode)
    {
    }

    protected override void FormInfoSetting(B1FormSetting FormSetting)
    {
    	//设置系统表单的Form类型(数字)如何取值详见ps
        FormSetting.FormType = B1FormTypes.sys_Purchase_Order;
    }

    protected override void InitializeForm(B1FormInitializePar InitPar)
    {
    }

	//系统单据增加按钮
    private void AddItemsInForm(){
        try {
            SAPbouiCOM.Button oButton;
            SAPbouiCOM.Item oEdItem;
            SAPbouiCOM.Button cancelEdt = this.CurrentForm.Items.Item("2").Specific;

            oEdItem = this.CurrentForm.Items.Add("ueItem", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
            oEdItem.Height = cancelEdt.Item.Height;
            oEdItem.Width = cancelEdt.Item.Width*2;
            oEdItem.Top = cancelEdt.Item.Top;
            oEdItem.Left = cancelEdt.Item.Left+ cancelEdt.Item.Width + 4;
            oButton = oEdItem.Specific;
            oButton.Caption = "复制从采购退货";
        }
        catch (Exception ex)
        {
            SBOApp.StatusBar.SetText(ex.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
        }
    }
}

ps. 打开系统单据,将鼠标放到任意控件上,在状态栏即可查看Form值,如下图

在这里插入图片描述

问题解决方案

一、实现类似系统单据的设置界面

1. 需求描述

限制用户点击查找 添加 第一条数据 上一条数据 下一条数据 最后一条数据 按钮,并且打开单据默认显示第一条数据

2. 解决方案

限制用户点击按钮,在srf文件中进行控制,附代码

<Menus>
  <action type="enable">
  </action>
  <action type="disable">
    <Menu uid="1281"/>
    <Menu uid="1282"/>
    <Menu uid="1288"/>
    <Menu uid="1289"/>
    <Menu uid="1290"/>
    <Menu uid="1291"/>
  </action>
</Menus>

打开单据默认显示第一条数据,因为限制了用户点击第一条数据按钮,所以,在这里需要进行特殊处理,一共分为两种情况:
①用户第一次打开单据,此时没有数据,需要用户添加一条数据,所以更改单据模式为增加模式,并自动赋值DocEntry字段为1
②用户再次打开单据,此时存在单据编号为1的数据,需要展示数据到界面,所以更改单据模式为查询,编写sql语句,查询出DocEntry的值,最后将DocEntry的值放入输入框中,模拟用户点击查询按钮

protected override void InitializeForm(B1FormInitializePar InitPar)
{
	SAPbobsCOM.Recordset oRs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
	this.CurrentForm.Items.Item("3").Enabled = true;
	SAPbouiCOM.EditText oDoc = this.CurrentForm.Items.Item("3").Specific;
	string sql = "select count(*) as count from [@COST_BASIC_SETUP]";
	oRs.DoQuery(sql);
	int count = oRs.Fields.Item("count").Value;
	if (count > 0)
	{
	    this.CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE;
	    sql = "select DocEntry from [@COST_BASIC_SETUP]";
	    oRs.DoQuery(sql);
	    int DocEntry = oRs.Fields.Item("DocEntry").Value;
	
	    oDoc.Value = DocEntry.ToString();
	    this.CurrentForm.Items.Item("1").Click();
	}
	else 
	{
	    oDoc.Value = "1";
	}
}

private void B1Form_Cost_BasicSetup_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
{
	if (!pVal.BeforeAction)
   	{
		if (pVal.ItemUID == "1" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.FormMode == 3 && pVal.ActionSuccess == true)
		{
		    this.CurrentForm.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE;
		    this.CurrentForm.Items.Item("3").Enabled = true;
		    SAPbouiCOM.EditText oDoc = this.CurrentForm.Items.Item("3").Specific;
		    oDoc.Value = "1";
		    this.CurrentForm.Items.Item("1").Click();
		    ControlTabStatus();
		}
	}
}

附件.

1.BoDataType Enum(用户数据源的数据类型)

MemberValueDescription
dt_LONG_NUMBER0Long number
dt_SHORT_NUMBER1Short number
dt_QUANTITY2Quantity
dt_PRICE3Price
dt_RATE4Rate
dt_MEASURE5Measure
dt_SUM6Sum
dt_PERCENT7Percent
dt_LONG_TEXT8Long text
dt_SHORT_TEXT9Short text
dt_DATE10Date

2.BoExpandType Enum(下拉框控件的展开类型)

MemberValueDescription
et_ValueDescription0Displays value and description.
et_ValueOnly1Displays value only.
et_DescriptionOnly2Displays description only.

3.BoFormItemTypes Enum(表单项类型)

MemberValueDescription
it_BUTTON4Button (not relevant for column type)
it_STATIC8StaticText (not relevant for column type)
it_EDIT16EditText
it_FOLDER99Folder (not relevant for column type)
it_RECTANGLE100Frame (not relevant for column type)
it_COMBO_BOX113ComboBox
it_LINKED_BUTTON116LinkedButton
it_PICTURE117PictureBox
it_EXTEDIT118EditText with multiple lines
it_CHECK_BOX121CheckBox
it_OPTION_BUTTON122OptionBtn (not relevant for column type)
it_MATRIX127Matrix (not relevant for column type)
it_GRID128Grid
it_PANE_COMBO_BOX104PaneComboBox (not relevant for column type)
it_ACTIVE_X102ActiveX
it_BUTTON_COMBO129ButtonCombo (not relevant for column type)
it_WEB_BROWSER131WebBrowser

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值