2024-05-29 01:56:37 +00:00
|
|
|
|
using DevExpress.XtraBars.ToolbarForm;
|
|
|
|
|
using DevExpress.XtraEditors;
|
|
|
|
|
using DevExpress.XtraEditors.DXErrorProvider;
|
2024-05-30 15:52:57 +00:00
|
|
|
|
using DeviceRepair.Models;
|
|
|
|
|
using DeviceRepair.Models.Common;
|
2024-05-29 01:56:37 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using TsSFCDeivceClient.Common;
|
|
|
|
|
using TsSFCDeivceClient.Email;
|
|
|
|
|
|
|
|
|
|
namespace TsSFCDeivceClient
|
|
|
|
|
{
|
|
|
|
|
public partial class DowntimeFormAdd : ToolbarForm
|
|
|
|
|
{
|
|
|
|
|
MailKitHelp mail = new MailKitHelp();
|
2024-05-30 15:52:57 +00:00
|
|
|
|
public DeviceInformationInfo CurrentDeviceInfo = null;
|
2024-06-02 16:38:52 +00:00
|
|
|
|
|
2024-05-29 01:56:37 +00:00
|
|
|
|
bool InProduction
|
|
|
|
|
{
|
|
|
|
|
get { return Convert.ToBoolean(rg_NeedValidate.EditValue); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsDown
|
|
|
|
|
{
|
|
|
|
|
get { return Convert.ToBoolean(rg_IsDown.EditValue); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WhereFailureOccurred
|
|
|
|
|
{
|
|
|
|
|
get { return Convert.ToInt32(ddlWhereFailureOccurred.EditValue); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DowntimeFormAdd()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.Load += DowntimeFormAdd_Load;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DowntimeFormAdd_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-06-02 16:38:52 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(RunConfig.config.ServiceApiUrl))
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
|
|
|
|
XtraMessageBoxHelper.Error($"缺少配置字段(设备管理软件接口地址)【ServiceApiUrl】。");
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-02 16:38:52 +00:00
|
|
|
|
APIResponseData apiResponseData = Biz.HttpHelper.Instance.Get($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.GetWhereFailureOccurred}");
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
|
|
|
|
if (!apiResponseData.IsSuccess)
|
|
|
|
|
throw new Exception(apiResponseData.Message);
|
|
|
|
|
|
|
|
|
|
List<FieldsInfo> lst = apiResponseData.ToDeserializeObject<List<FieldsInfo>>();
|
|
|
|
|
ddlWhereFailureOccurred.Properties.DataSource = lst;
|
|
|
|
|
ddlWhereFailureOccurred.Properties.DisplayMember = "FieldText";
|
|
|
|
|
ddlWhereFailureOccurred.Properties.ValueMember = "AutoID";
|
|
|
|
|
ddlWhereFailureOccurred.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
|
|
|
if (ddlWhereFailureOccurred.Properties.DataSource != null && (ddlWhereFailureOccurred.Properties.DataSource as List<FieldsInfo>).Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ddlWhereFailureOccurred.EditValue = (ddlWhereFailureOccurred.Properties.DataSource as List<FieldsInfo>)[0].AutoID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitializeMail()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (mail == null)
|
|
|
|
|
{
|
|
|
|
|
mail = new MailKitHelp();
|
|
|
|
|
}
|
|
|
|
|
//发件服务器设置
|
2024-06-02 16:38:52 +00:00
|
|
|
|
APIResponseData apiRtn = Biz.HttpHelper.Instance.Get($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.SysEmailConfig}?ModuleCode=DeviceWarranty");
|
2024-05-30 15:52:57 +00:00
|
|
|
|
if (!apiRtn.IsSuccess)
|
|
|
|
|
throw new Exception(apiRtn.Message);
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
2024-05-30 15:52:57 +00:00
|
|
|
|
SysEmailConfigInfo config = apiRtn.ToDeserializeObject<SysEmailConfigInfo>();
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
2024-05-30 15:52:57 +00:00
|
|
|
|
mail.FromMailAddress = config.EmailAddress;
|
|
|
|
|
mail.SmtpAddress = config.SmtpServer;
|
|
|
|
|
mail.IsSSL = config.SmtpSSL;
|
|
|
|
|
mail.SmtpPort = config.SmtpPort;
|
|
|
|
|
if (!config.EmailNoPass)
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
2024-05-30 15:52:57 +00:00
|
|
|
|
mail.PassWord = DESEncrypt.Decrypt(config.EmailPassWord);
|
2024-05-29 01:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2024-05-30 15:52:57 +00:00
|
|
|
|
{
|
|
|
|
|
mail.IsUseDefaultCredentials = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// mail.medtronic.com
|
|
|
|
|
//mail.SmtpAddress = m_Config.AppSettings.Settings["SmtpServer"].Value.Trim();
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
2024-05-30 15:52:57 +00:00
|
|
|
|
//// false
|
|
|
|
|
//mail.IsSSL = bool.Parse(m_Config.AppSettings.Settings["SmtpSSL"].Value.Trim());
|
|
|
|
|
|
|
|
|
|
//// 25
|
|
|
|
|
//mail.SmtpPort = int.Parse(m_Config.AppSettings.Settings["SmtpPort"].Value.Trim());
|
|
|
|
|
|
|
|
|
|
////是否启用无密码模式
|
|
|
|
|
//if (bool.Parse(m_Config.AppSettings.Settings["EmailNoPass"].Value.Trim()))
|
|
|
|
|
//{
|
|
|
|
|
// mail.IsUseDefaultCredentials = true;
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
// mail.PassWord = m_Config.AppSettings.Settings["EmailPassWord"].Value.Trim();
|
|
|
|
|
|
|
|
|
|
//mail.FromMailAddress = m_Config.AppSettings.Settings["EmailAddress"].Value.Trim();
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 故障发生时是否有产品在加工/测试在进行 - 是否开启批次号输入控件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void rg_NeedValidate_EditValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
txtBatch.Enabled = InProduction;
|
|
|
|
|
if (!InProduction)
|
|
|
|
|
txtBatch.EditValue = "N/A";
|
2024-05-30 02:11:52 +00:00
|
|
|
|
else
|
|
|
|
|
txtBatch.EditValue = "";
|
2024-05-29 01:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
XtraMessageBoxHelper.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选择设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void bbtnDevice_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CurrentDeviceInfo = null;
|
|
|
|
|
using (pageDeivceView view = new pageDeivceView())
|
|
|
|
|
{
|
2024-07-01 16:52:48 +00:00
|
|
|
|
if (view.ShowDialog(this) == DialogResult.OK)
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
|
|
|
|
CurrentDeviceInfo = view.CurrentDeviceInfo;
|
2024-06-03 17:21:11 +00:00
|
|
|
|
bbtnDevice.EditValue = $"{view.CurrentDeviceInfo.EquipmentName}({CurrentDeviceInfo.EquipmentID})";
|
2024-05-29 01:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
XtraMessageBoxHelper.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化验证控件
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitializeValidationProvider()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<BaseEdit> param = new List<BaseEdit> { textEdit2, bbtnDevice, ddlWhereFailureOccurred, memoEdit1 };
|
|
|
|
|
foreach (var item in param)
|
|
|
|
|
{
|
|
|
|
|
dxValidationProvider1.RemoveControlError(item);
|
|
|
|
|
}
|
|
|
|
|
dxValidationProvider1.RemoveControlError(txtBatch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dxValidationProvider1 = new DXValidationProvider();
|
|
|
|
|
|
|
|
|
|
//实例化一个必填规则,错误提示为:该字段不能为空
|
|
|
|
|
ConditionValidationRule required = new ConditionValidationRule("RequiredRule", ConditionOperator.IsNotBlank) { ErrorText = $"字段不能为空" };
|
|
|
|
|
|
|
|
|
|
if (InProduction)
|
|
|
|
|
{
|
|
|
|
|
param.Add(txtBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < param.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
dxValidationProvider1.SetValidationRule(param[i], required);
|
|
|
|
|
dxValidationProvider1.SetIconAlignment(param[i], ErrorIconAlignment.MiddleRight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
XtraMessageBoxHelper.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
InitializeValidationProvider();
|
|
|
|
|
if (dxValidationProvider1.Validate())
|
|
|
|
|
{
|
|
|
|
|
string cBatch = txtBatch.EditValue + "";
|
2024-05-30 15:52:57 +00:00
|
|
|
|
List<string> emailLst = new List<string>();
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
|
|
|
|
if (InProduction)
|
|
|
|
|
{
|
2024-06-02 16:38:52 +00:00
|
|
|
|
APIResponseData apiRtn = Biz.HttpHelper.Instance.Get($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.GetBatchInfoToStaff}?Batch={cBatch}");
|
2024-05-30 15:52:57 +00:00
|
|
|
|
if (!apiRtn.IsSuccess)
|
|
|
|
|
throw new Exception(apiRtn.Message);
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
2024-05-30 15:52:57 +00:00
|
|
|
|
if (apiRtn.ToInt() == 0)
|
|
|
|
|
throw new Exception("当前批次不存在!");
|
2024-05-29 01:56:37 +00:00
|
|
|
|
|
2024-06-02 16:38:52 +00:00
|
|
|
|
apiRtn = Biz.HttpHelper.Instance.Get($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.CurrentBatchManagerEmail}?Batch={cBatch}");
|
2024-05-30 15:52:57 +00:00
|
|
|
|
if (!apiRtn.IsSuccess)
|
|
|
|
|
throw new Exception(apiRtn.Message);
|
|
|
|
|
emailLst.AddRange(apiRtn.ToDeserializeObject<List<string>>());
|
2024-05-29 01:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 15:52:57 +00:00
|
|
|
|
DeviceWarrantyRequestFormView deviceWarrantyRequestForm = new DeviceWarrantyRequestFormView
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
|
|
|
|
EquipmentPK = CurrentDeviceInfo.AutoID,
|
|
|
|
|
EquipmentID = CurrentDeviceInfo.EquipmentID,
|
|
|
|
|
EquipmentName = CurrentDeviceInfo.EquipmentName,
|
|
|
|
|
Location = WhereFailureOccurred,
|
|
|
|
|
LocationName = ddlWhereFailureOccurred.Text?.Trim(),
|
|
|
|
|
InProduction = InProduction,
|
|
|
|
|
Batch = cBatch,
|
|
|
|
|
FaultSymptoms = memoEdit1.EditValue + "",
|
|
|
|
|
IsDown = IsDown,
|
|
|
|
|
ReceivingDep = "设备设施部"
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-02 16:38:52 +00:00
|
|
|
|
APIResponseData apiResponseData = Biz.HttpHelper.Instance.Post($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.DeviceDownFormAdd}", JsonConvert.SerializeObject(deviceWarrantyRequestForm));
|
2024-05-29 01:56:37 +00:00
|
|
|
|
if (!apiResponseData.IsSuccess)
|
|
|
|
|
throw new Exception(apiResponseData.Message);
|
|
|
|
|
|
2024-05-29 05:54:55 +00:00
|
|
|
|
int MaintenanceAutoID = Convert.ToInt32(apiResponseData.Data);
|
|
|
|
|
try
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
2024-05-30 15:52:57 +00:00
|
|
|
|
if (emailLst.Count > 0 && InitializeMail())
|
2024-05-29 05:54:55 +00:00
|
|
|
|
{
|
|
|
|
|
mail.Title = $"有在生产的设备出现故障,请您尽快评估故障状态!";
|
|
|
|
|
mail.IsBodyHtml = true;
|
|
|
|
|
System.Text.StringBuilder builder = new System.Text.StringBuilder();
|
2024-06-05 17:09:59 +00:00
|
|
|
|
builder.AppendLine($"<p>在 {ddlWhereFailureOccurred.Text} 发起的编号为:{MaintenanceAutoID} 的报修单,设备 {CurrentDeviceInfo.EquipmentName}({CurrentDeviceInfo.EquipmentID}) 发生故障,{(deviceWarrantyRequestForm.InProduction ? "存有产品在加工中,产品批次号:" + deviceWarrantyRequestForm.Batch : "")} ,请您尽快评估故障情况。</p>");
|
2024-05-29 05:54:55 +00:00
|
|
|
|
builder.AppendLine($"<p>发起人:生产部 - {Runtime.CurrentUser.UserName}</p>");
|
|
|
|
|
mail.Body = builder.ToString();
|
|
|
|
|
string msgResult = "";
|
|
|
|
|
//收件人
|
2024-05-30 15:52:57 +00:00
|
|
|
|
mail.ToMailAddress = emailLst.ToArray();
|
2024-05-29 05:54:55 +00:00
|
|
|
|
MailKitHelp.SendStatus ss = mail.Send(out msgResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2024-05-29 01:56:37 +00:00
|
|
|
|
{
|
2024-05-29 05:54:55 +00:00
|
|
|
|
XtraMessageBoxHelper.Warn($"新增数据成功,邮件发送失败,失败原因:{ex.Message}");
|
2024-05-29 01:56:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
XtraMessageBoxHelper.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtBatch_Properties_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//增加了自动切换大写,控制只能输入大写字母、数字、回退按钮、复制快捷键(复制的数据没有控制格式)
|
|
|
|
|
e.KeyChar = Convert.ToChar(e.KeyChar.ToString().ToUpper());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|