216 lines
6.3 KiB
C#
216 lines
6.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Data;
|
||
using System.Data.Common;
|
||
using Wellan.Common;
|
||
|
||
namespace Education
|
||
{
|
||
/// <summary>
|
||
/// 員工群組
|
||
/// </summary>
|
||
public class BWEH_DAC : DAC
|
||
{
|
||
DbCommand cmdInsert = null;
|
||
DbCommand cmdDelete = null;
|
||
|
||
public BWEH_DAC()
|
||
{
|
||
}
|
||
|
||
public BWEH_DAC(string connectionConfig, string connectionConfigName)
|
||
: base(connectionConfig, connectionConfigName)
|
||
{
|
||
}
|
||
|
||
private void PrepareSql()
|
||
{
|
||
EnsureQuery();
|
||
|
||
if (cmdInsert == null)
|
||
{
|
||
cmdInsert = Query.NewCommand("INSERT INTO " + WGuard1.WCFA("BWEH") + " (BPGLP, BPENO) VALUES (@BPGLP, @BPENO)");
|
||
cmdInsert.Parameters.Add(Query.NewParameter("BPGLP", DbType.String));
|
||
cmdInsert.Parameters.Add(Query.NewParameter("BPENO", DbType.String));
|
||
}
|
||
|
||
if (cmdDelete == null)
|
||
{
|
||
cmdDelete = Query.NewCommand("DELETE FROM " + WGuard1.WCFA("BWEH") + " WHERE BPGLP=@BPGLP AND BPENO=@BPENO");
|
||
cmdDelete.Parameters.Add(Query.NewParameter("BPGLP", DbType.String));
|
||
cmdDelete.Parameters.Add(Query.NewParameter("BPENO", DbType.String));
|
||
}
|
||
}
|
||
|
||
public void SelectByBpglp(string bpglp, out DataTable inGroup, out DataTable outGroup)
|
||
{
|
||
PrepareSql();
|
||
inGroup = Query.Select(
|
||
"SELECT E.BPENO AS BPENO, E.BPNME AS BPNME "
|
||
+ " FROM " + WGuard1.WCFA("BPSN") + " E," + WGuard1.WCFA("BWEH") + " G"
|
||
+ " WHERE G.BPENO=E.BPENO AND G.BPGLP='" + bpglp +"' "
|
||
+ " AND E.BPEDY IS NULL "
|
||
+ " ORDER BY E.BPENO ");
|
||
|
||
outGroup = Query.Select(
|
||
"SELECT BPENO, BPNME FROM " + WGuard1.WCFA("BPSN")
|
||
+ " WHERE BPENO<>' ' "
|
||
+ " AND BPEDY IS NULL "
|
||
+ " AND BPENO NOT IN (SELECT E.BPENO AS BPENO "
|
||
+ " FROM " + WGuard1.WCFA("BPSN") + " E," + WGuard1.WCFA("BWEH") + " G"
|
||
+ " WHERE G.BPENO=E.BPENO AND G.BPGLP='" + bpglp + "' "
|
||
+ " AND E.BPEDY IS NULL ) "
|
||
+ " ORDER BY BPENO");
|
||
}
|
||
|
||
public string[] GetBpenoListByBpglp(string bpglp)
|
||
{
|
||
PrepareSql();
|
||
DataTable inGroup = Query.Select(
|
||
"SELECT E.BPENO AS BPENO "
|
||
+ " FROM " + WGuard1.WCFA("BPSN") + " E," + WGuard1.WCFA("BWEH") + " G"
|
||
+ " WHERE G.BPENO=E.BPENO AND G.BPGLP='" + bpglp + "' "
|
||
+ " AND E.BPEDY IS NULL "
|
||
+ " ORDER BY E.BPENO ");
|
||
|
||
if (inGroup.Rows.Count == 0)
|
||
return new string[0];
|
||
else
|
||
{
|
||
string[] result = new string[inGroup.Rows.Count];
|
||
for (int i = 0; i < inGroup.Rows.Count; i++)
|
||
{
|
||
result[i] = inGroup.Rows[i][0].ToString();
|
||
}
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public void UpdateByBpglp(string bpglp, DataTable updateTable)
|
||
{
|
||
PrepareSql();
|
||
DbConnection conn = Query.NewConnection();
|
||
cmdDelete.Connection = conn;
|
||
cmdInsert.Connection = conn;
|
||
conn.Open();
|
||
|
||
DbTransaction tran = conn.BeginTransaction();
|
||
cmdDelete.Transaction = tran;
|
||
cmdInsert.Transaction = tran;
|
||
try
|
||
{
|
||
foreach (DataRow row in updateTable.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Added)
|
||
{
|
||
cmdInsert.Parameters["BPGLP"].Value = bpglp;
|
||
cmdInsert.Parameters["BPENO"].Value = row["BPENO", DataRowVersion.Current];
|
||
cmdInsert.ExecuteNonQuery();
|
||
}
|
||
|
||
if (row.RowState == DataRowState.Deleted)
|
||
{
|
||
cmdDelete.Parameters["BPGLP"].Value = bpglp;
|
||
cmdDelete.Parameters["BPENO"].Value = row["BPENO", DataRowVersion.Original];
|
||
cmdDelete.ExecuteNonQuery();
|
||
}
|
||
}
|
||
tran.Commit();
|
||
updateTable.AcceptChanges();
|
||
}
|
||
catch
|
||
{
|
||
tran.Rollback();
|
||
}
|
||
finally
|
||
{
|
||
conn.Close();
|
||
cmdInsert.Dispose();
|
||
cmdDelete.Dispose();
|
||
}
|
||
}
|
||
|
||
public void SelectByBpeno(string bpeno, out DataTable inGroup, out DataTable outGroup)
|
||
{
|
||
PrepareSql();
|
||
inGroup = Query.Select(
|
||
"SELECT E.BPGLP AS BPGLP, E.BPDSP AS BPDSP "
|
||
+ " FROM " + WGuard1.WCFA("BWEG") + " E," + WGuard1.WCFA("BWEH") + " G"
|
||
+ " WHERE E.BPGLP=G.BPGLP AND G.BPENO='" + bpeno + "' "
|
||
+ " ORDER BY E.BPGLP ");
|
||
|
||
outGroup = Query.Select(
|
||
"SELECT BPGLP, BPDSP FROM " + WGuard1.WCFA("BWEG")
|
||
+ " WHERE BPGLP NOT IN (SELECT BPGLP FROM " + WGuard1.WCFA("BWEH") + " WHERE BPENO='" + bpeno + "')"
|
||
+ " ORDER BY BPGLP");
|
||
}
|
||
|
||
public string[] GetBpglpListByBpeno(string bpeno)
|
||
{
|
||
PrepareSql();
|
||
DataTable inGroup = Query.Select(
|
||
"SELECT E.BPGLP AS BPGLP "
|
||
+ " FROM " + WGuard1.WCFA("BWEG") + " E," + WGuard1.WCFA("BWEH") + " G"
|
||
+ " WHERE E.BPGLP=G.BPGLP AND G.BPENO='" + bpeno + "' "
|
||
+ " ORDER BY E.BPGLP ");
|
||
|
||
if (inGroup.Rows.Count == 0)
|
||
return new string[0];
|
||
else
|
||
{
|
||
string[] result = new string[inGroup.Rows.Count];
|
||
for (int i = 0; i < inGroup.Rows.Count; i++)
|
||
{
|
||
result[i] = inGroup.Rows[i][0].ToString();
|
||
}
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public void UpdateByBpeno(string bpeno, DataTable updateTable)
|
||
{
|
||
PrepareSql();
|
||
DbConnection conn = Query.NewConnection();
|
||
cmdDelete.Connection = conn;
|
||
cmdInsert.Connection = conn;
|
||
conn.Open();
|
||
|
||
DbTransaction tran = conn.BeginTransaction();
|
||
cmdDelete.Transaction = tran;
|
||
cmdInsert.Transaction = tran;
|
||
try
|
||
{
|
||
foreach (DataRow row in updateTable.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Added)
|
||
{
|
||
cmdInsert.Parameters["BPENO"].Value = bpeno;
|
||
cmdInsert.Parameters["BPGLP"].Value = row["BPGLP", DataRowVersion.Current];
|
||
cmdInsert.ExecuteNonQuery();
|
||
}
|
||
|
||
if (row.RowState == DataRowState.Deleted)
|
||
{
|
||
cmdDelete.Parameters["BPENO"].Value = bpeno;
|
||
cmdDelete.Parameters["BPGLP"].Value = row["BPGLP", DataRowVersion.Original];
|
||
cmdDelete.ExecuteNonQuery();
|
||
}
|
||
}
|
||
tran.Commit();
|
||
updateTable.AcceptChanges();
|
||
}
|
||
catch
|
||
{
|
||
tran.Rollback();
|
||
}
|
||
finally
|
||
{
|
||
conn.Close();
|
||
cmdDelete.Dispose();
|
||
cmdInsert.Dispose();
|
||
}
|
||
}
|
||
}
|
||
}
|