183 lines
6.0 KiB
C#
183 lines
6.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Services;
|
|
using System.Web.Script.Services;
|
|
using WebLib;
|
|
|
|
namespace 報到系統
|
|
{
|
|
[WebService(Namespace = "http://tempuri.org/")]
|
|
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
|
[System.ComponentModel.ToolboxItem(false)]
|
|
[ScriptService]
|
|
public class RoleManageService : System.Web.Services.WebService
|
|
{
|
|
[WebMethod(EnableSession = true)]
|
|
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
|
|
public BaseResponse SearchEmployees(string keyword)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(keyword))
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = true,
|
|
Message = "請輸入搜尋關鍵字",
|
|
Data = new NameValueList()
|
|
};
|
|
}
|
|
|
|
DAC_BPSN dac = new DAC_BPSN();
|
|
var result = dac.Select(keyword);
|
|
return new BaseResponse
|
|
{
|
|
Success = true,
|
|
Message = "搜尋成功",
|
|
Data = result ?? new NameValueList(),
|
|
TotalCount = result != null ? result.Count : 0
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "搜尋員工失敗:" + ex.Message,
|
|
Data = new NameValueList()
|
|
};
|
|
}
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
|
|
public BaseResponse GetGroupMembers(string groupID)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(groupID))
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = true,
|
|
Message = "請選擇群組",
|
|
Data = new NameValueList()
|
|
};
|
|
}
|
|
|
|
DAC_BWEH dac = new DAC_BWEH();
|
|
var result = dac.SelectByGroupId(groupID);
|
|
return new BaseResponse
|
|
{
|
|
Success = true,
|
|
Message = "取得成功",
|
|
Data = result ?? new NameValueList(),
|
|
TotalCount = result != null ? result.Count : 0
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "取得群組成員失敗:" + ex.Message,
|
|
Data = new NameValueList()
|
|
};
|
|
}
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
|
|
public BaseResponse AddMemberToGroup(string groupID, string[] employeeIDs)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(groupID) || employeeIDs == null || employeeIDs.Length == 0)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "參數不正確"
|
|
};
|
|
}
|
|
|
|
DAC_BWEH dac = new DAC_BWEH();
|
|
int successCount = 0;
|
|
int totalCount = employeeIDs.Length;
|
|
|
|
foreach (string employeeID in employeeIDs)
|
|
{
|
|
if (dac.AddMemberToGroup(groupID, employeeID))
|
|
{
|
|
successCount++;
|
|
}
|
|
}
|
|
|
|
return new BaseResponse
|
|
{
|
|
Success = successCount > 0,
|
|
Message = successCount == totalCount
|
|
? $"成功加入 {successCount} 位成員"
|
|
: $"成功加入 {successCount} 位成員,失敗 {totalCount - successCount} 位",
|
|
TotalCount = successCount
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "加入群組失敗:" + ex.Message
|
|
};
|
|
}
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
|
|
public BaseResponse RemoveMemberFromGroup(string groupID, string[] employeeIDs)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(groupID) || employeeIDs == null || employeeIDs.Length == 0)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "參數不正確"
|
|
};
|
|
}
|
|
|
|
DAC_BWEH dac = new DAC_BWEH();
|
|
int successCount = 0;
|
|
int totalCount = employeeIDs.Length;
|
|
|
|
foreach (string employeeID in employeeIDs)
|
|
{
|
|
if (dac.RemoveMemberFromGroup(groupID, employeeID))
|
|
{
|
|
successCount++;
|
|
}
|
|
}
|
|
|
|
return new BaseResponse
|
|
{
|
|
Success = successCount > 0,
|
|
Message = successCount == totalCount
|
|
? $"成功移除 {successCount} 位成員"
|
|
: $"成功移除 {successCount} 位成員,失敗 {totalCount - successCount} 位",
|
|
TotalCount = successCount
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new BaseResponse
|
|
{
|
|
Success = false,
|
|
Message = "移除群組失敗:" + ex.Message
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|