159 lines
5.5 KiB
C#
159 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.DAL.Csvr;
|
|
using WX.CRM.IBLL.Csvr;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Csvr
|
|
{
|
|
public class CSVR_UNITECUSTOMERAPPLY_BL : ICSVR_UNITECUSTOMERAPPLY, ICSVR_UNITECUSTOMERAPPLY_Q
|
|
{
|
|
private UNITECUSTOMERCHECK_DAL dal = new UNITECUSTOMERCHECK_DAL();
|
|
|
|
public CSVR_UNITECUSTOMERAPPLY GetModel_UniteCustomerApply(decimal id)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.CSVR_UNITECUSTOMERAPPLY.FirstOrDefault(m => m.UNITEID == id);
|
|
}
|
|
}
|
|
|
|
public List<CSVR_UNITECUSTOMERAPPLY> GetList_UniteCustomerApply(ref Pager pg, string resid, decimal status, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
IQueryable<CSVR_UNITECUSTOMERAPPLY> data = db.CSVR_UNITECUSTOMERAPPLY.AsQueryable<CSVR_UNITECUSTOMERAPPLY>();
|
|
if (!string.IsNullOrEmpty(resid))
|
|
data = data.Where(m => (m.RESID1.Contains(resid) || m.RESID2.Contains(resid)) || (m.UMID1.Contains(resid) || m.UMID2.Contains(resid)));
|
|
if (status >= 0)
|
|
data = data.Where(m => m.STATE == status);
|
|
|
|
DateTime _stime;
|
|
DateTime _etime;
|
|
if (!string.IsNullOrEmpty(stime) && DateTime.TryParse(stime, out _stime))
|
|
data = data.Where(m => m.APPLYTIME >= _stime);
|
|
if (!string.IsNullOrEmpty(etime) && DateTime.TryParse(etime, out _etime))
|
|
{
|
|
_etime = _etime.AddDays(1);
|
|
data = data.Where(m => m.APPLYTIME < _etime);
|
|
}
|
|
|
|
if (pg.order == "desc")
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "applyTime":
|
|
data = data.OrderByDescending(c => c.APPLYTIME);
|
|
break;
|
|
|
|
case "applyName":
|
|
data = data.OrderByDescending(c => c.APPLYID);
|
|
break;
|
|
|
|
case "checkStatus":
|
|
data = data.OrderByDescending(c => c.STATE);
|
|
break;
|
|
|
|
default:
|
|
data = data.OrderByDescending(c => c.APPLYTIME);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "applyTime":
|
|
data = data.OrderBy(c => c.APPLYTIME);
|
|
break;
|
|
|
|
case "applyName":
|
|
data = data.OrderBy(c => c.APPLYID);
|
|
break;
|
|
|
|
case "checkStatus":
|
|
data = data.OrderBy(c => c.STATE);
|
|
break;
|
|
|
|
default:
|
|
data = data.OrderBy(c => c.APPLYTIME);
|
|
break;
|
|
}
|
|
}
|
|
PagerUtil.SetPager<CSVR_UNITECUSTOMERAPPLY>(ref data, ref pg);//分页
|
|
return data.ToList();
|
|
}
|
|
}
|
|
|
|
public decimal Create_UniteCustomerApply(ref ValidationErrors errors, CSVR_UNITECUSTOMERAPPLY model)
|
|
{
|
|
try
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
model.UNITEID = new SEQUENCES_BL().Seq_base_get();
|
|
db.CSVR_UNITECUSTOMERAPPLY.Add(model);
|
|
db.SaveChanges();
|
|
return model.UNITEID;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public bool Update_UniteCustomerApply(ref ValidationErrors errors, CSVR_UNITECUSTOMERAPPLY model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
CSVR_UNITECUSTOMERAPPLY entity = db.CSVR_UNITECUSTOMERAPPLY.FirstOrDefault(m => m.UNITEID == model.UNITEID);
|
|
if (entity != null)
|
|
{
|
|
entity.STATE = model.STATE;
|
|
entity.AUDITTIME = model.AUDITTIME;
|
|
entity.map_AUDITID = model.AUDITID;
|
|
entity.AUDITREMARK = model.AUDITREMARK;
|
|
entity.AUDITRESPONSE = model.AUDITRESPONSE;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
errors.Add("选择的申请记录不存在!");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Check_UniteCustomerApply(ref ValidationErrors errors, decimal id, decimal userid)
|
|
{
|
|
try
|
|
{
|
|
int rows = dal.UniteCustomerCheck(id, userid);
|
|
if (rows > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |