349 lines
15 KiB
C#
349 lines
15 KiB
C#
using BLL;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.ZHGL.RealName
|
||
{
|
||
public partial class SynchroSet : PageBase
|
||
{
|
||
/// <summary>
|
||
/// 用户编辑页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
///权限
|
||
this.GetButtonPower();
|
||
ProjectService.InitAllProjectShortNameDropDownList(this.drpProject, this.CurrUser.UserId, false);
|
||
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
||
{
|
||
this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
|
||
this.drpProject.Readonly = true;
|
||
}
|
||
if (this.CurrUser.UserId == Const.hfnbdId)
|
||
{
|
||
this.btnDataProcess.Hidden = false;
|
||
}
|
||
this.SetPage();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
Model.RealName_SynchroSet newSynchroSet = new Model.RealName_SynchroSet
|
||
{
|
||
UnitId = Const.UnitId_CWCEC,
|
||
ApiUrl = Funs.RealNameApiUrl,
|
||
ClientId = this.txtclientId.Text.Trim(),
|
||
UserName = this.txtUserName.Text.Trim(),
|
||
Password = this.txtword.Text.Trim(),
|
||
Intervaltime=Funs.GetNewInt(this.txtintervaltime.Text.Trim()),
|
||
};
|
||
newSynchroSet.ProCode = ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
BLL.SynchroSetService.SaveSynchroSet(newSynchroSet);
|
||
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 连接测试
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnConnect_Click(object sender, EventArgs e)
|
||
{
|
||
Model.RealName_SynchroSet newSynchroSet = new Model.RealName_SynchroSet
|
||
{
|
||
UnitId = Const.UnitId_CWCEC,
|
||
ApiUrl = Funs.RealNameApiUrl,
|
||
ClientId = this.txtclientId.Text.Trim(),
|
||
UserName = this.txtUserName.Text.Trim(),
|
||
Password = this.txtword.Text.Trim(),
|
||
Intervaltime = Funs.GetNewInt(this.txtintervaltime.Text.Trim()),
|
||
};
|
||
newSynchroSet.ProCode = ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
if (!string.IsNullOrEmpty(SynchroSetService.SaveToken(newSynchroSet)))
|
||
{
|
||
ShowNotify("连接成功!", MessageBoxIcon.Success);
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent("连接失败", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
#region 获取按钮权限
|
||
/// <summary>
|
||
/// 获取按钮权限
|
||
/// </summary>
|
||
/// <param name="button"></param>
|
||
/// <returns></returns>
|
||
private void GetButtonPower()
|
||
{
|
||
string menuId = !string.IsNullOrEmpty(this.CurrUser.LoginProjectId) ? Const.RealNameSynchroSetMenuId : Const.ServerRealNameSynchroSetMenuId;
|
||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, menuId);
|
||
if (buttonList.Count() > 0)
|
||
{
|
||
if (buttonList.Contains(BLL.Const.BtnSave))
|
||
{
|
||
this.btnSave.Hidden = false;
|
||
this.btnConnect.Hidden = false;
|
||
this.btnCompany.Hidden = false;
|
||
|
||
this.btnCompany.Hidden = false;
|
||
this.btnProCollCompany.Hidden = false;
|
||
this.btnCollTeam.Hidden = false;
|
||
this.btnPersons.Hidden = false;
|
||
this.btnAttendance.Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 推送参建企业
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnCompany_Click(object sender, EventArgs e)
|
||
{
|
||
ShowNotify(BLL.SynchroSetService.PushCollCompany(), MessageBoxIcon.Information);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 推送项目参建单位
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnProCollCompany_Click(object sender, EventArgs e)
|
||
{
|
||
string message = string.Empty;
|
||
string proCode =BLL.ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
var getRProjects = Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode);
|
||
if (getRProjects != null)
|
||
{
|
||
message += ("项目" + getRProjects.ProCode + SynchroSetService.PushProCollCompany(getRProjects.ProCode));
|
||
ShowNotify(message, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("当前项目还没有与实名制对接!", MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 推送施工队
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnCollTeam_Click(object sender, EventArgs e)
|
||
{
|
||
string message = string.Empty;
|
||
string proCode = BLL.ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
var getRProjects = Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode);
|
||
if (getRProjects != null)
|
||
{
|
||
message += ("项目" + getRProjects.ProCode + SynchroSetService.PushCollTeam(getRProjects.ProCode));
|
||
ShowNotify(message, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("当前项目还没有与实名制对接!", MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 推送人员信息
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnPersons_Click(object sender, EventArgs e)
|
||
{
|
||
//string add ="新增"+ BLL.SynchroSetService.PushPersons(Const.BtnAdd,null) ?? "";
|
||
//string update ="更新"+ BLL.SynchroSetService.PushPersons(Const.BtnModify,null) ?? "";
|
||
//ShowNotify(add+"|"+ update, MessageBoxIcon.Information);
|
||
string message = string.Empty;
|
||
string proCode = BLL.ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
var getRProjects = Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode);
|
||
if (getRProjects != null)
|
||
{
|
||
message += ("项目" + getRProjects.ProCode + "新增" + BLL.SynchroSetService.PushPersons(Const.BtnAdd, getRProjects.ProCode, null) ?? "");
|
||
message += ("|更新" + BLL.SynchroSetService.PushPersons(Const.BtnModify, getRProjects.ProCode, null) ?? "");
|
||
ShowNotify(message, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("当前项目还没有与实名制对接!", MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 推送考勤
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnAttendance_Click(object sender, EventArgs e)
|
||
{
|
||
string message = string.Empty;
|
||
string proCode = BLL.ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
var getRProjects = Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode);
|
||
if (getRProjects != null)
|
||
{
|
||
message +=("项目"+ getRProjects.ProCode+ SynchroSetService.PushAttendance(getRProjects.ProCode));
|
||
ShowNotify(message, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("当前项目还没有与实名制对接!", MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换项目
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void drpProject_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.SetPage();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
protected void SetPage()
|
||
{
|
||
this.txtclientId.Text = string.Empty;
|
||
this.txtUserName.Text = string.Empty;
|
||
this.txtword.Text = string.Empty;
|
||
this.txtapiUrl.Text = Funs.RealNameApiUrl;
|
||
this.txtintervaltime.Text = ConfigurationManager.AppSettings["Intervaltime"];
|
||
|
||
var getpro = Funs.DB.Base_Project.FirstOrDefault(x=>x.ProjectId == this.drpProject.SelectedValue);
|
||
if (getpro !=null && !string.IsNullOrEmpty(getpro.JTProjectCode))
|
||
{
|
||
var getSynchroSet = SynchroSetService.GetSynchroSetByUnitId(Const.UnitId_CWCEC, getpro.JTProjectCode);
|
||
if (getSynchroSet != null)
|
||
{
|
||
this.txtapiUrl.Text = Funs.RealNameApiUrl;
|
||
this.txtclientId.Text = getSynchroSet.ClientId;
|
||
this.txtUserName.Text = getSynchroSet.UserName;
|
||
this.txtword.Text = getSynchroSet.Password;
|
||
this.txtintervaltime.Text = getSynchroSet.Intervaltime.ToString();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按身份证推送
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnPushData_Click(object sender, EventArgs e)
|
||
{
|
||
string message = string.Empty;
|
||
string idText = this.txtIdentityCard.Text.Trim();
|
||
if (!string.IsNullOrEmpty(idText))
|
||
{
|
||
string proCode = ProjectService.GetJTProjectCodeByProjectId(this.drpProject.SelectedValue);
|
||
var getRProjects = Funs.DB.RealName_Project.FirstOrDefault(x => x.ProCode == proCode);
|
||
if (getRProjects != null && !string.IsNullOrEmpty(getRProjects.ProCode))
|
||
{
|
||
idText = idText.Replace(",",",").Replace("(条)","").Replace(";",";").Replace("(","(").Replace(")",")");
|
||
List<string> getList = new List<string>();
|
||
if (idText.Contains("("))
|
||
{
|
||
var getData = Funs.GetStrListByStr(idText, ';');
|
||
foreach (var itemD in getData)
|
||
{
|
||
if (!string.IsNullOrEmpty(itemD))
|
||
{
|
||
var a = itemD.Split('(');
|
||
if (a.Count() > 1)
|
||
{
|
||
var b = a[1].Split(')');
|
||
if (b.Count() > 1)
|
||
{
|
||
getList.Add(b[0]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
getList = Funs.GetStrListByStr(idText, ',');
|
||
}
|
||
|
||
if (getList != null && getList.Count > 0)
|
||
{
|
||
foreach (var item in getList)
|
||
{
|
||
message += ("项目" + getRProjects.ProCode + "新增" + BLL.SynchroSetService.PushPersonsByIdentityCard(Const.BtnAdd, getRProjects.ProCode, item) ?? "");
|
||
message += ("|更新" + BLL.SynchroSetService.PushPersonsByIdentityCard(Const.BtnModify, getRProjects.ProCode, item) ?? "");
|
||
}
|
||
ShowNotify(message, MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("当前项目还没有与实名制对接!", MessageBoxIcon.Information);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnDataProcess_Click(object sender, EventArgs e)
|
||
{
|
||
var result = (from x in Funs.DB.RealName_PersonInOutNow
|
||
group x by new
|
||
{
|
||
x.ProjectId,
|
||
date = x.ChangeTime.Value.Date,
|
||
x.IdcardNumber,
|
||
x.IsIn
|
||
} into g
|
||
where g.Count() > 1
|
||
select new
|
||
{
|
||
g.First().ProjectId,
|
||
date = g.First().ChangeTime.Value.Date,
|
||
g.First().IdcardNumber,
|
||
g.First().IsIn
|
||
}).Distinct().Take(500);
|
||
|
||
foreach (var item in result)
|
||
{
|
||
var getDateRecords = from x in Funs.DB.RealName_PersonInOutNow
|
||
where x.ProjectId == item.ProjectId && x.ChangeTime.Value >= item.date.Date && x.ChangeTime.Value < item.date.Date.AddDays(1)
|
||
&& x.IdcardNumber == item.IdcardNumber
|
||
select x;
|
||
DateTime? minChangeTime = getDateRecords.Where(x => x.IsIn == true).Min(x=>x.ChangeTime);
|
||
DateTime? maxChangeTime = getDateRecords.Where(x => x.IsIn == false).Max(x => x.ChangeTime);
|
||
var getDeleteR = from x in getDateRecords
|
||
where (minChangeTime.HasValue && x.IsIn == true && x.ChangeTime != minChangeTime) ||
|
||
(maxChangeTime.HasValue && x.IsIn == false && x.ChangeTime != maxChangeTime)
|
||
select x;
|
||
if (getDeleteR.Count() > 0)
|
||
{
|
||
Funs.DB.RealName_PersonInOutNow.DeleteAllOnSubmit(getDeleteR);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
Alert.ShowInTop("完成!", MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
} |