SGGL_JT/SUBQHSE/FineUIPro.Web/ProjectData/ProjectDevicesEdit.aspx.cs

132 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using BLL.Common;
using FastReport.Cloud.OAuth;
using FineUIPro.Web.DataShow;
using Org.BouncyCastle.Crypto;
namespace FineUIPro.Web.ProjectData
{
public partial class ProjectDevicesEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string DeviceId
{
get
{
return (string)ViewState["DeviceId"];
}
set
{
ViewState["DeviceId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.DeviceId = Request.Params["DeviceId"];
if (!string.IsNullOrEmpty(this.DeviceId))
{
Model.Project_Devices device = Funs.DB.Project_Devices.FirstOrDefault(x => x.DeviceId == this.DeviceId);
if (device != null)
{
this.txtDeviceName.Text = device.DeviceName;
this.txtDeviceSerial.Text = device.DeviceSerial;
this.txtAddress.Text = device.Address;
this.txtValidateCode.Text = device.ValidateCode;
if (!string.IsNullOrEmpty(device.IsInOut))
{
this.drpInOut.SelectedValue = device.IsInOut;
}
//this.txtThirdTeamCode.Text = teamGroup.ThirdTeamCode;
if (device.CreateDate != null)
{
this.dpCreateDate.Text = string.Format("{0:yyyy-MM-dd}", device.CreateDate);
}
}
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
Model.Project_Devices device = new Model.Project_Devices
{
ProjectId = this.CurrUser.LoginProjectId,
DeviceName = this.txtDeviceName.Text.Trim(),
DeviceSerial = this.txtDeviceSerial.Text.Trim(),
Address = txtAddress.Text.Trim(),
ValidateCode = txtValidateCode.Text.Trim(),
CreateDate = Funs.GetNewDateTime(this.dpCreateDate.Text.Trim())
};
if (this.drpInOut.SelectedValue != BLL.Const._Null)
{
device.IsInOut = this.drpInOut.SelectedValue;
}
if (!string.IsNullOrEmpty(this.DeviceId))
{
device.DeviceId = this.DeviceId;
BLL.ProjectDeviceService.UpdateProjectDevice(device);
var token = YunMouHelper.getToken();
YunMouHelper.updateDevices(device.DeviceSerial, device.DeviceName, token);
BLL.LogService.AddSys_Log(this.CurrUser, device.DeviceName, device.DeviceId, BLL.Const.ProjectDevicesMenuId, BLL.Const.BtnModify);
}
else
{
this.DeviceId = SQLHelper.GetNewID(typeof(Model.Project_Devices));
device.DeviceId = this.DeviceId;
var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId);
var token = YunMouHelper.getToken();
string data;
data = Regex.Replace(project.ProjectCode, "[^0-9A-Fa-f]", "", RegexOptions.IgnoreCase);
string addMessage = "";
device.YunMouDeviceId = YunMouHelper.addDevices(device.DeviceSerial, data, device.ValidateCode, token,out addMessage);//添加设备之后,将权限添加到权限组
var res = YunMouHelper.addDevicesToGroups(project.YunMouGroupId, new string[] { device.DeviceSerial }, token);//添加到权限组
if (!string.IsNullOrEmpty(res))
{
device.YunMouPermission = "已关联";
}
BLL.ProjectDeviceService.AddProjectDevice(device);
BLL.LogService.AddSys_Log(this.CurrUser, device.DeviceName, device.DeviceId, BLL.Const.ProjectDevicesMenuId, BLL.Const.BtnAdd);
}
ShowNotify("保存数据成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
}
}