SGGL_SHJ/SGGL/FineUIPro.Web/ProjectData/ProjectSysSet.aspx.cs

342 lines
14 KiB
C#
Raw Normal View History

2022-09-05 16:36:31 +08:00
using BLL;
using System;
using System.Linq;
using System.Collections.Generic;
using FineUIPro;
2022-09-05 16:36:31 +08:00
namespace FineUIPro.Web.common.ProjectSet
{
public partial class ProjectSysSet : PageBase
{
/// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
Show(this.CurrUser.LoginProjectId);
}
}
#region
/// <summary>
/// 判断按钮权限
/// </summary>
private void GetButtonPower()
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.CQMSSysSetMenuId, Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
#endregion
#region
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
string projectId = this.CurrUser.LoginProjectId;
if (string.IsNullOrEmpty(projectId))
{
ShowNotify("请选择项目!", MessageBoxIcon.Warning);
return;
}
SaveWeldingSettings(projectId);
SaveColorModelSettings(projectId);
SaveQualitySettings(projectId);
2022-09-05 16:36:31 +08:00
// 刷新界面
this.Show(projectId);
2022-09-05 16:36:31 +08:00
//BLL.Sys_LogService.AddLog(BLL.Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, "提交项目环境设置");
Alert.ShowInTop("提交成功!", MessageBoxIcon.Success);
}
2022-09-05 16:36:31 +08:00
private void SaveWeldingSettings(string projectId)
{
// Booleans stored in IsAuto
UpsertIsAutoById("1", projectId, this.ckbDayReport.Checked);
UpsertIsAutoById("2", projectId, this.ckbPoint.Checked);
// trust (id 3) uses special mapping: 1->IsAuto=true, 2->IsAuto=false, otherwise IsAuto=null and SetValue holds value
UpsertTrustSetting("3", projectId, this.robStandard.SelectedValue);
UpsertIsAutoById("4", projectId, this.ckbPdms.Checked);
// batch (id 5) is a list of checked items
UpsertBatchSetting("5", projectId);
UpsertIsAutoById("6", projectId, this.ckbJointB.Checked);
UpsertIsAutoById("7", projectId, this.ckbThickness.Checked);
UpsertValueById("8", projectId, this.rblPressUnit.SelectedValue);
UpsertValueById("9", projectId, this.AvevaNetUrl.Text.Trim(), setName: "AVEVA NET 地址");
UpsertIsAutoById("10", projectId, this.ckPressMustCheckBItem.Checked);
UpsertValueById("11", projectId, this.rbMaterialColorAttribute.SelectedValue);
}
2022-09-05 16:36:31 +08:00
private void SaveColorModelSettings(string projectId)
{
UpsertByName("管线未完成", projectId, this.txtPipelineNOComplete.Text.Trim());
UpsertByName("管线已完成", projectId, this.txtPipelineComplete.Text.Trim());
UpsertByName("焊口未完成", projectId, this.drpJointNOCompleteColor.SelectedValue.Trim());
UpsertByName("焊口已完成", projectId, this.drpJointCompleteColor.SelectedValue.Trim());
}
2022-09-05 16:36:31 +08:00
private void SaveQualitySettings(string projectId)
{
UpsertByName("检试验设备到期提醒天数", projectId, this.txtRemindDay.Text.Trim());
UpsertByName("月报开始日期", projectId, this.txtStarTime.Text.Trim());
UpsertByName("月报结束日期", projectId, this.txtEndTime.Text.Trim());
}
2022-09-05 16:36:31 +08:00
#endregion
2022-09-05 16:36:31 +08:00
#region Upsert Helpers
private void UpsertIsAutoById(string setId, string projectId, bool value)
{
var existing = BLL.Project_SysSetService.GetSysSetBySetId(setId, projectId);
if (existing != null)
{
existing.IsAuto = value;
BLL.Project_SysSetService.UpdateSet(existing);
2022-09-05 16:36:31 +08:00
}
else
{
var newSet = new Model.Project_Sys_Set
2022-09-05 16:36:31 +08:00
{
SetId = setId,
ProjectId = projectId,
IsAuto = value
};
BLL.Project_SysSetService.AddSet(newSet);
2022-09-05 16:36:31 +08:00
}
}
2022-09-05 16:36:31 +08:00
private void UpsertValueById(string setId, string projectId, string value, string setName = null)
{
if (string.IsNullOrEmpty(value)) return;
var existing = BLL.Project_SysSetService.GetSysSetBySetId(setId, projectId);
if (existing != null)
{
existing.SetValue = value;
if (!string.IsNullOrEmpty(setName)) existing.SetName = setName;
BLL.Project_SysSetService.UpdateSet(existing);
2022-09-05 16:36:31 +08:00
}
else
{
var newSet = new Model.Project_Sys_Set
2022-09-05 16:36:31 +08:00
{
SetId = setId,
ProjectId = projectId,
SetValue = value,
SetName = setName
};
BLL.Project_SysSetService.AddSet(newSet);
2022-09-05 16:36:31 +08:00
}
}
2022-09-05 16:36:31 +08:00
private void UpsertByName(string setName, string projectId, string value)
{
if (string.IsNullOrEmpty(value)) return;
var existing = BLL.Project_SysSetService.GetSysSetBySetName(setName, projectId);
if (existing != null)
{
existing.SetValue = value;
BLL.Project_SysSetService.UpdateSet(existing);
2022-09-05 16:36:31 +08:00
}
else
{
var newSet = new Model.Project_Sys_Set
2022-09-05 16:36:31 +08:00
{
SetId = SQLHelper.GetNewID(typeof(Model.Project_Sys_Set)),
ProjectId = projectId,
SetName = setName,
SetValue = value
};
BLL.Project_SysSetService.AddSet(newSet);
2022-09-05 16:36:31 +08:00
}
}
2022-09-05 16:36:31 +08:00
private void UpsertTrustSetting(string setId, string projectId, string selectedValue)
{
var existing = BLL.Project_SysSetService.GetSysSetBySetId(setId, projectId);
if (existing != null)
2022-09-05 16:36:31 +08:00
{
if (selectedValue == "1")
2022-09-05 16:36:31 +08:00
{
existing.IsAuto = true;
existing.SetValue = null;
2022-09-05 16:36:31 +08:00
}
else if (selectedValue == "2")
2022-09-05 16:36:31 +08:00
{
existing.IsAuto = false;
existing.SetValue = null;
2022-09-05 16:36:31 +08:00
}
else
2022-09-05 16:36:31 +08:00
{
existing.IsAuto = null;
existing.SetValue = selectedValue;
2022-09-05 16:36:31 +08:00
}
BLL.Project_SysSetService.UpdateSet(existing);
2022-09-05 16:36:31 +08:00
}
else
{
var newSet = new Model.Project_Sys_Set
{
SetId = setId,
ProjectId = projectId
};
if (selectedValue == "1")
2022-09-05 16:36:31 +08:00
{
newSet.IsAuto = true;
2022-09-05 16:36:31 +08:00
}
else if (selectedValue == "2")
{
newSet.IsAuto = false;
}
else
2022-09-05 16:36:31 +08:00
{
newSet.IsAuto = null;
newSet.SetValue = selectedValue;
2022-09-05 16:36:31 +08:00
}
BLL.Project_SysSetService.AddSet(newSet);
}
}
2022-09-05 16:36:31 +08:00
private void UpsertBatchSetting(string setId, string projectId)
{
var items = new List<string>();
if (cb1.Checked) items.Add("1");
if (cb2.Checked) items.Add("2");
if (cb3.Checked) items.Add("3");
if (cb4.Checked) items.Add("4");
if (cb5.Checked) items.Add("5");
if (cb6.Checked) items.Add("6");
if (cb7.Checked) items.Add("7");
if (items.Count == 0) return;
var lists = string.Join("|", items);
var existing = BLL.Project_SysSetService.GetSysSetBySetId(setId, projectId);
if (existing != null)
{
existing.IsAuto = true;
existing.SetValue = lists;
BLL.Project_SysSetService.UpdateSet(existing);
2022-09-05 16:36:31 +08:00
}
else
{
var newSet = new Model.Project_Sys_Set
2022-09-05 16:36:31 +08:00
{
SetId = setId,
ProjectId = projectId,
IsAuto = true,
SetValue = lists
};
BLL.Project_SysSetService.AddSet(newSet);
2022-09-05 16:36:31 +08:00
}
}
#endregion
#region
/// <summary>
/// 页面呈现
2022-09-05 16:36:31 +08:00
/// </summary>
private void Show(string projectId)
{
var q = from x in Funs.DB.Project_Sys_Set where x.ProjectId == projectId select x;
if (q.Any())
2022-09-05 16:36:31 +08:00
{
var dict = q.ToDictionary(x => x.SetId, x => x);
2022-09-05 16:36:31 +08:00
SetCheckFromDict(dict, "1", this.ckbDayReport);
SetCheckFromDict(dict, "2", this.ckbPoint);
SetRobStandardFromDict(dict, "3");
SetCheckFromDict(dict, "4", this.ckbPdms);
SetBatchFromDict(dict, "5");
SetCheckFromDict(dict, "6", this.ckbJointB);
SetCheckFromDict(dict, "7", this.ckbThickness);
SetRadioValueFromDict(dict, "8", this.rblPressUnit, defaultValue: "2");
if (dict.ContainsKey("9")) this.AvevaNetUrl.Text = dict["9"].SetValue;
SetCheckFromDict(dict, "10", this.ckPressMustCheckBItem);
if (dict.ContainsKey("11")) this.rbMaterialColorAttribute.SelectedValue = dict["11"].SetValue == "1" ? "1" : "2";
2022-09-05 16:36:31 +08:00
}
2022-09-05 16:36:31 +08:00
//颜色模型设置
var m1 = BLL.Project_SysSetService.GetSysSetBySetName("管线未完成", this.CurrUser.LoginProjectId);
if (m1 != null) this.txtPipelineNOComplete.Text = m1.SetValue;
var m2 = BLL.Project_SysSetService.GetSysSetBySetName("管线已完成", this.CurrUser.LoginProjectId);
if (m2 != null) this.txtPipelineComplete.Text = m2.SetValue;
var m3 = BLL.Project_SysSetService.GetSysSetBySetName("焊口未完成", this.CurrUser.LoginProjectId);
if (m3 != null) this.drpJointNOCompleteColor.SelectedValue = m3.SetValue;
var m4 = BLL.Project_SysSetService.GetSysSetBySetName("焊口已完成", this.CurrUser.LoginProjectId);
if (m4 != null) this.drpJointCompleteColor.SelectedValue = m4.SetValue;
2022-09-05 16:36:31 +08:00
///质量页面呈现
var c1 = BLL.Project_SysSetService.GetSysSetBySetName("检试验设备到期提醒天数", this.CurrUser.LoginProjectId);
if (c1 != null) this.txtRemindDay.Text = c1.SetValue;
var c2 = BLL.Project_SysSetService.GetSysSetBySetName("月报开始日期", this.CurrUser.LoginProjectId);
if (c2 != null) this.txtStarTime.Text = c2.SetValue; else this.txtStarTime.Text = "25";
var c3 = BLL.Project_SysSetService.GetSysSetBySetName("月报结束日期", this.CurrUser.LoginProjectId);
if (c3 != null) this.txtEndTime.Text = c3.SetValue; else this.txtEndTime.Text = "24";
}
private void SetCheckFromDict(Dictionary<string, Model.Project_Sys_Set> dict, string setId, CheckBox checkBox)
{
if (!dict.ContainsKey(setId)) return;
var s = dict[setId];
checkBox.Checked = s.IsAuto == true;
}
private void SetRobStandardFromDict(Dictionary<string, Model.Project_Sys_Set> dict, string setId)
{
if (!dict.ContainsKey(setId)) return;
var s = dict[setId];
if (s.IsAuto == true) this.robStandard.SelectedValue = "1";
else if (s.IsAuto == false) this.robStandard.SelectedValue = "2";
else if (s.SetValue == "3") this.robStandard.SelectedValue = "3";
else if (s.SetValue == "4") this.robStandard.SelectedValue = "4";
}
private void SetBatchFromDict(Dictionary<string, Model.Project_Sys_Set> dict, string setId)
{
if (!dict.ContainsKey(setId)) return;
// reset some checkboxes first
cb1.Checked = cb2.Checked = cb3.Checked = cb4.Checked = cb5.Checked = cb6.Checked = cb7.Checked = false;
var s = dict[setId];
if (string.IsNullOrEmpty(s.SetValue)) return;
var items = s.SetValue.Split('|');
foreach (var item in items)
{
switch (item)
{
case "1": cb1.Checked = true; break;
case "2": cb2.Checked = true; break;
case "3": cb3.Checked = true; break;
case "4": cb4.Checked = true; break;
case "5": cb5.Checked = true; break;
case "6": cb6.Checked = true; break;
case "7": cb7.Checked = true; break;
}
2022-09-05 16:36:31 +08:00
}
}
private void SetRadioValueFromDict(Dictionary<string, Model.Project_Sys_Set> dict, string setId, RadioButtonList rbl, string defaultValue = null)
{
if (!dict.ContainsKey(setId))
2022-09-05 16:36:31 +08:00
{
if (defaultValue != null) rbl.SelectedValue = defaultValue;
return;
2022-09-05 16:36:31 +08:00
}
var s = dict[setId];
rbl.SelectedValue = s.SetValue ?? defaultValue;
2022-09-05 16:36:31 +08:00
}
#endregion
}
}