规范要求

  • 格式:docx
  • 大小:124.86 KB
  • 文档页数:11

规范要求●不要直接操作控件,多使用datarow,datatable,注意用完以后endedit()●多用try-catch.在Form_BeforeSave()中必须加一个Try-catchtry{ }catch(Exception ee){this.ShowMessage(ee.Message);this.ContainerForm.CanSave=false;}目的,提示更友好,代码有错后,不会将错误数据写入数据库。

●尽量使用FormGridCtr控件,FormGridCtr主要封装了dev express的GridView控件●一般在每个表单的最前边声明控件的变量,不要在方法里声明FormGridCtr fgc {get{ return this["formGridCtr3"] as FormGridCtr;}}ComboBox cbx {get{ return this["comboBox3"] as ComboBox;}}●多使用string.Format提高字符串的可读性string sql = string.Format(“select * from wlxx where wlbh=‘{0}’ and wlmc=‘{1}’”,“物料编码”,“物料名称");常用方法A、流程表单打开脚本时去掉新增和删除按钮try{if(form.ContainerForm.Context!=null){(form.ContainerForm.Context as Zap.Window.Flow.ucWfForm).FlowFormToolBar.Items["itemDelete"].Visible=false;(form.ContainerForm.Context as Zap.Window.Flow.ucWfForm).FlowFormToolBar.Items["itemAdd"].Visible=false;}}catch(Exception ee){}B、不显示表单上的发起按钮this.FindToolStripButtonByName("btnSingleFlow",this.ContainerForm.ParentForm).Visible=false;1、窗口最大化FormGlobalScript.SetFormAnchor(this);然后设置要最大化的控件的Anchor2、FormGridCtr控件字段格式化FormGlobalScript.SetFormGridCtrDisPlayFormat(控件变量);3、将object转成decimalFormGlobalScript.getDec(要转换的对象)4、获得从数据集的DataSource(DataTable)DataTable dt = this.CurrentView.GuidToTableMap[数据集的GUID]5、得到当前流程任务的前置节点GUIDFormGlobalScript.getTaskPreNodeGuid(当前流程任务IDTaskid)6、打开新的表单FormGlobalScript.OpenWindow(FormType type,string bizGuid,string DataGuid,string ViewGuid,string FormGuid,DataRow dr)7、辅助增加选择数据DataRow[] DR= FormGlobalScript.AssInput(string guid,string keyCol,string filter)8、执行一段sql语句从数据库中取得数据DataSet ds = ZapDataVie w.GetAnyDataSet(“你的sql语句");9、根据数据集的guid从数据获取数据ZapDataView zdvBOM = new ZapDataView(“数据集的GUID");//设置zdvBOM.Filter过滤条件来得到自己需要的数据,必须设置FilterzdvBOM.Filter=string.Format("zyid={0} and pnode={1}",sZyid,sPnode);zdvBOM.OpenDataView();zdvBOM可以看成DataSet来使用。

9、用户变量erVariables[“我的变量名”]=我要传递的对象;UserVariables可以存储任何对象比如string,int,DataTable,DataRow,DataView10、视图变量ZapDataView.ViewParameters[“我的变量名”]=“只能存字符串”;这里声明的视图变量主要用于数据集的sql。

11、得到登陆用户的stid和stname表单中:string stid = this.CurrentUser.Id.ToString();string stname = ;业务脚本中:mon.SystemVar.Instance.ST_ID.ToString();mon.SystemVar.Instance.ST_NAME;12、取得登陆用户的所属部门和名称sys_staffdef.deptidGetDept(ref string deptId,ref string deptName)13、取服务器的当前时间DateTime date = FormGlobalScript.GetServerDateTime()14、自动单号函数(FormGlobalScript)get_new_billnum(string as_class, string as_type, string as_sub_type, string as_sub_sub_type, int ai_count, ref ArrayList as_billnum)15、取某物理表的主键的下一个新值(FormGlobalScript)1)、GetNextKey(string as_tbl_name, string as_key_col, ref string as_key_value)2)、GetNextKey(string as_tbl_name, string as_key_col, ref List<string> key,int count)16、分解BOM函数(FormGlobalScript)GetBom(string as_id, string as_execute_location, decimal ai_sl, ref System.Data.DataTable adt_result, string as_sgdh, int ai_first)17、对附件操作1)、将附件数据集挂到主视图下(row_guid=to_row_guid)FormGlobalScript fgs = new FormGlobalScript();2)、表单中新增附件fgs.AddAffix(this,主视图的rowGuid,innervercontrol控件的名字);3)、表单中删除附件fgs.DeleteAffix(this,innervercontrol控件的名字);4)、表单中预览附件fgs.OpenAffix(this,innervercontrol控件的名字);表单常用控件及用法1、ButtonTextBox值改变前事件,用于判断值是否应该改变(this["textFlStatus"] as ButtonTextBox).EditValueChanging+= delegate(object s, DevExpress.XtraEditors.Controls.ChangingEventArgs e1) {if(条件){e1.Cancel=true;this.ShowMessage("xxxx");}};2、ButtonTextBox过滤下拉列表的数据1)(this["textFlStatus"] as ButtonTextBox).ViewFilter="表达式“2)textbox.SelectedRow取得下拉所选行,进而可以取得其他的字段值textbox.SelectedRow[字段名]3、ComboBox更改下拉字段的数据源数据1)((this["cbXqlx"] as ComboBox).DataSource as DataTable).DefaultView.RowFilter="表达式";2)((this["cbXqlx"] as ComboBox).SelectedItem as DataRowView)[字段名]4、FormGridCtr常用的用法1) 取得当前行对应的DataRow DataRow drC = fgc.CurrentRow2) 取得指定行对应的DataRow DataRow dr = fgc.InnerGridView.GetDataRow(指定行)3) 设置整个控制只读在属性区域将Editable设成false4)隐藏分组区域,在属性区域将ShowGroupPanel设成false5) 打开页脚在属性区域将ShowFooter设成true6)如果要隐藏工具栏在属性区域(工具栏) 将属性‘显示工具栏’设成false7)显示添加按钮、删除按钮在属性区域(工具栏) 将属性‘显示删除按钮’‘显示添加按钮’设成true8)对控件的列或其他属性设置。

某一列在页脚显示合计数字:点到要显示的列修改SummaryItem区域的属性SummaryType=sum,等等以下是对行为(事件)的使用9)点新增时弹出辅助窗口选多行数据,然后添加到数据集中fgcQd.BeforeAdd+= delegate(object sender, ponentModel.CancelEventArgs e) {e.Cancel=true;DataRow[] DR= FormGlobalScript.AssInput(string guid,string keyCol,string filter)foreach(DataRow dr in DR){具体操作}};10)值更改时fgcQd.InnerGridView.FocusedRowChanged+= delegate(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if(e.FocusedRowHandle<0) return; DataRow dr = fgcQd.CurrentRow; if(fgc.InnerGridView.FocusedColumn.FieldName.ToLower()=="""") { 具体操作} };11)值校验事件fgc.InnerGridView.ValidatingEditor+= delegate(object sender1, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e1) {if(fgc.InnerGridView.FocusedColumn.FieldName.ToLower()==""""){string ss =e1.Value.ToString();if(ss==""221""){e1.Valid=false;this.ShowMessage(""xxxxxx"");SendKeys.Send(""{ESC}"");}}};11)行切换事件fgc.InnerGridView.FocusedRowChanged+= delegate(object sender1,DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e1) {};12)数据过滤((fgc.InnerGridControl.DataSource as BindingSource).List as DataView).RowFilter="hgsl >0";13)Group分组后,如果新增数据,需要执行以下代码刷新数据fgc.InnerGridView.RefreshData();表单常用控件及用法-InnerViewControlDataGridView dgv = this["inv_qtfsrkqd"] as DataGridView;得到当前行对应的DataRowViewDataRowView drvC = dgv_wlrkqd.CurrentRow.DataBoundItem as DataRowView得到指定行对应的DataRowViewDataRowView drvC = dgv_wlrkqd.Rows[指定行].DataBoundItem as DataRowView1)让题头居中dgv.ColumnHeadersDefaultCellStyle.Alignment=DataGridViewContentAlignment.MiddleCenter;2)设置整个控件数据只读dgv.ReadOnly=true;3)设置某些列只读,某些列可编辑for(int i=0;i<inv.Columns.Count;i++){inv_qtfsrkqd.Columns[i].ReadOnly = true;if( inv.Columns[i].ValueType==null)continue;if (inv.Columns[i].ValueType.ToString() == "System.Decimal"){inv.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;//设置列的内容居右inv.Columns[i].DefaultCellStyle.Format = "n";//设置数字列显示2位小数}}inv_qtfsrkqd.Columns["rksl"].ReadOnly = false;inv_qtfsrkqd.Columns["rkdj"].ReadOnly = false;4)列值校验dgv.CellValidating+= delegate(object sender1, DataGridViewCellValidatingEventArgs e1) { int row = e.RowIndex;int col = e.ColumnIndex;if(dgv.Columns[col].DataPropertyName == "rksl"){ // 修改了入库数量if(0 >= Convert.ToDecimal(e.FormattedValue)){MessageBox.Show("入库数量:" + Convert.ToString(e.FormattedValue) + "应大于0!", "提示");dgv.CurrentCell = dgv.Rows[row].Cells[col];dgv.Rows[row].Cells[col].Selected = true;dgv.CancelEdit();//放弃之前的更改}}};5)值更改后dgv.CellValueChanged+= delegate(object sender1, DataGridViewCellEventArgs e1) { switch (dgv.Columns[e.ColumnIndex].DataPropertyName) {case "rkdj":具体操作break;case "rkdj_fs":具体操作break;default:break;}};业务脚本常用代码1.1、方法ExtendToolBar()、ExtendContextMenu() 在业务打开的时候,一定会执行,所有有些设置类的代码都需要在这里编写。