117 lines
3.0 KiB
C#
117 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.ComponentModel;
|
|
using WebLib;
|
|
|
|
namespace Education
|
|
{
|
|
[DataObject]
|
|
public class DAC_站別: DAC
|
|
{
|
|
public DAC_站別()
|
|
{ }
|
|
|
|
public DAC_站別(DbConnection conn)
|
|
: base(conn)
|
|
{ }
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public NameValueList SelectForList()
|
|
{
|
|
NameValueList result = new NameValueList();
|
|
|
|
DbCommand cmd1 = NewCommand();
|
|
cmd1.CommandText =
|
|
@"SELECT 'A|' + CAST(組織ID AS VARCHAR) AS VALUE, '[部門] ' + 組織名稱 AS NAME FROM 組織圖
|
|
WHERE 上層ID = 1
|
|
UNION ALL
|
|
SELECT 'B|' + BSCLS AS VALUE, '[站別] ' + BSRMK AS NAME FROM BCLS WHERE BSPAR='BPSNBRH'
|
|
ORDER BY VALUE";
|
|
|
|
bool wantClose;
|
|
IDataReader reader1 = ExecuteReader(cmd1, out wantClose);
|
|
try
|
|
{
|
|
result.Fill(reader1, 1, 0);
|
|
cmd1.Cancel();
|
|
reader1.Close();
|
|
}
|
|
finally
|
|
{
|
|
cmd1.Dispose();
|
|
reader1.Dispose();
|
|
CloseConnection(wantClose);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public NameValueList SelectForDropDown()
|
|
{
|
|
NameValueList result = new NameValueList();
|
|
result.Add("(全部)", "");
|
|
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText =
|
|
@"SELECT 'A|' + CAST(組織ID AS VARCHAR) AS VALUE, '[部門] ' + 組織名稱 AS NAME FROM 組織圖
|
|
WHERE 上層ID = 1
|
|
UNION ALL
|
|
SELECT 'B|' + BSCLS AS VALUE, '[站別] ' + BSRMK AS NAME FROM BCLS WHERE BSPAR='BPSNBRH'
|
|
ORDER BY VALUE";
|
|
|
|
bool wantClose;
|
|
IDataReader reader = ExecuteReader(cmd, out wantClose);
|
|
try
|
|
{
|
|
result.Fill(reader, 1, 0, false);
|
|
cmd.Cancel();
|
|
reader.Close();
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
reader.Dispose();
|
|
CloseConnection(wantClose);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public string GetName(object value)
|
|
{
|
|
if (value == null)
|
|
return "";
|
|
string[] valueParts = DAC.GetString(value).Split('|');
|
|
if (valueParts.Length == 0)
|
|
return "";
|
|
|
|
if (valueParts.Length == 1 || valueParts.Length > 1 && valueParts[0] == "B")
|
|
{
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT BSRMK FROM BCLS WHERE BSPAR='BPSNBRH' AND BSCLS=@BSCLS";
|
|
if (valueParts.Length == 1)
|
|
AddParam(cmd, "BSCLS", valueParts[0]);
|
|
if (valueParts.Length > 1)
|
|
AddParam(cmd, "BSCLS", valueParts[1]);
|
|
string result;
|
|
ExecuteScalar(cmd, out result);
|
|
return result;
|
|
}
|
|
else if (valueParts.Length > 1 && valueParts[0] == "A")
|
|
{
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT 組織名稱 FROM 組織圖 WHERE 組織ID=@組織ID";
|
|
AddParam(cmd, "組織ID", valueParts[1]);
|
|
string result;
|
|
ExecuteScalar(cmd, out result);
|
|
return result;
|
|
}
|
|
else
|
|
return "";
|
|
}
|
|
}
|
|
} |