325 lines
13 KiB
C#
325 lines
13 KiB
C#
using MiniExcelLibs;
|
||
using Model;
|
||
using System.Collections.Generic;
|
||
using System;
|
||
using System.Linq;
|
||
|
||
namespace BLL
|
||
{
|
||
/// <summary>
|
||
/// 岗位培训课程
|
||
/// </summary>
|
||
public static class PostTrainingCourseService
|
||
{
|
||
/// <summary>
|
||
/// 根据主键获取岗位培训课程信息
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
public static Model.PostTraining_Course GetCourseById(string Id)
|
||
{
|
||
return Funs.DB.PostTraining_Course.FirstOrDefault(e => e.Id == Id);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加岗位培训课程
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public static void AddCourse(Model.PostTraining_Course model)
|
||
{
|
||
Model.PostTraining_Course newModel = new Model.PostTraining_Course
|
||
{
|
||
Id = model.Id,
|
||
Code = model.Code,
|
||
Name = model.Name,
|
||
CategoryId = model.CategoryId,
|
||
CategoryName = model.CategoryName,
|
||
Method1 = model.Method1,
|
||
Method2 = model.Method2,
|
||
Teachers1 = model.Teachers1,
|
||
Teachers2 = model.Teachers2,
|
||
CompileDate = model.CompileDate,
|
||
CompileMan = model.CompileMan,
|
||
Remark = model.Remark
|
||
};
|
||
Funs.DB.PostTraining_Course.InsertOnSubmit(newModel);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
public static void UpdateCourse(Model.PostTraining_Course model)
|
||
{
|
||
Model.PostTraining_Course newModel = Funs.DB.PostTraining_Course.FirstOrDefault(e => e.Id == model.Id);
|
||
if (newModel != null)
|
||
{
|
||
newModel.Code = model.Code;
|
||
newModel.Name = model.Name;
|
||
newModel.CategoryId = model.CategoryId;
|
||
newModel.CategoryName = model.CategoryName;
|
||
newModel.Method1 = model.Method1;
|
||
newModel.Method2 = model.Method2;
|
||
newModel.Teachers1 = model.Teachers1;
|
||
newModel.Teachers2 = model.Teachers2;
|
||
newModel.Remark = model.Remark;
|
||
newModel.CompileDate = model.CompileDate;
|
||
newModel.CompileMan = model.CompileMan;
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
public static void DeleteCourseById(string Id)
|
||
{
|
||
Model.PostTraining_Course model = Funs.DB.PostTraining_Course.FirstOrDefault(e => e.Id == Id);
|
||
if (model != null)
|
||
{
|
||
CommonService.DeleteAttachFileById(Id);
|
||
Funs.DB.PostTraining_Course.DeleteOnSubmit(model);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有岗位培训课程List
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static List<PostTraining_Course> GetCourseList()
|
||
{
|
||
return (from x in Funs.DB.PostTraining_Course orderby x.Code select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导入数据
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
/// <param name="projectid"></param>
|
||
/// <param name="creatUserId"></param>
|
||
/// <param name="errorList"></param>
|
||
/// <returns></returns>
|
||
public static ResponeData ImportData(string OriFileName, string path, string projectid, string creatUserId, ref List<Model.ErrorInfo> errorList)
|
||
{
|
||
var responeData = new ResponeData();
|
||
List<PostTrainingCourse_InputDataIn> temeplateDtoIns;
|
||
try
|
||
{
|
||
//A2:开始行
|
||
temeplateDtoIns = MiniExcel.Query<PostTrainingCourse_InputDataIn>(path, startCell: "A2").ToList();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "模板错误:" + ex.ToString();
|
||
return responeData;
|
||
}
|
||
|
||
if (temeplateDtoIns.Count == 0)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "导入数据为空!";
|
||
return responeData;
|
||
}
|
||
|
||
//培训课程
|
||
var lstCourse = GetCourseList();
|
||
//培训类别
|
||
var lstCategory = PostTrainingCategoryService.GetCategoryList();
|
||
//培训方式
|
||
var lstMethod = PostTrainingMethodService.GetMethodList();
|
||
//培训教资
|
||
var lstTeachers = PostTrainingTeachersService.GetTeachersList();
|
||
|
||
#region 数据校验
|
||
|
||
string errorMsg = string.Empty;
|
||
int rowIndex = 3;
|
||
foreach (var item in temeplateDtoIns)
|
||
{
|
||
string categoryName = !string.IsNullOrWhiteSpace(item.CategoryName) ? item.CategoryName.Trim() : string.Empty;
|
||
string name = !string.IsNullOrWhiteSpace(item.Name) ? item.Name.Trim() : string.Empty;
|
||
string method1 = !string.IsNullOrWhiteSpace(item.Method1) ? item.Method1.Trim() : string.Empty;
|
||
string method2 = !string.IsNullOrWhiteSpace(item.Method2) ? item.Method2.Trim() : string.Empty;
|
||
string teachers1 = !string.IsNullOrWhiteSpace(item.Teachers1) ? item.Teachers1.Trim() : string.Empty;
|
||
string teachers2 = !string.IsNullOrWhiteSpace(item.Teachers2) ? item.Teachers2.Trim() : string.Empty;
|
||
string remark = !string.IsNullOrWhiteSpace(item.Remark) ? item.Remark.Trim() : string.Empty;
|
||
|
||
if (!string.IsNullOrWhiteSpace(categoryName))
|
||
{
|
||
if (!lstCategory.Where(x => x.Name == categoryName).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训类别";
|
||
errorInfo.Reason = $"培训类别不存在:{categoryName}";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训类别";
|
||
errorInfo.Reason = "不可为空";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(name))
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "课程名称";
|
||
errorInfo.Reason = "不可为空";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(categoryName) && !string.IsNullOrWhiteSpace(name))
|
||
{
|
||
if (temeplateDtoIns.Where(x => x.Name == name && x.CategoryName == categoryName).Count() > 1)
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "课程名称";
|
||
errorInfo.Reason = $"导入数据重复:{name}({categoryName})";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
if (lstCourse.Where(x => x.Name == name && x.CategoryName == categoryName).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "课程名称";
|
||
errorInfo.Reason = $"已存在课程:{name}({categoryName})";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(method1))
|
||
{
|
||
if (!lstMethod.Where(x => x.Name == method1).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训方式一";
|
||
errorInfo.Reason = $"培训方式字典不存在:{method1}";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(method2))
|
||
{
|
||
if (!lstMethod.Where(x => x.Name == method2).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训方式二";
|
||
errorInfo.Reason = $"培训方式字典不存在:{method2}";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(teachers1))
|
||
{
|
||
if (!lstTeachers.Where(x => x.Name == teachers1).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训师资一";
|
||
errorInfo.Reason = $"培训师资字典不存在:{teachers1}";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(teachers2))
|
||
{
|
||
if (!lstTeachers.Where(x => x.Name == teachers2).Any())
|
||
{
|
||
Model.ErrorInfo errorInfo = new Model.ErrorInfo();
|
||
errorInfo.Row = rowIndex.ToString();
|
||
errorInfo.Column = "培训师资二";
|
||
errorInfo.Reason = $"培训师资字典不存在:{teachers2}";
|
||
errorList.Add(errorInfo);
|
||
}
|
||
}
|
||
|
||
rowIndex++;
|
||
}
|
||
|
||
if (errorList.Any())
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "存在异常数据!";
|
||
return responeData;
|
||
}
|
||
|
||
#endregion
|
||
|
||
foreach (var item in temeplateDtoIns)
|
||
{
|
||
string categoryName = !string.IsNullOrWhiteSpace(item.CategoryName) ? item.CategoryName.Trim() : string.Empty;
|
||
string name = !string.IsNullOrWhiteSpace(item.Name) ? item.Name.Trim() : string.Empty;
|
||
string method1 = !string.IsNullOrWhiteSpace(item.Method1) ? item.Method1.Trim() : string.Empty;
|
||
string method2 = !string.IsNullOrWhiteSpace(item.Method2) ? item.Method2.Trim() : string.Empty;
|
||
string teachers1 = !string.IsNullOrWhiteSpace(item.Teachers1) ? item.Teachers1.Trim() : string.Empty;
|
||
string teachers2 = !string.IsNullOrWhiteSpace(item.Teachers2) ? item.Teachers2.Trim() : string.Empty;
|
||
string remark = !string.IsNullOrWhiteSpace(item.Remark) ? item.Remark.Trim() : string.Empty;
|
||
|
||
Model.PostTraining_Course newModel = new Model.PostTraining_Course
|
||
{
|
||
Id = SQLHelper.GetNewID(typeof(Model.PostTraining_Course)),
|
||
Code = SQLHelper.RunProcNewId("SpGetNewCode5", "dbo.PostTraining_Course", "Code", ""),
|
||
//ProjectId = this.ProjectId,
|
||
CompileDate = DateTime.Now,
|
||
CompileMan = creatUserId
|
||
};
|
||
newModel.Name = name;
|
||
newModel.CategoryId = lstCategory.Where(x => x.Name == categoryName).FirstOrDefault().Id;
|
||
newModel.CategoryName = categoryName;
|
||
newModel.Method1 = method1;
|
||
newModel.Method2 = method2;
|
||
newModel.Teachers1 = teachers1;
|
||
newModel.Teachers2 = teachers2;
|
||
newModel.Remark = remark;
|
||
|
||
AddCourse(newModel);
|
||
}
|
||
return responeData;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取培训课程下拉框
|
||
/// </summary>
|
||
/// <param name="dropName"></param>
|
||
/// <param name="categoryId"></param>
|
||
/// <param name="isShowPlease"></param>
|
||
public static void InitPostTrainingCourseDropDownList(FineUIPro.DropDownList dropName, string categoryId, bool isShowPlease)
|
||
{
|
||
dropName.DataValueField = "Id";
|
||
dropName.DataTextField = "Name";
|
||
dropName.DataSource = GetPostTrainingCourseList(categoryId);
|
||
dropName.DataBind();
|
||
if (isShowPlease)
|
||
{
|
||
Funs.FineUIPleaseSelect(dropName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取培训课程下拉项
|
||
/// </summary>
|
||
/// <param name="categoryId"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.PostTraining_Course> GetPostTrainingCourseList(string categoryId)
|
||
{
|
||
var lst = (from x in Funs.DB.PostTraining_Course orderby x.Code select x).ToList();
|
||
if (!string.IsNullOrWhiteSpace(categoryId))
|
||
{
|
||
lst = lst.Where(x => x.CategoryId == categoryId).ToList();
|
||
}
|
||
return lst;
|
||
}
|
||
}
|
||
}
|