SendWmsTaskAction.cs
29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
using System;
using System.Collections.Generic;
using System.Data;
using Infrastructure;
using Quartz;
using WebApp;
using WebRepository;
namespace WebMvc
{
/// <summary>
/// 任务预警
/// </summary>
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class SendWmsTaskAction
{
private string ConnString { set; get; }
IJobExecutionContext Context { set; get; }
public SendWmsTaskAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute(JobContainer jobContainer)
{
DbHelp dbHelp = new DbHelp(ConnString);
string str = "";
try
{
string sql = "";
string sqlins = "";
//查询未分解的出库主表明细任务
sql = string.Format(@"SELECT B.station,A.sourceCode,A.shipmentCode, A.materialCode, A.batch, A.lot,A.qty,A.status,A.createTime,B.priority,A.qtyDivided
FROM dbo.shipment_detail A
JOIN shipment_header B ON A.shipmentCode = B.code AND A.status = {0}
ORDER BY A.createTime, A.sourceCode",
ShipmentHeaderStatus.新建);
DataSet ds = dbHelp.SelectGet(sql);
int Priority = 0;
string Station = "";
ShipmentDetail sd = new ShipmentDetail();
DataSet dsAlert = new DataSet();
foreach (DataRow dr in ds.Tables[0].Rows)
{
sd.SourceCode = dr["sourceCode"].ToString();
sd.ShipmentCode = dr["shipmentCode"].ToString();
sd.MaterialCode = dr["materialCode"].ToString();
sd.Batch = dr["batch"].ToString();
sd.Lot = dr["lot"].ToString();
sd.Qty = decimal.Parse(dr["qty"].ToString());
Station = dr["station"].ToString();
sd.Status = short.Parse(dr["status"].ToString());
sd.QtyDivided = decimal.Parse(dr["qtyDivided"].ToString());
Priority = int.Parse(dr["priority"].ToString());
str = AddTaskInfo(sd, Station, Priority);
//如果任务没有报错
if (str == "")
{
sqlins = string.Format(@"SELECT A.shipmentCode FROM dbo.shipment_detail A
WHERE A.qty = A.qtyDivided AND A.sourceCode = '{0}' AND A.shipmentCode = '{1}' AND A.materialCode = '{2}'",
sd.SourceCode, sd.ShipmentCode, sd.MaterialCode);
DataSet dcode = dbHelp.SelectGet(sqlins);
//出库是否任务完成
if (dcode.Tables[0].Rows.Count > 0)
{
//将出库主表明细已分配数量更改为已分配数量,状态更新为分配完成
sqlins = string.Format(@"UPDATE dbo.shipment_detail
SET status = {0}
WHERE sourceCode = '{1}' AND shipmentCode = '{2}' AND materialCode = '{3}'",
ShipmentHeaderStatus.分配完成, sd.SourceCode, sd.ShipmentCode, sd.MaterialCode);
dbHelp.DataOperator(sqlins);
//删除库存预警中的数据
sqlins = string.Format(@"DELETE dbo.inventory_Alert
WHERE shipmentCode = '{0}' AND materialCode = '{1}'",
sd.ShipmentCode, sd.MaterialCode);
dbHelp.DataOperator(sqlins);
}
//任务数量大于已分配数量
else
{
//查询库存预警表中符合当前物料号和出库单编码的数据
sqlins = string.Format(@"SELECT shipmentCode FROM dbo.inventory_Alert
WHERE shipmentCode = '{0}' AND materialCode = '{1}'",
sd.ShipmentCode, sd.MaterialCode);
dsAlert = dbHelp.SelectGet(sqlins);
//如果不存在符合的数据,创建相关数据的库存预警表数据
if (dsAlert.Tables[0].Rows.Count == 0)
{
sqlins = string.Format(@"INSERT INTO dbo.inventory_Alert (shipmentCode, materialCode, Qty, hadQty, createTime, createBy)
VALUES ('{0}','{1}',{2},{3},'{4}','System')",
sd.ShipmentCode, sd.MaterialCode, sd.Qty, sd.QtyDivided, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlins);
}
//如果存在符合的条件,将更新时间和已分配数量更新
else
{
sqlins = string.Format(@"UPDATE dbo.inventory_Alert
SET updateTime = '{3}', hadQty = {0}
WHERE shipmentCode = '{1}' AND materialCode = '{2}'",
sd.QtyDivided, sd.ShipmentCode, sd.MaterialCode, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlins);
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
//根据出库单明细数据创建Task主子任务
public string AddTaskInfo(ShipmentDetail shipmentDetail, string Station, int Priority)
{
string strError = "";
string sqlsh = "";
string sqltask = "";
string sqlinv = "";
string sqlShDeil = "";
string sqlInsDeil = "";
string sqldeil = "";
string sqlType = "";
string sqlStation = "";
DbHelp dbHelp = new DbHelp(ConnString);
try
{
//建立单据主任务和明细任务
Task task = new Task();
var tno = "";
//判断是否已经创建过Task主任务数据
sqlsh = string.Format(@"SELECT A.taskNo,B.type,B.totalQty,B.totalLines FROM dbo.task A
JOIN dbo.shipment_header B ON A.orderCode = B.code AND A.orderCode = '{0}'",
shipmentDetail.ShipmentCode);
DataSet ds = dbHelp.SelectGet(sqlsh);
if (ds.Tables[0].Rows.Count > 0)
{
tno = ds.Tables[0].Rows[0]["taskNo"].ToString();
}
else
{
//根据出库子表数据创建任务主表数据
tno = GetTaskNo(TaskNo.出库自动分配);
sqltask = string.Format(@"INSERT INTO dbo.task (taskNo, sourceCode, orderCode, firstStatus, lastStatus, createTime, createBy)
VALUES ('{0}','{1}','{2}',{3},{4},'{5}','{6}')",
tno, shipmentDetail.SourceCode, shipmentDetail.ShipmentCode, TaskStatus.待下发任务, TaskStatus.待下发任务, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), "System");
dbHelp.DataOperator(sqltask);
}
//查询满足条件可用的库存(根据批次排序)
sqlinv = string.Format(@"SELECT A.materialCode,A.containerCode,ISNULL(A.qty,0) qty,A.locationCode,ISNULL(C.roadway,0) roadway,A.oldBatch,A.lot FROM dbo.inventory A
JOIN container B ON A.containerCode = B.code
AND A.taskStatus = 'idle' AND B.IsLock != 2 AND A.materialCode = '{0}'
JOIN dbo.location C ON C.code = A.locationCode
ORDER BY A.batch",
shipmentDetail.MaterialCode);
DataSet dinv = dbHelp.SelectGet(sqlinv);
//任务所需要出库的数量
var sqty = shipmentDetail.Qty - shipmentDetail.QtyDivided;
decimal invQty;
foreach (DataRow dr in dinv.Tables[0].Rows)
{
//查询当前所选库存的托盘是否已经存在其他出库任务,并且和当前任务的目的站台不同(判断当前库存的容器是否可用)
sqlShDeil = string.Format(@"SELECT taskNo FROM dbo.task_detail
WHERE station <> '{0}' AND containerCode = '{1}' AND taskType <> '{2}'",
Station, dr["containerCode"].ToString(), TaskType.容器出库);
DataSet dShDeil = dbHelp.SelectGet(sqlShDeil);
if (dShDeil.Tables[0].Rows.Count == 0)
{
invQty = decimal.Parse(dr["qty"].ToString());
//查询当前容器的任务已完成数量
sqlShDeil = string.Format(@"SELECT ISNULL(SUM(hadQty),0) hadQty FROM dbo.task_detail
WHERE materialCode = '{0}' AND status >= {1} AND status < {2} AND containerCode = '{3}' AND taskNo NOT LIKE 'I%'",
shipmentDetail.MaterialCode, TaskStatus.新建任务, TaskStatus.已经完成, dr["containerCode"].ToString());
dShDeil = dbHelp.SelectGet(sqlShDeil);
}
else
{
continue;
}
//如果存在当前容器的任务,并且已完成数量不为0
if (decimal.Parse(dShDeil.Tables[0].Rows[0]["hadQty"].ToString()) != 0)
{
decimal taskhadqty = decimal.Parse(dShDeil.Tables[0].Rows[0]["hadQty"].ToString());
invQty = invQty - taskhadqty;
}
if (invQty == 0)
{
continue;
}
//库存数量大于要出库的数量(创建容器分拣出库任务子表和容器出库任务主子表)
if (invQty >= sqty)
{
var a = dr["containerCode"].ToString();
var b = dr["oldBatch"].ToString();
var c = dr["lot"].ToString();
//根据出库子表数据创建分拣出库类型任务子表表数据
TaskDetail taskDetail = new TaskDetail();
sqlInsDeil = string.Format(@"INSERT INTO dbo.task_detail (taskNo, taskType, sourceCode, containerCode, orderCode, materialCode, batch, lot, oderQty, containerQty, hadQty, sourceLocation, destinationLocation, roadway, station, status, priority, createTime)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9},{10},'{11}','{12}',{13},'{14}',{15},'{16}','{17}')",
tno, TaskType.分拣出库, shipmentDetail.SourceCode, dr["containerCode"].ToString(), shipmentDetail.ShipmentCode, dr["materialCode"].ToString(), dr["oldBatch"].ToString(),
dr["lot"].ToString(), shipmentDetail.Qty, invQty, sqty, dr["locationCode"].ToString(), Station, dr["roadway"].ToString(),
Station, TaskStatus.待下发任务, Priority, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlInsDeil);
//判断是否可以创建容器出库任务主子表数据
//查询当前容器是否已经创建
sqldeil = string.Format(@"SELECT taskNo FROM dbo.task_detail
WHERE status >= {0} AND status < {1} AND taskType = '{2}' AND containerCode = '{3}'",
TaskStatus.待下发任务, TaskStatus.已经完成, TaskType.容器出库, dr["containerCode"].ToString());
DataSet dDeil = dbHelp.SelectGet(sqldeil);
//当前容器还没有创建容器出库任务
if (dDeil.Tables[0].Rows.Count == 0)
{
//创建容器出库类型任务主表数据
var taskNo = GetTaskNo(TaskNo.容器出库);
sqltask = string.Format(@"INSERT INTO dbo.task (taskNo, sourceCode, orderCode, businessType, firstStatus, lastStatus, createTime, createBy)
VALUES ('{0}','{1}','{2}','{3}',{4},{5},'{6}','{7}')",
taskNo, shipmentDetail.SourceCode, shipmentDetail.ShipmentCode, BusinessType.出库_其他出库单
, TaskStatus.待下发任务, TaskStatus.待下发任务, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), "System");
dbHelp.DataOperator(sqltask);
//创建容器出库类型任务子表数据
sqlInsDeil = string.Format(@"INSERT INTO dbo.task_detail (taskNo, taskType, sourceCode, containerCode, orderCode, materialCode, batch, lot, oderQty, containerQty, hadQty, sourceLocation, destinationLocation, roadway, station, status, priority, createTime)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9},{10},'{11}','{12}',{13},'{14}',{15},'{16}','{17}')",
taskNo, TaskType.容器出库, shipmentDetail.SourceCode, dr["containerCode"].ToString(), shipmentDetail.ShipmentCode, shipmentDetail.MaterialCode, shipmentDetail.Batch,
shipmentDetail.Lot, 0, 0, 0, dr["locationCode"].ToString(), Station, dr["roadway"].ToString(),
Station, TaskStatus.待下发任务, Priority, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlInsDeil);
}
//已经创建了容器出库任务
else
{
//更新单据出入库主任务头尾状态和明细任务状态
//查询当前容器已经创建并且任务已执行的容器出库类型任务子表数据
string taskdetailsql = string.Format(@"SELECT taskNo FROM dbo.task_detail
WHERE taskType = '{0}' AND status > {1} AND status < {2} AND containerCode = '{3}'",
TaskType.容器出库, TaskStatus.待下发任务, TaskStatus.已经完成, dr["containerCode"].ToString());
DataSet taskdetailds = dbHelp.SelectGet(taskdetailsql);
//当前容器已经创建并且任务已执行的容器出库类型任务子表数据,
if (taskdetailds.Tables[0].Rows.Count > 0)
{
//当前托盘已经有了容器出库任务,并且任务已经执行
//将当前托盘的第二条任务的分拣出库类型任务主子表状态更改为已下发
string sqld = string.Format("UPDATE dbo.task_detail SET status = {0} WHERE containerCode = '{1}' AND status >= {2} AND status < {3} AND taskNo = '{4}';",
TaskStatus.下达任务, dr["containerCode"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成, tno);
dbHelp.DataOperator(sqld);
//查询前面已经创建的任务主表数据
string tasksql = string.Format("select * from [dbo].[task] where taskNo in (select taskNo from dbo.task_detail WHERE containerCode = '{0}' AND status >= {1} AND status < {2} AND taskNo = '{3}'); ",
dr["containerCode"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成, tno);
DataSet taskds = dbHelp.SelectGet(tasksql);
for (int i = 0; i < taskds.Tables[0].Rows.Count; i++)
{
//查询已经创建的分拣出库类型任务子表数据
taskdetailsql = string.Format("select top 1 status from dbo.task_detail WHERE taskNo = '{0}' AND status >= {1} AND status < {2} ORDER BY status; ",
taskds.Tables[0].Rows[i]["taskNo"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成);
taskdetailds = dbHelp.SelectGet(taskdetailsql);
int minstatus = int.Parse(taskdetailds.Tables[0].Rows[0]["status"].ToString());
//将当前已创建的分拣出库类型任务主表状态更新为已下发
//更新单据任务的头状态
if (int.Parse(taskds.Tables[0].Rows[i]["firstStatus"].ToString()) < TaskStatus.下达任务)
{
string uptaskdjf = string.Format("update [dbo].[task] set firstStatus={0} WHERE taskNo= '{1}';", TaskStatus.下达任务, taskds.Tables[0].Rows[i]["taskNo"].ToString());
dbHelp.DataOperator(uptaskdjf);
}
//更新单据任务的尾状态
if (int.Parse(taskds.Tables[0].Rows[i]["lastStatus"].ToString()) < minstatus)
{
string uptaskdjl = string.Format("update [dbo].[task] set lastStatus='{0}' WHERE taskNo= '{1}';", minstatus, taskds.Tables[0].Rows[i]["taskNo"].ToString());
dbHelp.DataOperator(uptaskdjl);
}
}
}
}
shipmentDetail.QtyDivided += sqty;
break;
}
//库存数量小于要出库的数量
else
{
//出库主表任务明细
TaskDetail taskDetail = new TaskDetail();
//创建整盘出库类型任务子表数据
sqlInsDeil = string.Format(@"INSERT INTO dbo.task_detail (taskNo, taskType, sourceCode, containerCode, orderCode, materialCode, batch, lot, oderQty, containerQty, hadQty, sourceLocation, destinationLocation, roadway, station, status, priority, createTime)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9},{10},'{11}','{12}',{13},'{14}',{15},'{16}','{17}')",
tno, TaskType.整盘出库, shipmentDetail.SourceCode, dr["containerCode"].ToString(), shipmentDetail.ShipmentCode, shipmentDetail.MaterialCode, shipmentDetail.Batch,
shipmentDetail.Lot, shipmentDetail.Qty, invQty, invQty, dr["locationCode"].ToString(), Station, int.Parse(dr["roadway"].ToString()),
Station, TaskStatus.待下发任务, Priority, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlInsDeil);
//剩余没有出库的数量
sqty = sqty - invQty;
// 判断是否可以创建容器出库任务主子表数据
//查询当前容器是否已经创建
sqldeil = string.Format(@"SELECT taskNo FROM dbo.task_detail
WHERE status >= {0} AND status < {1} AND taskType = '{2}' AND containerCode = '{3}'",
TaskStatus.新建任务, TaskStatus.已经完成, TaskType.容器出库, dr["containerCode"].ToString());
DataSet dDeil = dbHelp.SelectGet(sqldeil);
//容器出库任务未创建
if (dDeil.Tables[0].Rows.Count == 0)
{
//创建容器出库类型任务主表数据
var taskNo = GetTaskNo(TaskNo.容器出库);
sqltask = string.Format(@"INSERT INTO dbo.task (taskNo, sourceCode, orderCode, businessType, firstStatus, lastStatus, createTime, createBy)
VALUES ('{0}','{1}','{2}','{3}',{4},{5},'{6}','{7}')",
taskNo, shipmentDetail.SourceCode, shipmentDetail.ShipmentCode, BusinessType.出库_其他出库单
, TaskStatus.待下发任务, TaskStatus.待下发任务, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), "System");
dbHelp.DataOperator(sqltask);
//创建容器出库类型任务子表数据
sqlInsDeil = string.Format(@"INSERT INTO dbo.task_detail (taskNo, taskType, sourceCode, containerCode, orderCode, materialCode, batch, lot, oderQty, containerQty, hadQty, sourceLocation, destinationLocation, roadway, station, status, priority, createTime)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9},{10},'{11}','{12}',{13},'{14}',{15},'{16}','{17}')",
taskNo, TaskType.容器出库, shipmentDetail.SourceCode, dr["containerCode"].ToString(), shipmentDetail.ShipmentCode, shipmentDetail.MaterialCode, shipmentDetail.Batch,
shipmentDetail.Lot, 0, 0, 0, dr["locationCode"].ToString(), Station, dr["roadway"].ToString(),
Station, TaskStatus.待下发任务, Priority, DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
dbHelp.DataOperator(sqlInsDeil);
}
//容器出库任务已创建
else
{
//更新单据出入库主任务头尾状态和明细任务状态
//查询当前容器已经创建并且任务已执行的容器出库类型任务子表数据,
string taskdetailsql = string.Format(@"SELECT taskNo FROM dbo.task_detail
WHERE taskType = '{0}' AND status > {1} AND status < {2} AND containerCode = '{3}'",
TaskType.容器出库, TaskStatus.待下发任务, TaskStatus.已经完成, dr["containerCode"].ToString());
DataSet taskdetailds = dbHelp.SelectGet(taskdetailsql);
//存在当前容器已经创建并且任务已执行的容器出库类型任务子表数据,
if (taskdetailds.Tables[0].Rows.Count > 0)
{
// 当前托盘已经有了容器出库任务,并且任务已经执行
//将当前托盘的第二条任务的分拣出库类型任务主子表状态更改为已下发
string sqld = string.Format("UPDATE dbo.task_detail SET status = {0} WHERE containerCode = '{1}' AND status >= {2} AND status < {3} AND taskNo = '{4}';",
TaskStatus.下达任务, dr["containerCode"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成, tno);
dbHelp.DataOperator(sqld);
//查询前面已经创建的任务主表数据
string tasksql = string.Format("select * from [dbo].[task] where taskNo in (select taskNo from dbo.task_detail WHERE containerCode = '{0}' AND status >= {1} AND status < {2} AND taskNo = '{3}'); ",
dr["containerCode"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成, tno);
DataSet taskds = dbHelp.SelectGet(tasksql);
for (int i = 0; i < taskds.Tables[0].Rows.Count; i++)
{
//查询已经创建的分拣出库类型任务子表数据
taskdetailsql = string.Format("select top 1 status from dbo.task_detail WHERE taskNo = '{0}' AND status >= {1} AND status < {2} ORDER BY status; ",
taskds.Tables[0].Rows[i]["taskNo"].ToString(), TaskStatus.新建任务, TaskStatus.已经完成);
taskdetailds = dbHelp.SelectGet(taskdetailsql);
//任务状态
int minstatus = int.Parse(taskdetailds.Tables[0].Rows[0]["status"].ToString());
//更新单据任务的头状态
//将当前已创建的分拣出库类型任务主表状态更新为已下发
if (int.Parse(taskds.Tables[0].Rows[i]["firstStatus"].ToString()) < TaskStatus.下达任务)
{
string uptaskdjf = string.Format("update [dbo].[task] set firstStatus={0} WHERE taskNo= '{1}';", TaskStatus.下达任务, taskds.Tables[0].Rows[i]["taskNo"].ToString());
dbHelp.DataOperator(uptaskdjf);
}
//更新单据任务的尾状态
if (int.Parse(taskds.Tables[0].Rows[i]["lastStatus"].ToString()) < minstatus)
{
string uptaskdjl = string.Format("update [dbo].[task] set lastStatus='{0}' WHERE taskNo= '{1}';", minstatus, taskds.Tables[0].Rows[i]["taskNo"].ToString());
dbHelp.DataOperator(uptaskdjl);
}
}
}
}
shipmentDetail.QtyDivided += invQty;
}
}
sqlinv = string.Format(@"UPDATE dbo.shipment_detail
SET qtyDivided = {0}, qtyCompleted = '{4}'
WHERE sourceCode = '{1}' AND shipmentCode = '{2}' AND materialCode = '{3}' ",
shipmentDetail.QtyDivided, shipmentDetail.SourceCode, shipmentDetail.ShipmentCode, shipmentDetail.MaterialCode, shipmentDetail.QtyDivided);
dbHelp.DataOperator(sqlinv);
}
catch (Exception ex)
{
strError = ex.Message;
return strError;
}
return strError;
}
//根据不同任务类型获取任务号
public string GetTaskNo(string TaskType, int SeqLength = 4)
{
string Value = "1";
string sql = "";
string sqlup = "";
DbHelp dbHelp = new DbHelp(ConnString);
sql = string.Format(@"SELECT Type, Value
FROM dbo.sys_count
WHERE Type = '{0}'",
TaskType);
DataSet ds = dbHelp.SelectGet(sql);
string sysValue = ds.Tables[0].Rows[0]["Value"].ToString();
if (sysValue == null)
{
Value = TaskType + DateTime.Now.ToString("yyyyMMdd") + Value.PadLeft(SeqLength, '0');
sqlup = string.Format(@"UPDATE dbo.sys_count
SET Value = '{0}'
WHERE Type = '{1}'",
Value, TaskType);
dbHelp.DataOperator(sqlup);
}
else
{
string Date = sysValue.Substring(TaskType.Length, 8);
if (Date == DateTime.Now.ToString("yyyyMMdd"))
{
Value = Date + (int.Parse(sysValue.Substring(sysValue.Length - 4, 4)) + 1).ToString().PadLeft(SeqLength, '0');
}
else
{
Value = DateTime.Now.ToString("yyyyMMdd") + Value.PadLeft(SeqLength, '0');
}
Value = TaskType + Value;
sqlup = string.Format(@"UPDATE dbo.sys_count
SET Value = '{0}'
WHERE Type = '{1}'",
Value, TaskType);
dbHelp.DataOperator(sqlup);
}
return Value;
}
}
}