DeviceManager/TsSFCDevice.Client.Launch/Device/Page_DriveInfoEdit.cs

496 lines
19 KiB
C#
Raw Normal View History

2024-07-27 01:44:19 +00:00
using DevExpress.XtraEditors;
using DeviceRepair.Models;
using System;
2024-08-02 02:52:45 +00:00
using System.Linq;
2024-07-27 01:44:19 +00:00
using System.Windows.Forms;
2024-08-02 02:52:45 +00:00
using TsSFCDevice.Client.Biz.Base.Utils;
2024-07-27 01:44:19 +00:00
using TsSFCDevice.Client.Biz.Impl;
namespace TsSFCDevice.Client.Launch.Device
{
public partial class Page_DriveInfoEdit : XtraForm
{
private string Caption;
private View_DriveInfomationModel CurrentModel;
private int FormVerValue = 0;
private string FormVerName = "";
2024-08-05 09:21:06 +00:00
private int AMFormVerValue = 0;
private string AMFormVerName = "";
2024-07-27 01:44:19 +00:00
public DeviceInformationInfo OperationObject;
public DateTime ServiceTime;
public Page_DriveInfoEdit(string caption = null, View_DriveInfomationModel Model = null)
{
InitializeComponent();
2024-11-09 16:05:40 +00:00
if (!string.IsNullOrEmpty(caption))
{
txt_EquipmentName.Enabled = false;
}
2024-07-27 01:44:19 +00:00
Caption = caption ?? "新增";
2024-11-09 16:05:40 +00:00
2024-07-27 01:44:19 +00:00
CurrentModel = Model ?? new View_DriveInfomationModel();
layoutControlGroup1.ViewInfo.OwnerILayoutControl.AllowCustomizationMenu = false;
}
private void Page_DriveInfoEdit_Load(object sender, EventArgs e)
{
this.Text = Caption;
if (CurrentModel != null && CurrentModel.AutoID > 0)
BindDatas();
}
private void BindDatas()
{
txt_Route.Tag = CurrentModel.Route;
2024-08-02 02:52:45 +00:00
if (CurrentModel.Route > 0)
{
2024-08-05 09:21:06 +00:00
txt_Route.EditValue = Utility.SystemRuntimeInfo.CurrentDevRootCaches.FirstOrDefault(x => x.AutoID == CurrentModel.Route)?.Name;
2024-08-02 02:52:45 +00:00
}
//txt_Route.EditValue = CurrentModel.RouteText;
2024-07-27 01:44:19 +00:00
// 设备编号
txt_EquipmentID.Enabled = false;
txt_EquipmentID.Text = CurrentModel.EquipmentID;
// 设备名称
txt_EquipmentName.Text = CurrentModel.EquipmentName;
// 设备型号规格
txt_Specification.Text = CurrentModel.Specification;
// 制造厂家
txt_Manufacturer.Text = CurrentModel.Manufacturer;
// 出厂编号
txt_SerialNumber.Text = CurrentModel.SerialNumber;
// 投产年月
if (!string.IsNullOrWhiteSpace(CurrentModel.UsingDate))
{
DateTime t;
if (DateTime.TryParse(CurrentModel.UsingDate, out t))
txt_UsingDate.EditValue = t;
}
// 设备总容量
txt_Totalcapacity.Text = CurrentModel.Totalcapacity + "";
// 设备重量
txt_Weight.Text = CurrentModel.Weight + "";
// 设备类别
txt_EquipmentCategory.Text = CurrentModel.EquipmentCategory;
// 设备原值
txt_EquipmentOriginalvalue.Text = CurrentModel.EquipmentOriginalvalue + "";
// 保质期
txt_WarrantyPeriod.Text = CurrentModel.WarrantyPeriod;
// 安装地点
txt_InstallationLocation.Text = CurrentModel.InstallationLocation;
// 所属单元
txt_OwningUnit.Text = CurrentModel.OwningUnit;
// 运行参数
txt_OperatingParameters.Text = CurrentModel.OperatingParameters;
// 使用的表单
FormVerValue = CurrentModel.MaintenanceFormVersion;
//FormVerName = CurrentModel.MaintenanceFormVersionName;
2024-09-26 02:47:56 +00:00
btn_SelectFormRev.Text = $"{CurrentModel.VersionCode}-{CurrentModel.VersionRev}";
AMFormVerValue = CurrentModel.MaintenanceAMFormVersion;
btn_AM_Form.Text = $"{CurrentModel.AMVersionCode}-{CurrentModel.AMVersionRev}";
2024-07-27 01:44:19 +00:00
// 备注
txt_Remarks.Text = CurrentModel.Remarks;
}
private void btn_Submit_Click(object sender, EventArgs e)
{
try
{
splashScreenManager1.ShowWaitForm();
if (DataValidata())
{
if (CurrentModel.AutoID == 0)
{
APIResponseData apiResponseData = DevRepository.Instance.Insert((DeviceInformationInfo)CurrentModel, out OperationObject);
if (!apiResponseData.IsSuccess)
throw new Exception(apiResponseData.Message);
}
else
{
APIResponseData apiResponseData = DevRepository.Instance.Update(CurrentModel, out ServiceTime);
if (!apiResponseData.IsSuccess)
throw new Exception(apiResponseData.Message);
}
splashScreenManager1.TryCloseWait();
DialogResult = DialogResult.OK;
}
else
{
splashScreenManager1.TryCloseWait();
}
}
catch (Exception ex)
{
splashScreenManager1.TryCloseWait();
XtraMessageBoxHelper.Error(ex.Message);
DialogResult = DialogResult.Abort;
}
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
/// <summary>
/// 选择表单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_SelectFormRev_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
int Value = 0;
int.TryParse(FormVerValue + "", out Value);
Page_FormVersionDialog view = new Page_FormVersionDialog(Value);
if (view.ShowDialog(this) == DialogResult.OK)
{
CurrentModel.MaintenanceFormVersion = view.SelectValue;
FormVerValue = view.SelectValue;
FormVerName = view.SelectText + "";
btn_SelectFormRev.Text = FormVerName;
}
}
/// <summary>
/// 数据验证
/// </summary>
private bool DataValidata()
{
try
{
dxErrorProvider1.ClearErrors();
View_DriveInfomationModel t2 = new View_DriveInfomationModel
{
AutoID = CurrentModel.AutoID,
EquipmentID = txt_EquipmentID.Text,
EquipmentName = txt_EquipmentName.Text,
Specification = txt_Specification.Text,
Manufacturer = txt_Manufacturer.Text,
SerialNumber = txt_SerialNumber.Text,
Totalcapacity = Convert.ToDouble(txt_Totalcapacity.Text),
Weight = Convert.ToDouble(txt_Weight.Text),
EquipmentCategory = txt_EquipmentCategory.Text,
EquipmentOriginalvalue = Convert.ToDecimal(txt_EquipmentOriginalvalue.Text),
EquipmentStatus = 1,
WarrantyPeriod = txt_WarrantyPeriod.Text,
InstallationLocation = txt_InstallationLocation.Text,
OwningUnit = txt_OwningUnit.Text,
OperatingParameters = txt_OperatingParameters.Text,
MaintenanceFormVersion = FormVerValue,
2024-08-05 09:21:06 +00:00
MaintenanceAMFormVersion = AMFormVerValue,
2024-07-27 01:44:19 +00:00
Remarks = txt_Remarks.Text
};
#region
int Route = 0;
if (txt_Route.Tag == null || !int.TryParse(txt_Route.Tag + "", out Route) || Route <= 0)
{
dxErrorProvider1.SetError(txt_Route, "设备父级分类不能为空!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
t2.Route = Route;
#endregion
#region
if (CurrentModel.AutoID == 0)
{
if (string.IsNullOrWhiteSpace(t2.EquipmentID))
{
dxErrorProvider1.SetError(txt_EquipmentID, "设备编号字段不允许为空!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
if (t2.EquipmentID.Length > 50)
{
dxErrorProvider1.SetError(txt_EquipmentID, "设备编号字段长度超限,最大字数不能超出50", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
bool Exists = DevRepository.Instance.EquipmentID_EXISTS(t2.EquipmentID);
if (Exists)
{
dxErrorProvider1.SetError(txt_EquipmentID, $"设备编号 - {t2.EquipmentID}已经存在!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
}
#endregion
#region
if (string.IsNullOrWhiteSpace(t2.EquipmentName))
{
dxErrorProvider1.SetError(txt_EquipmentName, "设备名称字段不允许为空!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else if (t2.EquipmentName.Length > 200)
{
dxErrorProvider1.SetError(txt_EquipmentName, "设备名称字段长度超限,最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_EquipmentName, "");
}
#endregion
#region
if (t2.Specification.Length > 200)
{
dxErrorProvider1.SetError(txt_Specification, "设备型号规格字段长度超限,最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Specification, "");
}
#endregion
#region
if (t2.Manufacturer.Length > 200)
{
dxErrorProvider1.SetError(txt_Manufacturer, "制造厂家字段长度超限, 最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Manufacturer, "");
}
#endregion
#region
if (t2.SerialNumber.Length > 200)
{
dxErrorProvider1.SetError(txt_SerialNumber, "出厂编号字段长度超限, 最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_SerialNumber, "");
}
#endregion
#region
// 投产年月
if (!string.IsNullOrWhiteSpace(txt_UsingDate.EditValue + ""))
{
DateTime t;
if (DateTime.TryParse(txt_UsingDate.EditValue + "", out t))
{
DateTime CurrentDate = CommonRepository.Instance.ServiceTime();
if (t.Date > CurrentDate.Date)
{
dxErrorProvider1.SetError(txt_UsingDate, "投产年月字段不能超过当前时间!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_UsingDate, "");
t2.UsingDate = t.ToString("yyyy.MM.dd");
}
}
}
else
{
dxErrorProvider1.SetError(txt_UsingDate, "投产年月字段的格式不正确!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
#endregion
#region
if (t2.EquipmentCategory.Length > 20)
{
dxErrorProvider1.SetError(txt_EquipmentCategory, "设备类别字段长度超限,最大字数不能超出20", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_EquipmentCategory, "");
}
#endregion
#region
if (t2.WarrantyPeriod.Length > 50)
{
dxErrorProvider1.SetError(txt_WarrantyPeriod, "质保期字段长度超限,最大字数不能超出50", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_WarrantyPeriod, "");
}
#endregion
#region
if (t2.InstallationLocation.Length > 200)
{
dxErrorProvider1.SetError(txt_InstallationLocation, "安装地点字段长度超限,最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_InstallationLocation, "");
}
#endregion
#region
if (t2.OwningUnit.Length > 200)
{
dxErrorProvider1.SetError(txt_OwningUnit, "所属单元字段长度超限, 最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_OwningUnit, "");
}
#endregion
#region
if (t2.OperatingParameters.Length > 200)
{
dxErrorProvider1.SetError(txt_OperatingParameters, "运行参数字段长度超限, 最大字数不能超出200", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_OperatingParameters, "");
}
#endregion
#region
if (t2.Totalcapacity < 0)
{
dxErrorProvider1.SetError(txt_Totalcapacity, "设定值不能小于零!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else if (t2.Totalcapacity > 9999999999)
{
dxErrorProvider1.SetError(txt_Totalcapacity, $"设定值不能超出最大值9999999999", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Totalcapacity, "");
}
#endregion
#region
if (t2.Weight < 0)
{
dxErrorProvider1.SetError(txt_Weight, "设定值不能小于零!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else if (t2.Weight > 9999999999)
{
dxErrorProvider1.SetError(txt_Weight, $"设定值不能超出最大值9999999999", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Weight, "");
}
#endregion
#region
if (t2.EquipmentOriginalvalue < 0)
{
dxErrorProvider1.SetError(txt_EquipmentOriginalvalue, "设定值不能小于零!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
if (t2.EquipmentOriginalvalue > 9999999999)
{
dxErrorProvider1.SetError(txt_EquipmentOriginalvalue, $"设定值不能超出最大值9999999999", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Weight, "");
}
#endregion
#region
if (t2.Remarks.Length > 2000)
{
dxErrorProvider1.SetError(txt_Remarks, "备注字段长度超限,最大字数不能超出2000", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
return false;
}
else
{
dxErrorProvider1.SetError(txt_Remarks, "");
}
#endregion
CurrentModel = t2;
return true;
}
catch (Exception ex)
{
XtraMessageBoxHelper.Error(ex.Message);
return false;
}
}
/// <summary>
/// 选则父级
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
int Route = txt_Route.Tag == null ? 0 : (int)txt_Route.Tag;
using (pageRouteAssign view = new pageRouteAssign(Route))
{
if (view.ShowDialog(this) == DialogResult.OK)
{
txt_Route.EditValue = view.CurrentSelectModel.Name;
txt_Route.Tag = view.CurrentSelectModel.AutoID;
}
}
}
2024-08-05 09:21:06 +00:00
private void btn_AM_Form_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
int Value = 0;
int.TryParse(AMFormVerValue + "", out Value);
Page_FormVersionDialog view = new Page_FormVersionDialog(Value, DeviceRepair.Models.Enum.EnumDeviceBelong.AM);
if (view.ShowDialog(this) == DialogResult.OK)
{
CurrentModel.MaintenanceAMFormVersion = view.SelectValue;
AMFormVerValue = view.SelectValue;
AMFormVerName = view.SelectText + "";
btn_AM_Form.Text = AMFormVerName;
}
}
2024-07-27 01:44:19 +00:00
}
}