You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
6.1 KiB
163 lines
6.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSUserSkillDAL
|
|
{
|
|
public static string AddandEditList(List<ICSUserSkill> userSkillList, string conStr)
|
|
{
|
|
int ng = 0;
|
|
int insert = 0;
|
|
int update = 0;
|
|
int fail = 0;
|
|
List<string> list = new List<string>();
|
|
FramDataContext db = new FramDataContext(conStr);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
for (int i = 0; i < userSkillList.Count; i++)
|
|
{
|
|
ICSUserSkill input = userSkillList[i];
|
|
if (input.SkillCode == "" || input.UserCode.Trim() == "" || input.Qualification == "")
|
|
{
|
|
continue;
|
|
}
|
|
|
|
bool isNew = false;
|
|
var line = db.ICSUserSkill.FirstOrDefault(a =>
|
|
a.UserCode == input.UserCode
|
|
&& a.Qualification == input.Qualification
|
|
&& a.WorkPoint == AppConfig.WorkPointCode
|
|
);
|
|
if (line == null)
|
|
{
|
|
var baseuser = db.Sys_User.FirstOrDefault(a => a.UserCode == input.UserCode && a.WorkPointCode == AppConfig.WorkPointCode);
|
|
if (baseuser == null)
|
|
{
|
|
ng++;
|
|
list.Add("用户" + input.UserCode + "不存在");
|
|
continue;
|
|
}
|
|
isNew = true;
|
|
line = new ICSUserSkill();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.UserID = baseuser.ID;
|
|
line.UserCode = input.UserCode;
|
|
line.CreateDate = DateTime.Now;
|
|
line.CreateUserCode = input.CreateUserCode;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
}
|
|
line.Qualification = input.Qualification;
|
|
line.SkillCode = input.SkillCode;
|
|
line.SkillDesc = input.SkillDesc;
|
|
line.ModifyDate = DateTime.Now;
|
|
line.ModifyUserCode = input.CreateUserCode;
|
|
line.EnableFlag = true;
|
|
|
|
if (isNew)
|
|
{
|
|
db.ICSUserSkill.InsertOnSubmit(line);
|
|
insert++;
|
|
}
|
|
else
|
|
{
|
|
update++;
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
fail++;
|
|
db.Transaction.Rollback();
|
|
}
|
|
string smghead =
|
|
"不符合" + ng.ToString() + "更新" + update.ToString() + "新增" + insert.ToString() + "\r\n";
|
|
|
|
return
|
|
smghead + string.Join("\r\n", list);
|
|
}
|
|
|
|
public static void AddOrEdit(ICSUserSkill user, string conStr)
|
|
{
|
|
FramDataContext db = new FramDataContext(conStr);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
bool isNew = false;
|
|
var line = db.ICSUserSkill.FirstOrDefault(a =>
|
|
a.UserCode == user.UserCode
|
|
&& a.Qualification == user.Qualification
|
|
&& a.WorkPoint == AppConfig.WorkPointCode
|
|
);
|
|
if (String.IsNullOrEmpty(user.ID))
|
|
{
|
|
if (line != null)
|
|
{
|
|
throw new Exception("新增失败!用户:" + user.UserCode + "产品资格:" + user.Qualification + "已维护,技能等级为:" + user.SkillDesc);
|
|
}
|
|
isNew = true;
|
|
line = new ICSUserSkill();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.UserCode = user.UserCode;
|
|
line.UserID = user.UserID;
|
|
line.Qualification = user.Qualification;
|
|
line.CreateDate = DateTime.Now;
|
|
line.CreateUserCode = AppConfig.UserCode;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
}
|
|
else
|
|
{
|
|
if (line == null)
|
|
{
|
|
throw new Exception("修改失败!用户:" + user.UserCode + "产品资格:" + user.Qualification + "已被他人删除");
|
|
}
|
|
isNew = false;
|
|
}
|
|
line.SkillCode = user.SkillCode;
|
|
line.SkillDesc = user.SkillDesc;
|
|
line.EnableFlag = user.EnableFlag;
|
|
|
|
line.ModifyDate = DateTime.Now;
|
|
line.ModifyUserCode = AppConfig.UserCode;
|
|
|
|
if (isNew) db.ICSUserSkill.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void Delete(List<string> listID)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.ICSUserSkill.Where(a => listID.Contains(a.ID));
|
|
db.ICSUserSkill.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception("删除失败," + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|