为文档生成格式化名称我该怎么办? [英] Generate formatted name for document how should I do ?

查看:40
本文介绍了为文档生成格式化名称我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我正在为自己做一个示例项目,我想知道如何根据(CompanyName-projectName-(Number(根据CompanyName-projectName增加该数字)生成DocumentName)

当用户创建一个Document时,他从项目列表中选择了projectName,该列表与创建的Document相关联。我已经通过用户信息知道了他的公司名称。

DocumentNo将是这样的;

[CompanyNamePrefix] - [ProjectCode] - [编号]

Apl - 001 - 00001

Apl - 002 - 00001

Apl - 001 - 00002

Mcf - 001 - 00001

Mcf - 001 - 00002



我在MyDatabase(sqlserver)的公司表中有3个字母的公司名称前缀

我在MyDatabase(sqlserver)的CompanyProject表中有3个字母的ProjectCode

我将同时采用公司名称前缀和ProjectCode并附加,然后将格式化的递增编号附加到它们,然后保存在文档表中创建文档后。



我的问题是,如果用户想要同时创建文档?

我应该如何增加[数量] ?? (我不想使用触发器)我想通过使用纯C#来解决这个问题?可能吗。?我只想要一些逻辑

Hi people I am doing a example project for myself and I am wondering that how can I generate DocumentName based on( CompanyName-projectName-(Number(that number will be incremented by according to CompanyName-projectName))
when the user creates a Document he selects projectName from its projects list which associated with the Document gonna created. I allready know his Company name by user informations.
DocumentNo will be like this;
[CompanyNamePrefix]-[ProjectCode]-[Number]
Apl - 001 - 00001
Apl - 002 - 00001
Apl - 001 - 00002
Mcf - 001 - 00001
Mcf - 001 - 00002

I have 3 letter Company Name Prefix in my Company Table in MyDatabase(sqlserver)
I have 3 letter ProjectCode in CompanyProject Table in MyDatabase(sqlserver)
I will take both Company Name Prefix and ProjectCode and append ,then append formatted incrementing number to them ,then save in Documents Table after creation of Document .

My questions is If more than users want to create Document at the same time ?
How should I increment [Number] ?? (I dont want to use trigger)I want to solve that problem by using pure C# ? Is it possible.? I just want some logic

推荐答案

如果您决定使用存储过程,那么您可以使用大量的教程。

你不要提到你的服务器环境,所以我假设它是一个SQL Server。



SQL Server存储过程 [ ^ ]



存储过程可以通过多种方式输出值。

1.作为表格,例如

If you decide to go for a stored procedure there plenty of tutorials you can use.
You don't mention your server environment, so I just assume that it is an SQL Server.

SQL Server Stored Procedure[^]

A Stored Procedure can output values in several ways.
1. As a table, like
SELECT * FROM Users



2.作为输出参数


2. As an output parameter

PROCEDURE usp_getname(IN userID INT, OUT name VARCHAR(25))



3.作为函数的返回值


3. As a return value from a function

FUNCTION usp_getname(IN userID INT) RETURNS VARCHAR(25))



最常见的可能是使用选项1,因为表中可以有不同数量的列和行。



另一方面,触发器不应该提供任何输出。

您当然可以在触发器代码内更新表,写入文件等,但是因为它是事件驱动的,没有任何输出数据的接收器。



在C#端你可以使用DataAdapter类 [ ^ ]

示例从DataAdapter填充数据集 [ ^ ]



我希望此信息可以帮助您方式。


The most common is probably to use option 1 as you can have variable number of columns and rows in a table.

A trigger on the other hand is not supposed to give any output.
You can of course update a table, write to a file etc. inside the trigger code, but as it is event driven there is no receiver of any output data.

On the C# side you can use a DataAdapter class[^]
Examples Populating a DataSet from a DataAdapter[^]

I hope this info helps you on the way.


这篇关于为文档生成格式化名称我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆