SGGL_SHJ/SGGL/BLL/CQMS/RewardAndPunish/RewardAndPunishService.cs

401 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
namespace BLL
{
/// <summary>
/// 质量奖罚
/// </summary>
public static class RewardAndPunishService
{
public static Model.SGGLDB db = Funs.DB;
/// <summary>
/// 根据主键获取质量奖罚
/// </summary>
/// <param name="RewardAndPunishId"></param>
/// <returns></returns>
public static Model.RewardAndPunish_RewardAndPunish GetRewardAndPunishById(string RewardAndPunishId)
{
return Funs.DB.RewardAndPunish_RewardAndPunish.FirstOrDefault(e => e.RewardAndPunishId == RewardAndPunishId);
}
/// <summary>
/// 添加质量奖罚
/// </summary>
/// <param name="RewardAndPunish"></param>
public static void AddRewardAndPunish(Model.RewardAndPunish_RewardAndPunish RewardAndPunish)
{
Model.SGGLDB db = Funs.DB;
Model.RewardAndPunish_RewardAndPunish newRewardAndPunish = new Model.RewardAndPunish_RewardAndPunish
{
RewardAndPunishId = RewardAndPunish.RewardAndPunishId,
ProjectId = RewardAndPunish.ProjectId,
RewardAndPunishCode = RewardAndPunish.RewardAndPunishCode,
UnitId = RewardAndPunish.UnitId,
Type = RewardAndPunish.Type,
RewardAndPunishTypeId = RewardAndPunish.RewardAndPunishTypeId,
RewardAndPunishBasis = RewardAndPunish.RewardAndPunishBasis,
RewardAndPunishDecision = RewardAndPunish.RewardAndPunishDecision,
State = RewardAndPunish.State,
CompileMan = RewardAndPunish.CompileMan,
CompileDate = RewardAndPunish.CompileDate,
};
db.RewardAndPunish_RewardAndPunish.InsertOnSubmit(newRewardAndPunish);
db.SubmitChanges();
}
public static void AddRewardAndPunishForApi(Model.RewardAndPunish_RewardAndPunish RewardAndPunish)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.RewardAndPunish_RewardAndPunish newRewardAndPunish = new Model.RewardAndPunish_RewardAndPunish
{
RewardAndPunishId = RewardAndPunish.RewardAndPunishId,
ProjectId = RewardAndPunish.ProjectId,
RewardAndPunishCode = RewardAndPunish.RewardAndPunishCode,
UnitId = RewardAndPunish.UnitId,
Type = RewardAndPunish.Type,
RewardAndPunishTypeId = RewardAndPunish.RewardAndPunishTypeId,
RewardAndPunishBasis = RewardAndPunish.RewardAndPunishBasis,
State = RewardAndPunish.State,
CompileMan = RewardAndPunish.CompileMan,
CompileDate = RewardAndPunish.CompileDate,
RewardAndPunishDecision=RewardAndPunish.RewardAndPunishDecision,
};
db.RewardAndPunish_RewardAndPunish.InsertOnSubmit(newRewardAndPunish);
db.SubmitChanges();
Model.RewardAndPunish_RewardAndPunishApprove approve = new Model.RewardAndPunish_RewardAndPunishApprove();
approve.RewardAndPunishApproveId = BLL.SQLHelper.GetNewID();
approve.RewardAndPunishId = RewardAndPunish.RewardAndPunishId;
approve.ApproveType = BLL.Const.RewardAndPunish_Compile;
approve.ApproveMan = RewardAndPunish.CompileMan;
approve.ApproveDate = RewardAndPunish.CompileDate;
db.RewardAndPunish_RewardAndPunishApprove.InsertOnSubmit(approve);
db.SubmitChanges();
}
}
/// <summary>
/// 修改质量奖罚
/// </summary>
/// <param name="RewardAndPunish"></param>
public static void UpdateRewardAndPunish(Model.RewardAndPunish_RewardAndPunish RewardAndPunish)
{
Model.SGGLDB db = Funs.DB;
Model.RewardAndPunish_RewardAndPunish newRewardAndPunish = db.RewardAndPunish_RewardAndPunish.FirstOrDefault(e => e.RewardAndPunishId == RewardAndPunish.RewardAndPunishId);
if (newRewardAndPunish != null)
{
newRewardAndPunish.RewardAndPunishCode = RewardAndPunish.RewardAndPunishCode;
newRewardAndPunish.UnitId = RewardAndPunish.UnitId;
newRewardAndPunish.Type = RewardAndPunish.Type;
newRewardAndPunish.RewardAndPunishTypeId = RewardAndPunish.RewardAndPunishTypeId;
newRewardAndPunish.RewardAndPunishBasis = RewardAndPunish.RewardAndPunishBasis;
newRewardAndPunish.RewardAndPunishDecision = RewardAndPunish.RewardAndPunishDecision;
newRewardAndPunish.State = RewardAndPunish.State;
db.SubmitChanges();
}
}
public static void UpdateRewardAndPunishForApi(Model.RewardAndPunish_RewardAndPunish RewardAndPunish)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
Model.RewardAndPunish_RewardAndPunish newRewardAndPunish = db.RewardAndPunish_RewardAndPunish.First(e => e.RewardAndPunishId == RewardAndPunish.RewardAndPunishId);
if (!string.IsNullOrEmpty(RewardAndPunish.RewardAndPunishCode))
newRewardAndPunish.RewardAndPunishCode = RewardAndPunish.RewardAndPunishCode;
if (!string.IsNullOrEmpty(RewardAndPunish.UnitId))
newRewardAndPunish.UnitId = RewardAndPunish.UnitId;
if (!string.IsNullOrEmpty(RewardAndPunish.Type))
newRewardAndPunish.Type = RewardAndPunish.Type;
if (!string.IsNullOrEmpty(RewardAndPunish.RewardAndPunishTypeId))
newRewardAndPunish.RewardAndPunishTypeId = RewardAndPunish.RewardAndPunishTypeId;
if (!string.IsNullOrEmpty(RewardAndPunish.RewardAndPunishBasis))
newRewardAndPunish.RewardAndPunishBasis = RewardAndPunish.RewardAndPunishBasis;
if (!string.IsNullOrEmpty(RewardAndPunish.RewardAndPunishDecision))
newRewardAndPunish.RewardAndPunishDecision = RewardAndPunish.RewardAndPunishDecision;
if (!string.IsNullOrEmpty(RewardAndPunish.State))
newRewardAndPunish.State = RewardAndPunish.State;
db.SubmitChanges();
}
}
/// <summary>
/// 根据主键删除质量奖罚
/// </summary>
/// <param name="RewardAndPunishId"></param>
public static void DeleteRewardAndPunishById(string RewardAndPunishId)
{
Model.SGGLDB db = Funs.DB;
Model.RewardAndPunish_RewardAndPunish RewardAndPunish = db.RewardAndPunish_RewardAndPunish.FirstOrDefault(e => e.RewardAndPunishId == RewardAndPunishId);
if (RewardAndPunish != null)
{
BLL.CommonService.DeleteAttachFileById(RewardAndPunishId);
db.RewardAndPunish_RewardAndPunish.DeleteOnSubmit(RewardAndPunish);
db.SubmitChanges();
}
}
/// <summary>
/// 根据状态选择下一步办理类型
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static ListItem[] GetDHandleTypeByState(string state)
{
if (state == Const.RewardAndPunish_Compile || state == Const.RewardAndPunish_ReCompile)
{
ListItem[] lis = new ListItem[1];
lis[0] = new ListItem("质量经理审核", Const.RewardAndPunish_Audit1);
return lis;
}
else if (state == Const.RewardAndPunish_Audit1)
{
ListItem[] lis = new ListItem[2];
lis[0] = new ListItem("项目经理批准", Const.RewardAndPunish_Audit2);
lis[1] = new ListItem("重新编制", Const.RewardAndPunish_ReCompile);
return lis;
}
else if (state == Const.RewardAndPunish_Audit2)
{
ListItem[] lis = new ListItem[2];
lis[0] = new ListItem("审批完成", Const.RewardAndPunish_Complete);
lis[1] = new ListItem("重新编制", Const.RewardAndPunish_ReCompile);
return lis;
}
else
return null;
}
/// <summary>
/// 根据状态选择下一步办理类型
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetDHandleTypeByStateForApi(string state)
{
List<Model.BaseInfoItem> list = new List<Model.BaseInfoItem>();
if (state == Const.RewardAndPunish_Compile || state == Const.RewardAndPunish_ReCompile)
{
Model.BaseInfoItem item = new Model.BaseInfoItem();
item.BaseInfoId = Const.RewardAndPunish_Audit1;
item.BaseInfoName = "质量经理审核";
list.Add(item);
return list;
}
else if (state == Const.RewardAndPunish_Audit1)
{
Model.BaseInfoItem item = new Model.BaseInfoItem();
item.BaseInfoId = Const.RewardAndPunish_Audit2;
item.BaseInfoName = "项目经理批准";
list.Add(item);
Model.BaseInfoItem item2 = new Model.BaseInfoItem();
item2.BaseInfoId = Const.RewardAndPunish_ReCompile;
item2.BaseInfoName = "重新编制";
list.Add(item2);
return list;
}
else if (state == Const.RewardAndPunish_Audit2)
{
Model.BaseInfoItem item = new Model.BaseInfoItem();
item.BaseInfoId = Const.RewardAndPunish_Complete;
item.BaseInfoName = "审批完成";
list.Add(item);
Model.BaseInfoItem item2 = new Model.BaseInfoItem();
item2.BaseInfoId = Const.RewardAndPunish_ReCompile;
item2.BaseInfoName = "重新编制";
list.Add(item2);
return list;
}
else
return null;
}
/// <summary>
/// 把状态转换代号为文字形式
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static string ConvertState(object state)
{
if (state != null)
{
if (state.ToString() == BLL.Const.RewardAndPunish_ReCompile)
{
return "重新编制";
}
else if (state.ToString() == BLL.Const.RewardAndPunish_Compile)
{
return "编制";
}
else if (state.ToString() == BLL.Const.RewardAndPunish_Audit1)
{
return "质量经理审核";
}
else if (state.ToString() == BLL.Const.RewardAndPunish_Audit2)
{
return "项目经理批准";
}
else if (state.ToString() == BLL.Const.RewardAndPunish_Complete)
{
return "审批完成";
}
else
{
return "";
}
}
return "";
}
/// <summary>
/// 把状态转换代号为文字形式
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static string ConvertCause(object RewardAndPunishTypeId)
{
string cause = string.Empty;
if (RewardAndPunishTypeId != null)
{
Model.Base_RewardType rt = BLL.RewardTypeService.GetRewardTypeById(RewardAndPunishTypeId.ToString());
Model.Base_PunishType pt = BLL.PunishTypeService.GetPunishTypeById(RewardAndPunishTypeId.ToString());
if (rt != null)
{
cause = rt.RewardCause;
}
else if (pt != null)
{
cause = pt.PunishCause;
}
}
return cause;
}
public static List<Model.RewardAndPunish_RewardAndPunish> getListDataForApi(string projectId, int startRowIndex, int maximumRows, string type)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
IQueryable<Model.RewardAndPunish_RewardAndPunish> q = db.RewardAndPunish_RewardAndPunish;
if (!string.IsNullOrEmpty(projectId))
{
q = q.Where(e => e.ProjectId == projectId);
}
if (type != "0")
{
q = q.Where(e => e.Type == type);
}
var qres = from x in q
orderby x.CompileDate descending
select new
{
x.RewardAndPunishId,
x.ProjectId,
x.RewardAndPunishCode,
x.UnitId,
UnitName = (from y in db.Base_Unit where y.UnitId == x.UnitId select y.UnitName).First(),
x.Type,
TypeStr = x.Type == "1" ? "奖励" : "处罚",
x.RewardAndPunishTypeId,
RewardAndPunishTypeStr = ConvertCause(x.RewardAndPunishTypeId),
x.RewardAndPunishBasis,
x.RewardAndPunishDecision,
x.CompileDate,
x.CompileMan,
x.State,
StateStr = ConvertState(x.State),
CompileManName = (from y in db.Person_Persons where y.PersonId == x.CompileMan select y.PersonName).First(),
HandleManName = BLL.RewardAndPunishApproveService.GetHandleManName(x.RewardAndPunishId),
x.AttachUrl,
};
List<Model.RewardAndPunish_RewardAndPunish> res = new List<Model.RewardAndPunish_RewardAndPunish>();
var list = qres.Skip(startRowIndex).Take(maximumRows).ToList();
foreach (var item in list)
{
Model.RewardAndPunish_RewardAndPunish cd = new Model.RewardAndPunish_RewardAndPunish();
cd.RewardAndPunishId = item.RewardAndPunishId;
cd.ProjectId = item.ProjectId;
cd.RewardAndPunishCode = item.RewardAndPunishCode;
cd.UnitId = item.UnitId + "$" + item.UnitName;
cd.Type = item.Type + "$" + item.TypeStr;
cd.RewardAndPunishTypeId = item.RewardAndPunishTypeId + "$" + item.RewardAndPunishTypeStr;
cd.RewardAndPunishBasis = item.RewardAndPunishBasis;
cd.RewardAndPunishDecision = item.RewardAndPunishDecision;
cd.CompileDate = item.CompileDate;
cd.CompileMan = item.CompileMan + "$" + item.CompileManName;
cd.State = item.State + "$" + item.StateStr + "$" + item.HandleManName;
cd.AttachUrl = AttachFileService.getFileUrl(item.RewardAndPunishId);
res.Add(cd);
}
return res;
}
}
/// <summary>
/// 获取质量奖罚信息
/// </summary>
/// <param name="UnitWorkId"></param>
/// <returns></returns>
public static Model.RewardAndPunish_RewardAndPunish GetRewardAndPunishByRewardAndPunishIdForApi(string RewardAndPunishId)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
var q = db.RewardAndPunish_RewardAndPunish.FirstOrDefault(e => e.RewardAndPunishId == RewardAndPunishId);
if (q != null)
{
q.UnitId = q.UnitId + "$" + BLL.UnitService.GetUnitNameByUnitId(q.UnitId);
q.Type = q.Type + "$" + (q.Type == "1" ? "奖励" : "处罚");
q.RewardAndPunishTypeId = q.RewardAndPunishTypeId + "$" + ConvertCause(q.RewardAndPunishTypeId);
q.CompileMan = q.CompileMan + "$" + BLL.Person_PersonsService.GetPersonsNameById(q.CompileMan);
q.State = q.State + "$" + ConvertState(q.State) + "$" + BLL.RewardAndPunishApproveService.GetHandleManName(q.RewardAndPunishId);
q.AttachUrl = AttachFileService.getFileUrl(q.RewardAndPunishId);
}
return q;
}
}
/// <summary>
/// 根据状态获取办理人
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetHandleManListForApi(string state, string id, string projectId)
{
List<Model.BaseInfoItem> list = new List<Model.BaseInfoItem>();
if (state == Const.RewardAndPunish_Compile)
{
return null;
}
else if (state == Const.RewardAndPunish_ReCompile)
{
var user = BLL.Person_PersonsService.GetPerson_PersonsById(BLL.RewardAndPunishApproveService.GetAuditMan(id, BLL.Const.RewardAndPunish_Compile).ApproveMan);
Model.BaseInfoItem item = new Model.BaseInfoItem();
item.BaseInfoId = user.PersonId;
item.BaseInfoName = user.PersonName;
list.Add(item);
return list;
}
else if (state == Const.RewardAndPunish_Audit1 || state == Const.RewardAndPunish_Audit2)
{
var users = BLL.SitePerson_PersonService.GetSitePerson_PersonListByProjectIdUnitTypeRoleIds(projectId, Const.ProjectUnitType_1, null);
foreach (var user in users)
{
Model.BaseInfoItem item = new Model.BaseInfoItem();
item.BaseInfoId = user.PersonId;
item.BaseInfoName = user.PersonName;
list.Add(item);
}
return list;
}
else
return null;
}
}
}