钉钉氚云平台人事管理学习日记单据流水号
Posted no-trouble
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了钉钉氚云平台人事管理学习日记单据流水号相关的知识,希望对你有一定的参考价值。
今天产品小哥过来跟我说要做一个自动产生流水号的功能,由于该字段是位于表体,系统标准流水号功能只支持表头,所以需要进行开发。
设计思路:查询数据库中最大流水编号,+1 后update字段
其实有想过做一个种子表的,但由于其前面编号的规则是根据2个下拉框结果组合产生的,就是年+A字段+B字段+流水号,一种组合生成一种流水号编码,要根据所有组合一一创建种子表,不建议使用。
话不多说,上代码
using System;
using System.Collections.Generic;
using System.Text;
using H3;
public class D001365b02412ae8b784b3f94f8789416a9e42e: H3.SmartForm.SmartFormController
public D001365b02412ae8b784b3f94f8789416a9e42e(H3.SmartForm.SmartFormRequest request): base(request)
protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
base.OnLoad(response);
// string a ="19S001";
// string b=a.Length.ToString();
// response.Message=b;
protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response)
base.OnSubmit(actionName, postValue, response);
if(actionName == "Submit")
//判断是否是新增
bool isCreateMode = this.Request.IsCreateMode;
// if(isCreateMode == true)
//
string headtablename = "D001365b02412ae8b784b3f94f8789416a9e42e";
string entitytablename = "D001365F732ebe2190a845c7863dc39511ef3407";
// string headtablename = "D001365ff79a1a3560f4658a9156701f2bc83a3";
// string entitytablename = "D001365a139d3ff1a834f2bab4c45aa2be0ae0e";
string oldfield = "F0000072";
//加载当前对象
H3.DataModel.BizObject currentBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, this.Request.Engine, headtablename, this.Request.BizObject.ObjectId, false);
//获取子表的数据
H3.DataModel.BizObject[] entity = (H3.DataModel.BizObject[]) currentBo[entitytablename];
for(int i = 0;i < entity.Length; i++)
string number = entity[i][oldfield].ToString();
int len = number.Length;
//判断长度
if(len == 6)
int historynumber = HistoryNumber.GetHistoryNumber(this.Request.Engine, entitytablename, number) + 1;
string newnumber = number + historynumber.ToString().PadLeft(3, ‘0‘);
entity[i][oldfield] = newnumber;
entity[i].Update();
response.Refresh = true;
//
//获取流水号编码公共类
public class HistoryNumber
public static int GetHistoryNumber(H3.IEngine engine, string entitytablename, string number)
int m = 0;
//表名为阅读工作计划表
if(entitytablename == "D001365F732ebe2190a845c7863dc39511ef3407")
//if(entitytablename == "D001365a139d3ff1a834f2bab4c45aa2be0ae0e")
string field = "F0000072";
//构建表名
string sqltablename = "I_" + entitytablename;
string sql2 = string.Format("SELECT * FROM 0 ", sqltablename);
System.Data.DataTable dt2 = engine.Query.QueryTable(sql2, null);
//string sql = string.Format("select substring(2,6) as historynumber from 0 where 3 like ‘1%‘ and LENGTH(4) >6 order by substring(5,6) desc limit 1 ", sqltablename, number, newfield, newfield, newfield, newfield);
string sql = string.Format("select right(2,3) as historynumber from 0 where 3 like ‘1%‘ and LENGTH(4) >6 order by right(5,3) desc limit 1 ", sqltablename, number, field, field, field, field);
System.Data.DataTable dt = engine.Query.QueryTable(sql, null);
if(dt != null && dt.Rows.Count > 0)
int historynumber = Convert.ToInt32(dt.Rows[0]["historynumber"]);
return historynumber;
else //没有记录,则赋予初始流水号
return m;
else
return m;
流水号规则是前六位根据用户选择生成+3位流水号,由于前六位根据用户选择生成并有显示在流水号字段,所以我获取了单据上流水号字段,并在数据库中用order by和like截取了后三位最大的流水号,且判断只有字段长度为6才会触发获取流水号事件
以上是关于钉钉氚云平台人事管理学习日记单据流水号的主要内容,如果未能解决你的问题,请参考以下文章